User.php 72 KB

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