Order.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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\console\model;
  13. use app\common\enum\order\DeliveryStatus;
  14. use app\common\enum\order\ReceiptStatus;
  15. use app\common\model\Order as OrderModel;
  16. use app\common\enum\order\PayStatus as PayStatusEnum;
  17. use app\common\enum\order\OrderStatus as OrderStatusEnum;
  18. /**
  19. * 订单模型
  20. * Class Order
  21. * @package app\common\model
  22. */
  23. class Order extends OrderModel
  24. {
  25. /**
  26. * 获取订单列表
  27. * @param int $storeId 商城ID
  28. * @param array $filter
  29. * @param array $with
  30. * @return \think\Collection
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public function getList(int $storeId, $filter = [], $with = [])
  36. {
  37. return $this->with($with)
  38. ->where($filter)
  39. ->where('store_id', '=', $storeId)
  40. ->where('is_delete', '=', 0)
  41. ->select();
  42. }
  43. /**
  44. * 未发货列表
  45. * @param int $storeId
  46. * @param array $filter
  47. * @param array $with
  48. * @return Order[]|array|\think\Collection
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getUsableList(int $storeId, array $filter = [])
  54. {
  55. // 获取数据列表
  56. return $this->with(['goods', 'address'])
  57. ->where($filter)
  58. ->where('store_id', '=', $storeId)
  59. ->where('pay_status', '=', PayStatusEnum::SUCCESS)
  60. ->where('delivery_status', '=', DeliveryStatus::NOT_DELIVERED)
  61. ->where('order_status', '=', OrderStatusEnum::NORMAL)
  62. ->where('is_delete', '=', 0)
  63. ->limit(1)
  64. ->select();
  65. }
  66. /**
  67. * 获取订单ID集
  68. * @param int $storeId 商城ID
  69. * @param array $filter
  70. * @return array
  71. */
  72. public function getOrderIds(int $storeId, $filter = [])
  73. {
  74. return $this->where($filter)
  75. ->where('store_id', '=', $storeId)
  76. ->where('is_delete', '=', 0)
  77. ->column('order_id');
  78. }
  79. /**
  80. * 查询截止时间未支付的订单列表
  81. * @param int $storeId 商城ID
  82. * @param int $deadlineTime 截止日期的时间戳
  83. * @return \think\Collection
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\DbException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. */
  88. public function getListByClose(int $storeId, int $deadlineTime)
  89. {
  90. // 查询条件
  91. $filter = [
  92. ['pay_status', '=', PayStatusEnum::PENDING],
  93. ['order_status', '=', OrderStatusEnum::NORMAL],
  94. ['create_time', '<=', $deadlineTime],
  95. ];
  96. // 查询列表记录
  97. return $this->getList($storeId, $filter, ['goods', 'user']);
  98. }
  99. /**
  100. * 查询截止时间已完成的订单列表
  101. * @param int $storeId 商城ID
  102. * @param array $orderIds 订单ID集
  103. * @return \think\Collection
  104. * @throws \think\db\exception\DataNotFoundException
  105. * @throws \think\db\exception\DbException
  106. * @throws \think\db\exception\ModelNotFoundException
  107. */
  108. public function getListByOrderIds(int $storeId, array $orderIds)
  109. {
  110. // 查询条件
  111. $filter = [['order_id', 'in', $orderIds]];
  112. // 查询列表记录
  113. return $this->getList($storeId, $filter, ['goods' => ['refund']]);
  114. }
  115. /**
  116. * 查询截止时间未确认收货的订单ID集
  117. * @param int $storeId 商城ID
  118. * @param int $deadlineTime 截止时间
  119. * @return array
  120. */
  121. public function getOrderIdsByReceive(int $storeId, int $deadlineTime)
  122. {
  123. // 查询条件
  124. $filter = [
  125. ['pay_status', '=', PayStatusEnum::SUCCESS],
  126. ['delivery_status', '=', DeliveryStatus::DELIVERED],
  127. ['receipt_status', '=', ReceiptStatus::NOT_RECEIVED],
  128. ['delivery_time', '<=', $deadlineTime]
  129. ];
  130. // 查询列表记录
  131. return $this->getOrderIds($storeId, $filter);
  132. }
  133. /**
  134. * 查询截止时间确认收货的订单列表
  135. * @param int $storeId 商城ID
  136. * @param int $deadlineTime 截止时间
  137. * @return \think\Collection
  138. * @throws \think\db\exception\DataNotFoundException
  139. * @throws \think\db\exception\DbException
  140. * @throws \think\db\exception\ModelNotFoundException
  141. */
  142. public function getOrderListBySettled(int $storeId, int $deadlineTime)
  143. {
  144. // 查询条件
  145. $filter = [
  146. ['order_status', '=', OrderStatusEnum::COMPLETED],
  147. ['receipt_time', '<=', $deadlineTime],
  148. ['is_settled', '=', 0]
  149. ];
  150. // 查询列表记录
  151. return $this->getList($storeId, $filter, ['goods.refund']);
  152. }
  153. /**
  154. * 批量更新订单状态为已收货
  155. * @param array $orderIds
  156. * @return false|int
  157. */
  158. public function onUpdateReceived(array $orderIds)
  159. {
  160. return $this->onBatchUpdate($orderIds, [
  161. 'receipt_status' => ReceiptStatus::RECEIVED,
  162. 'receipt_time' => time(),
  163. 'order_status' => OrderStatusEnum::COMPLETED
  164. ]);
  165. }
  166. }