添加激活商户补贴定时任务
This commit is contained in:
parent
35eb3d2010
commit
004e200f42
@ -61,9 +61,10 @@ class StoreCouponDetail extends BaseModel
|
||||
* @param $order
|
||||
* @param $id
|
||||
* @param $amount
|
||||
* @param $status
|
||||
* @return void
|
||||
*/
|
||||
public static function income($order, $id, $amount)
|
||||
public static function income($order, $id, $amount, $status = 1)
|
||||
{
|
||||
$detailModel = new self();
|
||||
$detailModel->uid = $order['uid'];
|
||||
@ -73,6 +74,7 @@ class StoreCouponDetail extends BaseModel
|
||||
$detailModel->type = StoreCouponDetail::TYPE_INCOME;
|
||||
$detailModel->amount = $amount;
|
||||
$detailModel->pay_price = $order['pay_price'];
|
||||
$detailModel->status = $status;
|
||||
$detailModel->create_time = time();
|
||||
$detailModel->save();
|
||||
}
|
||||
|
@ -36,6 +36,11 @@ class StoreCouponUserRepository extends BaseRepository
|
||||
const SEND_TYPE_SEND = 'send';
|
||||
const SEND_TYPE_GIVE = 'give';
|
||||
const SEND_TYPE_NEW = 'new';
|
||||
|
||||
const STATUS_REPEAL = -1; //作废的
|
||||
const STATUS_UNUSED = 0; //未使用的
|
||||
const STATUS_USED = 1; //已使用的
|
||||
const STATUS_EXPIRED = 2; //过期的
|
||||
/**
|
||||
* @var StoreCouponUserDao
|
||||
*/
|
||||
|
@ -56,6 +56,7 @@ return [
|
||||
\crmeb\listens\SendSvipCouponListen::class,
|
||||
\crmeb\listens\SyncMerchantMarginStatusListen::class,
|
||||
\crmeb\listens\SyncQueueStatusListen::class,
|
||||
\crmeb\listens\ActivateCouponListen::class,
|
||||
] : [],
|
||||
'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class],
|
||||
'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class],
|
||||
@ -63,7 +64,7 @@ return [
|
||||
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
|
||||
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
|
||||
//数据大屏
|
||||
'data.screen.send' =>[\crmeb\listens\DataScreenListen::class],
|
||||
'data.screen.send' => [\crmeb\listens\DataScreenListen::class],
|
||||
//操作日志
|
||||
'create_operate_log' => [\crmeb\listens\CreateOperateLogListen::class], // 操作日志事件
|
||||
'mini_order_shipping' => [\crmeb\listens\MiniOrderShippingListen::class], // 小程序发货管理事件
|
||||
|
62
crmeb/listens/ActivateCouponListen.php
Normal file
62
crmeb/listens/ActivateCouponListen.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\listens;
|
||||
|
||||
use app\common\dao\store\order\StoreOrderDao;
|
||||
use app\common\model\store\coupon\StoreCoupon;
|
||||
use app\common\model\store\coupon\StoreCouponDetail;
|
||||
use app\common\model\store\coupon\StoreCouponUser;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
use crmeb\interfaces\ListenerInterface;
|
||||
use crmeb\services\TimerService;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 定时任务:激活商户补贴
|
||||
*/
|
||||
class ActivateCouponListen extends TimerService implements ListenerInterface
|
||||
{
|
||||
|
||||
public function handle($event): void
|
||||
{
|
||||
$this->tick(1000 * 60, function () {
|
||||
Log::info('定时任务:激活商户补贴');
|
||||
try {
|
||||
$couponId = StoreCoupon::where('type', StoreCouponRepository::TYPE_STORE_COUPON)
|
||||
->where('send_type', StoreCouponRepository::GET_COUPON_TYPE_PAY)
|
||||
->value('coupon_id');
|
||||
if (empty($couponId)) {
|
||||
return;
|
||||
}
|
||||
$storeCouponUser = StoreCouponUser::where('coupon_id', $couponId)
|
||||
->where('coupon_type', StoreCouponRepository::TYPE_STORE_COUPON)
|
||||
->where('buy', StoreCouponUserRepository::SEND_TYPE_BUY)
|
||||
->where('status', StoreCouponUserRepository::STATUS_REPEAL)
|
||||
->select();
|
||||
foreach ($storeCouponUser as $item) {
|
||||
$mainCouponId = StoreCouponDetail::where('order_id', $item['order_id'])
|
||||
->where('type', StoreCouponDetail::TYPE_INCOME)
|
||||
->value('coupon_user_id');
|
||||
$couponBalance = StoreCouponUser::where('coupon_user_id', $mainCouponId)->value('coupon_price');
|
||||
$merchantId = Merchant::where('uid', $item['uid'])->value('mer_id');
|
||||
$saleTotal = StoreOrder::where('mer_id', $merchantId)
|
||||
->whereIn('status', [StoreOrderDao::ORDER_STATUS_REPLY, StoreOrderDao::ORDER_STATUS_SUCCESS])
|
||||
->sum('total_price');
|
||||
if ($saleTotal >= $item['origin_price'] && $couponBalance <= 0) {
|
||||
$item->status = StoreCouponUserRepository::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();
|
||||
StoreCouponDetail::where('coupon_user_id', $item['coupon_user_id'])->update(['status', 1]);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::info('定时任务:激活商户补贴,error => ' . $e->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -43,7 +43,7 @@ class OrderDeliveryListen implements ListenerInterface
|
||||
$repo->endTime = '2025-07-01';
|
||||
$repo->status = -1;
|
||||
$couponUser = $repo->sendCoupon($giveCoupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
|
||||
StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price);
|
||||
StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price, 0);
|
||||
} catch (\Exception $e) {
|
||||
Log::info('自动发放买赠优惠券:' . $e->getMessage());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user