123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Activity;
- use App\Models\Address;
- use App\Models\Gifts;
- use App\Models\Goods;
- use App\Models\Order;
- use App\Models\OrderDetail;
- use App\Models\OrderGift;
- use App\Models\Store;
- use App\Models\UrlList;
- use App\Models\User;
- use GuzzleHttp\Client;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class SynOrderCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'SynOrderCommand';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- Log::info('kaishi');
- $url_list=UrlList::where('id','>',1)->get();
- foreach ($url_list as $k=>$v){
- $token=$v->token;
- if (!$token){
- $token=$this->getToekn($v->url,$v->id);
- // if ($token==0){
- // break;
- // }
- }
- $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":""}';
- $client=new Client();
- $url = $v->url.'/api/Admin/CompanyCustomerOrderList/GetMyCustomerOrderList';
- $data=json_decode($json,true);
- $data['PageSize']=30;
- $data['BrandIDS']=[1];
- $data['StateIDs']=[7];
- $data['EndDate']='2024-08-27 21:00:00';
- $data['StartDate']='2024-08-27 08:50:00';
- $re=$client->post($url,[
- 'headers' => [
- 'Content-Type' => 'application/json', // 设置请求头
- 'Auth-AdminToken' => $token, // 如果需要身份验证令牌
- ],
- 'json'=>$data
- ]);
- // dump($re);
- $res=$re->getBody()->getContents();
- Log::error($v->url.$res);
- $info=json_decode($res,true);
- // if ($info['errcode']=='ExpiredAuthorization' || empty($info['errcode'])){
- // $this->getToekn($v->url,$v->id);
- // break;
- // }
- $arr=$info['data']['Models'];
- $this->DelOrder($arr,$v->url);
- }
- Log::error('结束');
- }
- protected function getToekn($url,$id){
- $client=new Client();
- $re=$client->post($url.'/api/Admin/System/MainSubLogin',[
- 'headers' => [
- 'Content-Type' => 'application/json', // 设置请求头
- // 'Auth-AdminToken' => 'SjI5Ym5US0xZVzZjSVd4V1FheHg4VG5hL1dpWDJwVi82RDdMY09WU3NTeENIdmJUdmxxTEFVOHZSZkRiaXM1c3RuYUlZTGVIcmI2NGlUdXJ4MXZ6dkREWmRoY283UG5TclQ2RnI5amV3UGYzYjBjNkZ0RTFzUElzRzRhV2F1d0M=', // 如果需要身份验证令牌
- ],
- 'json'=>['UserName'=>'dwadmin','Password'=>'zS76UMV9']
- ]);
- $res=$re->getBody()->getContents();
- $info=json_decode($res,true);
- $urlinfo=UrlList::find($id);
- Log::error($res);
- Log::error($info);
- if (!$info['errcode']){
- $token=$info['data']['accessToken'];
- $urlinfo->token=$token;
- $urlinfo->save();
- return $token;
- }else{
- Log::error($urlinfo->name.'生成token出错===='.$info['errcode']);
- return 0;
- }
- }
- protected function DelOrder($arr,$url){
- if (!$arr){
- return;
- }
- $activity_id=Activity::where('is_ing',1)->value('id');
- foreach ($arr as $k=>$v){
- //批发商
- $order_num=$v['Code'];
- $order=Order::where('order_num',$order_num)->first();
- if ($order){
- if (!$order->is_deleted){
- $order->is_deleted=1;
- $order->wait_back_money+=$order->pay_money;
- $order->save();
- break;
- }
- }
- }
- }
- /*获取体验店*/
- public function get_storename(){
- return $this->success_list(Store::where('type',2)->get());
- }
- }
|