UserController.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Events\RegisterApplyEvent;
  4. use App\Handlers\ImageUploadHandler;
  5. use App\Http\Controllers\MiniSubController as Mini;
  6. use App\Models\Address;
  7. use App\Models\Order;
  8. use App\Models\Ordertest;
  9. use App\Models\ShareUser;
  10. use App\Models\Store;
  11. use App\Models\System;
  12. use App\Models\TestUserW;
  13. use App\Models\User;
  14. use App\Models\UserCert;
  15. use App\Models\UserZ;
  16. use App\Models\Warea;
  17. use Carbon\Carbon;
  18. use GuzzleHttp\Client;
  19. use Illuminate\Http\Request;
  20. use Illuminate\Support\Facades\Auth;
  21. use Illuminate\Support\Facades\Cache;
  22. use Illuminate\Support\Facades\DB;
  23. use Illuminate\Support\Facades\Log;
  24. use Intervention\Image\Facades\Image as Image;
  25. use Jenssegers\Agent\Facades\Agent;
  26. use Validator;
  27. use Illuminate\Support\Facades\Cookie;
  28. use Symfony\Component\HttpFoundation\Cookie as SCookie;
  29. class UserController extends Controller{
  30. /*获取用户状态*/
  31. public function getinfo(User $user,Request $request){
  32. $users=Auth::user();
  33. Log::error('sssss'.json_encode($request->all()));
  34. $user=User::find($users->id);
  35. if ($user->freeze_status==1){
  36. return $this->error(20014);
  37. }
  38. $user->login_at=Carbon::now();
  39. $user->save();
  40. $recom_num=UserCert::where('recom_id',$user->id)->where('recom_audit',0)->count();
  41. $agent_num=UserCert::where('agent_id',$user->id)->where('agent_audit',0)->count();
  42. $u_ids=User::where('cert_status',3)->where('crown_id',$user->id)->where('service_status',1)->pluck('id');
  43. $company_num= UserCert::whereIn('user_id',$u_ids)->where('agent_audit',1)->count();
  44. // $company_num= UserCert::whereHas('user_info',function($query)use($user){
  45. // $query->where('crown_id',$user->id)->where('service_status',1);
  46. // })->where('agent_audit',1)->count();
  47. // $recom_num=0;
  48. // $agent_num=0;
  49. // $company_num=0;
  50. // $num=0;
  51. $num=Ordertest::whereIn('pay_status',[0,1])->where('user_id',$users->id)->where('is_deleted',0)->sum('no_pay_money');
  52. if ($user->recom_id==null){
  53. $users->recom_nickname='';
  54. $users->recom_mobile='';
  55. }else{
  56. $users->recom_nickname=$user->recom_user->nickname;
  57. $users->recom_mobile=hide_phone($user->recom_user->mobile);
  58. }
  59. if ($users->cert_status==4){
  60. $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('recom_audit_desc');
  61. }elseif ($users->cert_status==5){
  62. $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('agent_audit_desc');
  63. }
  64. if ($user->openid){
  65. $users->openid=$user->openid;
  66. }else{
  67. $users->openid=$user->openid;
  68. }
  69. //测试微聊
  70. if(in_array($users->mobile,['15138929587','15238617326','18838980968','15236877164'])){//,'15286818088','15236877164'
  71. $users->is_weiliao=1;
  72. }else{
  73. $users->is_weiliao=0;
  74. }
  75. //获取账号余额
  76. // $sub_mchid=Store::withTrashed()->where('is_failure',0)->where('is_apply',3)->where('user_id',$users->id)->value('sub_mchid');
  77. //// $sub_mchid=null;
  78. // if($sub_mchid){
  79. // Log::info($sub_mchid);
  80. // $mini=new Mini();
  81. // $result=$mini->getAccount($sub_mchid);
  82. //// Log:info($users);
  83. // $users->pending_amount=$result['pending_amount'];
  84. // $users->available_amount=$result['available_amount'];
  85. // Log::info($user->mobile.'/////'.$user->deleted_at.'///'.$result['pending_amount'].'///'.$result['available_amount']);
  86. // }else{
  87. // $users->pending_amount=0;
  88. // $users->available_amount=0;
  89. // }
  90. $users->uuid = '1002'.substr($user->mobile,5,6);
  91. $users->status=$users->status==0?1:0;
  92. $users->recom_num=$recom_num;
  93. $users->agent_num=$agent_num;
  94. $users->company_num=$company_num;
  95. $users->no_money=$num;
  96. // $users->deleted_at=null;
  97. // Log::error($users->id);
  98. return $this->success($users);
  99. }
  100. //app首页获取信息专用接口
  101. public function getAppAgentInfo(){
  102. $users=Auth::user();
  103. $user=User::find($users->id);
  104. if ($user->freeze_status==1){
  105. return $this->error('450001','账号已冻结');
  106. }
  107. $user->login_at=Carbon::now();
  108. $user->save();
  109. // $users->headimgurl=$user->headimgurl;
  110. $recom_num=UserCert::where('recom_id',$user->id)->where('recom_audit',0)->count();
  111. $agent_num=UserCert::where('agent_id',$user->id)->where('recom_audit',1)->where('agent_audit',0)->count();
  112. $num=Ordertest::whereIn('pay_status',[0,1])->where('user_id',$users->id)->where('is_deleted',0)->sum('no_pay_money');
  113. if ($user->recom_id==null){
  114. $users->recom_nickname='';
  115. $users->recom_headimgurl='';
  116. $users->recom_mobile='';
  117. }else{
  118. $users->recom_headimgurl=$user->recom_user->headimgurl;
  119. $users->recom_nickname=$user->recom_user->nickname;
  120. $users->recom_mobile=$user->recom_user->mobile;
  121. }
  122. if ($user->agent_id==null){
  123. $users->agent_nickname='';
  124. $users->agent_mobile='';
  125. $users->agent_headimgurl='';
  126. }else{
  127. $users->agent_headimgurl=$user->agent_user->headimgurl;
  128. $users->agent_nickname=$user->agent_user->nickname;
  129. $users->agent_mobile=$user->agent_user->mobile;
  130. }
  131. if ($users->cert_status==4){
  132. $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('recom_audit_desc');
  133. }elseif ($users->cert_status==5){
  134. $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('agent_audit_desc');
  135. }
  136. if ($user->openid){
  137. $users->openid=$user->openid;
  138. }else{
  139. $users->openid=$user->openid;
  140. }
  141. //测试微聊
  142. if(in_array($users->mobile,['15138929587','15238617326','18838980968','15236877164'])){//,'15286818088','15236877164'
  143. $users->is_weiliao=1;
  144. }else{
  145. $users->is_weiliao=0;
  146. }
  147. //获取账号余额
  148. $sub_mchid=Store::withTrashed()->where('is_failure',0)->where('user_id',$users->id)->value('sub_mchid');
  149. if($sub_mchid){
  150. Log::info($sub_mchid);
  151. $mini=new Mini();
  152. $result=$mini->getAccount($sub_mchid);
  153. $users->pending_amount=$result['pending_amount'];
  154. $users->available_amount=$result['available_amount'];
  155. Log::info($user->mobile.'/////'.$user->deleted_at.'///'.$result['pending_amount'].'///'.$result['available_amount']);
  156. }else{
  157. $users->pending_amount=0;
  158. $users->available_amount=0;
  159. }
  160. $users->status=$users->status==0?1:0;
  161. $users->recom_num=$recom_num;
  162. $users->agent_num=$agent_num;
  163. $users->no_money=$num;
  164. $users->level= judge_level($user->level);
  165. $users->agent_level= $user->level;
  166. $users->store = $user->store==null?false:true;
  167. $users->order_num1=Order::where('agent_id',$user->id)->where('status','=',0)->count();//待审核订单数量
  168. $users->order_num2= Order::where('agent_id',$user->id)->where('status','=',2)->count();// 待收货订单数量
  169. $users->order_num3=Order::where('agent_id',$user->id)->whereIn('status',[3,4,5])->count();//已完成订单数量
  170. $users->openid=$user->openid;
  171. $users->warea=Warea::where('id',$user->warea_id)->value('name');
  172. $users->warea_info=Warea::where('id',$user->warea_id)->select('avatar','qrcode','admin_name')->first();
  173. if ($user->password==md5($user->mobile)){
  174. $users->pass_status=true;
  175. }else{
  176. $users->pass_status=false;
  177. }
  178. if($user->status==0 && $user->cert_status==6 && $user->service_status==0 && empty($user->deleted_at)){
  179. $users->show_store=true;
  180. }else{
  181. $users->show_store=false;
  182. }
  183. return $this->success($users);
  184. }
  185. /**获取openid**/
  186. public function get_openid(Request $request){
  187. // $wechat=app('wechat.')
  188. }
  189. /*实名认证的提交*/
  190. public function submit_user(Request $request,UserCert $userCert){
  191. if(empty($request->cre_num)){
  192. return $this->new_error(300,'身份证为必填项');
  193. };
  194. // if(strlen($request->cre_num) != 18){
  195. // return $this->new_error(300,'身份证号码有误');
  196. // };
  197. if(strlen($request->cre_num) == 18){
  198. $year = substr($request->cre_num, 6, 4);
  199. $age = date('Y') - $year;
  200. if($age > 60){
  201. return $this->new_error(300,'很抱歉,您的年龄已超过60岁,无法注册。');
  202. }
  203. }
  204. // $year = substr($request->cre_num, 6, 4);
  205. // $age = date('Y') - $year;
  206. // if($age > 65){
  207. // return $this->new_error(300,'很抱歉,您的年龄已超过65岁,无法注册。');
  208. // }
  209. $data=User::where('cre_num',$request->cre_num)->where('id','!=',Auth::user()->id)->first();
  210. if ($data){
  211. if ($data->deleted_at!=null){
  212. return $this->new_error(300,'当前身份证号已被禁用');
  213. }
  214. return $this->new_error(300,'当前身份证号已被使用');
  215. }
  216. $is_five_type=1;
  217. $user=User::find(Auth::user()->id);
  218. if(empty($user->nickname)){
  219. $user->nickname=$request->wechatname;
  220. $user->name=$request->wechatname;
  221. }
  222. $user->realname=$request->realname;
  223. $user->cre_num=$request->cre_num;
  224. // $user->password=md5($request);
  225. $share=ShareUser::where('phone',$user->mobile)->first();
  226. $recom=User::find($user->recom_id);
  227. if ($recom->level==2){
  228. if ($share){
  229. $share->status=1;
  230. }
  231. $user->agent_id=$recom->agent_id;
  232. $user->crown_id=$recom->agent_id;
  233. $userCert->recom_audit=1;
  234. $userCert->agent_id=$recom->agent_id;
  235. $userCert->recom_updated_at=Carbon::now()->toDateTimeString();
  236. $user->cert_status=2;
  237. }elseif ($recom->level==3){
  238. if ($share){
  239. $share->status=2;
  240. }
  241. $userCert->recom_audit=1;
  242. $userCert->recom_updated_at=Carbon::now()->toDateTimeString();
  243. $userCert->agent_id=$recom->id;
  244. $userCert->agent_updated_at=Carbon::now()->toDateTimeString();
  245. $userCert->agent_audit=1;
  246. $userCert->company_audit=1;
  247. $userCert->company_updated_at=Carbon::now()->toDateTimeString();
  248. $user->cert_status=3;
  249. $user->agent_id=$recom->id;
  250. $user->crown_id=$recom->id;
  251. $user->service_status=0;
  252. }
  253. $user->warea_id=$recom->warea_id;
  254. if ($share){
  255. $share->save();
  256. }
  257. $userCert->recom_id=$user->recom_id;
  258. $userCert->user_id=$user->id;
  259. $userCert->is_five_type=$is_five_type;
  260. $userCert->save();
  261. $user->save();
  262. if ($recom->level==2){
  263. $recom=User::where('id',$user->agent_id)->first();
  264. if($recom->openid){
  265. $mes['openid']=$recom->openid;
  266. $mes['data']=[
  267. 'first' => '注册信息已提交,请您及时审核',
  268. 'keyword1' => $user->nickname,
  269. 'keyword2' => $user->mobile,
  270. 'keyword3' => date("Y-m-d H:i"),
  271. 'remark' => '点击链接进入系统,查看详情',
  272. ];
  273. event(new RegisterApplyEvent($mes));
  274. }
  275. }
  276. return $this->success([]);
  277. }
  278. /*
  279. * 获取用户信息
  280. */
  281. public function per_data(Request $request){
  282. $users=Auth::user();
  283. $user=User::find($users->id);
  284. if(empty($user)){
  285. return $this->error('300',[],'代理信息不存在');
  286. }
  287. // $users->up_nickname=$user->agent_user->wechatname;
  288. // $users->recom_nickname=$user->recom_user->wechatname;
  289. // $users->level=judge_level($users->level);
  290. $re["id"]=$user->id;
  291. $re['uuid']= '1002'.substr($user->mobile,5,6);
  292. $re["nickname"]= $user->nickname;
  293. $re["avatar"]= $user->headimgurl;
  294. $re["money"]= $user->money;
  295. $re["level"]= judge_level($users->level);
  296. $re["agent_level"]= $users->level;
  297. $re["mobile"]= $user->mobile;
  298. $re["level_change"]= $user->level_change;
  299. $re["store"]= $user->store==null?false:true;
  300. $re["order_num1"]=Order::where('agent_id',$user->id)->where('status','=',0)->count();//待审核订单数量
  301. $re["order_num2"]= Order::where('agent_id',$user->id)->where('status','=',2)->count();// 待收货订单数量
  302. $re["order_num3"]=Order::where('agent_id',$user->id)->whereIn('status',[3,4,5])->count();//已完成订单数量
  303. $re['openid']=$user->openid;
  304. $re['warea']=Warea::where('id',$user->warea_id)->value('name');
  305. $re['warea_info']=Warea::where('id',$user->warea_id)->select('avatar','qrcode','admin_name')->first();
  306. // if ($user->password==md5($user->mobile)){
  307. // $re['pass_status']=true;
  308. // }else{
  309. // $re['pass_status']=false;
  310. // }
  311. $re['pass_status']=false;
  312. $user->level_change=0;
  313. $user->save();
  314. //测试人员
  315. // $test_user=TestUserW::pluck('phone')->toArray();
  316. // if(in_array($user->mobile,$test_user)){
  317. // $re['show_store']=true;
  318. // }else{
  319. // $re['show_store']=false;
  320. // }
  321. //正式开放
  322. if($user->status==0 && $user->cert_status==6 && $user->service_status==0 && empty($user->deleted_at)){
  323. $re['show_store']=true;
  324. }else{
  325. $re['show_store']=false;
  326. }
  327. return $this->success($re);
  328. }
  329. /*更改手机号*/
  330. public function change_num(Request $request){
  331. try {
  332. $login=new LoginController();
  333. // $code = $login->judge_code('verificationCode_' . MD5($request->mobile), $request->verify_code);
  334. // Cache::forget('verificationCode_' . MD5($request->mobile));
  335. $code = $login->judge_code('verificationCode_' . MD5($request->code.'-'.$request->mobile), $request->verify_code);
  336. Cache::forget('verificationCode_' . MD5($request->code.'-'.$request->mobile));
  337. if ($code==300||$code==400){
  338. return $this->new_error(300,'验证码不正确或过期');
  339. }
  340. $user=User::find(Auth::user()->id);
  341. $mobile=$user->mobile;
  342. $user->mobile=$request->mobile;
  343. $user->area_code=$request->code;
  344. $user->save();
  345. try{
  346. $u=UserZ::where('phone',$mobile)->first();
  347. if ($u){
  348. $u->phone=$request->mobile;
  349. $u->save();
  350. }
  351. }catch (\Exception $exception){
  352. Log::error('这是手机号更改的地方出错了'.$exception);
  353. }
  354. return $this->success([]);
  355. }catch (\Exception $exception){
  356. Log::error('-----更改手机号出错------');
  357. return $this->new_error(300,'更改出错,请联系客服');
  358. }
  359. }
  360. /*换绑手机号之发送*/
  361. public function send_code(Request $request){
  362. try {
  363. $mobile=Auth::user()->mobile;
  364. if ($request->mobile==$mobile){
  365. Log::error('fsdf');
  366. return $this->new_error(300,'该手机号和原手机号一致');
  367. }
  368. $count=User::where('mobile',$request->mobile)->where('id','<>',Auth::user()->id)->count();
  369. if ($count>0){
  370. return $this->new_error(300,'该手机号已被使用');
  371. }
  372. $login=new LoginController();
  373. $code=$login->send_code($request->mobile,0,$request->code);
  374. if ($code['code']==300){
  375. return $this->error(300,[],$code['message']);
  376. }
  377. return $this->success([]);
  378. }catch (\Exception $exception){
  379. Log::error('____更改手机号之发送验证码出错_____');
  380. return $this->new_error(300,'更改出错,请联系客服');
  381. }
  382. }
  383. /*地址管理---展示地址*/
  384. public function show_address(){
  385. $id=Auth::user()->id;
  386. $address=Address::where('user_id',$id)->where('is_deleted',0)->with(['get_user'])->orderByDesc('type')->orderbyDesc('updated_at')->orderbyDesc('id')->get();
  387. $data=[];
  388. foreach ($address as $k=>$v){
  389. $data[$k]["id"]=$v->id;
  390. $data[$k]["type"]=$v->type;
  391. $data[$k]["con_name"]=$v->username;
  392. $data[$k]["area_code"]=$v->area_code;
  393. $data[$k]["con_mobile"]=$v->mobile;
  394. $data[$k]["provice"]=$v->province;
  395. $data[$k]["city"]=$v->city;
  396. $data[$k]["area"]=$v->town;
  397. $data[$k]["address"]=$v->address;
  398. $data[$k]["belong_id"]=$v->belong_id==null?'':$v->belong_id;
  399. $data[$k]['belong_user']='';
  400. if ($v->belong_id){
  401. $user=User::where('id',$v->belong_id)->select('id as belong_id','level as belong_level','nickname as belong_nickname','mobile as belong_mobile','headimgurl as avatar')->first();
  402. $data[$k]['belong_user']=$user;
  403. }
  404. if ($v->get_user){
  405. $data[$k]["level"]=$v->get_user->level;
  406. $data[$k]["nickname"]=$v->get_user->nickname;
  407. $data[$k]["phone"]=$v->get_user->mobile;
  408. }else{
  409. $data[$k]["level"]=null;
  410. $data[$k]["nickname"]=null;
  411. $data[$k]["phone"]=null;
  412. }
  413. }
  414. // Log::error(json_encode($data));
  415. return $this->success_list($data);
  416. }
  417. /*地址管理-----新增地址*/
  418. public function add_address(Request $request,Address $address){
  419. // Log::error('{----地址----}'.json_encode($request->all()));
  420. $id=Auth::user()->id;
  421. // $data=$request->all();
  422. $add=Address::where('mobile',$request->con_mobile)->where('user_id',$id)->where('is_deleted',0)->where('username',$request->con_name)->where('address',$request->address)->first();
  423. if ($add){
  424. return $this->error(40023,'','当前地址已存在,请搜索手机号'.$request->con_mobile.'查找该地址');
  425. }
  426. if ($request->type==1){
  427. $count=Address::where('user_id',$id)->where('is_deleted',0)->where('type',1)->count();
  428. if ($count>=3){
  429. $num=$count-2;
  430. Address::where('user_id',$id)->where('is_deleted',0)->where('type',1)->orderBy('created_at')->limit($num)->update(['type'=>0]);
  431. }
  432. }
  433. $user=User::where('mobile',$request->con_mobile)->first();
  434. if ($user){
  435. // if ($user->id!=$id && $user->level==3){
  436. // return $this->error(40023,'','当前手机号对应的代理-不属于自己的团队');
  437. // }
  438. // $ids=User::where('agent_id',$id)->pluck('id')->toArray();
  439. // $idss=User::whereIn('agent_id',$ids)->pluck('id')->toArray();
  440. // $i=[$id];
  441. // $ar=array_merge($ids,$i);
  442. // $ar=array_merge($ar,$idss);
  443. // if (in_array($user->id,$ar)){
  444. // $address->belong_id=$user->id;
  445. // }else{
  446. // return $this->error(40023,$ar,'当前手机号对应的代理不属于自己的团队');
  447. // }
  448. $address->belong_id=$user->id;
  449. }
  450. // if (!$request->province){
  451. // return $this->error(50021,'','选择这省市区');
  452. // }
  453. $address->type=$request->type;
  454. $address->user_id=$id;
  455. $address->username=$request->con_name;
  456. $address->area_code=$request->input('areaCode','+86');
  457. $address->mobile=$request->con_mobile;
  458. $address->province=$request->provice;
  459. $address->city=$request->city;
  460. $address->town=$request->area;
  461. $address->address=$request->address;
  462. $re=User::where('mobile',$request->con_mobile)->select('level','nickname')->first();
  463. if ($re){
  464. $address->level=$re->level;
  465. $address->nickname=$re->nickname;
  466. }
  467. $address->save();
  468. return $this->success(['id'=>$address->id]);
  469. }
  470. /*地址管理----删除地址*/
  471. public function del_address(Request $request){
  472. $address=Address::find($request->id);
  473. $address->is_deleted=1;
  474. $address->save();
  475. return $this->success([]);
  476. }
  477. /*地址管理----编辑地址*/
  478. public function update_address(Request $request){
  479. $address=Address::find($request->id);
  480. if ($address->con_name==$request->con_name&& $address->mobile==$request->con_mobile&& $address->province==$request->provice&&$address->city==$request->city&&$address->town==$request->area&&$address->address==$request->address){
  481. return $this->error(50024,'','当前修改的地址已存在,请搜索手机号'.$request->con_mobile.'查找该地址');
  482. }
  483. if ($request->type==1){
  484. $count=Address::where('user_id',$request->id)->where('is_deleted',0)->where('type',1)->count();
  485. if ($count>=3){
  486. $num=$count-2;
  487. Address::where('user_id',$request->id)->where('is_deleted',0)->where('type',1)->orderBy('created_at')->limit($num)->update(['type'=>0]);
  488. }
  489. }
  490. $user=User::where('mobile',$request->con_mobile)->first();
  491. if ($user){
  492. // if ($user->id!=$address->user_id && $user->level==3){
  493. // return $this->error(40023,'','当前手机号对应的代理不属于自己的团队');
  494. // }
  495. // $ids=User::where('agent_id',$address->user_id)->pluck('id')->toArray();
  496. // $idss=User::whereIn('agent_id',$ids)->pluck('id')->toArray();
  497. // $ar=array_merge($ids,$address->user_id,$idss);
  498. // if (in_array($ar,$user->id)){
  499. // $address->belong_id=$user->id;
  500. // }else{
  501. // return $this->error(40023,'','当前手机号对应的代理不属于自己的团队');
  502. // }
  503. $address->belong_id=$user->id;
  504. }
  505. // if (!$request->province){
  506. // return $this->error(50021,'','选择这省市区');
  507. // }
  508. $address->type=$request->type;
  509. $address->username=$request->con_name;
  510. $address->area_code=$request->input('areaCode','+86');
  511. $address->mobile=$request->con_mobile;
  512. $address->province=$request->provice;
  513. $address->city=$request->city;
  514. $address->town=$request->area;
  515. $address->address=$request->address;
  516. $re=User::where('mobile',$request->con_mobile)->select('level','nickname')->first();
  517. if ($re){
  518. $address->level=$re->level;
  519. $address->nickname=$re->nickname;
  520. }
  521. $address->save();
  522. return $this->success([]);
  523. }
  524. /*搜索地址**/
  525. public function search_address(Request $request){
  526. $where=[];
  527. if ($request->search_name){
  528. $search_name=$request->search_name;
  529. $where=function ($q)use ($search_name){
  530. $q->where('username','like',"%$search_name%")
  531. ->orwhere('mobile','like',"%$search_name%");
  532. };
  533. }
  534. $re=Address::where('user_id',Auth::user()->id)->where($where)->with(['get_user'])->where('is_deleted',0)->orderByDesc('created_at')->get();
  535. foreach ($re as $k=>$v){
  536. if ($v->belong_id){
  537. $user=User::where('id',$v->belong_id)->select('id as belong_id','level as belong_level','nickname as belong_nickname','mobile as belong_mobile','headimgurl as avatar')->first();
  538. $re[$k]['belong_user']=$user;
  539. }
  540. if($v->get_user){
  541. $re[$k]['nickname']=$v->get_user->nickname;
  542. $re[$k]['level']=$v->get_user->level;
  543. }else{
  544. $re[$k]['nickname']=null;
  545. $re[$k]['level']=null;
  546. }
  547. unset($re[$k]['get_user']);
  548. }
  549. return $this->success_list($re);
  550. }
  551. /**--确认等级变动--**/
  552. public function confirm_level(){
  553. $id=Auth::user()->id;
  554. $user=User::find($id);
  555. $user->level_change=0;
  556. $user->save();
  557. return $this->success([]);
  558. }
  559. public function ress(Request $request){
  560. $add=Address::find($request->id);
  561. echo $add->user->realname;
  562. // return $add;
  563. }
  564. /*--授权书---*/
  565. public function auth_code(Request $request){
  566. // $users=Auth::user();
  567. // $user=User::find($users->id);
  568. // Log::error(json_encode($request->all()));
  569. $user=User::find($request->id);
  570. if ($user->cert_status==3||$user->cert_status==6){
  571. if ($user->auth_startime &&$user->auth_code){
  572. if ($user->auth_img==null){
  573. $name=$user->realname==null?$user->nickname:$user->realname;
  574. $url=$this->auth_create($name,$user->mobile,judge_level($user->level),$user->auth_code,$user->auth_startime,$user->auth_endtime,$user->id);
  575. $user->auth_img=$url;
  576. $user->save();
  577. }
  578. $data['status']=0;
  579. }else{
  580. $data['status']=1;
  581. }
  582. }else{
  583. $data['status']=1;
  584. }
  585. if ($user->service_status==1){
  586. // return $this->error(50021,'','该代理尚未通过政委审核');
  587. return $this->error(50021,'','该代理尚未通过经销商审核');
  588. }
  589. if ($user->service_status==2){
  590. // return $this->error(50021,'','该代理的申请已被政委驳回');
  591. return $this->error(50021,'','该代理的申请已被经销商驳回');
  592. }
  593. if ($user->in_group!=1){
  594. return $this->error(50021,'','该代理尚未通过政委审核');
  595. }
  596. $data['auth_startime']=strtotime($user->auth_startime)*1000;
  597. $data['auth_endtime']=strtotime($user->auth_endtime)*1000;
  598. $data['code']=$user->auth_code;
  599. $data['phone']=$user->mobile;
  600. $data['level_name']=judge_level($user->level);
  601. $data['nickname']=$user->nickname;
  602. $data['realname']=$user->realname==null?$user->nickname:$user->realname;
  603. $data['url']=$user->auth_img==null?'':$user->auth_img;
  604. // Log::error('{----------}'.json_encode($data));
  605. return $this->success($data);
  606. }
  607. public function auth_create($name,$phone,$level_name,$auth_code,$time_start,$time_end,$num){
  608. $client=new Client();
  609. $url='http://api.app.cliu.cc/138.jpg';
  610. $avatarResponse = $client->get($url);
  611. $img = Image::make($avatarResponse->getBody()->getContents());
  612. $img->text($name, 400, 565,function ($font){
  613. $font->file(base_path().'/public/fangzheng.ttf');
  614. $font->size(25);
  615. $font->angle(0);
  616. });
  617. $phones=mb_substr($phone,0,3).'****'.mb_substr($phone,7,4);
  618. $img->text($phones, 400, 635,function ($font){
  619. $font->file(base_path().'/public/fangzheng.ttf');
  620. $font->size(25);
  621. $font->angle(0);
  622. });
  623. $img->text($level_name, 350, 820,function ($font){
  624. $font->file(base_path().'/public/fangzheng.ttf');
  625. $font->size(60);
  626. $font->angle(0);
  627. });
  628. $img->text($auth_code, 285, 965,function ($font){
  629. $font->file(base_path().'/public/fangzheng.ttf');
  630. $font->size(25);
  631. $font->angle(0);
  632. });
  633. $year=mb_substr($time_start,0,4);
  634. $month=mb_substr($time_start,5,2);
  635. $day=mb_substr($time_start,8,2);
  636. $year_t=mb_substr($time_end,0,4);
  637. $month_t=mb_substr($time_end,5,2);
  638. $day_t=mb_substr($time_end,8,2);
  639. $img->text("{$year}年{$month}月{$day}日 - {$year_t}年{$month_t}月{$day_t}日", 285, 1050,function ($font){
  640. $font->file(base_path().'/public/fangzheng.ttf');
  641. $font->size(25);
  642. $font->angle(0);
  643. });
  644. $name=$this->rand_code($num);
  645. $img->save(base_path().'/public/public/uploads/auth_img/'.$name.'.jpg');
  646. return env('APP_URL').'/public/uploads/auth_img/'.$name.'.jpg';
  647. }
  648. //0未认证 1待审核 2通过邀请人审核 3通过上级审核 4邀请人驳回 5上级驳回 6正常
  649. public function authInfo(){
  650. $user_id=Auth::user()->id;
  651. $user=User::where('id',$user_id)
  652. ->with(['recom_user:id,nickname,mobile,level,headimgurl,warea_id','crown_info:id,nickname,mobile,level,headimgurl'])
  653. ->with(['agent_user:id,nickname,mobile,level,headimgurl'])->first();
  654. $users=[];
  655. if($user->cert_status==0){
  656. $user['status']=0;
  657. }else{
  658. // if(in_array($user->cert_status,[1,2,3,4,5])){
  659. $user_cert=UserCert::where('user_id',$user_id)->orderBy('id','desc')->limit(1)->get();
  660. $users['status']=$user->cert_status;
  661. $users['service_status']=$user->service_status;
  662. if($user->crown_info && $user->crown_info->level==3){
  663. $users['service_info']['nickname']=$user->crown_info->nickname;
  664. $users['service_info']['mobile']=hide_phone($user->crown_info->mobile);
  665. $users['service_info']['level']=$user->crown_info->level;
  666. $users['service_info']['headimgurl']=$user->crown_info->headimgurl;
  667. if(count($user_cert)>0){
  668. $users['service_info']['company_time']=$user_cert[0]->company_updated_at==null?strtotime($user_cert[0]->company_updated_at):'';
  669. }else{
  670. $users['service_info']['company_time']='';
  671. }
  672. }else{
  673. $users['service_info']['nickname']='';
  674. $users['service_info']['mobile']='';
  675. $users['service_info']['level']='';
  676. $users['service_info']['headimgurl']='';
  677. $users['service_info']['company_time']='';
  678. // $users['service_info']=[];
  679. }
  680. // if ($user->warea_id){
  681. // $users['service_info']=DB::table('warea')->where('id',$user->warea_id)->select('admin_name')->first();
  682. // }
  683. $users['nickname']=$user->nickname;
  684. $users['mobile']=hide_phone($user->mobile);
  685. $users['level']=$user->level;
  686. $users['headimgurl']=$user->headimgurl;
  687. $users['time']=strtotime($user->created_at);
  688. if($user->recom_user){
  689. $users['warea_info']=Warea::where('id',$user->recom_user->warea_id)->select('avatar','qrcode','admin_name')->first();
  690. $users['recom_name']=$user->recom_user->nickname;
  691. $users['recom_mobile']=hide_phone($user->recom_user->mobile);
  692. $users['recom_level']=$user->recom_user->level;
  693. $users['recom_headimgurl']=$user->recom_user->headimgurl;
  694. if(count($user_cert)>0){
  695. $users['recom_time']=strtotime($user_cert[0]->recom_updated_at);
  696. }else{
  697. $users['recom_time']=null;
  698. }
  699. if($user->agent_user){
  700. $users['agent_name']=$user->agent_user->nickname;
  701. $users['agent_mobile']=hide_phone($user->agent_user->mobile);
  702. $users['agent_level']=$user->agent_user->level;
  703. $users['agent_headimgurl']=$user->agent_user->headimgurl;
  704. if(count($user_cert)>0){
  705. $users['agent_time']=strtotime($user_cert[0]->agent_updated_at);
  706. }else{
  707. $users['agent_time']=null;
  708. }
  709. }
  710. }
  711. // }elseif ($user->cert_status==6){
  712. // $users['status']=6;
  713. }
  714. $users['in_group']=$user->in_group;
  715. $users['in_group_time']=$user->service_end_time;
  716. return $this->success($users);
  717. }
  718. public function rand_code($num){
  719. $code='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  720. $str=$num."_";
  721. $str_1='';
  722. for ($i=0;$i<20;$i++){
  723. $int=rand(0,34);
  724. $str_1.=mb_substr($code,$int,1);
  725. }
  726. $str=$str.mb_substr(time(),2,3).$str_1;
  727. return $str.mb_substr(time(),7,3);
  728. }
  729. /*--上传授权书---*/
  730. public function auth_share(Request $request,ImageUploadHandler $handler){
  731. Log::error('{---------开始----------}');
  732. if ($request->img){
  733. try{
  734. $data=$handler->save($request->img,'img',Auth::user()->id);
  735. Log::error('{---------开始-大幅度发的---------}');
  736. if ($data){
  737. $user=User::find(Auth::user()->id);
  738. $user->auth_img=$data['path'];
  739. $user->save();
  740. return $this->success(['url'=>$data['path']]);
  741. }else{
  742. return $this->error(300);
  743. }
  744. }catch (\Exception $e){
  745. Log::error('{------这里是上传授权书-----}'.Carbon::now()->toDateTimeString());
  746. return $this->error(300);
  747. }
  748. }
  749. }
  750. public function auth_sel(Request $request){
  751. $user=User::where('mobile',$request->phone)->first();
  752. if (!$user){
  753. $status=3;
  754. $msg='未查询到授权';
  755. }else{
  756. if ($user->freeze_status==1 || $user->status==1){
  757. $status=3;
  758. if ($user->status===1){
  759. $msg='未查询到授权';
  760. // $msg='授权已被取消';
  761. }else{
  762. $msg='未查询到授权';
  763. // $msg='该代理账户已被冻结';
  764. }
  765. }else{
  766. if ($user->service_status==1||$user->service_status==2) {
  767. $status = 3;
  768. $msg = '该代理尚未通过审核,暂未授权';
  769. }elseif($user->in_group != 1){
  770. $status = 3;
  771. $msg = '该代理尚未通过审核,暂未授权';
  772. }else{
  773. if ($user->deleted_at){
  774. $status=3;
  775. $re=DB::table('agent_operation_log')->where('user_id',$user->id)->where('type',4)->orderByDesc('id')->first();
  776. if ($re){
  777. // $cause_one=['不做','主动退货','不来了','没有进货','没货了','不在人间','单位考核','联系不上'];
  778. // $cause_two=['重复','夫妻俩都有授权','换号了','授权改为家属','更换手机号'];
  779. // $cause_three=['不思悔改','不愿意退差价','低价','淘宝','第三','窜货','长期不订货','骚扰代理','不进货','私自'];
  780. // $msg='';
  781. // foreach ($cause_one as $k=>$v){
  782. // $res=stripos($re->remark,$v);
  783. // if ($res===0 ||$res){
  784. // $msg='主动退货退出';
  785. // break;
  786. // }
  787. // }
  788. // if (!$msg){
  789. // foreach ($cause_two as $ke=>$va){
  790. // $res=stripos($re->remark,$va);
  791. // if ($res===0 ||$res){
  792. // $msg='授权重复被撤销';
  793. // break;
  794. // }
  795. // }
  796. // }
  797. // if (!$msg){
  798. // foreach ($cause_three as $kes=>$vas){
  799. // $res=stripos($re->remark,$vas);
  800. // if ($res===0 ||$res){
  801. // $msg='违规被取消授权';
  802. // }
  803. // }
  804. // }
  805. // if (!$msg){
  806. // $msg='授权被取消';
  807. // }
  808. $msg='未查询到授权';
  809. }else{
  810. $msg='未查询到授权';
  811. }
  812. }else{
  813. $st=[0,1,2,4,5];
  814. if (in_array($user->cert_status,$st)){
  815. $msg='正在审核中';
  816. $status=3;
  817. }else{
  818. // $now=Carbon::now()->timestamp;
  819. // $time=strtotime($user->auth_endtime);
  820. // if ($now>$time){
  821. // $status=3;
  822. // $msg='授权已过期';
  823. // }else{
  824. $data['phone']=$user->mobile;
  825. $data['level']=judge_level($user->level);
  826. $data['wechat']=$user->nickname;
  827. $data['num']=$user->cre_num;
  828. $data['realname']=$user->realname;
  829. $msg='ok';
  830. $status=1;
  831. // }
  832. }
  833. }
  834. }
  835. }
  836. }
  837. $data['status']=$status;
  838. return $this->success($data,$msg);
  839. }
  840. public function auth_show(Request $request){
  841. $user=User::where('mobile',$request->phone)->first();
  842. if ($user->auth_img==null){
  843. $name=$user->realname==null?$user->nickname:$user->realname;
  844. $url=$this->auth_create($name,$user->mobile,judge_level($user->level),$user->auth_code,$user->auth_startime,$user->auth_endtime,$user->id);
  845. $user->auth_img=$url;
  846. $user->save();
  847. }
  848. // $data['time_start']=strtotime($user->auth_startime)*1000;
  849. // $data['time_end']=strtotime($user->auth_endtime)*1000;
  850. // $data['auth_code']=$user->auth_code;
  851. // $data['phone']=$request->phone;
  852. // $data['level']=judge_level($user->level);
  853. // $data['nickname']=$user->nickname==null?$user->name:$user->nickname;
  854. // $data['realname']=$user->realname==''?$user->nickname:$user->realname;
  855. $data['url']=$user->auth_img;
  856. return $this->success($data);
  857. }
  858. public function gzh(Request $request){
  859. // if ($request->has('from')){
  860. // return ' <div style="padding: 2vw; box-sizing: border-box; height: 100%; background: rgb(243, 243, 243); display: flex; flex-direction: column; align-items: center;">
  861. // <div style="margin-top: 30vw; width: 20vw; height: 20vw; border-radius: 50%; background: rgb(247, 98, 95); display: flex; justify-content: center; align-items: center; font-size: 18vw; color: #ffffff;">!</div>
  862. // <div style="margin-top: 24vw; font-size: 6vw; color: black;">已停止访问该网页</div>
  863. // </div>';
  864. // }
  865. Log::error(json_encode($request->all()));
  866. // return '<script>alert("暂无信息")</script>';
  867. $url=$request->url();
  868. Log::info($url);
  869. $num=mb_strlen($url);
  870. $num1=mb_strlen('http://tw.cliu.cc/api/gzh/');
  871. if ($num>$num1){
  872. $data=substr($url,-5);
  873. if ($data=='david'){
  874. return '<script>alert("当前链接失效,请联系邀请人分享二维码进行注册")</script>';
  875. }
  876. $time=substr($url,-10);
  877. if (is_numeric($time)){
  878. }else{
  879. return '<script>alert("当前链接失效,请联系邀请人重新分享二维码")</script>';
  880. }
  881. }
  882. return view('yzm');
  883. }
  884. public function gzhtest(Request $request){
  885. // if ($request->has('from')){
  886. // return ' <div style="padding: 2vw; box-sizing: border-box; height: 100%; background: rgb(243, 243, 243); display: flex; flex-direction: column; align-items: center;">
  887. // <div style="margin-top: 30vw; width: 20vw; height: 20vw; border-radius: 50%; background: rgb(247, 98, 95); display: flex; justify-content: center; align-items: center; font-size: 18vw; color: #ffffff;">!</div>
  888. // <div style="margin-top: 24vw; font-size: 6vw; color: black;">已停止访问该网页</div>
  889. // </div>';
  890. // }
  891. return view('yzmtest');
  892. }
  893. public function test(Request $request){
  894. if ($request->has('from')){
  895. return redirect('/api/test',301);
  896. }
  897. return view('test');
  898. }
  899. public function gzh1(){
  900. return view('recom');
  901. }
  902. public function auth_select(){
  903. // return '<script>alert("暂无信息")</script>';
  904. // if (!Agent::isMobile()){
  905. // return view()->file(base_path().'/public/selectstatic/header.html');
  906. // }
  907. return view('select');
  908. }
  909. public function logout(){
  910. $user=Auth::user();
  911. $row=User::where('id',$user->id)->update([
  912. 'openid'=>null,
  913. 'unionid'=>null
  914. ]);
  915. if($row){
  916. return $this->success([]);
  917. }
  918. return $this->error();
  919. // return response(view('yzm')) ->withCookie(new SCookie('DWBSTOKEN', 'sid9999', time()-1,'/api'))
  920. // ->withCookie(new SCookie('DWBSTOKEN','DWBSTOKEN',time()-10,'/'));
  921. }
  922. public function login(Request $request){
  923. $user=User::where('mobile',$request->mobile)->where('deleted_at','=',null)->first();
  924. if (!$user){
  925. return $this->error(600);
  926. }
  927. if ($user->status==1){
  928. return $this->error(700);
  929. }
  930. $password = md5($request->password);
  931. if (!hash_equals($password,$user->password)) {
  932. //返回401
  933. return $this->error(300);
  934. }
  935. $token=Auth::guard()->fromUser($user);
  936. return $this->success(['token'=>$token]);
  937. }
  938. public function update_pass(Request $request){
  939. $id=Auth::user()->id;
  940. $user=User::find($id);
  941. $user->password=md5($request->password);
  942. $user->save();
  943. return $this->success([]);
  944. }
  945. public function update_nickname(Request $request){
  946. DB::beginTransaction();
  947. try{
  948. $user=User::find(Auth::user()->id);
  949. $user->nickname=$request->nickname;
  950. $user->save();
  951. DB::commit();
  952. return $this->success([],'修改昵称成功');
  953. }catch (\Exception $exception){
  954. Log::error('{-------用户修改昵称出错----错误信息为--}'.$exception);
  955. DB::rollBack();
  956. return $this->error(40013,'','修改出错,请重新尝试');
  957. }
  958. }
  959. public function CreateTokenTest(Request $request){
  960. $phone=$request->input('phone','');
  961. if ($phone){
  962. $re=User::where('mobile',$phone)->first();
  963. if ($re){
  964. return $this->success(Auth::guard('api')->fromUser($re));
  965. }else{
  966. return $this->error(50214,'','没找到');
  967. }
  968. }
  969. return $this->error(50214,'','请添加参数 phone');
  970. }
  971. public function GetSetingTime(){
  972. $re=System::where('keys','upgrade_status')->value('values');
  973. if ($re==1){
  974. $start_time=System::where('keys','upgrade_start_time')->value('values');
  975. $end_time=System::where('keys','upgrade_end_time')->value('values');
  976. return $this->success(['status'=>true,'start_time'=>$start_time,'end_time'=>$end_time]);
  977. }
  978. return $this->success(['status'=>false]);
  979. }
  980. //设置代理皇冠
  981. public function setUserCrown()
  982. {
  983. // User::where('level',3)->whereIn('cert_status',[3,6])->update(['crown_id'=>null]);
  984. // $crowns = User::where('level',3)->whereIn('cert_status',[3,6])->get();
  985. // foreach($crowns as $key=>$val){
  986. // User::where('agent_id',$val->id)->update(['crown_id'=>$val->id]);
  987. // $tops=User::where('level',2)->whereIn('cert_status',[3,6])->where('agent_id',$val->id)->get();
  988. // foreach($tops as $k=>$v){
  989. // User::where('agent_id',$v->id)->update(['crown_id'=>$val->id]);
  990. // }
  991. // }
  992. }
  993. public function shouquan(Request $request){
  994. $url='http://api.cl.jiuweiyun.cn';
  995. return redirect($url);
  996. }
  997. /***
  998. *author:kele
  999. *信箱授权AA
  1000. */
  1001. public function xxShouQuan(Request $request){
  1002. $url='http://api.cl.jiuweiyun.cn/api/cl?status=1&code='.$request->input('code');
  1003. // $url='http://192.168.2.120:8080?status=1&code='.$request->input('code');
  1004. return redirect($url);
  1005. }
  1006. }