Book.php 4.4 KB

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