From 4ab38446820abcab34b74d97e30bafec9f51389c Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 3 Nov 2023 16:11:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E8=B4=A1=E7=8C=AE?= =?UTF-8?q?=E5=80=BC=E5=88=86=E7=BA=A2=E8=AE=B0=E5=BD=95=E5=8F=8A=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=E8=AE=B0=E5=BD=95=E6=9F=A5=E7=9C=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cultural-space/src/PluginApplication.php | 22 +-- .../src/admin/ContributionController.php | 45 ++---- .../src/models/ContributionBonus.php | 23 +++ .../src/models/ContributionBonusLog.php | 146 ++++-------------- .../src/models/ContributionLog.php | 14 +- .../views/contribution/index.blade.php | 66 +++++--- 6 files changed, 119 insertions(+), 197 deletions(-) diff --git a/plugins/cultural-space/src/PluginApplication.php b/plugins/cultural-space/src/PluginApplication.php index a715c300..313c8a77 100644 --- a/plugins/cultural-space/src/PluginApplication.php +++ b/plugins/cultural-space/src/PluginApplication.php @@ -70,7 +70,7 @@ class PluginApplication extends \app\common\services\PluginApplication{ 'child' => [ // 权限补充 'plugin_cultural_space_contribution_index' => [ - 'name' => '变更明细', + 'name' => '贡献值管理', 'url' => 'plugin.cultural-space.admin.contribution.index', 'url_params' => '', 'permit' => 1, @@ -79,26 +79,6 @@ class PluginApplication extends \app\common\services\PluginApplication{ 'item' => 'plugin_cultural_space_contribution_index', 'parents' => ['cultural-space','plugin_cultural_space_contribution'] ], - 'plugin_cultural_space_contribution_hold' => [ - 'name' => '用户持有统计', - 'url' => 'plugin.cultural-space.admin.contribution.hold', - 'url_params' => '', - 'permit' => 1, - 'menu' => 0, - 'icon' => '', - 'item' => 'plugin_cultural_space_contribution_hold', - 'parents' => ['cultural-space','plugin_cultural_space_contribution'] - ], - 'plugin_cultural_space_contribution_bonus' => [ - 'name' => '分红记录', - 'url' => 'plugin.cultural-space.admin.contribution.bonus', - 'url_params' => '', - 'permit' => 1, - 'menu' => 0, - 'icon' => '', - 'item' => 'plugin_cultural_space_contribution_bonus', - 'parents' => ['cultural-space','plugin_cultural_space_contribution'] - ], ] ], 'plugin_cultural_space_set' => [ diff --git a/plugins/cultural-space/src/admin/ContributionController.php b/plugins/cultural-space/src/admin/ContributionController.php index 80f15135..c51db228 100644 --- a/plugins/cultural-space/src/admin/ContributionController.php +++ b/plugins/cultural-space/src/admin/ContributionController.php @@ -2,12 +2,13 @@ namespace Yunshop\CulturalSpace\admin; use app\common\components\BaseController; +use Yunshop\CulturalSpace\models\ContributionBonus; +use Yunshop\CulturalSpace\models\ContributionBonusLog; use Yunshop\CulturalSpace\models\ContributionLog; use Yunshop\CulturalSpace\models\CulturalSpace; class ContributionController extends BaseController{ - /** * Common: 变更明细 * Author: wu-hui @@ -19,18 +20,14 @@ class ContributionController extends BaseController{ if(request()->isMethod('post')){ // 参数获取 $search = request()->input('search'); + $tabsActive = request()->input('tabs_active'); // 获取变更记录 - $field = [ - 'id', - 'uid', - 'change_type', - 'change_quantity', - 'change_front', - 'change_after', - 'remark', - 'created_at' - ]; - $result = ContributionLog::getList($search,$field); + switch($tabsActive){ + case 'show_detail':$result = ContributionLog::getList($search);break;// 贡献值变更明细 + case 'show_group':$result = CulturalSpace::getList($search);break;// 贡献值用户持有统计 + case 'show_bonus':$result = ContributionBonusLog::getList($search);break;// 贡献值分红明细 + case 'show_cycle':$result = ContributionBonus::getList();break;// 贡献值分红周期记录 + } return $this->successJson('success',[ 'current_page' => $result['current_page'], @@ -41,30 +38,6 @@ class ContributionController extends BaseController{ return view('Yunshop\CulturalSpace::contribution.index')->render(); } - /** - * Common: 用户持有统计 - * Author: wu-hui - * Time: 2023/11/03 10:03 - * @return \Illuminate\Http\JsonResponse - */ - public function hold(){ - // 参数获取 - $search = request()->input('search'); - // 获取记录 - $result = CulturalSpace::getList($search); - - return $this->successJson('success',[ - 'current_page' => $result['current_page'], - 'data' => $result['data'], - 'last_page' => $result['last_page'], - ]); - } - // 分红记录 - public function bonus(){} - - - - diff --git a/plugins/cultural-space/src/models/ContributionBonus.php b/plugins/cultural-space/src/models/ContributionBonus.php index a011bc99..447f6d91 100644 --- a/plugins/cultural-space/src/models/ContributionBonus.php +++ b/plugins/cultural-space/src/models/ContributionBonus.php @@ -15,11 +15,34 @@ class ContributionBonus extends BaseModel{ public $timestamps = false; protected $hidden = ['uniacid']; public $casts = [ + 'start_time' => 'datetime:Y-m-d H:i:s', + 'end_time' => 'datetime:Y-m-d H:i:s', 'created_at' => 'datetime:Y-m-d H:i:s', ]; protected $fillable = ['uniacid','uid','order_total_money','contribution_bonus_ratio','total_money','start_time','end_time','created_at']; + /** + * Common: 获取周期记录列表 + * Author: wu-hui + * Time: 2023/11/03 16:00 + * @return array + */ + public function getList(){ + $list = self::uniacid() + ->select(['id','order_total_money','contribution_bonus_ratio','total_money','start_time','end_time','created_at']) + ->orderBy('created_at','DESC') + ->orderBy('id','DESC') + ->paginate(10); + + return $list ? $list->toArray() : []; + } + + + + + + diff --git a/plugins/cultural-space/src/models/ContributionBonusLog.php b/plugins/cultural-space/src/models/ContributionBonusLog.php index 984e2960..d7400079 100644 --- a/plugins/cultural-space/src/models/ContributionBonusLog.php +++ b/plugins/cultural-space/src/models/ContributionBonusLog.php @@ -3,6 +3,7 @@ namespace Yunshop\CulturalSpace\models; use app\common\models\BaseModel; +use app\common\models\Member; use app\common\models\Order; use app\common\models\OrderGoods; use app\common\models\UniAccount; @@ -24,6 +25,34 @@ class ContributionBonusLog extends BaseModel{ private $orderTotalMoney = 0;// 周期订单总金额 private $bonusTotalMoney = 0;// 分红总销售额(周期订单总金额的N%) + /** + * Common: 获取分红记录 + * Author: wu-hui + * Time: 2023/11/03 15:53 + * @param $search + * @return array + */ + public function getList($search){ + // 条件生成 + $where = []; + if($search['uid'] > 0) $where[] = ['uid','=',$search['uid']]; + if($search['is_settlement'] >= 0 && $search['is_settlement'] != '') $where[] = ['is_settlement','=',$search['is_settlement']]; + // 列表获取 + $list = self::uniacid() + ->select(['id','uid','total_money','money','total_contribution','hold_contribution','proportion','is_settlement','created_at']) + ->where($where) + ->with([ + 'member' => function($query){ + $query->select(['uid','nickname','realname','avatar']); + } + ]) + ->orderBy('created_at','DESC') + ->orderBy('id','DESC') + ->paginate(10); + + return $list ? $list->toArray() : []; + } + /** * Common: 贡献值分红 - 分红处理开始 @@ -192,120 +221,13 @@ class ContributionBonusLog extends BaseModel{ } - - - - - - - - /** - * Common: 店长信息统计 - 初始化 + * Common: 一对一关联 用户信息 * Author: wu-hui - * Time: 2023/09/18 14:46 + * Time: 2023/11/03 15:50 + * @return \Illuminate\Database\Eloquent\Relations\HasOne */ - public function infoStatistics(){ - set_time_limit(0); - try{ - // 循环平台 进行处理 - $uniAccount = UniAccount::getEnable() ?: []; - foreach ($uniAccount as $u) { - Setting::$uniqueAccountId = \YunShop::app()->uniacid = $u->uniacid; - $set = Setting::get('plugin.team_dividend'); - $isRun = (boolean)$this->isRun($set); - // 判断:允许下一步 开启店长 店补比例大于0 - if ($isRun && (int)$set['store_manager_switch'] == 1 && (float)$set['store_manager_proportion'] > 0) { - \Log::debug('--- 经销商 - 店长统计 - 满足条件,开始处理:'.$u->uniacid); - $this->infoStatisticsHandle($set); - } else { - \Log::debug('--- 经销商 - 店长统计 - 不满足条件:'.$u->uniacid); - } - } - }catch(\Exception $e){ - \Log::debug('--- 经销商 - 店长统计 - 错误:'.$e->getMessage()); - } + public function member(){ + return $this->hasOne(Member::class,'uid','uid'); } - /** - * Common: 店长信息统计 - 开始处理 - * Author: wu-hui - * Time: 2023/09/18 14:03 - * @param $set - */ - public function infoStatisticsHandle($set){ - // 获取所有店长 - $storeManagerList = self::uniacid() - ->select(['id','uid']) - ->where('status',1) - ->orderBy('id','DESC') - ->get(); - if(!$storeManagerList){ - \Log::debug('--- 经销商 - 店长统计 - 没有店长信息'); - return; - } - // 订单查询条件 - $storeManagerCycle = $set['store_manager_cycle'] ?? 'last_month'; - [$startTime,$endTime] = getTimeStamp($storeManagerCycle); - $where = [ - ['yz_order.pay_time','>=',$startTime], - ['yz_order.pay_time','<',$endTime], - ['yz_order_goods.payment_amount','>',0],// 实际支付金额必须大于0 - ]; - // 循环处理店长 - $storeIds = array_column($storeManagerList->toArray(),'uid'); - $insertData = []; - $time = time(); - foreach($storeManagerList as $storeInfo){ - // 获取全部有效下级 - $validChild = $this->getValidChild($storeInfo->uid,$storeIds); - $validChild[] = $storeInfo->uid;// 包括本人 - // 获取团队全部订单,这里以订单商品的实际支付价格算;统计已支付-待发货,已支付-待收货,已完成订单 - $totalMoney = (float)OrderGoods::uniacid() - ->join('yz_order', 'yz_order_goods.order_id', '=','yz_order.id') - ->where($where) - ->whereIn('yz_order.status',[Order::WAIT_SEND,Order::WAIT_RECEIVE,Order::COMPLETE]) - ->whereIn('yz_order.uid',$validChild) - ->sum('yz_order_goods.payment_amount'); - $insertData[] = [ - 'uniacid' => \YunShop::app()->uniacid, - 'uid' => $storeInfo->uid, - 'total_money' => $totalMoney, - 'money' => sprintf("%.2f",$totalMoney * (float)$set['store_manager_proportion'] / 100), - 'proportion' => (float)$set['store_manager_proportion'], - 'start_time' => $startTime, - 'end_time' => $endTime, - 'created_at' => $time, - ]; - } - // 添加记录 - StoreManagerRecordModel::insert($insertData); - - return; - } - /** - * Common: 店长信息统计 - 获取店长全部有效下级(去除店长及其团队的全部下级) - * Author: wu-hui - * Time: 2023/09/18 13:34 - * @param $uid - * @param $storeIds - * @return array - */ - public function getValidChild($uid,$storeIds){ - $allChild = MemberChild::uniacid()->where('member_id',$uid)->pluck('child_id')->toArray(); - $diff = array_values(array_intersect($allChild,$storeIds));// 获取交集 判断下级中是否存在店长 - if(count($diff) > 0){ - // 下级中存在店长 进行处理,剔除所有店长及其团队成员 - $subAllChild = MemberChild::uniacid()->whereIn('member_id',$diff)->pluck('child_id')->toArray(); - $delIds = array_values(array_merge($diff,$subAllChild)); - $allChild = array_diff($allChild,$delIds); - } - - return $allChild; - } - - - - - - } diff --git a/plugins/cultural-space/src/models/ContributionLog.php b/plugins/cultural-space/src/models/ContributionLog.php index 1ecb7cbd..4f9f9f81 100644 --- a/plugins/cultural-space/src/models/ContributionLog.php +++ b/plugins/cultural-space/src/models/ContributionLog.php @@ -34,17 +34,25 @@ class ContributionLog extends BaseModel{ * Author: wu-hui * Time: 2023/11/03 9:39 * @param $search - * @param string[] $field * @return array */ - public function getList($search,$field = ['*']){ + public function getList($search){ // 条件生成 $where = []; if($search['uid'] > 0) $where[] = ['uid','=',$search['uid']]; if($search['change_type'] >= 0 && $search['change_type'] != '') $where[] = ['change_type','=',$search['change_type']]; // 列表获取 $list = self::uniacid() - ->select($field) + ->select([ + 'id', + 'uid', + 'change_type', + 'change_quantity', + 'change_front', + 'change_after', + 'remark', + 'created_at' + ]) ->where($where) ->with([ 'member' => function($query){ diff --git a/plugins/cultural-space/views/contribution/index.blade.php b/plugins/cultural-space/views/contribution/index.blade.php index c9dffe1f..5611545a 100644 --- a/plugins/cultural-space/views/contribution/index.blade.php +++ b/plugins/cultural-space/views/contribution/index.blade.php @@ -82,7 +82,7 @@ {{--表单--}} - +