User.php 44 KB

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