User.php 65 KB

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