OrderConfirm.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\command;
  20. use app\common\enum\OrderEnum;
  21. use app\common\enum\OrderLogEnum;
  22. use app\common\enum\PayEnum;
  23. use app\common\enum\YesNoEnum;
  24. use app\common\model\Order;
  25. use app\common\model\OrderLog;
  26. use app\common\service\ConfigService;
  27. use app\shopapi\logic\Order\OrderLogic;
  28. use think\console\Command;
  29. use think\console\Input;
  30. use think\console\Output;
  31. use think\Db;
  32. use think\facade\Log;
  33. /**
  34. * 订单自动完成
  35. * Class OrderFinish
  36. * @package app\common\command
  37. */
  38. class OrderConfirm extends Command
  39. {
  40. protected function configure()
  41. {
  42. $this->setName('order_confirm')
  43. ->setDescription('系统自动确认收货');
  44. }
  45. protected function execute(Input $input, Output $output)
  46. {
  47. $now = time();
  48. $ableAuto = ConfigService::get('transaction', 'automatically_confirm_receipt');
  49. $confirmTime = ConfigService::get('transaction', 'automatically_confirm_receipt_days') * 24 * 60 * 60;
  50. if ($ableAuto == YesNoEnum::NO) {
  51. return true;
  52. }
  53. $orders = Order::with([ 'after_sale_ing' ])->where([
  54. 'order_status' => OrderEnum::STATUS_WAIT_RECEIVE,
  55. 'pay_status' => PayEnum::ISPAID
  56. ])->whereRaw("express_time+$confirmTime < $now")->select();
  57. try {
  58. foreach ($orders as $order) {
  59. // 是否售后中
  60. if (isset($order['after_sale_ing']['id'])) {
  61. continue;
  62. }
  63. //更新订单状态
  64. Order::update([
  65. 'order_status' => OrderEnum::STATUS_FINISH,
  66. 'confirm_take_time' => time(),
  67. 'after_sale_deadline' => OrderLogic::getAfterSaleDeadline(), //售后截止时间
  68. ], ['id' => $order['id']]);
  69. //订单日志
  70. (new OrderLog())->record([
  71. 'type' => OrderLogEnum::TYPE_USER,
  72. 'channel' => OrderLogEnum::USER_CONFIRM_ORDER,
  73. 'order_id' => $order['id']
  74. ]);
  75. }
  76. } catch (\Exception $e) {
  77. Log::write('订单自动确认失败,失败原因:' . $e->getMessage());
  78. }
  79. }
  80. }