User.php 70 KB

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