123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- namespace App\Http\Controllers;
- use App\Handlers\ImageUploadHandler;
- use App\Models\FwCode;
- use App\Models\GoodSelect;
- 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\Log;
- use Zxing\QrReader;
- class SelectController extends Controller
- {
- public function code(\Illuminate\Support\Facades\Request $request){
- return response()->view('fangwei');
- }
- public function wazi(Request $request){
- $code=$request->input('f');
- $lenth=mb_strlen($code);
- //大码
- if ($lenth==10){
- $re = FwCode::where('top_code', $code)->first();
- }elseif ($lenth==11){
- $re = FwCode::where('mid_code', $code)->first();
- }else{
- $re = FwCode::where('code', $code)->first();
- }
- if ($re){
- if ($re->goods_id!=14){
- return response()->view('fangweineiku');
- }
- }
- return response()->view('fangweiwazi');
- }
- /**查询二维码中是谁的信息**/
- public function select_user(Request $request){
- if($request->has('type')){
- $lenth=mb_strlen($request->input('code'));
- if ($lenth!=12){
- if ($lenth==10){
- $dw=FwCode::where('top_code',$request->input('code'))->first();
- }elseif($lenth==11){
- $dw=FwCode::where('mid_code',$request->input('code'))->first();
- }else{
- return $this->error(300,'','查不到此二维码信息');
- }
- if (!$dw){
- return $this->error(300,'','查不到此二维码信息');
- }
- $status=1;
- if ($dw->user_id){
- $status=0;
- }
- return $this->error(700,['com_binding'=>$status],'请使用小码进行查询');
- }
- $dw=FwCode::where('code',$request->input('code'))
- ->with(['select_good_log'=>function($q){
- $q->where('op_id',0)->OrderByDesc('created_at')->limit(1);
- }])
- ->first();
- if (!$dw){
- return $this->error(300,'','此货物是假货,请联系官方电话进行举报');
- }
- if (!$dw->user_id){
- return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
- }
- $user=User::select('nickname','mobile','id','level','area_code','cre_num')->find($dw->user_id);
- if (!$user){
- $nickname='未知用户';
- $level=2;
- }else{
- $nickname=$user->nickname;
- $level=$user->level;
- }
- $price='';
- $goodname='';
- if ($request->input('type')){
- $goods=GoodSelect::where('id',$dw->goods_id)->first();
- $price=$goods->price;
- $goodname=$goods->good_name;
- }
- $data=[
- 'style'=>$goodname,
- 'price'=>$price,
- 'hidePrice'=>'',
- // 'info'=>$re->select_good_log,
- 'nickname'=>$nickname,
- // 'nicknames'=>$re->select_good_log->accept_name,
- 'level'=>$this->judge_level($level),
- 'phone'=>'不显示',
- 'time'=>$dw->select_good_log->created_at->toDateTimeString(),
- 'url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png'
- ];
- return $this->success($data);
- }
- $re=Select::where('code',$request->code)->with(['select_good','select_good_log'=>function($q){
- $q->where('type',0)->OrderByDesc('created_at')->limit(1);
- }])->first();
- if ($re){
- if ($re->is_true==1){
- return $this->error(300,'','此货物是假货,请联系官方电话进行举报');
- }
- if ($re->is_lowest!=1){
- return $this->error(700,['com_binding'=>$re->com_binding],'请使用小码进行查询');
- }
- if ($re->com_binding==1){
- return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
- }
- if (!$re->user_id){
- return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
- }
- $re->select_num+=1;
- $re->save();
- $user=User::select('nickname','mobile','id','level','area_code','cre_num')->find($re->user_id);
- $nickname='';
- $level=4;
- $mobiles='';
- $hidePrice=0;
- if(!$user){
- // if ($re->select_good_log->op_id!=0){
- // $user=User::where('id',$re->select_good_log->op_id)->first();
- // if (!$user){
- // $mobiles=$re->select_good_log->accept_phone;
- // $nickname=$re->select_good_log->accept_name;
- // $level=4;
- //// return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
- // }
- // }else{
- // $mobiles=$re->select_good_log->accept_phone;
- // $nickname=$re->select_good_log->accept_name;
- // $level=4;
- //// return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
- // }
- }else{
- if ($re->select_good->good_name=='大卫博士健康内裤(精装版)'){
- if ($user->area_code=='+886'){
- $hidePrice=1;
- }
- if (!is_numeric(mb_substr($user->cre_num,0,1))){
- $hidePrice=1;
- }
- }
- if ($re->is_lowest==1){
- $user->is_lowest=true;
- }else{
- $user->is_lowest=false;
- }
- $mobiles=$user->mobile;
- $nickname=$user->nickname;
- $level=$user->level;
- if ($user->id==39516){
- $mobiles='大卫博士公司';
- }
- }
- $data=[
- 'style'=>$re->select_good->good_name,
- 'price'=>$re->select_good->price,
- 'hidePrice'=>$hidePrice,
- // 'info'=>$re->select_good_log,
- 'nickname'=>$nickname,
- // 'nicknames'=>$re->select_good_log->accept_name,
- 'level'=>$this->judge_level($level),
- 'phone'=>'不显示',
- 'time'=>$re->updated_at->toDateTimeString(),
- 'url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png'
- ];
- return $this->success($data);
- }else{
- return $this->error(50021,['url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png'],'暂无该货物信息,请重试');
- }
- }
- public function get_img_url(){
- return $this->success(['url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png']);
- }
- /**真伪查询**/
- public function select_true(Request $request){
- $re=Select::where('security_code',$request->security_code)->where('code',$request->code)->first();
- if ($re){
- if ($re->com_binding==1){
- return $this->error(40021,'','该商品是假货');
- }
- if ($re->is_true==1){
- return $this->error(40021,'','该商品是假货');
- }
- return $this->success([]);
- }else{
- return $this->error(40023,'','暂未查到该商品的真伪信息,请检查防伪码是否输入正确!');
- }
- }
- /**真伪查询**/
- public function select_truewazi(Request $request){
- $re=FwCode::where('num',$request->security_code)->where('code',$request->code)->first();
- if ($re){
- // if ($re->com_binding==1){
- // return $this->error(40021,'','该商品是假货');
- // }
- // if ($re->is_true==1){
- // return $this->error(40021,'','该商品是假货');
- // }
- return $this->success([]);
- }else{
- return $this->error(40023,'','暂未查到该商品的真伪信息,请检查防伪码是否输入正确!');
- }
- }
- /**展示退货商品所属信息**/
- public function select_return_user(Request $request){
- $re=Select::where('code',$request->code)->with(['select_user','select_good'])->first();
- if (empty($re)){
- return $this->error(52121,'','暂无信息查询');
- }
- if (!$re->select_user){
- return $this->error(52121,'','暂无代理信息');
- }
- if (!$re->select_good){
- return $this->error(52121,'','暂无商品信息');
- }
- $res=$this->check_user_level(Auth::user()->id,$re->user_id);
- if ($res['code']!=200){
- return $this->error($res['code'],'',$res['message']);
- }
- $time=SendGoodLog::where('select_id',$re->id)->where('accept_id',$re->user_id)->orderByDesc('created_at')->first();
- $data=[
- 'style'=>$re->select_good->good_name,
- 'nickname'=>$re->select_user->nickname,
- 'level'=>$this->judge_level($re->select_user->level),
- 'phone'=>$re->select_user->mobile,
- 'time'=>$time->created_at->toDateString()
- ];
- return $this->success($data);
- }
- /**检查用户**/
- public function check_user_level($id,$user_id){
- if ($id==$user_id){
- return ['code'=>50026,'message'=>'你不能对自己的货物进行退货操作'];
- }
- return ['code'=>200];
- }
- /**判断等级**/
- public function judge_level($status){
- switch ($status){
- case 2:
- $level='经销商';
- break;
- case 3:
- $level='批发商';
- break;
- default:
- $level='';
- break;
- }
- return $level;
- }
- /**展示发货商品所属信息**/
- public function select_send_user(Request $request){
- Log::error($request->all());
- $user=Auth::user();
- $re=Select::where('code',$request->code)->with(['select_user','select_good'])->first();
- if (empty($re)){
- Log::error(1);
- return $this->error(52119,'','暂无信息查询');
- }
- if (!$re->select_user){
- Log::error(2);
- return $this->error(52120,'','暂无代理信息');
- }
- if (!$re->select_good){
- Log::error(3);
- return $this->error(52121,'','暂无商品信息');
- }
- if ($re->user_id!=$user->id){
- Log::error(4);
- return $this->error(50021,'','当前货物不是您的货物,不能使用此码进行发货');
- }
- $time=SendGoodLog::where('select_id',$re->id)->where('accept_id',$re->user_id)->orderByDesc('created_at')->first();
- if ($time){
- $times=$time->created_at->toDateString();
- }else{
- $times=Carbon::now()->toDateString();
- }
- $data=[
- 'style'=>$re->select_good->good_name,
- 'nickname'=>$re->select_user->nickname,
- 'avatar'=>$re->select_user->headimgurl,
- 'level'=>$this->judge_level($re->select_user->level),
- 'phone'=>$re->select_user->mobile,
- 'time'=>$times
- ];
- return $this->success($data);
- }
- /**查询二维码中是谁的信息**/
- public function CKSelect(Request $request,ImageUploadHandler $imageUploadHandler){
- if ($request->file('image')){
- try {
- $path=$imageUploadHandler->save($request->image,'QrCodeCK','1');
- $qrcode=new QrReader($path['path']);
- $text=$qrcode->text();
- $code=mb_substr($text,35);
- $url=$path['url'];
- unlink(public_path()."$url");
- $re=Select::where('code',$code)->with(['select_good','select_good_log'=>function($q){
- $q->where('type',0)->OrderBy('created_at');
- }])->first();
- if ($re){
- return $this->success($re);
- }else{
- return $this->error(500214,'1','未查出信息,请确保二维码拍摄清晰!');
- }
- }catch (\Exception $exception){
- return $this->error(500214,$exception->getMessage(),'未识别出信息');
- }
- }
- return $this->error(500214,'3','未识别出信息');
- }
- }
|