Book.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\service;
  13. use app\common\enum\book\order\PayStatus;
  14. use app\console\model\Book as OrderModel;
  15. use app\common\service\BaseService;
  16. use app\common\service\Book as OrderService;
  17. use app\common\library\helper;
  18. use app\console\library\Tools;
  19. /**
  20. * 服务类:报名订单订单模块
  21. * Class Book
  22. * @package app\console\service
  23. */
  24. class Book extends BaseService
  25. {
  26. /**
  27. * 未支付订单自动关闭
  28. * @param int $storeId
  29. * @param int $closeHours 自定关闭订单有效期 (小时)
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function closeEvent(int $storeId, int $closeHours)
  35. {
  36. // 截止时间
  37. $deadlineTime = time() - ((int)$closeHours * 60 * 60);
  38. // 查询截止时间未支付的订单
  39. $model = new OrderModel;
  40. $list = $model->getListByClose($deadlineTime);
  41. // 订单ID集
  42. $orderIds = helper::getArrayColumn($list, 'order_id');
  43. if (!empty($orderIds)) {
  44. // 取消订单事件处理
  45. /* foreach ($list as $order) {
  46. OrderService::cancelEvent($order);
  47. }*/
  48. // 批量更新订单状态为已取消
  49. $model->onBatchUpdate($orderIds, ['order_status' => PayStatus::CANCEL]);
  50. }
  51. // 记录日志
  52. Tools::taskLogs('Book', 'closeEvent', [
  53. 'storeId' => $storeId,
  54. 'closeHours' => $closeHours,
  55. 'deadlineTime' => $deadlineTime,
  56. 'orderIds' => helper::jsonEncode($orderIds)
  57. ]);
  58. }
  59. /**
  60. * 已发货订单自动确认收货
  61. * @param int $storeId
  62. * @param int $receiveDays 自动收货天数
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\DbException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. */
  67. public function receiveEvent(int $storeId, int $receiveDays)
  68. {
  69. // 截止时间
  70. $deadlineTime = time() - ((int)$receiveDays * 86400);
  71. // 查询截止时间未确认收货的订单ID集
  72. $model = new OrderModel;
  73. $orderIds = $model->getOrderIdsByReceive($deadlineTime);
  74. // 更新订单收货状态
  75. if (!empty($orderIds)) {
  76. // 批量更新订单状态为已收货
  77. $model->onUpdateReceived($orderIds);
  78. }
  79. // 记录日志
  80. Tools::taskLogs('Book', 'receiveEvent', [
  81. 'storeId' => $storeId,
  82. 'receiveDays' => $receiveDays,
  83. 'deadlineTime' => $deadlineTime,
  84. 'orderIds' => helper::jsonEncode($orderIds)
  85. ]);
  86. }
  87. }