Order.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\task;
  13. use app\common\model\Order as OrderModel;
  14. use app\console\service\Order as OrderService;
  15. use app\console\service\OrderGood as OrderGoodService;
  16. use app\console\model\Setting as SettingModel;
  17. /**
  18. * 定时任务:商城订单
  19. * Class Order
  20. * @package app\console\task
  21. */
  22. class Order extends Task
  23. {
  24. // 当前任务唯一标识
  25. private $taskKey = 'Order';
  26. // 任务执行间隔时长 (单位:秒)
  27. protected $taskExpire = 60 * 30;
  28. // 当前商城ID
  29. private $storeId;
  30. /**
  31. * 任务处理
  32. * @param array $param
  33. * @throws \think\Exception
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function handle(array $param)
  39. {
  40. if(env('SERVE_ENV')=='test'){
  41. $this->taskExpire = 30;
  42. }
  43. ['storeId' => $this->storeId] = $param;
  44. $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
  45. echo $this->taskKey . PHP_EOL;
  46. // 未支付订单自动关闭--待支付订单定时频率太快,单独拿出来处理-2021年11月2日 11:58:18
  47. // 已发货订单自动确认收货
  48. $this->receiveEvent();
  49. // 确认收货订单自动评价
  50. $this->commentEvent();
  51. });
  52. }
  53. /**
  54. * 自动确认收货订单的天数
  55. * @throws \think\Exception
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. private function receiveEvent()
  61. {
  62. // 取消n天以前的的未付款订单
  63. // $receiveDays = (int)$this->getRefundSetting()['receive_days'];
  64. // // 执行自动确认收货
  65. // if ($receiveDays > 0) {
  66. $service = new OrderGoodService;
  67. $service->receiveEvent($this->storeId, 0);
  68. // }
  69. }
  70. /**
  71. * 已完成订单自动结算
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. */
  76. private function settledEvent()
  77. {
  78. // 取消n天以前的的未付款订单
  79. $refundDays = (int)$this->getRefundSetting()['refund_days'];
  80. // 执行自动确认收货
  81. if ($refundDays > 0) {
  82. $service = new OrderService;
  83. $service->settledEvent($this->storeId, $refundDays);
  84. }
  85. }
  86. /**
  87. * 已完成订单自动评价
  88. * 确认收货的订单,15天内显示“去评价”按钮;超过15天用户未评价则默认五星好评,默认评价语是“此用户没有填写评价。”
  89. */
  90. private function commentEvent()
  91. {
  92. // 自动评价n天以前的的已确认收货的订单商品
  93. $commentDays = OrderModel::getCommentDeadline();
  94. // 执行自动评价
  95. if ($commentDays > 0) {
  96. $service = new OrderService;
  97. $service->commentEvent($this->storeId, $commentDays);
  98. }
  99. }
  100. /**
  101. * 获取商城交易设置
  102. * @return array|mixed
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. */
  107. private function getRefundSetting()
  108. {
  109. return SettingModel::getItem('refund', $this->storeId);
  110. }
  111. }