This commit is contained in:
2025-04-26 11:07:05 +08:00
commit abf553c41b
4942 changed files with 930993 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
<?php
namespace app\common\model;
use think\Cache;
use think\Model;
/**
* 地区数据模型
*/
class Area extends Model
{
/**
* 根据经纬度获取当前地区信息
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area 城市信息
*/
public static function getAreaFromLngLat($lng, $lat, $level = 3)
{
$namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
$rangearr = [1 => 15000, 2 => 1000, 3 => 200];
$geoname = $namearr[$level] ?? $namearr[3];
$georange = $rangearr[$level] ?? $rangearr[3];
// 读取范围内的ID
$redis = Cache::store('redis')->handler();
$georadiuslist = [];
if (method_exists($redis, 'georadius')) {
$georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
}
if ($georadiuslist) {
list($id, $distance) = $georadiuslist[0];
}
$id = isset($id) && $id ? $id : 3;
return self::get($id);
}
/**
* 根据经纬度获取省份
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area
*/
public static function getProvinceFromLngLat($lng, $lat)
{
$provincedata = null;
$citydata = self::getCityFromLngLat($lng, $lat);
if ($citydata) {
$provincedata = self::get($citydata['pid']);
}
return $provincedata;
}
/**
* 根据经纬度获取城市
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area
*/
public static function getCityFromLngLat($lng, $lat)
{
$citydata = null;
$districtdata = self::getDistrictFromLngLat($lng, $lat);
if ($districtdata) {
$citydata = self::get($districtdata['pid']);
}
return $citydata;
}
/**
* 根据经纬度获取地区
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area
*/
public static function getDistrictFromLngLat($lng, $lat)
{
$districtdata = self::getAreaFromLngLat($lng, $lat, 3);
return $districtdata;
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace app\common\model;
use think\Model;
class Attachment extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 定义字段类型
protected $type = [
];
protected $append = [
'thumb_style'
];
protected static function init()
{
// 如果已经上传该资源,则不再记录
self::beforeInsert(function ($model) {
if (self::where('url', '=', $model['url'])->where('storage', $model['storage'])->find()) {
return false;
}
});
self::beforeWrite(function ($row) {
if (isset($row['category']) && $row['category'] == 'unclassed') {
$row['category'] = '';
}
});
}
public function setUploadtimeAttr($value)
{
return is_numeric($value) ? $value : strtotime($value);
}
public function getCategoryAttr($value)
{
return $value == '' ? 'unclassed' : $value;
}
public function setCategoryAttr($value)
{
return $value == 'unclassed' ? '' : $value;
}
/**
* 获取云储存的缩略图样式字符
*/
public function getThumbStyleAttr($value, $data)
{
if (!isset($data['storage']) || $data['storage'] == 'local') {
return '';
} else {
$config = get_addon_config($data['storage']);
if ($config && isset($config['thumbstyle'])) {
return $config['thumbstyle'];
}
}
return '';
}
/**
* 获取Mimetype列表
* @return array
*/
public static function getMimetypeList()
{
$data = [
"image/*" => __("Image"),
"audio/*" => __("Audio"),
"video/*" => __("Video"),
"text/*" => __("Text"),
"application/*" => __("Application"),
"zip,rar,7z,tar" => __("Zip"),
];
return $data;
}
/**
* 获取定义的附件类别列表
* @return array
*/
public static function getCategoryList()
{
$data = config('site.attachmentcategory') ?? [];
foreach ($data as $index => &$datum) {
$datum = __($datum);
}
$data['unclassed'] = __('Unclassed');
return $data;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 分类模型
*/
class Category extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'type_text',
'flag_text',
];
protected static function init()
{
self::afterInsert(function ($row) {
$row->save(['weigh' => $row['id']]);
});
}
public function setFlagAttr($value, $data)
{
return is_array($value) ? implode(',', $value) : $value;
}
/**
* 读取分类类型
* @return array
*/
public static function getTypeList()
{
$typeList = config('site.categorytype');
foreach ($typeList as $k => &$v) {
$v = __($v);
}
return $typeList;
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : $data['type'];
$list = $this->getTypeList();
return $list[$value] ?? '';
}
public function getFlagList()
{
return ['hot' => __('Hot'), 'index' => __('Index'), 'recommend' => __('Recommend')];
}
public function getFlagTextAttr($value, $data)
{
$value = $value ? $value : $data['flag'];
$valueArr = explode(',', $value);
$list = $this->getFlagList();
return implode(',', array_intersect_key($list, array_flip($valueArr)));
}
/**
* 读取分类列表
* @param string $type 指定类型
* @param string $status 指定状态
* @return array
*/
public static function getCategoryArray($type = null, $status = null)
{
$list = collection(self::where(function ($query) use ($type, $status) {
if (!is_null($type)) {
$query->where('type', '=', $type);
}
if (!is_null($status)) {
$query->where('status', '=', $status);
}
})->order('weigh', 'desc')->select())->toArray();
return $list;
}
}

View File

@@ -0,0 +1,227 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 配置模型
*/
class Config extends Model
{
// 表名,不含前缀
protected $name = 'config';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
'extend_html'
];
protected $type = [
'setting' => 'json',
];
/**
* 读取配置类型
* @return array
*/
public static function getTypeList()
{
$typeList = [
'string' => __('String'),
'password' => __('Password'),
'text' => __('Text'),
'editor' => __('Editor'),
'number' => __('Number'),
'date' => __('Date'),
'time' => __('Time'),
'datetime' => __('Datetime'),
'datetimerange' => __('Datetimerange'),
'select' => __('Select'),
'selects' => __('Selects'),
'image' => __('Image'),
'images' => __('Images'),
'file' => __('File'),
'files' => __('Files'),
'switch' => __('Switch'),
'checkbox' => __('Checkbox'),
'radio' => __('Radio'),
'city' => __('City'),
'selectpage' => __('Selectpage'),
'selectpages' => __('Selectpages'),
'array' => __('Array'),
'custom' => __('Custom'),
];
return $typeList;
}
public static function getRegexList()
{
$regexList = [
'required' => '必选',
'digits' => '数字',
'letters' => '字母',
'date' => '日期',
'time' => '时间',
'email' => '邮箱',
'url' => '网址',
'qq' => 'QQ号',
'IDcard' => '身份证',
'tel' => '座机电话',
'mobile' => '手机号',
'zipcode' => '邮编',
'chinese' => '中文',
'username' => '用户名',
'password' => '密码'
];
return $regexList;
}
public function getExtendHtmlAttr($value, $data)
{
$result = preg_replace_callback("/\{([a-zA-Z]+)\}/", function ($matches) use ($data) {
if (isset($data[$matches[1]])) {
return $data[$matches[1]];
}
}, $data['extend']);
return $result;
}
/**
* 读取分类分组列表
* @return array
*/
public static function getGroupList()
{
$groupList = config('site.configgroup');
foreach ($groupList as $k => &$v) {
$v = __($v);
}
return $groupList;
}
public static function getArrayData($data)
{
if (!isset($data['value'])) {
$result = [];
foreach ($data as $index => $datum) {
$result['field'][$index] = $datum['key'];
$result['value'][$index] = $datum['value'];
}
$data = $result;
}
$fieldarr = $valuearr = [];
$field = $data['field'] ?? ($data['key'] ?? []);
$value = $data['value'] ?? [];
foreach ($field as $m => $n) {
if ($n != '') {
$fieldarr[] = $field[$m];
$valuearr[] = $value[$m];
}
}
return $fieldarr ? array_combine($fieldarr, $valuearr) : [];
}
/**
* 将字符串解析成键值数组
* @param string $text
* @return array
*/
public static function decode($text, $split = "\r\n")
{
$content = explode($split, $text);
$arr = [];
foreach ($content as $k => $v) {
if (stripos($v, "|") !== false) {
$item = explode('|', $v);
$arr[$item[0]] = $item[1];
}
}
return $arr;
}
/**
* 将键值数组转换为字符串
* @param array $array
* @return string
*/
public static function encode($array, $split = "\r\n")
{
$content = '';
if ($array && is_array($array)) {
$arr = [];
foreach ($array as $k => $v) {
$arr[] = "{$k}|{$v}";
}
$content = implode($split, $arr);
}
return $content;
}
/**
* 本地上传配置信息
* @return array
*/
public static function upload()
{
$uploadcfg = config('upload');
$uploadurl = request()->module() ? $uploadcfg['uploadurl'] : ($uploadcfg['uploadurl'] === 'ajax/upload' ? 'index/' . $uploadcfg['uploadurl'] : $uploadcfg['uploadurl']);
if (!preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $uploadurl) && substr($uploadurl, 0, 1) !== '/') {
$uploadurl = url($uploadurl, '', false);
}
$uploadcfg['fullmode'] = isset($uploadcfg['fullmode']) && $uploadcfg['fullmode'];
$uploadcfg['thumbstyle'] = $uploadcfg['thumbstyle'] ?? '';
$upload = [
'cdnurl' => $uploadcfg['cdnurl'],
'uploadurl' => $uploadurl,
'bucket' => 'local',
'maxsize' => $uploadcfg['maxsize'],
'mimetype' => $uploadcfg['mimetype'],
'chunking' => $uploadcfg['chunking'],
'chunksize' => $uploadcfg['chunksize'],
'savekey' => $uploadcfg['savekey'],
'multipart' => [],
'multiple' => $uploadcfg['multiple'],
'fullmode' => $uploadcfg['fullmode'],
'thumbstyle' => $uploadcfg['thumbstyle'],
'storage' => 'local'
];
return $upload;
}
/**
* 刷新配置文件
*/
public static function refreshFile()
{
//如果没有配置权限无法进行修改
if (!\app\admin\library\Auth::instance()->check('general/config/edit')) {
return false;
}
$config = [];
$configList = self::all();
foreach ($configList as $k => $v) {
$value = $v->toArray();
if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) {
$value['value'] = explode(',', $value['value']);
}
if ($value['type'] == 'array') {
$value['value'] = (array)json_decode($value['value'], true);
}
$config[$value['name']] = $value['value'];
}
file_put_contents(
CONF_PATH . 'extra' . DS . 'site.php',
'<?php' . "\n\nreturn " . var_export_short($config) . ";\n"
);
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 邮箱验证码
*/
class Ems extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,25 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaCard extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,28 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaCardLog extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
public function junkacard()
{
return $this->hasMany('junkaCard', 'card_log_id', 'id');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaCode extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaList extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaPurchcardLog extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 退货
*/
class JunkaReject extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaStore extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 购卡记录
*/
class JunkaStoreMoneyLog extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 会员余额日志模型
*/
class MoneyLog extends Model
{
// 表名
protected $name = 'user_money_log';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = '';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,314 @@
<?php
namespace app\common\model;
use app\admin\model\JunkaCardlock;
use app\admin\model\JunkaCardunlock;
use app\api\model\JunkaCardLog;
use app\api\model\JunkaList;
use fast\Http;
use fast\Random;
use think\Db;
use think\Exception;
use think\Log;
use think\Model;
/**
* 订单模型
*/
class Order extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 获取卡种类
protected $get_junka_type_url = 'http://Service.800j.com/UCard/UCardKindList.aspx';
// 购卡接口
protected $get_junka_url = 'http://Service.800j.com/UCard/UCardFetchSubmit.aspx';
// 锁卡/解锁
protected $cardlock_url = 'http://Service.800j.com/UCard/UCardLock.aspx';
// 接口签名key
protected $junka_key = '4FC3D043CBE3';
// 加密密钥
protected $junka_secret_key = '90B85D57A29043AFA5F9618A';
/**
* 骏卡获取卡种类
*/
public function getjunkatype()
{
$agent_id = config('junka.agent_id');
$data = Http::get($this->get_junka_type_url, ['agent_id' => $agent_id]);
p($data);
}
/**
* 购卡
* @param array $params 参数
* @param int $store_id 商户
* @param int $is_z 1 直购
*/
public function getjunka($params, $store, $is_z = true, $codelist, $price)
{
$junka_list = JunkaList::where(['id' => 1])->find();
try {
Db::startTrans();
$params['admin_id'] = $store->admin_id;
$log_arr = array_merge($params, ['price' => $price, 'store_id' => $store->id]);
$junka = JunkaCardLog::create($log_arr);
unset($params['admin_id']);
$params['card_kind'] = $junka_list->junka_id;
$params['time_stamp'] = date('YmdHis');
$params['sign'] = $this->getsign($params);
if(empty($params['is_dynamic']) && !empty($params['product_code'])) {
$params['card_price'] = $codelist->par_value;
}
$junka->card_price = $params['card_price'];
$data = Http::get($this->get_junka_url, $params);
// $data = 'ret_code=0&ret_msg=<3D><EFBFBD>ɹ<EFBFBD>&agent_id=2193854&bill_id=61961621651265961&jnet_bill_no=P240119247419915&par_price=10.000&purchase_amt=20.000&card_no_data=584ABBCD815FCD8D9734779E7906A9761FF7AAE142E458E732C9D944F69023124070E666834731BD809081BFCA3CF93391EA1B394A14D2B2C931CD7D46D4AA81B1513617D29D237567B29D79DC9119351D4B3ADBC8523570705600099C018AFC2AB7D35B1B5BCE87CD7C8032230A51C9&ext_param=&sign=d6744a50ea926ff304b25b0d6b71576f';
Log::write($data);
$res = $this->returnparamssave($data);
$junka_card = [];
// 购买成功
if($res['ret_code'] == 0) {
$junka->status = 1;
$junka_data = $this->decry($res['card_no_data']);
foreach ($junka_data as $k => $v) {
$junka_data = explode(',', $v);
$junka_card[] = [
'card_number' => $junka_data[0], // 卡号
'card_password' => $junka_data[1], // 卡密
'expiration_time' => $junka_data[2], // 过期时间
'card_log_id' => $junka->id,
'product_code' => $params['product_code'],
'store_id' => $store->id,
'card_price' => $params['card_price'],
'price' => $price,
'status' => 2,
'admin_id' => $store->admin_id,
'card_list_id' => $junka_list->id,
'card_list_name' => $junka_list->junka_name,
];
}
if($junka_card) {
// 加入库存后锁卡
$this->addkc($junka_card);
// 如果不是直接购买,则需要锁卡
if($is_z == false) {
// 锁卡
// $this->cardlock($junka_card);
}
}
}else {
$junka->error_msg = $res['ret_code'] . '-' . $res['ret_msg'];
$this->error = $res['ret_code'] . '-' . $res['ret_msg'];
$junka->save();
Db::commit();
return false;
}
$junka->save();
Db::commit();
return $junka_card;
}catch (Exception $e) {
Log::write('购卡错误---' . $e);
Db::rollback();
}
}
/**
* 解密
*/
public function decry($data)
{
$encrypted = hex2bin($data);//十六进制字符串转为加密前参数
$decrypted = openssl_decrypt($encrypted, 'des-ede3', $this->junka_secret_key, OPENSSL_RAW_DATA);
// 将解密结果转换为中文 GBK 格式
$decrypted = iconv('GBK', 'UTF-8', $decrypted);
$junka_data = explode('|', $decrypted);
return $junka_data;
}
/**
* 加密
*/
public function getsign($params)
{
$string = http_build_query($params) . '|||' . $this->junka_key;
return md5($string);
}
/**
* 卡锁定
*/
public function cardlock($card, $bill_id = 0)
{
$msg = '';
$money_save_card = [];
foreach ($card as $k => $v) {
$get_arr = [
'agent_id' => config('junka.agent_id'),
'account_type' => 2,
'card_no' => $v['card_number'],
'card_par_amt' => $v['card_price'],
'card_style' => 1,
'lock_type' => 1, // 锁卡
'time_stamp' => date('YmdHis'),
];
$get_arr['sign'] = $this->getsign($get_arr);
$res = Http::get($this->cardlock_url, $get_arr);
$res = $this->returnparamssave($res);
$msg .= '【' .$res['ret_msg'] . '】';;
if($res['ret_code'] == 0) { // 锁定成功
$end_time = (Config::get(['name' => 'card_expire_time'])->value * 24 * 3600) + time();
\app\api\model\JunkaCard::where(['card_number' => $v['card_number']])->update(['status' => 3, 'status_notes' => $res['ret_msg'], 'end_time' => $end_time]);
$money_save_card[] = $v['card_number'];
if($bill_id) {
// 改状态
\app\admin\model\JunkaPurchcardLog::where(['bill_id' => $bill_id])->update(['status' => 5]);
}
}else {
if($res['ret_msg'] == '该卡已被锁定') {
\app\api\model\JunkaCard::where(['card_number' => $v['card_number']])->update(['status' => 3, 'status_notes' => $res['ret_msg']]);
}else {
\app\api\model\JunkaCard::where(['card_number' => $v['card_number']])->update(['status' => 4, 'status_notes' => $res['ret_msg']]);
}
}
// 锁卡记录
JunkaCardlock::create([
'bill_id' => $bill_id,
'card_number' => $v['card_number'],
'ret_code' => $res['ret_code'],
'ret_msg' => $res['ret_msg'],
]);
}
return ['msg' => $msg, 'money_save_card' => $money_save_card];
}
/**
* 卡解锁
*/
public function jx($card, $bill_id = 0)
{
$msg = '';
$money_save_card = [];
$is_j = false;
foreach ($card as $k => $v) {
$get_arr = [
'agent_id' => config('junka.agent_id'),
'account_type' => 2,
'card_no' => $v['card_number'],
'card_par_amt' => $v['card_price'],
'card_style' => 1,
'lock_type' => 2, // 解锁
'time_stamp' => date('YmdHis'),
];
$get_arr['sign'] = $this->getsign($get_arr);
$res = Http::get($this->cardlock_url, $get_arr);
$res = $this->returnparamssave($res);
$msg .= '【' .$res['ret_msg'] . '】';
if($res['ret_code'] == 0) { // 解锁
$money_save_card[] = $v['card_number'];
\app\api\model\JunkaCard::where(['card_number' => $v['card_number']])->update(['status' => 1, 'status_notes' => $res['ret_msg']]);
$is_j = true;
}
// 解锁记录
JunkaCardunlock::create([
'bill_id' => $bill_id,
'card_number' => $v['card_number'],
'ret_code' => $res['ret_code'],
'ret_msg' => $res['ret_msg'],
]);
}
if($is_j) {
if($bill_id) {
// 改状态
$log = \app\admin\model\JunkaPurchcardLog::where(['bill_id' => $bill_id])->find();
if($log) {
$log->status = 1;
$log->save();
}
}else {
$log = \app\admin\model\JunkaPurchcardLog::where('data', 'like', '%' . $card[0]['card_number'] . '%')->select();
if($log) {
foreach ($log as $k => $v) {
if($v->status == 5) {
$v->status = 1;
$v->save();
}
}
}
}
}
return ['msg' => $msg, 'money_save_card' => $money_save_card];
}
/**
* 卡解锁
*/
public function cardunlock($card, $status = 1)
{
$get_arr = [
'agent_id' => config('junka.agent_id'),
'account_type' => 2,
'card_no' => $card->card_number,
'card_par_amt' => $card->card_price,
'card_style' => 1,
'lock_type' => 2, // 解锁
'time_stamp' => date('YmdHis'),
];
$get_arr['sign'] = $this->getsign($get_arr);
$res = Http::get($this->cardlock_url, $get_arr);
$res = $this->returnparamssave($res);
$card->status_notes = $res['ret_msg'];
if($res['ret_code'] == 0) { // 解锁
$card->status = $status;
}
$card->save();
return $res;
}
/**
* 加入库存
*/
public function addkc($data)
{
$card = new \app\api\model\JunkaCard;
return $card->saveAll($data);
}
/**
* 处理返回参数
*/
public function returnparamssave($data)
{
$data = iconv("gbk", "utf-8", $data);
$res_data = explode('&', $data);
$res = [];
foreach ($res_data as $k => $v) {
$n_res = explode('=', $v);
$res[$n_res[0]] = $n_res[1];
}
return $res;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 会员积分日志模型
*/
class ScoreLog extends Model
{
// 表名
protected $name = 'user_score_log';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = '';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 短信验证码
*/
class Sms extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,151 @@
<?php
namespace app\common\model;
use think\Db;
use think\Model;
/**
* 会员模型
*/
class User extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'url',
];
/**
* 获取个人URL
* @param string $value
* @param array $data
* @return string
*/
public function getUrlAttr($value, $data)
{
return "/u/" . $data['id'];
}
/**
* 获取头像
* @param string $value
* @param array $data
* @return string
*/
public function getAvatarAttr($value, $data)
{
if (!$value) {
//如果不需要启用首字母头像,请使用
//$value = '/assets/img/avatar.png';
$value = letter_avatar($data['nickname']);
}
return $value;
}
/**
* 获取会员的组别
*/
public function getGroupAttr($value, $data)
{
return UserGroup::get($data['group_id']);
}
/**
* 获取验证字段数组值
* @param string $value
* @param array $data
* @return object
*/
public function getVerificationAttr($value, $data)
{
$value = array_filter((array)json_decode($value, true));
$value = array_merge(['email' => 0, 'mobile' => 0], $value);
return (object)$value;
}
/**
* 设置验证字段
* @param mixed $value
* @return string
*/
public function setVerificationAttr($value)
{
$value = is_object($value) || is_array($value) ? json_encode($value) : $value;
return $value;
}
/**
* 变更会员余额
* @param int $money 余额
* @param int $user_id 会员ID
* @param string $memo 备注
*/
public static function money($money, $user_id, $memo)
{
Db::startTrans();
try {
$user = self::lock(true)->find($user_id);
if ($user && $money != 0) {
$before = $user->money;
//$after = $user->money + $money;
$after = function_exists('bcadd') ? bcadd($user->money, $money, 2) : $user->money + $money;
//更新会员信息
$user->save(['money' => $after]);
//写入日志
MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => $memo]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
/**
* 变更会员积分
* @param int $score 积分
* @param int $user_id 会员ID
* @param string $memo 备注
*/
public static function score($score, $user_id, $memo)
{
Db::startTrans();
try {
$user = self::lock(true)->find($user_id);
if ($user && $score != 0) {
$before = $user->score;
$after = $user->score + $score;
$level = self::nextlevel($after);
//更新会员信息
$user->save(['score' => $after, 'level' => $level]);
//写入日志
ScoreLog::create(['user_id' => $user_id, 'score' => $score, 'before' => $before, 'after' => $after, 'memo' => $memo]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
/**
* 根据积分获取等级
* @param int $score 积分
* @return int
*/
public static function nextlevel($score = 0)
{
$lv = array(1 => 0, 2 => 30, 3 => 100, 4 => 500, 5 => 1000, 6 => 2000, 7 => 3000, 8 => 5000, 9 => 8000, 10 => 10000);
$level = 1;
foreach ($lv as $key => $value) {
if ($score >= $value) {
$level = $key;
}
}
return $level;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
class UserGroup extends Model
{
// 表名
protected $name = 'user_group';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
class UserRule extends Model
{
// 表名
protected $name = 'user_rule';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,50 @@
<?php
namespace app\common\model;
use think\Model;
class Version extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 定义字段类型
protected $type = [
];
/**
* 检测版本号
*
* @param string $version 客户端版本号
* @return array
*/
public static function check($version)
{
$versionlist = self::where('status', 'normal')->cache('__version__')->order('weigh desc,id desc')->select();
foreach ($versionlist as $k => $v) {
// 版本正常且新版本号不等于验证的版本号且找到匹配的旧版本
if ($v['status'] == 'normal' && $v['newversion'] !== $version && \fast\Version::check($version, $v['oldversion'])) {
$updateversion = $v;
break;
}
}
if (isset($updateversion)) {
$search = ['{version}', '{newversion}', '{downloadurl}', '{url}', '{packagesize}'];
$replace = [$version, $updateversion['newversion'], $updateversion['downloadurl'], $updateversion['downloadurl'], $updateversion['packagesize']];
$upgradetext = str_replace($search, $replace, $updateversion['content']);
return [
"enforce" => $updateversion['enforce'],
"version" => $version,
"newversion" => $updateversion['newversion'],
"downloadurl" => $updateversion['downloadurl'],
"packagesize" => $updateversion['packagesize'],
"upgradetext" => $upgradetext
];
}
return null;
}
}