MonthOrderPaySuccess.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Modules\Trade\Pay;
  3. use App\Modules\Subscribe\Models\Order;
  4. use App\Modules\Subscribe\Models\YearOrder;
  5. class MonthOrderPaySuccess extends PaySuccessAbstract
  6. {
  7. private $year_order;
  8. public function __construct(Order $order)
  9. {
  10. parent::__construct($order);
  11. $this->year_order = [];
  12. $this->year_order['uid'] = $order->uid;
  13. $this->year_order['distribution_channel_id'] = $order->distribution_channel_id;
  14. $this->year_order['fee'] = $order->price;
  15. $this->year_order['send_order_id'] = $order->send_order_id;
  16. }
  17. protected function handlePayProcess()
  18. {
  19. $this->year_order['begin_time'] = date('Y-m-d H:i:s');
  20. $this->year_order['end_time'] = date('Y-m-d H:i:s', strtotime('+31 day'));
  21. $old = YearOrder::where('uid', $this->year_order['uid'])->select('id', 'uid', 'u', 'begin_time', 'end_time', 'fee')->first();
  22. if ($old) {
  23. //如果包过年
  24. if (strtotime($old->end_time) > time()) {
  25. //旧的包年没过期
  26. $old->end_time = date('Y-m-d H:i:s', strtotime($old->end_time) + 86400 * 30);
  27. $old->fee = $old->fee + $this->year_order['fee'];
  28. $old->save();
  29. } else {
  30. //旧的包年过期了
  31. $old->end_time = date('Y-m-d H:i:s', strtotime('+30 day'));
  32. $old->fee = $old->fee + $this->year_order['fee'];
  33. $old->save();
  34. }
  35. return $old;
  36. } else {
  37. return YearOrder::firstOrCreate($this->year_order);
  38. }
  39. }
  40. }