User.php 65 KB

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