初始化项目:添加后端代码、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
@@ -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);
}
}