User.php 44 KB

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