User.php 44 KB

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