User.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  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. // 搜索该用户是否发过邀请奖励
  459. $usd = (new UserScoreDetail())->where("uid", $parent_uid)->where("code", "subInfo_score")->where("link_id", $save["uid"])->find();
  460. if (empty($usd)){
  461. (new UserScoreDetail())->incomeScore($parent_uid,$sys['points_share'],'',"subInfo_score",[],$save["uid"],'邀请奖励','邀请用户生成名片奖励积分');
  462. }
  463. }
  464. }
  465. return app('json')->success("提交成功,数据已通过审核");
  466. }
  467. /**
  468. * 平台认证
  469. * @param Request $request
  470. */
  471. public function subTypeAudit(Request $request)
  472. {
  473. $data = (new TypeAudit)->where("uid", $request->user["uid"])->order("id desc")->find();
  474. if (!empty($data) && $data["status"] == 0) {
  475. return app('json')->fail("平台审核中,请勿重复提交");
  476. }
  477. $post = UtilService::getMore([
  478. ['service_audit_imgs', [], "empty", "请上传服务认证截图"],
  479. ['store_name', '', '', ''],
  480. ], $request);
  481. $save = [];
  482. $save["service_audit_imgs"] = is_array($post["service_audit_imgs"]) ? implode(",", $post["service_audit_imgs"]) : "";
  483. $save["store_name"] = empty($post["store_name"]) ? "" : $post["store_name"];
  484. $save["status"] = 0;
  485. $save["time"] = time();
  486. $save["uid"] = $request->user["uid"];
  487. if (empty($save["service_audit_imgs"])) {
  488. return app('json')->fail("请上传服务认证截图");
  489. }
  490. $r = (new TypeAudit)->insertGetId($save);
  491. if (!$r) {
  492. return app('json')->fail("系统错误");
  493. }
  494. $no = "CERT-" . date("YmdHis") . "-" . $r;
  495. (new TypeAudit)->where("id", $r)->update(["no" => $no]);
  496. return app('json')->success("提交成功,请耐心等待审核");
  497. }
  498. /**
  499. * 模板订单提交[第一步]
  500. * @param Request $request
  501. */
  502. public function subShowTemplateOrder(Request $request)
  503. {
  504. [$id, $pay_type] = UtilService::getMore([
  505. ['id', '', 'empty', '参数错误'],
  506. ['pay_type', '', 'empty', '请选择支付方式'],
  507. ], $request, true);
  508. if (!in_array($pay_type, ["wxpay", "balance"])) {
  509. return app('json')->fail('不支持该支付方式!');
  510. }
  511. $weixinConfig = (new SysModel)->getWeixinConfig();
  512. // if(empty($weixinConfig)){
  513. // return app('json')->fail('支付配置为空!');
  514. // }
  515. //缓存
  516. $redis = \think\facade\Cache::store('redis');
  517. $key = 'show_template_order_sub_' . $request->user['uid'];
  518. $bool = $redis->handler()->exists($key);
  519. if ($bool) {
  520. return app('json')->fail('请务重复操作,请稍等在重试!');
  521. }
  522. $redis->set($key, 1, 5);//5秒缓存
  523. $proData = (new ShowTemplate)->where("id", $id)->where("status", 1)->find();
  524. if (empty($proData)) {
  525. return app('json')->fail("当前模板已下架");
  526. }
  527. $proData = $proData->toArray();
  528. $count = (new UserShowTemplate)->where("uid", $request->user['uid'])->where("show_template_id", $id)->count();
  529. if ($count > 0) {
  530. return app('json')->fail("您已购买过当前模板");
  531. }
  532. //验证
  533. $orderCount = (new ShowTemplateOrder)->where("uid", $request->user['uid'])->where("show_template_id", $id)->where("status", 1)->count();
  534. if ($orderCount > 0) {
  535. return app('json')->fail("您已下单该模板,请勿重复下单");
  536. }
  537. $price = floatval($proData["price"]);
  538. // if($price<0.01){
  539. // return app('json')->fail("模板信息错误");
  540. // }
  541. $allMoney = $price;//订单商品费用
  542. $total_money = $allMoney;//订单总费用
  543. $payMoney = $total_money;//订单需支付费用
  544. $payMoney = $payMoney <= 0 ? 0 : $payMoney;
  545. $nowTime = time();
  546. //余额支付验证
  547. if ($pay_type == "balance" && $payMoney > $request->user["money"]) {
  548. return app('json')->fail("当前余额不足");
  549. }
  550. //主订单数据
  551. $save = [];
  552. $save['uid'] = $request->user['uid'];
  553. $save['order_id'] = makeOrderId($request->user['uid'], "ST");
  554. $save['pay_type'] = $pay_type;//
  555. $save['total_money'] = $total_money;//订单总金额
  556. $save['all_money'] = $allMoney;//商品中金额
  557. $save['pay_money'] = $payMoney;//实际支付金额
  558. $save['balance'] = 0;//余额支付了多少(目前不用)
  559. $save['status'] = $payMoney <= 0 ? 1 : 0;
  560. $save['pay_time'] = $payMoney <= 0 ? time() : 0;
  561. $save['time'] = $nowTime;
  562. $save['show_template_id'] = $proData["id"];
  563. $save['show_template_title'] = $proData["title"];;
  564. $save['show_template_price'] = $proData["price"];
  565. $save['show_template_img'] = empty($proData["imgs"]) ? "" : explode(",", $proData["imgs"])[0];
  566. $save['show_template_code'] = $proData["code"];
  567. //余额实时支付
  568. if ($pay_type == "balance") {
  569. $save['status'] = 1;
  570. $save['pay_time'] = time();
  571. }
  572. try {
  573. Db::startTrans();
  574. $o_id = (new ShowTemplateOrder)->insertGetId($save);
  575. if (empty($o_id)) {
  576. return app('json')->fail("订单提交失败");
  577. }
  578. //不需要支付
  579. if ($payMoney <= 0 && $save['status'] == 1) {
  580. //验证并绑定当前模板
  581. (new UserShowTemplate)->userBindTemp($save["show_template_id"], $save['uid']);
  582. Db::commit();
  583. return app("json")->success(["order_id" => $save['order_id'], "money" => $payMoney, "status" => $save['status']]);
  584. }
  585. //余额支付
  586. if ($pay_type == "balance") {
  587. //验证并绑定当前模板
  588. (new UserShowTemplate)->userBindTemp($save["show_template_id"], $save['uid']);
  589. //修改用户余额
  590. $res = (new UserDetailModel)->balancePay($request->user["uid"], $payMoney, "show_temp_pay", ["to_id" => $o_id]);
  591. if (!$res) {
  592. Db::rollback();
  593. return app('json')->fail("余额支付失败");
  594. }
  595. Db::commit();
  596. return app("json")->success(["order_id" => $save['order_id'], "money" => $payMoney, "status" => $save['status']]);
  597. }
  598. //微信支付
  599. if (empty($request->user['openid'])) {
  600. Db::rollback();
  601. return app('json')->fail('用户还未绑定微信!');
  602. }
  603. //清理之前支付凭证 || 防止重复购买
  604. $payTrade = (new PayTradeModel)
  605. ->where("uid", $request->user["uid"])
  606. ->where("o_id", $o_id)
  607. ->where("order_type", 0)
  608. ->where("type", "temp")
  609. ->where("status", 0)
  610. ->where("time", "<", time() - 7 * 24 * 60 * 60)
  611. ->select()
  612. ->toArray();
  613. $wxpay = new wxpayApi();
  614. // $wxpay = new wxpayApi($weixinConfig);
  615. foreach ($payTrade as $v) {
  616. // if($v['pay_type'] == 'wxpay') {
  617. // $result = $wxpay->closeOrder($v['pay_no']);
  618. // }
  619. (new PayTradeModel)->where("id", $v['id'])->where("status", 0)->where("order_type", 0)->delete();
  620. }
  621. $mtime = microtime(true) * 10000;
  622. $payOn = "T" . date("Ymd") . $mtime . rand(100, 999) . $request->user['uid'];
  623. $out_trade_no = "";
  624. $payType = $save["pay_type"];
  625. //添加交易记录
  626. $trade = [
  627. 'uid' => $request->user['uid'],
  628. 'o_id' => $o_id,
  629. 'order_id' => $save["order_id"],
  630. 'pay_no' => $payOn,
  631. 'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
  632. 'pay_type' => $payType,
  633. 'money' => $payMoney,
  634. 'type' => 'temp',
  635. 'd_json' => serialize(['orderId' => $save["order_id"], "give_score" => 0]),
  636. 'time' => time(),
  637. 'status' => 0,
  638. ];
  639. $r = (new PayTradeModel)->insert($trade);
  640. if (!$r) {
  641. Db::rollback();
  642. return app('json')->fail('支付信息获取失败!');
  643. }
  644. $clictip = get_client_ip();
  645. if (empty($clictip)) {
  646. $clictip = $request->ip();
  647. }
  648. $payData = $wxpay->wxmpPay([
  649. 'body' => "微信小程序购买模板",
  650. 'out_trade_no' => $payOn,
  651. 'total' => $payMoney,
  652. 'openid' => $request->user['openid'],
  653. 'payer_client_ip' => $clictip,
  654. ]);
  655. if (empty($payData)) {
  656. Db::rollback();
  657. return app('json')->fail($wxpay->errorMsg);
  658. }
  659. Db::commit();
  660. $redis->delete($key);
  661. return app('json')->success([
  662. 'jsApiParameters' => $payData,
  663. 'pay_no' => $payOn,
  664. 'order_id' => $save["order_id"],
  665. "status" => $save['status'],
  666. "money" => $payMoney,
  667. ]);
  668. } catch (DbException $db) {
  669. Db::rollback();
  670. return app('json')->fail("订单生成失败");
  671. }
  672. }
  673. /**
  674. * 获取模板购买订单详情
  675. * @param Request $request
  676. */
  677. public function payShowTemplateOrderInfo(Request $request)
  678. {
  679. [$order_id] = UtilService::getMore([
  680. ['order_id', '', 'empty', '参数错误'],
  681. ], $request, true);
  682. $data = (new ShowTemplateOrder)
  683. ->field("order_id,total_money,all_money,pay_money,status,time")
  684. ->where("order_id", $order_id)
  685. ->where("uid", $request->user["uid"])
  686. ->find();
  687. if (empty($data)) {
  688. return app('json')->fail('信息不存在!');
  689. }
  690. $data = $data->toArray();
  691. if ($data["status"] == 0 && $data["time"] < time() - 30 * 60) {
  692. (new ShowTemplateOrder)->where("id", $data["id"])->where("uid", $request->user["uid"])->update(["status" => -1]);
  693. $data["status"] == -1;
  694. }
  695. $data["time"] = date("Y-m-d H:i:s", $data["time"]);
  696. return app('json')->success($data);
  697. }
  698. /**
  699. * 用户模板列表
  700. * @param Request $request
  701. */
  702. public function userShowTemplateList(Request $request)
  703. {
  704. $post = UtilService::getMore([
  705. ['page', 1],
  706. ['pageSize', 50],
  707. ], $request);
  708. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  709. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  710. $where = [];
  711. $where[] = ["ut.uid", "=", $request->user["uid"]];
  712. $totalCount = (new UserShowTemplate)->alias("ut")->where($where)->count();
  713. $data = null;
  714. if ($totalCount > 0) {
  715. $data = (new UserShowTemplate)
  716. ->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")
  717. ->alias("ut")
  718. ->join("show_template t", "t.id = ut.show_template_id", "left")
  719. ->where($where)
  720. ->order("ut.is_default", "desc")
  721. ->order("ut.id", "desc")
  722. ->page($post["page"], $post["pageSize"])
  723. ->select();
  724. foreach ($data as $k => $v) {
  725. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  726. $data[$k]["imgs"] = getImageAr($v["imgs"]);
  727. $data[$k]["img"] = empty($data[$k]["imgs"]) ? "" : $data[$k]["imgs"][0];
  728. $data[$k]["sales_count"] = $data[$k]["real_sales"] + $data[$k]["unreal_sales"];
  729. unset($data[$k]["real_sales"]);
  730. unset($data[$k]["unreal_sales"]);
  731. }
  732. }
  733. $data = empty($data) ? [] : $data;
  734. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  735. }
  736. /**
  737. * 设置默认模板
  738. * @param Request $request
  739. */
  740. public function setShowTemplate(Request $request)
  741. {
  742. [$show_template_id] = UtilService::getMore([
  743. ['show_template_id', '', 'empty', '参数错误'],
  744. ], $request, true);
  745. (new UserShowTemplate)->where("uid", $request->user["uid"])->where("is_default", 1)->update(["is_default" => 0]);
  746. (new UserShowTemplate)->where("uid", $request->user["uid"])->where("show_template_id", $show_template_id)->update(["is_default" => 1]);
  747. return app('json')->success("设置成功");
  748. }
  749. /**
  750. * 获取邀请海报小程序码
  751. * @param Request $request
  752. */
  753. public function getWxmpInviteQrcode(Request $request)
  754. {
  755. $inviteData = (new SysModel)->getDataInfo("invite");
  756. $bgimg = $inviteData["img"];
  757. if (!empty($request->user["invite_img"])) {
  758. return app('json')->success(["qrcode" => $request->user["invite_img"], "bgimg" => $bgimg]);
  759. }
  760. $weixinA = new weixina();
  761. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  762. $data = $weixinA->getUnlimitedQRCode("pages/index/index", $request->user["uid"]);
  763. // var_dump($data);
  764. if (empty($data)) {
  765. return app('json')->fail("小程序码获取失败" . $weixinA->error);
  766. }
  767. $base64 = 'data:' . $data['contentType'] . ';base64,' . base64_encode($data['buffer']);
  768. $res = $this->uploadImageBase64("wximg", $base64, 1);
  769. if ($res["code"] != 1) {
  770. return app('json')->fail($res["msg"]);
  771. }
  772. (new UserModel)->where("uid", $request->user["uid"])->update(["invite_img" => $res["url"]]);
  773. return app('json')->success(["qrcode" => $res["url"], "bgimg" => $bgimg]);
  774. }
  775. /**
  776. * 获取邀请海报小程序码
  777. * @param Request $request
  778. */
  779. public function getWxmpShowQrcode(Request $request)
  780. {
  781. $inviteData = (new SysModel)->getDataInfo("invite");
  782. $id = $request->param('id', 0);
  783. $bgimg = $inviteData["img"];
  784. // if(!empty($request->user["show_img"])){
  785. // return app('json')->success(["qrcode"=>$request->user["show_img"],"bgimg"=>$bgimg]);
  786. // }
  787. $templateData = (new UserShowTemplate())->where("uid", $request->user["uid"])->where("id", $id)->where("is_default", 1)->find();
  788. // if(!empty($request->user["show_img"])){
  789. // return app('json')->success(["qrcode"=>$request->user["show_img"],"bgimg"=>$bgimg]);
  790. // }
  791. if (!empty($templateData)) {
  792. return app('json')->success(["qrcode" => $request->user["show_img"], "bgimg" => $bgimg]);
  793. }
  794. $weixinA = new weixina();
  795. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  796. $data = $weixinA->getUnlimitedQRCode("pages/user/model/model", $request->user["uid"] . '_' . $id);
  797. $weixinA = new weixina();
  798. // $data = $weixinA->getUnlimitedQRCode("pages/index/index","scene=".$request->user["uid"]);
  799. $data = $weixinA->getUnlimitedQRCode("pages/user/model/model", $request->user["uid"] . '_' . $id);
  800. if (empty($data)) {
  801. return app('json')->fail("小程序码获取失败" . $weixinA->error);
  802. }
  803. $base64 = 'data:' . $data['contentType'] . ';base64,' . base64_encode($data['buffer']);
  804. $res = $this->uploadImageBase64("wximg", $base64, 1);
  805. if ($res["code"] != 1) {
  806. return app('json')->fail($res["msg"]);
  807. }
  808. (new UserModel)->where("uid", $request->user["uid"])->update(["show_img" => $res["url"]]);
  809. return app('json')->success(["qrcode" => $res["url"], "bgimg" => $bgimg]);
  810. }
  811. public function useCode(Request $request)
  812. {
  813. $uid = $request->user["uid"];
  814. $code = $request->post('code', '');
  815. if (!$code) return app('json')->fail('请输入激活码');
  816. $info = Db::name('active_code')->where('code', $code)->find();
  817. if (!$info) return app('json')->fail('无效的激活码');
  818. if ($info['status'] != 0) return app('json')->fail('无效的激活码');
  819. if ($info['use_times'] >= $info['times']) return app('json')->fail('无效的激活码');
  820. $old = (new UserShowTemplate)->where('uid', $uid)->where('show_template_id', $info['show_template_id'])->find();
  821. if ($old) {
  822. return app('json')->success('该模板已激活');
  823. }
  824. UserShowTemplate::startTrans();
  825. try {
  826. //验证并绑定当前模板
  827. (new UserShowTemplate)->userBindTemp($info["show_template_id"], $uid);
  828. $update['use_times'] = $info['use_times'] + 1;
  829. if ($update['use_times'] >= $info['times']) $update['status'] = 1;
  830. if ($info['use_uid']) {
  831. $old_uids = explode(',', $info['use_uid']);
  832. } else {
  833. $old_uids = [];
  834. }
  835. $update['use_uid'] = implode(',', array_merge([$uid], $old_uids));
  836. Db::name('active_code')->where('code', $code)->update($update);
  837. UserShowTemplate::commit();
  838. return app('json')->success('模板已激活');
  839. } catch (DbException $dbException) {
  840. UserShowTemplate::rollback();
  841. return app('json')->fail($dbException->getMessage());
  842. }
  843. }
  844. /**
  845. * 点赞/收藏
  846. * @param Request $request
  847. * @return mixed
  848. * @throws DataNotFoundException
  849. * @throws DbException
  850. * @throws ModelNotFoundException
  851. */
  852. public function likeAndBookmark(Request $request)
  853. {
  854. $uid = $request->param('uid', 0);
  855. $type = $request->param('type', 0);
  856. $userData = (new UserModel)->where("uid", $uid)->find();
  857. if (empty($userData)) {
  858. return app('json')->fail("用户不存在");
  859. }
  860. if (empty($type)) {
  861. return app('json')->fail("参数错误");
  862. }
  863. $likeBookmarkInfo = (new LikeBookmark())->where('uid', $request->user['uid'])->where('aid', $uid)->where('type', $type)->where('is_del', 0)->find();
  864. if ($type == 1) {
  865. $typeName = 'like_count';
  866. } else {
  867. $typeName = 'bookmark_count';
  868. }
  869. if (!$likeBookmarkInfo) {
  870. (new LikeBookmark())->save([
  871. 'uid' => $request->user['uid'],
  872. 'aid' => $uid,
  873. 'type' => $type,
  874. 'add_time' => time()
  875. ]);
  876. (new UserModel)->where("uid", $uid)->inc($typeName, 1)->update();
  877. } else {
  878. (new LikeBookmark())->where('id', $likeBookmarkInfo['id'])->update(['is_del' => 1, 'del_time' => time()]);
  879. (new UserModel)->where("uid", $uid)->dec($typeName, 1)->update();
  880. }
  881. return app("json")->success("操作成功");
  882. }
  883. /**
  884. * 收藏列表
  885. * @param Request $request
  886. * @return mixed
  887. * @throws DataNotFoundException
  888. * @throws DbException
  889. * @throws ModelNotFoundException
  890. */
  891. public function BookmarkList(Request $request)
  892. {
  893. $post = UtilService::getMore([
  894. ['page', 1],
  895. ['pageSize', 20],
  896. ], $request);
  897. $likeBookMarkDb = new LikeBookmark();
  898. $where = "l.uid = " . $request->user['uid'] . " and l.type =2 and l.is_del = 0";
  899. $totalCount = $likeBookMarkDb->alias("l")
  900. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  901. ->leftJoin("user u", "l.aid=u.uid")
  902. ->leftJoin("info_audit a", "u.uid=a.uid")
  903. ->where($where)
  904. ->count();
  905. if ($totalCount > 0) {
  906. $data = $likeBookMarkDb->alias("l")
  907. ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
  908. ->leftJoin("user u", "l.aid=u.uid")
  909. ->leftJoin("info_audit a", "u.uid=a.uid")
  910. ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板
  911. ->where($where)
  912. ->order("u.uid", "desc")
  913. ->page((int)$post['page'], (int)$post['pageSize'])
  914. ->select()->toArray();
  915. $infoAuditDb = new InfoAudit();
  916. foreach ($data as $k => $v) {
  917. $item = [
  918. "name" => "",
  919. "avatar" => "",
  920. "age" => "",
  921. "service_project_ar" => [],
  922. "user_work_type_title" => "",
  923. "service_area_all" => [],
  924. "birthday" => ""
  925. ];
  926. $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]);
  927. if (!empty($infoData)) {
  928. foreach ($item as $k2 => $v2) {
  929. $item[$k2] = $infoData[$k2];
  930. }
  931. }
  932. $data[$k] = array_merge($v, $item);
  933. }
  934. }
  935. $data = empty($data) ? [] : $data;
  936. return app('json')->success(["list" => $data, "pageSize" => $post['pageSize'], "page" => $post['page'], "totalCount" => $totalCount]);
  937. }
  938. /**
  939. * 图片上传
  940. * @param Request $request
  941. * @return type
  942. */
  943. public function upload(Request $request){
  944. $uploadConfig = config('filesystem');
  945. $sysData = (new SysModel())->where("id",1)->find();
  946. $file = $request->file('file');
  947. $code = $request->post("code","image");
  948. if(empty($file)) {
  949. return app('json')->fail("未上传文件");
  950. }
  951. $size = $file->getSize();
  952. if(!empty($size) && $size>$uploadConfig["image"]["size"]*1024*1024){
  953. return app('json')->fail("图片不能超过{$uploadConfig["image"]["size"]}M");
  954. }
  955. if(!in_array($code, $uploadConfig['image']['path'])){
  956. return app('json')->fail("上传路径错误");
  957. }
  958. $ext = $file->extension();
  959. if(!in_array($ext, $uploadConfig['image']['ext'])){
  960. return app('json')->fail("图片类型错误");
  961. }
  962. $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
  963. if(!$upPath){
  964. return app('json')->fail("上传失败01");
  965. }
  966. $savePath = $sysData['system_url'].'/resource/' . $upPath;
  967. $imgUrl = str_replace("\\", "/", $savePath);
  968. return app('json')->success(['img'=>$imgUrl,'size'=>$size]);
  969. }
  970. /**
  971. * 视频上传
  972. * @param Request $request
  973. * @return type
  974. */
  975. public function uploadVideo(Request $request){
  976. $uploadConfig = config('filesystem');
  977. $sysData = (new SysModel())->where("id",1)->find();
  978. $file = $request->file('file');
  979. $code = $request->post("code","video");
  980. if(empty($file)) {
  981. return app('json')->fail("未上传文件");
  982. }
  983. if(!in_array($code, $uploadConfig['video']['path'])){
  984. return app('json')->fail("上传路径错误");
  985. }
  986. $ext = $file->extension();
  987. if(!in_array($ext, $uploadConfig['video']['ext'])){
  988. return app('json')->fail("视频类型错误");
  989. }
  990. $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
  991. if(!$upPath){
  992. return app('json')->fail("上传失败01");
  993. }
  994. $savePath = $sysData['system_url'].'/resource/' . $upPath;
  995. $imgUrl = str_replace("\\", "/", $savePath);
  996. return app('json')->success(['video'=>$imgUrl]);
  997. }
  998. /**
  999. * base64文件上传
  1000. * @param type $code
  1001. * @param type $base64
  1002. */
  1003. public function uploadImageBase64($code,$base64,$isQiniu=0){
  1004. $sysData = (new SysModel())->where("id",1)->find();
  1005. $uploadConfig = config('filesystem');
  1006. //验证base64格式
  1007. preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64, $result);
  1008. if(!$result){
  1009. return ["code"=>-1,"msg"=>"base64格式格式错误"];
  1010. }
  1011. //验证图片后缀
  1012. if (!in_array($result[2], $uploadConfig['image']['ext'], true)) {
  1013. return ["code"=>-1,"msg"=>"不支持的图片格式"];
  1014. }
  1015. $rootPath = config('filesystem.disks.resource.root');
  1016. $hashName = $code.DIRECTORY_SEPARATOR.date('Ymd') . DIRECTORY_SEPARATOR . md5((string) microtime(true)).".".$result[2];
  1017. $filePath = $rootPath. DIRECTORY_SEPARATOR .$hashName;
  1018. $path = dirname($filePath);
  1019. // 检测目录
  1020. if (!is_dir($path)) {
  1021. if (!mkdir($path, 0777, true)) {
  1022. return ["code"=>-1,"msg"=>"生成目录失败"];
  1023. }
  1024. return ["code"=>-1,"msg"=>"上传目录不存在"];
  1025. }
  1026. //重名文件验证
  1027. if (is_file($filePath)) {
  1028. return ["code"=>-1,"msg"=>"文件已存在"];
  1029. }
  1030. if(!file_put_contents($filePath, base64_decode(str_replace($result[1], '', $base64)))){
  1031. return ["code"=>-1,"msg"=>"文件报错失败"];
  1032. }
  1033. //七牛上传
  1034. if($isQiniu==1){
  1035. $qiniu = new Qiniu;
  1036. $img_url = $qiniu->updateFile('img', $filePath, $filePath);
  1037. if (empty($img_url['url'])) {
  1038. return ["code"=>-1,"msg"=>"文件报错失败:".$qiniu->getError()];
  1039. }
  1040. @unlink($filePath);
  1041. return ["code"=>1,"url"=>str_replace("\\", "/", $img_url['url'])];
  1042. }
  1043. $savePath = $sysData['system_url'].config('filesystem.disks.resource.url').DIRECTORY_SEPARATOR.$hashName;
  1044. return ["code"=>1,"url"=>str_replace("\\", "/", $savePath)];
  1045. }
  1046. /**
  1047. * 七牛上传图片
  1048. * @param Request $request
  1049. */
  1050. public function qiniuUpload(Request $request)
  1051. {
  1052. $file = $request->file('file');
  1053. if (empty($file)) {
  1054. return app('json')->fail("未上传文件");
  1055. }
  1056. $rootTmp = config('filesystem.disks.local.root') . '/' . \think\facade\Filesystem::putFile('tmp', $file);
  1057. $image_size = @getimagesize($rootTmp);
  1058. if ($image_size[0] > 1000) {
  1059. $imgS = Image::open($rootTmp);
  1060. $imgS->thumb(1000, $image_size[1]);
  1061. $imgS->save($rootTmp);
  1062. } else {
  1063. if ($image_size[1] > 1000) {
  1064. $imgS = Image::open($rootTmp);
  1065. $imgS->thumb($image_size[0], 1000);
  1066. $imgS->save($rootTmp);
  1067. }
  1068. }
  1069. $qiniu = new Qiniu;
  1070. $img_url = $qiniu->updateFile('img', $rootTmp, $rootTmp);
  1071. if (empty($img_url['url'])) {
  1072. return app('json')->fail($qiniu->getError());
  1073. }
  1074. @unlink($rootTmp);
  1075. return app('json')->success(['img' => $img_url['url']]);
  1076. }
  1077. /**
  1078. * 七牛上传token
  1079. * @param Request $request
  1080. */
  1081. public function qiniuUploadToken(Request $request){
  1082. [$bucket] = UtilService::getMore([
  1083. ['bucket', ''],
  1084. ], $request,true);
  1085. $qiniu = new Qiniu;
  1086. $token = $qiniu->createUploadToken($bucket);
  1087. return app('json')->success(['token' => $token]);
  1088. }
  1089. /**
  1090. * 获取用户模板信息
  1091. * @param int $uid 用户ID
  1092. * @return array
  1093. */
  1094. private function getUserInfo($uid)
  1095. {
  1096. $userInfo = (new UserModel)->where('uid', $uid)->find();
  1097. $auth = (new InfoAudit)->where('uid', $uid)->find();
  1098. $user_work_type_title = (new UserWorkType)->where('id', $auth['user_work_type_id'])->find();
  1099. if ($auth) {
  1100. $auth_info = $auth->toArray();
  1101. } else {
  1102. $auth_info = null;
  1103. }
  1104. return [
  1105. 'is_type_audit' => $auth && $auth['status'] == 1 ? 1 : 0,
  1106. 'ancestral_place' => $auth ? $auth['ancestral_place'] : '',
  1107. 'auth_info' => $auth_info,
  1108. 'user_work_type_id' => $user_work_type_title['title'],
  1109. ];
  1110. }
  1111. /**
  1112. * 合约列表
  1113. * @param \app\Request $request
  1114. * @return mixed
  1115. */
  1116. public function getContractList(\think\Request $request)
  1117. {
  1118. // $pageSize = 50;
  1119. // $post = UtilService::getMore([
  1120. // ['page',1],
  1121. // ['pageSize',50],
  1122. // ['nickname',''],
  1123. //// ['uid',''],
  1124. // ['parent_uid',''],
  1125. // ['mobile',''],
  1126. // ['status',''],
  1127. // ['time',[]],
  1128. // ],$request);
  1129. //// $post['uid']=$request->user["uid"];
  1130. // $data = (new UserModel)->getDataList($post,"*",1);
  1131. // return app('json')->success([
  1132. // 'list' => $data["list"],
  1133. // 'pageCount' => $data["totalCount"],
  1134. // 'pageSize' => $data["pageSize"],
  1135. // 'page' => $data["page"],
  1136. // ]);
  1137. $post = UtilService::getMore([
  1138. ['page', 1],
  1139. ['pageSize', 50],
  1140. ['status', -2] //1未签约 2已签约 3已解约
  1141. ], $request);
  1142. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  1143. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  1144. $where = [];
  1145. $uid = UtilService::getMore([
  1146. ['uid', 0],
  1147. ], $request);
  1148. $uid = $uid['uid'];
  1149. // if ($uid>0){
  1150. // $where[]=["uid","=",$uid];
  1151. // }
  1152. $totalCount = (new UserContractRecordModel)->where($where)
  1153. ->when($uid > 0, function ($query) use ($uid) {
  1154. $query->where(function ($query) use ($uid) {
  1155. $query->where('uid', $uid)
  1156. ->whereOr('to_uid', $uid);
  1157. });
  1158. })->count();
  1159. if ($post["status"] != -2) {
  1160. $where[] = ['status', '=', $post["status"]];
  1161. }
  1162. $data = null;
  1163. if ($totalCount > 0) {
  1164. $data = (new UserContractRecordModel)
  1165. ->where($where)
  1166. ->when($uid > 0, function ($query) use ($uid) {
  1167. $query->where(function ($query) use ($uid) {
  1168. $query->where('uid', $uid)
  1169. ->whereOr('to_uid', $uid);
  1170. });
  1171. })
  1172. ->order("id", "desc")
  1173. ->page($post["page"], $post["pageSize"])
  1174. ->select();
  1175. // var_dump((new UserContractRecordModel)->getLastSql());die();
  1176. foreach ($data as $k => $v) {
  1177. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  1178. switch ($data[$k]["status"]) {
  1179. case 0:
  1180. $data[$k]["status_name"] = "未签约";
  1181. break;
  1182. case 1:
  1183. $data[$k]["status_name"] = "已签约";
  1184. break;
  1185. case -1:
  1186. $data[$k]["status_name"] = "已解约";
  1187. break;
  1188. }
  1189. // $data[$k]["comment"] = (new ContractCommentModel())->where('contract_id',$v["id"])->select();
  1190. $data[$k]["comment"] = (new ContractCommentModel())->where('contract_id', $v["id"])->find();
  1191. if (!empty($data[$k]["comment"])) {
  1192. $data[$k]["comment"] = $data[$k]["comment"]->toArray();
  1193. }
  1194. }
  1195. }
  1196. $data = empty($data) ? [] : $data;
  1197. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  1198. }
  1199. /**
  1200. * 甲方创建合约
  1201. */
  1202. public function form_save(Request $request)
  1203. {
  1204. $post = UtilService::getMore([
  1205. ['id', 0],
  1206. ['uid', '0'], //甲方uid
  1207. // ['name', ''], //甲方姓名
  1208. // ['phone', ''], //甲方手机号
  1209. // ['address', ''], //甲方地址
  1210. // ['card', ''], //甲方身份证号
  1211. ['to_uid', 0], //员工uid
  1212. ['to_name', ''], //乙方姓名
  1213. // ['price', 0], //服务费
  1214. // ['deposit', 0], // 定金
  1215. // ['balance', 0], //余款
  1216. // ['period', 0], // 周期天数
  1217. ['start_time', ''], // 开始时间
  1218. ['end_time', ''], // 结束时间
  1219. // ['mark', ''], //备注
  1220. ['content', []], //备注
  1221. ['template_id', 0], //合同模板id
  1222. ['longitude', ''], //经度
  1223. ['latitude', ''] //纬度
  1224. // ['uid_img',''] //甲方签名图片路径
  1225. // ['to_phone',''].
  1226. // ['to_address',''],
  1227. // ['to_card',''],
  1228. // ['data',[]],
  1229. // ['year',''],
  1230. // ['month',''],
  1231. // ['day',''],
  1232. ], $request);
  1233. $id = (int)$post["id"];
  1234. unset($post["id"]);
  1235. $uid = (int)$post["uid"];
  1236. if (empty($uid)) {
  1237. return app('json')->fail("参数错误");
  1238. }
  1239. // $post['content'] = $post['content'];
  1240. $post['start_time'] = strtotime($post['start_time']);
  1241. $post['end_time'] = strtotime($post['end_time'] . ' 23:59:59');
  1242. $start = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('start_time', [$post['start_time'], $post['end_time']])->find();
  1243. $end = (new UserContractRecordModel)->where('to_uid', $post['to_uid'])->where('status', 1)->whereBetween('end_time', [$post['start_time'], $post['end_time']])->find();
  1244. // $start2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('start_time',[$post['start_time'],$post['end_time']])->find();
  1245. // $end2=(new UserContractRecordModel)->where('to_uid',$post['to_uid'])->where('status',0)->whereBetween('end_time',[$post['start_time'],$post['end_time']])->find();
  1246. // if (!empty($start)||!empty($end)||!empty($start2)||!empty($end2)){
  1247. if (!empty($start) || !empty($end)) {
  1248. return app('json')->fail("与对方其他合约时间有冲突,请与对方协商");
  1249. }
  1250. // $year = $post['year'];
  1251. // $month = $post['month'];
  1252. // $day = $post['day'];
  1253. //
  1254. //// 检查年月日是否为空
  1255. // if (empty($year) || empty($month) || empty($day)) {
  1256. // return app('json')->fail("日期参数错误");
  1257. // }
  1258. //
  1259. //// 创建 DateTime 对象
  1260. // $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
  1261. //
  1262. //// 检查日期是否有效
  1263. // if (!$date || $date->format('Y-m-d') !== "$year-$month-$day") {
  1264. // return app('json')->fail("无效的日期");
  1265. // }
  1266. // unset($post['year']);
  1267. // unset($post['month']);
  1268. // unset($post['day']);
  1269. //// 转换为时间戳
  1270. // $timestamp = $date->getTimestamp();
  1271. //
  1272. // $post['create_time'] = $timestamp;
  1273. //用户信息
  1274. // if(!empty($post["uid_img"])){
  1275. // $post['status'] = 2;
  1276. // }else{
  1277. $post['status'] = 0;
  1278. // }
  1279. if ($id > 0) {
  1280. $r = (new UserContractRecordModel)->where("id", $id)->update($post);
  1281. } else {
  1282. $post['contract_no'] = makeOrderId($post['uid'], "CR");
  1283. $r = (new UserContractRecordModel)->save($post);
  1284. }
  1285. return app('json')->success("数据保存成功");
  1286. }
  1287. /**
  1288. * 甲方签约合约
  1289. */
  1290. public function check(Request $request)
  1291. {
  1292. $post = UtilService::getMore([
  1293. ['id', 0], //合约id
  1294. ['uid_img', ''], //甲方签名图片路径
  1295. ['check_time', ''],//签约时间
  1296. ['content', []]//签约内容
  1297. // ['to_phone',''].
  1298. // ['to_address',''],
  1299. // ['to_card',''],
  1300. // ['data',[]],
  1301. // ['year',''],
  1302. // ['month',''],
  1303. // ['day',''],
  1304. ], $request);
  1305. $info = (new UserContractRecordModel)->where("id", $post["id"])->find();
  1306. if (empty($info)) {
  1307. return app('json')->fail("合约不存在");
  1308. }
  1309. $post['content'] = json_encode($post['content']);
  1310. // 检查签约时间是否为空
  1311. if (empty($post['uid_img'])) {
  1312. return app('json')->fail("签字错误");
  1313. }
  1314. // 检查签约时间是否为空
  1315. if (empty($post['check_time'])) {
  1316. return app('json')->fail("日期参数错误");
  1317. }
  1318. $post['check_time'] = strtotime($post['check_time']);
  1319. // $post['status'] = 1;
  1320. $post['from_check'] = 1;
  1321. if ($info['to_check'] == 1) {
  1322. $post['status'] = 1;
  1323. }
  1324. // $post['contract_no'] = makeOrderId($post['uid'],"CR");
  1325. $r = (new UserContractRecordModel)->where("id", $post["id"])->update($post);
  1326. return app('json')->success("数据保存成功");
  1327. }
  1328. // 乙方确认
  1329. public function to_check(Request $request)
  1330. {
  1331. $post = UtilService::getMore([
  1332. ['id', '0'], //
  1333. ['to_uid_img', ''], //乙方签名图片路径
  1334. ['content', []], //内容
  1335. // ['to_phone', ''], //乙方手机号
  1336. // ['to_address', ''], //乙方地址
  1337. // ['to_card', ''], //乙方身份证号
  1338. ['to_check_time', '']//签约时间
  1339. ], $request);
  1340. $info = (new UserContractRecordModel)->where("id", $post["id"])->find();
  1341. if (empty($info)) {
  1342. return app('json')->fail("合约不存在");
  1343. }
  1344. // 检查签约时间是否为空
  1345. if (empty($post['to_uid_img'])) {
  1346. return app('json')->fail("签字错误");
  1347. }
  1348. // 检查签约时间是否为空
  1349. if (empty($post['to_check_time'])) {
  1350. return app('json')->fail("日期参数错误");
  1351. }
  1352. $post['to_check_time'] = strtotime($post['to_check_time']);
  1353. $post['to_check'] = 1;
  1354. if ($info['from_check'] == 1) {
  1355. $post['status'] = 1;
  1356. }
  1357. $post['content'] = json_encode($post['content']);
  1358. $r = (new UserContractRecordModel)->where("id", $post["id"])->update($post);
  1359. return app('json')->success("数据保存成功");
  1360. }
  1361. // 员工签到
  1362. public function clock_in(Request $request)
  1363. {
  1364. $post = UtilService::getMore([
  1365. ['contract_id', '0'], //合约id
  1366. ['longitude', ''], //经度
  1367. ['latitude', ''], //纬度
  1368. ['content', ''], //工作内容
  1369. // ['uid',0]
  1370. ], $request);
  1371. $uid = UtilService::getMore([
  1372. ['uid', 0],
  1373. ], $request);
  1374. $uid = $uid['uid'];
  1375. // $uid = (int)$post["uid"];
  1376. // 检查签约时间是否为空
  1377. if (empty($post['contract_id'])) {
  1378. return app('json')->fail("签字错误");
  1379. }
  1380. $time = time();
  1381. $info = (new UserContractRecordModel)->where('status',1)->where("id", $post["contract_id"])->where('start_time', '<', $time)->where('end_time', '>', $time)->find();
  1382. if (!empty($info)) {
  1383. $info = $info->toArray();
  1384. } else {
  1385. return app('json')->fail("合约未签约或已解约");
  1386. }
  1387. // $nickname=\app\model\api\User::where('uid',$uid)->value('nickname');
  1388. $r = (new UserClockModel)->save([
  1389. 'uid' => $uid,
  1390. 'nickname' => $info['to_name'],
  1391. 'longitude' => $post['longitude'],
  1392. 'latitude' => $post['latitude'],
  1393. 'contract_id' => $post['contract_id'],
  1394. 'content' => $post['content'],
  1395. 'create_time' => time()
  1396. ]);
  1397. return app('json')->success("数据保存成功");
  1398. }
  1399. // 添加客户评论
  1400. public function comment(Request $request)
  1401. {
  1402. $post = UtilService::getMore([
  1403. ['contract_id', '0'], //合约id
  1404. ['content', ''], //评论内容
  1405. ['imgs', []], //图片数组,新增
  1406. // ['uid',0]
  1407. ], $request);
  1408. $uid = UtilService::getMore([
  1409. ['uid', 0],
  1410. ], $request);
  1411. if($uid==0){
  1412. $uid = $request->param('uid', 0);
  1413. }else{
  1414. $uid = $uid['uid'];
  1415. }
  1416. $time = time();
  1417. $info = (new UserContractRecordModel)->where("id", $post["contract_id"])->find();
  1418. if (!empty($info)) {
  1419. $info = $info->toArray();
  1420. } else {
  1421. return app('json')->fail("没有签约中的合约");
  1422. }
  1423. if ($info['status'] != 1) {
  1424. return app('json')->fail("只有签约状态才能发表评论");
  1425. }
  1426. if ($info['start_time'] > $time || $info['end_time'] < $time) {
  1427. return app('json')->fail("只能在签约期间才能发表评论");
  1428. }
  1429. // 处理图片数组,用逗号连接成字符串
  1430. $imgs_str = '';
  1431. if (!empty($post['imgs']) && is_array($post['imgs'])) {
  1432. $imgs_str = implode(',', $post['imgs']);
  1433. }
  1434. $r = (new ContractCommentModel)->save([
  1435. 'uid' => $uid,
  1436. 'name' => $info['name'],
  1437. 'contract_id' => $post['contract_id'],
  1438. 'contract_no' => $info['contract_no'],
  1439. 'to_uid' => $info['to_uid'],
  1440. 'to_name' => $info['to_name'],
  1441. 'content' => $post['content'],
  1442. 'imgs' => $imgs_str, //新增图片字段
  1443. 'create_time' => time()
  1444. ]);
  1445. return app('json')->success("数据保存成功");
  1446. }
  1447. // 甲方主动解约
  1448. public function lift_contract(Request $request)
  1449. {
  1450. $post = UtilService::getMore([
  1451. ['contract_id', '0'], //合约id
  1452. // ['uid',0]
  1453. ], $request);
  1454. // 检查签约时间是否为空
  1455. if (empty($post['contract_id'])) {
  1456. return app('json')->fail("没有该合约");
  1457. }
  1458. $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([
  1459. 'status' => -1,
  1460. 'delete_time' => time()
  1461. ]);
  1462. return app('json')->success("解约成功");
  1463. }
  1464. // 乙方主动解约
  1465. public function right_contract(Request $request)
  1466. {
  1467. $post = UtilService::getMore([
  1468. ['contract_id', '0'], //合约id
  1469. // ['uid',0]
  1470. ], $request);
  1471. // 检查签约时间是否为空
  1472. if (empty($post['contract_id'])) {
  1473. return app('json')->fail("没有该合约");
  1474. }
  1475. $r = (new UserContractRecordModel())->where('id', $post['contract_id'])->update([
  1476. 'status' => -1,
  1477. 'delete_time' => time()
  1478. ]);
  1479. return app('json')->success("解约成功");
  1480. }
  1481. // 打卡列表
  1482. /**
  1483. * 打卡列表
  1484. * @param \app\Request $request
  1485. * @return mixed
  1486. */
  1487. public function getClockList(\think\Request $request)
  1488. {
  1489. $post = UtilService::getMore([
  1490. ['page', 1],
  1491. ['pageSize', 50],
  1492. ['time', ''],
  1493. ['contract_id',0]
  1494. ], $request);
  1495. $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"];
  1496. $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
  1497. $where = [];
  1498. $uid = UtilService::getMore([
  1499. ['uid', 0],
  1500. ], $request);
  1501. $uid = $uid['uid'];
  1502. if ($uid > 0) {
  1503. $where[] = ["uid", "=", $uid];
  1504. }
  1505. if (!empty($post['time'])) {
  1506. $start_time = strtotime($post['time']);
  1507. $end_time = $start_time + 86400;
  1508. // 将时间范围添加到查询条件中
  1509. $where[] = ["create_time", ">=", $start_time];
  1510. $where[] = ["create_time", "<", $end_time];
  1511. // $where[] = ["create_time",'=',strtotime($post['time'])];
  1512. }
  1513. if ($post['contract_id']>0){
  1514. $where[] = ["contract_id",'=',$post['contract_id']];
  1515. }
  1516. $totalCount = (new UserClockModel())->where($where)->count();
  1517. $data = null;
  1518. if ($totalCount > 0) {
  1519. $data = (new UserClockModel)
  1520. ->where($where)
  1521. ->order("id", "desc")
  1522. ->page($post["page"], $post["pageSize"])
  1523. ->select();
  1524. }
  1525. $data = empty($data) ? [] : $data;
  1526. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]);
  1527. }
  1528. // 合同模板详情接口
  1529. public function getContractTemplatInfo($id)
  1530. {
  1531. $data = (new ContractTemplate())
  1532. ->field("*")
  1533. ->where("id", $id)
  1534. ->where("is_show",1)
  1535. ->find();
  1536. if (empty($data)) {
  1537. return app('json')->fail("模板不存在");
  1538. }
  1539. // if ($data["is_init"] == 0 && $data["status"] != 1) {
  1540. // return app('json')->fail("模板已下架");
  1541. // }
  1542. $data = $data->toArray();
  1543. // $data["is_use"] = 0;
  1544. $data["imgs"] = getImageAr($data["imgs"]);
  1545. $data['content'] = json_decode($data['content']);
  1546. $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  1547. $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  1548. $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  1549. // $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  1550. // unset($data["real_sales"]);
  1551. unset($data["code"]);
  1552. //验证是否购买过并添加浏览记录
  1553. // $this->checkUser(request()->header("token", ""));
  1554. // if (!empty($this->user)) {
  1555. // $data["is_use"] = (new UserShowTemplate)->where("uid", $this->user["uid"])->where("show_template_id", $data["id"])->count() > 0 ? 1 : 0;
  1556. // (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  1557. // }
  1558. return app('json')->success($data);
  1559. }
  1560. // 合同详情接口
  1561. public function getContractRecordInfo($id)
  1562. {
  1563. // 合约详情
  1564. $data = (new UserContractRecordModel())
  1565. ->field("*")
  1566. ->where("id", $id)
  1567. // ->where("is_show",1)
  1568. ->find();
  1569. if (empty($data)) {
  1570. return app('json')->fail("合约不存在");
  1571. }
  1572. $data = $data->toArray();
  1573. // $data['content'] = $data['content'];
  1574. // 模版详情
  1575. $data2 = (new ContractTemplate())->where('id',$data['template_id'])->find();
  1576. if (empty($data2)) {
  1577. return app('json')->fail("模板不存在");
  1578. }
  1579. $data2 -> toArray();
  1580. // $data["is_use"] = 0;
  1581. $data["imgs"] = getImageAr($data2["imgs"]);
  1582. $data['template_content'] = json_decode($data2['content']);
  1583. $data['template_title'] = $data2['title'];
  1584. $data["img"] = empty($data["imgs"]) ? "" : $data["imgs"][0];
  1585. // $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  1586. // $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  1587. // $data["sales_count"] = $data["real_sales"] + $data["unreal_sales"];
  1588. // unset($data["real_sales"]);
  1589. unset($data["code"]);
  1590. //验证是否购买过并添加浏览记录
  1591. // $this->checkUser(request()->header("token", ""));
  1592. // if (!empty($this->user)) {
  1593. // $data["is_use"] = (new UserShowTemplate)->where("uid", $this->user["uid"])->where("show_template_id", $data["id"])->count() > 0 ? 1 : 0;
  1594. // (new ShowTemplate)->where('id', $data["id"])->inc('look_count', 1)->update();
  1595. // }
  1596. return app('json')->success($data);
  1597. }
  1598. /**
  1599. * 积分明细列表(API端)
  1600. * @param Request $request
  1601. * @return mixed
  1602. */
  1603. public function scoreDetailList(Request $request)
  1604. {
  1605. $post = UtilService::getMore([
  1606. ['page', 1],
  1607. ['pageSize', 20],
  1608. ['type', -1], // 1收入 -1支出
  1609. ['order_sn', ''],
  1610. ], $request);
  1611. $uid = UtilService::getMore([
  1612. ['uid', 0],
  1613. ], $request);
  1614. $uid = $uid['uid'];
  1615. if (!$uid) {
  1616. return app('json')->fail('用户未登录');
  1617. }
  1618. $where = [];
  1619. $where[] = ['uid', '=', $uid];
  1620. // if (!empty($post['type'])) {
  1621. if ($post['type'] >-1){
  1622. $where[] = ['type', '=', $post['type']];
  1623. }
  1624. // }
  1625. if (!empty($post['order_sn'])) {
  1626. $where[] = ['order_id', 'like', '%' . $post['order_sn'] . '%'];
  1627. }
  1628. $pageSize = $post['pageSize'] > 50 ? 50 : (int)$post['pageSize'];
  1629. $page = $post['page'] <= 0 ? 1 : (int)$post['page'];
  1630. $totalCount = (new UserScoreDetail())->where($where)->count();
  1631. $list = [];
  1632. if ($totalCount > 0) {
  1633. $list = (new UserScoreDetail())
  1634. ->where($where)
  1635. ->order('id', 'desc')
  1636. ->page($page, $pageSize)
  1637. ->select()
  1638. ->toArray();
  1639. $sql = (new UserScoreDetail())->getLastSql();
  1640. @file_put_contents('quanju.txt', $sql. "-积分列表sql语句\r\n", 8);
  1641. // 格式化时间
  1642. foreach ($list as &$item) {
  1643. $item['time'] = date('Y-m-d H:i:s', $item['time']);
  1644. $item['type_name'] = $item['type'] == 1 ? '收入' : '支出';
  1645. }
  1646. }
  1647. return app('json')->success([
  1648. 'list' => $list,
  1649. 'pageSize' => $pageSize,
  1650. 'page' => $page,
  1651. 'totalCount' => $totalCount
  1652. ]);
  1653. }
  1654. }