FwCodeController.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Events\ReturnGoodLog;
  4. use App\Events\SendGoodLogEvent;
  5. use App\Jobs\GoodSendJobs;
  6. use App\Models\DeviceAccount;
  7. use App\Models\Express;
  8. use App\Models\FwCode;
  9. use App\Models\FwCodeLog;
  10. use App\Models\GoodSelect;
  11. use App\Models\OrderTest;
  12. use App\Models\Select;
  13. use App\Models\SendGoodLog;
  14. use App\Models\User;
  15. use Carbon\Carbon;
  16. use Illuminate\Http\Request;
  17. use Illuminate\Support\Facades\Auth;
  18. use Illuminate\Support\Facades\Cache;
  19. use Illuminate\Support\Facades\Crypt;
  20. use Illuminate\Support\Facades\DB;
  21. use Illuminate\Support\Facades\Log;
  22. use Illuminate\Support\Facades\Validator;
  23. class FwCodeController extends Controller
  24. {
  25. /**公司扫码快递单*/
  26. public function get_express(Request $request)
  27. {
  28. $u_id=Auth::user()->id;
  29. $users=User::find($u_id);
  30. if ($users->mobile==17333738670){
  31. return $this->error(500214,'','账号暂停使用');
  32. }
  33. Log::error($request->all());
  34. Log::error($u_id);
  35. $re=DB::table('newexpress')->where('express_num','like',"%".$request->express_number."%")->first();
  36. if ($re){
  37. $data['belong_user_nickname'] = '';
  38. $data['belong_user_mobile'] = '';
  39. $data['address_name'] = '';
  40. $data['belong_user_id'] = '';
  41. $data['user_id'] = '';
  42. $order=OrderTest::where('order_num',$re->order_num)->first();
  43. if (!$order){
  44. // $res=DB::table('newexpress_copy1')->where('express_num',$request->express_number)->first();
  45. // $user=User::where('mobile',$res->mobile)->first();
  46. if (!$order){
  47. return $this->error(50214,'','订单号:'.$re->order_num.'不存在');
  48. }
  49. }
  50. $user=User::find($order->good_user_id);
  51. $data['user_id'] = $user->id;
  52. $data['belong_user_nickname'] = $user->remark_name;
  53. $data['belong_user_mobile'] = $user->mobile;
  54. $data['belong_user_avatar'] = $user->headimgurl;
  55. $data['belong_user_id'] = $user->id;
  56. return $this->success($data);
  57. }
  58. $datas = Express::where('express_number', $request->express_number)->first();
  59. if (!$datas){
  60. $nums=mb_substr($request->express_number,0,1);
  61. Log::error($nums.'sss');
  62. if ($nums==7){
  63. $num=(int)$request->express_number;
  64. $datas = Express::where('express_number','=',$num)->first();
  65. }
  66. }
  67. $data['belong_user_nickname'] = '';
  68. $data['belong_user_mobile'] = '';
  69. $data['address_name'] = '';
  70. $data['belong_user_id'] = '';
  71. $data['user_id'] = '';
  72. if ($datas) {
  73. $order = OrderTest::with(['get_good_user', 'get_address_user'])->find($datas->order_id);
  74. $data['user_id'] = $order->user_id;
  75. if ($order->get_good_user) {
  76. $data['belong_user_nickname'] = $order->get_good_user->nickname;
  77. $data['belong_user_mobile'] = $order->get_good_user->mobile;
  78. $data['belong_user_avatar'] = $order->get_good_user->headimgurl;
  79. $data['belong_user_id'] = $order->get_good_user->id;
  80. }
  81. if ($order->get_address_user) {
  82. $data['address_name'] = $order->get_address_user->username;
  83. }
  84. return $this->success($data);
  85. } else {
  86. return $this->error(50023, '', '请检查快递单号是否正确');
  87. }
  88. }
  89. /*四种商品的选择**/
  90. public function get_good()
  91. {
  92. $re = GoodSelect::select('id', 'name as good_name')->orderByDesc('rank')->where('status',0)->get();
  93. return $this->success($re);
  94. }
  95. /****/
  96. public function JudgePhone($phone){
  97. if ($phone=='15220141101'){
  98. $name='公司';
  99. }elseif ($phone=='17333738670'){
  100. $name='吴桥仓库';
  101. }else{
  102. $name=DeviceAccount::where('mobile',$phone)->orwhere('phone',$phone)->where('status',0)->value('name');
  103. }
  104. return $name;
  105. }
  106. public function message($k,$v,$ks=14){
  107. // $m='袜子';
  108. if ($ks==1){
  109. $m='精装版';
  110. }elseif ($ks==2){
  111. $m='简约版';
  112. }elseif ($ks==3){
  113. $m='高腰版';
  114. }elseif ($ks==4){
  115. $m='纯棉版';
  116. }elseif ($ks==9){
  117. $m='青春版';
  118. }elseif ($ks==6){
  119. $m='精装版G';
  120. }elseif ($ks==7){
  121. $m='简约版G';
  122. }elseif ($ks==8){
  123. $m='高腰版G';
  124. }elseif ($ks==10){
  125. $m='青春版G';
  126. }elseif($ks==11){
  127. $m='纯棉赠';
  128. }elseif($ks==12){
  129. $m='青春赠';
  130. }elseif($ks==13){
  131. $m='简约赠';
  132. }elseif($ks==14){
  133. $m='袜子';
  134. }
  135. else{
  136. $m='精装(赠)';
  137. }
  138. Log::info($v.'没有查到相应的信息');
  139. return '没有查到二维码对应的信息,请删除'.$m.'中第'.($k+1).'个数据重新提交。并将对应的货物单独取出';
  140. }
  141. public function sendlog($event){
  142. DB::beginTransaction();
  143. try{
  144. $log=new FwCodeLog();
  145. if ($event['type']==1){
  146. $op_id=0;
  147. $note='此货物('.$event['good_name'].')由'.$event['op_name'].'在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
  148. }else{
  149. $op_id=$event['op_id'];
  150. $note='此货物由昵称为:'.$event['op_name'].'、手机号为:'.$event['op_phone'].'在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
  151. }
  152. $event['note']=$note;
  153. $event['op_id']=$op_id;
  154. // SendGoodLog::create($event);
  155. $log->op_name=$event['op_name'];
  156. $log->op_phone=$event['op_phone'];
  157. $log->op_id=$op_id;
  158. $log->accept_name=$event['accept_name'];
  159. $log->accept_phone=$event['accept_phone'];
  160. $log->accept_id=$event['accept_id'];
  161. $log->select_id=$event['select_id'];
  162. $log->note=$note;
  163. if (!$log->save()){
  164. throw new \Exception('1');
  165. }
  166. DB::commit();
  167. }catch (\Exception $exception){
  168. Log::error($exception);
  169. DB::rollBack();
  170. }
  171. }
  172. /**公司发货**/
  173. public function sendwazi(Request $request)
  174. {
  175. $input = $request->all();
  176. $u_id=Auth::user()->id;
  177. $users=User::find($u_id);
  178. if ($users->mobile==17333738670){
  179. return $this->error(500214,'','账号暂停使用');
  180. }
  181. $name=$this->JudgePhone($users->mobile);
  182. $user = User::where('id', $request->id)->first();
  183. Log::error($input['code']);
  184. Log::error($u_id);
  185. $code = json_decode($input['code']);
  186. DB::beginTransaction();
  187. try {
  188. foreach ($code as $ks => $vs) {
  189. $good=GoodSelect::where('id',$ks)->select('good_name')->first();
  190. foreach ($vs as $k=>$v){
  191. $lenth=mb_strlen($v);
  192. //大码
  193. if ($lenth==10){
  194. $re = FwCode::where('top_code', $v)->first();
  195. if (!$re){
  196. $message=$this->message($k,$v);
  197. $this->error(400,'',$message);
  198. }
  199. $child_count=FwCode::where('top_code',$v)->groupBy('user_id')->get();
  200. if (count($child_count)!=1){
  201. return $this->error(50026,'','小码已发货不能使用大码发货');
  202. }
  203. $child=FwCode::where('top_code',$v)->get();
  204. FwCode::where('top_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  205. foreach ($child as $kke=>$vve){
  206. $data = [
  207. 'op_name' => $name,
  208. 'op_phone' => $users->mobile,
  209. 'op_id' => 0,
  210. 'good_name'=>$good->good_name,
  211. 'accept_name' => $user->nickname,
  212. 'accept_phone' => $user->mobile,
  213. 'accept_id' => $user->id,
  214. 'type' => 1,
  215. 'select_id' => $vve->id
  216. ];
  217. $this->sendlog($data);
  218. }
  219. }elseif ($lenth==11){//中码发货
  220. $re = FwCode::where('mid_code', $v)->first();
  221. if (!$re){
  222. $message=$this->message($k,$v);
  223. $this->error(400,'',$message);
  224. }
  225. $child_count=FwCode::where('mid_code',$v)->groupBy('user_id')->get();
  226. if (count($child_count)!=1){
  227. return $this->error(50026,'','小码已发货不能使用大码发货');
  228. }
  229. $child=FwCode::where('mid_code',$v)->get();
  230. FwCode::where('mid_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  231. foreach ($child as $kke=>$vve){
  232. $data = [
  233. 'op_name' => $name,
  234. 'op_phone' => $users->mobile,
  235. 'op_id' => 0,
  236. 'good_name'=>$good->good_name,
  237. 'accept_name' => $user->nickname,
  238. 'accept_phone' => $user->mobile,
  239. 'accept_id' => $user->id,
  240. 'type' => 1,
  241. 'select_id' => $vve->id
  242. ];
  243. $this->sendlog($data);
  244. }
  245. }elseif ($lenth==12){ //小码发货
  246. $re = FwCode::where('code', $v)->first();
  247. if (!$re){
  248. $message=$this->message($k,$v);
  249. $this->error(400,'',$message);
  250. }
  251. FwCode::where('code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  252. $data = [
  253. 'op_name' => $name,
  254. 'op_phone' => $users->mobile,
  255. 'op_id' => 0,
  256. 'good_name'=>$good->good_name,
  257. 'accept_name' => $user->nickname,
  258. 'accept_phone' => $user->mobile,
  259. 'accept_id' => $user->id,
  260. 'type' => 1,
  261. 'select_id' => $re->id
  262. ];
  263. $this->sendlog($data);
  264. }
  265. }
  266. }
  267. DB::commit();
  268. return $this->success([]);
  269. } catch (\Exception $exception) {
  270. DB::rollBack();
  271. Log::error($exception);
  272. return $this->error(40023, '', '发货失败,请重新尝试');
  273. }
  274. }
  275. public function send_goods_new(Request $request)
  276. {
  277. $input = $request->all();
  278. Log::error($input);
  279. $u_id=Auth::user()->id;
  280. $users=User::find($u_id);
  281. if ($users->mobile==17333738670){
  282. return $this->error(500214,'','账号暂停使用');
  283. }
  284. $name=$this->JudgePhone($users->mobile);
  285. $user = User::where('id', $request->id)->first();
  286. Log::error($input['code']);
  287. $code = json_decode($input['code']);
  288. // $code=$input['code'];
  289. DB::beginTransaction();
  290. try {
  291. foreach ($code as $ks => $vs) {
  292. $good=GoodSelect::where('id',$ks)->select('good_name')->first();
  293. foreach ($vs as $k=>$v){
  294. $v=trim($v);
  295. $re = Select::where('code', $v)->first();
  296. if ($re) {
  297. //小码发货
  298. if ($re->is_lowest == 1) {
  299. $re->user_id = $user->id;
  300. $re->track_status = 2;
  301. $re->com_binding = 0;
  302. $re->is_true = 0;
  303. $re->good_select_id = $ks;
  304. $num = $this->update_full($re->pid);
  305. if ($num == 300) {
  306. return $this->error(50021, '', '修改状态出错');
  307. }
  308. $data = [
  309. 'op_name' => $name,
  310. 'op_phone' => $users->mobile,
  311. 'op_id' => 0,
  312. 'good_name'=>$good->good_name,
  313. 'accept_name' => $user->nickname,
  314. 'accept_phone' => $user->mobile,
  315. 'accept_id' => $user->id,
  316. 'type' => 1,
  317. 'select_id' => $re->id
  318. ];
  319. if (!$re->save()) {
  320. throw new \Exception(1);
  321. }
  322. event(new SendGoodLogEvent($data));
  323. } else {//中码或者大码发货
  324. $num = $this->is_full($v);
  325. if ($num == 300) {
  326. return $this->error(50026, '', '小码已经部分发货,不能扫描中码或者大码进行发货');
  327. }
  328. if ($re->level != 1) {
  329. $re->user_id = $request->id;
  330. $re->com_binding = 0;
  331. $re->is_true = 0;
  332. $re->good_select_id = $ks;
  333. if (!$re->save()) {
  334. throw new \Exception('1');
  335. }
  336. $num = $this->update_full($re->pid);
  337. if ($num == 300) {
  338. throw new \Exception(1);
  339. }
  340. $data = [
  341. 'op_name' => $name,
  342. 'op_phone' => $users->mobile,
  343. 'op_id' => 0,
  344. 'good_name'=>$good->good_name,
  345. 'accept_name' => $user->nickname,
  346. 'accept_phone' => $user->mobile,
  347. 'accept_id' => $user->id,
  348. 'type' => 1,
  349. 'select_id' => $re->id
  350. ];
  351. event(new SendGoodLogEvent($data));
  352. $level_data = Select::where('pid', $re->sort)->get();
  353. foreach ($level_data as $ke => $va) {
  354. $res = Select::where('code', $va->code)->first();
  355. $res->user_id = $request->id;
  356. $res->com_binding = 0;
  357. $res->is_true = 0;
  358. $res->good_select_id = $ks;
  359. if (!$res->save()) {
  360. throw new \Exception(1);
  361. }
  362. $data = [
  363. 'op_name' => $name,
  364. 'op_phone' => $users->mobile,
  365. 'op_id' => 0,
  366. 'good_name'=>$good->good_name,
  367. 'accept_name' => $user->nickname,
  368. 'accept_phone' => $user->mobile,
  369. 'accept_id' => $user->id,
  370. 'type' => 1,
  371. 'select_id' => $va->id
  372. ];
  373. event(new SendGoodLogEvent($data));
  374. }
  375. } else {
  376. /***大码发货,并记录日志情况*/
  377. $re->user_id = $request->id;
  378. $re->com_binding = 0;
  379. $re->is_true = 0;
  380. $re->good_select_id = $ks;
  381. if (!$re->save()) {
  382. throw new \Exception('1');
  383. }
  384. $data = [
  385. 'op_name' => $name,
  386. 'op_phone' => $users->mobile,
  387. 'op_id' => 0,
  388. 'good_name'=>$good->good_name,
  389. 'accept_name' => $user->nickname,
  390. 'accept_phone' => $user->mobile,
  391. 'accept_id' => $user->id,
  392. 'type' => 1,
  393. 'select_id' => $re->id
  394. ];
  395. event(new SendGoodLogEvent($data));
  396. /**查询**/
  397. $level_data = Select::where('pid', $re->sort)->get();
  398. foreach ($level_data as $ke => $va) {
  399. /***修改所有所属者*/
  400. $res = Select::where('code', $va->code)->first();
  401. $res->user_id = $request->id;
  402. $res->com_binding = 0;
  403. $res->is_true = 0;
  404. $res->good_select_id = $ks;
  405. if (!$res->save()) {
  406. throw new \Exception(1);
  407. }
  408. $data = [
  409. 'op_name' => $name,
  410. 'op_phone' => $users->mobile,
  411. 'op_id' => 0,
  412. 'good_name'=>$good->good_name,
  413. 'accept_name' => $user->nickname,
  414. 'accept_phone' => $user->mobile,
  415. 'accept_id' => $user->id,
  416. 'type' => 1,
  417. 'select_id' => $va->id
  418. ];
  419. event(new SendGoodLogEvent($data));
  420. /**如果现在的等级不是最低级,则执行下面的内容**/
  421. if ($va->is_lowest != 1) {
  422. $ress = Select::where('pid', $va->sort)->get();
  423. foreach ($ress as $kes => $vas) {
  424. $resss = Select::where('code', $vas->code)->first();
  425. $resss->user_id = $request->id;
  426. $resss->com_binding = 0;
  427. $resss->is_true = 0;
  428. $resss->good_select_id = $ks;
  429. if (!$resss->save()) {
  430. throw new \Exception(1);
  431. }
  432. $data = [
  433. 'op_name' => $name,
  434. 'op_phone' => $users->mobile,
  435. 'op_id' => 0,
  436. 'accept_name' => $user->nickname,
  437. 'accept_phone' => $user->mobile,
  438. 'accept_id' => $user->id,
  439. 'type' => 1,
  440. 'good_name'=>$good->good_name,
  441. 'select_id' => $vas->id
  442. ];
  443. event(new SendGoodLogEvent($data));
  444. }
  445. }
  446. }
  447. }
  448. }
  449. } else {
  450. Log::error($k+1);
  451. if ($ks==1){
  452. $m='精装版';
  453. }elseif ($ks==2){
  454. $m='简约版';
  455. }elseif ($ks==3){
  456. $m='高腰版';
  457. }elseif ($ks==4){
  458. $m='纯棉版';
  459. }elseif ($ks==9){
  460. $m='青春版';
  461. }elseif ($ks==6){
  462. $m='精装版G';
  463. }elseif ($ks==7){
  464. $m='简约版G';
  465. }elseif ($ks==8){
  466. $m='高腰版G';
  467. }elseif ($ks==10){
  468. $m='青春版G';
  469. }else{
  470. $m='精装(赠)';
  471. }
  472. Log::info($v.'没有查到相应的信息');
  473. return $this->error(4000101, ['code'=>$v], '没有查到二维码对应的信息,请删除'.$m.'中第'.($k+1).'个数据重新提交。并将对应的货物单独取出');
  474. }
  475. }
  476. }
  477. DB::commit();
  478. return $this->success([]);
  479. } catch (\Exception $exception) {
  480. DB::rollBack();
  481. Log::error($exception);
  482. return $this->error(40023, '', '发货失败,请重新尝试');
  483. }
  484. }
  485. /**子码同时发货**/
  486. public function send_child_good($id, $user_id, $good_select_id)
  487. {
  488. DB::beginTransaction();
  489. try {
  490. //查找下一级
  491. $data = Select::where('pid', $id)->get();
  492. //当前货物信息
  493. $re = Select::where('sort', '=', $id)->first();
  494. //中码发货时
  495. if ($re->level != 1) {
  496. //修改中码所属大码的状态
  497. $num = $this->update_full($re->pid);
  498. if ($num == 300) {
  499. throw new \Exception(1);
  500. }
  501. }
  502. foreach ($data as $k => $v) {
  503. if ($v->is_lowest != 1) {
  504. $num = $this->send_child_good($v->id, $user_id, $good_select_id);
  505. if ($num == 300) {
  506. throw new \Exception(1);
  507. }
  508. }
  509. $se = Select::find($v->id);
  510. $se->track_status = 2;
  511. $se->com_binding = 0;
  512. $se->user_id = $user_id;
  513. $se->good_select_id = $good_select_id;
  514. if (!$se->save()) {
  515. throw new \Exception('1');
  516. }
  517. $user_s = User::find($user_id);
  518. $data = [
  519. 'op_name' => '公司',
  520. 'op_phone' => '',
  521. 'op_id' => '',
  522. 'accept_name' => $user_s->nickname,
  523. 'accept_phone' => $user_s->mobile,
  524. 'accept_id' => $user_s->id,
  525. 'type' => 1,
  526. 'select_id' => $v->id
  527. ];
  528. event(new SendGoodLogEvent($data));
  529. }
  530. DB::commit();
  531. return 200;
  532. } catch (\Exception $exception) {
  533. DB::rollBack();
  534. return 300;
  535. }
  536. }
  537. public function user_send_good(Request $request)
  538. {
  539. return $this->success([]);
  540. }
  541. /**代理发货子码跟着发货(已取消)**/
  542. public function user_send_goods($pid, $user_id, $id, $type = 0)
  543. {
  544. //查找下一级
  545. $data = Select::where('pid', $pid)->get();
  546. //当前货物信息
  547. $re = Select::where('sort', '=', $pid)->first();
  548. //中码发货时
  549. if ($type == 0) {
  550. if ($re->level != 1) {
  551. //修改中码所属大码的状态
  552. $num = $this->update_full($re->pid);
  553. if ($num == 300) {
  554. throw new \Exception(1);
  555. }
  556. }
  557. }
  558. foreach ($data as $k => $v) {
  559. if ($v->is_lowest != 1) {
  560. $num = $this->user_send_goods($v->sort, $user_id, $id);
  561. if ($num == 300) {
  562. throw new \Exception(1);
  563. }
  564. }
  565. $se = Select::find($v->id);
  566. $se->track_status = 2;
  567. $se->user_id = $user_id;
  568. if (!$se->save()) {
  569. Log::error('走了这里(所属者的改变)');
  570. throw new \Exception('1');
  571. }
  572. $users = User::find($id);
  573. $user_s = User::find($user_id);
  574. $data = [
  575. 'op_name' => $users->nickname,
  576. 'op_phone' => $users->mobile,
  577. 'op_id' => $users->id,
  578. 'accept_name' => $user_s->nickname,
  579. 'accept_phone' => $user_s->mobile,
  580. 'accept_id' => $user_s->id,
  581. 'type' => 0,
  582. 'select_id' => $v->id
  583. ];
  584. event(new SendGoodLogEvent($data));
  585. }
  586. }
  587. /**小码发货时更改中码和大码**/
  588. public function update_full($pid)
  589. {
  590. DB::beginTransaction();
  591. try {
  592. $re = Select::where('sort', '=', $pid)->first();
  593. $re->is_full = 1;
  594. if (!$re->save()) {
  595. throw new \Exception('1');
  596. }
  597. if ($re->level != 1) {
  598. $this->update_full($re->pid);
  599. }
  600. DB::commit();
  601. return 200;
  602. } catch (\Exception $exception) {
  603. DB::rollBack();
  604. Log::error($exception);
  605. return 300;
  606. }
  607. }
  608. public function get_lower_user(Request $request)
  609. {
  610. return $this->success_list([]);
  611. }
  612. /**查询**/
  613. public function get_lower_users(Request $request)
  614. {
  615. Log::error($request->all());
  616. if ($request->has('type')) {
  617. if ($request->type == 0) {
  618. return $this->success_list([]);
  619. } else {
  620. $search_name = $request->search_name;
  621. $user = User::where('nickname', 'like', '%' . $search_name . '%')->orwhere('realname', 'like', '%' . $search_name . '%')->orwhere('mobile', 'like', "%$search_name");
  622. // $user = User::where('nickname', 'like', '%' . $search_name . '%')->orwhere('mobile', 'like', '%' . $search_name . '%');
  623. $count = $user->get()->count();
  624. $user = $user->select('mobile as phone','uuid', 'nickname', 'realname', 'id', 'headimgurl as avatar','level')->take(30)->skip(($request->page - 1) * 30)->get();
  625. foreach ($user as $k=>$v){
  626. try {
  627. $user[$k]->phone=Crypt::decryptString($v->uuid);
  628. }catch (\Exception $exception){
  629. }
  630. }
  631. return $this->success_list($user, '', $count);
  632. }
  633. }
  634. }
  635. /**检查是够已经发货**/
  636. public function is_full($code)
  637. {
  638. $re = Select::where('code', $code)->first();
  639. if ($re->is_full == 1) {
  640. return 300;
  641. }
  642. return 200;
  643. }
  644. /**代理退货**/
  645. public function user_return_good(Request $request)
  646. {
  647. return $this->error(40029, '', '暂未查询到相应的信息');
  648. }
  649. /**检查是否为真**/
  650. public function is_true($code)
  651. {
  652. $re = Select::where('code', $code)->first();
  653. if ($re->is_true == 1) {
  654. return 300;
  655. }
  656. return 200;
  657. }
  658. /**检查用户**/
  659. public function check_user_level($id, $user_id)
  660. {
  661. if ($id == $user_id) {
  662. return ['code' => 50026, 'message' => '你不能对自己的货物进行退货操作'];
  663. }
  664. return ['code' => 200];
  665. }
  666. public function new_send_good(Request $request)
  667. {
  668. if ($request->id) {
  669. return $this->error(50026, '', '请选择代理进行发货');
  670. }
  671. DB::beginTransaction();
  672. try {
  673. } catch (\Exception $exception) {
  674. }
  675. }
  676. /*
  677. * 新版发货
  678. * **/
  679. public function new_send(Request $request){
  680. }
  681. public function send_goodss(Request $request)
  682. {
  683. $input = $request->all();
  684. $code = json_decode($input['code']);
  685. $codes=array_merge($code[1],$code[2],$code[3],$code[4]);
  686. $r=Select::whereIn('code',$codes)->where('is_full',1)->first();
  687. if($r){
  688. return $this->error(50021, '', '小码已经部分发货,不能扫描中码或者大码进行发货');
  689. }
  690. $count=Select::whereIn('code',$codes)->count();
  691. if ($count!=count($codes)){
  692. return $this->error(40023, '', '没有查到二维码对应的信息,请重试');
  693. }
  694. GoodSendJobs::dispatch($input);
  695. return $this->success([]);
  696. }
  697. /*四种商品的选择**/
  698. public function get_goodwazi()
  699. {
  700. $re = GoodSelect::select('id', 'name as good_name')->where('id',14)->orderByDesc('rank')->where('status',0)->get();
  701. return $this->success($re);
  702. }
  703. public function wazineiku(Request $request)
  704. {
  705. $input = $request->all();
  706. $u_id=Auth::user()->id;
  707. $users=User::find($u_id);
  708. if ($users->mobile==17333738670){
  709. return $this->error(500214,'','账号暂停使用');
  710. }
  711. $name=$this->JudgePhone($users->mobile);
  712. $user = User::where('id', $request->id)->first();
  713. Log::error($input['code']);
  714. Log::error($u_id);
  715. $code = json_decode($input['code']);
  716. DB::beginTransaction();
  717. try {
  718. foreach ($code as $ks => $vs) {
  719. $good=GoodSelect::where('id',$ks)->select('good_name')->first();
  720. foreach ($vs as $k=>$v){
  721. $lenth=mb_strlen($v);
  722. if ($lenth>20){
  723. $v=trim($v);
  724. $re = Select::where('code', $v)->first();
  725. if ($re) {
  726. //小码发货
  727. if ($re->is_lowest == 1) {
  728. $re->user_id = $user->id;
  729. $re->track_status = 2;
  730. $re->com_binding = 0;
  731. $re->is_true = 0;
  732. $re->good_select_id = $ks;
  733. $num = $this->update_full($re->pid);
  734. if ($num == 300) {
  735. return $this->error(50021, '', '修改状态出错');
  736. }
  737. $data = [
  738. 'op_name' => $name,
  739. 'op_phone' => $users->mobile,
  740. 'op_id' => 0,
  741. 'good_name'=>$good->good_name,
  742. 'accept_name' => $user->nickname,
  743. 'accept_phone' => $user->mobile,
  744. 'accept_id' => $user->id,
  745. 'type' => 1,
  746. 'select_id' => $re->id
  747. ];
  748. if (!$re->save()) {
  749. throw new \Exception(1);
  750. }
  751. event(new SendGoodLogEvent($data));
  752. } else {//中码或者大码发货
  753. $num = $this->is_full($v);
  754. if ($num == 300) {
  755. return $this->error(50026, '', '小码已经部分发货,不能扫描中码或者大码进行发货');
  756. }
  757. if ($re->level != 1) {
  758. $re->user_id = $request->id;
  759. $re->com_binding = 0;
  760. $re->is_true = 0;
  761. $re->good_select_id = $ks;
  762. if (!$re->save()) {
  763. throw new \Exception('1');
  764. }
  765. $num = $this->update_full($re->pid);
  766. if ($num == 300) {
  767. throw new \Exception(1);
  768. }
  769. $data = [
  770. 'op_name' => $name,
  771. 'op_phone' => $users->mobile,
  772. 'op_id' => 0,
  773. 'good_name'=>$good->good_name,
  774. 'accept_name' => $user->nickname,
  775. 'accept_phone' => $user->mobile,
  776. 'accept_id' => $user->id,
  777. 'type' => 1,
  778. 'select_id' => $re->id
  779. ];
  780. event(new SendGoodLogEvent($data));
  781. $level_data = Select::where('pid', $re->sort)->get();
  782. foreach ($level_data as $ke => $va) {
  783. $res = Select::where('code', $va->code)->first();
  784. $res->user_id = $request->id;
  785. $res->com_binding = 0;
  786. $res->is_true = 0;
  787. $res->good_select_id = $ks;
  788. if (!$res->save()) {
  789. throw new \Exception(1);
  790. }
  791. $data = [
  792. 'op_name' => $name,
  793. 'op_phone' => $users->mobile,
  794. 'op_id' => 0,
  795. 'good_name'=>$good->good_name,
  796. 'accept_name' => $user->nickname,
  797. 'accept_phone' => $user->mobile,
  798. 'accept_id' => $user->id,
  799. 'type' => 1,
  800. 'select_id' => $va->id
  801. ];
  802. event(new SendGoodLogEvent($data));
  803. }
  804. } else {
  805. /***大码发货,并记录日志情况*/
  806. $re->user_id = $request->id;
  807. $re->com_binding = 0;
  808. $re->is_true = 0;
  809. $re->good_select_id = $ks;
  810. if (!$re->save()) {
  811. throw new \Exception('1');
  812. }
  813. $data = [
  814. 'op_name' => $name,
  815. 'op_phone' => $users->mobile,
  816. 'op_id' => 0,
  817. 'good_name'=>$good->good_name,
  818. 'accept_name' => $user->nickname,
  819. 'accept_phone' => $user->mobile,
  820. 'accept_id' => $user->id,
  821. 'type' => 1,
  822. 'select_id' => $re->id
  823. ];
  824. event(new SendGoodLogEvent($data));
  825. /**查询**/
  826. $level_data = Select::where('pid', $re->sort)->get();
  827. foreach ($level_data as $ke => $va) {
  828. /***修改所属者*/
  829. $res = Select::where('code', $va->code)->first();
  830. $res->user_id = $request->id;
  831. $res->com_binding = 0;
  832. $res->is_true = 0;
  833. $res->good_select_id = $ks;
  834. if (!$res->save()) {
  835. throw new \Exception(1);
  836. }
  837. $data = [
  838. 'op_name' => $name,
  839. 'op_phone' => $users->mobile,
  840. 'op_id' => 0,
  841. 'good_name'=>$good->good_name,
  842. 'accept_name' => $user->nickname,
  843. 'accept_phone' => $user->mobile,
  844. 'accept_id' => $user->id,
  845. 'type' => 1,
  846. 'select_id' => $va->id
  847. ];
  848. event(new SendGoodLogEvent($data));
  849. /**如果现在的等级不是最低级,则执行下面的内容**/
  850. if ($va->is_lowest != 1) {
  851. $ress = Select::where('pid', $va->sort)->get();
  852. foreach ($ress as $kes => $vas) {
  853. $resss = Select::where('code', $vas->code)->first();
  854. $resss->user_id = $request->id;
  855. $resss->com_binding = 0;
  856. $resss->is_true = 0;
  857. $resss->good_select_id = $ks;
  858. if (!$resss->save()) {
  859. throw new \Exception(1);
  860. }
  861. $data = [
  862. 'op_name' => $name,
  863. 'op_phone' => $users->mobile,
  864. 'op_id' => 0,
  865. 'accept_name' => $user->nickname,
  866. 'accept_phone' => $user->mobile,
  867. 'accept_id' => $user->id,
  868. 'type' => 1,
  869. 'good_name'=>$good->good_name,
  870. 'select_id' => $vas->id
  871. ];
  872. event(new SendGoodLogEvent($data));
  873. }
  874. }
  875. }
  876. }
  877. }
  878. }
  879. else {
  880. Log::error($k+1);
  881. if ($ks==1){
  882. $m='精装版';
  883. }elseif ($ks==2){
  884. $m='简约版';
  885. }elseif ($ks==3){
  886. $m='高腰版';
  887. }elseif ($ks==4){
  888. $m='纯棉版';
  889. }elseif ($ks==9){
  890. $m='青春版';
  891. }elseif ($ks==6){
  892. $m='精装版G';
  893. }elseif ($ks==7){
  894. $m='简约版G';
  895. }elseif ($ks==8){
  896. $m='高腰版G';
  897. }elseif ($ks==10){
  898. $m='青春版G';
  899. }elseif($ks==11){
  900. $m='纯棉赠';
  901. }elseif($ks==12){
  902. $m='青春赠';
  903. }elseif($ks==13){
  904. $m='简约赠';
  905. }
  906. else{
  907. $m='精装(赠)';
  908. }
  909. Log::info($v.'没有查到相应的信息');
  910. return $this->error(4000101, ['code'=>$v], '没有查到二维码对应的信息,请删除'.$m.'中第'.($k+1).'个数据重新提交。并将对应的货物单独取出');
  911. }
  912. }else{
  913. if ($lenth==10){
  914. $re = FwCode::where('top_code', $v)->first();
  915. if (!$re){
  916. $message=$this->message($k,$v,$ks);
  917. $this->error(400,'',$message);
  918. }
  919. $child_count=FwCode::where('top_code',$v)->groupBy('user_id')->get();
  920. if (count($child_count)!=1){
  921. return $this->error(50026,'','小码已发货不能使用大码发货');
  922. }
  923. $child=FwCode::where('top_code',$v)->get();
  924. FwCode::where('top_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  925. foreach ($child as $kke=>$vve){
  926. $data = [
  927. 'op_name' => $name,
  928. 'op_phone' => $users->mobile,
  929. 'op_id' => 0,
  930. 'good_name'=>$good->good_name,
  931. 'accept_name' => $user->nickname,
  932. 'accept_phone' => $user->mobile,
  933. 'accept_id' => $user->id,
  934. 'type' => 1,
  935. 'select_id' => $vve->id
  936. ];
  937. $this->sendlog($data);
  938. }
  939. }
  940. elseif ($lenth==11){//中码发货
  941. $re = FwCode::where('mid_code', $v)->first();
  942. if (!$re){
  943. $message=$this->message($k,$v,$ks);
  944. $this->error(400,'',$message);
  945. }
  946. $child_count=FwCode::where('mid_code',$v)->groupBy('user_id')->get();
  947. if (count($child_count)!=1){
  948. return $this->error(50026,'','小码已发货不能使用大码发货');
  949. }
  950. $child=FwCode::where('mid_code',$v)->get();
  951. FwCode::where('mid_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  952. foreach ($child as $kke=>$vve){
  953. $data = [
  954. 'op_name' => $name,
  955. 'op_phone' => $users->mobile,
  956. 'op_id' => 0,
  957. 'good_name'=>$good->good_name,
  958. 'accept_name' => $user->nickname,
  959. 'accept_phone' => $user->mobile,
  960. 'accept_id' => $user->id,
  961. 'type' => 1,
  962. 'select_id' => $vve->id
  963. ];
  964. $this->sendlog($data);
  965. }
  966. }
  967. elseif ($lenth==12){ //小码发货
  968. $re = FwCode::where('code', $v)->first();
  969. if (!$re){
  970. $message=$this->message($k,$v,$ks);
  971. $this->error(400,'',$message);
  972. }
  973. FwCode::where('code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  974. $data = [
  975. 'op_name' => $name,
  976. 'op_phone' => $users->mobile,
  977. 'op_id' => 0,
  978. 'good_name'=>$good->good_name,
  979. 'accept_name' => $user->nickname,
  980. 'accept_phone' => $user->mobile,
  981. 'accept_id' => $user->id,
  982. 'type' => 1,
  983. 'select_id' => $re->id
  984. ];
  985. $this->sendlog($data);
  986. }
  987. }
  988. //大码
  989. }
  990. }
  991. DB::commit();
  992. return $this->success([]);
  993. } catch (\Exception $exception) {
  994. DB::rollBack();
  995. Log::error($exception);
  996. return $this->error(40023, '', '发货失败,请重新尝试');
  997. }
  998. }
  999. public function newcode($v){
  1000. //大码
  1001. if ($lenth==10){
  1002. $re = FwCode::where('top_code', $v)->first();
  1003. if (!$re){
  1004. $message=$this->message($k,$v);
  1005. $this->error(400,'',$message);
  1006. }
  1007. $child_count=FwCode::where('top_code',$v)->groupBy('user_id')->get();
  1008. if (count($child_count)!=1){
  1009. return $this->error(50026,'','小码已发货不能使用大码发货');
  1010. }
  1011. $child=FwCode::where('top_code',$v)->get();
  1012. FwCode::where('top_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  1013. foreach ($child as $kke=>$vve){
  1014. $data = [
  1015. 'op_name' => $name,
  1016. 'op_phone' => $users->mobile,
  1017. 'op_id' => 0,
  1018. 'good_name'=>$good->good_name,
  1019. 'accept_name' => $user->nickname,
  1020. 'accept_phone' => $user->mobile,
  1021. 'accept_id' => $user->id,
  1022. 'type' => 1,
  1023. 'select_id' => $vve->id
  1024. ];
  1025. $this->sendlog($data);
  1026. }
  1027. }
  1028. elseif ($lenth==11){//中码发货
  1029. $re = FwCode::where('mid_code', $v)->first();
  1030. if (!$re){
  1031. $message=$this->message($k,$v);
  1032. $this->error(400,'',$message);
  1033. }
  1034. $child_count=FwCode::where('mid_code',$v)->groupBy('user_id')->get();
  1035. if (count($child_count)!=1){
  1036. return $this->error(50026,'','小码已发货不能使用大码发货');
  1037. }
  1038. $child=FwCode::where('mid_code',$v)->get();
  1039. FwCode::where('mid_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  1040. foreach ($child as $kke=>$vve){
  1041. $data = [
  1042. 'op_name' => $name,
  1043. 'op_phone' => $users->mobile,
  1044. 'op_id' => 0,
  1045. 'good_name'=>$good->good_name,
  1046. 'accept_name' => $user->nickname,
  1047. 'accept_phone' => $user->mobile,
  1048. 'accept_id' => $user->id,
  1049. 'type' => 1,
  1050. 'select_id' => $vve->id
  1051. ];
  1052. $this->sendlog($data);
  1053. }
  1054. }
  1055. elseif ($lenth==12){ //小码发货
  1056. $re = FwCode::where('code', $v)->first();
  1057. if (!$re){
  1058. $message=$this->message($k,$v);
  1059. $this->error(400,'',$message);
  1060. }
  1061. FwCode::where('code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
  1062. $data = [
  1063. 'op_name' => $name,
  1064. 'op_phone' => $users->mobile,
  1065. 'op_id' => 0,
  1066. 'good_name'=>$good->good_name,
  1067. 'accept_name' => $user->nickname,
  1068. 'accept_phone' => $user->mobile,
  1069. 'accept_id' => $user->id,
  1070. 'type' => 1,
  1071. 'select_id' => $re->id
  1072. ];
  1073. $this->sendlog($data);
  1074. }
  1075. }
  1076. public function oldcode(){
  1077. }
  1078. }