User.php 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  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. ['longitude', ''], //经度
  1187. ['latitude', ''] //纬度
  1188. // ['uid_img',''] //甲方签名图片路径
  1189. // ['to_phone',''].
  1190. // ['to_address',''],
  1191. // ['to_card',''],
  1192. // ['data',[]],
  1193. // ['year',''],
  1194. // ['month',''],
  1195. // ['day',''],
  1196. ], $request);
  1197. $id = (int)$post["id"];
  1198. unset($post["id"]);
  1199. $uid = (int)$post["uid"];
  1200. if (empty($uid)) {
  1201. return app('json')->fail("参数错误");
  1202. }
  1203. $post['content'] = json_encode($post['content']);
  1204. $post['start_time'] = strtotime($post['start_time']);
  1205. $post['end_time'] = strtotime($post['end_time']);
  1206. $start = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('start_time', [$post['start_time'], $post['end_time']])->find();
  1207. $end = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('end_time', [$post['start_time'], $post['end_time']])->find();
  1208. // $start2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('start_time',[$post['start_time'],$post['end_time']])->find();
  1209. // $end2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('end_time',[$post['start_time'],$post['end_time']])->find();
  1210. // if (!empty($start)||!empty($end)||!empty($start2)||!empty($end2)){
  1211. if (!empty($start) || !empty($end)) {
  1212. return app('json')->fail("与对方其他合约时间有冲突,请与对方协商");
  1213. }
  1214. // $year = $post['year'];
  1215. // $month = $post['month'];
  1216. // $day = $post['day'];
  1217. //
  1218. //// 检查年月日是否为空
  1219. // if (empty($year) || empty($month) || empty($day)) {
  1220. // return app('json')->fail("日期参数错误");
  1221. // }
  1222. //
  1223. //// 创建 DateTime 对象
  1224. // $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
  1225. //
  1226. //// 检查日期是否有效
  1227. // if (!$date || $date->format('Y-m-d') !== "$year-$month-$day") {
  1228. // return app('json')->fail("无效的日期");
  1229. // }
  1230. // unset($post['year']);
  1231. // unset($post['month']);
  1232. // unset($post['day']);
  1233. //// 转换为时间戳
  1234. // $timestamp = $date->getTimestamp();
  1235. //
  1236. // $post['create_time'] = $timestamp;
  1237. //用户信息
  1238. // if(!empty($post["uid_img"])){
  1239. // $post['status'] = 2;
  1240. // }else{
  1241. $post['status'] = 0;
  1242. // }
  1243. if ($id > 0) {
  1244. $r = (new UserContractRecordModel)->where("id", $id)->update($post);
  1245. } else {
  1246. $post['contract_no'] = makeOrderId($post['uid'], "CR");
  1247. $r = (new UserContractRecordModel)->save($post);
  1248. }
  1249. return app('json')->success("数据保存成功");
  1250. }
  1251. /**
  1252. * 甲方签约合约
  1253. */
  1254. public function check(Request $request)
  1255. {
  1256. $post = UtilService::getMore([
  1257. ['id', 0], //合约id
  1258. ['uid_img', ''], //甲方签名图片路径
  1259. ['check_time', ''],//签约时间
  1260. ['content', []]//签约内容
  1261. // ['to_phone',''].
  1262. // ['to_address',''],
  1263. // ['to_card',''],
  1264. // ['data',[]],
  1265. // ['year',''],
  1266. // ['month',''],
  1267. // ['day',''],
  1268. ], $request);
  1269. $info = (new UserContractRecordModel)->where("id", $post["id"])->find();
  1270. if (empty($info)) {
  1271. return app('json')->fail("合约不存在");
  1272. }
  1273. $post['content'] = json_encode($post['content']);
  1274. // 检查签约时间是否为空
  1275. if (empty($post['uid_img'])) {
  1276. return app('json')->fail("签字错误");
  1277. }
  1278. // 检查签约时间是否为空
  1279. if (empty($post['check_time'])) {
  1280. return app('json')->fail("日期参数错误");
  1281. }
  1282. $post['check_time'] = strtotime($post['check_time']);
  1283. // $post['status'] = 1;
  1284. $post['from_check'] = 1;
  1285. if ($info['to_check'] == 1) {
  1286. $post['status'] = 1;
  1287. }
  1288. // $post['contract_no'] = makeOrderId($post['uid'],"CR");
  1289. $r = (new UserContractRecordModel)->where("id", $post["id"])->update($post);
  1290. return app('json')->success("数据保存成功");
  1291. }
  1292. // 乙方确认
  1293. public function to_check(Request $request)
  1294. {
  1295. $post = UtilService::getMore([
  1296. ['id', '0'], //
  1297. ['to_uid_img', ''], //乙方签名图片路径
  1298. ['content', []], //内容
  1299. // ['to_phone', ''], //乙方手机号
  1300. // ['to_address', ''], //乙方地址
  1301. // ['to_card', ''], //乙方身份证号
  1302. ['to_check_time', '']//签约时间
  1303. ], $request);
  1304. $info = (new UserContractRecordModel)->where("id", $post["id"])->find();
  1305. if (empty($info)) {
  1306. return app('json')->fail("合约不存在");
  1307. }
  1308. // 检查签约时间是否为空
  1309. if (empty($post['to_uid_img'])) {
  1310. return app('json')->fail("签字错误");
  1311. }
  1312. // 检查签约时间是否为空
  1313. if (empty($post['to_check_time'])) {
  1314. return app('json')->fail("日期参数错误");
  1315. }
  1316. $post['to_check_time'] = strtotime($post['to_check_time']);
  1317. $post['to_check'] = 1;
  1318. if ($info['from_check'] == 1) {
  1319. $post['status'] = 1;
  1320. }
  1321. $post['content'] = json_encode($post['content']);
  1322. $r = (new UserContractRecordModel)->where("id", $post["id"])->update($post);
  1323. return app('json')->success("数据保存成功");
  1324. }
  1325. // 员工签到
  1326. public function clock_in(Request $request)
  1327. {
  1328. $post = UtilService::getMore([
  1329. ['contract_id', '0'], //合约id
  1330. ['longitude', ''], //经度
  1331. ['latitude', ''], //纬度
  1332. ['content', ''], //工作内容
  1333. // ['uid',0]
  1334. ], $request);
  1335. $uid = UtilService::getMore([
  1336. ['uid', 0],
  1337. ], $request);
  1338. $uid = $uid['uid'];
  1339. // $uid = (int)$post["uid"];
  1340. // 检查签约时间是否为空
  1341. if (empty($post['contract_id'])) {
  1342. return app('json')->fail("签字错误");
  1343. }
  1344. $time = time();
  1345. $info = (new UserContractRecordModel)->where('status',1)->where("id", $post["contract_id"])->where('start_time', '<', $time)->where('end_time', '>', $time)->find();
  1346. if (!empty($info)) {
  1347. $info = $info->toArray();
  1348. } else {
  1349. return app('json')->fail("合约未签约或已解约");
  1350. }
  1351. // $nickname=\app\model\api\User::where('uid',$uid)->value('nickname');
  1352. $r = (new UserClockModel)->save([
  1353. 'uid' => $uid,
  1354. 'nickname' => $info['to_name'],
  1355. 'longitude' => $post['longitude'],
  1356. 'latitude' => $post['latitude'],
  1357. 'contract_id' => $post['contract_id'],
  1358. 'content' => $post['content'],
  1359. 'create_time' => time()
  1360. ]);
  1361. return app('json')->success("数据保存成功");
  1362. }
  1363. // 添加客户评论
  1364. public function comment(Request $request)
  1365. {
  1366. $post = UtilService::getMore([
  1367. ['contract_id', '0'], //合约id
  1368. ['content', ''], //评论内容
  1369. // ['uid',0]
  1370. ], $request);
  1371. $uid = UtilService::getMore([
  1372. ['uid', 0],
  1373. ], $request);
  1374. $uid = $uid['uid'];
  1375. // $uid = $post['uid'];
  1376. $time = time();
  1377. $info = (new UserContractRecordModel)->where("id", $post["contract_id"])->find();
  1378. if (!empty($info)) {
  1379. $info = $info->toArray();
  1380. } else {
  1381. return app('json')->fail("没有签约中的合约");
  1382. }
  1383. if ($info['status'] != 1) {
  1384. return app('json')->fail("只有签约状态才能发表评论");
  1385. }
  1386. // var_dump($time);
  1387. // var_dump($info);die();
  1388. if ($info['start_time'] > $time || $info['end_time'] < $time) {
  1389. return app('json')->fail("只能在签约期间才能发表评论");
  1390. }
  1391. // ->where('start_time','>',$time)->where('end_time','<',$time)
  1392. // 检查签约时间是否为空
  1393. // if (empty($post['id'])) {
  1394. // return app('json')->fail("签字错误");
  1395. // }
  1396. $r = (new ContractCommentModel)->save([
  1397. 'uid' => $uid,
  1398. 'name' => $info['name'],
  1399. 'contract_id' => $post['contract_id'],
  1400. 'contract_no' => $info['contract_no'],
  1401. 'to_uid' => $info['to_uid'],
  1402. 'to_name' => $info['to_name'],
  1403. 'content' => $post['content'],
  1404. 'create_time' => time()
  1405. ]);
  1406. return app('json')->success("数据保存成功");
  1407. }
  1408. // 甲方主动解约
  1409. public function lift_contract(Request $request)
  1410. {
  1411. $post = UtilService::getMore([
  1412. ['contract_id', '0'], //合约id
  1413. // ['uid',0]
  1414. ], $request);
  1415. // 检查签约时间是否为空
  1416. if (empty($post['contract_id'])) {
  1417. return app('json')->fail("没有该合约");
  1418. }
  1419. $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([
  1420. 'status' => -1,
  1421. 'delete_time' => time()
  1422. ]);
  1423. return app('json')->success("解约成功");
  1424. }
  1425. // 乙方主动解约
  1426. public function right_contract(Request $request)
  1427. {
  1428. $post = UtilService::getMore([
  1429. ['contract_id', '0'], //合约id
  1430. // ['uid',0]
  1431. ], $request);
  1432. // 检查签约时间是否为空
  1433. if (empty($post['contract_id'])) {
  1434. return app('json')->fail("没有该合约");
  1435. }
  1436. $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([
  1437. 'status' => -1,
  1438. 'delete_time' => time()
  1439. ]);
  1440. return app('json')->success("解约成功");
  1441. }
  1442. // 打卡列表
  1443. /**
  1444. * 打卡列表
  1445. * @param \app\Request $request
  1446. * @return mixed
  1447. */
  1448. public function getClockList(\think\Request $request)
  1449. {
  1450. $post = UtilService::getMore([
  1451. ['page', 1],
  1452. ['pageSize', 50],
  1453. ['time', ''],
  1454. ['contract_id',0]
  1455. ], $request);
  1456. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  1457. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  1458. $where = [];
  1459. $uid = UtilService::getMore([
  1460. ['uid', 0],
  1461. ], $request);
  1462. $uid = $uid['uid'];
  1463. if ($uid > 0) {
  1464. $where[] = ["uid", "=", $uid];
  1465. }
  1466. if (!empty($post['time'])) {
  1467. $start_time = strtotime($post['time']);
  1468. $end_time = $start_time + 86400;
  1469. // 将时间范围添加到查询条件中
  1470. $where[] = ["create_time", ">=", $start_time];
  1471. $where[] = ["create_time", "<", $end_time];
  1472. // $where[] = ["create_time",'=',strtotime($post['time'])];
  1473. }
  1474. if ($post['contract_id']>0){
  1475. $where[] = ["contract_id",'=',$post['contract_id']];
  1476. }
  1477. $totalCount = (new UserClockModel())->where($where)->count();
  1478. $data = null;
  1479. if ($totalCount > 0) {
  1480. $data = (new UserClockModel)
  1481. ->where($where)
  1482. ->order("id", "desc")
  1483. ->page($post["page"], $post["pageSize"])
  1484. ->select();
  1485. }
  1486. $data = empty($data) ? [] : $data;
  1487. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  1488. }
  1489. // 合同模板详情接口
  1490. public function getContractTemplatInfo($id)
  1491. {
  1492. $data = (new ContractTemplate())
  1493. ->field("*")
  1494. ->where("id", $id)
  1495. ->where("is_show",1)
  1496. ->find();
  1497. if (empty($data)) {
  1498. return app('json')->fail("模板不存在");
  1499. }
  1500. // if ($data["is_init"] == 0 && $data["status"] != 1) {
  1501. // return app('json')->fail("模板已下架");
  1502. // }
  1503. $data = $data->toArray();
  1504. // $data["is_use"] = 0;
  1505. $data["imgs"] = getImageAr($data["imgs"]);
  1506. $data['content'] = json_decode($data['content']);
  1507. $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  1508. $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  1509. $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  1510. // $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  1511. // unset($data["real_sales"]);
  1512. unset($data["code"]);
  1513. //验证是否购买过并添加浏览记录
  1514. // $this->checkUser(request()->header("token", ""));
  1515. // if (!empty($this->user)) {
  1516. // $data["is_use"] = (new UserShowTemplate)->where("uid", $this->user["uid"])->where("show_template_id", $data["id"])->count() > 0 ? 1 : 0;
  1517. // (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  1518. // }
  1519. return app('json')->success($data);
  1520. }
  1521. // 合同详情接口
  1522. public function getContractRecordInfo($id)
  1523. {
  1524. // 合约详情
  1525. $data = (new UserContractRecordModel())
  1526. ->field("*")
  1527. ->where("id", $id)
  1528. // ->where("is_show",1)
  1529. ->find();
  1530. if (empty($data)) {
  1531. return app('json')->fail("合约不存在");
  1532. }
  1533. $data = $data->toArray();
  1534. $data2['record_content'] = json_decode($data['content']);
  1535. // 模版详情
  1536. $data2 = (new ContractTemplate())->where('id',$data['template_id'])->find();
  1537. if (empty($data2)) {
  1538. return app('json')->fail("模板不存在");
  1539. }
  1540. $data2 = $data2 -> toArray();
  1541. // $data["is_use"] = 0;
  1542. $data2["imgs"] = getImageAr($data["imgs"]);
  1543. $data2['content'] = json_decode($data2['content']);
  1544. $data2["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  1545. // $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  1546. // $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  1547. // $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  1548. // unset($data["real_sales"]);
  1549. unset($data["code"]);
  1550. //验证是否购买过并添加浏览记录
  1551. // $this->checkUser(request()->header("token", ""));
  1552. // if (!empty($this->user)) {
  1553. // $data["is_use"] = (new UserShowTemplate)->where("uid", $this->user["uid"])->where("show_template_id", $data["id"])->count() > 0 ? 1 : 0;
  1554. // (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  1555. // }
  1556. return app('json')->success($data2);
  1557. }
  1558. }