GoodsVirtualLogic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\logic;
  20. use app\common\enum\DefaultEnum;
  21. use app\common\enum\DeliveryEnum;
  22. use app\common\enum\GoodsEnum;
  23. use app\common\enum\OrderEnum;
  24. use app\common\enum\OrderLogEnum;
  25. use app\common\model\Delivery;
  26. use app\common\model\Order;
  27. use app\common\model\OrderLog;
  28. use app\shopapi\logic\Order\OrderLogic;
  29. class GoodsVirtualLogic
  30. {
  31. /**
  32. * @notes 虚拟商品下单后更新订单状态
  33. * @param $orderIds
  34. * @author cjhao
  35. * @date 2022/4/19 17:34
  36. */
  37. public static function afterPayVirtualDelivery($orderIds){
  38. $orderList = Order::where(['id'=>$orderIds])->with(['order_goods'])->select()->toArray();
  39. foreach ($orderList as $order){
  40. $updateData = [];
  41. if(OrderEnum::VIRTUAL_ORDER != $order['order_type']){
  42. continue;
  43. }
  44. $orderGoods = array_shift($order['order_goods']);
  45. if(empty($orderGoods)){
  46. continue;
  47. }
  48. $goodsSnap = $orderGoods['goods_snap'];
  49. //实物商品,不处理
  50. if(GoodsEnum::GOODS_REALITY == $goodsSnap->type){
  51. continue;
  52. }
  53. //自动发货
  54. if(GoodsEnum::AFTER_PAY_AUTO == $goodsSnap->after_pay){
  55. switch ($goodsSnap->delivery_type) {
  56. // 固定内容
  57. case 0:
  58. $updateData['delivery_content'] = $goodsSnap->delivery_content ?? '';
  59. $updateData['delivery_content_type'] = 0;
  60. break;
  61. // 发货模版
  62. case 1:
  63. if (! isset($goodsSnap->delivery_template)) {
  64. break;
  65. }
  66. $updateData['delivery_content_type'] = $goodsSnap->delivery_template['type'];
  67. if ($goodsSnap->delivery_template['type'] === 0) {
  68. $updateData['delivery_content'] = $goodsSnap->delivery_template['content'] ?? '';
  69. }
  70. if ($goodsSnap->delivery_template['type'] === 1) {
  71. $updateData['delivery_content1'] = $goodsSnap->delivery_template['content1'] ?? [];
  72. }
  73. break;
  74. default:
  75. $updateData['delivery_content'] = '';
  76. break;
  77. }
  78. //更新数据
  79. $updateData = array_merge($updateData,[
  80. 'order_status' => OrderEnum::STATUS_WAIT_RECEIVE,
  81. 'express_status' => DeliveryEnum::NOT_SHIPPED,
  82. 'express_time' => time(),
  83. 'delivery_id' => 0,
  84. ]);
  85. //自动完成订单
  86. if(GoodsEnum::AFTER_DELIVERY_AUTO == $goodsSnap->after_delivery){
  87. $updateData['order_status'] = OrderEnum::STATUS_FINISH;
  88. $updateData['confirm_take_time'] = time();
  89. $updateData['after_sale_deadline'] = OrderLogic::getAfterSaleDeadline();
  90. //记录日志
  91. (new OrderLog())->record([
  92. 'type' => OrderLogEnum::TYPE_SYSTEM,
  93. 'channel' => OrderLogEnum::USER_CONFIRM_ORDER,
  94. 'order_id' => $order['id']
  95. ]);
  96. }
  97. }
  98. //更新订单状态
  99. $updateData && Order::update($updateData,['id'=>$order['id']]);
  100. }
  101. }
  102. }