SynOrderCommand.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Activity;
  4. use App\Models\Address;
  5. use App\Models\Gifts;
  6. use App\Models\Goods;
  7. use App\Models\Order;
  8. use App\Models\OrderDetail;
  9. use App\Models\OrderGift;
  10. use App\Models\Store;
  11. use App\Models\UrlList;
  12. use App\Models\User;
  13. use GuzzleHttp\Client;
  14. use Illuminate\Console\Command;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Log;
  17. class SynOrderCommand extends Command
  18. {
  19. /**
  20. * The name and signature of the console command.
  21. *
  22. * @var string
  23. */
  24. protected $signature = 'SynOrderCommand';
  25. /**
  26. * The console command description.
  27. *
  28. * @var string
  29. */
  30. protected $description = 'Command description';
  31. /**
  32. * Create a new command instance.
  33. *
  34. * @return void
  35. */
  36. public function __construct()
  37. {
  38. parent::__construct();
  39. }
  40. /**
  41. * Execute the console command.
  42. *
  43. * @return mixed
  44. */
  45. public function handle()
  46. {
  47. Log::info('kaishi');
  48. $url_list=UrlList::where('id','>',1)->get();
  49. foreach ($url_list as $k=>$v){
  50. $token=$v->token;
  51. if (!$token){
  52. $token=$this->getToekn($v->url,$v->id);
  53. // if ($token==0){
  54. // break;
  55. // }
  56. }
  57. $json = '{"QueryType":"0","Code":"","BrandIDS":[],"StartDate":"","EndDate":"","StartMoney":"","EndMoney":"","WarehouseIDS":[],"AccountMethod":"","CurrencyIDS":[],"AddrName":"","AddrPhone":"","Addr":"","IsChina":"","AddrID":"","Remark":"","SourceName":"","SourcePhone":"","ProductName":"","ProductCode":"","SourceAuthorizationCode":"","SalesRemark":"","SelectOrderIDs":[],"TeamID":"","PageNo":1,"PageSize":10,"DeliveryType":"","IsCreateOrderSales":null,"Sort":"","IsAsc":false,"PackagesType":[],"BrandLevels":[],"SelfDeliveryStoreName":"","BusinessContactName":"","StateIDs":[],"TeamIDs":[],"ExpressAccountMethod":"","CustomerOrderCategoryID":0,"EMSCompany":"","DateType":"","EMSCode":"","AccuracyQueryKey":[],"NotLikeQueryKey":[],"GratisOrReachedToPay":""}';
  58. $client=new Client();
  59. $url = $v->url.'/api/Admin/CompanyCustomerOrderList/GetMyCustomerOrderList';
  60. $data=json_decode($json,true);
  61. $data['PageSize']=30;
  62. $data['BrandIDS']=[1];
  63. $data['StateIDs']=[7];
  64. $data['EndDate']='2024-08-27 21:00:00';
  65. $data['StartDate']='2024-08-27 08:50:00';
  66. $re=$client->post($url,[
  67. 'headers' => [
  68. 'Content-Type' => 'application/json', // 设置请求头
  69. 'Auth-AdminToken' => $token, // 如果需要身份验证令牌
  70. ],
  71. 'json'=>$data
  72. ]);
  73. // dump($re);
  74. $res=$re->getBody()->getContents();
  75. Log::error($v->url.$res);
  76. $info=json_decode($res,true);
  77. // if ($info['errcode']=='ExpiredAuthorization' || empty($info['errcode'])){
  78. // $this->getToekn($v->url,$v->id);
  79. // break;
  80. // }
  81. $arr=$info['data']['Models'];
  82. $this->DelOrder($arr,$v->url);
  83. }
  84. Log::error('结束');
  85. }
  86. protected function getToekn($url,$id){
  87. $client=new Client();
  88. $re=$client->post($url.'/api/Admin/System/MainSubLogin',[
  89. 'headers' => [
  90. 'Content-Type' => 'application/json', // 设置请求头
  91. // 'Auth-AdminToken' => 'SjI5Ym5US0xZVzZjSVd4V1FheHg4VG5hL1dpWDJwVi82RDdMY09WU3NTeENIdmJUdmxxTEFVOHZSZkRiaXM1c3RuYUlZTGVIcmI2NGlUdXJ4MXZ6dkREWmRoY283UG5TclQ2RnI5amV3UGYzYjBjNkZ0RTFzUElzRzRhV2F1d0M=', // 如果需要身份验证令牌
  92. ],
  93. 'json'=>['UserName'=>'dwadmin','Password'=>'zS76UMV9']
  94. ]);
  95. $res=$re->getBody()->getContents();
  96. $info=json_decode($res,true);
  97. $urlinfo=UrlList::find($id);
  98. Log::error($res);
  99. Log::error($info);
  100. if (!$info['errcode']){
  101. $token=$info['data']['accessToken'];
  102. $urlinfo->token=$token;
  103. $urlinfo->save();
  104. return $token;
  105. }else{
  106. Log::error($urlinfo->name.'生成token出错===='.$info['errcode']);
  107. return 0;
  108. }
  109. }
  110. protected function DelOrder($arr,$url){
  111. if (!$arr){
  112. return;
  113. }
  114. $activity_id=Activity::where('is_ing',1)->value('id');
  115. foreach ($arr as $k=>$v){
  116. //批发商
  117. $order_num=$v['Code'];
  118. $order=Order::where('order_num',$order_num)->first();
  119. if ($order){
  120. if (!$order->is_deleted){
  121. $order->is_deleted=1;
  122. $order->wait_back_money+=$order->pay_money;
  123. $order->save();
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. /*获取体验店*/
  130. public function get_storename(){
  131. return $this->success_list(Store::where('type',2)->get());
  132. }
  133. }