User.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: TABLE ME
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-25 17:23
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\controller;
  13. use app\BaseController;
  14. use app\model\api\User as UserModel;
  15. use app\model\api\UserDetail as UserDetailModel;
  16. use app\model\api\ServiceType as ServiceTypeModel;
  17. use app\model\api\InfoAudit;
  18. use app\model\api\TypeAudit;
  19. use app\model\api\UserAudit;
  20. use app\model\api\ServiceType;
  21. use app\model\api\ServiceLabel as ServiceLabelModel;
  22. use app\model\api\ServiceTimeType;
  23. use app\model\api\City as CityModel;
  24. use app\model\api\Sys as SysModel;
  25. use app\model\api\ShowTemplate;
  26. use app\model\api\ShowTemplateOrder;
  27. use app\model\api\UserShowTemplate;
  28. use app\model\api\UserWorkType;
  29. use app\model\api\PayTrade as PayTradeModel;
  30. use app\api\controller\pub;
  31. use app\Request;
  32. use library\services\UtilService;
  33. use library\utils\QRcodeComm;
  34. use library\utils\Qiniu;
  35. use library\utils\IdentityCard;
  36. use library\utils\WxpayV2 as wxpayApi;
  37. use think\db\exception\DbException;
  38. use library\lib\weixina;
  39. use think\facade\Db;
  40. use think\Image;
  41. use think\Route;
  42. use think\Collection;
  43. class User extends BaseController
  44. {
  45. /**
  46. * 获取用户详情
  47. * @param Request $request
  48. */
  49. public function userInfo(Request $request){
  50. //资料审核信息
  51. $infoAuditData = (new InfoAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
  52. $userAuditData = (new UserAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
  53. $typeAuditData = (new TypeAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
  54. $data = [];
  55. $data['uid'] = $request->user['uid'];
  56. $data['nickname'] = $request->user['nickname'];
  57. $data['mobile'] = $request->user['mobile'];
  58. $data['avatar'] = $request->user['avatar'];
  59. $data['name'] = $request->user['name'];
  60. $data['sex'] = $request->user['sex'];
  61. $data['type'] = $request->user['type'];//用户类型
  62. $data['type_name'] = "";//用户类型名称
  63. $data['work_type_id'] = $request->user['work_type_id'];//用户职称类型
  64. $data['work_type_title'] = $request->user['work_type_title'];//用户职称类型名称
  65. $data['card_look_count'] = $request->user['card_look_count'];//用户名片浏览次数
  66. $data['info_audit_status'] = empty($infoAuditData)?-2:$infoAuditData["status"];
  67. $data['user_audit_status'] = empty($userAuditData)?-2:$userAuditData["status"];
  68. $data['type_audit_status'] = empty($typeAuditData)?-2:$typeAuditData["status"];
  69. //资料通过需要重新提交认证
  70. if(!empty($infoAuditData) && !empty($typeAuditData)){
  71. if($infoAuditData["status"]==1 && $typeAuditData["status"]==1 && $infoAuditData["admin_time"]>$typeAuditData["admin_time"]){
  72. $data['type_audit_status'] = -3;
  73. }
  74. }
  75. $data['show_template_code'] = "";
  76. $data['show_template_id'] = "";
  77. $tmpData = (new UserShowTemplate)
  78. ->field("t.id,t.code,t.title,t.is_init,b.is_default")
  79. ->alias("b")
  80. ->join("show_template t","t.id = b.show_template_id","left")
  81. ->where("b.uid",$request->user['uid'])
  82. ->order("b.is_default","desc")
  83. ->order("b.id","desc")
  84. ->find();
  85. if(!empty($tmpData)){
  86. $data['show_template_code'] = $tmpData["code"];
  87. $data['show_template_id'] = $tmpData["id"];
  88. $data['show_template_init'] = $tmpData["is_init"];
  89. $data['show_template_default'] = $tmpData["is_default"];
  90. }
  91. return app('json')->success($data);
  92. }
  93. /**
  94. * 获取用户子级列表
  95. * @param Request $request
  96. */
  97. public function getChildList(Request $request){
  98. $post = UtilService::getMore([
  99. ['page', 1],
  100. ['pageSize', 50],
  101. ], $request);
  102. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  103. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  104. $post["parent_uid"]= $request->user["uid"];
  105. $data = (new UserModel)->getDataList($post,"u.uid,u.mobile,u.nickname,u.avatar");
  106. return app('json')->success($data);
  107. }
  108. /**
  109. * 获取用户总邀请人数排行榜
  110. * @param Request $request
  111. */
  112. public function getInviterRanking(Request $request)
  113. {
  114. $time = $request->param('time');
  115. $times = $request->param('times');
  116. $users = (new UserModel())
  117. ->where('parent_uid', '<>', 0)
  118. ->where('regtime', '>=', $time)
  119. ->where('regtime', '<=', $times)
  120. ->field('parent_uid as uid, count(*) as invite_count')
  121. ->group('parent_uid')
  122. ->order('invite_count', 'desc')
  123. ->select();
  124. $users2 = (new UserModel())
  125. ->where('parent_uid', 0)
  126. ->where('regtime', '>=', $time)
  127. ->where('regtime', '<=', $times)
  128. ->field('parent_uid as uid, count(*) as invite_count')
  129. ->group('parent_uid')
  130. ->order('uid', 'desc')
  131. ->select();
  132. $rankList = [];
  133. $rankList2 = [];
  134. foreach ($users as $key => $value) {
  135. $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
  136. $auth = (new InfoAudit)->where('uid', $value['uid'])->find();
  137. $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
  138. $rankList[] = [
  139. 'rank' => $key + 1,
  140. 'uid' => $value['uid'],
  141. 'nickname' => $userInfo['nickname'],
  142. 'avatar' => $userInfo['avatar'],
  143. 'invite_count' => $value['invite_count'],
  144. 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
  145. 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
  146. 'auth_info' => $auth ? $auth->toArray() : [],
  147. 'user_work_type_id' => $user_work_type_title['title'],
  148. ];
  149. }
  150. foreach ($users2 as $key => $value) {
  151. $userInfo2 = (new UserModel)->where('uid', $value['uid'])->find();
  152. $auth2 = (new InfoAudit)->where('uid', $value['uid'])->find();
  153. $user_work_type_title2 = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
  154. $rankList2[] = [
  155. 'rank' => $key + 1,
  156. 'uid' => $value['uid'],
  157. 'nickname' => $userInfo2['nickname'],
  158. 'avatar' => $userInfo2['avatar'],
  159. 'invite_count' => $value['invite_count'],
  160. 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
  161. 'ancestral_place' => $auth2 ? $auth2['ancestral_place'] : '',
  162. 'auth_info' => $auth ? $auth->toArray() : [],
  163. 'user_work_type_id' => $user_work_type_title2['title'],
  164. ];
  165. }
  166. $rankList = array_values(array_filter($rankList, function ($item) {
  167. return !empty($item['ancestral_place']);
  168. }));
  169. $rankList2 = array_values(array_filter($rankList2, function ($item) {
  170. return !empty($item['ancestral_place']);
  171. }));
  172. $inviteCount = array_column($rankList, 'invite_count');
  173. $uid = array_column($rankList, 'uid');
  174. array_multisort($inviteCount, SORT_DESC, $uid, SORT_ASC, $rankList);
  175. $inviteCount2 = array_column($rankList2, 'invite_count');
  176. $uid2 = array_column($rankList2, 'uid');
  177. array_multisort($inviteCount2, SORT_DESC, $uid2, SORT_ASC, $rankList2);
  178. $data['list'] = $rankList;
  179. $data['list2'] = $rankList2;
  180. return app('json')->success($data);
  181. }
  182. // public function getInviterRanking(Request $request)
  183. // {
  184. // $time = $request->param('time');
  185. // $times = $request->param('times');
  186. // $users = (new UserModel())
  187. // ->leftJoin('user u', 'u.uid = user.parent_uid')
  188. // ->where('user.parent_uid', '<>', 0)
  189. // ->where('user.regtime', '>=', $time)
  190. // ->where('user.regtime', '<=', $times)
  191. // ->field('user.parent_uid as uid, IFNULL(count(u.uid), 0) as invite_count')
  192. // ->group('user.parent_uid')
  193. // ->order('invite_count', 'desc')
  194. // ->order('user.parent_uid', 'asc')
  195. // ->select();
  196. // $rankList = [];
  197. // foreach ($users as $key => $value) {
  198. // $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
  199. // $auth = (new InfoAudit)->where('uid', $value['uid'])->find();
  200. // $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
  201. // $rankList[] = [
  202. // 'rank' => $key + 1,
  203. // 'uid' => $value['uid'],
  204. // 'nickname' => $userInfo['nickname'],
  205. // 'avatar' => $userInfo['avatar'],
  206. // 'invite_count' => $value['invite_count'],
  207. // 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
  208. // 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
  209. // 'auth_info' => $auth ? $auth->toArray() : [],
  210. // 'user_work_type_id' => $user_work_type_title['title'],
  211. // ];
  212. // }
  213. //
  214. // $rankList = array_values(array_filter($rankList, function ($item) {
  215. // return empty($item['auth_info']['service_area']);
  216. // }));
  217. //
  218. // $inviteCount = array_column($rankList, 'invite_count');
  219. // $uid = array_column($rankList, 'uid');
  220. // array_multisort($inviteCount, SORT_DESC, $uid, SORT_ASC, $rankList);
  221. //
  222. // $data['list'] = $rankList;
  223. //
  224. // return app('json')->success($data);
  225. // }
  226. /**
  227. * 设置用户信息
  228. * @param Request $request
  229. */
  230. public function setUserInfo(Request $request){
  231. $post = UtilService::getMore([
  232. ['avatar',''],
  233. ['nickname',''],
  234. ['name',''],
  235. // ['mobile',''],
  236. ['sex', ''],
  237. ],$request);
  238. $save=[];
  239. if(!empty($post["avatar"])){
  240. $save["avatar"] = $post["avatar"];
  241. }
  242. if(!empty($post["nickname"])){
  243. $save["nickname"] = $post["nickname"];
  244. }
  245. if(!empty($post["name"])){
  246. $save["name"] = $post["name"];
  247. }
  248. // if(!empty($post["mobile"])){
  249. // if(is_mobile($post["mobile"])){
  250. // return app("json")->fail("请输入正确的手机号码");
  251. // }
  252. // $save["mobile"] = $post["mobile"];
  253. // }
  254. if(in_array((string)$post["sex"],["0","1","2"])){
  255. $save["sex"] = (int)$post["sex"];
  256. }
  257. if(empty($save)){
  258. return app("json")->fail("提交数据为空");
  259. }
  260. //是否需要审核
  261. $isInfoAudit = 0;
  262. if($isInfoAudit==0){
  263. $r = (new UserModel)->where("uid",$request->user["uid"])->update($save);
  264. if(!$r){
  265. return app("json")->fail("提交数据为空");
  266. }
  267. }else{
  268. $data = (new UserAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
  269. if(!empty($data) && $data["status"]==0){
  270. return app('json')->fail("资料审核中,请勿重复提交");
  271. }
  272. $save["uid"] = $request->user["uid"];
  273. $save["status"] = 0;
  274. $r = (new UserAudit)->insert($save);
  275. if(!$r){
  276. return app("json")->fail("提交数据为空");
  277. }
  278. }
  279. return app("json")->success("提交成功");
  280. }
  281. /**
  282. * 绑定手机号
  283. * @param Request $request
  284. */
  285. public function bindMobile(Request $request){
  286. [$code] = UtilService::getMore([
  287. ['code', '', 'empty', 'code参数错误'],
  288. ], $request, true);
  289. if(!empty($request->user['mobile'])){
  290. return app('json')->fail("当前账户已绑定过手机号码");
  291. }
  292. $weixinA = new weixina();
  293. $data=$weixinA->getPhoneNumber($code);//新版
  294. if(empty($data) || empty($data['purePhoneNumber'])) {
  295. return app('json')->fail("绑定失败,请重新绑定01".$weixinA->error);
  296. }
  297. $save=[
  298. // "countryCode"=>empty($data['countryCode'])?"":$data['countryCode'],
  299. "mobile"=>$data['purePhoneNumber'],
  300. ];
  301. // if($request->user["nickname"]=="微信用户"){
  302. // $save["nickname"] = $data['purePhoneNumber'];
  303. // }
  304. $r = (new UserModel)->where('uid', $request->user['uid'])->update($save);
  305. if(!$r){
  306. return app('json')->fail("绑定失败,请重新绑定02");
  307. }
  308. $result = [];
  309. $result['nickname'] = $request->user['nickname'];
  310. $result['avatar'] = $request->user['avatar'];
  311. return app('json')->success($result);
  312. }
  313. /**
  314. * 获取名片信息
  315. * @param Request $request
  316. */
  317. public function getUserCardInfo(Request $request){
  318. $data = (new InfoAudit)->getItem(["uid"=>$request->user["uid"],"status"=>1]);
  319. if(empty($data)){
  320. return app('json')->fail("您还没有通过名片信息审核");
  321. }
  322. $typeData = (new TypeAudit)->where("uid",$request->user["uid"])->order("id","desc")->find();
  323. $data["is_type_audit"] = (empty($typeData) || $typeData["status"]!=1)?0:1;
  324. return app('json')->success($data);
  325. }
  326. /**
  327. * 提交资料审核
  328. * @param Request $request
  329. */
  330. public function subInfoAudit(Request $request){
  331. $data = (new InfoAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
  332. if(!empty($data) && $data["status"]==0){
  333. return app('json')->fail("资料审核中,请勿重复提交");
  334. }
  335. $post = UtilService::getMore([
  336. ['avatar',''],
  337. ['name','','empty','请输入真实姓名'],
  338. ['mobile','','is_moblie','请输入正确的手机号码'],
  339. ['idcard','','empty','请输入正确的身份证号码'],
  340. ['birthday',''],
  341. ['service_type',''],
  342. ['service_price',''],
  343. ['service_min_price',''],
  344. ['service_max_price',''],
  345. ['service_area',[]],
  346. ['service_project',[]],
  347. ['service_intro_content',''],
  348. ['service_intro_imgs',[]],
  349. ['service_audit_imgs',[]],//此处为我的证书
  350. ['service_imgs',[]],//我的服务照片
  351. ['service_count',0],
  352. ['work_year',''],
  353. ['ancestral_place',''],
  354. ['education',''],
  355. ['minority',''],
  356. ['is_china',1],
  357. ['user_work_type_id','0'],//服务职称
  358. ['service_label',[]],//服务标签
  359. ],$request);
  360. if(!IdentityCard::isValid($post["idcard"])){
  361. return app('json')->fail("请输入正确的身份证号码");
  362. }
  363. $save=[];
  364. $save["avatar"] = empty($post["avatar"]) ? "" : $post["avatar"];
  365. $save["name"] = empty($post["name"]) ? "" : $post["name"];
  366. $save["mobile"] = empty($post["mobile"]) ? "" : $post["mobile"];
  367. $save["idcard"] = empty($post["idcard"]) ? "" : $post["idcard"];
  368. $save["service_count"] = $post['service_count'];
  369. // $save["birthday"] = empty($post["birthday"])? 0 : strtotime($post["birthday"]);
  370. $save["constellation"] = IdentityCard::get_starsign($post["idcard"]);//星座
  371. $save["twelve"] = IdentityCard::get_zodiac($post["idcard"]);//星座
  372. $save["birthday"] = strtotime(IdentityCard::get_birthday($post["idcard"]));
  373. //服务类型
  374. if(!empty($post["service_type"])){
  375. $timeTypeData = (new ServiceTimeType)->where("code",$post["service_type"])->where("status",1)->select();
  376. if(empty($timeTypeData)){
  377. return app('json')->fail("服务时长类型不存在");
  378. }
  379. $save["service_type"] = $post["service_type"];
  380. }
  381. //服务价格区间
  382. // $save["service_price"] = empty($post["service_price"]) ? "" : $post["service_price"];
  383. $save["service_min_price"] = empty($post["service_min_price"]) ? 0 : $post["service_min_price"];
  384. $save["service_max_price"] = empty($post["service_max_price"]) ? 0 : $post["service_max_price"];
  385. //服务区域
  386. $cityModel = new CityModel();
  387. if(!empty($post["service_area"]) && is_array($post["service_area"])){
  388. $saveAre=[];
  389. foreach($post["service_area"] as $v){
  390. $stc = str_replace(['省','市','区','县'],['','','',''],$v);
  391. $str = str_replace(['辖'],['市辖'],$stc);
  392. $arr = explode(",",$str);
  393. $city_id = $cityModel->where('merger_name','like',"%".$arr[1].",".$arr[2])->value('id');
  394. if(!$city_id) $city_id = $cityModel->where('merger_name','like',"%".$arr[0].",".$arr[1])->value('id');
  395. $saveAre[] = $city_id;
  396. }
  397. if(!empty($saveAre)){
  398. $save["service_area"] = implode(",", $saveAre);
  399. }
  400. }
  401. // //服务区域
  402. // $cityModel = new CityModel();
  403. // if(!empty($post["service_area"]) && is_array($post["service_area"])){
  404. // $saveAre=[];
  405. // foreach($post["service_area"] as $v){
  406. // @file_put_contents('dub.txt','1');
  407. // $arr = explode(",",$v);
  408. // $str1 = $arr[0].','.$arr[1];
  409. // @file_put_contents('dub.txt','2');
  410. // $stc = str_replace(['省','市','区','县'],['','','',''],$str1);
  411. // $str2 = $stc.",".$arr[2]!='市辖区'?str_replace(['省','市','区','县'],['','','',''],$arr[2]):'市辖区';
  412. // $arr3 = explode(",",$str2);
  413. // $city_id = $cityModel->where('merger_name','like',"%".$arr3[1].",".$arr3[2])->value('id');
  414. // @file_put_contents('dub.txt','3');
  415. // if(!$city_id)
  416. // {
  417. // $city_id = $cityModel->where('merger_name','like',"%".$arr3[0].",".$arr3[1])->value('id');
  418. // $city_id1 = $cityModel->where('merger_name','like',"%".$arr3[0].",".$arr3[1])->value('city_id');
  419. // $city_id2 = $cityModel->where('parent_id',$city_id1)->where('name','市辖区')->value('id');
  420. // if($city_id2>0) $city_id= $city_id2;
  421. // }
  422. // @file_put_contents('dub.txt','4');
  423. // $saveAre[] = $city_id;
  424. //
  425. // }
  426. // if(!empty($saveAre)){
  427. // $save["service_area"] = implode(",", $saveAre);
  428. // }
  429. // }
  430. //服务内容
  431. $serviceTypeModel = new ServiceTypeModel();
  432. if(!empty($post["service_project"]) && is_array($post["service_project"])){
  433. $saveCon=[];
  434. foreach($post["service_project"] as $k=>$v){
  435. if(empty(trim($v))){
  436. continue;
  437. }
  438. $itemData = $serviceTypeModel->where("id",(int)$v)->where("status",1)->find();
  439. if(!empty($itemData)){
  440. $saveCon[]=$itemData["id"];
  441. }
  442. }
  443. if(!empty($saveCon)){
  444. $save["service_project"] = implode(",", $saveCon);
  445. }
  446. }
  447. //服务标签
  448. $save["service_label"]="";
  449. $labelData = (new ServiceLabelModel)->getColumnList("id","id",$post["service_label"]);
  450. if(!empty($labelData)){
  451. $save["service_label"] = implode(",", $labelData);
  452. }
  453. $save["service_intro_content"] = empty($post["service_intro_content"])? "" : $post["service_intro_content"];
  454. $save["service_intro_imgs"] = empty($post["service_intro_imgs"]) ? "" : implode(",", $post["service_intro_imgs"]);
  455. $save["service_audit_imgs"] = empty($post["service_audit_imgs"]) ? "" : implode(",", $post["service_audit_imgs"]);
  456. $save["service_imgs"] = empty($post["service_imgs"]) ? "" : implode(",", $post["service_imgs"]);//我的服务展示
  457. $save['work_year'] = empty($post["work_year"]) ? "": $post["work_year"];
  458. $save['ancestral_place'] = empty($post["ancestral_place"])? "": $post["ancestral_place"];
  459. $save['education'] = empty($post["education"]) ? "": $post["education"];
  460. $save['minority'] = empty($post["minority"]) ? "": $post["minority"];
  461. $save["status"] = 0;
  462. $save["time"] = time();
  463. $save["uid"] = $request->user["uid"];
  464. $save['is_china'] = $post["is_china"];
  465. //服务职称
  466. $save["user_work_type_id"] = empty($post["user_work_type_id"]) ? 0: (int)$post["user_work_type_id"];
  467. if($save["user_work_type_id"]>0 && (new UserWorkType)->where("id",$post["user_work_type_id"])->where("status",1)->count()<=0){
  468. return app('json')->fail("当前类型不能选择");
  469. }
  470. //生成编码
  471. $r = (new InfoAudit)->insertGetId($save);
  472. if (!$r) {
  473. return app('json')->fail("系统错误");
  474. }
  475. $exist = (new InfoAudit)->where('uid', $save['uid'])->find();
  476. if ($exist && !empty($exist['no'])) {
  477. $no = $exist['no'];
  478. } else {
  479. $id = str_pad($r, 5, "0", STR_PAD_LEFT);
  480. $no = "MYJ" . date("ym") . $id;
  481. }
  482. (new InfoAudit)->where("id", $r)->update(["no" => $no]);
  483. return app('json')->success("提交成功,请耐心等待审核");
  484. }
  485. /**
  486. * 平台认证
  487. * @param Request $request
  488. */
  489. public function subTypeAudit(Request $request){
  490. $data = (new TypeAudit)->where("uid",$request->user["uid"])->order("id desc")->find();
  491. if(!empty($data) && $data["status"]==0){
  492. return app('json')->fail("平台审核中,请勿重复提交");
  493. }
  494. $post = UtilService::getMore([
  495. ['service_audit_imgs',[],"empty","请上传服务认证截图"],
  496. ],$request);
  497. $save=[];
  498. $save["service_audit_imgs"] = empty($post["service_audit_imgs"]) ?"": implode(",", $post["service_audit_imgs"]);
  499. $save["status"] = 0;
  500. $save["time"] = time();
  501. $save["uid"] = $request->user["uid"];
  502. if(empty($save["service_audit_imgs"])){
  503. return app('json')->fail("请上传服务认证截图");
  504. }
  505. $r = (new TypeAudit)->insertGetId($save);
  506. if(!$r){
  507. return app('json')->fail("系统错误");
  508. }
  509. $no = "CERT-".date("YmdHis")."-".$r;
  510. (new TypeAudit)->where("id",$r)->update(["no"=>$no]);
  511. return app('json')->success("提交成功,请耐心等待审核");
  512. }
  513. /**
  514. * 模板订单提交[第一步]
  515. * @param Request $request
  516. */
  517. public function subShowTemplateOrder(Request $request){
  518. [$id,$pay_type] = UtilService::getMore([
  519. ['id','','empty','参数错误'],
  520. ['pay_type','','empty','请选择支付方式'],
  521. ],$request,true);
  522. if(!in_array($pay_type,["wxpay","balance"])){
  523. return app('json')->fail('不支持该支付方式!');
  524. }
  525. $weixinConfig = (new SysModel)->getWeixinConfig();
  526. // if(empty($weixinConfig)){
  527. // return app('json')->fail('支付配置为空!');
  528. // }
  529. //缓存
  530. $redis = \think\facade\Cache::store('redis');
  531. $key = 'show_template_order_sub_' . $request->user['uid'];
  532. $bool = $redis->handler()->exists($key);
  533. if ($bool) {
  534. return app('json')->fail('请务重复操作,请稍等在重试!');
  535. }
  536. $redis->set($key,1,5);//5秒缓存
  537. $proData = (new ShowTemplate)->where("id",$id)->where("status",1)->find();
  538. if(empty($proData)){
  539. return app('json')->fail("当前模板已下架");
  540. }
  541. $proData = $proData->toArray();
  542. $count = (new UserShowTemplate)->where("uid",$request->user['uid'])->where("show_template_id",$id)->count();
  543. if($count>0){
  544. return app('json')->fail("您已购买过当前模板");
  545. }
  546. //验证
  547. $orderCount = (new ShowTemplateOrder)->where("uid",$request->user['uid'])->where("show_template_id",$id)->where("status",1)->count();
  548. if($orderCount>0){
  549. return app('json')->fail("您已下单该模板,请勿重复下单");
  550. }
  551. $price = floatval($proData["price"]);
  552. // if($price<0.01){
  553. // return app('json')->fail("模板信息错误");
  554. // }
  555. $allMoney = $price;//订单商品费用
  556. $total_money = $allMoney;//订单总费用
  557. $payMoney = $total_money;//订单需支付费用
  558. $payMoney = $payMoney <= 0 ? 0 : $payMoney;
  559. $nowTime = time();
  560. //余额支付验证
  561. if($pay_type=="balance" && $payMoney > $request->user["money"]){
  562. return app('json')->fail("当前余额不足");
  563. }
  564. //主订单数据
  565. $save=[];
  566. $save['uid'] = $request->user['uid'];
  567. $save['order_id'] = makeOrderId($request->user['uid'],"ST");
  568. $save['pay_type'] = $pay_type;//
  569. $save['total_money'] = $total_money;//订单总金额
  570. $save['all_money'] = $allMoney;//商品中金额
  571. $save['pay_money'] = $payMoney;//实际支付金额
  572. $save['balance'] = 0;//余额支付了多少(目前不用)
  573. $save['status'] = $payMoney <= 0 ? 1 : 0;
  574. $save['pay_time'] = $payMoney <= 0 ? time() : 0;
  575. $save['time'] = $nowTime;
  576. $save['show_template_id'] = $proData["id"];
  577. $save['show_template_title'] = $proData["title"];;
  578. $save['show_template_price'] = $proData["price"];
  579. $save['show_template_img'] = empty($proData["imgs"]) ? "" : explode(",", $proData["imgs"])[0];
  580. $save['show_template_code'] = $proData["code"];
  581. //余额实时支付
  582. if($pay_type=="balance"){
  583. $save['status'] = 1;
  584. $save['pay_time'] = time();
  585. }
  586. try{
  587. Db::startTrans();
  588. $o_id = (new ShowTemplateOrder)->insertGetId($save);
  589. if(empty($o_id)){
  590. return app('json')->fail("订单提交失败");
  591. }
  592. //不需要支付
  593. if($payMoney<=0 && $save['status']==1){
  594. //验证并绑定当前模板
  595. (new UserShowTemplate)->userBindTemp($save["show_template_id"],$save['uid']);
  596. Db::commit();
  597. return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
  598. }
  599. //余额支付
  600. if($pay_type=="balance"){
  601. //验证并绑定当前模板
  602. (new UserShowTemplate)->userBindTemp($save["show_template_id"],$save['uid']);
  603. //修改用户余额
  604. $res = (new UserDetailModel)->balancePay($request->user["uid"],$payMoney,"show_temp_pay",["to_id"=>$o_id]);
  605. if(!$res){
  606. Db::rollback();
  607. return app('json')->fail("余额支付失败");
  608. }
  609. Db::commit();
  610. return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
  611. }
  612. //微信支付
  613. if(empty($request->user['openid'])){
  614. Db::rollback();
  615. return app('json')->fail('用户还未绑定微信!');
  616. }
  617. //清理之前支付凭证 || 防止重复购买
  618. $payTrade = (new PayTradeModel)
  619. ->where("uid",$request->user["uid"])
  620. ->where("o_id",$o_id)
  621. ->where("type","temp")
  622. ->where("status",0)
  623. ->where("time","<",time() - 7*24*60*60)
  624. ->select()
  625. ->toArray();
  626. $wxpay = new wxpayApi();
  627. // $wxpay = new wxpayApi($weixinConfig);
  628. foreach ($payTrade as $v) {
  629. // if($v['pay_type'] == 'wxpay') {
  630. // $result = $wxpay->closeOrder($v['pay_no']);
  631. // }
  632. (new PayTradeModel)->where("id",$v['id'])->where("status",0)->delete();
  633. }
  634. $mtime = microtime(true)*10000;
  635. $payOn = "T".date("Ymd").$mtime .rand(100,999) . $request->user['uid'];
  636. $out_trade_no="";
  637. $payType = $save["pay_type"];
  638. //添加交易记录
  639. $trade = [
  640. 'uid' => $request->user['uid'],
  641. 'o_id' => $o_id,
  642. 'order_id' =>$save["order_id"],
  643. 'pay_no' => $payOn,
  644. 'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
  645. 'pay_type' => $payType,
  646. 'money' => $payMoney,
  647. 'type' => 'temp',
  648. 'd_json' => serialize(['orderId'=>$save["order_id"],"give_score"=>0]),
  649. 'time' => time(),
  650. 'status' => 0,
  651. ];
  652. $r=(new PayTradeModel)->insert($trade);
  653. if(!$r){
  654. Db::rollback();
  655. return app('json')->fail('支付信息获取失败!');
  656. }
  657. $clictip = get_client_ip();
  658. if(empty($clictip)){
  659. $clictip = $request->ip();
  660. }
  661. $payData = $wxpay->wxmpPay([
  662. 'body' => "微信小程序购买模板",
  663. 'out_trade_no' => $payOn,
  664. 'total' => $payMoney,
  665. 'openid' => $request->user['openid'],
  666. 'payer_client_ip' => $clictip,
  667. ]);
  668. if(empty($payData)){
  669. Db::rollback();
  670. return app('json')->fail($wxpay->errorMsg);
  671. }
  672. Db::commit();
  673. $redis->delete($key);
  674. return app('json')->success([
  675. 'jsApiParameters'=> $payData,
  676. 'pay_no' => $payOn,
  677. 'order_id' => $save["order_id"],
  678. "status" => $save['status'],
  679. "money" => $payMoney,
  680. ]);
  681. } catch (DbException $db){
  682. Db::rollback();
  683. return app('json')->fail("订单生成失败");
  684. }
  685. }
  686. /**
  687. * 获取模板购买订单详情
  688. * @param Request $request
  689. */
  690. public function payShowTemplateOrderInfo(Request $request){
  691. [$order_id] = UtilService::getMore([
  692. ['order_id','','empty','参数错误'],
  693. ],$request,true);
  694. $data = (new ShowTemplateOrder)
  695. ->field("order_id,total_money,all_money,pay_money,status,time")
  696. ->where("order_id",$order_id)
  697. ->where("uid",$request->user["uid"])
  698. ->find();
  699. if(empty($data)){
  700. return app('json')->fail('信息不存在!');
  701. }
  702. $data=$data->toArray();
  703. if($data["status"]==0 && $data["time"]<time() - 30*60){
  704. (new ShowTemplateOrder)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
  705. $data["status"]==-1;
  706. }
  707. $data["time"] = date("Y-m-d H:i:s",$data["time"]);
  708. return app('json')->success($data);
  709. }
  710. /**
  711. * 用户模板列表
  712. * @param Request $request
  713. */
  714. public function userShowTemplateList(Request $request){
  715. $post = UtilService::getMore([
  716. ['page', 1],
  717. ['pageSize', 50],
  718. ], $request);
  719. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  720. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  721. $where=[];
  722. $where[]=["ut.uid","=",$request->user["uid"]];
  723. $totalCount = (new UserShowTemplate)->alias("ut")->where($where)->count();
  724. $data=null;
  725. if($totalCount>0){
  726. $data = (new UserShowTemplate)
  727. ->field("ut.id,t.id as show_template_id,t.title,t.price,t.old_price,t.status,t.imgs,t.is_hot,t.is_recommend,t.code,look_count,t.real_sales,t.unreal_sales,ut.is_default")
  728. ->alias("ut")
  729. ->join("show_template t", "t.id = ut.show_template_id","left")
  730. ->where($where)
  731. ->order("ut.is_default", "desc")
  732. ->order("ut.id", "desc")
  733. ->page($post["page"], $post["pageSize"])
  734. ->select();
  735. foreach($data as $k=>$v){
  736. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  737. $data[$k]["imgs"] = getImageAr($v["imgs"]);
  738. $data[$k]["img"] = empty($data[$k]["imgs"]) ? "" : $data[$k]["imgs"][0];
  739. $data[$k]["sales_count"] = $data[$k]["real_sales"] + $data[$k]["unreal_sales"];
  740. unset($data[$k]["real_sales"]);
  741. unset($data[$k]["unreal_sales"]);
  742. }
  743. }
  744. $data = empty($data)?[]:$data;
  745. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
  746. }
  747. /**
  748. * 设置默认模板
  749. * @param Request $request
  750. */
  751. public function setShowTemplate(Request $request) {
  752. [$show_template_id] = UtilService::getMore([
  753. ['show_template_id', '', 'empty', '参数错误'],
  754. ], $request, true);
  755. (new UserShowTemplate)->where("uid", $request->user["uid"])->where("is_default", 1)->update(["is_default" => 0]);
  756. (new UserShowTemplate)->where("uid", $request->user["uid"])->where("show_template_id", $show_template_id)->update(["is_default" => 1]);
  757. return app('json')->success("设置成功");
  758. }
  759. /**
  760. * 获取邀请海报小程序码
  761. * @param Request $request
  762. */
  763. public function getWxmpInviteQrcode(Request $request){
  764. $inviteData = (new SysModel)->getDataInfo("invite");
  765. $bgimg = $inviteData["img"];
  766. if(!empty($request->user["invite_img"])){
  767. return app('json')->success(["qrcode"=>$request->user["invite_img"],"bgimg"=>$bgimg]);
  768. }
  769. $weixinA = new weixina();
  770. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  771. $data = $weixinA->getUnlimitedQRCode("pages/index/index",$request->user["uid"]);
  772. // var_dump($data);
  773. if(empty($data)){
  774. return app('json')->fail("小程序码获取失败".$weixinA->error);
  775. }
  776. $base64 = 'data:'.$data['contentType'].';base64,'.base64_encode($data['buffer']);
  777. $res = $this->uploadImageBase64("wximg",$base64,1);
  778. if($res["code"]!=1){
  779. return app('json')->fail($res["msg"]);
  780. }
  781. (new UserModel)->where("uid",$request->user["uid"])->update(["invite_img"=>$res["url"]]);
  782. return app('json')->success(["qrcode"=>$res["url"],"bgimg"=>$bgimg]);
  783. }
  784. // public function getWxmpInviteQrcode2(Request $request){
  785. //
  786. // //获取小程序码
  787. // $weixinA = new weixina();
  788. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  789. // if(empty($data)){
  790. // return app('json')->fail("小程序码获取失败".$weixinA->error);
  791. // }
  792. // $base64 = 'data:'.$data['contentType'].';base64,'.base64_encode($data['buffer']);
  793. // $code = "temp";
  794. // $sysData = (new SysModel())->where("id",1)->find();
  795. // $uploadConfig = config('filesystem');
  796. // //验证base64格式
  797. // preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
  798. // if(!$result){
  799. // return ["code"=>-1,"msg"=>"base64格式格式错误"];
  800. // }
  801. // //验证图片后缀
  802. // if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
  803. // return ["code"=>-1,"msg"=>"不支持的图片格式"];
  804. // }
  805. // $rootPath = config('filesystem.disks.resource.root');
  806. // $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
  807. // $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
  808. // $path = dirname($filePath);
  809. // // 检测目录
  810. // if (!is_dir($path)) {
  811. // if (!mkdir($path, 0777, true)) {
  812. // return ["code"=>-1,"msg"=>"生成目录失败"];
  813. // }
  814. // return ["code"=>-1,"msg"=>"上传目录不存在"];
  815. // }
  816. // //重名文件验证
  817. // if (is_file($filePath)) {
  818. // return ["code"=>-1,"msg"=>"文件已存在"];
  819. // }
  820. // if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
  821. // return ["code"=>-1,"msg"=>"文件报错失败"];
  822. // }
  823. //
  824. // //获取海报背景
  825. // $inviteData = (new SysModel)->getDataInfo("invite");
  826. // if(empty($inviteData["img"])){
  827. // return ["code"=>-1,"msg"=>"海报背景不存在"];
  828. // }
  829. // $bgimg =explode("resource", $inviteData["img"])[1];
  830. // if(empty($bgimg)){
  831. // return ["code"=>-1,"msg"=>"海报背景不存在"];
  832. // }
  833. //
  834. // $savePath = $rootPath. DIRECTORY_SEPARATOR .$code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true))."b".".jpg";
  835. //
  836. //
  837. //
  838. //
  839. // $bg = $rootPath.$bgimg;
  840. // $bgSize = getimagesize($bg);
  841. // $qrcodeSize = getimagesize($filePath);
  842. // $handle = Image::open($bg);
  843. // $handle->water($filePath,[($bgSize[0]-$qrcodeSize[0])/2,($bgSize[1]-$qrcodeSize[1])/2]);
  844. // $handle->save($savePath,"jpg",80);
  845. // $qiniu = new Qiniu;
  846. // $img_url = $qiniu->updateFile('img', $savePath, $savePath);
  847. // if (empty($img_url['url'])) {
  848. // return ["code"=>-1,"msg"=>"文件报错失败:".$qiniu->getError()];
  849. // }
  850. // @unlink($filePath);
  851. // @unlink($savePath);
  852. // return ["code"=>1,"url"=>str_replace("\\", "/", $img_url['url'])];
  853. // }
  854. //
  855. // public function checkImgPath(){
  856. //
  857. // }
  858. /**
  859. * 图片合成
  860. * @param type $bg
  861. * @param type $qrcode
  862. * @param type $savePath
  863. */
  864. public function createPosterImg($bg,$qrcode,$savePath){
  865. }
  866. /**
  867. * 获取小程序码
  868. * @param Request $request
  869. */
  870. public function getWxmpQrcode(Request $request){
  871. $weixinA = new weixina();
  872. $data = $weixinA->getUnlimitedQRCode("pages/index/index","a=1");
  873. if(empty($data)){
  874. return app('json')->fail("小程序码获取失败".$weixinA->error);
  875. }
  876. $base64 = 'data:'.$data['contentType'].';base64,'.base64_encode($data['buffer']);
  877. $res = $this->uploadImageBase64("wximg",$base64);
  878. if($res["code"]!=1){
  879. return app('json')->fail($res["msg"]);
  880. }
  881. return app('json')->success(["img"=>$res["data"]]);
  882. }
  883. /**
  884. *
  885. * @param Request $request
  886. */
  887. public function uploadBase64(Request $request){
  888. [$img,$code] = UtilService::getMore([
  889. ['img', '','empty',"请上传图片"],
  890. ['code', 'image'],
  891. ], $request,true);
  892. // $imgAr = explode("base64,",$img);
  893. // if(empty($imgAr)){
  894. // return app("json")->fail("请上传base64图片");
  895. // }
  896. // $imgBase64 = count($imgAr)==1?$imgAr[0]:$imgAr[1];
  897. // //判断字符串是否经过编码方法
  898. // if($imgBase64!=base64_encode(base64_decode($imgBase64))){
  899. // return app("json")->fail("请上传base64图片");
  900. // }
  901. // $base64 = "data:application/octet-stream;base64,".$imgBase64;//七牛
  902. $res = $this->uploadImageBase64($code,$img);
  903. if($res["code"]!=1){
  904. return app('json')->fail($res["msg"]);
  905. }
  906. return app('json')->success(["img"=>$res["data"]]);
  907. }
  908. /**
  909. * 图片上传
  910. * @param Request $request
  911. * @return type
  912. */
  913. public function upload(Request $request){
  914. $uploadConfig = config('filesystem');
  915. $sysData = (new SysModel())->where("id",1)->find();
  916. $file = $request->file('file');
  917. $code = $request->post("code","image");
  918. if(empty($file)) {
  919. return app('json')->fail("未上传文件");
  920. }
  921. $size = $file->getSize();
  922. if(!empty($size) && $size>$uploadConfig["image"]["size"]*1024*1024){
  923. return app('json')->fail("图片不能超过{$uploadConfig["image"]["size"]}M");
  924. }
  925. if(!in_array($code, $uploadConfig['image']['path'])){
  926. return app('json')->fail("上传路径错误");
  927. }
  928. $ext = $file->extension();
  929. if(!in_array($ext, $uploadConfig['image']['ext'])){
  930. return app('json')->fail("图片类型错误");
  931. }
  932. $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
  933. if(!$upPath){
  934. return app('json')->fail("上传失败01");
  935. }
  936. $savePath = $sysData['system_url'].'/resource/' . $upPath;
  937. $imgUrl = str_replace("\\", "/", $savePath);
  938. return app('json')->success(['img'=>$imgUrl,'size'=>$size]);
  939. }
  940. /**
  941. * 视频上传
  942. * @param Request $request
  943. * @return type
  944. */
  945. public function uploadVideo(Request $request){
  946. $uploadConfig = config('filesystem');
  947. $sysData = (new SysModel())->where("id",1)->find();
  948. $file = $request->file('file');
  949. $code = $request->post("code","video");
  950. if(empty($file)) {
  951. return app('json')->fail("未上传文件");
  952. }
  953. if(!in_array($code, $uploadConfig['video']['path'])){
  954. return app('json')->fail("上传路径错误");
  955. }
  956. $ext = $file->extension();
  957. if(!in_array($ext, $uploadConfig['video']['ext'])){
  958. return app('json')->fail("视频类型错误");
  959. }
  960. $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
  961. if(!$upPath){
  962. return app('json')->fail("上传失败01");
  963. }
  964. $savePath = $sysData['system_url'].'/resource/' . $upPath;
  965. $imgUrl = str_replace("\\", "/", $savePath);
  966. return app('json')->success(['video'=>$imgUrl]);
  967. }
  968. /**
  969. * base64文件上传
  970. * @param type $code
  971. * @param type $base64
  972. */
  973. public function uploadImageBase64($code,$base64,$isQiniu=0){
  974. $sysData = (new SysModel())->where("id",1)->find();
  975. $uploadConfig = config('filesystem');
  976. //验证base64格式
  977. preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
  978. if(!$result){
  979. return ["code"=>-1,"msg"=>"base64格式格式错误"];
  980. }
  981. //验证图片后缀
  982. if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
  983. return ["code"=>-1,"msg"=>"不支持的图片格式"];
  984. }
  985. $rootPath = config('filesystem.disks.resource.root');
  986. $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
  987. $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
  988. $path = dirname($filePath);
  989. // 检测目录
  990. if (!is_dir($path)) {
  991. if (!mkdir($path, 0777, true)) {
  992. return ["code"=>-1,"msg"=>"生成目录失败"];
  993. }
  994. return ["code"=>-1,"msg"=>"上传目录不存在"];
  995. }
  996. //重名文件验证
  997. if (is_file($filePath)) {
  998. return ["code"=>-1,"msg"=>"文件已存在"];
  999. }
  1000. if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
  1001. return ["code"=>-1,"msg"=>"文件报错失败"];
  1002. }
  1003. //七牛上传
  1004. if($isQiniu==1){
  1005. $qiniu = new Qiniu;
  1006. $img_url = $qiniu->updateFile('img', $filePath, $filePath);
  1007. if (empty($img_url['url'])) {
  1008. return ["code"=>-1,"msg"=>"文件报错失败:".$qiniu->getError()];
  1009. }
  1010. @unlink($filePath);
  1011. return ["code"=>1,"url"=>str_replace("\\", "/", $img_url['url'])];
  1012. }
  1013. $savePath = $sysData['system_url'].config('filesystem.disks.resource.url').DIRECTORY_SEPARATOR.$hashName;
  1014. return ["code"=>1,"url"=>str_replace("\\", "/", $savePath)];
  1015. }
  1016. /**
  1017. * 七牛上传图片
  1018. * @param Request $request
  1019. */
  1020. public function qiniuUpload(Request $request)
  1021. {
  1022. $file = $request->file('file');
  1023. if (empty($file)) {
  1024. return app('json')->fail("未上传文件");
  1025. }
  1026. $rootTmp = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
  1027. $image_size = @getimagesize($rootTmp);
  1028. if ($image_size[0] > 1000) {
  1029. $imgS = Image::open($rootTmp);
  1030. $imgS->thumb(1000, $image_size[1]);
  1031. $imgS->save($rootTmp);
  1032. } else {
  1033. if ($image_size[1] > 1000) {
  1034. $imgS = Image::open($rootTmp);
  1035. $imgS->thumb($image_size[0], 1000);
  1036. $imgS->save($rootTmp);
  1037. }
  1038. }
  1039. $qiniu = new Qiniu;
  1040. $img_url = $qiniu->updateFile('img', $rootTmp, $rootTmp);
  1041. if (empty($img_url['url'])) {
  1042. return app('json')->fail($qiniu->getError());
  1043. }
  1044. @unlink($rootTmp);
  1045. return app('json')->success(['img' => $img_url['url']]);
  1046. }
  1047. /**
  1048. * 七牛上传token
  1049. * @param Request $request
  1050. */
  1051. public function qiniuUploadToken(Request $request){
  1052. [$bucket] = UtilService::getMore([
  1053. ['bucket', ''],
  1054. ], $request,true);
  1055. $qiniu = new Qiniu;
  1056. $token = $qiniu->createUploadToken($bucket);
  1057. return app('json')->success(['token' => $token]);
  1058. }
  1059. /**
  1060. * 获取用户总邀请人数
  1061. * @param int $uid 用户ID
  1062. * @return int 总邀请人数
  1063. */
  1064. public function getTotalInvites($uid)
  1065. {
  1066. return (new UserModel)->where('parent_uid', $uid)->count();
  1067. }
  1068. }