User.php 64 KB

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