添加:平台抽成 - 招商佣金和推广佣金到账(冻结中)
This commit is contained in:
parent
9eabc934a9
commit
b9a3852f19
|
|
@ -103,7 +103,7 @@ class StoreOrderDao extends BaseDao
|
||||||
->when(isset($where['is_spread']) && $where['is_spread'] !== '', function ($query) use ($where) {
|
->when(isset($where['is_spread']) && $where['is_spread'] !== '', function ($query) use ($where) {
|
||||||
if ($where['is_spread']) {
|
if ($where['is_spread']) {
|
||||||
$query->where(function($query) {
|
$query->where(function($query) {
|
||||||
$query->where('spread_uid','>',0)->whereOr('top_uid','>',0);
|
$query->where('StoreOrder.spread_uid','>',0)->whereOr('top_uid','>',0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -101,18 +101,44 @@ class UserBillDao extends BaseDao
|
||||||
* @author xaboy
|
* @author xaboy
|
||||||
* @day 2020/6/22
|
* @day 2020/6/22
|
||||||
*/
|
*/
|
||||||
public function lockBrokerage($uid)
|
public function lockBrokerage($uid){
|
||||||
{
|
// 减少佣金退款金额
|
||||||
$lst = UserBill::getDB()->where('category', 'brokerage')
|
$lst = UserBill::getDB()
|
||||||
->whereIn('type', ['order_one', 'order_two'])->where('uid', $uid)->where('status', 0)->field('link_id,number')->select()->toArray();
|
->where('category','brokerage')
|
||||||
|
->whereIn('type',['order_one','order_two'])
|
||||||
|
->where('uid',$uid)
|
||||||
|
->where('status',0)
|
||||||
|
->field('link_id,number')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
$refundPrice = 0;
|
$refundPrice = 0;
|
||||||
if(count($lst)){
|
if(count($lst)){
|
||||||
$refundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
|
$refundPrice = -1 * UserBill::getDB()
|
||||||
->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number');
|
->whereIn('link_id',array_column($lst,'link_id'))
|
||||||
|
->where('uid',$uid)
|
||||||
|
->where('category','brokerage')
|
||||||
|
->whereIn('type',['refund_two','refund_one'])
|
||||||
|
->sum('number');
|
||||||
}
|
}
|
||||||
foreach($lst as $bill){
|
foreach($lst as $bill){
|
||||||
$refundPrice = bcadd($refundPrice,$bill['number'],2);
|
$refundPrice = bcadd($refundPrice,$bill['number'],2);
|
||||||
}
|
}
|
||||||
|
// 招商佣金&推广员佣金
|
||||||
|
$commissionList = UserBill::getDB()->where('category', 'brokerage')
|
||||||
|
->whereIn('type', ['commission_merchants','commission_promoter'])
|
||||||
|
->where('uid', $uid)
|
||||||
|
->where('status', 0)
|
||||||
|
->field('link_id,number')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
// if (count($lst)) {
|
||||||
|
// $refundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
|
||||||
|
// ->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number');
|
||||||
|
// }
|
||||||
|
foreach ($commissionList as $billTwo) {
|
||||||
|
$refundPrice = bcadd($refundPrice, $billTwo['number'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
return $refundPrice;
|
return $refundPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ class UserBillRepository extends BaseRepository
|
||||||
'brokerage/order_two' => '获得二级推广佣金',
|
'brokerage/order_two' => '获得二级推广佣金',
|
||||||
'brokerage/refund_one' => '退还一级佣金',
|
'brokerage/refund_one' => '退还一级佣金',
|
||||||
'brokerage/refund_two' => '退还二级佣金',
|
'brokerage/refund_two' => '退还二级佣金',
|
||||||
|
'brokerage/commission_merchants' => '招商员佣金',
|
||||||
|
'brokerage/commission_promoter' => '推广员佣金',
|
||||||
'integral/cancel' => '退回积分',
|
'integral/cancel' => '退回积分',
|
||||||
'integral/deduction' => '购买商品',
|
'integral/deduction' => '购买商品',
|
||||||
'integral/points' => '兑换商品',
|
'integral/points' => '兑换商品',
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,15 @@ namespace app\controller\api;
|
||||||
|
|
||||||
use app\common\model\store\platformCommission\WeightValue;
|
use app\common\model\store\platformCommission\WeightValue;
|
||||||
use app\common\model\store\platformCommission\WeightValueLog;
|
use app\common\model\store\platformCommission\WeightValueLog;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
||||||
use app\common\repositories\store\order\StoreOrderRepository;
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
use app\common\repositories\store\order\StoreRefundOrderRepository;
|
use app\common\repositories\store\order\StoreRefundOrderRepository;
|
||||||
|
use app\common\repositories\store\platformCommission\RecordRepository;
|
||||||
use app\common\repositories\store\platformCommission\WeightValueRepository;
|
use app\common\repositories\store\platformCommission\WeightValueRepository;
|
||||||
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
|
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
|
||||||
|
use app\common\repositories\user\UserBillRepository;
|
||||||
use app\common\repositories\user\UserBrokerageRepository;
|
use app\common\repositories\user\UserBrokerageRepository;
|
||||||
use app\common\repositories\user\UserRepository;
|
use app\common\repositories\user\UserRepository;
|
||||||
use app\common\repositories\user\UserSignRepository;
|
use app\common\repositories\user\UserSignRepository;
|
||||||
|
|
@ -51,21 +55,6 @@ use crmeb\jobs\SendSmsJob;
|
||||||
class Auth extends BaseController
|
class Auth extends BaseController
|
||||||
{
|
{
|
||||||
public function test(){
|
public function test(){
|
||||||
// $data = [
|
|
||||||
// 'tempId' => '',
|
|
||||||
// 'id' => '',
|
|
||||||
// ];
|
|
||||||
// Queue::push(SendSmsJob::class,$data);
|
|
||||||
// $status = app()->make(SystemNoticeConfigRepository::class)->getNoticeStatusByConstKey($data['tempId']);
|
|
||||||
// if ($status['notice_sms'] == 1) {
|
|
||||||
// SmsService::sendMessage($data);
|
|
||||||
// }
|
|
||||||
// if ($status['notice_wechat'] == 1) {
|
|
||||||
// app()->make(WechatTemplateMessageService::class)->sendTemplate($data);
|
|
||||||
// }
|
|
||||||
// if ($status['notice_routine'] == 1) {
|
|
||||||
// app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 分销商升级模拟
|
// 分销商升级模拟
|
||||||
// $user = app()->make(UserRepository::class)->get(327706);
|
// $user = app()->make(UserRepository::class)->get(327706);
|
||||||
|
|
@ -75,8 +64,6 @@ class Auth extends BaseController
|
||||||
// ]);
|
// ]);
|
||||||
// debug(['升级结果'=>$res]);
|
// debug(['升级结果'=>$res]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// $userList = app()->make(WeightValueRepository::class)->getUserHoldList(327706);
|
// $userList = app()->make(WeightValueRepository::class)->getUserHoldList(327706);
|
||||||
// debug(['用户列表'=>$userList]);
|
// debug(['用户列表'=>$userList]);
|
||||||
// 订单支付成功 触发购买商品赠送上级权重值
|
// 订单支付成功 触发购买商品赠送上级权重值
|
||||||
|
|
@ -85,6 +72,10 @@ class Auth extends BaseController
|
||||||
// 'group_order_id' => 133
|
// 'group_order_id' => 133
|
||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\jobs\store\platformCommission;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\store\platformCommission\Record;
|
||||||
|
use app\common\repositories\store\platformCommission\RecordRepository;
|
||||||
|
use app\common\repositories\user\UserBillRepository;
|
||||||
|
use app\common\repositories\user\UserRepository;
|
||||||
|
use crmeb\interfaces\JobInterface;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 招商员佣金结算
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/12/27 16:38
|
||||||
|
* Class CommissionMerchantsSettlementJob
|
||||||
|
* @package app\jobs\store\platformCommission
|
||||||
|
*/
|
||||||
|
class CommissionMerchantsSettlementJob implements JobInterface{
|
||||||
|
|
||||||
|
public function fire($job,$data){
|
||||||
|
try{
|
||||||
|
Log::info('招商员佣金结算 - 开始处理: '.var_export($data,1));
|
||||||
|
$list = app()->make(RecordRepository::class)
|
||||||
|
->getSearch([])
|
||||||
|
->field(['id','uid','mer_id','order_id','commission_merchants_money'])
|
||||||
|
->whereIn('order_id',$data['order_ids'])
|
||||||
|
->where('commission_merchants_status',0)
|
||||||
|
->where('commission_merchants_money','>',0)
|
||||||
|
->with([
|
||||||
|
'mer' => function($query){
|
||||||
|
$query->field('mer_id,mer_name,mer_avatar,spread_uid as mer_spread_uid')->bind(['mer_name','mer_avatar','mer_spread_uid']);
|
||||||
|
},
|
||||||
|
'user' => function($query){
|
||||||
|
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
|
||||||
|
},
|
||||||
|
])
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
if($list){
|
||||||
|
$userBillRepository = app()->make(UserBillRepository::class);
|
||||||
|
$userRepository = app()->make(UserRepository::class);
|
||||||
|
$updateData = [];
|
||||||
|
foreach($list as $singleInfo){
|
||||||
|
if((int)$singleInfo['mer_spread_uid'] > 0){
|
||||||
|
$userBillRepository->incBill($singleInfo['mer_spread_uid'], 'brokerage', 'commission_merchants', [
|
||||||
|
'link_id' => $singleInfo['order_id'],
|
||||||
|
'status' => 0,
|
||||||
|
'title' => '获得招商佣金',
|
||||||
|
'number' => $singleInfo['commission_merchants_money'],
|
||||||
|
'mark' => $singleInfo['nickname'] . '在' . $singleInfo['mer_name'] . '进行消费,奖励招商佣金' . floatval($singleInfo['commission_merchants_money']),
|
||||||
|
'balance' => 0
|
||||||
|
]);
|
||||||
|
$userRepository->incBrokerage($singleInfo['mer_spread_uid'], $singleInfo['commission_merchants_money']);
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $singleInfo['id'],
|
||||||
|
'commission_merchants_status' => 1
|
||||||
|
];
|
||||||
|
}else{
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $singleInfo['id'],
|
||||||
|
'commission_merchants_status' => 2
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 修改成功信息
|
||||||
|
Record::batchUpdate(array_values($updateData));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
$data['error_msg'] = $e->getMessage();
|
||||||
|
Log::info('招商员佣金结算 - 失败: '.var_export($data,1));
|
||||||
|
}
|
||||||
|
$job->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function failed($data){
|
||||||
|
Log::info('招商员佣金结算 - 失败(failed): '.var_export($data,1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\jobs\store\platformCommission;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\store\platformCommission\Record;
|
||||||
|
use app\common\repositories\store\platformCommission\RecordRepository;
|
||||||
|
use app\common\repositories\user\UserBillRepository;
|
||||||
|
use app\common\repositories\user\UserRepository;
|
||||||
|
use crmeb\interfaces\JobInterface;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common: 推广员佣金结算
|
||||||
|
* Author: wu-hui
|
||||||
|
* Time: 2023/12/27 16:38
|
||||||
|
* Class CommissionMerchantsSettlementJob
|
||||||
|
* @package app\jobs\store\platformCommission
|
||||||
|
*/
|
||||||
|
class CommissionPromoterSettlementJob implements JobInterface{
|
||||||
|
|
||||||
|
public function fire($job,$data){
|
||||||
|
try{
|
||||||
|
Log::info('推广员佣金结算 - 开始处理: '.var_export($data,1));
|
||||||
|
$list = app()->make(RecordRepository::class)
|
||||||
|
->getSearch([])
|
||||||
|
->field(['id','uid','mer_id','order_id','commission_promoter_money'])
|
||||||
|
->whereIn('order_id',$data['order_ids'])
|
||||||
|
->where('commission_promoter_status',0)
|
||||||
|
->where('commission_promoter_money','>',0)
|
||||||
|
->with([
|
||||||
|
'user' => function($query){
|
||||||
|
$query->field('uid,nickname,avatar,spread_uid')->bind(['nickname','avatar','spread_uid']);
|
||||||
|
},
|
||||||
|
])
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
if($list){
|
||||||
|
$userBillRepository = app()->make(UserBillRepository::class);
|
||||||
|
$userRepository = app()->make(UserRepository::class);
|
||||||
|
$updateData = [];
|
||||||
|
foreach($list as $singleInfo){
|
||||||
|
if((int)$singleInfo['spread_uid'] > 0){
|
||||||
|
$userBillRepository->incBill($singleInfo['spread_uid'], 'brokerage', 'commission_promoter', [
|
||||||
|
'link_id' => $singleInfo['order_id'],
|
||||||
|
'status' => 0,
|
||||||
|
'title' => '获得推广佣金',
|
||||||
|
'number' => $singleInfo['commission_promoter_money'],
|
||||||
|
'mark' => $singleInfo['nickname'] . '进行消费,奖励推广佣金' . floatval($singleInfo['commission_promoter_money']),
|
||||||
|
'balance' => 0
|
||||||
|
]);
|
||||||
|
$userRepository->incBrokerage($singleInfo['spread_uid'], $singleInfo['commission_promoter_money']);
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $singleInfo['id'],
|
||||||
|
'commission_promoter_status' => 1
|
||||||
|
];
|
||||||
|
}else{
|
||||||
|
$updateData[] = [
|
||||||
|
'id' => $singleInfo['id'],
|
||||||
|
'commission_promoter_status' => 2
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 修改成功信息
|
||||||
|
Record::batchUpdate(array_values($updateData));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(\Exception $e){
|
||||||
|
$data['error_msg'] = $e->getMessage();
|
||||||
|
Log::info('推广员佣金结算 - 失败: '.var_export($data,1));
|
||||||
|
}
|
||||||
|
$job->delete();
|
||||||
|
}
|
||||||
|
public function failed($data){
|
||||||
|
Log::info('推广员佣金结算 - 失败(failed): '.var_export($data,1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -61,8 +61,8 @@ class GiveWeightValueJob implements JobInterface{
|
||||||
}
|
}
|
||||||
// 数据结果处理
|
// 数据结果处理
|
||||||
if(count($insertLogData) > 0){
|
if(count($insertLogData) > 0){
|
||||||
$res = WeightValue::batchUpdate(array_values($updateData));
|
WeightValue::batchUpdate(array_values($updateData));
|
||||||
$res = WeightValueLog::insertAll($insertLogData);
|
WeightValueLog::insertAll($insertLogData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(\Exception $e){
|
catch(\Exception $e){
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ namespace app\listener\platformCommission;
|
||||||
use app\common\model\store\platformCommission\Record;
|
use app\common\model\store\platformCommission\Record;
|
||||||
use app\common\model\system\merchant\Merchant;
|
use app\common\model\system\merchant\Merchant;
|
||||||
use app\common\repositories\store\platformCommission\RecordRepository;
|
use app\common\repositories\store\platformCommission\RecordRepository;
|
||||||
|
use app\jobs\store\platformCommission\CommissionMerchantsSettlementJob;
|
||||||
|
use app\jobs\store\platformCommission\CommissionPromoterSettlementJob;
|
||||||
use app\jobs\store\platformCommission\GiveWeightValueJob;
|
use app\jobs\store\platformCommission\GiveWeightValueJob;
|
||||||
use crmeb\jobs\UserBrokerageLevelJob;
|
use crmeb\jobs\UserBrokerageLevelJob;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
|
|
@ -47,7 +49,9 @@ class OrderPaySuccessEvent{
|
||||||
}
|
}
|
||||||
// 循环处理单个商品抽成信息
|
// 循环处理单个商品抽成信息
|
||||||
$insertData = [];
|
$insertData = [];
|
||||||
|
$orderIds = [];
|
||||||
foreach($groupOrder->orderList as $orderInfo){
|
foreach($groupOrder->orderList as $orderInfo){
|
||||||
|
$orderIds[] = $orderInfo->order_id;
|
||||||
foreach($orderInfo->orderProduct as $orderProductInfo){
|
foreach($orderInfo->orderProduct as $orderProductInfo){
|
||||||
// 获取商户设置抽成比例 获取抽成总金额
|
// 获取商户设置抽成比例 获取抽成总金额
|
||||||
$platformCommissionRate = (float)Merchant::getDB()->where('mer_id', $orderInfo->mer_id)->value('platform_commission');
|
$platformCommissionRate = (float)Merchant::getDB()->where('mer_id', $orderInfo->mer_id)->value('platform_commission');
|
||||||
|
|
@ -79,8 +83,19 @@ class OrderPaySuccessEvent{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 记录平台抽成信息
|
||||||
|
if(count($insertData) > 0){
|
||||||
Record::insertAll($insertData);
|
Record::insertAll($insertData);
|
||||||
|
// 招商员佣金结算
|
||||||
|
Queue::push(CommissionMerchantsSettlementJob::class,[
|
||||||
|
'order_ids' => $orderIds
|
||||||
|
]);
|
||||||
|
// 推广员佣金结算
|
||||||
|
Queue::push(CommissionPromoterSettlementJob::class,[
|
||||||
|
'order_ids' => $orderIds
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue