User.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  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\ContractComment as ContractCommentModel;
  15. use app\model\api\ContractRecord as UserContractRecordModel;
  16. use app\model\api\ContractTemplate;
  17. use app\model\api\LikeBookmark;
  18. use app\model\api\User as UserModel;
  19. use app\model\api\UserClock as UserClockModel;
  20. use app\model\api\UserDetail as UserDetailModel;
  21. use app\model\api\ServiceType as ServiceTypeModel;
  22. use app\model\api\InfoAudit;
  23. use app\model\api\TypeAudit;
  24. use app\model\api\UserAudit;
  25. use app\model\api\ServiceType;
  26. use app\model\api\ServiceLabel as ServiceLabelModel;
  27. use app\model\api\ServiceTimeType;
  28. use app\model\api\City as CityModel;
  29. use app\model\api\Sys as SysModel;
  30. use app\model\api\ShowTemplate;
  31. use app\model\api\ShowTemplateOrder;
  32. use app\model\api\UserScoreDetail;
  33. use app\model\api\UserShowTemplate;
  34. use app\model\api\UserWorkType;
  35. use app\model\api\PayTrade as PayTradeModel;
  36. use app\api\controller\pub;
  37. use app\Request;
  38. use library\services\UtilService;
  39. use library\utils\QRcodeComm;
  40. use library\utils\Qiniu;
  41. use library\utils\IdentityCard;
  42. use library\utils\WxpayV2 as wxpayApi;
  43. use think\db\exception\DbException;
  44. use library\lib\weixina;
  45. use think\facade\Db;
  46. use think\Image;
  47. use think\Route;
  48. use think\Collection;
  49. class User extends BaseController
  50. {
  51. /**
  52. * 获取用户详情
  53. * @param Request $request
  54. */
  55. public function userInfo(Request $request)
  56. {
  57. //资料审核信息
  58. $infoAuditData = (new InfoAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  59. $userAuditData = (new UserAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  60. $typeAuditData = (new TypeAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  61. $data = [];
  62. $data['uid'] = $request->user['uid'];
  63. $data['nickname'] = $request->user['nickname'];
  64. $data['mobile'] = $request->user['mobile'];
  65. $data['avatar'] = $request->user['avatar'];
  66. $data['name'] = $request->user['name'];
  67. $data['sex'] = $request->user['sex'];
  68. $data['type'] = $request->user['type'];//用户类型
  69. $data['type_name'] = "";//用户类型名称
  70. $data['work_type_id'] = $request->user['work_type_id'];//用户职称类型
  71. $data['work_type_title'] = $request->user['work_type_title'];//用户职称类型名称
  72. $data['card_look_count'] = $request->user['card_look_count'];//用户名片浏览次数
  73. $data['bookmark_count'] = $request->user['bookmark_count'];//收藏数量
  74. $data['info_audit_status'] = empty($infoAuditData) ? -2 : $infoAuditData["status"];
  75. $data['user_audit_status'] = empty($userAuditData) ? -2 : $userAuditData["status"];
  76. $data['type_audit_status'] = empty($typeAuditData) ? -2 : $typeAuditData["status"];
  77. //资料通过需要重新提交认证
  78. if (!empty($infoAuditData) && !empty($typeAuditData)) {
  79. if ($infoAuditData["status"] == 1 && $typeAuditData["status"] == 1 && $infoAuditData["admin_time"] > $typeAuditData["admin_time"]) {
  80. $data['type_audit_status'] = -3;
  81. }
  82. }
  83. $data['show_template_code'] = "";
  84. $data['show_template_id'] = "";
  85. $tmpData = (new UserShowTemplate)
  86. ->field("t.id,t.code,t.title,t.is_init,b.is_default")
  87. ->alias("b")
  88. ->join("show_template t", "t.id = b.show_template_id", "left")
  89. ->where("b.uid", $request->user['uid'])
  90. ->order("b.is_default", "desc")
  91. ->order("b.id", "desc")
  92. ->find();
  93. if (!empty($tmpData)) {
  94. $data['show_template_code'] = $tmpData["code"];
  95. $data['show_template_id'] = $tmpData["id"];
  96. $data['show_template_init'] = $tmpData["is_init"];
  97. $data['show_template_default'] = $tmpData["is_default"];
  98. }
  99. return app('json')->success($data);
  100. }
  101. /**
  102. * 获取用户子级列表
  103. * @param Request $request
  104. */
  105. public function getChildList(Request $request)
  106. {
  107. $post = UtilService::getMore([
  108. ['page', 1],
  109. ['pageSize', 50],
  110. ], $request);
  111. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  112. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  113. $post["parent_uid"] = $request->user["uid"];
  114. $data = (new UserModel)->getDataList($post, "u.uid,u.mobile,u.nickname,u.avatar");
  115. $list = $data["list"];
  116. foreach ($list as &$item) {
  117. $userInfo = $this->getUserInfo($item["uid"]);
  118. $item["is_type_audit"] = $userInfo["is_type_audit"];
  119. $item["ancestral_place"] = $userInfo["ancestral_place"];
  120. $item["auth_info"] = $userInfo["auth_info"];
  121. $item["user_work_type_id"] = $userInfo["user_work_type_id"];
  122. }
  123. $data["list"] = $list;
  124. return app('json')->success($data);
  125. }
  126. /**
  127. * 获取用户总邀请人数排行榜
  128. * @param Request $request
  129. */
  130. public function getInviterRanking(Request $request)
  131. {
  132. $time = $request->param('time');
  133. $times = $request->param('times');
  134. $users = (new UserModel())
  135. ->where('parent_uid', '<>', 0)
  136. ->where('regtime', '>=', $time)
  137. ->where('regtime', '<=', $times)
  138. ->field('parent_uid as uid, count(*) as invite_count')
  139. ->group('parent_uid')
  140. ->order('invite_count', 'desc')
  141. ->select();
  142. $rankList = [];
  143. foreach ($users as $key => $value) {
  144. $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
  145. if (!$userInfo['nickname']) {
  146. continue;
  147. }
  148. $auth = (new InfoAudit)->where('uid', $value['uid'])->find();
  149. $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
  150. if ($auth) {
  151. $auth_info = $auth->toArray();
  152. } else {
  153. $auth_info = null;
  154. }
  155. $rankList[] = [
  156. 'rank' => $key + 1,
  157. 'uid' => $value['uid'],
  158. 'nickname' => $userInfo['nickname'],
  159. 'avatar' => $userInfo['avatar'],
  160. 'invite_count' => $value['invite_count'],
  161. 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
  162. 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
  163. 'auth_info' => $auth_info,
  164. 'user_work_type_id' => $user_work_type_title['title'],
  165. ];
  166. }
  167. $inviteCount = array_column($rankList, 'invite_count');
  168. $uid = array_column($rankList, 'uid');
  169. array_multisort($inviteCount, SORT_DESC, $uid, SORT_ASC, $rankList);
  170. $data['list'] = $rankList;
  171. return app('json')->success($data);
  172. }
  173. /**
  174. * 设置用户信息
  175. * @param Request $request
  176. */
  177. public function setUserInfo(Request $request)
  178. {
  179. $post = UtilService::getMore([
  180. ['avatar', ''],
  181. ['nickname', ''],
  182. ['name', ''],
  183. // ['mobile',''],
  184. ['sex', ''],
  185. ], $request);
  186. $save = [];
  187. if (!empty($post["avatar"])) {
  188. $save["avatar"] = $post["avatar"];
  189. }
  190. if (!empty($post["nickname"])) {
  191. $save["nickname"] = $post["nickname"];
  192. }
  193. if (!empty($post["name"])) {
  194. $save["name"] = $post["name"];
  195. }
  196. // if(!empty($post["mobile"])){
  197. // if(is_mobile($post["mobile"])){
  198. // return app("json")->fail("请输入正确的手机号码");
  199. // }
  200. // $save["mobile"] = $post["mobile"];
  201. // }
  202. if (in_array((string)$post["sex"], ["0", "1", "2"])) {
  203. $save["sex"] = (int)$post["sex"];
  204. }
  205. if (empty($save)) {
  206. return app("json")->fail("提交数据为空");
  207. }
  208. //是否需要审核
  209. $isInfoAudit = 0;
  210. if ($isInfoAudit == 0) {
  211. $r = (new UserModel)->where("uid", $request->user["uid"])->update($save);
  212. if (!$r) {
  213. return app("json")->fail("提交数据为空");
  214. }
  215. } else {
  216. $data = (new UserAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  217. if (!empty($data) && $data["status"] == 0) {
  218. return app('json')->fail("资料审核中,请勿重复提交");
  219. }
  220. $save["uid"] = $request->user["uid"];
  221. $save["status"] = 0;
  222. $r = (new UserAudit)->insert($save);
  223. if (!$r) {
  224. return app("json")->fail("提交数据为空");
  225. }
  226. }
  227. return app("json")->success("提交成功");
  228. }
  229. /**
  230. * 绑定手机号
  231. * @param Request $request
  232. */
  233. public function bindMobile(Request $request)
  234. {
  235. [$code] = UtilService::getMore([
  236. ['code', '', 'empty', 'code参数错误'],
  237. ], $request, true);
  238. if (!empty($request->user['mobile'])) {
  239. return app('json')->fail("当前账户已绑定过手机号码");
  240. }
  241. $weixinA = new weixina();
  242. $data = $weixinA->getPhoneNumber($code);//新版
  243. if (empty($data) || empty($data['purePhoneNumber'])) {
  244. return app('json')->fail("绑定失败,请重新绑定01" . $weixinA->error);
  245. }
  246. $save = [
  247. // "countryCode"=>empty($data['countryCode'])?"":$data['countryCode'],
  248. "mobile" => $data['purePhoneNumber'],
  249. ];
  250. // if($request->user["nickname"]=="微信用户"){
  251. // $save["nickname"] = $data['purePhoneNumber'];
  252. // }
  253. $r = (new UserModel)->where('uid', $request->user['uid'])->update($save);
  254. if (!$r) {
  255. return app('json')->fail("绑定失败,请重新绑定02");
  256. }
  257. $result = [];
  258. $result['nickname'] = $request->user['nickname'];
  259. $result['avatar'] = $request->user['avatar'];
  260. return app('json')->success($result);
  261. }
  262. /**
  263. * 获取名片信息
  264. * @param Request $request
  265. */
  266. public function getUserCardInfo(Request $request)
  267. {
  268. $data = (new InfoAudit)->getItem(["uid" => $request->user["uid"], "status" => 1]);
  269. if (empty($data)) {
  270. return app('json')->fail("您还没有通过名片信息审核");
  271. }
  272. $typeData = (new TypeAudit)->where("uid", $request->user["uid"])->order("id", "desc")->find();
  273. $data["is_type_audit"] = (empty($typeData) || $typeData["status"] != 1) ? 0 : 1;
  274. return app('json')->success($data);
  275. }
  276. /**
  277. * 提交资料审核
  278. * @param Request $request
  279. */
  280. public function subInfoAudit(Request $request)
  281. {
  282. $data = (new InfoAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  283. if (!empty($data) && $data["status"] == 0) {
  284. return app('json')->fail("资料审核中,请勿重复提交");
  285. }
  286. $post = UtilService::getMore([
  287. ['avatar', ''],
  288. ['name', '', 'empty', '请输入真实姓名'],
  289. ['mobile', '', 'is_moblie', '请输入正确的手机号码'],
  290. ['idcard', '', 'empty', '请输入正确的身份证号码'],
  291. ['birthday', ''],
  292. ['service_type', ''],
  293. ['service_price', ''],
  294. ['service_min_price', ''],
  295. ['service_max_price', ''],
  296. ['service_area', []],
  297. ['service_project', []],
  298. ['service_intro_content', ''],
  299. ['service_intro_imgs', []],
  300. ['service_audit_imgs', []],//此处为我的证书
  301. ['service_imgs', []],//我的服务照片
  302. ['model_imgs', []],//我的服务照片
  303. ['service_count', 0],
  304. ['work_year', ''],
  305. ['ancestral_place', ''],
  306. ['education', ''],
  307. ['weight', 0],
  308. ['height', 0],
  309. ['minority', ''],
  310. ['is_china', 1],
  311. ['is_global', 0],
  312. ['modelType', 0],
  313. ['user_work_type_id', '0'],//服务职称
  314. ['service_label', []],//服务标签
  315. ], $request);
  316. if (!IdentityCard::isValid($post["idcard"])) {
  317. return app('json')->fail("请输入正确的身份证号码");
  318. }
  319. $save = [];
  320. $save["avatar"] = empty($post["avatar"]) ? "" : $post["avatar"];
  321. $save["name"] = empty($post["name"]) ? "" : $post["name"];
  322. $save["mobile"] = empty($post["mobile"]) ? "" : $post["mobile"];
  323. $save["idcard"] = empty($post["idcard"]) ? "" : $post["idcard"];
  324. $save["weight"] = empty($post["weight"]) ? 0 : $post["weight"];
  325. $save["height"] = empty($post["height"]) ? 0 : $post["height"];
  326. $save["service_count"] = $post['service_count'];
  327. // $save["birthday"] = empty($post["birthday"])? 0 : strtotime($post["birthday"]);
  328. $save["constellation"] = IdentityCard::get_starsign($post["idcard"]);//星座
  329. $save["twelve"] = IdentityCard::get_zodiac($post["idcard"]);//星座
  330. $save["birthday"] = strtotime(IdentityCard::get_birthday($post["idcard"]));
  331. //服务类型
  332. if (!empty($post["service_type"])) {
  333. $timeTypeData = (new ServiceTimeType)->where("code", $post["service_type"])->where("status", 1)->select();
  334. if (empty($timeTypeData)) {
  335. return app('json')->fail("服务时长类型不存在");
  336. }
  337. $save["service_type"] = $post["service_type"];
  338. }
  339. //服务价格区间
  340. // $save["service_price"] = empty($post["service_price"]) ? "" : $post["service_price"];
  341. $save["service_min_price"] = empty($post["service_min_price"]) ? 0 : $post["service_min_price"];
  342. $save["service_max_price"] = empty($post["service_max_price"]) ? 0 : $post["service_max_price"];
  343. //服务区域
  344. $cityModel = new CityModel();
  345. if (!empty($post["service_area"]) && is_array($post["service_area"])) {
  346. $saveAre = [];
  347. foreach ($post["service_area"] as $v) {
  348. $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
  349. $str = str_replace(['辖'], ['市辖'], $stc);
  350. $arr = explode(",", $str);
  351. $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
  352. if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
  353. $saveAre[] = $city_id;
  354. }
  355. if (!empty($saveAre)) {
  356. $save["service_area"] = implode(",", $saveAre);
  357. }
  358. }
  359. // //服务区域
  360. // $cityModel = new CityModel();
  361. // if(!empty($post["service_area"]) && is_array($post["service_area"])){
  362. // $saveAre=[];
  363. // foreach($post["service_area"] as $v){
  364. // @file_put_contents('dub.txt','1');
  365. // $arr = explode(",",$v);
  366. // $str1 = $arr[0].','.$arr[1];
  367. // @file_put_contents('dub.txt','2');
  368. // $stc = str_replace(['省','市','区','县'],['','','',''],$str1);
  369. // $str2 = $stc.",".$arr[2]!='市辖区'?str_replace(['省','市','区','县'],['','','',''],$arr[2]):'市辖区';
  370. // $arr3 = explode(",",$str2);
  371. // $city_id = $cityModel->where('merger_name','like',"%".$arr3[1].",".$arr3[2])->value('id');
  372. // @file_put_contents('dub.txt','3');
  373. // if(!$city_id)
  374. // {
  375. // $city_id = $cityModel->where('merger_name','like',"%".$arr3[0].",".$arr3[1])->value('id');
  376. // $city_id1 = $cityModel->where('merger_name','like',"%".$arr3[0].",".$arr3[1])->value('city_id');
  377. // $city_id2 = $cityModel->where('parent_id',$city_id1)->where('name','市辖区')->value('id');
  378. // if($city_id2>0) $city_id= $city_id2;
  379. // }
  380. // @file_put_contents('dub.txt','4');
  381. // $saveAre[] = $city_id;
  382. //
  383. // }
  384. // if(!empty($saveAre)){
  385. // $save["service_area"] = implode(",", $saveAre);
  386. // }
  387. // }
  388. //服务内容
  389. $serviceTypeModel = new ServiceTypeModel();
  390. if (!empty($post["service_project"]) && is_array($post["service_project"])) {
  391. $saveCon = [];
  392. foreach ($post["service_project"] as $k => $v) {
  393. if (empty(trim($v))) {
  394. continue;
  395. }
  396. $itemData = $serviceTypeModel->where("id", (int)$v)->where("status", 1)->find();
  397. if (!empty($itemData)) {
  398. $saveCon[] = $itemData["id"];
  399. }
  400. }
  401. if (!empty($saveCon)) {
  402. $save["service_project"] = implode(",", $saveCon);
  403. }
  404. }
  405. //服务标签
  406. $save["service_label"] = "";
  407. $labelData = (new ServiceLabelModel)->getColumnList("id", "id", $post["service_label"]);
  408. if (!empty($labelData)) {
  409. $save["service_label"] = implode(",", $labelData);
  410. }
  411. $save["service_intro_content"] = empty($post["service_intro_content"]) ? "" : $post["service_intro_content"];
  412. $save["service_intro_imgs"] = empty($post["service_intro_imgs"]) ? "" : implode(",", $post["service_intro_imgs"]);
  413. $save["service_audit_imgs"] = empty($post["service_audit_imgs"]) ? "" : implode(",", $post["service_audit_imgs"]);
  414. $save["service_imgs"] = empty($post["service_imgs"]) ? "" : implode(",", $post["service_imgs"]);//我的服务展示
  415. $save["model_imgs"] = empty($post["model_imgs"]) ? "" : implode(",", $post["model_imgs"]);//我的服务展示
  416. $save['work_year'] = empty($post["work_year"]) ? "" : $post["work_year"];
  417. $save['ancestral_place'] = empty($post["ancestral_place"]) ? "" : $post["ancestral_place"];
  418. $save['education'] = empty($post["education"]) ? "" : $post["education"];
  419. $save['minority'] = empty($post["minority"]) ? "" : $post["minority"];
  420. $save["status"] = 1;
  421. $save["time"] = time();
  422. $save["uid"] = $request->user["uid"];
  423. $save['is_china'] = $post["is_china"];
  424. $save['is_global'] = $post["is_global"];
  425. $save['modelType'] = $post["modelType"];
  426. //服务职称
  427. $save["user_work_type_id"] = empty($post["user_work_type_id"]) ? 0 : (int)$post["user_work_type_id"];
  428. if ($save["user_work_type_id"] > 0 && (new UserWorkType)->where("id", $post["user_work_type_id"])->where("status", 1)->count() <= 0) {
  429. return app('json')->fail("当前类型不能选择");
  430. }
  431. //生成编码
  432. $r = (new InfoAudit)->insertGetId($save);
  433. if (!$r) {
  434. return app('json')->fail("系统错误");
  435. }
  436. $exist = (new InfoAudit)->where('uid', $save['uid'])->find();
  437. if ($exist && !empty($exist['no'])) {
  438. $no = $exist['no'];
  439. } else {
  440. $id = str_pad($r, 5, "0", STR_PAD_LEFT);
  441. $no = "MYJ" . date("ym") . $id;
  442. }
  443. (new InfoAudit)->where("id", $r)->update(["no" => $no]);
  444. (new InfoAudit)->where("id", $r)->update(["status" => 1]);
  445. (new UserModel)->where("uid", $save["uid"])->update(["work_type_id" => $save["user_work_type_id"]]);
  446. //绑定初始化模板
  447. (new UserShowTemplate)->userBindTempInit($save["uid"]);
  448. //删除以前的资料
  449. (new InfoAudit)->where('uid', $save['uid'])->where("id", "<>", $r)->delete();
  450. $first = (new InfoAudit)->where('uid', $save['uid'])->value('first');
  451. if ($first==0){
  452. (new UserModel())->where("uid",$save["uid"])->update(["first"=>1]);
  453. $parent_uid = (new UserModel)->where("uid", $save["uid"])->value("parent_uid");
  454. if ($parent_uid>0){
  455. (new UserScoreDetail())->incomeScore($parent_uid,10,'',"subInfo_score",[],$save["uid"]);
  456. }
  457. }
  458. return app('json')->success("提交成功,数据已通过审核");
  459. }
  460. /**
  461. * 平台认证
  462. * @param Request $request
  463. */
  464. public function subTypeAudit(Request $request)
  465. {
  466. $data = (new TypeAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  467. if (!empty($data) && $data["status"] == 0) {
  468. return app('json')->fail("平台审核中,请勿重复提交");
  469. }
  470. $post = UtilService::getMore([
  471. ['service_audit_imgs', [], "empty", "请上传服务认证截图"],
  472. ['store_name', '', '', ''],
  473. ], $request);
  474. $save = [];
  475. $save["service_audit_imgs"] = is_array($post["service_audit_imgs"]) ? implode(",", $post["service_audit_imgs"]) : "";
  476. $save["store_name"] = empty($post["store_name"]) ? "" : $post["store_name"];
  477. $save["status"] = 0;
  478. $save["time"] = time();
  479. $save["uid"] = $request->user["uid"];
  480. if (empty($save["service_audit_imgs"])) {
  481. return app('json')->fail("请上传服务认证截图");
  482. }
  483. $r = (new TypeAudit)->insertGetId($save);
  484. if (!$r) {
  485. return app('json')->fail("系统错误");
  486. }
  487. $no = "CERT-" . date("YmdHis") . "-" . $r;
  488. (new TypeAudit)->where("id", $r)->update(["no" => $no]);
  489. return app('json')->success("提交成功,请耐心等待审核");
  490. }
  491. /**
  492. * 模板订单提交[第一步]
  493. * @param Request $request
  494. */
  495. public function subShowTemplateOrder(Request $request)
  496. {
  497. [$id, $pay_type] = UtilService::getMore([
  498. ['id', '', 'empty', '参数错误'],
  499. ['pay_type', '', 'empty', '请选择支付方式'],
  500. ], $request, true);
  501. if (!in_array($pay_type, ["wxpay", "balance"])) {
  502. return app('json')->fail('不支持该支付方式!');
  503. }
  504. $weixinConfig = (new SysModel)->getWeixinConfig();
  505. // if(empty($weixinConfig)){
  506. // return app('json')->fail('支付配置为空!');
  507. // }
  508. //缓存
  509. $redis = \think\facade\Cache::store('redis');
  510. $key = 'show_template_order_sub_' . $request->user['uid'];
  511. $bool = $redis->handler()->exists($key);
  512. if ($bool) {
  513. return app('json')->fail('请务重复操作,请稍等在重试!');
  514. }
  515. $redis->set($key, 1, 5);//5秒缓存
  516. $proData = (new ShowTemplate)->where("id", $id)->where("status", 1)->find();
  517. if (empty($proData)) {
  518. return app('json')->fail("当前模板已下架");
  519. }
  520. $proData = $proData->toArray();
  521. $count = (new UserShowTemplate)->where("uid", $request->user['uid'])->where("show_template_id", $id)->count();
  522. if ($count > 0) {
  523. return app('json')->fail("您已购买过当前模板");
  524. }
  525. //验证
  526. $orderCount = (new ShowTemplateOrder)->where("uid", $request->user['uid'])->where("show_template_id", $id)->where("status", 1)->count();
  527. if ($orderCount > 0) {
  528. return app('json')->fail("您已下单该模板,请勿重复下单");
  529. }
  530. $price = floatval($proData["price"]);
  531. // if($price<0.01){
  532. // return app('json')->fail("模板信息错误");
  533. // }
  534. $allMoney = $price;//订单商品费用
  535. $total_money = $allMoney;//订单总费用
  536. $payMoney = $total_money;//订单需支付费用
  537. $payMoney = $payMoney <= 0 ? 0 : $payMoney;
  538. $nowTime = time();
  539. //余额支付验证
  540. if ($pay_type == "balance" && $payMoney > $request->user["money"]) {
  541. return app('json')->fail("当前余额不足");
  542. }
  543. //主订单数据
  544. $save = [];
  545. $save['uid'] = $request->user['uid'];
  546. $save['order_id'] = makeOrderId($request->user['uid'], "ST");
  547. $save['pay_type'] = $pay_type;//
  548. $save['total_money'] = $total_money;//订单总金额
  549. $save['all_money'] = $allMoney;//商品中金额
  550. $save['pay_money'] = $payMoney;//实际支付金额
  551. $save['balance'] = 0;//余额支付了多少(目前不用)
  552. $save['status'] = $payMoney <= 0 ? 1 : 0;
  553. $save['pay_time'] = $payMoney <= 0 ? time() : 0;
  554. $save['time'] = $nowTime;
  555. $save['show_template_id'] = $proData["id"];
  556. $save['show_template_title'] = $proData["title"];;
  557. $save['show_template_price'] = $proData["price"];
  558. $save['show_template_img'] = empty($proData["imgs"]) ? "" : explode(",", $proData["imgs"])[0];
  559. $save['show_template_code'] = $proData["code"];
  560. //余额实时支付
  561. if ($pay_type == "balance") {
  562. $save['status'] = 1;
  563. $save['pay_time'] = time();
  564. }
  565. try {
  566. Db::startTrans();
  567. $o_id = (new ShowTemplateOrder)->insertGetId($save);
  568. if (empty($o_id)) {
  569. return app('json')->fail("订单提交失败");
  570. }
  571. //不需要支付
  572. if ($payMoney <= 0 && $save['status'] == 1) {
  573. //验证并绑定当前模板
  574. (new UserShowTemplate)->userBindTemp($save["show_template_id"], $save['uid']);
  575. Db::commit();
  576. return app("json")->success(["order_id" => $save['order_id'], "money" => $payMoney, "status" => $save['status']]);
  577. }
  578. //余额支付
  579. if ($pay_type == "balance") {
  580. //验证并绑定当前模板
  581. (new UserShowTemplate)->userBindTemp($save["show_template_id"], $save['uid']);
  582. //修改用户余额
  583. $res = (new UserDetailModel)->balancePay($request->user["uid"], $payMoney, "show_temp_pay", ["to_id" => $o_id]);
  584. if (!$res) {
  585. Db::rollback();
  586. return app('json')->fail("余额支付失败");
  587. }
  588. Db::commit();
  589. return app("json")->success(["order_id" => $save['order_id'], "money" => $payMoney, "status" => $save['status']]);
  590. }
  591. //微信支付
  592. if (empty($request->user['openid'])) {
  593. Db::rollback();
  594. return app('json')->fail('用户还未绑定微信!');
  595. }
  596. //清理之前支付凭证 || 防止重复购买
  597. $payTrade = (new PayTradeModel)
  598. ->where("uid", $request->user["uid"])
  599. ->where("o_id", $o_id)
  600. ->where("type", "temp")
  601. ->where("status", 0)
  602. ->where("time", "<", time() - 7 * 24 * 60 * 60)
  603. ->select()
  604. ->toArray();
  605. $wxpay = new wxpayApi();
  606. // $wxpay = new wxpayApi($weixinConfig);
  607. foreach ($payTrade as $v) {
  608. // if($v['pay_type'] == 'wxpay') {
  609. // $result = $wxpay->closeOrder($v['pay_no']);
  610. // }
  611. (new PayTradeModel)->where("id", $v['id'])->where("status", 0)->delete();
  612. }
  613. $mtime = microtime(true) * 10000;
  614. $payOn = "T" . date("Ymd") . $mtime . rand(100, 999) . $request->user['uid'];
  615. $out_trade_no = "";
  616. $payType = $save["pay_type"];
  617. //添加交易记录
  618. $trade = [
  619. 'uid' => $request->user['uid'],
  620. 'o_id' => $o_id,
  621. 'order_id' => $save["order_id"],
  622. 'pay_no' => $payOn,
  623. 'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
  624. 'pay_type' => $payType,
  625. 'money' => $payMoney,
  626. 'type' => 'temp',
  627. 'd_json' => serialize(['orderId' => $save["order_id"], "give_score" => 0]),
  628. 'time' => time(),
  629. 'status' => 0,
  630. ];
  631. $r = (new PayTradeModel)->insert($trade);
  632. if (!$r) {
  633. Db::rollback();
  634. return app('json')->fail('支付信息获取失败!');
  635. }
  636. $clictip = get_client_ip();
  637. if (empty($clictip)) {
  638. $clictip = $request->ip();
  639. }
  640. $payData = $wxpay->wxmpPay([
  641. 'body' => "微信小程序购买模板",
  642. 'out_trade_no' => $payOn,
  643. 'total' => $payMoney,
  644. 'openid' => $request->user['openid'],
  645. 'payer_client_ip' => $clictip,
  646. ]);
  647. if (empty($payData)) {
  648. Db::rollback();
  649. return app('json')->fail($wxpay->errorMsg);
  650. }
  651. Db::commit();
  652. $redis->delete($key);
  653. return app('json')->success([
  654. 'jsApiParameters' => $payData,
  655. 'pay_no' => $payOn,
  656. 'order_id' => $save["order_id"],
  657. "status" => $save['status'],
  658. "money" => $payMoney,
  659. ]);
  660. } catch (DbException $db) {
  661. Db::rollback();
  662. return app('json')->fail("订单生成失败");
  663. }
  664. }
  665. /**
  666. * 获取模板购买订单详情
  667. * @param Request $request
  668. */
  669. public function payShowTemplateOrderInfo(Request $request)
  670. {
  671. [$order_id] = UtilService::getMore([
  672. ['order_id', '', 'empty', '参数错误'],
  673. ], $request, true);
  674. $data = (new ShowTemplateOrder)
  675. ->field("order_id,total_money,all_money,pay_money,status,time")
  676. ->where("order_id", $order_id)
  677. ->where("uid", $request->user["uid"])
  678. ->find();
  679. if (empty($data)) {
  680. return app('json')->fail('信息不存在!');
  681. }
  682. $data = $data->toArray();
  683. if ($data["status"] == 0 && $data["time"] < time() - 30 * 60) {
  684. (new ShowTemplateOrder)->where("id", $data["id"])->where("uid", $request->user["uid"])->update(["status" => -1]);
  685. $data["status"] == -1;
  686. }
  687. $data["time"] = date("Y-m-d H:i:s", $data["time"]);
  688. return app('json')->success($data);
  689. }
  690. /**
  691. * 用户模板列表
  692. * @param Request $request
  693. */
  694. public function userShowTemplateList(Request $request)
  695. {
  696. $post = UtilService::getMore([
  697. ['page', 1],
  698. ['pageSize', 50],
  699. ], $request);
  700. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  701. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  702. $where = [];
  703. $where[] = ["ut.uid", "=", $request->user["uid"]];
  704. $totalCount = (new UserShowTemplate)->alias("ut")->where($where)->count();
  705. $data = null;
  706. if ($totalCount > 0) {
  707. $data = (new UserShowTemplate)
  708. ->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")
  709. ->alias("ut")
  710. ->join("show_template t", "t.id = ut.show_template_id", "left")
  711. ->where($where)
  712. ->order("ut.is_default", "desc")
  713. ->order("ut.id", "desc")
  714. ->page($post["page"], $post["pageSize"])
  715. ->select();
  716. foreach ($data as $k => $v) {
  717. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  718. $data[$k]["imgs"] = getImageAr($v["imgs"]);
  719. $data[$k]["img"] = empty($data[$k]["imgs"]) ? "" : $data[$k]["imgs"][0];
  720. $data[$k]["sales_count"] = $data[$k]["real_sales"] + $data[$k]["unreal_sales"];
  721. unset($data[$k]["real_sales"]);
  722. unset($data[$k]["unreal_sales"]);
  723. }
  724. }
  725. $data = empty($data) ? [] : $data;
  726. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  727. }
  728. /**
  729. * 设置默认模板
  730. * @param Request $request
  731. */
  732. public function setShowTemplate(Request $request)
  733. {
  734. [$show_template_id] = UtilService::getMore([
  735. ['show_template_id', '', 'empty', '参数错误'],
  736. ], $request, true);
  737. (new UserShowTemplate)->where("uid", $request->user["uid"])->where("is_default", 1)->update(["is_default" => 0]);
  738. (new UserShowTemplate)->where("uid", $request->user["uid"])->where("show_template_id", $show_template_id)->update(["is_default" => 1]);
  739. return app('json')->success("设置成功");
  740. }
  741. /**
  742. * 获取邀请海报小程序码
  743. * @param Request $request
  744. */
  745. public function getWxmpInviteQrcode(Request $request)
  746. {
  747. $inviteData = (new SysModel)->getDataInfo("invite");
  748. $bgimg = $inviteData["img"];
  749. if (!empty($request->user["invite_img"])) {
  750. return app('json')->success(["qrcode" => $request->user["invite_img"], "bgimg" => $bgimg]);
  751. }
  752. $weixinA = new weixina();
  753. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  754. $data = $weixinA->getUnlimitedQRCode("pages/index/index", $request->user["uid"]);
  755. // var_dump($data);
  756. if (empty($data)) {
  757. return app('json')->fail("小程序码获取失败" . $weixinA->error);
  758. }
  759. $base64 = 'data:' . $data['contentType'] . ';base64,' . base64_encode($data['buffer']);
  760. $res = $this->uploadImageBase64("wximg", $base64, 1);
  761. if ($res["code"] != 1) {
  762. return app('json')->fail($res["msg"]);
  763. }
  764. (new UserModel)->where("uid", $request->user["uid"])->update(["invite_img" => $res["url"]]);
  765. return app('json')->success(["qrcode" => $res["url"], "bgimg" => $bgimg]);
  766. }
  767. /**
  768. * 获取邀请海报小程序码
  769. * @param Request $request
  770. */
  771. public function getWxmpShowQrcode(Request $request)
  772. {
  773. $inviteData = (new SysModel)->getDataInfo("invite");
  774. $id = $request->param('id', 0);
  775. $bgimg = $inviteData["img"];
  776. // if(!empty($request->user["show_img"])){
  777. // return app('json')->success(["qrcode"=>$request->user["show_img"],"bgimg"=>$bgimg]);
  778. // }
  779. $templateData = (new UserShowTemplate())->where("uid", $request->user["uid"])->where("id", $id)->where("is_default", 1)->find();
  780. // if(!empty($request->user["show_img"])){
  781. // return app('json')->success(["qrcode"=>$request->user["show_img"],"bgimg"=>$bgimg]);
  782. // }
  783. if (!empty($templateData)) {
  784. return app('json')->success(["qrcode" => $request->user["show_img"], "bgimg" => $bgimg]);
  785. }
  786. $weixinA = new weixina();
  787. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  788. $data = $weixinA->getUnlimitedQRCode("pages/user/model/model", $request->user["uid"] . '_' . $id);
  789. $weixinA = new weixina();
  790. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  791. $data = $weixinA->getUnlimitedQRCode("pages/user/model/model", $request->user["uid"] . '_' . $id);
  792. if (empty($data)) {
  793. return app('json')->fail("小程序码获取失败" . $weixinA->error);
  794. }
  795. $base64 = 'data:' . $data['contentType'] . ';base64,' . base64_encode($data['buffer']);
  796. $res = $this->uploadImageBase64("wximg", $base64, 1);
  797. if ($res["code"] != 1) {
  798. return app('json')->fail($res["msg"]);
  799. }
  800. (new UserModel)->where("uid", $request->user["uid"])->update(["show_img" => $res["url"]]);
  801. return app('json')->success(["qrcode" => $res["url"], "bgimg" => $bgimg]);
  802. }
  803. public function useCode(Request $request)
  804. {
  805. $uid = $request->user["uid"];
  806. $code = $request->post('code', '');
  807. if (!$code) return app('json')->fail('请输入激活码');
  808. $info = Db::name('active_code')->where('code', $code)->find();
  809. if (!$info) return app('json')->fail('无效的激活码');
  810. if ($info['status'] != 0) return app('json')->fail('无效的激活码');
  811. if ($info['use_times'] >= $info['times']) return app('json')->fail('无效的激活码');
  812. $old = (new UserShowTemplate)->where('uid', $uid)->where('show_template_id', $info['show_template_id'])->find();
  813. if ($old) {
  814. return app('json')->success('该模板已激活');
  815. }
  816. UserShowTemplate::startTrans();
  817. try {
  818. //验证并绑定当前模板
  819. (new UserShowTemplate)->userBindTemp($info["show_template_id"], $uid);
  820. $update['use_times'] = $info['use_times'] + 1;
  821. if ($update['use_times'] >= $info['times']) $update['status'] = 1;
  822. if ($info['use_uid']) {
  823. $old_uids = explode(',', $info['use_uid']);
  824. } else {
  825. $old_uids = [];
  826. }
  827. $update['use_uid'] = implode(',', array_merge([$uid], $old_uids));
  828. Db::name('active_code')->where('code', $code)->update($update);
  829. UserShowTemplate::commit();
  830. return app('json')->success('模板已激活');
  831. } catch (DbException $dbException) {
  832. UserShowTemplate::rollback();
  833. return app('json')->fail($dbException->getMessage());
  834. }
  835. }
  836. /**
  837. * 点赞/收藏
  838. * @param Request $request
  839. * @return mixed
  840. * @throws DataNotFoundException
  841. * @throws DbException
  842. * @throws ModelNotFoundException
  843. */
  844. public function likeAndBookmark(Request $request)
  845. {
  846. $uid = $request->param('uid', 0);
  847. $type = $request->param('type', 0);
  848. $userData = (new UserModel)->where("uid", $uid)->find();
  849. if (empty($userData)) {
  850. return app('json')->fail("用户不存在");
  851. }
  852. if (empty($type)) {
  853. return app('json')->fail("参数错误");
  854. }
  855. $likeBookmarkInfo = (new LikeBookmark())->where('uid', $request->user['uid'])->where('aid', $uid)->where('type', $type)->where('is_del', 0)->find();
  856. if ($type == 1) {
  857. $typeName = 'like_count';
  858. } else {
  859. $typeName = 'bookmark_count';
  860. }
  861. if (!$likeBookmarkInfo) {
  862. (new LikeBookmark())->save([
  863. 'uid' => $request->user['uid'],
  864. 'aid' => $uid,
  865. 'type' => $type,
  866. 'add_time' => time()
  867. ]);
  868. (new UserModel)->where("uid", $uid)->inc($typeName, 1)->update();
  869. } else {
  870. (new LikeBookmark())->where('id', $likeBookmarkInfo['id'])->update(['is_del' => 1, 'del_time' => time()]);
  871. (new UserModel)->where("uid", $uid)->dec($typeName, 1)->update();
  872. }
  873. return app("json")->success("操作成功");
  874. }
  875. /**
  876. * 收藏列表
  877. * @param Request $request
  878. * @return mixed
  879. * @throws DataNotFoundException
  880. * @throws DbException
  881. * @throws ModelNotFoundException
  882. */
  883. public function BookmarkList(Request $request)
  884. {
  885. $post = UtilService::getMore([
  886. ['page', 1],
  887. ['pageSize', 20],
  888. ], $request);
  889. $likeBookMarkDb = new LikeBookmark();
  890. $where = "l.uid = " . $request->user['uid'] . " and l.type =2 and l.is_del = 0";
  891. $totalCount = $likeBookMarkDb->alias("l")
  892. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  893. ->leftJoin("user u", "l.aid=u.uid")
  894. ->leftJoin("info_audit a", "u.uid=a.uid")
  895. ->where($where)
  896. ->count();
  897. if ($totalCount > 0) {
  898. $data = $likeBookMarkDb->alias("l")
  899. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  900. ->leftJoin("user u", "l.aid=u.uid")
  901. ->leftJoin("info_audit a", "u.uid=a.uid")
  902. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  903. ->where($where)
  904. ->order("u.uid", "desc")
  905. ->page((int)$post['page'], (int)$post['pageSize'])
  906. ->select()->toArray();
  907. $infoAuditDb = new InfoAudit();
  908. foreach ($data as $k => $v) {
  909. $item = [
  910. "name" => "",
  911. "avatar" => "",
  912. "age" => "",
  913. "service_project_ar" => [],
  914. "user_work_type_title" => "",
  915. "service_area_all" => [],
  916. "birthday" => ""
  917. ];
  918. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  919. if (!empty($infoData)) {
  920. foreach ($item as $k2 => $v2) {
  921. $item[$k2] = $infoData[$k2];
  922. }
  923. }
  924. $data[$k] = array_merge($v, $item);
  925. }
  926. }
  927. $data = empty($data) ? [] : $data;
  928. return app('json')->success(["list" => $data, "pageSize" => $post['pageSize'], "page" => $post['page'], "totalCount" => $totalCount]);
  929. }
  930. /**
  931. * 图片上传
  932. * @param Request $request
  933. * @return type
  934. */
  935. public function upload(Request $request){
  936. $uploadConfig = config('filesystem');
  937. $sysData = (new SysModel())->where("id",1)->find();
  938. $file = $request->file('file');
  939. $code = $request->post("code","image");
  940. if(empty($file)) {
  941. return app('json')->fail("未上传文件");
  942. }
  943. $size = $file->getSize();
  944. if(!empty($size) && $size>$uploadConfig["image"]["size"]*1024*1024){
  945. return app('json')->fail("图片不能超过{$uploadConfig["image"]["size"]}M");
  946. }
  947. if(!in_array($code, $uploadConfig['image']['path'])){
  948. return app('json')->fail("上传路径错误");
  949. }
  950. $ext = $file->extension();
  951. if(!in_array($ext, $uploadConfig['image']['ext'])){
  952. return app('json')->fail("图片类型错误");
  953. }
  954. $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
  955. if(!$upPath){
  956. return app('json')->fail("上传失败01");
  957. }
  958. $savePath = $sysData['system_url'].'/resource/' . $upPath;
  959. $imgUrl = str_replace("\\", "/", $savePath);
  960. return app('json')->success(['img'=>$imgUrl,'size'=>$size]);
  961. }
  962. /**
  963. * 视频上传
  964. * @param Request $request
  965. * @return type
  966. */
  967. public function uploadVideo(Request $request){
  968. $uploadConfig = config('filesystem');
  969. $sysData = (new SysModel())->where("id",1)->find();
  970. $file = $request->file('file');
  971. $code = $request->post("code","video");
  972. if(empty($file)) {
  973. return app('json')->fail("未上传文件");
  974. }
  975. if(!in_array($code, $uploadConfig['video']['path'])){
  976. return app('json')->fail("上传路径错误");
  977. }
  978. $ext = $file->extension();
  979. if(!in_array($ext, $uploadConfig['video']['ext'])){
  980. return app('json')->fail("视频类型错误");
  981. }
  982. $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
  983. if(!$upPath){
  984. return app('json')->fail("上传失败01");
  985. }
  986. $savePath = $sysData['system_url'].'/resource/' . $upPath;
  987. $imgUrl = str_replace("\\", "/", $savePath);
  988. return app('json')->success(['video'=>$imgUrl]);
  989. }
  990. /**
  991. * base64文件上传
  992. * @param type $code
  993. * @param type $base64
  994. */
  995. public function uploadImageBase64($code,$base64,$isQiniu=0){
  996. $sysData = (new SysModel())->where("id",1)->find();
  997. $uploadConfig = config('filesystem');
  998. //验证base64格式
  999. preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
  1000. if(!$result){
  1001. return ["code"=>-1,"msg"=>"base64格式格式错误"];
  1002. }
  1003. //验证图片后缀
  1004. if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
  1005. return ["code"=>-1,"msg"=>"不支持的图片格式"];
  1006. }
  1007. $rootPath = config('filesystem.disks.resource.root');
  1008. $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
  1009. $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
  1010. $path = dirname($filePath);
  1011. // 检测目录
  1012. if (!is_dir($path)) {
  1013. if (!mkdir($path, 0777, true)) {
  1014. return ["code"=>-1,"msg"=>"生成目录失败"];
  1015. }
  1016. return ["code"=>-1,"msg"=>"上传目录不存在"];
  1017. }
  1018. //重名文件验证
  1019. if (is_file($filePath)) {
  1020. return ["code"=>-1,"msg"=>"文件已存在"];
  1021. }
  1022. if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
  1023. return ["code"=>-1,"msg"=>"文件报错失败"];
  1024. }
  1025. //七牛上传
  1026. if($isQiniu==1){
  1027. $qiniu = new Qiniu;
  1028. $img_url = $qiniu->updateFile('img', $filePath, $filePath);
  1029. if (empty($img_url['url'])) {
  1030. return ["code"=>-1,"msg"=>"文件报错失败:".$qiniu->getError()];
  1031. }
  1032. @unlink($filePath);
  1033. return ["code"=>1,"url"=>str_replace("\\", "/", $img_url['url'])];
  1034. }
  1035. $savePath = $sysData['system_url'].config('filesystem.disks.resource.url').DIRECTORY_SEPARATOR.$hashName;
  1036. return ["code"=>1,"url"=>str_replace("\\", "/", $savePath)];
  1037. }
  1038. /**
  1039. * 七牛上传图片
  1040. * @param Request $request
  1041. */
  1042. public function qiniuUpload(Request $request)
  1043. {
  1044. $file = $request->file('file');
  1045. if (empty($file)) {
  1046. return app('json')->fail("未上传文件");
  1047. }
  1048. $rootTmp = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
  1049. $image_size = @getimagesize($rootTmp);
  1050. if ($image_size[0] > 1000) {
  1051. $imgS = Image::open($rootTmp);
  1052. $imgS->thumb(1000, $image_size[1]);
  1053. $imgS->save($rootTmp);
  1054. } else {
  1055. if ($image_size[1] > 1000) {
  1056. $imgS = Image::open($rootTmp);
  1057. $imgS->thumb($image_size[0], 1000);
  1058. $imgS->save($rootTmp);
  1059. }
  1060. }
  1061. $qiniu = new Qiniu;
  1062. $img_url = $qiniu->updateFile('img', $rootTmp, $rootTmp);
  1063. if (empty($img_url['url'])) {
  1064. return app('json')->fail($qiniu->getError());
  1065. }
  1066. @unlink($rootTmp);
  1067. return app('json')->success(['img' => $img_url['url']]);
  1068. }
  1069. /**
  1070. * 七牛上传token
  1071. * @param Request $request
  1072. */
  1073. public function qiniuUploadToken(Request $request){
  1074. [$bucket] = UtilService::getMore([
  1075. ['bucket', ''],
  1076. ], $request,true);
  1077. $qiniu = new Qiniu;
  1078. $token = $qiniu->createUploadToken($bucket);
  1079. return app('json')->success(['token' => $token]);
  1080. }
  1081. /**
  1082. * 合约列表
  1083. * @param \app\Request $request
  1084. * @return mixed
  1085. */
  1086. public function getContractList(\think\Request $request)
  1087. {
  1088. // $pageSize = 50;
  1089. // $post = UtilService::getMore([
  1090. // ['page',1],
  1091. // ['pageSize',50],
  1092. // ['nickname',''],
  1093. //// ['uid',''],
  1094. // ['parent_uid',''],
  1095. // ['mobile',''],
  1096. // ['status',''],
  1097. // ['time',[]],
  1098. // ],$request);
  1099. //// $post['uid']=$request->user["uid"];
  1100. // $data = (new UserModel)->getDataList($post,"*",1);
  1101. // return app('json')->success([
  1102. // 'list' => $data["list"],
  1103. // 'pageCount' => $data["totalCount"],
  1104. // 'pageSize' => $data["pageSize"],
  1105. // 'page' => $data["page"],
  1106. // ]);
  1107. $post = UtilService::getMore([
  1108. ['page', 1],
  1109. ['pageSize', 50],
  1110. ['status', -2] //1未签约 2已签约 3已解约
  1111. ], $request);
  1112. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  1113. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  1114. $where = [];
  1115. $uid = UtilService::getMore([
  1116. ['uid', 0],
  1117. ], $request);
  1118. $uid = $uid['uid'];
  1119. // if ($uid>0){
  1120. // $where[]=["uid","=",$uid];
  1121. // }
  1122. $totalCount = (new UserContractRecordModel)->where($where)
  1123. ->when($uid > 0, function ($query) use ($uid) {
  1124. $query->where(function ($query) use ($uid) {
  1125. $query->where('uid', $uid)
  1126. ->whereOr('to_uid', $uid);
  1127. });
  1128. })->count();
  1129. if ($post["status"] != -2) {
  1130. $where[] = ['status', '=', $post["status"]];
  1131. }
  1132. $data = null;
  1133. if ($totalCount > 0) {
  1134. $data = (new UserContractRecordModel)
  1135. ->where($where)
  1136. ->when($uid > 0, function ($query) use ($uid) {
  1137. $query->where(function ($query) use ($uid) {
  1138. $query->where('uid', $uid)
  1139. ->whereOr('to_uid', $uid);
  1140. });
  1141. })
  1142. ->order("id", "desc")
  1143. ->page($post["page"], $post["pageSize"])
  1144. ->select();
  1145. // var_dump((new UserContractRecordModel)->getLastSql());die();
  1146. foreach ($data as $k => $v) {
  1147. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  1148. switch ($data[$k]["status"]) {
  1149. case 0:
  1150. $data[$k]["status_name"] = "未签约";
  1151. break;
  1152. case 1:
  1153. $data[$k]["status_name"] = "已签约";
  1154. break;
  1155. case -1:
  1156. $data[$k]["status_name"] = "已解约";
  1157. break;
  1158. }
  1159. // $data[$k]["comment"] = (new ContractCommentModel())->where('contract_id',$v["id"])->select();
  1160. $data[$k]["comment"] = (new ContractCommentModel())->where('contract_id', $v["id"])->find();
  1161. if (!empty($data[$k]["comment"])) {
  1162. $data[$k]["comment"] = $data[$k]["comment"]->toArray();
  1163. }
  1164. }
  1165. }
  1166. $data = empty($data) ? [] : $data;
  1167. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  1168. }
  1169. /**
  1170. * 甲方创建合约
  1171. */
  1172. public function form_save(Request $request)
  1173. {
  1174. $post = UtilService::getMore([
  1175. ['id', 0],
  1176. ['uid', '0'], //甲方uid
  1177. // ['name', ''], //甲方姓名
  1178. // ['phone', ''], //甲方手机号
  1179. // ['address', ''], //甲方地址
  1180. // ['card', ''], //甲方身份证号
  1181. ['to_uid', 0], //员工uid
  1182. ['to_name', ''], //乙方姓名
  1183. // ['price', 0], //服务费
  1184. // ['deposit', 0], // 定金
  1185. // ['balance', 0], //余款
  1186. // ['period', 0], // 周期天数
  1187. ['start_time', ''], // 开始时间
  1188. ['end_time', ''], // 结束时间
  1189. // ['mark', ''], //备注
  1190. ['content', []], //备注
  1191. ['template_id', 0], //合同模板id
  1192. ['longitude', ''], //经度
  1193. ['latitude', ''] //纬度
  1194. // ['uid_img',''] //甲方签名图片路径
  1195. // ['to_phone',''].
  1196. // ['to_address',''],
  1197. // ['to_card',''],
  1198. // ['data',[]],
  1199. // ['year',''],
  1200. // ['month',''],
  1201. // ['day',''],
  1202. ], $request);
  1203. $id = (int)$post["id"];
  1204. unset($post["id"]);
  1205. $uid = (int)$post["uid"];
  1206. if (empty($uid)) {
  1207. return app('json')->fail("参数错误");
  1208. }
  1209. // $post['content'] = $post['content'];
  1210. $post['start_time'] = strtotime($post['start_time']);
  1211. $post['end_time'] = strtotime($post['end_time']);
  1212. $start = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('start_time', [$post['start_time'], $post['end_time']])->find();
  1213. $end = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('end_time', [$post['start_time'], $post['end_time']])->find();
  1214. // $start2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('start_time',[$post['start_time'],$post['end_time']])->find();
  1215. // $end2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('end_time',[$post['start_time'],$post['end_time']])->find();
  1216. // if (!empty($start)||!empty($end)||!empty($start2)||!empty($end2)){
  1217. if (!empty($start) || !empty($end)) {
  1218. return app('json')->fail("与对方其他合约时间有冲突,请与对方协商");
  1219. }
  1220. // $year = $post['year'];
  1221. // $month = $post['month'];
  1222. // $day = $post['day'];
  1223. //
  1224. //// 检查年月日是否为空
  1225. // if (empty($year) || empty($month) || empty($day)) {
  1226. // return app('json')->fail("日期参数错误");
  1227. // }
  1228. //
  1229. //// 创建 DateTime 对象
  1230. // $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
  1231. //
  1232. //// 检查日期是否有效
  1233. // if (!$date || $date->format('Y-m-d') !== "$year-$month-$day") {
  1234. // return app('json')->fail("无效的日期");
  1235. // }
  1236. // unset($post['year']);
  1237. // unset($post['month']);
  1238. // unset($post['day']);
  1239. //// 转换为时间戳
  1240. // $timestamp = $date->getTimestamp();
  1241. //
  1242. // $post['create_time'] = $timestamp;
  1243. //用户信息
  1244. // if(!empty($post["uid_img"])){
  1245. // $post['status'] = 2;
  1246. // }else{
  1247. $post['status'] = 0;
  1248. // }
  1249. if ($id > 0) {
  1250. $r = (new UserContractRecordModel)->where("id", $id)->update($post);
  1251. } else {
  1252. $post['contract_no'] = makeOrderId($post['uid'], "CR");
  1253. $r = (new UserContractRecordModel)->save($post);
  1254. }
  1255. return app('json')->success("数据保存成功");
  1256. }
  1257. /**
  1258. * 甲方签约合约
  1259. */
  1260. public function check(Request $request)
  1261. {
  1262. $post = UtilService::getMore([
  1263. ['id', 0], //合约id
  1264. ['uid_img', ''], //甲方签名图片路径
  1265. ['check_time', ''],//签约时间
  1266. ['content', []]//签约内容
  1267. // ['to_phone',''].
  1268. // ['to_address',''],
  1269. // ['to_card',''],
  1270. // ['data',[]],
  1271. // ['year',''],
  1272. // ['month',''],
  1273. // ['day',''],
  1274. ], $request);
  1275. $info = (new UserContractRecordModel)->where("id", $post["id"])->find();
  1276. if (empty($info)) {
  1277. return app('json')->fail("合约不存在");
  1278. }
  1279. $post['content'] = json_encode($post['content']);
  1280. // 检查签约时间是否为空
  1281. if (empty($post['uid_img'])) {
  1282. return app('json')->fail("签字错误");
  1283. }
  1284. // 检查签约时间是否为空
  1285. if (empty($post['check_time'])) {
  1286. return app('json')->fail("日期参数错误");
  1287. }
  1288. $post['check_time'] = strtotime($post['check_time']);
  1289. // $post['status'] = 1;
  1290. $post['from_check'] = 1;
  1291. if ($info['to_check'] == 1) {
  1292. $post['status'] = 1;
  1293. }
  1294. // $post['contract_no'] = makeOrderId($post['uid'],"CR");
  1295. $r = (new UserContractRecordModel)->where("id", $post["id"])->update($post);
  1296. return app('json')->success("数据保存成功");
  1297. }
  1298. // 乙方确认
  1299. public function to_check(Request $request)
  1300. {
  1301. $post = UtilService::getMore([
  1302. ['id', '0'], //
  1303. ['to_uid_img', ''], //乙方签名图片路径
  1304. ['content', []], //内容
  1305. // ['to_phone', ''], //乙方手机号
  1306. // ['to_address', ''], //乙方地址
  1307. // ['to_card', ''], //乙方身份证号
  1308. ['to_check_time', '']//签约时间
  1309. ], $request);
  1310. $info = (new UserContractRecordModel)->where("id", $post["id"])->find();
  1311. if (empty($info)) {
  1312. return app('json')->fail("合约不存在");
  1313. }
  1314. // 检查签约时间是否为空
  1315. if (empty($post['to_uid_img'])) {
  1316. return app('json')->fail("签字错误");
  1317. }
  1318. // 检查签约时间是否为空
  1319. if (empty($post['to_check_time'])) {
  1320. return app('json')->fail("日期参数错误");
  1321. }
  1322. $post['to_check_time'] = strtotime($post['to_check_time']);
  1323. $post['to_check'] = 1;
  1324. if ($info['from_check'] == 1) {
  1325. $post['status'] = 1;
  1326. }
  1327. $post['content'] = json_encode($post['content']);
  1328. $r = (new UserContractRecordModel)->where("id", $post["id"])->update($post);
  1329. return app('json')->success("数据保存成功");
  1330. }
  1331. // 员工签到
  1332. public function clock_in(Request $request)
  1333. {
  1334. $post = UtilService::getMore([
  1335. ['contract_id', '0'], //合约id
  1336. ['longitude', ''], //经度
  1337. ['latitude', ''], //纬度
  1338. ['content', ''], //工作内容
  1339. // ['uid',0]
  1340. ], $request);
  1341. $uid = UtilService::getMore([
  1342. ['uid', 0],
  1343. ], $request);
  1344. $uid = $uid['uid'];
  1345. // $uid = (int)$post["uid"];
  1346. // 检查签约时间是否为空
  1347. if (empty($post['contract_id'])) {
  1348. return app('json')->fail("签字错误");
  1349. }
  1350. $time = time();
  1351. $info = (new UserContractRecordModel)->where('status',1)->where("id", $post["contract_id"])->where('start_time', '<', $time)->where('end_time', '>', $time)->find();
  1352. if (!empty($info)) {
  1353. $info = $info->toArray();
  1354. } else {
  1355. return app('json')->fail("合约未签约或已解约");
  1356. }
  1357. // $nickname=\app\model\api\User::where('uid',$uid)->value('nickname');
  1358. $r = (new UserClockModel)->save([
  1359. 'uid' => $uid,
  1360. 'nickname' => $info['to_name'],
  1361. 'longitude' => $post['longitude'],
  1362. 'latitude' => $post['latitude'],
  1363. 'contract_id' => $post['contract_id'],
  1364. 'content' => $post['content'],
  1365. 'create_time' => time()
  1366. ]);
  1367. return app('json')->success("数据保存成功");
  1368. }
  1369. // 添加客户评论
  1370. public function comment(Request $request)
  1371. {
  1372. $post = UtilService::getMore([
  1373. ['contract_id', '0'], //合约id
  1374. ['content', ''], //评论内容
  1375. // ['uid',0]
  1376. ], $request);
  1377. $uid = UtilService::getMore([
  1378. ['uid', 0],
  1379. ], $request);
  1380. $uid = $uid['uid'];
  1381. // $uid = $post['uid'];
  1382. $time = time();
  1383. $info = (new UserContractRecordModel)->where("id", $post["contract_id"])->find();
  1384. if (!empty($info)) {
  1385. $info = $info->toArray();
  1386. } else {
  1387. return app('json')->fail("没有签约中的合约");
  1388. }
  1389. if ($info['status'] != 1) {
  1390. return app('json')->fail("只有签约状态才能发表评论");
  1391. }
  1392. // var_dump($time);
  1393. // var_dump($info);die();
  1394. if ($info['start_time'] > $time || $info['end_time'] < $time) {
  1395. return app('json')->fail("只能在签约期间才能发表评论");
  1396. }
  1397. // ->where('start_time','>',$time)->where('end_time','<',$time)
  1398. // 检查签约时间是否为空
  1399. // if (empty($post['id'])) {
  1400. // return app('json')->fail("签字错误");
  1401. // }
  1402. $r = (new ContractCommentModel)->save([
  1403. 'uid' => $uid,
  1404. 'name' => $info['name'],
  1405. 'contract_id' => $post['contract_id'],
  1406. 'contract_no' => $info['contract_no'],
  1407. 'to_uid' => $info['to_uid'],
  1408. 'to_name' => $info['to_name'],
  1409. 'content' => $post['content'],
  1410. 'create_time' => time()
  1411. ]);
  1412. return app('json')->success("数据保存成功");
  1413. }
  1414. // 甲方主动解约
  1415. public function lift_contract(Request $request)
  1416. {
  1417. $post = UtilService::getMore([
  1418. ['contract_id', '0'], //合约id
  1419. // ['uid',0]
  1420. ], $request);
  1421. // 检查签约时间是否为空
  1422. if (empty($post['contract_id'])) {
  1423. return app('json')->fail("没有该合约");
  1424. }
  1425. $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([
  1426. 'status' => -1,
  1427. 'delete_time' => time()
  1428. ]);
  1429. return app('json')->success("解约成功");
  1430. }
  1431. // 乙方主动解约
  1432. public function right_contract(Request $request)
  1433. {
  1434. $post = UtilService::getMore([
  1435. ['contract_id', '0'], //合约id
  1436. // ['uid',0]
  1437. ], $request);
  1438. // 检查签约时间是否为空
  1439. if (empty($post['contract_id'])) {
  1440. return app('json')->fail("没有该合约");
  1441. }
  1442. $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([
  1443. 'status' => -1,
  1444. 'delete_time' => time()
  1445. ]);
  1446. return app('json')->success("解约成功");
  1447. }
  1448. // 打卡列表
  1449. /**
  1450. * 打卡列表
  1451. * @param \app\Request $request
  1452. * @return mixed
  1453. */
  1454. public function getClockList(\think\Request $request)
  1455. {
  1456. $post = UtilService::getMore([
  1457. ['page', 1],
  1458. ['pageSize', 50],
  1459. ['time', ''],
  1460. ['contract_id',0]
  1461. ], $request);
  1462. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  1463. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  1464. $where = [];
  1465. $uid = UtilService::getMore([
  1466. ['uid', 0],
  1467. ], $request);
  1468. $uid = $uid['uid'];
  1469. if ($uid > 0) {
  1470. $where[] = ["uid", "=", $uid];
  1471. }
  1472. if (!empty($post['time'])) {
  1473. $start_time = strtotime($post['time']);
  1474. $end_time = $start_time + 86400;
  1475. // 将时间范围添加到查询条件中
  1476. $where[] = ["create_time", ">=", $start_time];
  1477. $where[] = ["create_time", "<", $end_time];
  1478. // $where[] = ["create_time",'=',strtotime($post['time'])];
  1479. }
  1480. if ($post['contract_id']>0){
  1481. $where[] = ["contract_id",'=',$post['contract_id']];
  1482. }
  1483. $totalCount = (new UserClockModel())->where($where)->count();
  1484. $data = null;
  1485. if ($totalCount > 0) {
  1486. $data = (new UserClockModel)
  1487. ->where($where)
  1488. ->order("id", "desc")
  1489. ->page($post["page"], $post["pageSize"])
  1490. ->select();
  1491. }
  1492. $data = empty($data) ? [] : $data;
  1493. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  1494. }
  1495. // 合同模板详情接口
  1496. public function getContractTemplatInfo($id)
  1497. {
  1498. $data = (new ContractTemplate())
  1499. ->field("*")
  1500. ->where("id", $id)
  1501. ->where("is_show",1)
  1502. ->find();
  1503. if (empty($data)) {
  1504. return app('json')->fail("模板不存在");
  1505. }
  1506. // if ($data["is_init"] == 0 && $data["status"] != 1) {
  1507. // return app('json')->fail("模板已下架");
  1508. // }
  1509. $data = $data->toArray();
  1510. // $data["is_use"] = 0;
  1511. $data["imgs"] = getImageAr($data["imgs"]);
  1512. $data['content'] = json_decode($data['content']);
  1513. $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  1514. $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  1515. $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  1516. // $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  1517. // unset($data["real_sales"]);
  1518. unset($data["code"]);
  1519. //验证是否购买过并添加浏览记录
  1520. // $this->checkUser(request()->header("token", ""));
  1521. // if (!empty($this->user)) {
  1522. // $data["is_use"] = (new UserShowTemplate)->where("uid", $this->user["uid"])->where("show_template_id", $data["id"])->count() > 0 ? 1 : 0;
  1523. // (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  1524. // }
  1525. return app('json')->success($data);
  1526. }
  1527. // 合同详情接口
  1528. public function getContractRecordInfo($id)
  1529. {
  1530. // 合约详情
  1531. $data = (new UserContractRecordModel())
  1532. ->field("*")
  1533. ->where("id", $id)
  1534. // ->where("is_show",1)
  1535. ->find();
  1536. if (empty($data)) {
  1537. return app('json')->fail("合约不存在");
  1538. }
  1539. $data = $data->toArray();
  1540. // $data['content'] = $data['content'];
  1541. // 模版详情
  1542. $data2 = (new ContractTemplate())->where('id',$data['template_id'])->find();
  1543. if (empty($data2)) {
  1544. return app('json')->fail("模板不存在");
  1545. }
  1546. $data2 -> toArray();
  1547. // $data["is_use"] = 0;
  1548. $data["imgs"] = getImageAr($data2["imgs"]);
  1549. $data['template_content'] = json_decode($data2['content']);
  1550. $data['template_title'] = $data2['title'];
  1551. $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  1552. // $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  1553. // $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  1554. // $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  1555. // unset($data["real_sales"]);
  1556. unset($data["code"]);
  1557. //验证是否购买过并添加浏览记录
  1558. // $this->checkUser(request()->header("token", ""));
  1559. // if (!empty($this->user)) {
  1560. // $data["is_use"] = (new UserShowTemplate)->where("uid", $this->user["uid"])->where("show_template_id", $data["id"])->count() > 0 ? 1 : 0;
  1561. // (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  1562. // }
  1563. return app('json')->success($data);
  1564. }
  1565. }