User.php 69 KB

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