SelectController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Handlers\ImageUploadHandler;
  4. use App\Models\FwCode;
  5. use App\Models\GoodSelect;
  6. use App\Models\Select;
  7. use App\Models\SendGoodLog;
  8. use App\Models\User;
  9. use Carbon\Carbon;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\Auth;
  12. use Illuminate\Support\Facades\Log;
  13. use Zxing\QrReader;
  14. class SelectController extends Controller
  15. {
  16. public function code(\Illuminate\Support\Facades\Request $request){
  17. return response()->view('fangwei');
  18. }
  19. public function wazi(Request $request){
  20. $code=$request->input('f');
  21. $lenth=mb_strlen($code);
  22. //大码
  23. if ($lenth==10){
  24. $re = FwCode::where('top_code', $code)->first();
  25. }elseif ($lenth==11){
  26. $re = FwCode::where('mid_code', $code)->first();
  27. }else{
  28. $re = FwCode::where('code', $code)->first();
  29. }
  30. if ($re){
  31. if ($re->goods_id!=14){
  32. return response()->view('fangweineiku');
  33. }
  34. }
  35. return response()->view('fangweiwazi');
  36. }
  37. /**查询二维码中是谁的信息**/
  38. public function select_user(Request $request){
  39. if($request->has('type')){
  40. $lenth=mb_strlen($request->input('code'));
  41. if ($lenth!=12){
  42. if ($lenth==10){
  43. $dw=FwCode::where('top_code',$request->input('code'))->first();
  44. }elseif($lenth==11){
  45. $dw=FwCode::where('mid_code',$request->input('code'))->first();
  46. }else{
  47. return $this->error(300,'','查不到此二维码信息');
  48. }
  49. if (!$dw){
  50. return $this->error(300,'','查不到此二维码信息');
  51. }
  52. $status=1;
  53. if ($dw->user_id){
  54. $status=0;
  55. }
  56. return $this->error(700,['com_binding'=>$status],'请使用小码进行查询');
  57. }
  58. $dw=FwCode::where('code',$request->input('code'))
  59. ->with(['select_good_log'=>function($q){
  60. $q->where('op_id',0)->OrderByDesc('created_at')->limit(1);
  61. }])
  62. ->first();
  63. if (!$dw){
  64. return $this->error(300,'','此货物是假货,请联系官方电话进行举报');
  65. }
  66. if (!$dw->user_id){
  67. return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
  68. }
  69. $user=User::select('nickname','mobile','id','level','area_code','cre_num')->find($dw->user_id);
  70. if (!$user){
  71. $nickname='未知用户';
  72. $level=2;
  73. }else{
  74. $nickname=$user->nickname;
  75. $level=$user->level;
  76. }
  77. $price='';
  78. $goodname='';
  79. if ($request->input('type')){
  80. $goods=GoodSelect::where('id',$dw->goods_id)->first();
  81. $price=$goods->price;
  82. $goodname=$goods->good_name;
  83. }
  84. $data=[
  85. 'style'=>$goodname,
  86. 'price'=>$price,
  87. 'hidePrice'=>'',
  88. // 'info'=>$re->select_good_log,
  89. 'nickname'=>$nickname,
  90. // 'nicknames'=>$re->select_good_log->accept_name,
  91. 'level'=>$this->judge_level($level),
  92. 'phone'=>'不显示',
  93. 'time'=>$dw->select_good_log->created_at->toDateTimeString(),
  94. 'url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png'
  95. ];
  96. return $this->success($data);
  97. }
  98. $re=Select::where('code',$request->code)->with(['select_good','select_good_log'=>function($q){
  99. $q->where('type',0)->OrderByDesc('created_at')->limit(1);
  100. }])->first();
  101. if ($re){
  102. if ($re->is_true==1){
  103. return $this->error(300,'','此货物是假货,请联系官方电话进行举报');
  104. }
  105. if ($re->is_lowest!=1){
  106. return $this->error(700,['com_binding'=>$re->com_binding],'请使用小码进行查询');
  107. }
  108. if ($re->com_binding==1){
  109. return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
  110. }
  111. if (!$re->user_id){
  112. return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
  113. }
  114. $re->select_num+=1;
  115. $re->save();
  116. $user=User::select('nickname','mobile','id','level','area_code','cre_num')->find($re->user_id);
  117. $nickname='';
  118. $level=4;
  119. $mobiles='';
  120. $hidePrice=0;
  121. if(!$user){
  122. // if ($re->select_good_log->op_id!=0){
  123. // $user=User::where('id',$re->select_good_log->op_id)->first();
  124. // if (!$user){
  125. // $mobiles=$re->select_good_log->accept_phone;
  126. // $nickname=$re->select_good_log->accept_name;
  127. // $level=4;
  128. //// return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
  129. // }
  130. // }else{
  131. // $mobiles=$re->select_good_log->accept_phone;
  132. // $nickname=$re->select_good_log->accept_name;
  133. // $level=4;
  134. //// return $this->error(50022,'','此货物暂未绑定代理,请联系官方进行处理');
  135. // }
  136. }else{
  137. if ($re->select_good->good_name=='大卫博士健康内裤(精装版)'){
  138. if ($user->area_code=='+886'){
  139. $hidePrice=1;
  140. }
  141. if (!is_numeric(mb_substr($user->cre_num,0,1))){
  142. $hidePrice=1;
  143. }
  144. }
  145. if ($re->is_lowest==1){
  146. $user->is_lowest=true;
  147. }else{
  148. $user->is_lowest=false;
  149. }
  150. $mobiles=$user->mobile;
  151. $nickname=$user->nickname;
  152. $level=$user->level;
  153. if ($user->id==39516){
  154. $mobiles='大卫博士公司';
  155. }
  156. }
  157. $data=[
  158. 'style'=>$re->select_good->good_name,
  159. 'price'=>$re->select_good->price,
  160. 'hidePrice'=>$hidePrice,
  161. // 'info'=>$re->select_good_log,
  162. 'nickname'=>$nickname,
  163. // 'nicknames'=>$re->select_good_log->accept_name,
  164. 'level'=>$this->judge_level($level),
  165. 'phone'=>'不显示',
  166. 'time'=>$re->updated_at->toDateTimeString(),
  167. 'url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png'
  168. ];
  169. return $this->success($data);
  170. }else{
  171. return $this->error(50021,['url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png'],'暂无该货物信息,请重试');
  172. }
  173. }
  174. public function get_img_url(){
  175. return $this->success(['url'=>'http://fangw.jiuweiyun.cn/banner_1/banner_1.png']);
  176. }
  177. /**真伪查询**/
  178. public function select_true(Request $request){
  179. $re=Select::where('security_code',$request->security_code)->where('code',$request->code)->first();
  180. if ($re){
  181. if ($re->com_binding==1){
  182. return $this->error(40021,'','该商品是假货');
  183. }
  184. if ($re->is_true==1){
  185. return $this->error(40021,'','该商品是假货');
  186. }
  187. return $this->success([]);
  188. }else{
  189. return $this->error(40023,'','暂未查到该商品的真伪信息,请检查防伪码是否输入正确!');
  190. }
  191. }
  192. /**真伪查询**/
  193. public function select_truewazi(Request $request){
  194. $re=FwCode::where('num',$request->security_code)->where('code',$request->code)->first();
  195. if ($re){
  196. // if ($re->com_binding==1){
  197. // return $this->error(40021,'','该商品是假货');
  198. // }
  199. // if ($re->is_true==1){
  200. // return $this->error(40021,'','该商品是假货');
  201. // }
  202. return $this->success([]);
  203. }else{
  204. return $this->error(40023,'','暂未查到该商品的真伪信息,请检查防伪码是否输入正确!');
  205. }
  206. }
  207. /**展示退货商品所属信息**/
  208. public function select_return_user(Request $request){
  209. $re=Select::where('code',$request->code)->with(['select_user','select_good'])->first();
  210. if (empty($re)){
  211. return $this->error(52121,'','暂无信息查询');
  212. }
  213. if (!$re->select_user){
  214. return $this->error(52121,'','暂无代理信息');
  215. }
  216. if (!$re->select_good){
  217. return $this->error(52121,'','暂无商品信息');
  218. }
  219. $res=$this->check_user_level(Auth::user()->id,$re->user_id);
  220. if ($res['code']!=200){
  221. return $this->error($res['code'],'',$res['message']);
  222. }
  223. $time=SendGoodLog::where('select_id',$re->id)->where('accept_id',$re->user_id)->orderByDesc('created_at')->first();
  224. $data=[
  225. 'style'=>$re->select_good->good_name,
  226. 'nickname'=>$re->select_user->nickname,
  227. 'level'=>$this->judge_level($re->select_user->level),
  228. 'phone'=>$re->select_user->mobile,
  229. 'time'=>$time->created_at->toDateString()
  230. ];
  231. return $this->success($data);
  232. }
  233. /**检查用户**/
  234. public function check_user_level($id,$user_id){
  235. if ($id==$user_id){
  236. return ['code'=>50026,'message'=>'你不能对自己的货物进行退货操作'];
  237. }
  238. return ['code'=>200];
  239. }
  240. /**判断等级**/
  241. public function judge_level($status){
  242. switch ($status){
  243. case 2:
  244. $level='经销商';
  245. break;
  246. case 3:
  247. $level='批发商';
  248. break;
  249. default:
  250. $level='';
  251. break;
  252. }
  253. return $level;
  254. }
  255. /**展示发货商品所属信息**/
  256. public function select_send_user(Request $request){
  257. Log::error($request->all());
  258. $user=Auth::user();
  259. $re=Select::where('code',$request->code)->with(['select_user','select_good'])->first();
  260. if (empty($re)){
  261. Log::error(1);
  262. return $this->error(52119,'','暂无信息查询');
  263. }
  264. if (!$re->select_user){
  265. Log::error(2);
  266. return $this->error(52120,'','暂无代理信息');
  267. }
  268. if (!$re->select_good){
  269. Log::error(3);
  270. return $this->error(52121,'','暂无商品信息');
  271. }
  272. if ($re->user_id!=$user->id){
  273. Log::error(4);
  274. return $this->error(50021,'','当前货物不是您的货物,不能使用此码进行发货');
  275. }
  276. $time=SendGoodLog::where('select_id',$re->id)->where('accept_id',$re->user_id)->orderByDesc('created_at')->first();
  277. if ($time){
  278. $times=$time->created_at->toDateString();
  279. }else{
  280. $times=Carbon::now()->toDateString();
  281. }
  282. $data=[
  283. 'style'=>$re->select_good->good_name,
  284. 'nickname'=>$re->select_user->nickname,
  285. 'avatar'=>$re->select_user->headimgurl,
  286. 'level'=>$this->judge_level($re->select_user->level),
  287. 'phone'=>$re->select_user->mobile,
  288. 'time'=>$times
  289. ];
  290. return $this->success($data);
  291. }
  292. /**查询二维码中是谁的信息**/
  293. public function CKSelect(Request $request,ImageUploadHandler $imageUploadHandler){
  294. if ($request->file('image')){
  295. try {
  296. $path=$imageUploadHandler->save($request->image,'QrCodeCK','1');
  297. $qrcode=new QrReader($path['path']);
  298. $text=$qrcode->text();
  299. $code=mb_substr($text,35);
  300. $url=$path['url'];
  301. unlink(public_path()."$url");
  302. $re=Select::where('code',$code)->with(['select_good','select_good_log'=>function($q){
  303. $q->where('type',0)->OrderBy('created_at');
  304. }])->first();
  305. if ($re){
  306. return $this->success($re);
  307. }else{
  308. return $this->error(500214,'1','未查出信息,请确保二维码拍摄清晰!');
  309. }
  310. }catch (\Exception $exception){
  311. return $this->error(500214,$exception->getMessage(),'未识别出信息');
  312. }
  313. }
  314. return $this->error(500214,'3','未识别出信息');
  315. }
  316. }