56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Bonus\Direct;
|
|
use App\Models\ActivityLog;
|
|
use App\Notifications\OrderPaied as OrderPaiedNotifications;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use RuLong\Coupon\Models\CouponUserLog;
|
|
use RuLong\Order\Events\OrderPaid as OrderPaidEvent;
|
|
|
|
class OrderPaidListener implements ShouldQueue
|
|
{
|
|
|
|
public $queue = 'LISTENER';
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param OrderPaidEvent $event
|
|
* @return void
|
|
*/
|
|
public function handle(OrderPaidEvent $event)
|
|
{
|
|
$order = $event->order;
|
|
if ($order->item_type == 'LESSON') {
|
|
Direct::settlement($order->user, ['orderid' => $order->id]);
|
|
if ($order->user->identity->identity_id === 0) {
|
|
$order->user->identityUpdate(1, 'AutoUp');
|
|
}
|
|
$order->delcart(); //删除购物车
|
|
$order->user->increment('lottery_num'); //增加一次抽奖机会
|
|
$order->createGift(); //创建赠品订单
|
|
$order->lessonlogs()->update(['status' => 1]); //更新课程状态
|
|
}
|
|
|
|
if ($order->item_type == 'ACTIVITY') {
|
|
ActivityLog::create([
|
|
'order_id' => $order->id,
|
|
'user_id' => $order->user_id,
|
|
'activity_id' => $order->detail->item_id,
|
|
]);
|
|
}
|
|
|
|
if ($order->couponuse) {
|
|
$couponuserlog = CouponUserLog::where('user_id', $order->user_id)->where('coupon_id', $order->couponuse->coupon_id)->first();
|
|
if ($couponuserlog) {
|
|
$couponuserlog->update(['status' => 1]);
|
|
}
|
|
}
|
|
|
|
\Notification::send($event->order->user, new OrderPaiedNotifications($event->order));
|
|
|
|
}
|
|
}
|