12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151 |
- <?php
- namespace App\Http\Controllers;
- use App\Events\ReturnGoodLog;
- use App\Events\SendGoodLogEvent;
- use App\Jobs\GoodSendJobs;
- use App\Models\DeviceAccount;
- use App\Models\Express;
- use App\Models\FwCode;
- use App\Models\FwCodeLog;
- use App\Models\GoodSelect;
- use App\Models\OrderTest;
- use App\Models\Select;
- use App\Models\SendGoodLog;
- use App\Models\User;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Crypt;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Validator;
- class FwCodeController extends Controller
- {
- /**公司扫码快递单*/
- public function get_express(Request $request)
- {
- $u_id=Auth::user()->id;
- $users=User::find($u_id);
- if ($users->mobile==17333738670){
- return $this->error(500214,'','账号暂停使用');
- }
- Log::error($request->all());
- Log::error($u_id);
- $re=DB::table('newexpress')->where('express_num','like',"%".$request->express_number."%")->first();
- if ($re){
- $data['belong_user_nickname'] = '';
- $data['belong_user_mobile'] = '';
- $data['address_name'] = '';
- $data['belong_user_id'] = '';
- $data['user_id'] = '';
- $order=OrderTest::where('order_num',$re->order_num)->first();
- if (!$order){
- // $res=DB::table('newexpress_copy1')->where('express_num',$request->express_number)->first();
- // $user=User::where('mobile',$res->mobile)->first();
- if (!$order){
- return $this->error(50214,'','订单号:'.$re->order_num.'不存在');
- }
- }
- $user=User::find($order->good_user_id);
- $data['user_id'] = $user->id;
- $data['belong_user_nickname'] = $user->remark_name;
- $data['belong_user_mobile'] = $user->mobile;
- $data['belong_user_avatar'] = $user->headimgurl;
- $data['belong_user_id'] = $user->id;
- return $this->success($data);
- }
- $datas = Express::where('express_number', $request->express_number)->first();
- if (!$datas){
- $nums=mb_substr($request->express_number,0,1);
- Log::error($nums.'sss');
- if ($nums==7){
- $num=(int)$request->express_number;
- $datas = Express::where('express_number','=',$num)->first();
- }
- }
- $data['belong_user_nickname'] = '';
- $data['belong_user_mobile'] = '';
- $data['address_name'] = '';
- $data['belong_user_id'] = '';
- $data['user_id'] = '';
- if ($datas) {
- $order = OrderTest::with(['get_good_user', 'get_address_user'])->find($datas->order_id);
- $data['user_id'] = $order->user_id;
- if ($order->get_good_user) {
- $data['belong_user_nickname'] = $order->get_good_user->nickname;
- $data['belong_user_mobile'] = $order->get_good_user->mobile;
- $data['belong_user_avatar'] = $order->get_good_user->headimgurl;
- $data['belong_user_id'] = $order->get_good_user->id;
- }
- if ($order->get_address_user) {
- $data['address_name'] = $order->get_address_user->username;
- }
- return $this->success($data);
- } else {
- return $this->error(50023, '', '请检查快递单号是否正确');
- }
- }
- /*四种商品的选择**/
- public function get_good()
- {
- $re = GoodSelect::select('id', 'name as good_name')->orderByDesc('rank')->where('status',0)->get();
- return $this->success($re);
- }
- /****/
- public function JudgePhone($phone){
- if ($phone=='15220141101'){
- $name='公司';
- }elseif ($phone=='17333738670'){
- $name='吴桥仓库';
- }else{
- $name=DeviceAccount::where('mobile',$phone)->orwhere('phone',$phone)->where('status',0)->value('name');
- }
- return $name;
- }
- public function message($k,$v,$ks=14){
- // $m='袜子';
- if ($ks==1){
- $m='精装版';
- }elseif ($ks==2){
- $m='简约版';
- }elseif ($ks==3){
- $m='高腰版';
- }elseif ($ks==4){
- $m='纯棉版';
- }elseif ($ks==9){
- $m='青春版';
- }elseif ($ks==6){
- $m='精装版G';
- }elseif ($ks==7){
- $m='简约版G';
- }elseif ($ks==8){
- $m='高腰版G';
- }elseif ($ks==10){
- $m='青春版G';
- }elseif($ks==11){
- $m='纯棉赠';
- }elseif($ks==12){
- $m='青春赠';
- }elseif($ks==13){
- $m='简约赠';
- }elseif($ks==14){
- $m='袜子';
- }
- else{
- $m='精装(赠)';
- }
- Log::info($v.'没有查到相应的信息');
- return '没有查到二维码对应的信息,请删除'.$m.'中第'.($k+1).'个数据重新提交。并将对应的货物单独取出';
- }
- public function sendlog($event){
- DB::beginTransaction();
- try{
- $log=new FwCodeLog();
- if ($event['type']==1){
- $op_id=0;
- $note='此货物('.$event['good_name'].')由'.$event['op_name'].'在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
- }else{
- $op_id=$event['op_id'];
- $note='此货物由昵称为:'.$event['op_name'].'、手机号为:'.$event['op_phone'].'在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
- }
- $event['note']=$note;
- $event['op_id']=$op_id;
- // SendGoodLog::create($event);
- $log->op_name=$event['op_name'];
- $log->op_phone=$event['op_phone'];
- $log->op_id=$op_id;
- $log->accept_name=$event['accept_name'];
- $log->accept_phone=$event['accept_phone'];
- $log->accept_id=$event['accept_id'];
- $log->select_id=$event['select_id'];
- $log->note=$note;
- if (!$log->save()){
- throw new \Exception('1');
- }
- DB::commit();
- }catch (\Exception $exception){
- Log::error($exception);
- DB::rollBack();
- }
- }
- /**公司发货**/
- public function sendwazi(Request $request)
- {
- $input = $request->all();
- $u_id=Auth::user()->id;
- $users=User::find($u_id);
- if ($users->mobile==17333738670){
- return $this->error(500214,'','账号暂停使用');
- }
- $name=$this->JudgePhone($users->mobile);
- $user = User::where('id', $request->id)->first();
- Log::error($input['code']);
- Log::error($u_id);
- $code = json_decode($input['code']);
- DB::beginTransaction();
- try {
- foreach ($code as $ks => $vs) {
- $good=GoodSelect::where('id',$ks)->select('good_name')->first();
- foreach ($vs as $k=>$v){
- $lenth=mb_strlen($v);
- //大码
- if ($lenth==10){
- $re = FwCode::where('top_code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v);
- $this->error(400,'',$message);
- }
- $child_count=FwCode::where('top_code',$v)->groupBy('user_id')->get();
- if (count($child_count)!=1){
- return $this->error(50026,'','小码已发货不能使用大码发货');
- }
- $child=FwCode::where('top_code',$v)->get();
- FwCode::where('top_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- foreach ($child as $kke=>$vve){
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $vve->id
- ];
- $this->sendlog($data);
- }
- }elseif ($lenth==11){//中码发货
- $re = FwCode::where('mid_code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v);
- $this->error(400,'',$message);
- }
- $child_count=FwCode::where('mid_code',$v)->groupBy('user_id')->get();
- if (count($child_count)!=1){
- return $this->error(50026,'','小码已发货不能使用大码发货');
- }
- $child=FwCode::where('mid_code',$v)->get();
- FwCode::where('mid_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- foreach ($child as $kke=>$vve){
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $vve->id
- ];
- $this->sendlog($data);
- }
- }elseif ($lenth==12){ //小码发货
- $re = FwCode::where('code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v);
- $this->error(400,'',$message);
- }
- FwCode::where('code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- $this->sendlog($data);
- }
- }
- }
- DB::commit();
- return $this->success([]);
- } catch (\Exception $exception) {
- DB::rollBack();
- Log::error($exception);
- return $this->error(40023, '', '发货失败,请重新尝试');
- }
- }
- public function send_goods_new(Request $request)
- {
- $input = $request->all();
- Log::error($input);
- $u_id=Auth::user()->id;
- $users=User::find($u_id);
- if ($users->mobile==17333738670){
- return $this->error(500214,'','账号暂停使用');
- }
- $name=$this->JudgePhone($users->mobile);
- $user = User::where('id', $request->id)->first();
- Log::error($input['code']);
- $code = json_decode($input['code']);
- // $code=$input['code'];
- DB::beginTransaction();
- try {
- foreach ($code as $ks => $vs) {
- $good=GoodSelect::where('id',$ks)->select('good_name')->first();
- foreach ($vs as $k=>$v){
- $v=trim($v);
- $re = Select::where('code', $v)->first();
- if ($re) {
- //小码发货
- if ($re->is_lowest == 1) {
- $re->user_id = $user->id;
- $re->track_status = 2;
- $re->com_binding = 0;
- $re->is_true = 0;
- $re->good_select_id = $ks;
- $num = $this->update_full($re->pid);
- if ($num == 300) {
- return $this->error(50021, '', '修改状态出错');
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- if (!$re->save()) {
- throw new \Exception(1);
- }
- event(new SendGoodLogEvent($data));
- } else {//中码或者大码发货
- $num = $this->is_full($v);
- if ($num == 300) {
- return $this->error(50026, '', '小码已经部分发货,不能扫描中码或者大码进行发货');
- }
- if ($re->level != 1) {
- $re->user_id = $request->id;
- $re->com_binding = 0;
- $re->is_true = 0;
- $re->good_select_id = $ks;
- if (!$re->save()) {
- throw new \Exception('1');
- }
- $num = $this->update_full($re->pid);
- if ($num == 300) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- event(new SendGoodLogEvent($data));
- $level_data = Select::where('pid', $re->sort)->get();
- foreach ($level_data as $ke => $va) {
- $res = Select::where('code', $va->code)->first();
- $res->user_id = $request->id;
- $res->com_binding = 0;
- $res->is_true = 0;
- $res->good_select_id = $ks;
- if (!$res->save()) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $va->id
- ];
- event(new SendGoodLogEvent($data));
- }
- } else {
- /***大码发货,并记录日志情况*/
- $re->user_id = $request->id;
- $re->com_binding = 0;
- $re->is_true = 0;
- $re->good_select_id = $ks;
- if (!$re->save()) {
- throw new \Exception('1');
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- event(new SendGoodLogEvent($data));
- /**查询**/
- $level_data = Select::where('pid', $re->sort)->get();
- foreach ($level_data as $ke => $va) {
- /***修改所有所属者*/
- $res = Select::where('code', $va->code)->first();
- $res->user_id = $request->id;
- $res->com_binding = 0;
- $res->is_true = 0;
- $res->good_select_id = $ks;
- if (!$res->save()) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $va->id
- ];
- event(new SendGoodLogEvent($data));
- /**如果现在的等级不是最低级,则执行下面的内容**/
- if ($va->is_lowest != 1) {
- $ress = Select::where('pid', $va->sort)->get();
- foreach ($ress as $kes => $vas) {
- $resss = Select::where('code', $vas->code)->first();
- $resss->user_id = $request->id;
- $resss->com_binding = 0;
- $resss->is_true = 0;
- $resss->good_select_id = $ks;
- if (!$resss->save()) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'good_name'=>$good->good_name,
- 'select_id' => $vas->id
- ];
- event(new SendGoodLogEvent($data));
- }
- }
- }
- }
- }
- } else {
- Log::error($k+1);
- if ($ks==1){
- $m='精装版';
- }elseif ($ks==2){
- $m='简约版';
- }elseif ($ks==3){
- $m='高腰版';
- }elseif ($ks==4){
- $m='纯棉版';
- }elseif ($ks==9){
- $m='青春版';
- }elseif ($ks==6){
- $m='精装版G';
- }elseif ($ks==7){
- $m='简约版G';
- }elseif ($ks==8){
- $m='高腰版G';
- }elseif ($ks==10){
- $m='青春版G';
- }else{
- $m='精装(赠)';
- }
- Log::info($v.'没有查到相应的信息');
- return $this->error(4000101, ['code'=>$v], '没有查到二维码对应的信息,请删除'.$m.'中第'.($k+1).'个数据重新提交。并将对应的货物单独取出');
- }
- }
- }
- DB::commit();
- return $this->success([]);
- } catch (\Exception $exception) {
- DB::rollBack();
- Log::error($exception);
- return $this->error(40023, '', '发货失败,请重新尝试');
- }
- }
- /**子码同时发货**/
- public function send_child_good($id, $user_id, $good_select_id)
- {
- DB::beginTransaction();
- try {
- //查找下一级
- $data = Select::where('pid', $id)->get();
- //当前货物信息
- $re = Select::where('sort', '=', $id)->first();
- //中码发货时
- if ($re->level != 1) {
- //修改中码所属大码的状态
- $num = $this->update_full($re->pid);
- if ($num == 300) {
- throw new \Exception(1);
- }
- }
- foreach ($data as $k => $v) {
- if ($v->is_lowest != 1) {
- $num = $this->send_child_good($v->id, $user_id, $good_select_id);
- if ($num == 300) {
- throw new \Exception(1);
- }
- }
- $se = Select::find($v->id);
- $se->track_status = 2;
- $se->com_binding = 0;
- $se->user_id = $user_id;
- $se->good_select_id = $good_select_id;
- if (!$se->save()) {
- throw new \Exception('1');
- }
- $user_s = User::find($user_id);
- $data = [
- 'op_name' => '公司',
- 'op_phone' => '',
- 'op_id' => '',
- 'accept_name' => $user_s->nickname,
- 'accept_phone' => $user_s->mobile,
- 'accept_id' => $user_s->id,
- 'type' => 1,
- 'select_id' => $v->id
- ];
- event(new SendGoodLogEvent($data));
- }
- DB::commit();
- return 200;
- } catch (\Exception $exception) {
- DB::rollBack();
- return 300;
- }
- }
- public function user_send_good(Request $request)
- {
- return $this->success([]);
- }
- /**代理发货子码跟着发货(已取消)**/
- public function user_send_goods($pid, $user_id, $id, $type = 0)
- {
- //查找下一级
- $data = Select::where('pid', $pid)->get();
- //当前货物信息
- $re = Select::where('sort', '=', $pid)->first();
- //中码发货时
- if ($type == 0) {
- if ($re->level != 1) {
- //修改中码所属大码的状态
- $num = $this->update_full($re->pid);
- if ($num == 300) {
- throw new \Exception(1);
- }
- }
- }
- foreach ($data as $k => $v) {
- if ($v->is_lowest != 1) {
- $num = $this->user_send_goods($v->sort, $user_id, $id);
- if ($num == 300) {
- throw new \Exception(1);
- }
- }
- $se = Select::find($v->id);
- $se->track_status = 2;
- $se->user_id = $user_id;
- if (!$se->save()) {
- Log::error('走了这里(所属者的改变)');
- throw new \Exception('1');
- }
- $users = User::find($id);
- $user_s = User::find($user_id);
- $data = [
- 'op_name' => $users->nickname,
- 'op_phone' => $users->mobile,
- 'op_id' => $users->id,
- 'accept_name' => $user_s->nickname,
- 'accept_phone' => $user_s->mobile,
- 'accept_id' => $user_s->id,
- 'type' => 0,
- 'select_id' => $v->id
- ];
- event(new SendGoodLogEvent($data));
- }
- }
- /**小码发货时更改中码和大码**/
- public function update_full($pid)
- {
- DB::beginTransaction();
- try {
- $re = Select::where('sort', '=', $pid)->first();
- $re->is_full = 1;
- if (!$re->save()) {
- throw new \Exception('1');
- }
- if ($re->level != 1) {
- $this->update_full($re->pid);
- }
- DB::commit();
- return 200;
- } catch (\Exception $exception) {
- DB::rollBack();
- Log::error($exception);
- return 300;
- }
- }
- public function get_lower_user(Request $request)
- {
- return $this->success_list([]);
- }
- /**查询**/
- public function get_lower_users(Request $request)
- {
- Log::error($request->all());
- if ($request->has('type')) {
- if ($request->type == 0) {
- return $this->success_list([]);
- } else {
- $search_name = $request->search_name;
- $user = User::where('nickname', 'like', '%' . $search_name . '%')->orwhere('realname', 'like', '%' . $search_name . '%')->orwhere('mobile', 'like', "%$search_name");
- // $user = User::where('nickname', 'like', '%' . $search_name . '%')->orwhere('mobile', 'like', '%' . $search_name . '%');
- $count = $user->get()->count();
- $user = $user->select('mobile as phone','uuid', 'nickname', 'realname', 'id', 'headimgurl as avatar','level')->take(30)->skip(($request->page - 1) * 30)->get();
- foreach ($user as $k=>$v){
- try {
- $user[$k]->phone=Crypt::decryptString($v->uuid);
- }catch (\Exception $exception){
- }
- }
- return $this->success_list($user, '', $count);
- }
- }
- }
- /**检查是够已经发货**/
- public function is_full($code)
- {
- $re = Select::where('code', $code)->first();
- if ($re->is_full == 1) {
- return 300;
- }
- return 200;
- }
- /**代理退货**/
- public function user_return_good(Request $request)
- {
- return $this->error(40029, '', '暂未查询到相应的信息');
- }
- /**检查是否为真**/
- public function is_true($code)
- {
- $re = Select::where('code', $code)->first();
- if ($re->is_true == 1) {
- return 300;
- }
- return 200;
- }
- /**检查用户**/
- public function check_user_level($id, $user_id)
- {
- if ($id == $user_id) {
- return ['code' => 50026, 'message' => '你不能对自己的货物进行退货操作'];
- }
- return ['code' => 200];
- }
- public function new_send_good(Request $request)
- {
- if ($request->id) {
- return $this->error(50026, '', '请选择代理进行发货');
- }
- DB::beginTransaction();
- try {
- } catch (\Exception $exception) {
- }
- }
- /*
- * 新版发货
- * **/
- public function new_send(Request $request){
- }
- public function send_goodss(Request $request)
- {
- $input = $request->all();
- $code = json_decode($input['code']);
- $codes=array_merge($code[1],$code[2],$code[3],$code[4]);
- $r=Select::whereIn('code',$codes)->where('is_full',1)->first();
- if($r){
- return $this->error(50021, '', '小码已经部分发货,不能扫描中码或者大码进行发货');
- }
- $count=Select::whereIn('code',$codes)->count();
- if ($count!=count($codes)){
- return $this->error(40023, '', '没有查到二维码对应的信息,请重试');
- }
- GoodSendJobs::dispatch($input);
- return $this->success([]);
- }
- /*四种商品的选择**/
- public function get_goodwazi()
- {
- $re = GoodSelect::select('id', 'name as good_name')->where('id',14)->orderByDesc('rank')->where('status',0)->get();
- return $this->success($re);
- }
- public function wazineiku(Request $request)
- {
- $input = $request->all();
- $u_id=Auth::user()->id;
- $users=User::find($u_id);
- if ($users->mobile==17333738670){
- return $this->error(500214,'','账号暂停使用');
- }
- $name=$this->JudgePhone($users->mobile);
- $user = User::where('id', $request->id)->first();
- Log::error($input['code']);
- Log::error($u_id);
- $code = json_decode($input['code']);
- DB::beginTransaction();
- try {
- foreach ($code as $ks => $vs) {
- $good=GoodSelect::where('id',$ks)->select('good_name')->first();
- foreach ($vs as $k=>$v){
- $lenth=mb_strlen($v);
- if ($lenth>20){
- $v=trim($v);
- $re = Select::where('code', $v)->first();
- if ($re) {
- //小码发货
- if ($re->is_lowest == 1) {
- $re->user_id = $user->id;
- $re->track_status = 2;
- $re->com_binding = 0;
- $re->is_true = 0;
- $re->good_select_id = $ks;
- $num = $this->update_full($re->pid);
- if ($num == 300) {
- return $this->error(50021, '', '修改状态出错');
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- if (!$re->save()) {
- throw new \Exception(1);
- }
- event(new SendGoodLogEvent($data));
- } else {//中码或者大码发货
- $num = $this->is_full($v);
- if ($num == 300) {
- return $this->error(50026, '', '小码已经部分发货,不能扫描中码或者大码进行发货');
- }
- if ($re->level != 1) {
- $re->user_id = $request->id;
- $re->com_binding = 0;
- $re->is_true = 0;
- $re->good_select_id = $ks;
- if (!$re->save()) {
- throw new \Exception('1');
- }
- $num = $this->update_full($re->pid);
- if ($num == 300) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- event(new SendGoodLogEvent($data));
- $level_data = Select::where('pid', $re->sort)->get();
- foreach ($level_data as $ke => $va) {
- $res = Select::where('code', $va->code)->first();
- $res->user_id = $request->id;
- $res->com_binding = 0;
- $res->is_true = 0;
- $res->good_select_id = $ks;
- if (!$res->save()) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $va->id
- ];
- event(new SendGoodLogEvent($data));
- }
- } else {
- /***大码发货,并记录日志情况*/
- $re->user_id = $request->id;
- $re->com_binding = 0;
- $re->is_true = 0;
- $re->good_select_id = $ks;
- if (!$re->save()) {
- throw new \Exception('1');
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- event(new SendGoodLogEvent($data));
- /**查询**/
- $level_data = Select::where('pid', $re->sort)->get();
- foreach ($level_data as $ke => $va) {
- /***修改所属者*/
- $res = Select::where('code', $va->code)->first();
- $res->user_id = $request->id;
- $res->com_binding = 0;
- $res->is_true = 0;
- $res->good_select_id = $ks;
- if (!$res->save()) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $va->id
- ];
- event(new SendGoodLogEvent($data));
- /**如果现在的等级不是最低级,则执行下面的内容**/
- if ($va->is_lowest != 1) {
- $ress = Select::where('pid', $va->sort)->get();
- foreach ($ress as $kes => $vas) {
- $resss = Select::where('code', $vas->code)->first();
- $resss->user_id = $request->id;
- $resss->com_binding = 0;
- $resss->is_true = 0;
- $resss->good_select_id = $ks;
- if (!$resss->save()) {
- throw new \Exception(1);
- }
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'good_name'=>$good->good_name,
- 'select_id' => $vas->id
- ];
- event(new SendGoodLogEvent($data));
- }
- }
- }
- }
- }
- }
- else {
- Log::error($k+1);
- if ($ks==1){
- $m='精装版';
- }elseif ($ks==2){
- $m='简约版';
- }elseif ($ks==3){
- $m='高腰版';
- }elseif ($ks==4){
- $m='纯棉版';
- }elseif ($ks==9){
- $m='青春版';
- }elseif ($ks==6){
- $m='精装版G';
- }elseif ($ks==7){
- $m='简约版G';
- }elseif ($ks==8){
- $m='高腰版G';
- }elseif ($ks==10){
- $m='青春版G';
- }elseif($ks==11){
- $m='纯棉赠';
- }elseif($ks==12){
- $m='青春赠';
- }elseif($ks==13){
- $m='简约赠';
- }
- else{
- $m='精装(赠)';
- }
- Log::info($v.'没有查到相应的信息');
- return $this->error(4000101, ['code'=>$v], '没有查到二维码对应的信息,请删除'.$m.'中第'.($k+1).'个数据重新提交。并将对应的货物单独取出');
- }
- }else{
- if ($lenth==10){
- $re = FwCode::where('top_code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v,$ks);
- $this->error(400,'',$message);
- }
- $child_count=FwCode::where('top_code',$v)->groupBy('user_id')->get();
- if (count($child_count)!=1){
- return $this->error(50026,'','小码已发货不能使用大码发货');
- }
- $child=FwCode::where('top_code',$v)->get();
- FwCode::where('top_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- foreach ($child as $kke=>$vve){
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $vve->id
- ];
- $this->sendlog($data);
- }
- }
- elseif ($lenth==11){//中码发货
- $re = FwCode::where('mid_code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v,$ks);
- $this->error(400,'',$message);
- }
- $child_count=FwCode::where('mid_code',$v)->groupBy('user_id')->get();
- if (count($child_count)!=1){
- return $this->error(50026,'','小码已发货不能使用大码发货');
- }
- $child=FwCode::where('mid_code',$v)->get();
- FwCode::where('mid_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- foreach ($child as $kke=>$vve){
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $vve->id
- ];
- $this->sendlog($data);
- }
- }
- elseif ($lenth==12){ //小码发货
- $re = FwCode::where('code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v,$ks);
- $this->error(400,'',$message);
- }
- FwCode::where('code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- $this->sendlog($data);
- }
- }
- //大码
- }
- }
- DB::commit();
- return $this->success([]);
- } catch (\Exception $exception) {
- DB::rollBack();
- Log::error($exception);
- return $this->error(40023, '', '发货失败,请重新尝试');
- }
- }
- public function newcode($v){
- //大码
- if ($lenth==10){
- $re = FwCode::where('top_code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v);
- $this->error(400,'',$message);
- }
- $child_count=FwCode::where('top_code',$v)->groupBy('user_id')->get();
- if (count($child_count)!=1){
- return $this->error(50026,'','小码已发货不能使用大码发货');
- }
- $child=FwCode::where('top_code',$v)->get();
- FwCode::where('top_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- foreach ($child as $kke=>$vve){
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $vve->id
- ];
- $this->sendlog($data);
- }
- }
- elseif ($lenth==11){//中码发货
- $re = FwCode::where('mid_code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v);
- $this->error(400,'',$message);
- }
- $child_count=FwCode::where('mid_code',$v)->groupBy('user_id')->get();
- if (count($child_count)!=1){
- return $this->error(50026,'','小码已发货不能使用大码发货');
- }
- $child=FwCode::where('mid_code',$v)->get();
- FwCode::where('mid_code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- foreach ($child as $kke=>$vve){
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $vve->id
- ];
- $this->sendlog($data);
- }
- }
- elseif ($lenth==12){ //小码发货
- $re = FwCode::where('code', $v)->first();
- if (!$re){
- $message=$this->message($k,$v);
- $this->error(400,'',$message);
- }
- FwCode::where('code',$v)->update(['user_id'=>$user->id,'goods_id'=>$ks]);
- $data = [
- 'op_name' => $name,
- 'op_phone' => $users->mobile,
- 'op_id' => 0,
- 'good_name'=>$good->good_name,
- 'accept_name' => $user->nickname,
- 'accept_phone' => $user->mobile,
- 'accept_id' => $user->id,
- 'type' => 1,
- 'select_id' => $re->id
- ];
- $this->sendlog($data);
- }
- }
- public function oldcode(){
- }
- }
|