Order.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\timer\model;
  13. use app\common\model\Order as OrderModel;
  14. use app\common\enum\order\PayStatus as PayStatusEnum;
  15. use app\common\enum\order\OrderStatus as OrderStatusEnum;
  16. use app\common\enum\order\OrderSource as OrderSourceEnum;
  17. use app\common\enum\order\ReceiptStatus as ReceiptStatusEnum;
  18. use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
  19. /**
  20. * 订单模型
  21. * Class Order
  22. * @package app\common\model
  23. */
  24. class Order extends OrderModel
  25. {
  26. /**
  27. * 获取订单列表
  28. * @param int $storeId 商城ID
  29. * @param array $filter
  30. * @param array $with
  31. * @return \think\Collection
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function getList(int $storeId, array $filter = [], array $with = []): \think\Collection
  37. {
  38. return $this->with($with)
  39. ->where($filter)
  40. ->where('store_id', '=', $storeId)
  41. ->where('is_delete', '=', 0)
  42. ->select();
  43. }
  44. /**
  45. * 获取订单ID集
  46. * @param int $storeId 商城ID
  47. * @param array $filter
  48. * @return array
  49. */
  50. public function getOrderIds(int $storeId, array $filter = []): array
  51. {
  52. return $this->where($filter)
  53. ->where('store_id', '=', $storeId)
  54. ->where('is_delete', '=', 0)
  55. ->column('order_id');
  56. }
  57. /**
  58. * 查询截止时间未支付的订单列表
  59. * @param int $storeId 商城ID
  60. * @param int $deadlineTime 截止日期的时间戳
  61. * @param int|null $orderSource 订单来源(默认为全部)
  62. * @return \think\Collection
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\DbException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. */
  67. public function getListByClose(int $storeId, int $deadlineTime, int $orderSource = null): \think\Collection
  68. {
  69. // 查询条件
  70. $filter = [
  71. ['pay_status', '=', PayStatusEnum::PENDING],
  72. ['order_status', '=', OrderStatusEnum::NORMAL],
  73. ['create_time', '<=', $deadlineTime],
  74. ];
  75. // 订单来源
  76. !empty($orderSource) && $filter[] = ['order_source', '=', $orderSource];
  77. // 查询列表记录
  78. return $this->getList($storeId, $filter, ['goods', 'user']);
  79. }
  80. /**
  81. * 查询截止时间已完成的订单列表
  82. * @param int $storeId 商城ID
  83. * @param array $orderIds 订单ID集
  84. * @return \think\Collection
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\DbException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. */
  89. public function getListByOrderIds(int $storeId, array $orderIds): \think\Collection
  90. {
  91. // 查询条件
  92. $filter = [['order_id', 'in', $orderIds]];
  93. // 查询列表记录
  94. return $this->getList($storeId, $filter, ['goods' => ['refund']]);
  95. }
  96. /**
  97. * 查询截止时间未确认收货的订单ID集
  98. * @param int $storeId 商城ID
  99. * @param int $deadlineTime 截止时间
  100. * @return array
  101. */
  102. public function getOrderIdsByReceive(int $storeId, int $deadlineTime): array
  103. {
  104. // 查询条件
  105. $filter = [
  106. ['pay_status', '=', PayStatusEnum::SUCCESS],
  107. ['delivery_status', '=', DeliveryStatusEnum::DELIVERED],
  108. ['receipt_status', '=', ReceiptStatusEnum::NOT_RECEIVED],
  109. ['delivery_time', '<=', $deadlineTime]
  110. ];
  111. // 查询列表记录
  112. return $this->getOrderIds($storeId, $filter);
  113. }
  114. /**
  115. * 查询截止时间确认收货的订单列表
  116. * @param int $storeId 商城ID
  117. * @param int $deadlineTime 截止时间
  118. * @return \think\Collection
  119. * @throws \think\db\exception\DataNotFoundException
  120. * @throws \think\db\exception\DbException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. */
  123. public function getOrderListBySettled(int $storeId, int $deadlineTime): \think\Collection
  124. {
  125. // 查询条件
  126. $filter = [
  127. ['order_status', '=', OrderStatusEnum::COMPLETED],
  128. ['receipt_time', '<=', $deadlineTime],
  129. ['is_settled', '=', 0]
  130. ];
  131. // 查询列表记录
  132. return $this->getList($storeId, $filter, ['goods.refund']);
  133. }
  134. /**
  135. * 批量更新订单状态为已收货
  136. * @param array $orderIds 订单ID集
  137. * @return false|int
  138. */
  139. public function onUpdateReceived(array $orderIds)
  140. {
  141. return $this->onBatchUpdate($orderIds, [
  142. 'receipt_status' => ReceiptStatusEnum::RECEIVED,
  143. 'receipt_time' => time(),
  144. 'order_status' => OrderStatusEnum::COMPLETED
  145. ]);
  146. }
  147. }