User.php 60 KB

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