User.php 53 KB

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