No Description

SyncMjOrderStatus.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $data['send_time'] = date('Y-m-d');
  30. Order::where('id', $order['id'])->update($data);
  31. }elseif($status == '已取消'){
  32. $data['is_del'] = 1;
  33. Order::where('id', $order['id'])->update($data);
  34. }
  35. }
  36. }
  37. }
  38. /**
  39. * 获取订单信息,可用来判断订单是否存在,同步订单状态
  40. */
  41. public function getMjOrder($id, $outerCode=''){
  42. $order = array();
  43. $order['eshopCode'] = config('constants.ESHOP_CODE');
  44. if(!$outerCode){
  45. $outerCode = Order::where('id', $id)->pluck('outerCode');
  46. }
  47. $order['outerCode'] = $outerCode;
  48. $mjOrder = Order::mjOrderGet($order);
  49. if(!isset($mjOrder['order']['code'])){
  50. return false;
  51. }
  52. return $mjOrder['order'];
  53. }
  54. }