SearchWdOrderCommand.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Basic;
  4. use App\Models\Enroll;
  5. use App\Models\InteDetail;
  6. use App\Models\InteLog;
  7. use App\Models\InteReview;
  8. use App\Models\InteUser;
  9. use App\Models\User;
  10. use App\Models\WdOrder;
  11. use Carbon\Carbon;
  12. use GuzzleHttp\Client;
  13. use Illuminate\Console\Command;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\File;
  16. use Illuminate\Support\Facades\Log;
  17. use Intervention\Image\Facades\Image;
  18. class SearchWdOrderCommand extends Command
  19. {
  20. /**
  21. * The name and signature of the console command.
  22. *
  23. * @var string
  24. */
  25. protected $signature = 'SearchWdOrderCommand';
  26. /**
  27. * The console command description.
  28. *
  29. * @var string
  30. */
  31. protected $description = 'Command description';
  32. /**
  33. * Create a new command instance.
  34. *
  35. * @return void
  36. */
  37. public function __construct()
  38. {
  39. parent::__construct();
  40. }
  41. /**
  42. * Execute the console command.
  43. *
  44. * @return mixed
  45. */
  46. public function handle()
  47. {
  48. /*
  49. * 学分查询
  50. * */
  51. $number_arr=InteReview::where('season',48)->where('inte_type',1)->pluck('number')->toArray();
  52. if ($number_arr){
  53. $order_no_arr=WdOrder::whereIn('order_no',$number_arr)->where('apply_cancel',2)
  54. ->pluck('order_no');
  55. if ($order_no_arr){
  56. InteReview::whereIn('number',$order_no_arr)->delete();
  57. $rr=InteLog::whereIn('number',$order_no_arr)->get();
  58. foreach ($rr as $k=>$v){
  59. $uu=InteUser::where('id',$v->uid)->first();
  60. $uu->integral-=$v->integral;
  61. $uu->save();
  62. }
  63. InteLog::whereIn('number',$order_no_arr)->delete();
  64. }
  65. }
  66. $order_today_arr=WdOrder::where('apply_cancel','<>',2)
  67. ->whereBetween('pay_at',[Carbon::now()->addHours(-1),Carbon::now()])->pluck('order_no')->toArray();
  68. Log::error($order_today_arr);
  69. //求交集
  70. $array_intersect=array_intersect($number_arr,$order_today_arr);
  71. $array_diff=array_diff($order_today_arr,$array_intersect);
  72. // Log::error('微店的日志');
  73. // Log::error($array_diff);
  74. // Log::error($order_today_arr);
  75. if ($array_diff){
  76. $re=WdOrder::whereIn('order_no',$array_diff)->with(['orderDetail','store'=>function($q){
  77. $q->whereNull('deleted_at');
  78. }])->get();
  79. // Log::error($re);
  80. foreach ($re as $k=>$v){
  81. $type1=0;
  82. $i=0;
  83. $ii=0;
  84. $iii=0;
  85. $iiii=0;
  86. $iiiii=0;
  87. $iiiiis=0;
  88. $jiu=0;
  89. $type_size_1=[];
  90. $type_size_2=[];
  91. $type_size_3=[];
  92. $type_size_4=[];
  93. $type_size_5=[];
  94. $type_size_6=[];
  95. $type_size_jiu=[];
  96. $type2=0;
  97. $type3=0;
  98. $type4=0;
  99. $type5=0;
  100. $type6=0;
  101. $typejiu=0;
  102. if ($v->store){
  103. $user=InteUser::where('user_id',$v->store->user_id)->first();
  104. if ($user){
  105. if ($v->orderDetail){
  106. foreach ($v->orderDetail as $ke=>$va){
  107. if ($va->goods_id==1 || $va->goods_id==26){
  108. $type1+=$va->num;
  109. $s=mb_substr($va->type,0,1);
  110. if ($s=='男'){
  111. $sex=1;
  112. }else{
  113. $sex=0;
  114. }
  115. $type_size_1[$i]=[
  116. 'size'=>$va->size,
  117. 'sex'=>$sex,
  118. 'num'=>$va->num
  119. ];
  120. $i++;
  121. }elseif ($va->goods_id==2){
  122. $type2+=$va->num;
  123. $s=mb_substr($va->type,0,1);
  124. if ($s=='男'){
  125. $sex=1;
  126. }else{
  127. $sex=0;
  128. }
  129. $type_size_2[$ii]=[
  130. 'size'=>$va->size,
  131. 'sex'=>$sex,
  132. 'num'=>$va->num
  133. ];
  134. $ii++;
  135. }elseif ($va->goods_id==3){
  136. $type3+=$va->num;
  137. $s=mb_substr($va->type,0,1);
  138. if ($s=='男'){
  139. $sex=1;
  140. }else{
  141. $sex=0;
  142. }
  143. $type_size_2[$iii]=[
  144. 'size'=>$va->size,
  145. 'sex'=>$sex,
  146. 'num'=>$va->num
  147. ];
  148. $iii++;
  149. }elseif ($va->goods_id==4){
  150. $type4+=$va->num;
  151. $s=mb_substr($va->type,0,1);
  152. if ($s=='男'){
  153. $sex=1;
  154. }else{
  155. $sex=0;
  156. }
  157. $type_size_2[$iiii]=[
  158. 'size'=>$va->size,
  159. 'sex'=>$sex,
  160. 'num'=>$va->num
  161. ];
  162. $iiii++;
  163. }elseif ($va->goods_id==25){
  164. $type5+=$va->num;
  165. $s=mb_substr($va->type,0,1);
  166. if ($s=='男'){
  167. $sex=1;
  168. }else{
  169. $sex=0;
  170. }
  171. $type_size_5[$iiiii]=[
  172. 'size'=>$va->size,
  173. 'sex'=>$sex,
  174. 'num'=>$va->num
  175. ];
  176. $iiiii++;
  177. }
  178. elseif ($va->goods_id==27){
  179. $type6+=$va->num;
  180. $sex=1;
  181. $type_size_6[$iiiii]=[
  182. 'size'=>$va->size,
  183. 'sex'=>$sex,
  184. 'num'=>$va->num
  185. ];
  186. $iiiiis++;
  187. }elseif ($va->goods_id==28 || $va->goods_id==29){
  188. $typejiu+=$va->num;
  189. $sex=1;
  190. $type_size_jiu[$jiu]=[
  191. 'size'=>$va->size,
  192. 'sex'=>$sex,
  193. 'num'=>$va->num
  194. ];
  195. $jiu++;
  196. }
  197. }
  198. $int=new InteReview();
  199. $int->uid=$user->id;
  200. $int->season=48;
  201. $int->integral=($type1+$type2+$type3+$type4+$type5+$type6)*20+$typejiu*20;
  202. $int->type_one=$type1;
  203. $int->type_two=$type2;
  204. $int->type_three=$type3;
  205. $int->type_four=$type4;
  206. $int->type_five=$type5;
  207. $int->type_six=$type6;
  208. $int->type_jiu=$typejiu;
  209. $int->time=strtotime($v->pay_at);
  210. $int->figure=$v->account;
  211. $int->number=$v->order_no;
  212. $int->imgurl=$v->order_no;
  213. $int->inte_type=1;
  214. $int->type=0;
  215. $int->status=0;
  216. $int->save();
  217. $user->integral+=$int->integral;
  218. $user->save();
  219. if ($type_size_1){
  220. foreach ($type_size_1 as $kes=>$val){
  221. $r=new InteDetail();
  222. $r->inte_review_id=$int->id;
  223. $r->size=$val['size'];
  224. $r->num=$val['num'];
  225. $r->sex=$val['sex'];
  226. $r->status=0;
  227. $r->type=1;
  228. $r->save();
  229. }
  230. }
  231. if ($type_size_2){
  232. foreach ($type_size_2 as $kes=>$val){
  233. $r=new InteDetail();
  234. $r->inte_review_id=$int->id;
  235. $r->size=$val['size'];
  236. $r->num=$val['num'];
  237. $r->sex=$val['sex'];
  238. $r->status=0;
  239. $r->type=2;
  240. $r->save();
  241. }
  242. }
  243. if ($type_size_3){
  244. foreach ($type_size_3 as $kes=>$val){
  245. $r=new InteDetail();
  246. $r->inte_review_id=$int->id;
  247. $r->size=$val['size'];
  248. $r->num=$val['num'];
  249. $r->sex=$val['sex'];
  250. $r->status=0;
  251. $r->type=3;
  252. $r->save();
  253. }
  254. }
  255. if ($type_size_4){
  256. foreach ($type_size_4 as $kes=>$val){
  257. $r=new InteDetail();
  258. $r->inte_review_id=$int->id;
  259. $r->size=$val['size'];
  260. $r->num=$val['num'];
  261. $r->sex=$val['sex'];
  262. $r->status=0;
  263. $r->type=4;
  264. $r->save();
  265. }
  266. }
  267. if ($type_size_5){
  268. foreach ($type_size_5 as $kes=>$val){
  269. $r=new InteDetail();
  270. $r->inte_review_id=$int->id;
  271. $r->size=$val['size'];
  272. $r->num=$val['num'];
  273. $r->sex=$val['sex'];
  274. $r->status=0;
  275. $r->type=5;
  276. $r->save();
  277. }
  278. }
  279. if ($type_size_6){
  280. foreach ($type_size_6 as $kes=>$val){
  281. $r=new InteDetail();
  282. $r->inte_review_id=$int->id;
  283. $r->size=$val['size'];
  284. $r->num=$val['num'];
  285. $r->sex=$val['sex'];
  286. $r->status=0;
  287. $r->type=6;
  288. $r->save();
  289. }
  290. }
  291. if ($type_size_jiu){
  292. foreach ($type_size_jiu as $kes=>$val){
  293. $r=new InteDetail();
  294. $r->inte_review_id=$int->id;
  295. $r->size=$val['size'];
  296. $r->num=$val['num'];
  297. $r->sex=$val['sex'];
  298. $r->status=0;
  299. $r->type=6;
  300. $r->save();
  301. }
  302. }
  303. $in_log=new InteLog();
  304. $in_log->season=48;
  305. $in_log->integral=$int->integral;
  306. $in_log->time=$int->time;
  307. $in_log->type=1;
  308. $in_log->number=$int->number;
  309. $in_log->uid=$user->id;
  310. $in_log->save();
  311. }
  312. }else{
  313. Log::error('根据手机号找不到对应的代理,手机号为:'.$v->store->phone);
  314. }
  315. }
  316. }
  317. }
  318. Log::error('拉取微店支付结束');
  319. }
  320. }