diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index e088f138..392aa73d 100755 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -236,12 +236,15 @@ class StoreConsumptionUserDao extends BaseDao */ public function send($consumption, float $rate, int $userId, string $groupOrderIds, float $amount, $status = -2, $type = 1) { - $title = $type == StoreConsumptionUser::TYPE_TWO ? '春耕采购补贴' : '春耕采购余额'; + $title = $type == StoreConsumptionUser::TYPE_TWO ? '补贴' : '春耕采购余额'; $model = StoreConsumptionUser::where('uid', $userId)->where('type', StoreConsumptionUser::TYPE_TWO)->find(); $couponPrice = bcmul($amount, $rate, 2); if (!empty($model) && $model['type'] == $type) { $model->coupon_price = bcadd($model->coupon_price, $couponPrice, 2); $model->balance = bcadd($model->balance, $couponPrice, 2); + if ($model->status != StoreConsumptionUser::STATUS_UNUSED) { + $model->status = StoreConsumptionUser::STATUS_UNUSED; + } } else { $model = new StoreConsumptionUser(); $model->coupon_id = $consumption['coupon_id']; diff --git a/app/common/model/store/consumption/StoreConsumption.php b/app/common/model/store/consumption/StoreConsumption.php index 869a28d2..9708e755 100755 --- a/app/common/model/store/consumption/StoreConsumption.php +++ b/app/common/model/store/consumption/StoreConsumption.php @@ -16,6 +16,7 @@ class StoreConsumption extends BaseModel const TYPE_PULL_CONSUMPTION = 14; //拉新消费金 const TYPE_FIRST_ORDER_COMMISSION = 15; //首单佣金 const TYPE_RECHARGE = 16; //充值赠送 + const TYPE_SALE_SUBSIDY = 17; //销售补贴 public static function tablePk(): string { @@ -27,4 +28,4 @@ class StoreConsumption extends BaseModel return 'store_consumption'; } -} \ No newline at end of file +} diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 132e173e..6ca00e06 100755 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -589,6 +589,8 @@ class MerchantRepository extends BaseRepository $bill->save(); } if ($money > 0) { + //订单确认收货,增加商户销售金额 + Merchant::where('mer_id', $bill->mer_id)->update(['sale_amount' => Db::raw('sale_amount+' . $money)]); app()->make(UserBillRepository::class)->incBill($bill->uid, 'mer_computed_money', 'order', [ 'link_id' => $order->order_id, 'mer_id' => $bill->mer_id, diff --git a/app/event.php b/app/event.php index c5645222..1add50b7 100755 --- a/app/event.php +++ b/app/event.php @@ -58,6 +58,7 @@ return [ \crmeb\listens\AutoCheckCreditBuyListen::class, \crmeb\listens\ActivateConsumptionListen::class, \crmeb\listens\SetProductProfitRateListen::class, + \crmeb\listens\SendSubsidyCouponListen::class, ] : [], 'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class], 'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class], diff --git a/crmeb/listens/SendSubsidyCouponListen.php b/crmeb/listens/SendSubsidyCouponListen.php new file mode 100644 index 00000000..63375971 --- /dev/null +++ b/crmeb/listens/SendSubsidyCouponListen.php @@ -0,0 +1,52 @@ +tick(1000 * 60 * 20, function () { + Log::info('定时任务:发放商户采购补贴券'); + try { + $consumption = StoreConsumption::where('type', StoreConsumption::TYPE_SALE_SUBSIDY)->find(); + $count = 0; + if ($consumption) { + foreach ($consumption['config'] as $item) { + $purchaseAmount = $item['amount'] * 0.5; + $merchants = Merchant::whereIn('type_id', $item['type_id']) + ->where('sale_amount', '>=', $item['amount']) + ->where('purchase_amount', '>=', $purchaseAmount) + ->select(); + foreach ($merchants as $merchant) { + //商户已获得的补贴金额 + $gotSubsidy = StoreConsumptionUser::where('coupon_id', $consumption['coupon_id']) + ->where('uid', $merchant->uid) + ->value('coupon_price'); + if ($gotSubsidy >= $item['subsidy']) { + continue; + } + //补贴金额为当前补贴减去已获得的补贴 + $amount = bcsub($item['subsidy'], $gotSubsidy, 2); + $consumptionRepo = new StoreConsumptionUserDao(); + $consumptionRepo->send($consumption, 1, $merchant->uid, 0, $amount, StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO); + $count++; + } + } + } + Log::info('定时任务:发放商户采购补贴券,成功数量:' . $count); + } catch (\Throwable $e) { + Log::info('定时任务:发放商户采购补贴券,error => ' . $e->getMessage()); + } + }); + } +}