WechatMiniExpressSendSync.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\common\command;
  3. use app\common\enum\DeliveryEnum;
  4. use app\common\enum\IntegralGoodsEnum;
  5. use app\common\enum\IntegralOrderEnum;
  6. use app\common\enum\OrderEnum;
  7. use app\common\enum\PayEnum;
  8. use app\common\model\IntegralOrder;
  9. use app\common\model\Order;
  10. use app\common\model\RechargeOrder;
  11. use app\common\service\ConfigService;
  12. use app\common\service\WechatMiniExpressSendSyncService;
  13. use think\console\Command;
  14. use think\console\Input;
  15. use think\console\Output;
  16. class WechatMiniExpressSendSync extends Command
  17. {
  18. protected function configure()
  19. {
  20. $this->setName('wechat_mini_express_send_sync')->setDescription('微信小程序发货同步');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. // 未开启发货同步
  25. if (! ConfigService::get('mini_program', 'express_send_sync', 1)) {
  26. return ;
  27. }
  28. // 订单
  29. static::order();
  30. // 积分订单
  31. static::integral_order();
  32. // 用户充值
  33. static::user_recharge();
  34. }
  35. private static function order()
  36. {
  37. // 快递
  38. $list = Order::where('delivery_type', DeliveryEnum::EXPRESS_DELIVERY)
  39. ->where('express_status', 1)
  40. ->where('pay_status', 1)
  41. ->where('pay_way', PayEnum::WECHAT_PAY)
  42. ->where('wechat_mini_express_sync', '<>',1)
  43. ->where('order_status', 'in', [ OrderEnum::STATUS_WAIT_RECEIVE, OrderEnum::STATUS_FINISH ])
  44. ->limit(60)
  45. ->order('id desc')
  46. ->select()->toArray();
  47. // 自提
  48. $list2 = Order::where('delivery_type', DeliveryEnum::SELF_DELIVERY)
  49. ->where('pay_status', 1)
  50. ->where('pay_way', PayEnum::WECHAT_PAY)
  51. ->where('wechat_mini_express_sync', '<>',1)
  52. ->where('order_status', 'in', [ OrderEnum::STATUS_WAIT_DELIVERY, OrderEnum::STATUS_WAIT_RECEIVE, OrderEnum::STATUS_FINISH ])
  53. ->limit(20)
  54. ->order('id desc')
  55. ->select()->toArray();
  56. // 虚拟发货
  57. $list3 = Order::where('delivery_type', DeliveryEnum::DELIVERY_VIRTUAL)
  58. ->where('pay_status', 1)
  59. ->where('pay_way', PayEnum::WECHAT_PAY)
  60. ->where('wechat_mini_express_sync', '<>',1)
  61. ->where('order_status', 'in', [ OrderEnum::STATUS_WAIT_RECEIVE, OrderEnum::STATUS_FINISH ])
  62. ->limit(20)
  63. ->order('id desc')
  64. ->select()->toArray();
  65. foreach ([ ...$list, ...$list2, ...$list3 ] as $item) {
  66. WechatMiniExpressSendSyncService::_sync_order($item);
  67. }
  68. }
  69. private static function integral_order()
  70. {
  71. $list = IntegralOrder::where('pay_status', 1)
  72. ->where('pay_way', PayEnum::WECHAT_PAY)
  73. ->where('wechat_mini_express_sync', 0)
  74. ->where('order_status', 'in', [ IntegralOrderEnum::ORDER_STATUS_GOODS, IntegralOrderEnum::ORDER_STATUS_COMPLETE ])
  75. ->limit(20)
  76. ->order('id desc')
  77. ->select()->toArray();
  78. foreach ($list as $item) {
  79. WechatMiniExpressSendSyncService::_sync_integral_order($item);
  80. }
  81. }
  82. private static function user_recharge()
  83. {
  84. $list = RechargeOrder::where('pay_status', 1)
  85. ->where('pay_way', PayEnum::WECHAT_PAY)
  86. ->where('wechat_mini_express_sync', 0)
  87. ->limit(60)
  88. ->order('id desc')
  89. ->cursor();
  90. foreach ($list as $item) {
  91. WechatMiniExpressSendSyncService::_sync_recharge($item->toArray());
  92. }
  93. }
  94. }