Order.php 2.4 KB

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