User.php 45 KB

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