Kernel.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <?php
  2. namespace App\Console;
  3. use App\Console\Commands\AutoPayment;
  4. use App\Console\Commands\BigGiftUserImgCommand;
  5. use App\Console\Commands\BigGiftUserImgDCommand;
  6. use App\Console\Commands\SynOrderCommand;
  7. use App\Console\Commands\SynOrderNewCommand;
  8. use App\Http\Controllers\ActivityImgController;
  9. use App\Http\Controllers\SynOrderController;
  10. use App\Models\Activity;
  11. use App\Models\Address;
  12. use App\Models\BigGiftApply;
  13. use App\Models\Data;
  14. use App\Models\DataInfo;
  15. use App\Models\Gifts;
  16. use App\Models\GiftUserImg;
  17. use App\Models\Goods;
  18. use App\Models\Order;
  19. use App\Models\OrderDetail;
  20. use App\Models\OrderGift;
  21. use App\Models\UrlList;
  22. use App\Models\User;
  23. use App\Models\UserPay;
  24. use Carbon\Carbon;
  25. use GuzzleHttp\Client;
  26. use Illuminate\Console\Scheduling\Schedule;
  27. use Illuminate\Encryption\Encrypter;
  28. use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
  29. use Illuminate\Support\Facades\Auth;
  30. use Illuminate\Support\Facades\DB;
  31. use Illuminate\Support\Facades\Hash;
  32. use Illuminate\Support\Facades\Log;
  33. use Illuminate\Support\Str;
  34. use Intervention\Image\Facades\Image;
  35. class Kernel extends ConsoleKernel
  36. {
  37. /**
  38. * The Artisan commands provided by your application.
  39. *
  40. * @var array
  41. */
  42. protected $commands = [
  43. SynOrderNewCommand::class,
  44. SynOrderCommand::class,
  45. AutoPayment::class,
  46. BigGiftUserImgDCommand::class,
  47. BigGiftUserImgCommand::class,
  48. ];
  49. /**
  50. * Define the application's command schedule.
  51. *
  52. * @param \Illuminate\Console\Scheduling\Schedule $schedule
  53. * @return void
  54. */
  55. protected function schedule(Schedule $schedule)
  56. {
  57. // $schedule->command('inspire')
  58. // ->hourly();
  59. $schedule->command(AutoPayment::class)->everyMinute();
  60. // $schedule->command(SynOrderNewCommand::class)->everyMinute()->withoutOverlapping();
  61. // $schedule->command(BigGiftUserImgDCommand::class)->dailyAt('11:17');
  62. $schedule->command(BigGiftUserImgCommand::class)->dailyAt('11:17');
  63. // $schedule->command(SynOrderCommand::class)->everyMinute()->withoutOverlapping();
  64. // $schedule->command(SynOrderCommand::class)->everyMinute()->withoutOverlapping();
  65. $schedule->call(function (){
  66. $data=BigGiftApply::where('status',2)->get();
  67. $activity_id=15;
  68. foreach ($data as $k=>$v){
  69. $re=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',1)->where('img_type',0)->first();
  70. $img=GiftUserImg::where('activity_id',$activity_id)->where('type',0)->where('is_main',0)->where('img_type',0)->first();
  71. if (!$re || !$img){
  72. return;
  73. }
  74. try {
  75. $image=Image::make($v->headimgurl);
  76. $folder_name = "uploads/UserHeadImg/" . date("Ym/d", time());
  77. $upload_path = 'public/'.$folder_name;
  78. // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在
  79. $extension = 'png';
  80. // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID
  81. // 值如:1_1493521050_7BVc9v9ujP.png
  82. $filename = Str::random(10).random_int(1111,9999) .'.'. $extension;
  83. // File::isDirectory($upload_path) or File::makeDirectory($upload_path, 077, true, true);
  84. if (!file_exists(public_path($upload_path))) {
  85. mkdir(public_path($upload_path), 0777, true);
  86. }
  87. // 将图片移动到我们的目标存储路径中
  88. $image->save(public_path().'/'.$upload_path . '/' . $filename);
  89. $url=env('APP_URL').'/'.$upload_path.'/'.$filename;
  90. }catch (\Exception $exception){
  91. $url='https://image.chuliu.cc/daweiboshi-admin/activity_img/user_img/1731058524_9hKCPWXJzl.jpg';
  92. }
  93. $res=new GiftUserImg();
  94. $res->type=0;
  95. $res->activity_id=$activity_id;
  96. $res->nickname=$v->nickname;
  97. $res->user_img=$url;
  98. $res->img_type=1;
  99. $cc=new ActivityImgController();
  100. $user_url=$cc->CreateImg(1,$re->url,$url,$v->nickname,$img->url);
  101. $res->url=$user_url;
  102. $res->city=$v->city;
  103. $res->area=$v->area;
  104. $res->address=$v->address;
  105. $res->phone=$v->mobile;
  106. $res->car_name=$v->name;
  107. $res->province=$v->province;
  108. $res->op_name=$v->kefu;
  109. $res->save();
  110. BigGiftApply::where('id',$v->id)->update(['status'=>4,'img'=>$user_url]);
  111. }
  112. })->dailyAt('14:50');
  113. // $schedule->call(function (){
  114. // ini_set('memory_limit', '-1');
  115. // $in=DataInfo::where('status',0)->get();
  116. // foreach ($in as $k=>$v){
  117. // $this->DelOrder(json_decode($v->data,true),$v->url);
  118. // DataInfo::where('id',$v->id)->update(['status'=>1]);
  119. // }
  120. // })->everyMinute();
  121. // $schedule->call(function (){
  122. // $re=DB::connection('mysql_w')
  123. // ->table('data_or_user')
  124. //// ->where('id','<','3872')
  125. // ->where('status',0)
  126. // ->where('created_at','>',Carbon::now()->startOfDay()->toDateTimeString())
  127. // ->get();
  128. // if ($re->count()==0) {
  129. // Log::error('没有了');
  130. // }
  131. // foreach ($re as $k=>$v){
  132. // $string=$v->data;
  133. // $customKey = base64_decode('RUFBOTI3OTdGNEVEQTgwOUQyM0YzMUZDRDY1MTIwRkM'); // 从第一个项目获取的密钥(需要解码)
  134. // $encryptedData = $string; // 加密后的数据
  135. //
  136. //
  137. // $encrypter = new Encrypter($customKey, config('app.cipher')); // cipher 通常是 AES-256-CBC
  138. //
  139. // $decryptedData = $encrypter->decryptString($encryptedData);
  140. // $arr=json_decode($decryptedData,true);
  141. //
  142. // $url=UrlList::where('url',mb_substr($arr['Domain'],0,-1))->first();
  143. // $token=$this->getToekn($url->url,$url->id);
  144. //
  145. // $client=new Client();
  146. // $re=$client->post($url->url.'/api/Admin/CustomerCompanyList/GetCustomerDetail',[
  147. // 'headers' => [
  148. // 'Content-Type' => 'application/json', // 设置请求头
  149. // 'Auth-AdminToken' => $token, // 如果需要身份验证令牌
  150. // ],
  151. // 'json'=>['ID'=>$arr['CustomerID']]
  152. // ]);
  153. // $res=$re->getBody()->getContents();
  154. // $info=json_decode($res,true);
  155. // $data_info=$info['data'];
  156. // $mobile=$data_info['Telephone'];
  157. // $name=$data_info['Name'];
  158. // $code=$data_info['CustomerBrandDetail'][0]['AuthorizationCode'];
  159. // $level=$data_info['CustomerBrandDetail'][0]['BrandLevelName'];
  160. // if ($arr['Type']==2){
  161. // DB::connection('mysql_z')
  162. // ->table('base_users')
  163. // ->where('code',$code)
  164. // ->update(['deleted_at'=>Carbon::now()->toDateTimeString()]);
  165. // $remark='用户删除';
  166. // }else{
  167. // $user=DB::connection('mysql_z')
  168. // ->table('base_users')
  169. // ->where('code',$code)
  170. // ->first();
  171. // if ($level=='经销商'){
  172. // $g=2;
  173. // }elseif ($level=='批发商'){
  174. // $g=3;
  175. // }else{
  176. // $g=2;
  177. // }
  178. // $remark='用户存在';
  179. // if (!$user){
  180. // $remark='用户导入';
  181. // $customKey = base64_decode('ikvRFbC6TDfmDDJw/rpYghnneWQ4Kz9KzXP7Nxq8GOM='); // 从第一个项目获取的密钥(需要解码)
  182. //
  183. // $decrypt = new Encrypter($customKey, config('app.cipher')); // cipher 通常是 AES-256-CBC
  184. //
  185. // $encryptData = $decrypt->encryptString($mobile);
  186. // $insert_user=[
  187. // 'nickname'=>$name,
  188. // 'mobile'=>mb_substr($mobile,0,3).'****'.mb_substr($mobile,-4),
  189. // 'mobile_code'=>'+86',
  190. // 'group_id'=>$g,
  191. // 'mobile_encryption'=>$encryptData,
  192. // 'created_at'=>Carbon::now()->toDateTimeString(),
  193. // 'updated_at'=>Carbon::now()->toDateTimeString(),
  194. // 'code'=>$code
  195. // ];
  196. // DB::connection('mysql_z')
  197. // ->table('base_users')
  198. // ->insert($insert_user);
  199. // }
  200. // }
  201. // DB::connection('mysql_w')
  202. // ->table('data_or_user')
  203. // ->where('id',$v->id)
  204. // ->update(['status'=>1,'remark'=>$remark]);
  205. // }
  206. // })->everyMinute()
  207. // ->name('insert_users')
  208. // ->withoutOverlapping();
  209. $schedule->call(function (){
  210. // $url='http://hnsystemfo.quzhouoy.top';
  211. //// $url_list=UrlList::where('id','>',1)->where('url',$url)->get();
  212. //// foreach ($url_list as $k=>$v){
  213. //// $this->getToekn($v->url,$v->id);
  214. //// }
  215. //
  216. // $zz=new SynOrderController();
  217. //
  218. // $id=1146;
  219. // $zz->SearchOrder($url,$id);
  220. })->everyMinute();
  221. // $schedule->call(function (){
  222. // $data=Order::where('created_at','>','2024-08-27 09:00:00')
  223. // ->where('created_at','<','2024-08-29 21:00:00')
  224. // ->select('user_id',DB::raw('SUM(money) as money'))
  225. // ->where('is_deleted',0)->groupBy('user_id')->get();
  226. // foreach ($data as $k=>$v){
  227. // if ($v->money>=300000){
  228. // $pay_money=Order::where('created_at','>','2024-08-27 09:00:00')
  229. // ->where('created_at','<','2024-08-29 21:00:00')
  230. // ->where('user_id',$v->user_id)
  231. // ->where('is_deleted',0)->sum('pay_money');
  232. // //折扣金额
  233. // $money=$v->money*0.95;
  234. // if ($money==$pay_money){
  235. // Order::where('created_at','>','2024-08-27 09:00:00')
  236. // ->where('created_at','<','2024-08-29 21:00:00')
  237. // ->where('user_id',$v->user_id)
  238. // ->where('is_deleted',0)->update(['pay_status'=>2]);
  239. // }elseif($money<$pay_money){
  240. // Order::where('created_at','>','2024-08-27 09:00:00')
  241. // ->where('created_at','<','2024-08-29 21:00:00')
  242. // ->where('user_id',$v->user_id)
  243. // ->where('is_deleted',0)->update(['pay_status'=>2]);
  244. // }
  245. //
  246. // }
  247. // }
  248. // })->everyMinute();
  249. // $schedule->call(function (){
  250. // Log::error('kaishi');
  251. // $data=Order::where('is_deleted',0)->get();
  252. //
  253. //// $arr=['精装','高腰','青春'];
  254. // foreach ($data as $k=>$v){
  255. //// $detail=OrderDetail::where('order_id',$v->id)->get();
  256. //
  257. // $hard=OrderDetail::where('order_id',$v->id)->where('goods_name','like',"%精装%")->sum('num');
  258. // $gaoyao=OrderDetail::where('order_id',$v->id)->where('goods_name','like',"%高腰%")->sum('num');
  259. // $qingchun=OrderDetail::where('order_id',$v->id)->where('goods_name','like',"%青春%")->sum('num');
  260. //
  261. // $gift_ka=$hard+$gaoyao*2+$qingchun*6;
  262. //
  263. // $num=$hard+$gaoyao*2+$qingchun*2;
  264. //
  265. // $gift_xl=intval($num/6);
  266. //
  267. //
  268. // if ($gift_xl>0){
  269. // $re=new OrderGift();
  270. // $re->order_id=$v->id;
  271. // $re->gift_id=10;
  272. // $re->num=$gift_xl;
  273. // $re->activity_id=8;
  274. // $re->save();
  275. // }
  276. //
  277. // if ($gift_ka>0){
  278. // $res=new OrderGift();
  279. // $res->order_id=$v->id;
  280. // $res->gift_id=11;
  281. // $res->num=$gift_ka;
  282. // $res->activity_id=8;
  283. // $res->save();
  284. // }
  285. // }
  286. // Log::error('结束');
  287. // })->dailyAt('15:43');
  288. // $schedule->call(function (){
  289. // $arr=UrlList::where('id','>',1)->get();
  290. // foreach ($arr as $k=>$v){
  291. // $client=new Client();
  292. //
  293. // $re=$client->post($v->url.'/api/Admin/System/MainSubLogin',[
  294. // 'headers' => [
  295. // 'Content-Type' => 'application/json', // 设置请求头
  296. //// 'Auth-AdminToken' => 'SjI5Ym5US0xZVzZjSVd4V1FheHg4VG5hL1dpWDJwVi82RDdMY09WU3NTeENIdmJUdmxxTEFVOHZSZkRiaXM1c3RuYUlZTGVIcmI2NGlUdXJ4MXZ6dkREWmRoY283UG5TclQ2RnI5amV3UGYzYjBjNkZ0RTFzUElzRzRhV2F1d0M=', // 如果需要身份验证令牌
  297. // ],
  298. // 'json'=>['UserName'=>'dwadmin','Password'=>'zS76UMV9']
  299. // ]);
  300. // $res=$re->getBody()->getContents();
  301. // $info=json_decode($res,true);
  302. // $urlinfo=UrlList::find($v->id);
  303. // Log::error($res);
  304. // Log::error($info);
  305. //
  306. // $token=$info['data']['accessToken'];
  307. // $urlinfo->token=$token;
  308. // $urlinfo->save();
  309. //// if (!$info['errcode']){
  310. ////
  311. //// }else{
  312. //// Log::error($urlinfo->name.'生成token出错===='.$info['errcode']);
  313. //// }
  314. // }
  315. // $arr=UrlList::where('id','>',1)->get();
  316. // foreach ($arr as $k=>$v){
  317. // $json='{"BrandID":1,"BrandLevel":1,"BrandState":"0","TeamID":0,"AuthorizationCode":"","AuthorizationTimeStart":"","AuthorizationTimeEnd":"","CreateTimeStart":"","CreateTimeEnd":"","Name":"","WeChat":"","Phone":"","IdentityCard":"","UserName":"","IsChina":"","AddrID":"","AddressDetail":"","CustomerFieldValue":[],"CustomerBrandFieldValue":[],"PageNo":1,"PageSize":10,"Sort":"CreateTime","IsAsc":false,"CustomerParentName":"","CustomerParentPhone":"","ParentAuthorizationCode":"","SuperiorName":"","SuperiorPhone":"","SuperiorAuthorizationCode":"","MemberType":"","BusinessContactName":"","BusinessInfoQuery":{"BusinessType":"","RegisteredCapital":"","BusinessScope":"","RegisterCode":"","LegalPerson":""},"AccuracyQueryKey":[]}';
  318. // $client=new Client();
  319. // $data=json_decode($json,true);
  320. // $data['PageSize']=200;
  321. //
  322. // $re=$client->post($v->url.'/api/Admin/CustomerCompanyList/Comput_GetCustomerBrandQuery',[
  323. // 'headers' => [
  324. // 'Content-Type' => 'application/json', // 设置请求头
  325. // 'Auth-AdminToken' => $v->token, // 如果需要身份验证令牌
  326. // ],
  327. // 'json'=>$data
  328. // ]);
  329. // $res=$re->getBody()->getContents();
  330. // $info=json_decode($res,true);
  331. // Log::error($info);
  332. // $arrs=$info['data']['Models'];
  333. //
  334. // if ($arrs){
  335. // foreach ($arrs as $ke=>$va){
  336. // $Sourcemobile=$va['Telephone'];
  337. // $Sourcenickname=$va['Name'];
  338. // $Sourcecode=$va['AuthorizationCode'];
  339. // $user=User::where('auth_code',$va['AuthorizationCode'])->first();
  340. // if (!$user){
  341. // $user=new User();
  342. // $user->name=$Sourcenickname;
  343. // $user->nickname=$Sourcenickname;
  344. // $user->realname=$Sourcenickname;
  345. // $user->remark_name=$Sourcenickname;
  346. // $user->mobile=$Sourcemobile;
  347. // $user->uuid=$Sourcemobile;
  348. // $user->auth_code=$Sourcecode;
  349. // $user->level=3;
  350. // $user->url=$v->url;
  351. // $user->save();
  352. // }
  353. // }
  354. // }
  355. //
  356. // }
  357. // dd(1);
  358. // })->everyMinute();
  359. // $schedule->call(function (){
  360. // $this->shenhe();
  361. // })->dailyAt('13:30');
  362. // $schedule->call(function (){
  363. // $data=Order::where('created_at','>','2024-11-05 09:00:00')
  364. // ->where('created_at','<','2024-11-08 12:20:00')
  365. //
  366. // ->select('user_id',DB::raw('SUM(money) as money'),DB::raw('SUM(pay_money) as pay_money'))
  367. // ->where('is_deleted',0)->groupBy('user_id')->get();
  368. // foreach ($data as $k=>$v){
  369. // if ($v->money>=300000){
  370. // if ($v->money*0.95 <=$v->pay_money){
  371. // Order::where('created_at','>','2024-11-05 09:00:00')
  372. // ->where('created_at','<','2024-11-08 13:20:00')
  373. // ->where('user_id',$v->user_id)
  374. // ->where('is_deleted',0)
  375. // ->update(['pay_status'=>2]);
  376. // }
  377. // }
  378. // }
  379. // })->dailyAt('13:37');
  380. // $schedule->call(function (){
  381. // $data=Order::where('created_at','>','2024-11-05 09:00:00')
  382. // ->where('created_at','<','2024-11-08 12:20:00')
  383. // ->select('user_id',DB::raw('SUM(money) as money'))
  384. //// ->where('user_id',14836)
  385. // ->where('is_deleted',0)->groupBy('user_id')->get();
  386. // foreach ($data as $k=>$v){
  387. // if ($v->money>=300000){
  388. // $pay_money=Order::where('created_at','>','2024-11-05 09:00:00')
  389. // ->where('created_at','<','2024-11-08 12:20:00')
  390. // ->where('user_id',$v->user_id)
  391. // ->where('is_deleted',0)->sum('pay_money');
  392. // //折扣金额
  393. // $money=$v->money*0.95;
  394. // if($money<$pay_money){
  395. // $cha_money=$pay_money-$money;
  396. // if ($cha_money>0){
  397. // $order_moneu=Order::where('created_at','>','2024-11-05 09:00:00')
  398. // ->where('created_at','<','2024-11-08 12:20:00')
  399. // ->where('user_id',$v->user_id)
  400. // ->where('is_deleted',0)
  401. // ->orderByDesc('money')->first();
  402. // $pay_num=$this->pay_num($v->user_id);
  403. // $user_money=User::find($v->user_id);
  404. // $user_money->money+=$cha_money;
  405. // $user_money->save();
  406. // //支付日志
  407. // $arr=[
  408. // 'user_id'=>$v->user_id,
  409. // 'remark'=>'订单编号为' . $order_moneu->order_num.'满九五折,退款:'.$cha_money,
  410. // 'op_name'=>'系统自动退款',
  411. // 'type'=>2,
  412. // 'created_at'=>Carbon::now()->toDateTimeString(),
  413. // 'updated_at'=>Carbon::now()->toDateTimeString(),
  414. // 'order_num'=>$order_moneu->order_num,
  415. // 'pay_num'=>$pay_num,
  416. // 'pay_money'=>$cha_money,
  417. // 'user_money'=>$user_money->money
  418. // ];
  419. // DB::table('user_pay_log')->insert($arr);
  420. // Order::where('id',$order_moneu->id)
  421. // ->update(['pay_money'=>$order_moneu->pay_money-$cha_money,'no_pay_money'=>$order_moneu->no_pay_money+$cha_money]);
  422. // }
  423. // }
  424. // }
  425. // }
  426. // Log::error('九五折退款');
  427. // })->dailyAt('17:35');
  428. }
  429. /**
  430. * Register the commands for the application.
  431. *
  432. * @return void
  433. */
  434. protected function commands()
  435. {
  436. $this->load(__DIR__.'/Commands');
  437. require base_path('routes/console.php');
  438. }
  439. //支付单号
  440. public function pay_num($user_id)
  441. {
  442. $num = date('Ymd', time()) . '100000' . str_pad($user_id, 6, 0, STR_PAD_LEFT) . rand(11111, 99999);
  443. return $num;
  444. }
  445. protected function shenhe(){
  446. $url_list=UrlList::where('id','>',1)->get();
  447. foreach ($url_list as $k=>$v){
  448. $token=$this->getToekn($v->url,$v->id);
  449. $order=Order::where('status',3)
  450. ->where('created_at','>','2024-10-18')
  451. ->where('url',$v->url)->get();
  452. foreach ($order as $ke=>$va){
  453. $client=new Client();
  454. $url = $v->url.'/api/Admin/CompanyCustomerOrderSubmit/OrderReviewSuccess';
  455. $data=['ID'=>$va->ZDL_id];
  456. $re=$client->post($url,[
  457. 'headers' => [
  458. 'Content-Type' => 'application/json', // 设置请求头
  459. 'Auth-AdminToken' => $token, // 如果需要身份验证令牌
  460. ],
  461. 'json'=>$data
  462. ]);
  463. $res=$re->getBody()->getContents();
  464. $info=json_decode($res,true);
  465. Log::error($info);
  466. }
  467. }
  468. }
  469. protected function DelOrder($arr,$url){
  470. // Log::error($arr);
  471. if (!$arr){
  472. return;
  473. }
  474. $activity_id=Activity::where('is_ing',1)->value('id');
  475. foreach ($arr as $k=>$v){
  476. if ($v['Packages']!=1 && $v['Packages'] !=0){
  477. Log::info($v['Code']);
  478. break;
  479. }
  480. //批发商
  481. $Sourcemobile=$v['SourceCustomerModel']['Telephone'];
  482. $Sourcenickname=$v['SourceCustomerModel']['CustomerName'];
  483. $Sourcecode=$v['SourceCustomerModel']['AuthorizationCode'];
  484. $user=User::where('auth_code',$Sourcecode)->first();
  485. Log::info($Sourcecode);
  486. if (!$user){
  487. $user=new User();
  488. $user->name=$Sourcenickname;
  489. $user->nickname=$Sourcenickname;
  490. $user->realname=$Sourcenickname;
  491. $user->remark_name=$Sourcenickname;
  492. $user->mobile=$Sourcemobile;
  493. $user->uuid=$Sourcemobile;
  494. $user->auth_code=$Sourcecode;
  495. $user->level=3;
  496. $user->url=$url;
  497. $user->save();
  498. }
  499. $TopCode=$v['TopCustomerModel']['AuthorizationCode'];
  500. $belongUser=User::where('auth_code',$TopCode)->first();
  501. if (!$belongUser){
  502. //经销商
  503. $belongUser=new User();
  504. $belongUser->name=$v['TopCustomerModel']['CustomerName'];
  505. $belongUser->nickname=$v['TopCustomerModel']['CustomerName'];
  506. $belongUser->realname=$v['TopCustomerModel']['CustomerName'];
  507. $belongUser->remark_name=$v['TopCustomerModel']['CustomerName'];
  508. $belongUser->mobile=$v['TopCustomerModel']['Telephone'];
  509. $belongUser->uuid=$v['TopCustomerModel']['Telephone'];
  510. $belongUser->auth_code=$TopCode;
  511. $belongUser->level=2;
  512. $belongUser->url=$url;
  513. $belongUser->save();
  514. }
  515. $order_num=$v['Code'];
  516. Log::info($order_num);
  517. $order=Order::where('order_num',$order_num)->first();
  518. if ($order){
  519. if ($v['State']==7 || $v['State']==6){
  520. if (!$order->is_deleted){
  521. $order->wait_back_money=$order->pay_money;
  522. $order->pay_status=3;
  523. }
  524. $order->is_deleted=1;
  525. $order->save();
  526. break;
  527. }
  528. $address=Address::where('id',$order->address_id)->first();
  529. $address->user_id=$user->id;
  530. $address->username=$v['AddressDetail']['Name'];
  531. $address->mobile=$v['AddressDetail']['Phone'];
  532. $address->province=$v['AddressDetail']['Province'];
  533. $address->city=$v['AddressDetail']['City'];
  534. $address->town=$v['AddressDetail']['District'];
  535. $address->address=$v['AddressDetail']['Address'];
  536. $address->type=0;
  537. $address->save();
  538. if ($order->money!=$v['TotalCash']){
  539. OrderDetail::where('order_id',$order->id)->delete();
  540. }
  541. $order->money=$v['TotalCash'];
  542. if ($order->money==$order->pay_money){
  543. $order->no_pay_money=0;//未支付变为0
  544. $order->pay_status=2;//支付状态2,为全部支付
  545. $order->wait_back_money=0;//待退回金额为0
  546. }elseif ($order->money<$order->pay_money){//订单金额小于支付金额
  547. $order->no_pay_money=0;//未支付金额变为0
  548. $order->pay_status=3;//支付状态3,待退款状态
  549. $order->wait_back_money=$order->pay_money-$order->money;//待退款金额为支付金额减去订单金额
  550. }elseif ($order->money>$order->pay_money){//订单金额大于支付金额
  551. if ($order->pay_money==0){//如果支付金额为0
  552. $order->pay_status=0;//则支付状态0,未支付
  553. }else{
  554. $order->pay_status=1;//否则支付状态1,部分支付
  555. }
  556. $order->no_pay_money=$order->money-$order->pay_money;//未支付金额等于订单金额减去支付金额
  557. $order->wait_back_money=0;//待退款为0
  558. }
  559. $order->total=$v['TotalQty'];
  560. $order->State=$v['State'];
  561. $order->save();
  562. $detail=$v['OrderDetailOutput'];
  563. $activity_status=false;
  564. $orderdrtail_id=[];
  565. foreach ($detail as $ke=>$va){
  566. if ($va['IsGift']){
  567. $activity_status=true;
  568. $gift_name=$va['ProductName'];
  569. $num=$va['Qty'];
  570. $gift=Gifts::where('name',$gift_name)->where('activity_id',$activity_id)->first();
  571. $ordergift=OrderGift::where('order_id',$order->id)
  572. ->where('gift_id',$gift->id)->first();
  573. if (!$ordergift){
  574. $ordergift=new OrderGift();
  575. }
  576. $order->total-=$num;
  577. $order->save();
  578. $ordergift->gift_id=$gift->id;
  579. $ordergift->order_id=$order->id;
  580. $ordergift->activity_id=$activity_id;
  581. $ordergift->num=$num;
  582. $ordergift->limit_num=1;
  583. $ordergift->save();
  584. }else{
  585. // Log::error($va);
  586. $GroupID=$va['ProductGroupSKUID'];
  587. $num=$va['Qty'];
  588. $goods=Goods::where('groupID',$GroupID)->first();
  589. if (!$goods){
  590. Log::error('不存在该商品'.$GroupID);
  591. }
  592. $orderDetail=OrderDetail::where('order_id',$order->id)
  593. ->where('goods_id',$goods->id)->first();
  594. if (!$orderDetail){
  595. $orderDetail=new OrderDetail();
  596. }
  597. $orderDetail->order_id=$order->id;
  598. $orderDetail->goods_id=$goods->id;
  599. $orderDetail->num=$num;
  600. $orderDetail->goods_price=$va['Price'];
  601. $orderDetail->money=$num*$va['Price'];
  602. $orderDetail->goods_name=$goods->name;
  603. $orderDetail->goods_size=$goods->size;
  604. $orderDetail->goods_unit=$goods->unit;
  605. $orderDetail->goods_sku=$va['SKUCode'];
  606. $orderDetail->save();
  607. $order_id[]=$orderDetail->id;
  608. }
  609. }
  610. // $order->is_deleted=0;
  611. // $order->wait_back_money=$order->pay_money;
  612. // $order->save();
  613. }else{
  614. $address=new Address();
  615. $address->user_id=$user->id;
  616. $address->username=$v['AddressDetail']['Name'];
  617. $address->mobile=$v['AddressDetail']['Phone'];
  618. $address->province=$v['AddressDetail']['Province'];
  619. $address->city=$v['AddressDetail']['City'];
  620. $address->town=$v['AddressDetail']['District'];
  621. $address->address=$v['AddressDetail']['Address'];
  622. $address->type=0;
  623. $address->uid=$belongUser->id;
  624. $address->save();
  625. $order=new Order();
  626. $order->order_num=$order_num;
  627. $order->money=$v['TotalCash'];
  628. $order->no_pay_money=$v['TotalCash'];
  629. $order->user_id=$user->id;
  630. $order->total=$v['TotalQty'];
  631. $order->created_at=$v['CreateDate'];
  632. $order->ZDL_id=$v['CustomerOrderID'];
  633. $order->url=$url;
  634. $order->State=$v['State'];
  635. $order->address_id=$address->id;
  636. $order->good_user_id=$belongUser->id;
  637. if ($v['State']=='7'){
  638. $order->is_deleted=1;
  639. }
  640. $order->save();
  641. $detail=$v['OrderDetailOutput'];
  642. $activity_status=false;
  643. foreach ($detail as $ke=>$va){
  644. if ($va['IsGift']){
  645. $activity_status=true;
  646. $gift_name=$va['ProductName'];
  647. $num=$va['Qty'];
  648. $gift=Gifts::where('name',$gift_name)->where('activity_id',$activity_id)->first();
  649. $ordergift=new OrderGift();
  650. $ordergift->gift_id=$gift->id;
  651. $ordergift->order_id=$order->id;
  652. $ordergift->activity_id=$activity_id;
  653. $ordergift->num=$num;
  654. $ordergift->limit_num=1;
  655. $ordergift->save();
  656. $order->total-=$num;
  657. $order->save();
  658. }else{
  659. $GroupID=$va['ProductGroupSKUID'];
  660. $num=$va['Qty'];
  661. $goods=Goods::where('groupID',$GroupID)->first();
  662. if (!$goods){
  663. Log::error('不存在该商品'.$GroupID);
  664. }
  665. $orderDetail=new OrderDetail();
  666. $orderDetail->order_id=$order->id;
  667. $orderDetail->goods_id=$goods->id;
  668. $orderDetail->num=$num;
  669. $orderDetail->goods_price=$va['Price'];
  670. $orderDetail->money=$num*$va['Price'];
  671. $orderDetail->goods_name=$goods->name;
  672. $orderDetail->goods_size=$goods->size;
  673. $orderDetail->goods_unit=$goods->unit;
  674. $orderDetail->goods_sku=$va['SKUCode'];
  675. $orderDetail->save();
  676. }
  677. }
  678. if ($activity_status){
  679. $order->activity_id=$activity_id;
  680. $order->save();
  681. }
  682. }
  683. }
  684. }
  685. protected function getToekn($url,$id){
  686. $client=new Client();
  687. $re=$client->post($url.'/api/Admin/System/MainSubLogin',[
  688. 'headers' => [
  689. 'Content-Type' => 'application/json', // 设置请求头
  690. // 'Auth-AdminToken' => 'SjI5Ym5US0xZVzZjSVd4V1FheHg4VG5hL1dpWDJwVi82RDdMY09WU3NTeENIdmJUdmxxTEFVOHZSZkRiaXM1c3RuYUlZTGVIcmI2NGlUdXJ4MXZ6dkREWmRoY283UG5TclQ2RnI5amV3UGYzYjBjNkZ0RTFzUElzRzRhV2F1d0M=', // 如果需要身份验证令牌
  691. ],
  692. 'json'=>['UserName'=>'dwadmin','Password'=>'zS76UMV9']
  693. ]);
  694. $res=$re->getBody()->getContents();
  695. $info=json_decode($res,true);
  696. $urlinfo=UrlList::find($id);
  697. // Log::error($res);
  698. // Log::error($info);
  699. if (!$info['errcode']){
  700. $token=$info['data']['accessToken'];
  701. $urlinfo->token=$token;
  702. $urlinfo->time=time()+9*60;
  703. $urlinfo->save();
  704. return $token;
  705. }else{
  706. Log::error($urlinfo->name.'生成token出错===='.$info['errcode']);
  707. return 0;
  708. }
  709. }
  710. }