User.php 66 KB

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