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