RechargeOrderPaySuccess.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Modules\Trade\Pay;
  3. use App\Jobs\UserBalanceJob;
  4. use App\Modules\Product\Models\Product;
  5. use App\Modules\Subscribe\Models\Order;
  6. use App\Modules\User\Models\User;
  7. use DB;
  8. /**
  9. *
  10. * @property \App\Modules\Product\Models\Product $product
  11. */
  12. class RechargeOrderPaySuccess extends PaySuccessAbstract
  13. {
  14. private $product;
  15. public function __construct(Order $order)
  16. {
  17. parent::__construct($order);
  18. $this->product = Product::find($order->product_id);
  19. }
  20. protected function handlePayProcess()
  21. {
  22. $charge = $this->product->price * 100;
  23. $given = $this->product->given;
  24. $uid = $this->order->uid;
  25. User::where('id', $uid)->update(
  26. [
  27. 'balance' => DB::raw('balance+' . ($charge + $given)),
  28. 'charge_balance' => DB::raw('charge_balance+' . $charge),
  29. 'reward_balance' => DB::raw('reward_balance+' . $given),
  30. ]
  31. );
  32. try{
  33. $job = (new UserBalanceJob($uid,1,$charge,1,'充值'))->onConnection('rabbitmq')->delay(0)->onQueue('user_balance_job');
  34. dispatch($job);
  35. if($given){
  36. $job = (new UserBalanceJob($uid,2,$given,2,'充送'))->onConnection('rabbitmq')->delay(0)->onQueue('user_balance_job');
  37. dispatch($job);
  38. }
  39. }catch (\Exception $e){
  40. myLog('UserBalanceJob')->info($e);
  41. }
  42. }
  43. }