User.php 67 KB

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