User.php 63 KB

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