其余文件
This commit is contained in:
143
app/admin/logic/distribution/ApplyLogic.php
Normal file
143
app/admin/logic/distribution/ApplyLogic.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\logic\DistributionLogic;
|
||||
use app\common\model\distribution\Distribution;
|
||||
use app\common\model\distribution\DistributionMemberApply;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\AreaServer;
|
||||
use app\common\server\UrlServer;
|
||||
use think\facade\Db;
|
||||
|
||||
class ApplyLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @Notes: 分销申请列表
|
||||
* @Author: 张无忌
|
||||
* @param $get
|
||||
* @return array
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
try {
|
||||
$where[] = ['DMA.status', '=', $get['type'] ?? 0];
|
||||
$where[] = ['U.user_delete', '=', 0];
|
||||
if (!empty($get['keyword']) and $get['keyword']) {
|
||||
switch ($get['keyword_type']) {
|
||||
case 'sn':
|
||||
$where[] = ['U.sn', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['U.nickname', 'like', '%'.$get['keyword'].'%'];
|
||||
break;
|
||||
case 'mobile':
|
||||
$where[] = ['U.mobile', '=', $get['keyword']];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$model = new DistributionMemberApply();
|
||||
$lists = $model->field(['DMA.*'])->alias('DMA')
|
||||
->where($where)
|
||||
->with(['user.level'])
|
||||
->join('user U', 'U.id = DMA.user_id')
|
||||
->paginate([
|
||||
'page' => $get['page'],
|
||||
'list_rows' => $get['limit'],
|
||||
'var_page' => 'page'
|
||||
])->toArray();
|
||||
|
||||
foreach ($lists['data'] as &$item) {
|
||||
if ($item['user']) {
|
||||
$item['user']['avatar'] = UrlServer::getFileUrl($item['user']['avatar']);
|
||||
}
|
||||
$item['region'] = AreaServer::getAddress([
|
||||
$item['province'],
|
||||
$item['city'],
|
||||
$item['district']]
|
||||
);
|
||||
}
|
||||
|
||||
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
||||
} catch (\Exception $e) {
|
||||
return ['error'=>$e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 分销申请详细
|
||||
* @Author: 张无忌
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public static function detail($id)
|
||||
{
|
||||
$model = new DistributionMemberApply();
|
||||
$detail = $model->field(true)
|
||||
->with(['user.level'])
|
||||
->findOrEmpty($id)
|
||||
->toArray();
|
||||
|
||||
$detail['status_text'] = DistributionMemberApply::getApplyStatus($detail['status']);
|
||||
$detail['region'] = AreaServer::getAddress([
|
||||
$detail['province'],
|
||||
$detail['city'],
|
||||
$detail['district']]
|
||||
);
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Notes: 审核分销申请
|
||||
* @Author: 张无忌
|
||||
* @param $post
|
||||
* @return bool
|
||||
*/
|
||||
public static function audit($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($post['audit_status'] == 1) {
|
||||
// 审核通过
|
||||
$model = new DistributionMemberApply();
|
||||
$apply = $model->field(true)->findOrEmpty((int)$post['id'])->toArray();
|
||||
|
||||
DistributionMemberApply::update([
|
||||
'status' => $post['audit_status'],
|
||||
'denial_reason' => $post['denial_reason'] ?? '',
|
||||
'update_time' => time()
|
||||
], ['id'=>(int)$post['id']]);
|
||||
|
||||
$distribution = Distribution::where('user_id', $apply['user_id'])->findOrEmpty()->toArray();
|
||||
if (empty($distribution)) {
|
||||
// 生成分销基础信息表
|
||||
DistributionLogic::add($apply['user_id']);
|
||||
}
|
||||
// 更新分销基础信息表
|
||||
Distribution::where('user_id', $apply['user_id'])->update([
|
||||
'is_distribution' => 1,
|
||||
'distribution_time' => time()
|
||||
]);
|
||||
} else {
|
||||
// 审核拒绝
|
||||
DistributionMemberApply::update([
|
||||
'status' => $post['audit_status'],
|
||||
'denial_reason' => $post['denial_reason'] ?? '',
|
||||
'update_time' => time()
|
||||
], ['id'=>(int)$post['id']]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
static::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
143
app/admin/logic/distribution/CenterLogic.php
Normal file
143
app/admin/logic/distribution/CenterLogic.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\distribution\Distribution;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class CenterLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @notes 数据概览
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/6 14:40
|
||||
*/
|
||||
public static function center()
|
||||
{
|
||||
$data = [
|
||||
'earnings' => self::earnings(),
|
||||
'members' => self::members(),
|
||||
'topGoods' => self::topGoods(),
|
||||
'topMembers' => self::topMembers(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 佣金数据
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/6 14:46
|
||||
*/
|
||||
public static function earnings()
|
||||
{
|
||||
// 累计已入账佣金
|
||||
$totalSuccess = DistributionOrderGoods::where([
|
||||
'status' => 2,
|
||||
])->sum('money');
|
||||
// 今日已入账佣金
|
||||
$totalTodaySuccess = DistributionOrderGoods::where([
|
||||
'status' => 2,
|
||||
])->whereDay('settlement_time')->sum('money');
|
||||
// 累计待结算佣金
|
||||
$totalWait = DistributionOrderGoods::where([
|
||||
'status' => 1,
|
||||
])->sum('money');
|
||||
// 今日待结算佣金
|
||||
$totalTodayWait = DistributionOrderGoods::where([
|
||||
'status' => 1,
|
||||
])->whereDay('create_time')->sum('money');
|
||||
|
||||
return [
|
||||
'total_success' => $totalSuccess,
|
||||
'total_today_success' => $totalTodaySuccess,
|
||||
'total_wait' => $totalWait,
|
||||
'total_today_wait' => $totalTodayWait,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销会员数据
|
||||
* @author Tab
|
||||
* @date 2021/9/6 14:57
|
||||
*/
|
||||
public static function members()
|
||||
{
|
||||
$members = Distribution::where('is_distribution', 1)->count();
|
||||
$users = Distribution::count();
|
||||
$proportion = 0;
|
||||
if ($users) {
|
||||
$proportion = round(($members / $users), 2) * 100;
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'members' => $members,
|
||||
'proportion' => $proportion,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销商品排行榜
|
||||
* @author Tab
|
||||
* @date 2021/9/6 14:59
|
||||
*/
|
||||
public static function topGoods()
|
||||
{
|
||||
$field = [
|
||||
'sum(dog.money)' => 'total_money',
|
||||
'og.image' => 'goods_image',
|
||||
'og.goods_name',
|
||||
];
|
||||
$where = [
|
||||
'dog.status' => 2, // 已入账
|
||||
];
|
||||
$topGoods = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->group('dog.money,og.image,og.goods_name')
|
||||
->order('total_money', 'desc')
|
||||
->limit(10)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $topGoods;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销会员排行榜
|
||||
* @return mixed
|
||||
* @author Tab
|
||||
* @date 2021/9/6 15:01
|
||||
*/
|
||||
public static function topMembers()
|
||||
{
|
||||
$field = [
|
||||
'sum(dog.money)' => 'total_money',
|
||||
'u.avatar',
|
||||
'u.nickname',
|
||||
];
|
||||
$where = [
|
||||
'dog.status' => 2, // 已入账
|
||||
];
|
||||
$topMembers = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('user u', 'u.id = dog.user_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->group('dog.money,u.avatar,u.nickname')
|
||||
->order('total_money', 'desc')
|
||||
->limit(10)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach($topMembers as &$item) {
|
||||
$item['avatar'] = empty($item['avatar']) ? '' : UrlServer::getFileUrl($item['avatar']);
|
||||
}
|
||||
|
||||
return $topMembers;
|
||||
}
|
||||
}
|
||||
169
app/admin/logic/distribution/DistributionGoodsLogic.php
Normal file
169
app/admin/logic/distribution/DistributionGoodsLogic.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\distribution\DistributionGoods;
|
||||
use app\common\model\distribution\DistributionLevel;
|
||||
use app\common\model\goods\Goods;
|
||||
|
||||
class DistributionGoodsLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @notes 分销商品列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
* @date 2021/9/2 17:41
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [
|
||||
['del', '<>', '1'],
|
||||
];
|
||||
// 商品信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['name|code', 'like', '%'. $params['keyword']. '%'];
|
||||
}
|
||||
// 平台商品分类
|
||||
if (isset($params['platform_cate_id']) && $params['platform_cate_id'] != 'all') {
|
||||
$where[] = ['first_cate_id|second_cate_id|third_cate_id', '=', $params['platform_cate_id']];
|
||||
}
|
||||
|
||||
$field = [
|
||||
'id',
|
||||
'code',
|
||||
'name',
|
||||
'image',
|
||||
'max_price',
|
||||
'min_price',
|
||||
'id' => 'distribution_flag',
|
||||
'shop_id',
|
||||
];
|
||||
$lists = Goods::with(['Shop'])
|
||||
->field($field)
|
||||
->where($where)
|
||||
->withSearch('is_distribution', ["is_distribution" => 1])
|
||||
->page($params['page'], $params['limit'])
|
||||
->order([
|
||||
'shop_id' => 'desc',
|
||||
'id' => 'desc'
|
||||
])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = Goods::field($field)
|
||||
->where($where)
|
||||
->withSearch('is_distribution', ["is_distribution" => 1])
|
||||
->count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 商品详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
* @date 2021/9/1 19:59
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
// 商品信息
|
||||
$goods = Goods::field('id,code,name')->with('goods_item')->findOrEmpty($params['id'])->toArray();
|
||||
// 分销等级信息
|
||||
$distributionLevelLists = DistributionLevel::order('weights', 'asc')->select()->toArray();
|
||||
// 商品分销信息
|
||||
$distributionGoods = DistributionGoods::where('goods_id', $params['id'])->select()->toArray();
|
||||
if(empty($distributionGoods)) {
|
||||
// 未参与分销
|
||||
$goods['is_distribution'] = 0;
|
||||
$goods['rule'] = 1;
|
||||
$ratio = self::formatLevel($distributionLevelLists, $goods);
|
||||
} else {
|
||||
$goods['is_distribution'] = $distributionGoods[0]['is_distribution'];
|
||||
$goods['rule'] = $distributionGoods[0]['rule'];
|
||||
if($distributionGoods[0]['rule'] == 1) {
|
||||
$ratio = self::formatLevel($distributionLevelLists, $goods);
|
||||
} else {
|
||||
$ratio = self::formatGoods($distributionLevelLists, $goods);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'goods' => $goods,
|
||||
'ratio' => $ratio
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 拼装分销等级佣金比例
|
||||
* @param $distributionLevelLists
|
||||
* @param $goods
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/1 19:44
|
||||
*/
|
||||
public static function formatLevel($distributionLevelLists, $goods)
|
||||
{
|
||||
$ratio = [];
|
||||
foreach($distributionLevelLists as $level) {
|
||||
foreach($goods['goods_item'] as $item) {
|
||||
$temp = [
|
||||
'level_id' => $level['id'],
|
||||
'level_name' => $level['name'],
|
||||
'first_ratio' => $level['first_ratio'],
|
||||
'second_ratio' => $level['second_ratio'],
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['id'],
|
||||
'spec_value_str' => $item['spec_value_str'],
|
||||
'price' => $item['price']
|
||||
];
|
||||
$ratio[] = $temp;
|
||||
}
|
||||
}
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 拼装单独设置的佣金比例
|
||||
* @param $distributionLevelLists
|
||||
* @param $goods
|
||||
* @param $distributionGoods
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/2 9:28
|
||||
*/
|
||||
public static function formatGoods($distributionLevelLists, $goods)
|
||||
{
|
||||
$ratio = [];
|
||||
foreach($distributionLevelLists as $level) {
|
||||
foreach($goods['goods_item'] as $item) {
|
||||
$record = DistributionGoods::where([
|
||||
'level_id' => $level['id'],
|
||||
'item_id' => $item['id'],
|
||||
])->findOrEmpty()->toArray();
|
||||
$temp = [
|
||||
'level_id' => $level['id'],
|
||||
'level_name' => $level['name'],
|
||||
'first_ratio' => $record['first_ratio'],
|
||||
'second_ratio' => $record['second_ratio'],
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['id'],
|
||||
'spec_value_str' => $item['spec_value_str'],
|
||||
'price' => $item['price']
|
||||
];
|
||||
$ratio[] = $temp;
|
||||
}
|
||||
}
|
||||
return $ratio;
|
||||
}
|
||||
}
|
||||
514
app/admin/logic/distribution/DistributionLevelLogic.php
Normal file
514
app/admin/logic/distribution/DistributionLevelLogic.php
Normal file
@ -0,0 +1,514 @@
|
||||
<?php
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\distribution\Distribution;
|
||||
use app\common\model\distribution\DistributionGoods;
|
||||
use app\common\model\distribution\DistributionLevel;
|
||||
use app\common\model\distribution\DistributionLevelUpdate;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderTrade;
|
||||
use think\facade\Db;
|
||||
|
||||
class DistributionLevelLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @notes 分销等级列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
* @date 2021/9/1 16:19
|
||||
*/
|
||||
public static function index()
|
||||
{
|
||||
$field = [
|
||||
'id',
|
||||
'name',
|
||||
'weights' => 'weights_desc',
|
||||
'first_ratio',
|
||||
'second_ratio',
|
||||
'is_default',
|
||||
'id' => 'members_num'
|
||||
];
|
||||
$lists = DistributionLevel::field($field)
|
||||
->order('weights', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = DistributionLevel::count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加分销会员等级
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/1 14:53
|
||||
*/
|
||||
public static function add($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
// 写入等级主表
|
||||
$params['remark'] = $params['remark'] ?? '';
|
||||
// 佣金比例保留两位小数
|
||||
$params['first_ratio'] = !empty($params['first_ratio']) ? round($params['first_ratio'], 2) : 0;
|
||||
$params['second_ratio'] = !empty($params['second_ratio']) ? round($params['second_ratio'], 2) : 0;
|
||||
$newLevel = DistributionLevel::create($params);
|
||||
|
||||
// 写入升级条件表
|
||||
self::addUpdateCondition($params, $newLevel->id);
|
||||
|
||||
// 处理分销商品比例
|
||||
self::updateDistributionGoods($newLevel->id);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加更新升级条件
|
||||
* @param $params
|
||||
* @param $level_id
|
||||
* @throws \Exception
|
||||
* @author Tab
|
||||
* @date 2021/9/1 15:08
|
||||
*/
|
||||
public static function addUpdateCondition($params, $level_id)
|
||||
{
|
||||
$updateConditionData = [];
|
||||
foreach($params['update_condition'] as $key) {
|
||||
// 判断是否在规定的条件字段
|
||||
if(!in_array($key, DistributionLevel::UPDATE_CONDITION_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($params[$key] < 0) {
|
||||
throw new \Exception('升级条件不允许小于0');
|
||||
}
|
||||
// 获取键对应值的字段名
|
||||
$valueField = DistributionLevel::getValueFiled($key);
|
||||
$updateConditionData[] = [
|
||||
'level_id' => $level_id,
|
||||
'key' => $key,
|
||||
$valueField => $params[$key]
|
||||
];
|
||||
}
|
||||
(new DistributionLevelUpdate())->saveAll($updateConditionData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取分销等级详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/1 15:36
|
||||
*/
|
||||
public static function detail($params)
|
||||
{
|
||||
$level = DistributionLevel::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']);
|
||||
if($level->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
$level = $level->toArray();
|
||||
// 默认等级
|
||||
if($level['is_default']) {
|
||||
unset($level['self_ratio']);
|
||||
unset($level['third_ratio']);
|
||||
unset($level['update_relation']);
|
||||
return $level;
|
||||
}
|
||||
// 自定义等级
|
||||
$level['update_condition'] = self::getUpdateCondition($level);
|
||||
unset($level['self_ratio']);
|
||||
unset($level['third_ratio']);
|
||||
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取升级条件
|
||||
* @param $level
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/1 15:36
|
||||
*/
|
||||
public static function getUpdateCondition($level)
|
||||
{
|
||||
$updateCondition = DistributionLevelUpdate::where('level_id', $level['id'])->column('key,value_int,value_decimal,value_text');
|
||||
$updateConditionData = [];
|
||||
foreach($updateCondition as $item) {
|
||||
if($item['value_int']) {
|
||||
$updateConditionData[$item['key']] = $item['value_int'];
|
||||
continue;
|
||||
}
|
||||
if($item['value_decimal']) {
|
||||
$updateConditionData[$item['key']] = $item['value_decimal'];
|
||||
continue;
|
||||
}
|
||||
if($item['value_text']) {
|
||||
$updateConditionData[$item['key']] = $item['value_text'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'keys' => array_keys($updateConditionData),
|
||||
'data' => $updateConditionData
|
||||
];
|
||||
// 补全条件
|
||||
foreach(DistributionLevel::UPDATE_CONDITION_FIELDS as $field) {
|
||||
if(!isset($data['data'][$field])) {
|
||||
$data['data'][$field] = '';
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑分销等级
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/1 16:20
|
||||
*/
|
||||
public static function edit($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$params['remark'] = $params['remark'] ?? '';
|
||||
$level = DistributionLevel::findOrEmpty($params['id']);
|
||||
if($level->isEmpty()) {
|
||||
throw new \Exception('等级不存在');
|
||||
}
|
||||
|
||||
// 佣金比例保留两位小数
|
||||
$params['first_ratio'] = !empty($params['first_ratio']) ? round($params['first_ratio'], 2) : 0;
|
||||
$params['second_ratio'] = !empty($params['second_ratio']) ? round($params['second_ratio'], 2) : 0;
|
||||
|
||||
// 默认等级
|
||||
if($level->is_default) {
|
||||
$level->allowField(['name', 'first_ratio', 'second_ratio','remark'])->save($params);
|
||||
Db::commit();
|
||||
return true;
|
||||
}
|
||||
// 自定义等级 - 更新主表信息
|
||||
if(!$params['weights'] > 1) {
|
||||
throw new \Exception('级别须大于1');
|
||||
}
|
||||
if(!isset($params['update_relation'])) {
|
||||
throw new \Exception('请选择升级关系');
|
||||
}
|
||||
if(!isset($params['update_condition']) || !count($params['update_condition'])) {
|
||||
throw new \Exception('请选择升级条件');
|
||||
}
|
||||
$level->allowField(['name', 'weights', 'first_ratio', 'second_ratio','remark', 'update_relation'])->save($params);
|
||||
|
||||
// 自定义等级 - 删除旧升级条件
|
||||
$deleteIds = DistributionLevelUpdate::where('level_id', $level->id)->column('id');
|
||||
DistributionLevelUpdate::destroy($deleteIds);
|
||||
|
||||
// 自定义等级 - 添加新的升级条件
|
||||
self::addUpdateCondition($params, $level->id);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除分销等级
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/1 16:21
|
||||
*/
|
||||
public static function delete($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$level = DistributionLevel::findOrEmpty($params['id']);
|
||||
if($level->isEmpty()) {
|
||||
throw new \Exception('等级不存在');
|
||||
}
|
||||
if($level->is_default) {
|
||||
throw new \Exception('系统默认等级不允许删除');
|
||||
}
|
||||
|
||||
// 重置该等级下的分销会员为系统默认等级
|
||||
$defaultId = DistributionLevel::where('is_default', 1)->value('id');
|
||||
Distribution::where('level_id', $level->id)->update(['level_id' => $defaultId]);
|
||||
|
||||
// 删除升级条件
|
||||
$deleteIds = DistributionLevelUpdate::where('level_id', $level->id)->column('id');
|
||||
DistributionLevelUpdate::destroy($deleteIds);
|
||||
|
||||
// 删除该等级下的分销商品比例
|
||||
$deleteIds = DistributionGoods::where('level_id', $level->id)->column('id');
|
||||
DistributionGoods::destroy($deleteIds);
|
||||
|
||||
// 删除等级
|
||||
$level->delete();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新分销会员等级
|
||||
* @param $userId
|
||||
* @return false
|
||||
* @author Tab
|
||||
* @date 2021/9/2 16:39
|
||||
*/
|
||||
public static function updateDistributionLevel($userId)
|
||||
{
|
||||
// 非默认等级
|
||||
$levels = DistributionLevel::where('is_default', 0)
|
||||
->order('weights', 'desc')
|
||||
->column('id,name,weights,update_relation', 'id');
|
||||
|
||||
$userInfo = Distribution::alias('d')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field('d.is_distribution,d.level_id,dl.weights')
|
||||
->where('d.user_id', $userId)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
// 非分销会员直接返回false
|
||||
if(empty($userInfo) || !$userInfo['is_distribution']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($levels as $level) {
|
||||
if(self::isMeetConditions($userId, $level) && $level['weights'] > $userInfo['weights']) {
|
||||
// 满足升级条件且是升更高的等级
|
||||
Distribution::where(['user_id' => $userId])->update(['level_id' => $level['id']]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足当前等级的升级条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/2 16:42
|
||||
*/
|
||||
public static function isMeetConditions($userId, $level)
|
||||
{
|
||||
$updateRelation = $level['update_relation'];
|
||||
// 任一条件满足升级
|
||||
if($updateRelation == 1) {
|
||||
$flagOr = self::singleConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
|| self::cumulativeConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
|| self::cumulativeConsumptionTimesFlag($userId, $level, $updateRelation)
|
||||
|| self::returnedCommissionFlag($userId, $level, $updateRelation);
|
||||
return $flagOr;
|
||||
}
|
||||
|
||||
// 全部条件满足升级
|
||||
if($updateRelation == 2) {
|
||||
$flagAnd = self::singleConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
&& self::cumulativeConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
&& self::cumulativeConsumptionTimesFlag($userId, $level, $updateRelation)
|
||||
&& self::returnedCommissionFlag($userId, $level, $updateRelation);
|
||||
return $flagAnd;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足单笔消费金额条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/2 16:44
|
||||
*/
|
||||
public static function singleConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'singleConsumptionAmount'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$recentOrder = Order::where([
|
||||
'user_id' => $userId,
|
||||
'pay_status' => 1
|
||||
])
|
||||
->order('id', 'desc')
|
||||
->findOrEmpty();
|
||||
if($recentOrder->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
$singleConsumptionAmount = OrderTrade::where('id', $recentOrder['trade_id'])->findOrEmpty()->toArray();
|
||||
if($singleConsumptionAmount['order_amount'] >= $condition['value_decimal']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足累计消费金额条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/2 16:50
|
||||
*/
|
||||
public static function cumulativeConsumptionAmountFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'cumulativeConsumptionAmount'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$cumulativeConsumptionAmount = Order::where([
|
||||
'user_id' => $userId,
|
||||
'pay_status' => 1
|
||||
])->sum('order_amount');
|
||||
if($cumulativeConsumptionAmount >= $condition['value_decimal']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否满足累计消费次数条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/2 16:53
|
||||
*/
|
||||
public static function cumulativeConsumptionTimesFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'cumulativeConsumptionTimes'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$allTradeIds = Order::where([
|
||||
'user_id' => $userId,
|
||||
'pay_status' => 1
|
||||
])->column('trade_id');
|
||||
$cumulativeConsumptionTimes = count(array_unique($allTradeIds));
|
||||
if($cumulativeConsumptionTimes >= $condition['value_int']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 判断是否消费已返佣金条件
|
||||
* @param $userId
|
||||
* @param $level
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/2 17:06
|
||||
*/
|
||||
public static function returnedCommissionFlag($userId, $level, $updateRelation)
|
||||
{
|
||||
$condition = DistributionLevelUpdate::field('value_int,value_decimal,value_text')
|
||||
->where([
|
||||
'level_id' => $level['id'],
|
||||
'key' => 'returnedCommission'
|
||||
])
|
||||
->findOrEmpty();
|
||||
if($condition->isEmpty()) {
|
||||
// 等级条件为满足任一条件(updateRelation=1) 返回false (满足已设置的任一条件时才升级,未设置的条件归为未满足,返回false)
|
||||
// 等级条件为满足全部条件(updateRelation=2) 返回true (满足已设置的所有条件时才升级,未设置的条件归为已满足,返回true)
|
||||
return $updateRelation == 2;
|
||||
}
|
||||
$returnedCommission = DistributionOrderGoods::where([
|
||||
'user_id' => $userId,
|
||||
'status' => 2
|
||||
])->sum('money');
|
||||
if($returnedCommission >= $condition['value_decimal']) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取所有分销会员等级
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/2 18:31
|
||||
*/
|
||||
public static function getLevels()
|
||||
{
|
||||
return DistributionLevel::order('weights', 'asc')->column('id, name,weights');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新分销商品比例
|
||||
* @param $levelId
|
||||
* @author Tab
|
||||
* @date 2021/9/7 17:27
|
||||
*/
|
||||
public static function updateDistributionGoods($levelId)
|
||||
{
|
||||
// 处理单独设置比例的商品,新增分销会等级佣金比例初始化为0
|
||||
$field = [
|
||||
'shop_id',
|
||||
'goods_id',
|
||||
'item_id',
|
||||
];
|
||||
$distribution = DistributionGoods::distinct(true)->field($field)->where('rule', 2)->select()->toArray();
|
||||
$addData = [];
|
||||
foreach($distribution as $item) {
|
||||
$temp = [
|
||||
'shop_id' => $item['shop_id'],
|
||||
'goods_id' => $item['goods_id'],
|
||||
'item_id' => $item['item_id'],
|
||||
'level_id' => $levelId,
|
||||
'first_ratio' => 0,
|
||||
'second_ratio' => 0,
|
||||
'rule' => 2,
|
||||
];
|
||||
$addData[] = $temp;
|
||||
}
|
||||
(new DistributionGoods())->saveAll($addData);
|
||||
}
|
||||
}
|
||||
231
app/admin/logic/distribution/DistributionMemberLogic.php
Normal file
231
app/admin/logic/distribution/DistributionMemberLogic.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\distribution\Distribution;
|
||||
use app\common\model\distribution\DistributionLevel;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
/**
|
||||
* 分销会员逻辑层
|
||||
* Class DistributionMemberLogic
|
||||
* @package app\admin\logic\distribution
|
||||
*/
|
||||
class DistributionMemberLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @notes 分销会员列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/9/2 18:44
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where = [
|
||||
['d.is_distribution', '=', 1]
|
||||
];
|
||||
// 用户信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['u.sn|u.nickname', 'like', '%'. $params['keyword'] .'%'];
|
||||
}
|
||||
// 分销等级
|
||||
if (isset($params['level_id']) && $params['level_id'] != 'all') {
|
||||
$where[] = ['d.level_id', '=', $params['level_id']];
|
||||
}
|
||||
// 分销状态
|
||||
if (isset($params['is_freeze']) && $params['is_freeze'] != 'all') {
|
||||
$where[] = ['d.is_freeze', '=', $params['is_freeze']];
|
||||
}
|
||||
|
||||
$field = [
|
||||
'u.id' => 'user_id',
|
||||
'u.sn' => 'user_sn',
|
||||
'u.avatar',
|
||||
'u.nickname',
|
||||
'u.user_delete',
|
||||
'dl.id' => 'level_id',
|
||||
'dl.weights',
|
||||
'dl.name' => 'level_name',
|
||||
'd.is_freeze',
|
||||
'd.distribution_time',
|
||||
];
|
||||
$lists = Distribution::alias('d')
|
||||
->leftJoin('user u', 'u.id = d.user_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order('u.id', 'desc')
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = Distribution::alias('d')
|
||||
->leftJoin('user u', 'u.id = d.user_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['avatar'] = empty($item['avatar']) ? '' : UrlServer::getFileUrl($item['avatar']);
|
||||
$item['earnings'] = DistributionOrderGoods::getEarnings($item['user_id']);
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 用户列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author Tab
|
||||
* @date 2021/9/3 9:55
|
||||
*/
|
||||
public static function getUserLists($params)
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
$where[] = ['user_delete', '=', 0];
|
||||
// 用户信息
|
||||
if (isset($params['keyword']) && !empty($params['keyword'])) {
|
||||
$where[] = ['sn|nickname', 'like', '%'. $params['keyword'] .'%'];
|
||||
}
|
||||
|
||||
$lists = User::field('id,sn,nickname,id as distribution')
|
||||
->where($where)
|
||||
->withSearch(['distribution'], $params)
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
$count = User::where($where)->withSearch(['distribution'], $params)->count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 开通分销会员
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/3 11:09
|
||||
*/
|
||||
public static function open($params)
|
||||
{
|
||||
try {
|
||||
$user = User::where('id', $params['user_id'])->findOrEmpty()->toArray();
|
||||
if(empty($user)) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
if (User::UserIsDelete($params['user_id'])) {
|
||||
throw new \Exception('用户已注销');
|
||||
}
|
||||
$distribution = Distribution::where('user_id', $params['user_id'])->findOrEmpty()->toArray();
|
||||
if(!empty($distribution) && $distribution['is_distribution'] == 1) {
|
||||
throw new \Exception('用户已是分销会员');
|
||||
}
|
||||
if(!empty($distribution) && $distribution['is_distribution'] == 0) {
|
||||
Distribution::where('user_id', $params['user_id'])->update([
|
||||
'is_distribution' => 1,
|
||||
'distribution_time' => time(),
|
||||
'level_id' => $params['level_id'],
|
||||
]);
|
||||
}
|
||||
if(empty($distribution)) {
|
||||
$data = [
|
||||
'user_id' => $params['user_id'],
|
||||
'level_id' => $params['level_id'],
|
||||
'is_distribution' => 1,
|
||||
'is_freeze' => 0,
|
||||
'remark' => '后台开通分销',
|
||||
'distribution_time' => time()
|
||||
];
|
||||
|
||||
Distribution::create($data);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUser($params)
|
||||
{
|
||||
$field = [
|
||||
'u.id' => 'user_id',
|
||||
'u.sn' => 'user_sn',
|
||||
'u.nickname' => 'user_nickname',
|
||||
'dl.name' => 'level_name',
|
||||
'dl.weights',
|
||||
];
|
||||
$info = Distribution::alias('d')
|
||||
->leftJoin('user u', 'u.id = d.user_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = d.level_id')
|
||||
->field($field)
|
||||
->where('d.user_id', $params['id'])
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销会员等级调整
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/3 14:14
|
||||
*/
|
||||
public static function adjust($params)
|
||||
{
|
||||
try {
|
||||
if (User::UserIsDelete($params['user_id'])) {
|
||||
throw new \Exception('用户已注销');
|
||||
}
|
||||
Distribution::where(['user_id' => $params['user_id']])->update([
|
||||
'level_id' => $params['level_id']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 冻结资格/恢复资格
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/3 14:24
|
||||
*/
|
||||
public static function isFreeze($params)
|
||||
{
|
||||
try {
|
||||
if (User::UserIsDelete($params['user_id'])) {
|
||||
throw new \Exception('用户已注销');
|
||||
}
|
||||
Distribution::where(['user_id' => $params['user_id']])->update([
|
||||
'is_freeze' => $params['is_freeze']
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
110
app/admin/logic/distribution/DistributionOrderLogic.php
Normal file
110
app/admin/logic/distribution/DistributionOrderLogic.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\distribution\DistributionLevel;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class DistributionOrderLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @notes 分销订单列表
|
||||
* @param $params
|
||||
* @return int[]
|
||||
* @author Tab
|
||||
* @date 2021/9/3 14:53
|
||||
*/
|
||||
public static function lists($params)
|
||||
{
|
||||
$where= [];
|
||||
// 订单信息
|
||||
if (isset($params['order_keyword']) && !empty($params['order_keyword'])) {
|
||||
$where[] = ['o.order_sn', '=', $params['order_keyword']];
|
||||
}
|
||||
// 商品名称
|
||||
if (isset($params['goods_keyword']) && !empty($params['goods_keyword'])) {
|
||||
$where[] = ['og.goods_name', 'like', '%'.$params['goods_keyword'].'%'];
|
||||
}
|
||||
// 分销会员
|
||||
if (isset($params['distribution_keyword']) && !empty($params['distribution_keyword'])) {
|
||||
$where[] = ['u.sn|u.nickname', 'like', '%'.$params['distribution_keyword'].'%'];
|
||||
}
|
||||
// 佣金状态
|
||||
if (isset($params['status']) && !empty($params['status'])) {
|
||||
$where[] = ['dog.status', '=', $params['status']];
|
||||
}
|
||||
|
||||
$field = [
|
||||
'o.id' => 'order_id',
|
||||
'o.order_sn',
|
||||
'o.create_time' => 'order_create_time',
|
||||
'o.user_id' => 'order_user_id',
|
||||
'u.id' => 'distribution_user_id',
|
||||
'u.avatar' => 'distribution_avatar',
|
||||
'u.sn' => 'distribution_sn',
|
||||
'u.nickname' => 'distribution_nickname',
|
||||
'og.image' => 'goods_image',
|
||||
'og.goods_name' => 'goods_name',
|
||||
'og.spec_value' => 'spec_value',
|
||||
'og.goods_num' => 'goods_num',
|
||||
'og.total_pay_price' => 'total_pay_price',
|
||||
'dog.level_id',
|
||||
'dog.level',
|
||||
'dog.ratio',
|
||||
'dog.money',
|
||||
'dog.status' => 'status_desc',
|
||||
'dog.settlement_time',
|
||||
's.id' => 'shop_id',
|
||||
's.name' => 'shop_name',
|
||||
's.logo' => 'shop_logo',
|
||||
];
|
||||
|
||||
$lists = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('order o', 'o.id = dog.order_id')
|
||||
->leftJoin('user u', 'u.id = dog.user_id')
|
||||
->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = dog.level_id')
|
||||
->leftJoin('shop s', 's.id = dog.shop_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order('dog.id', 'desc')
|
||||
->page($params['page'], $params['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = DistributionOrderGoods::alias('dog')
|
||||
->leftJoin('order o', 'o.id = dog.order_id')
|
||||
->leftJoin('user u', 'u.id = dog.user_id')
|
||||
->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
|
||||
->leftJoin('distribution_level dl', 'dl.id = dog.level_id')
|
||||
->leftJoin('shop s', 's.id = dog.shop_id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['order_create_time'] = date('Y-m-d H:i:s', $item['order_create_time']);
|
||||
$item['user_info'] = User::getUserInfo($item['order_user_id']);
|
||||
if ($item['user_info'] == '系统') {
|
||||
// 用户不存在(已被删除的情况)
|
||||
$item['user_info'] = [
|
||||
'avatar' => '',
|
||||
'nickname' => '-',
|
||||
'sn' => '-',
|
||||
];
|
||||
}
|
||||
$item['distribution_avatar'] = empty($item['distribution_avatar']) ? '' : UrlServer::getFileUrl($item['distribution_avatar']);
|
||||
$item['user_info']['avatar'] = empty($item['user_info']['avatar']) ? '' : UrlServer::getFileUrl($item['user_info']['avatar']);
|
||||
$item['level_name'] = DistributionLevel::getLevelName($item['level_id']);
|
||||
$item['shop_logo'] = empty($item['shop_logo']) ? '' : UrlServer::getFileUrl($item['shop_logo']);
|
||||
$item['goods_image'] = empty($item['goods_image']) ? '' : UrlServer::getFileUrl($item['goods_image']);
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
}
|
||||
95
app/admin/logic/distribution/DistributionSettingLogic.php
Normal file
95
app/admin/logic/distribution/DistributionSettingLogic.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\logic\DistributionLogic;
|
||||
use app\common\model\distribution\Distribution;
|
||||
use app\common\model\user\User;
|
||||
use app\common\server\ConfigServer;
|
||||
use think\facade\Db;
|
||||
|
||||
class DistributionSettingLogic extends Logic
|
||||
{
|
||||
/**
|
||||
* @notes 获取分销配置
|
||||
* @return array
|
||||
* @author Tab
|
||||
* @date 2021/8/31 17:45
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
$config = [
|
||||
// 分销功能 0-关闭(默认) 1-开启
|
||||
'is_open' => ConfigServer::get('distribution', 'is_open', 0),
|
||||
// 分销层级 1-一级分销 2-二级分销(默认)
|
||||
'level' => ConfigServer::get('distribution', 'level', 2),
|
||||
// 商品详情是否显示佣金 0-不显示(默认) 1-默认
|
||||
'is_show_earnings' => ConfigServer::get('distribution', 'is_show_earnings', 0),
|
||||
// 详情页佣金可见用户 0-全部用户 1-分销商
|
||||
'show_earnings_scope' => ConfigServer::get('distribution', 'show_earnings_scope', 0),
|
||||
// 开通分销会员条件 1-无条件 2-申请分销(默认) 3-指定分销
|
||||
'apply_condition' => ConfigServer::get('distribution', 'apply_condition', 2),
|
||||
// 佣金计算方式 1-商品实际支付金额(默认)
|
||||
'cale_method' => ConfigServer::get('distribution', 'cale_method', 1),
|
||||
// 结算时机 1-订单完成后(默认)
|
||||
'settlement' => ConfigServer::get('distribution', 'settlement', 1),
|
||||
// 结算时机 订单完成后多少天内(默认7天)
|
||||
'settlement_days' => ConfigServer::get('distribution', 'settlement_days', 7),
|
||||
];
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 分销设置
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author Tab
|
||||
* @date 2021/9/2 14:47
|
||||
*/
|
||||
public static function set($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$allowFields = ['is_open', 'level', 'is_show_earnings', 'apply_condition', 'cale_method', 'settlement_days', 'show_earnings_scope'];
|
||||
foreach ($allowFields as $field) {
|
||||
if(isset($params[$field])) {
|
||||
ConfigServer::set('distribution', $field, $params[$field]);
|
||||
}
|
||||
if($field == 'apply_condition' && isset($params[$field]) && $params[$field] == 1) {
|
||||
// 开通分销会员无条件时,所有会员均成为分销会员
|
||||
self::distribution();
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 全员分销
|
||||
* @author Tab
|
||||
* @date 2021/9/2 14:38
|
||||
*/
|
||||
public static function distribution()
|
||||
{
|
||||
// 将非分销会员变为分销会员
|
||||
Distribution::where('is_distribution', 0)->update([
|
||||
'is_distribution' => 1
|
||||
]);
|
||||
// 获取所有分销会员id
|
||||
$distributionIds = Distribution::distinct(true)->column('user_id');
|
||||
// 查找未生成分销会员基础信息表的会员
|
||||
$notDistributionIds = User::where([
|
||||
['id', 'not in', $distributionIds],
|
||||
['del', '=', 0],
|
||||
])->column('id');
|
||||
foreach($notDistributionIds as $userId) {
|
||||
// 生成分销会员基础信息表
|
||||
DistributionLogic::add($userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
414
app/admin/logic/distribution/MemberLogic.php
Normal file
414
app/admin/logic/distribution/MemberLogic.php
Normal file
@ -0,0 +1,414 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserLevel;
|
||||
use app\common\server\UrlServer;
|
||||
use app\common\model\WithdrawApply;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
use app\common\model\distribution\DistributionMemberApply;
|
||||
use think\facade\Db;
|
||||
|
||||
class MemberLogic extends Logic
|
||||
{
|
||||
public static function memberLists($get)
|
||||
{
|
||||
// 关键词
|
||||
$where[] = ['is_distribution', '=', 1];
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$where[] = [$get['search_key'], '=', trim($get['keyword'])];
|
||||
}
|
||||
//分销状态
|
||||
if (isset($get['freeze_distribution']) && $get['freeze_distribution'] != '') {
|
||||
$where[] = ['freeze_distribution', '=', $get['freeze_distribution']];
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$count = $user->where($where)->count();
|
||||
|
||||
$lists = $user
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->append(['fans', 'distribution_order', 'leader'])
|
||||
->hidden(['password,pay_password,salt'])
|
||||
->order('id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
|
||||
$item['distribution_num'] = $item['distribution_order']['num'] ?? 0;//分销订单数
|
||||
$item['distribution_amount'] = $item['distribution_order']['amount'] ?? 0;//分销订单金额
|
||||
$item['distribution_money'] = $item['distribution_order']['money'] ?? 0;//分销佣金
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
public static function addMember($post)
|
||||
{
|
||||
// 根据会员编号查询用户
|
||||
$user = User::field('id,sn,is_distribution,distribution_add_remarks,del')
|
||||
->where(['sn'=>$post['sn']])->findOrEmpty();
|
||||
// 校验用户
|
||||
if ($user->isEmpty()) { return '该用户不存在!'; }
|
||||
$user = $user->toArray();
|
||||
if ($user['del'] === 1) { return '该用户已被删除!'; }
|
||||
if ($user['is_distribution']) { return '该用户已是分销会员,无需重复添加'; }
|
||||
$result = User::where(['id' => (int)$user['id']])->update([
|
||||
'is_distribution' => 1,
|
||||
'distribution_add_remarks' => $post['remarks'] ?? '',
|
||||
'update_time' => time()
|
||||
]);
|
||||
return $result ? true : '添加失败';
|
||||
}
|
||||
|
||||
public static function getMemberInfo($get)
|
||||
{
|
||||
$user_id = $get['id'];
|
||||
$user = User::alias('u')
|
||||
->field('u.*,u.sn as user_sn')
|
||||
->leftJoin('distribution_order_goods d', 'd.user_id = u.id')
|
||||
->where('u.id', $user_id)
|
||||
->append(['distribution_order'])
|
||||
->hidden(['password', 'pay_password', 'salt'])
|
||||
->find();
|
||||
|
||||
$user['distribution_text'] = '否';
|
||||
if ($user['is_distribution'] == 1) {
|
||||
$user['distribution_text'] = '是';
|
||||
}
|
||||
|
||||
//上级编号
|
||||
$user['first_leader_sn'] = User::where('id', $user['first_leader'])->value('sn');
|
||||
//直推会员数
|
||||
$user['first_fans'] = User::where(['first_leader' => $user_id, 'del' => 0])->count();
|
||||
// 已提现金额
|
||||
$have_withdraw = WithdrawApply::where(['status' => WithdrawApply::STATUS_SUCCESS, 'user_id' => $user_id])
|
||||
->sum('money');
|
||||
|
||||
$user['distribution_num'] = $user['distribution_order']['num'] ?? 0;//分销订单数
|
||||
$user['distribution_amount'] = $user['distribution_order']['amount'] ?? 0;//分销订单金额
|
||||
$user['distribution_money'] = $user['distribution_order']['money'] ?? 0;//分销佣金
|
||||
$user['have_withdraw'] = $have_withdraw;//已提现金额
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function getFansLists($get)
|
||||
{
|
||||
$user_id = $get['id'];
|
||||
$where = [];
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$keyword = $get['keyword'];
|
||||
$where[] = [$get['search_key'], 'like', '%' . $keyword . '%'];
|
||||
}
|
||||
|
||||
$fans_type = $get['type'] ?? 'all';
|
||||
if ($fans_type == 'all') {
|
||||
$where[] = ['first_leader|second_leader|third_leader', '=', $user_id];
|
||||
} else {
|
||||
$where[] = [$fans_type, '=', $user_id];
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$count = $user
|
||||
->where($where)
|
||||
->append(['fans', 'distribution_order'])
|
||||
->hidden(['password,pay_password,salt'])
|
||||
->count();
|
||||
|
||||
$lists = $user
|
||||
->where($where)
|
||||
->append(['fans', 'distribution_order'])
|
||||
->hidden(['password,pay_password,salt'])
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()->toArray();
|
||||
|
||||
// 用户等级列表
|
||||
$user_level = UserLevel::where(['del' => 0])->column('name', 'id');
|
||||
// 提取所有上级id
|
||||
$leader_ids = array_column($lists, 'first_leader');
|
||||
// 所有上级列表
|
||||
$leaders = User::where('id', 'in', $leader_ids)
|
||||
->column('sn,nickname,mobile,level', 'id');
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
$item['leader'] = $leaders[$item['first_leader']] ?? [];
|
||||
if (!empty($item['leader'])) {
|
||||
$leader_level = $item['leader']['level'] ?? 0;
|
||||
$item['leader']['level'] = $user_level[$leader_level] ?? '无等级';
|
||||
}
|
||||
$item['distribution_num'] = $item['distribution_order']['num'] ?? 0;//分销订单数
|
||||
$item['distribution_amount'] = $item['distribution_order']['amount'] ?? 0;//分销订单金额
|
||||
$item['distribution_money'] = $item['distribution_order']['money'] ?? 0;//分销佣金
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
public static function getEarningsDetail($get)
|
||||
{
|
||||
$user_id = $get['id'];
|
||||
$where = [];
|
||||
$where[] = ['d.user_id', '=', $user_id];
|
||||
$where[] = ['d.status', '=', DistributionOrderGoods::STATUS_SUCCESS];
|
||||
|
||||
//记录时间
|
||||
if (isset($get['start_time']) && $get['start_time'] != '') {
|
||||
$where[] = ['d.create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
if (isset($get['end_time']) && $get['end_time'] != '') {
|
||||
$where[] = ['d.create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
|
||||
$count = DistributionOrderGoods::alias('d')
|
||||
->field('d.id as distribution_id, d.sn, o.order_sn, d.money, d.create_time')
|
||||
->join('order_goods og', 'og.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = og.order_id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$lists = DistributionOrderGoods::alias('d')
|
||||
->field('d.id as distribution_id, d.sn, o.order_sn, d.money, d.create_time')
|
||||
->join('order_goods og', 'og.id = d.order_goods_id')
|
||||
->join('order o', 'o.id = og.order_id')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->select();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['type'] = '分销佣金';
|
||||
}
|
||||
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
public static function getLeaderInfo($user_id)
|
||||
{
|
||||
$first_leader = User::alias('u')
|
||||
->field('u1.nickname,u1.sn')
|
||||
->join('user u1', 'u1.id = u.first_leader')
|
||||
->where('u.id', $user_id)
|
||||
->find();
|
||||
|
||||
$leader_data = '无';
|
||||
if ($first_leader) {
|
||||
$leader_data = $first_leader['nickname'] . '(' . $first_leader['sn'] . ')';
|
||||
}
|
||||
return $leader_data;
|
||||
}
|
||||
|
||||
public static function updateRelation($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$user_id = $post['user_id'];
|
||||
$referrer_sn = $post['referrer_sn'];
|
||||
|
||||
//清空上级
|
||||
$data = [
|
||||
'first_leader' => 0,
|
||||
'second_leader' => 0,
|
||||
'third_leader' => 0,
|
||||
'ancestor_relation' => '',
|
||||
];
|
||||
$my_first_leader = 0;
|
||||
$my_second_leader = 0;
|
||||
$my_ancestor_relation = '';
|
||||
|
||||
if ($post['change_type'] == 'appoint'){
|
||||
//指定上级
|
||||
$my_leader = User::where(['sn' => $referrer_sn])->findOrEmpty();
|
||||
|
||||
//更新我的第一上级、第二上级、第三上级、关系链
|
||||
$my_first_leader = $my_leader['id'];
|
||||
$my_second_leader = $my_leader['first_leader'];
|
||||
$my_third_leader = $my_leader['second_leader'];
|
||||
$my_ancestor_relation = trim("{$my_first_leader},{$my_leader['ancestor_relation']}", ',');
|
||||
$data = [
|
||||
'first_leader' => $my_first_leader,
|
||||
'second_leader' => $my_second_leader,
|
||||
'third_leader' => $my_third_leader,
|
||||
'ancestor_relation' => $my_ancestor_relation,
|
||||
];
|
||||
}
|
||||
// 更新我的上级、上上级、上上上级、关系链
|
||||
User::where(['id' => $user_id])->update($data);
|
||||
|
||||
//更新我向下一级的第二上级、第三上级
|
||||
$data = [
|
||||
'second_leader' => $my_first_leader,
|
||||
'third_leader' => $my_second_leader,
|
||||
];
|
||||
User::where(['first_leader' => $user_id])->update($data);
|
||||
|
||||
//更新我向下二级的第三级
|
||||
$data = [
|
||||
'third_leader' => $my_first_leader,
|
||||
];
|
||||
User::where(['second_leader' => $user_id])->update($data);
|
||||
|
||||
//更新当前用户所有后代的关系链
|
||||
$posterityArr = User::field('id,ancestor_relation')
|
||||
->whereFindInSet('ancestor_relation', $post['user_id'])
|
||||
->select()
|
||||
->toArray();
|
||||
$updateData = [];
|
||||
$replace_ancestor_relation = $post['user_id'] . ','. $my_ancestor_relation;
|
||||
foreach($posterityArr as $item) {
|
||||
$updateData[] = [
|
||||
'id' => $item['id'],
|
||||
'ancestor_relation' => str_replace($post['user_id'], $replace_ancestor_relation, $item['ancestor_relation'])
|
||||
];
|
||||
}
|
||||
// 批量更新
|
||||
(new User())->saveAll($updateData);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function freeze($post)
|
||||
{
|
||||
$user = User::where('id', $post['id'])->find();
|
||||
$user->freeze_distribution = 1;
|
||||
if ($post['type'] == 'unfreeze'){
|
||||
$user->freeze_distribution = 0;
|
||||
}
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
public static function del($post)
|
||||
{
|
||||
$user = User::find($post['id']);
|
||||
$user->is_distribution = 0;
|
||||
$user->update_time = time();
|
||||
return $user->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 待审核会员列表
|
||||
*/
|
||||
public static function auditLists($get)
|
||||
{
|
||||
$where = [];
|
||||
if (!empty($get['search_key']) && !empty($get['keyword'])) {
|
||||
$keyword = $get['keyword'];
|
||||
if ($get['search_key'] == 'mobile') {
|
||||
$where[] = ['u.mobile', 'like', '%' . $keyword . '%'];
|
||||
} else {
|
||||
$where[] = [$get['search_key'], 'like', '%' . $keyword . '%'];
|
||||
}
|
||||
}
|
||||
//审核状态
|
||||
if (isset($get['status']) && $get['status'] != '') {
|
||||
$where[] = ['status', '=', $get['status']];
|
||||
}
|
||||
|
||||
|
||||
$field = [
|
||||
'a.*', 'u.sn', 'u.nickname', 'u.mobile', 'u.level', 'u.sex', 'a.reason',
|
||||
'u.create_time' => 'register_time', 'u.avatar', 'u.first_leader'
|
||||
];
|
||||
|
||||
$count = DistributionMemberApply::alias('a')
|
||||
->join('user u', 'u.id = a.user_id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$lists = DistributionMemberApply::alias('a')
|
||||
->field($field)
|
||||
->join('user u', 'u.id = a.user_id')
|
||||
->order('a.id desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->where($where)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$user_level = UserLevel::where(['del' => 0])->column('name', 'id');
|
||||
|
||||
$leader_ids = array_column($lists, 'first_leader');
|
||||
$leaders = User::where('id', 'in', $leader_ids)
|
||||
->column('sn,nickname,mobile,level', 'id');
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['level'] = $user_level[$item['level']] ?? '无等级';
|
||||
$item['sex'] = self::getSexText($item['sex']);
|
||||
$item['register_time'] = date('Y-m-d H:i:s', $item['register_time']);
|
||||
$item['status_text'] = DistributionMemberApply::getApplyStatus($item['status']);
|
||||
$item['leader'] = $leaders[$item['first_leader']] ?? [];
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
if (!empty($item['leader'])) {
|
||||
$leader_level = $item['leader']['level'] ?? 0;
|
||||
$item['leader']['level'] = $user_level[$leader_level] ?? '无等级';
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
public static function getSexText($value)
|
||||
{
|
||||
switch ($value) {
|
||||
case 1:
|
||||
return '男';
|
||||
case 2:
|
||||
return '女';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
public static function auditPass($post)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$apply = DistributionMemberApply::where('id', $post['id'])->find();
|
||||
$apply->status = DistributionMemberApply::STATUS_AUDIT_SUCCESS;
|
||||
$apply->update_time = time();
|
||||
$apply->save();
|
||||
|
||||
$user = User::where('id', $apply['user_id'])->find();
|
||||
$user->is_distribution = 1;
|
||||
$user->save();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function auditRefuse($post)
|
||||
{
|
||||
$apply = DistributionMemberApply::where('id', $post['id'])->find();
|
||||
$apply->status = DistributionMemberApply::STATUS_AUDIT_ERROR;
|
||||
$apply->denial_reason = $post['denial_reason'] ?? '';
|
||||
$apply->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
84
app/admin/logic/distribution/RecordLogic.php
Normal file
84
app/admin/logic/distribution/RecordLogic.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic\distribution;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\distribution\DistributionOrderGoods;
|
||||
|
||||
class RecordLogic extends Logic
|
||||
{
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
// 搜索
|
||||
if(!empty($get['keyword'])) {
|
||||
$fieldDesc = '';
|
||||
switch($get['keyword_type']) {
|
||||
case 'order_sn':
|
||||
$fieldDesc = 'o.order_sn';
|
||||
break;
|
||||
case 'user_nickname':
|
||||
$fieldDesc = 'u.nickname';
|
||||
break;
|
||||
case 'user_sn':
|
||||
$fieldDesc = 'u.sn';
|
||||
break;
|
||||
case 'user_mobile':
|
||||
$fieldDesc = 'u.mobile';
|
||||
break;
|
||||
}
|
||||
$where[] = [$fieldDesc, '=', trim($get['keyword'])];
|
||||
}
|
||||
// 佣金状态
|
||||
if(!empty($get['status'])) {
|
||||
$where[] = ['dog.status', '=', $get['status']];
|
||||
}
|
||||
// 记录时间
|
||||
if(!empty($get['start_time'])) {
|
||||
$where[] = ['dog.create_time', '>=', strtotime($get['start_time'])];
|
||||
}
|
||||
if(!empty($get['end_time'])) {
|
||||
$where[] = ['dog.create_time', '<=', strtotime($get['end_time'])];
|
||||
}
|
||||
$lists = DistributionOrderGoods::alias('dog')
|
||||
->field('dog.money, dog.status as status_desc,dog.create_time as distribution_create_time,u.nickname as user_nickname,u.sn as user_sn,u.mobile as user_mobile,og.total_pay_price,o.order_sn')
|
||||
->leftJoin('user u', 'u.id=dog.user_id')
|
||||
->leftJoin('order_goods og', 'og.id=dog.order_goods_id')
|
||||
->leftJoin('order o', 'o.id=og.order_id')
|
||||
->where($where)
|
||||
->order('dog.create_time', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = DistributionOrderGoods::alias('dog')
|
||||
->field('dog.money, dog.status as status_desc,dog.create_time as distribution_create_time,u.nickname as user_nickname,u.sn as user_sn,u.mobile as user_mobile,og.total_pay_price,o.order_sn')
|
||||
->leftJoin('user u', 'u.id=dog.user_id')
|
||||
->leftJoin('order_goods og', 'og.id=dog.order_goods_id')
|
||||
->leftJoin('order o', 'o.id=og.order_id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user