MiniOrderJob.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs;
  12. use app\services\order\StoreOrderServices;
  13. use crmeb\basic\BaseJobs;
  14. use crmeb\services\easywechat\orderShipping\MiniOrderService;
  15. use crmeb\traits\QueueTrait;
  16. use EasyWeChat\Core\Exceptions\HttpException;
  17. use think\Exception;
  18. class MiniOrderJob extends BaseJobs
  19. {
  20. use QueueTrait;
  21. /**
  22. * @throws HttpException
  23. */
  24. public function doJob(string $out_trade_no, int $logistics_type, array $shipping_list, string $payer_openid, string $path, int $delivery_mode = 1, bool $is_all_delivered = true)
  25. {
  26. try {
  27. MiniOrderService::shippingByTradeNo($out_trade_no, $logistics_type, $shipping_list, $payer_openid, $path, $delivery_mode, $is_all_delivered);
  28. return true;
  29. } catch (HttpException $e) {
  30. // 订单异常处理
  31. throw new HttpException($e);
  32. }
  33. }
  34. /**
  35. * 同步商城发货但是小程序未发货的订单
  36. * @return bool
  37. * @author wuhaotian
  38. * @email 442384644@qq.com
  39. * @date 2025/8/14
  40. */
  41. public function syncOrderShipping()
  42. {
  43. try {
  44. if (sys_config('order_shipping_open')) {
  45. $time = time();
  46. $params = [
  47. 'order_state' => 1,
  48. 'pay_time_range' => [
  49. 'begin_time' => $time - (86400 * 7),
  50. 'end_time' => $time
  51. ]
  52. ];
  53. $res = MiniOrderService::shippingOrderList($params);
  54. if ($res['errcode'] == 0 && isset($res['order_list']) && count($res['order_list']) > 0) {
  55. foreach ($res['order_list'] as $item) {
  56. $shipping_list = [
  57. ['item_desc' => '未知']
  58. ];
  59. $path = '/pages/index/index';
  60. if (strpos($item['merchant_trade_no'], 'hy') !== false) {
  61. $shipping_list = [
  62. ['item_desc' => '用户购买付费会员']
  63. ];
  64. $path = '/pages/annex/vip_paid/index';
  65. }
  66. if (strpos($item['merchant_trade_no'], 'cz') !== false) {
  67. $shipping_list = [
  68. ['item_desc' => '用户充值']
  69. ];
  70. $path = '/pages/users/user_bill/index?type=2';
  71. }
  72. if (strpos($item['merchant_trade_no'], 'cp') !== false) {
  73. $is_shipping = app()->make(StoreOrderServices::class)->value(['order_id' => $item['merchant_trade_no']], 'status');
  74. if ((int)$is_shipping === 0) continue;
  75. $shipping_list = [
  76. ['item_desc' => '购买商品']
  77. ];
  78. $path = 'pages/goods/order_details/index?order_id=' . $item['merchant_trade_no'];
  79. }
  80. MiniOrderService::shippingByTradeNo($item['merchant_trade_no'], 4, $shipping_list, $item['openid'], $path, 1, true);
  81. }
  82. }
  83. }
  84. return true;
  85. } catch (HttpException $e) {
  86. return true;
  87. }
  88. }
  89. }