初始化项目:添加后端代码、ThinkPHP框架、前端资源

This commit is contained in:
amb
2026-09-03 12:42:39 +08:00
commit 482bece22e
3726 changed files with 416708 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
<?php
namespace app\common\model\app;
use think\Model;
use think\Cache;
/**
* 配置模型
*/
class Config extends Model
{
// 表名,不含前缀
protected $name = 'app_config';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 获取配置
* @param $name
* @return mixed
*/
public static function getConfig($name){
$cacheConfig = Cache::get(\app\common\constant\cache\Keys::APP_CONFIG.$name);
if($cacheConfig){
return $cacheConfig;
}
$config = self::where(['name'=>$name])->find();
if(!$config){
$configFilePath = APP_PATH . 'common/model/fill/data/app_config.php';
$config = require($configFilePath);
if($config){
foreach ($config as $item){
if($item['name'] == $name){
Cache::set(\app\common\constant\cache\Keys::APP_CONFIG.$name,json_decode($item['value'],true));
return json_decode($item['value'],true);
}
}
}
Cache::set(\app\common\constant\cache\Keys::APP_CONFIG.$name,\app\common\model\app\ConfigDefault::$agent);
//获取默认配置
return \app\common\model\app\ConfigDefault::$agent;
}else{
Cache::set(\app\common\constant\cache\Keys::APP_CONFIG.$name,json_decode($config['value'],true));
return json_decode($config['value'],true);
}
}
/**
* 设置配置
* @param $name
* @param $value
* @return bool
*/
public static function setConfig($name,$value){
$config = self::where([
'name'=>$name
])->find();
$value = json_encode($value,true);
if(!$config){
self::insert([
'name'=>$name,
'uniacid'=>UNIACID,
'createtime'=>time(),
'value'=>$value
]);
}else{
self::where([
'name'=>$name
])->cache(\app\common\constant\cache\Keys::APP_CONFIG.$name)->update([
'value'=>$value
]);
}
return true;
}
}
@@ -0,0 +1,21 @@
<?php
namespace app\common\model\app;
use think\Model;
/**
* 默认配置
*/
class ConfigDefault extends Model
{
public static $agent = [
];
public static $goodsProp = [
'status'=>1,
'mode'=>1,
'prop_rule'=>[]
];
}
@@ -0,0 +1,21 @@
<?php
namespace app\common\model\app\activity;
use think\Model;
/**
* 线下活动
*/
class Activity extends Model
{
// 表名,不含前缀
protected $name = 'app_activity';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
}
@@ -0,0 +1,21 @@
<?php
namespace app\common\model\app\activity;
use think\Model;
/**
* 线下活动
*/
class Ticket extends Model
{
// 表名,不含前缀
protected $name = 'app_activity_ticket';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
}
@@ -0,0 +1,218 @@
<?php
namespace app\common\model\app\agent;
use think\Model;
/**
* 分销商品
*/
class Goods extends Model
{
// 表名,不含前缀
protected $name = 'app_agent_goods';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 获取商品分佣比例
* @param $goodsId
* @return array
*/
public static function getGoodsAllProp($goodsId,$goodsType)
{
if($goodsType == 'vipcard'){
$cardInfo = explode("_",$goodsId);
$goodsId = $cardInfo[0];
}
$detail = self::where([
'goods_id'=>$goodsId,
'goods_type'=>$goodsType
])->find();
if(!$detail){
//默认配置
$detail = \app\common\model\app\ConfigDefault::$goodsProp;
}else{
$detail = $detail->toArray();
$detail['prop_rule'] = json_decode($detail['prop_rule'],true);
}
$systemConfig = \app\common\model\app\Config::getConfig('agent');
$systemConfig['levelPlan'] = \app\common\model\app\agent\Level::getLevelList();
$systemProportion = self::getSystemProportion();
$data = [
'config'=>$systemConfig,
'goods'=>$detail,
'system'=>$systemProportion,
'merge'=>self::propMerge($systemProportion,$detail['prop_rule'])
];
return $data;
}
/**
* 获取格式化后的商品分佣金比例
* @return void
*/
public static function getGoodsProp($goodsId,$goodsType){
$prop = self::getGoodsAllProp($goodsId,$goodsType);
if(!isset($prop['goods']) ||$prop['goods']['status'] !=1){
return false;
}
switch ($prop['goods']['mode']){
case 1:
$list = $prop['system'];
break;
case 2:
$list = [];
foreach ($prop['merge'] as $index => $item){
$list[$index] = $item['proportion'];
}
break;
case 3:
$list = [];
foreach ($prop['merge'] as $index => $item){
$list[$index] = $item['price'];
}
break;
}
if(!$list){
return false;
}
$data = [
'mode'=>$prop['goods']['mode'],
'list'=>$list
];
return $data;
}
/**
* 获取指定用户对应的商品佣金
* @param $userId 用户ID
* @param $goodsId 商品ID
* @return array|false
*/
public static function getUserGoodsProp($userId,$goodsId,$goodsType,$price){
$levelModel = new \app\api\model\app\agent\Level();
$userLevel = $levelModel->getUserLevel($userId);
if(!$userLevel){
return false;
}
$goodsProp = self::getGoodsProp($goodsId,$goodsType);
if(!$goodsProp){
return false;
}
$userLevelId = isset($userLevel['id']) && !empty($userLevel['id']) ? $userLevel['id'] :'0';
//要考虑用户等级没有匹配的问题
$prop = isset($goodsProp['list'][$userLevelId]) ? $goodsProp['list'][$userLevelId] : $goodsProp['list'][0];
$data = [
'mode'=>$goodsProp['mode'],//分佣模式
'prop'=>$prop
];
if($goodsProp['mode'] == 3){
$data['price'] = $prop;
}else{
$data['price'] = self::propToPrice($goodsId,$goodsType,$prop,$price);
}
if(!$data['price']){
return false;
}
return $data;
}
/**
* 通过比例计算商品佣金金额
* @return void
*/
public static function propToPrice($goodsId,$goodsType,$prop,$price=0){
if(!$price){
$goodsDetail = \app\common\model\goods\Handle::getGoodsDetail($goodsId,$goodsType);
if (!$goodsDetail || $goodsDetail['status'] != 1 || $goodsDetail['pay_type'] != 'pay') {
$price = 0;
}else{
$price = $goodsDetail['price'];
}
}
foreach ($prop as &$item){
$item = $item ? $item : 0;
$item = number_format($price * $item / 100, 2, '.', '');
}
return $prop;
}
/**
* 获取系统的分佣比例
* @return array
*/
public static function getSystemProportion(){
$config = \app\common\model\app\Config::getConfig('agent');
$list = [];
foreach ($config['levelPlan'] as $item){
$id = isset($item['id']) && !empty($item['id']) ? $item['id'] : '0';
$list[$id] = $item['proportion'];
}
return $list;
}
/**
* 合并分销比例配置
* @param $system
* @param $goods
* @return void
*/
public static function propMerge($system,$goods){
$list = [];
foreach ($system as $index => $item){
$temp = [];
if(isset($goods[$index])){
$temp = $goods[$index];
}else{
$temp['proportion'] = $item;
}
if(!isset($temp['price'])){
//这里最好可以获取商品价格 再计算金额
$temp['price'] = [
'customer'=>'0',
'goods'=>'0',
];
}
$list[$index] = $temp;
}
return $list;
}
}
@@ -0,0 +1,53 @@
<?php
namespace app\common\model\app\agent;
use think\Model;
/**
* 等级
*/
class Level extends Model
{
/**
* 获取等级列表
* @return array
*/
public static function getLevelList(){
$data = \app\common\model\app\Config::getConfig('agent');
$list = [];
if(!empty($data['levelPlan'])){
foreach ($data['levelPlan'] as $item){
$id = isset($item['id']) && !empty($item['id']) ? $item['id'] : '0';
$list[$id] = $item;
}
}
return $list;
}
/**
* 删除level配置后重置受影响的用户等级
* @return void
*/
public static function delLevelConfigReset()
{
$levelList = self::getLevelList();
$newLevel = end($levelList);
if($newLevel){
$newLevelId = isset($newLevel['id']) ? $newLevel['id'] : 0;
\app\admin\model\app\agent\Member::where([
'level'=>['>',$newLevelId]
])->update([
'level'=>$newLevelId
]);
return true;
}
return false;
}
}
@@ -0,0 +1,87 @@
<?php
namespace app\common\model\app\agent;
use think\Model;
/**
* 推销员
*/
class Member extends Model
{
// 表名,不含前缀
protected $name = 'app_agent_member';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
public function getMember($userId){
$data = self::where([
'user_id'=>$userId
])->find();
if(!$data){
return false;
}
return $data;
}
/**
* 获取申请状态
* @param $userId
* @return int 1 已通过 2申请中 3拒绝 4 没有记录
*/
public function getAuditStatus($userId){
$memberData = $this->getMember($userId);
if(!$memberData){
$code = 4;
}else{
$code = $memberData['audit'];
}
return $code;
}
/**
* 获取用户交易信息统计
* @param $userId
* @return void
*/
public function getMemberStatistics($userId){
$orderModel = new \app\api\model\app\agent\Order();
$data = [
'order'=>[],
'customer'=>[]
];
$data['order']['total'] = $orderModel->getTotal($userId);
$data['order']['today'] = $orderModel->getTotal($userId,'',[
'start'=>strtotime(date('Y-m-d').'00:00:00'),
'end'=>strtotime(date('Y-m-d').'23:59:59')
]);
$relationModel = new \app\api\model\app\agent\Relation();
$data['customer']['total'] = $relationModel->getUserTotal($userId);
$data['customer']['today'] = $relationModel->getUserTotal($userId,'',[
'start'=>strtotime(date('Y-m-d').'00:00:00'),
'end'=>strtotime(date('Y-m-d').'23:59:59')
]);
return $data;
}
}
@@ -0,0 +1,23 @@
<?php
namespace app\common\model\app\agent;
use think\Model;
/**
* 分销订单
*/
class Order extends Model
{
// 表名,不含前缀
protected $name = 'app_agent_order';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
}
@@ -0,0 +1,45 @@
<?php
namespace app\common\model\app\agent;
use think\Model;
/**
* 分销员申请
*/
class Recruit extends Model
{
/**
* 检查加入条件
* @return void
*/
public function checkCondition($userId){
$config = \app\common\model\app\Config::getConfig('agent');
//无条件加入
if($config['member_recruit_condition'] == 0){
return true;
}
if($config['member_recruit_condition_payprice_status']==1 || $config['member_recruit_condition_paycount_value']==1){
$total = (new \app\admin\model\order\Order())->getTransactionStatistic($userId);
if(!$total){
return false;
}
if($config['member_recruit_condition_payprice_status']==1 && $total['pay_price'] < $config['member_recruit_condition_payprice_value']){
//自购金额满n元
return false;
}
if($config['member_recruit_condition_paycount_status']==1 && $total['pay_count'] < $config['member_recruit_condition_paycount_value']){
//消费笔数满n笔
return false;
}
}
return true;
}
}
@@ -0,0 +1,103 @@
<?php
namespace app\common\model\app\agent;
use think\Model;
/**
* 分销关系
*/
class Relation extends Model
{
// 表名,不含前缀
protected $name = 'app_agent_relation';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 获取用户的分销关系
* @param $user
* @return void
*/
public static function getUserRelation($userId){
$relation = [
'parent'=>false,//父
'grandpa'=>false//爷
];
$relation['parent'] = self::getParentUser($userId);
if($relation['parent']){
$relation['grandpa'] = self::getParentUser($relation['parent']['parent_id']);
}
return $relation;
}
/**
* 获取上级用户详情
* @param $userId
* @return false
*/
public static function getParentUser($userId){
$data = self::with(['parentUser','member'])->where([
'relation.user_id'=>$userId,
'relation.status'=>1
])->find();
if($data){
return $data->toArray();
}
return false;
}
/**
* 绑定上级
* @param $userId
* @param $parentId
* @return bool
*/
public static function bindParant($userId,$parentId){
$isBind = self::where([
'user_id'=>$userId
])->find();
if($isBind){
return false;
}
$parentInfo = \app\common\model\User::getUserInfo($parentId);
if(!$parentInfo){
return false;
}
self::insert([
'uniacid'=>UNIACID,
'parent_id'=>$parentId,
'user_id'=>$userId,
'createtime'=>time(),
'status'=>1
]);
//检查升级
(new \app\api\model\app\agent\Level())->handle($parentId);
return true;
}
public function parentUser()
{
return $this->belongsTo('app\common\model\User', 'parent_id', 'id', [], 'right')->setEagerlyType(0);
}
public function member()
{
return $this->belongsTo('app\common\model\app\agent\Member', 'parent_id', 'user_id', [], 'right')->setEagerlyType(0);
}
}
@@ -0,0 +1,28 @@
<?php
namespace app\common\model\app\exam;
use think\Model;
/**
* 题库练习
*/
class Exercises extends Model
{
// 表名,不含前缀
protected $name = 'app_exam_exercises';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
public static function subscribe($userId,$exercisesId){
}
public static function checkSubscribe($userId,$exercisesId){
}
}
@@ -0,0 +1,53 @@
<?php
namespace app\common\model\app\exam;
use think\Model;
use app\common\model\app\exam\WarehouseGroup;
class ExercisesBindWarehouseGroup extends Model
{
// 表名
protected $name = 'app_exam_exercises_bind_warehouse_group';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
/**
* 获取练习绑定的题库分组
* @param $exercisesId
* @return mixed
*/
public static function getExercisesBindWarehouseGroupIds($exercisesId){
return self::where([
'exercises_id'=>$exercisesId
])->field('warehouse_group_id')->column('warehouse_group_id');
}
/**
* 获取没有被练习绑定的分组ID
* 为什么要查这个?
* 当分组被删除时,绑定被删除的分组的题目的分组ID未变更,
* 当练习绑定了未分组的题目集合是,仅搜索分组为0的数据查不到上面情景的题目,故获取该类型的分组ID进行not in 反查询
* @return void
*/
public static function getNotInExercisesGroupIds($exercisesId){
$bindIds = self::getExercisesBindWarehouseGroupIds($exercisesId);
return WarehouseGroup::where([
'id'=>['not in',$bindIds]
])->field('id')->column('id');
}
}
@@ -0,0 +1,176 @@
<?php
namespace app\common\model\app\exam;
use think\Model;
use app\common\model\app\exam\Exercises;
use app\common\model\app\exam\WarehouseQuestion;
use app\common\model\app\exam\ExercisesBindWarehouseGroup;
/**
* 题库练习记录
*/
class ExercisesLog extends Model
{
// 表名,不含前缀
protected $name = 'app_exam_exercises_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 出题
* @return void
*/
public function buildLog($userId,$exercisesId)
{
//获取出题配置
$exercisesInfo = Exercises::where([
'exercises_id'=>$exercisesId,
'stutus'=>1
])->find();
if(!$exercisesInfo){
return false;
}
$questionIds = $this->getQuestionIds($userId,$exercisesId,$exercisesInfo['question_mode'],$exercisesInfo['question_count']);
if(!$questionIds){
return false;
}
$logId = self::insertGetId([
'user_id'=>$userId,
'uniacid'=>UNIACID,
'exercises_id'=>$exercisesId,
'question_ids'=>implode(",",$questionIds),
'data_index'=>'',
'question_count'=>count($questionIds),
'result_true_count'=>0,
'createtime'=>time()
]);
if(!$logId){
return false;
}
return $logId;
}
public function getQuestionList($userId,$exercisesId){
//获取出题配置
$exercisesInfo = Exercises::where([
'id'=>$exercisesId,
'status'=>1
])->find();
if(!$exercisesInfo){
return false;
}
$questionIds = $this->getQuestionIds($userId,$exercisesId,$exercisesInfo['question_mode'],$exercisesInfo['question_count']);
if(!$questionIds){
return false;
}
$questionList = WarehouseQuestion::where([
'id'=>['in',$questionIds]
])->select();
if(!$questionList){
return false;
}
foreach ($questionList as &$item){
$item->option = json_decode($item->option,true);
switch ($item['type']){
case 'multiple':
case 'indefinite':
$item->answer = explode(",",$item->answer);
break;
case 'fillblank':
$item->answer = json_decode($item->answer,true);
break;
case 'essay':
// 问答题答案为富文本字符串,保持原样
break;
default:
$item->answer = intval($item->answer);
}
}
return $questionList;
}
public function getQuestionIds($userId,$exercisesId,$mode,$count){
if($mode == 'random'){
$questionIds = $this->getRandomQuestion($exercisesId,$count);
}else{
// 判断是否已经过题了
$exercisesLog = self::where([
'exercises_id'=>$exercisesId,
'user_id'=>$userId
])->order('createtime','desc')->find();
$dataIndex = 0;
if($exercisesLog){
$dataIndex = $exercisesLog['index'];
}
$questionIds = $this->getSortQuestion($exercisesId,$dataIndex,$count);
}
if(!$questionIds){
return false;
}
shuffle($questionIds);
return $questionIds;
}
/**
* 随机出题
* @return void
*/
public function getRandomQuestion($exercisesId,$count){
$groupIds = ExercisesBindWarehouseGroup::getNotInExercisesGroupIds($exercisesId);
if(!$groupIds){
return false;
}
$questionIds = WarehouseQuestion::where(['group_id'=>['not in',$groupIds]])->orderRaw('rand()')->limit($count)->field('id')->column('id');
if(!$questionIds){
return false;
}
return $questionIds;
}
/**
* 顺序出题
* @param $exercisesId 练习
* @param $dataIndex 上次查询的下标
* @param $count 获取数量
* @return void
*/
public function getSortQuestion($exercisesId,$dataIndex,$count){
}
}
@@ -0,0 +1,97 @@
<?php
namespace app\common\model\app\exam;
use think\Model;
/**
* 题库练习订阅
*/
class ExercisesSubscribe extends Model
{
// 表名,不含前缀
protected $name = 'app_exam_exercises_subscribe';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 增加订阅
* @param $userId 用户
* @param $exercisesId 练习ID
* @param $type 订阅方式
* @return void
*/
public static function subscribe($userId,$exercisesId,$type = ''){
self::insert([
'user_id'=>$userId,
'exercises_id'=>$exercisesId,
'type'=>$type,
'createtime'=>time(),
'uniacid'=>UNIACID
]);
}
/**
* 判断是否订阅
* @param $userId
* @param $exercisesId
* @return void
*/
public static function checkSubscribe($userId,$exercisesId){
$data = self::where([
'user_id'=>$userId,
'exercises_id'=>$exercisesId
])->find();
if($data){
return true;
}
return false;
}
/**
* 检查是否有使用权限
* @param $userId
* @param $exercisesId
* @return void
*/
public static function checkAuth($userId,$exercisesId){
$exercises = \app\common\model\app\exam\Exercises::where([
'id'=>$exercisesId,
'status'=>1
])->find();
if(!$exercises){
return false;
}
switch ($exercises['sales_type']){
case 1:
return true;
break;
case 2:
$isSubscribe = self::checkSubscribe($userId,$exercisesId);
if($isSubscribe){
return true;
}
break;
case 3:
//关联课程 判断课程订阅权限
if(\app\common\model\user\Subscription::getSubscriptionAuth($userId,$exercises['bind_course'])){
return true;
}
break;
}
return false;
}
}
@@ -0,0 +1,34 @@
<?php
namespace app\common\model\app\exam;
use think\Model;
class WarehouseGroup extends Model
{
// 表名
protected $name = 'app_exam_warehouse_group';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
/**
* 获取所有的分组ID
* @return mixed
*/
public static function getAllGroupIds(){
return self::field('id')->column('id');
}
}
@@ -0,0 +1,27 @@
<?php
namespace app\common\model\app\exam;
use think\Model;
class WarehouseQuestion extends Model
{
// 表名
protected $name = 'app_exam_warehouse_question';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
@@ -0,0 +1,74 @@
<?php
namespace app\common\model\app\physical;
use think\Model;
class Goods extends Model
{
protected $name = 'app_physical_goods';
protected $autoWriteTimestamp = 'integer';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
protected $append = [
'status_text',
'spec_type_text'
];
public function getStatusList()
{
return [1 => '上架', 0 => '下架'];
}
public function getSpecTypeList()
{
return ['single' => '单规格', 'multi' => '多规格'];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getSpecTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['spec_type']) ? $data['spec_type'] : '');
$list = $this->getSpecTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getCarouselAttr($value, $data)
{
$value = $value ? $value : (isset($data['carousel']) ? $data['carousel'] : '');
if (empty($value)) {
return [];
}
$carousel = json_decode($value, true);
return is_array($carousel) ? $carousel : [];
}
public function getParamsAttr($value, $data)
{
$value = $value ? $value : (isset($data['params']) ? $data['params'] : '');
if (empty($value)) {
return [];
}
$params = json_decode($value, true);
return is_array($params) ? $params : [];
}
public function skus()
{
return $this->hasMany('app\admin\model\app\goods\Sku', 'goods_id', 'id');
}
public function skuPrices()
{
return $this->hasMany('app\admin\model\app\goods\SkuPrice', 'goods_id', 'id');
}
}
@@ -0,0 +1,40 @@
<?php
namespace app\common\model\app\physical;
use think\Model;
/**
* 实物商品订单地址模型
*/
class OrderAddress extends Model
{
protected $name = 'app_physical_order_address';
protected $autoWriteTimestamp = 'integer';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
/**
* 根据订单ID获取地址
* @param int $orderId 订单ID
* @return array|null
*/
public static function getByOrderId($orderId)
{
$address = self::where([
'order_id' => $orderId,
'uniacid' => UNIACID
])->field([
'mobile',
'city_name',
'province_name',
'district_name',
'address',
'consignee'
])->find();
return $address ? $address->toArray() : null;
}
}
@@ -0,0 +1,73 @@
<?php
namespace app\common\model\app\physical;
use think\Model;
/**
* 实物商品快递包裹模型
*/
class OrderExpress extends Model
{
protected $name = 'app_physical_order_express';
protected $autoWriteTimestamp = 'integer';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
protected $append = ['status_text'];
/**
* 根据订单ID获取快递信息
* @param int $orderId 订单ID
* @return array|null
*/
public static function getByOrderId($orderId)
{
$express = self::where([
'order_id' => $orderId,
'uniacid' => UNIACID
])->find();
return $express ? $express->toArray() : null;
}
/**
* 获取物流轨迹
* @param int $expressId 快递包裹ID
* @return array
*/
public function getLogs()
{
$logs = OrderExpressLog::where([
'order_express_id' => $this->id,
'uniacid' => UNIACID
])->order('change_date', 'desc')
->select();
if (is_array($logs)) {
return $logs;
}
return $logs->toArray();
}
public function getStatusTextAttr($value, $data)
{
$statusList = [
'noinfo' => '暂无信息',
'collect' => '已揽件',
'transport' => '运输中',
'delivery' => '派送中',
'signfor' => '已签收',
'refuse' => '用户拒收',
'difficulty' => '问题件',
'invalid' => '无效件',
'timeout' => '超时单',
'fail' => '签收失败',
'back' => '退回'
];
return $statusList[$data['status']] ?? '';
}
}
@@ -0,0 +1,18 @@
<?php
namespace app\common\model\app\physical;
use think\Model;
/**
* 实物商品物流信息模型
*/
class OrderExpressLog extends Model
{
protected $name = 'app_physical_order_express_log';
protected $autoWriteTimestamp = 'integer';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace app\common\model\app\vip;
use think\Model;
/**
* 付费会员卡绑定会员
*/
class Card extends Model
{
// 表名,不含前缀
protected $name = 'app_vip_card';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
}
@@ -0,0 +1,130 @@
<?php
namespace app\common\model\app\vip;
use think\Model;
/**
* 付费会员卡绑定会员
*/
class CardPrivilege extends Model
{
// 表名,不含前缀
protected $name = 'app_vip_card_privilege';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 折扣权益的作用范围:all=全部课程 specify=指定课程
*/
const DISCOUNT_SCOPE_ALL = 'all';
const DISCOUNT_SCOPE_SPECIFY = 'specify';
/**
* 全部课程作用域下,仅以下课程类型享受会员卡权益
*/
const SCOPE_ALL_ALLOW_TYPES = ['article','video','audio','live','column'];
/**
* 判断商品是否在「全部课程」作用域内
* 仅 tuzhi_course 表中 article/video/audio/live/column 类型的课程视为受作用
* @param $goodsId
* @return bool
*/
public static function isCourseInScopeAll($goodsId)
{
$course = \app\common\model\course\Course::where([
'id' => $goodsId,
'uniacid' => UNIACID
])->find();
if (!$course) {
return false;
}
return in_array($course['type'], self::SCOPE_ALL_ALLOW_TYPES);
}
/**
* 获取用户对应的优惠商品折扣
* @param $userId 用户
* @param $goodsId 商品ID
* @return void
*/
public static function getPrivilegeGoodsDiscount($userId,$goodsId){
//判断会员卡状态
$vipConfig = \app\common\model\app\Config::getConfig('vip');
if($vipConfig['status'] != 1){
return false;
}
$userVipInfo = \app\common\model\app\vip\CardUser::getUserVipInfo($userId);
if(!$userVipInfo){
return false;
}
//当前会员卡是否开启了折扣权益
if (empty($userVipInfo['card']) || $userVipInfo['card']['privilege_discount'] != 1) {
return false;
}
$discountScope = isset($userVipInfo['card']['privilege_discount_scope'])
? $userVipInfo['card']['privilege_discount_scope']
: self::DISCOUNT_SCOPE_SPECIFY;
if ($discountScope == self::DISCOUNT_SCOPE_ALL) {
//全部课程作用域:仅作用于 article/video/audio/live/column 类型的课程
if (!self::isCourseInScopeAll($goodsId)) {
return false;
}
return $userVipInfo['card']['privilege_discount_val'];
}
//指定课程作用域:保持原有逻辑,需匹配权益商品 IDS
$privilegeGoodsIds = self::getPrivilegeGoodsIds($userVipInfo['card_id'],'discount');
if(!in_array($goodsId,$privilegeGoodsIds)){
return false;
}
//返回折扣
return $userVipInfo['card']['privilege_discount_val'];
}
/**
* 获取会员卡包函的权益商品IDS集合
* @param $cardId
* @param $type
* @return array
*/
public static function getPrivilegeGoodsIds($cardId,$type){
$list = self::where([
'card_id'=>$cardId,
'type'=>$type
])->field('goods_id')->select();
$ids = [];
if($list){
foreach ($list as $item){
$ids[] = $item['goods_id'];
}
}
return $ids;
}
}
@@ -0,0 +1,105 @@
<?php
namespace app\common\model\app\vip;
use think\Model;
/**
* 付费会员卡绑定会员
*/
class CardUser extends Model
{
// 表名,不含前缀
protected $name = 'app_vip_card_user';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
];
/**
* 开通会员
* @param $userId 用户
* @param $cardId 会员卡ID
* @param $time 开通时长 天数
* @return void
*/
public static function openVip($userId,$cardId,$time){
$data = self::where([
'user_id'=>$userId,
'card_id'=>$cardId,
])->find();
$time *= 86400;
if($data){
$endtime = ( $data['end_time'] > time() ? $data['end_time'] :time() ) + $time;
self::where([
'id'=>$data['id']
])->update([
'updatetime'=>time(),
'end_time'=>$endtime
]);
}else{
$endtime = time() + $time;
self::insert([
'updatetime'=>time(),
'createtime'=>time(),
'end_time'=>$endtime,
'status'=>1,
'user_id'=>$userId,
'card_id'=>$cardId,
'uniacid'=>UNIACID
]);
}
return true;
}
/**
* 获取用户VIP信息
* @param $userId
* @return void
*/
public static function getUserVipInfo($userId){
$data = self::with(['card'])->where([
'card_user.user_id'=>$userId,
'card_user.status'=>1,
// 'card.status'=>1,
'card_user.end_time'=>['>',time()]
])->order('card_user.updatetime','desc')->find();
return $data;
}
/**
* 获取用户VIP信息
* @param $userId
* @return void
*/
public static function getUserAllVipInfo($userId){
$data = self::with(['card'])->where([
'card_user.user_id'=>$userId,
'card_user.status'=>1,
// 'card.status'=>1,
'card_user.end_time'=>['>',time()]
])->order('card_user.updatetime','desc')->select();
return $data;
}
public function card()
{
return $this->belongsTo('app\api\model\app\vip\Card', 'card_id', 'id', [], 'Right')->setEagerlyType(0);
}
}