User.php 54 KB

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