调整佣金发放和首单判断

This commit is contained in:
luofei 2024-01-29 11:03:51 +08:00
parent c015a8f00c
commit d738995aef
3 changed files with 18 additions and 21 deletions

View File

@ -36,8 +36,9 @@ class CommissionDao
if (!$isFirstOrder) {
return $finance;
}
$commission = bcmul($order['pay_price'], $consumption['config']['commission_rate'], 2);
if ($commission > 0) {
$commission = bcmul($order['pay_price'], 0.01, 2);
if ($commission > 0 && $order['order_type'] == 1) {
// 订单为自提且佣金大于0
$finance[] = [
'order_id' => $order->order_id,
'order_sn' => $order->order_sn,
@ -52,11 +53,7 @@ class CommissionDao
];
app()->make(MerchantRepository::class)->addLockMoney($order['mer_id'], 'order', $order['order_id'], $commission);
}
$redPack = bcmul($order['pay_price'], $consumption['config']['red_pack_rate'], 2);
if ($redPack > 0) {
$userId = Merchant::where('mer_id', $order['mer_id'])->value('uid');
$storeConsumptionDao->send($consumption, $consumption['config']['red_pack_rate'], $userId, $order['order_id'], $order['pay_price'], StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO);
}
// TODO 商户暂时没有推广码,只给村合伙人和小组服务团队分佣
$promotionCode = User::where('uid', $order['uid'])->value('promotion_code');
if (!empty($promotionCode)) {
$this->sendCommission($order, $promotionCode);
@ -109,14 +106,9 @@ class CommissionDao
continue;
}
$redPack = bcmul($order['pay_price'], $consumption['config']['red_pack_rate'], 2);
$user = User::where('phone', $user['account'])->find();
if ($redPack > 0 && !empty($user)) {
if ($redPack > 0) {
try {
(new StoreConsumptionUserDao())->send($consumption, $consumption['config']['red_pack_rate'], $user['uid'], $order['order_id'], $order['pay_price'], StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO);
$user->red_pack_balance = bcadd($user->red_pack_balance, $redPack, 2);
if (!$user->save()) {
throw new \Exception('红包余额更新出错');
}
(new StoreConsumptionUserDao())->send($consumption, $consumption['config']['red_pack_rate'], $order['uid'], $order['order_id'], $order['pay_price'], StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
@ -131,6 +123,7 @@ class CommissionDao
/**
* 给镇合伙人或推广人发放佣金(支付完成后调用,推广人仅首单奖励)
* 请求发送给供应商平台后异步回调
* 暂时取消镇合伙人佣金
* @param $order
* @param $promotionCode
* @param int $type 类型1=>小组2=>村合伙人3=>镇合伙人4=>配送员

View File

@ -8,6 +8,7 @@ use app\common\dao\store\StoreActivityUserDao;
use app\common\model\store\consumption\StoreConsumption;
use app\common\model\store\consumption\StoreConsumptionUser;
use app\common\model\store\order\StoreGroupOrder;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\StoreActivityOrder;
use app\common\model\user\User;
use app\common\repositories\user\UserBillRepository;
@ -273,7 +274,15 @@ class StoreConsumptionUserDao extends BaseDao
if ($isNewUser == 0) {
return 0;
}
$count = StoreGroupOrder::where('uid', $userId)->where('paid', 1)->whereBetweenTime('pay_time', $startTime, $endTime)->count();
$exceptGroupOrderIds = StoreOrder::where('uid', $userId)
->where('source', 105)
->group('group_order_id')
->column('group_order_id');
$count = StoreGroupOrder::where('uid', $userId)
->whereNotIn('group_order_id', $exceptGroupOrderIds)
->where('paid', 1)
->whereBetweenTime('pay_time', $startTime, $endTime)
->count();
return intval($count <= 1);
}

View File

@ -506,14 +506,9 @@ class StoreOrderRepository extends BaseRepository
], $order->mer_id);
//自动打印订单
$this->autoPrinter($order->order_id, $order->mer_id);
if ($order['pay_price'] > 0) {
if ($order['pay_price'] > 0 && $order['source'] != 105) {
// "惠农供销,谱写数字新篇章"活动首单分润,商户和村、小组合伙人
$finance = (new CommissionDao())->firstOrderCommission($order, $finance, $financeSn . ($i++));
$addressCode = explode(',', $order['user_address_code']);
// "惠农供销,谱写数字新篇章"活动首单分润,镇合伙人
if (!empty($addressCode[3])) {
(new CommissionDao())->sendCommission($order, $addressCode[3], 3);
}
}
}
//分销判断