添加定时激活商户补贴

This commit is contained in:
luofei 2024-02-22 16:40:11 +08:00
parent 31d5a68c21
commit fdbe4e0626
3 changed files with 49 additions and 1 deletions

View File

@ -89,6 +89,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$isPlatformCard = true;
}
if ($isPlatformCard) {
$merchantTypeId = Merchant::where('uid', $uid)->value('type_id');
if ($merchantTypeId != 21) {
throw new ValidateException('大礼包仅限种养殖户购买');
}
//平台购物卡仅能购买一次
$productIds = ProductCate::where('mer_cate_id', env('PLATFORM_CARD_CATE_ID'))->column('product_id');
$orderRecord = StoreOrder::alias('t1')

View File

@ -0,0 +1,44 @@
<?php
namespace crmeb\listens;
use app\common\model\store\consumption\StoreConsumption;
use app\common\model\store\consumption\StoreConsumptionUser;
use app\common\model\store\order\StoreOrder;
use app\common\model\system\merchant\Merchant;
use crmeb\interfaces\ListenerInterface;
use crmeb\services\TimerService;
/**
* 定时任务:激活商户补贴
*/
class ActivateConsumptionListen extends TimerService implements ListenerInterface
{
public function handle($event): void
{
$this->tick(1000 * 60 * 10, function () {
$couponId = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->value('coupon_id');
if (empty($couponId)) {
return;
}
$storeConsumptionUser = StoreConsumptionUser::where('coupon_id', $couponId)
->where('status', StoreConsumptionUser::STATUS_REPEAL)
->select();
foreach ($storeConsumptionUser as $item) {
$isUsed = StoreConsumptionUser::where('order_id_set', $item['order_id_set'])
->where('balance', 0)
->count();
$merchantId = Merchant::where('uid', $item['uid'])->value('mer_id');
$saleTotal = StoreOrder::where('mer_id', $merchantId)->whereIn('status', [2, 3])->sum('pay_price');
if ($saleTotal >= $item['order_amount'] && $isUsed > 0) {
$item->status = StoreConsumptionUser::STATUS_UNUSED;
$item->start_time = date('Y-m-d H:i:s');
$item->end_time = date('Y-m-d H:i:s', strtotime('+1 year'));
$item->save();
}
}
});
}
}

View File

@ -31,7 +31,7 @@ class OrderDeliveryListen implements ListenerInterface
$repo->send($consumption, 1, $order['uid'], $order['group_order_id'], $order->total_price, StoreConsumptionUser::STATUS_UNUSED);
//TODO 当商户销售和购买达到指定金额后,激活抵扣补贴
$consumption = StoreConsumption::where('type', StoreConsumption::TYPE_OWNER_CONSUMPTION)->find();
$consumption = StoreConsumption::where('type', StoreConsumption::TYPE_RECHARGE)->find();
$repo->startTime = date('Y-m-d H:i:s');
$repo->endTime = '2025-07-01';
$rate = $this->getRate($order->total_price);