Order.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\task\model\sharing;
  3. use app\common\model\sharing\Order as OrderModel;
  4. use app\common\service\order\Refund as RefundService;
  5. /**
  6. * 拼团订单模型
  7. * Class Order
  8. * @package app\common\model\sharing
  9. */
  10. class Order extends OrderModel
  11. {
  12. /**
  13. * 获取订单列表
  14. * @param array $filter
  15. * @param array $with
  16. * @return false|\PDOStatement|string|\think\Collection
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function getList($filter = [], $with = [])
  22. {
  23. return $this->with($with)
  24. ->where($filter)
  25. ->where('is_delete', '=', 0)
  26. ->select();
  27. }
  28. /**
  29. * 获取拼团失败的订单
  30. * @param int $limit
  31. * @return false|\PDOStatement|string|\think\Collection
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. * @throws \think\exception\DbException
  35. */
  36. public function getFailedOrderList($limit = 100)
  37. {
  38. return $this->alias('order')
  39. ->join('sharing_active active', 'order.active_id = active.active_id', 'INNER')
  40. ->where('order_type', '=', 20)
  41. ->where('pay_status', '=', 20)
  42. ->where('order_status', '=', 10)
  43. ->where('active.status', '=', 30)
  44. ->where('is_refund', '=', 0)
  45. ->where('order.is_delete', '=', 0)
  46. ->limit($limit)
  47. ->select();
  48. }
  49. /**
  50. * 更新拼团失败的订单并退款
  51. * @param $orderList
  52. * @return bool
  53. */
  54. public function updateFailedStatus($orderList)
  55. {
  56. // 批量更新订单状态
  57. foreach ($orderList as $order) {
  58. /* @var static $order */
  59. try {
  60. // 执行退款操作
  61. (new RefundService)->execute($order);
  62. // 更新订单状态
  63. $order->save([
  64. 'is_refund' => 1,
  65. 'order_status' => '20'
  66. ]);
  67. } catch (\Exception $e) {
  68. $this->error = '订单ID:' . $order['order_id'] . ' 退款失败,错误信息:' . $e->getMessage();
  69. return false;
  70. }
  71. }
  72. return true;
  73. }
  74. }