添加商户销售补贴发放
This commit is contained in:
parent
7f38a8183e
commit
5abee67569
@ -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'];
|
||||
|
@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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],
|
||||
|
52
crmeb/listens/SendSubsidyCouponListen.php
Normal file
52
crmeb/listens/SendSubsidyCouponListen.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\listens;
|
||||
|
||||
use app\common\dao\store\consumption\StoreConsumptionUserDao;
|
||||
use app\common\model\store\consumption\StoreConsumption;
|
||||
use app\common\model\store\consumption\StoreConsumptionUser;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use crmeb\interfaces\ListenerInterface;
|
||||
use crmeb\services\TimerService;
|
||||
use think\facade\Log;
|
||||
|
||||
class SendSubsidyCouponListen extends TimerService implements ListenerInterface
|
||||
{
|
||||
|
||||
public function handle($event): void
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user