Order.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * 获取订单ID集
  45. * @param int $storeId 商城ID
  46. * @param array $filter
  47. * @return array
  48. */
  49. public function getOrderIds(int $storeId, $filter = [])
  50. {
  51. return $this->where($filter)
  52. ->where('store_id', '=', $storeId)
  53. ->where('is_delete', '=', 0)
  54. ->column('order_id');
  55. }
  56. /**
  57. * 查询截止时间未支付的订单列表
  58. * @param int $storeId 商城ID
  59. * @param int $deadlineTime 截止日期的时间戳
  60. * @return \think\Collection
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function getListByClose(int $storeId, int $deadlineTime)
  66. {
  67. // 查询条件
  68. $filter = [
  69. ['pay_status', '=', PayStatusEnum::PENDING],
  70. ['order_status', '=', OrderStatusEnum::NORMAL],
  71. ['create_time', '<=', $deadlineTime],
  72. ];
  73. // 查询列表记录
  74. return $this->getList($storeId, $filter, ['goods', 'user']);
  75. }
  76. /**
  77. * 查询截止时间已完成的订单列表
  78. * @param int $storeId 商城ID
  79. * @param array $orderIds 订单ID集
  80. * @return \think\Collection
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\DbException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. */
  85. public function getListByOrderIds(int $storeId, array $orderIds)
  86. {
  87. // 查询条件
  88. $filter = [['order_id', 'in', $orderIds]];
  89. // 查询列表记录
  90. return $this->getList($storeId, $filter, ['goods' => ['refund']]);
  91. }
  92. /**
  93. * 查询截止时间未确认收货的订单ID集
  94. * @param int $storeId 商城ID
  95. * @param int $deadlineTime 截止时间
  96. * @return array
  97. */
  98. public function getOrderIdsByReceive(int $storeId, int $deadlineTime)
  99. {
  100. // 查询条件
  101. $filter = [
  102. ['pay_status', '=', PayStatusEnum::SUCCESS],
  103. ['delivery_status', '=', DeliveryStatus::DELIVERED],
  104. ['receipt_status', '=', ReceiptStatus::NOT_RECEIVED],
  105. ['delivery_time', '<=', $deadlineTime]
  106. ];
  107. // 查询列表记录
  108. return $this->getOrderIds($storeId, $filter);
  109. }
  110. /**
  111. * 查询截止时间确认收货的订单列表
  112. * @param int $storeId 商城ID
  113. * @param int $deadlineTime 截止时间
  114. * @return \think\Collection
  115. * @throws \think\db\exception\DataNotFoundException
  116. * @throws \think\db\exception\DbException
  117. * @throws \think\db\exception\ModelNotFoundException
  118. */
  119. public function getOrderListBySettled(int $storeId, int $deadlineTime)
  120. {
  121. // 查询条件
  122. $filter = [
  123. ['order_status', '=', OrderStatusEnum::COMPLETED],
  124. ['receipt_time', '<=', $deadlineTime],
  125. ['is_settled', '=', 0]
  126. ];
  127. // 查询列表记录
  128. return $this->getList($storeId, $filter, ['goods.refund']);
  129. }
  130. /**
  131. * 批量更新订单状态为已收货
  132. * @param array $orderIds
  133. * @return false|int
  134. */
  135. public function onUpdateReceived(array $orderIds)
  136. {
  137. return $this->onBatchUpdate($orderIds, [
  138. 'receipt_status' => ReceiptStatus::RECEIVED,
  139. 'receipt_time' => time(),
  140. 'order_status' => OrderStatusEnum::COMPLETED
  141. ]);
  142. }
  143. }