Nessuna descrizione

SyncMjOrderStatus.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use DB;
  5. use App\Order;
  6. class SyncMjOrderStatus extends Command {
  7. protected $signature = 'SyncMjOrderStatus';
  8. /**
  9. * The console command description.
  10. *
  11. * @var string
  12. */
  13. protected $description = '同步订单状态';
  14. public function handle()
  15. {
  16. $this->SyncMjOrderStatus();
  17. }
  18. public function SyncMjOrderStatus(){
  19. $orders = Order::select('id', 'outerCode')->where('orderCode','>',0)->where('status', '<', 3)->where('warehouse', 3)->orderBy('id', 'desc')->get();
  20. $orders = json_decode(json_encode($orders), true);
  21. foreach($orders as $k=>$order){
  22. $result = $this->getMjOrder($order['id'], $order['outerCode']);
  23. if( !empty($result) ){
  24. $data = array();
  25. $status = $result['status'];
  26. if($status == '已发货' || $status == '已完成'){
  27. $data['status'] = 3;
  28. $data['logistics_id'] = $result['expressCode'];
  29. Order::where('id', $order['id'])->update($data);
  30. }elseif($status == '已取消'){
  31. $data['is_del'] = 1;
  32. Order::where('id', $order['id'])->update($data);
  33. }
  34. }
  35. }
  36. }
  37. /**
  38. * 获取订单信息,可用来判断订单是否存在,同步订单状态
  39. */
  40. public function getMjOrder($id, $outerCode=''){
  41. $order = array();
  42. $order['eshopCode'] = config('constants.ESHOP_CODE');
  43. if(!$outerCode){
  44. $outerCode = Order::where('id', $id)->pluck('outerCode');
  45. }
  46. $order['outerCode'] = $outerCode;
  47. $mjOrder = Order::mjOrderGet($order);
  48. if(!isset($mjOrder['order']['code'])){
  49. return false;
  50. }
  51. return $mjOrder['order'];
  52. }
  53. }