all(); Log::info($input); $rules = [ 'sign' => 'required', 'string' => 'required', ]; $messages = [ 'sign.required' => 'sign不能为空.', 'string.required' => 'info不能为空.', ]; $validator = Validator::make($input, $rules, $messages); if ($validator->fails()) { return response()->json(['status' => 0, 'message' => '参数不对哦']); } if ($input['sign'] != 'AD253SghasdklasSdafAGAdsa541') { return response()->json(['status' => 0, 'message' => '标识不对哦']); } $info = $input['string']; $result = mb_strpos($info, 'http'); if ($result === false) { Log::error('string不对啊--'.$info); return response()->json(['status' => 0, 'message' => 'string不对啊']); } // $result = mb_strpos($info, 'http'); $result1 = mb_strripos($info, 'CL'); if ($result1 === false) { Log::error('缺少CL哦--'.$info); return response()->json(['status' => 0, 'message' => '缺少CL哦']); } // $url = mb_substr($info, $result, $result1 - $result); // $sts = trim($url); // $num = mb_strpos($sts, 'auth'); // $code = mb_substr($sts, $num + 5); $code=$this->extractData($info); if (!$code){ Log::error($info.'=====缺少code'); return response()->json(['status' => 0, 'message' => '缺少code哦']); // return response()->json(['status' => 0, 'message' => '缺少code哦']); } $express = mb_substr($info, 2, $result - 3); $express_info = Express::where('express_number', $express)->first(); Log::info('进行到了这里1'); if ($express_info) { $status = mb_strpos($express_info->note, '精'); if ($status !== false) { $good_id = 1; } else { $status = mb_strpos($express_info->note, '高'); if ($status !== false) { $good_id = 3; } else { $status = mb_strpos($express_info->note, '青'); if ($status !== false) { $good_id = 9; } else { $status = mb_strpos($express_info->note, '红'); if ($status !== false) { $good_id = 1; } else { $status = mb_strpos($express_info->note, '袜子'); if ($status !== false) { $good_id = 14; } else { Log::error('找不到款式哦--'.$info); return response()->json(['status' => 0, 'message' => '找不到款式哦']); } } } } } $orders=OrderTest::where('id',$express_info->order_id)->first(); $user = User::where('id', $express_info->user_id)->first(); if ($orders){ $user=User::where('id',$orders->good_user_id)->first(); } $good = GoodSelect::find($good_id); Log::info($code); if (mb_strlen($code)>18){ $re = Select::where('code', $code)->first(); if ($re) { if ($re->level!=1){ Log::error('防伪码不对啊--'.$info); return response()->json(['status' => 0, 'message' => '防伪码不对啊']); } /***大码发货,并记录日志情况*/ $re->user_id = $request->id; $re->com_binding = 0; $re->is_true = 0; $re->good_select_id = $good_id; if (!$re->save()) { return response()->json(['status' => 0, 'message' => '']); } $data = [ 'op_name' => '流水线', 'op_phone' => '流水线', '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 = $user->id; $res->com_binding = 0; $res->is_true = 0; $res->good_select_id = $good_id; if (!$res->save()) { throw new \Exception(1); } $data = [ 'op_name' => '流水线', 'op_phone' => '流水线', '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 = $user->id; $resss->com_binding = 0; $resss->is_true = 0; $resss->good_select_id = $good_id; if (!$resss->save()) { return response()->json(['status' => 0, 'message' => '']); } $data = [ 'op_name' => '流水线', 'op_phone' => '流水线', '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)); } } } return response()->json(['status' => 1, 'message' => '成功了啊']); } }else{ if (mb_strlen($code)==10){ $re = FwCode::where('top_code', $code)->first(); if (!$re){ return response()->json(['status' => 0, 'message' => '防伪码找不到哦','data'=>[]]); } $child_count=FwCode::where('top_code',$code)->groupBy('user_id')->get(); if (count($child_count)!=1){ return response()->json(['status' => 0, 'message' => '小码已发货不能使用大码发货','data'=>[]]); } $child=FwCode::where('top_code',$code)->get(); FwCode::where('top_code',$code)->update(['user_id'=>$user->id,'goods_id'=>$good_id]); foreach ($child as $kke=>$vve){ $data = [ 'op_name' => '流水线', 'op_phone' => '', '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); } return response()->json(['status' => 1, 'message' => '成功了啊']); } return response()->json(['status' => 0, 'message' => '防伪码用的是小码','data'=>[]]); } Log::error('防伪码找不到哦--'.$info); return response()->json(['status' => 0, 'message' => '防伪码找不到哦','data'=>$re]); } else { Log::error('快递单找不到--'.$info); return response()->json(['status' => 0, 'message' => '快递单找不到']); } } public function extractData($str) { try { // 根据不同的URL模式进行分割和提取 if (strpos($str, 'fw.jiuweiyun.cn') !== false) { // 处理第一个URL模式 $pattern = '/f=([a-zA-Z0-9]+) /'; preg_match($pattern, $str, $matches); return $matches[1]; } elseif (strpos($str, 'fangw.jiuweiyun.cn') !== false) { // 处理第二个URL模式 $pattern = '/auth\/([^ ]+) CL/'; preg_match($pattern, $str, $matches); return $matches[1]; } return null; }catch (\Exception $exception){ return null; } } 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 getinfos(Request $request) { Log::info('请求了'); $input = $request->all(); Log::info($input); $rules = [ 'sign' => 'required', 'string' => 'required', ]; $messages = [ 'sign.required' => 'sign不能为空.', 'string.required' => 'info不能为空.', ]; $validator = Validator::make($input, $rules, $messages); if ($validator->fails()) { return response()->json(['status' => 0, 'message' => '参数不对哦']); } if ($input['sign'] != 'AD253SghasdklasSdafAGAdsa541') { return response()->json(['status' => 0, 'message' => '标识不对哦']); } $info = $input['string']; $result = mb_strpos($info, 'http'); if ($result === false) { Log::error('string不对啊--'.$info); return response()->json(['status' => 0, 'message' => 'string不对啊']); } // $result = mb_strpos($info, 'http'); $result1 = mb_strripos($info, 'CL'); if ($result1 === false) { Log::error('缺少CL哦--'.$info); return response()->json(['status' => 0, 'message' => '缺少CL哦']); } $url = mb_substr($info, $result, $result1 - $result); $sts = trim($url); $num = mb_strpos($sts, 'auth'); $code = mb_substr($sts, $num + 5); $express = mb_substr($info, 2, $result - 3); $express_info = Express::where('express_number', $express)->first(); Log::info('进行到了这里1'); if ($express_info) { $status = mb_strpos($express_info->note, '精'); if ($status !== false) { $good_id = 1; } else { $status = mb_strpos($express_info->note, '高'); if ($status !== false) { $good_id = 3; } else { $status = mb_strpos($express_info->note, '青'); if ($status !== false) { $good_id = 9; } else { $status = mb_strpos($express_info->note, '红'); if ($status !== false) { $good_id = 1; } else { Log::error('找不到款式哦--'.$info); return response()->json(['status' => 0, 'message' => '找不到款式哦']); } } } } $orders=OrderTest::where('id',$express_info->order_id)->first(); $user = User::where('id', $express_info->user_id)->first(); if ($orders){ $user=User::where('id',$orders->good_user_id)->first(); } $good = GoodSelect::find($good_id); Log::info($code); $re = Select::where('code', $code)->first(); if ($re) { if ($re->level!=1){ Log::error('防伪码不对啊--'.$info); return response()->json(['status' => 0, 'message' => '防伪码不对啊']); } /***大码发货,并记录日志情况*/ $re->user_id = $request->id; $re->com_binding = 0; $re->is_true = 0; $re->good_select_id = $good_id; if (!$re->save()) { return response()->json(['status' => 0, 'message' => '']); } $data = [ 'op_name' => '流水线', 'op_phone' => '流水线', '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 = $user->id; $res->com_binding = 0; $res->is_true = 0; $res->good_select_id = $good_id; if (!$res->save()) { throw new \Exception(1); } $data = [ 'op_name' => '流水线', 'op_phone' => '流水线', '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 = $user->id; $resss->com_binding = 0; $resss->is_true = 0; $resss->good_select_id = $good_id; if (!$resss->save()) { return response()->json(['status' => 0, 'message' => '']); } $data = [ 'op_name' => '流水线', 'op_phone' => '流水线', '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)); } } } return response()->json(['status' => 1, 'message' => '成功了啊']); } Log::error('防伪码找不到哦--'.$info); return response()->json(['status' => 0, 'message' => '防伪码找不到哦','data'=>$re]); } else { Log::error('快递单找不到--'.$info); return response()->json(['status' => 0, 'message' => '快递单找不到']); } } }