User.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\controller\general\Profile;
  4. use app\common\controller\Api;
  5. use app\common\controller\DescribeFaceVerify;
  6. use app\common\controller\InitFaceVerify;
  7. use app\common\library\Ems;
  8. use app\common\library\Sms;
  9. use app\common\model\Activity;
  10. use app\common\model\Apply;
  11. use app\common\model\Area;
  12. use app\common\model\EducationAuthentication;
  13. use app\common\model\Like;
  14. use app\common\model\MoneyLog;
  15. use app\common\model\Order;
  16. use app\common\model\Selection;
  17. use app\common\model\Shield;
  18. use app\common\model\SystemMessages;
  19. use app\common\model\Unlockprogress;
  20. use app\common\model\UserObject;
  21. use app\common\model\WorkAuthentication;
  22. use fast\Random;
  23. use http\Params;
  24. use think\Config;
  25. use think\Db;
  26. use think\Exception;
  27. use think\Request;
  28. use think\Validate;
  29. use app\common\model\User as UserModel;
  30. use addons\epay\controller\Api as payApi;
  31. use app\api\controller\Common;
  32. use function MongoDB\BSON\fromJSON;
  33. /**
  34. * 会员接口
  35. */
  36. class User extends Api
  37. {
  38. protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
  39. protected $noNeedRight = '*';
  40. public function _initialize()
  41. {
  42. parent::_initialize();
  43. if (!Config::get('fastadmin.usercenter')) {
  44. $this->error(__('User center already closed'));
  45. }
  46. }
  47. /**
  48. * 会员中心
  49. * @ApiReturnParams(name="integrity", description='个人资料进度')
  50. * @ApiReturnParams(name="ilike", description='我喜欢的')
  51. * @ApiReturnParams(name="likeme", description='喜欢我的')
  52. * @ApiReturnParams(name="apply", description='申请我的')
  53. * @ApiReturnParams(name="authentication", description='认证数量')
  54. */
  55. public function index()
  56. {
  57. $uid = $this->auth->id;
  58. $userinfo = UserModel::where('id',$uid)
  59. ->with('userObject.education,education')
  60. ->find()
  61. ->toArray();
  62. $userinfo['integrity'] = $this->integrity();
  63. $userinfo['ilike'] = Like::where(['uid'=>$uid,'type'=>1])->count();
  64. $userinfo['likeme'] = Like::where(['nid'=>$uid,'type'=>1])->count();
  65. $userinfo['apply'] = Apply::where('nid',$uid)->count();
  66. $userinfo['lookme'] = Like::where(['nid'=>$uid,'type'=>2])->count();
  67. //未解锁数量
  68. $userinfo['likeme_subscript'] = Like::where(['nid'=>$uid,'type'=>1,'is_read'=>0])->count();
  69. $userinfo['apply_subscript'] = Apply::where(['nid'=>$uid,'n_is_read'=>0])->count();
  70. $userinfo['lookme_subscript'] = Like::where(['nid'=>$uid,'type'=>2,'is_read'=>0])->count();
  71. $userinfo['authentication'] = 0;
  72. $userinfo['id_authentication']?$userinfo['authentication']++:'';
  73. $userinfo['work_authentication']?$userinfo['authentication']++:'';
  74. $userinfo['education_authentication']?$userinfo['authentication']++:'';
  75. $userinfo['photo'] = explode(',',$userinfo['photo']);
  76. $userinfo['age'] = getAge($userinfo['birthday']);;
  77. //城市
  78. $userinfo['province_name'] = Area::where('id',$userinfo['province'])->value('name');
  79. $userinfo['city_name'] = Area::where('id',$userinfo['city'])->value('name');
  80. $userinfo['area_name'] = Area::where('id',$userinfo['area'])->value('name');
  81. $this->success('', ['welcome' => $userinfo]);
  82. }
  83. //计算信息完整度百分比
  84. public function integrity(){
  85. $userinfo = UserModel::where('id',$this->auth->id)
  86. ->field('avatar,username,id,birthday,marriage,children,height,education,school,work,max_income,region_province,region_city,region_area,futurehometown,marriedtime,wx,signature,photo,tag,constellation,house,car,father_work,mother_work,brother,work_authentication,education_authentication,id_authentication,familyhow,objecthow,mehow')
  87. ->find()
  88. ->toArray();
  89. $userobject = UserObject::where('uid',$this->auth->id)->find()->toArray();
  90. $sum = count($userinfo) + count($userobject);
  91. $cpl = round( ($this->count_($userinfo)+$this->count_($userobject))/$sum * 100) . "%";
  92. return $cpl;
  93. }
  94. //计算用户信息数量
  95. public function count_($arr){
  96. foreach ($arr as $k=>$v){
  97. if($v == ''){
  98. unset($arr[$k]);
  99. }
  100. }
  101. return count($arr);
  102. }
  103. /**
  104. * 我喜欢的/喜欢我的/申请我的/看了我的列表
  105. * @ApiMethod (POST)
  106. * @ApiParams (name="type",description="1我喜欢的 2喜欢我的 3申请我的 4看了我的")
  107. */
  108. public function dynamic(){
  109. $uid = $this->auth->id;
  110. $type = input('type');
  111. if($type==1){
  112. $ilike = Like::where(['uid'=>$uid,'type'=>1])
  113. ->with('Nuser')
  114. ->order('id','desc')
  115. ->select();
  116. $res = $ilike;
  117. }elseif($type==2){
  118. $ilike = Like::where(['nid'=>$uid,'type'=>1])
  119. ->with('Uuser')
  120. ->order('id','desc')
  121. ->select();
  122. foreach ($ilike as $k=>$v){
  123. Like::get(['uid'=>$uid,'nid'=>$v['uid']])??$ilike[$k]['like']=1;
  124. Unlockprogress::get(['uid'=>$v['nid'],'nid'=>$v['uid']])?$ilike[$k]['Unlockprogress']=1:$ilike[$k]['Unlockprogress']=null;
  125. }
  126. $res = $ilike;
  127. }elseif($type==3){
  128. $ilike = Apply::where(['nid'=>$uid])
  129. ->with('uidinfo')
  130. ->order('id','desc')
  131. ->select();
  132. $res = $ilike;
  133. Apply::n_read($ilike);
  134. }elseif($type==4){
  135. $ilike = Like::where(['nid'=>$uid,'type'=>2])
  136. ->with('Uuser')
  137. ->order('id','desc')
  138. ->select();
  139. foreach ($ilike as $k=>$v){
  140. Unlockprogress::get(['uid'=>$v['nid'],'nid'=>$v['uid']])?$ilike[$k]['Unlockprogress']=1:$ilike[$k]['Unlockprogress']=null;
  141. }
  142. $res = $ilike;
  143. Like::read($ilike);
  144. }
  145. $this->success('',$res);
  146. }
  147. /**
  148. * 解锁资料
  149. * @ApiMethod (POST)
  150. * @ApiParams (name="type",description="1解锁喜欢我的2解锁访客")
  151. * @ApiParams (name="nid")
  152. */
  153. public function unlock(){
  154. $uid = $this->auth->id;
  155. $nid = $this->request->post('nid');
  156. $type = $this->request->post('type');
  157. if(!$nid || !$type){
  158. $this->error('参数缺失');
  159. }
  160. $user = Unlockprogress::where(['uid'=>$this->auth->id,'nid'=>$nid])->find();
  161. if($user)$this->error('您已解锁');
  162. if($type == 1){
  163. $cost = config('site.expenditure_grain')['查看收藏我的'];
  164. if($cost>$this->auth->money)$this->error('余额不足');
  165. Db::startTrans();
  166. try {
  167. $data = [
  168. 'uid'=>$uid,
  169. 'nid'=>$nid,
  170. 'status'=>2
  171. ];
  172. Unlockprogress::insert($data);
  173. $look = [
  174. 'uid'=>$uid,
  175. 'nid'=>$nid,
  176. 'type'=>2,
  177. 'status'=>0
  178. ];
  179. Like::insert($look);
  180. UserModel::money(-$cost,$uid,'解锁喜欢我的资料');
  181. Db::commit();
  182. $this->success('解锁成功');
  183. }catch (Exception $e){
  184. Db::rollback();
  185. $this->error($e);
  186. return false;
  187. }
  188. }elseif($type == 2){
  189. $cost = config('site.expenditure_grain')['查看访客'];
  190. if($cost>$this->auth->money)$this->error('余额不足');
  191. Db::startTrans();
  192. try {
  193. $data = [
  194. 'uid'=>$uid,
  195. 'nid'=>$nid,
  196. 'status'=>2
  197. ];
  198. Unlockprogress::insert($data);
  199. $look = [
  200. 'uid'=>$uid,
  201. 'nid'=>$nid,
  202. 'type'=>2,
  203. 'status'=>0
  204. ];
  205. Like::insert($look);
  206. UserModel::money(-$cost,$uid,'解锁访客资料');
  207. Db::commit();
  208. $this->success('解锁成功');
  209. }catch (Exception $e){
  210. Db::rollback();
  211. $this->error($e);
  212. return false;
  213. }
  214. }
  215. }
  216. /**
  217. * 申请我的操作
  218. * @param string $id id
  219. * @param string $type 1同意2拒绝
  220. */
  221. public function applyop(){
  222. $type = input('type');
  223. $apply = Apply::get(['status'=>0,'id'=>input('id')]);
  224. if(!$apply)$this->error('数据异常');
  225. if($type==1){
  226. $apply->save(['status'=>1]);
  227. $this->success('已同意',$apply);
  228. }elseif($type==2){
  229. $grain = $apply['grain']*0.5;
  230. UserModel::money($grain,$apply['uid'],'拒绝认识申请,退还狗粮');
  231. $apply->save(['status'=>2,'refund_grain'=>$grain]);
  232. $this->success('已拒绝',$apply);
  233. }
  234. }
  235. /**
  236. * 会员登录
  237. *
  238. * @ApiMethod (POST)
  239. * @param string $account 账号
  240. * @param string $password 密码
  241. */
  242. public function login()
  243. {
  244. $account = $this->request->post('account');
  245. $password = $this->request->post('password');
  246. if (!$account || !$password) {
  247. $this->error(__('Invalid parameters'));
  248. }
  249. $ret = $this->auth->login($account, $password);
  250. if ($ret) {
  251. $data = ['userinfo' => $this->auth->getUserinfo()];
  252. $this->success(__('Logged in successful'), $data);
  253. } else {
  254. $this->error($this->auth->getError());
  255. }
  256. }
  257. /**
  258. * 手机验证码登录
  259. *
  260. * @ApiMethod (POST)
  261. * @param string $mobile 手机号
  262. * @param string $captcha 验证码
  263. * @param string $code code
  264. */
  265. public function mobilelogin()
  266. {
  267. $mobile = $this->request->post('mobile');
  268. $captcha = $this->request->post('captcha');
  269. $code = $this->request->post('code');
  270. $inviter_id = $this->request->post('inviter_id');
  271. if (!$mobile || !$captcha || !$code) {
  272. $this->error(__('Invalid parameters'));
  273. }
  274. if (!Validate::regex($mobile, "^1\d{10}$")) {
  275. $this->error(__('Mobile is incorrect'));
  276. }
  277. // if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  278. // $this->error(__('Captcha is incorrect'));
  279. // }
  280. $user = \app\common\model\User::getByMobile($mobile);
  281. $wx_userinfo = (new \app\api\controller\Common())->getUserinfo($code);
  282. if ($user) {
  283. if ($user->status != 'normal') {
  284. $this->error('用户已注销');
  285. }
  286. //如果已经有账号则直接登录
  287. $ret = $this->auth->direct($user->id,$wx_userinfo['openid']);
  288. } else {
  289. $ret = $this->auth->register($wx_userinfo['nickname'], Random::alnum(), '', $mobile, [],$wx_userinfo['openid'],$inviter_id);
  290. //注册奖励
  291. $u = new \app\common\model\User();
  292. $u->registerAward($this->auth->id);
  293. }
  294. if ($ret) {
  295. Sms::flush($mobile, 'mobilelogin');
  296. $data = ['userinfo' => $this->auth->getUserinfo()];
  297. $data['openid'] = $wx_userinfo['openid'];
  298. $this->success(__('Logged in successful'), $data);
  299. } else {
  300. $this->error($this->auth->getError());
  301. }
  302. }
  303. // /**
  304. // * 注册会员
  305. // *
  306. // * @ApiMethod (POST)
  307. // * @param string $username 用户名
  308. // * @param string $password 密码
  309. // * @param string $email 邮箱
  310. // * @param string $mobile 手机号
  311. // * @param string $code 验证码
  312. // */
  313. // public function register()
  314. // {
  315. // $username = $this->request->post('username');
  316. // $password = $this->request->post('password');
  317. // $email = $this->request->post('email');
  318. // $mobile = $this->request->post('mobile');
  319. // $code = $this->request->post('code');
  320. // if (!$username || !$password) {
  321. // $this->error(__('Invalid parameters'));
  322. // }
  323. // if ($email && !Validate::is($email, "email")) {
  324. // $this->error(__('Email is incorrect'));
  325. // }
  326. // if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
  327. // $this->error(__('Mobile is incorrect'));
  328. // }
  329. // $ret = Sms::check($mobile, $code, 'register');
  330. // if (!$ret) {
  331. // $this->error(__('Captcha is incorrect'));
  332. // }
  333. // $ret = $this->auth->register($username, $password, $email, $mobile, []);
  334. // if ($ret) {
  335. // $data = ['userinfo' => $this->auth->getUserinfo()];
  336. // $this->success(__('Sign up successful'), $data);
  337. // } else {
  338. // $this->error($this->auth->getError());
  339. // }
  340. // }
  341. /**
  342. * 退出登录
  343. * @ApiMethod (POST)
  344. */
  345. public function logout()
  346. {
  347. if (!$this->request->isPost()) {
  348. $this->error(__('Invalid parameters'));
  349. }
  350. $this->auth->logout();
  351. $this->success(__('Logout successful'));
  352. }
  353. /**
  354. * 修改会员个人信息
  355. *
  356. * @ApiMethod (POST)
  357. * @param string $avatar 头像地址
  358. * @param string $username 用户名
  359. * @param string $nickname 昵称
  360. * @param string $bio 个人简介
  361. */
  362. public function profile()
  363. {
  364. $user = $this->auth->getUser();
  365. $username = $this->request->post('username');
  366. $nickname = $this->request->post('nickname');
  367. $bio = $this->request->post('bio');
  368. $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
  369. if ($username) {
  370. $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
  371. if ($exists) {
  372. $this->error(__('Username already exists'));
  373. }
  374. $user->username = $username;
  375. }
  376. if ($nickname) {
  377. $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
  378. if ($exists) {
  379. $this->error(__('Nickname already exists'));
  380. }
  381. $user->nickname = $nickname;
  382. }
  383. $user->bio = $bio;
  384. $user->avatar = $avatar;
  385. $user->save();
  386. $this->success();
  387. }
  388. /**
  389. * 修改手机号
  390. *
  391. * @ApiMethod (POST)
  392. * @param string $mobile 手机号
  393. * @param string $captcha 验证码
  394. */
  395. public function changemobile()
  396. {
  397. $user = $this->auth->getUser();
  398. $mobile = $this->request->post('mobile');
  399. $captcha = $this->request->post('captcha');
  400. if (!$mobile || !$captcha) {
  401. $this->error(__('Invalid parameters'));
  402. }
  403. if (!Validate::regex($mobile, "^1\d{10}$")) {
  404. $this->error(__('Mobile is incorrect'));
  405. }
  406. if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
  407. $this->error(__('Mobile already exists'));
  408. }
  409. $result = Sms::check($mobile, $captcha, 'changemobile');
  410. if (!$result) {
  411. $this->error(__('Captcha is incorrect'));
  412. }
  413. $verification = $user->verification;
  414. $verification->mobile = 1;
  415. $user->verification = $verification;
  416. $user->mobile = $mobile;
  417. $user->save();
  418. Sms::flush($mobile, 'changemobile');
  419. $this->success();
  420. }
  421. // /**
  422. // * 第三方登录
  423. // *
  424. // * @ApiMethod (POST)
  425. // * @param string $platform 平台名称
  426. // * @param string $code Code码
  427. // */
  428. // public function third()
  429. // {
  430. // $url = url('user/index');
  431. // $platform = $this->request->post("platform");
  432. // $code = $this->request->post("code");
  433. // $config = get_addon_config('third');
  434. // if (!$config || !isset($config[$platform])) {
  435. // $this->error(__('Invalid parameters'));
  436. // }
  437. // $app = new \addons\third\library\Application($config);
  438. // //通过code换access_token和绑定会员
  439. // $result = $app->{$platform}->getUserInfo(['code' => $code]);
  440. // if ($result) {
  441. // $loginret = \addons\third\library\Service::connect($platform, $result);
  442. // if ($loginret) {
  443. // $data = [
  444. // 'userinfo' => $this->auth->getUserinfo(),
  445. // 'thirdinfo' => $result
  446. // ];
  447. // $this->success(__('Logged in successful'), $data);
  448. // }
  449. // }
  450. // $this->error(__('Operation failed'), $url);
  451. // }
  452. // /**
  453. // * 重置密码
  454. // *
  455. // * @ApiMethod (POST)
  456. // * @param string $mobile 手机号
  457. // * @param string $newpassword 新密码
  458. // * @param string $captcha 验证码
  459. // */
  460. // public function resetpwd()
  461. // {
  462. // $type = $this->request->post("type");
  463. // $mobile = $this->request->post("mobile");
  464. // $email = $this->request->post("email");
  465. // $newpassword = $this->request->post("newpassword");
  466. // $captcha = $this->request->post("captcha");
  467. // if (!$newpassword || !$captcha) {
  468. // $this->error(__('Invalid parameters'));
  469. // }
  470. // //验证Token
  471. // if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  472. // $this->error(__('Password must be 6 to 30 characters'));
  473. // }
  474. // if ($type == 'mobile') {
  475. // if (!Validate::regex($mobile, "^1\d{10}$")) {
  476. // $this->error(__('Mobile is incorrect'));
  477. // }
  478. // $user = \app\common\model\User::getByMobile($mobile);
  479. // if (!$user) {
  480. // $this->error(__('User not found'));
  481. // }
  482. // $ret = Sms::check($mobile, $captcha, 'resetpwd');
  483. // if (!$ret) {
  484. // $this->error(__('Captcha is incorrect'));
  485. // }
  486. // Sms::flush($mobile, 'resetpwd');
  487. // } else {
  488. // if (!Validate::is($email, "email")) {
  489. // $this->error(__('Email is incorrect'));
  490. // }
  491. // $user = \app\common\model\User::getByEmail($email);
  492. // if (!$user) {
  493. // $this->error(__('User not found'));
  494. // }
  495. // $ret = Ems::check($email, $captcha, 'resetpwd');
  496. // if (!$ret) {
  497. // $this->error(__('Captcha is incorrect'));
  498. // }
  499. // Ems::flush($email, 'resetpwd');
  500. // }
  501. // //模拟一次登录
  502. // $this->auth->direct($user->id);
  503. // $ret = $this->auth->changepwd($newpassword, '', true);
  504. // if ($ret) {
  505. // $this->success(__('Reset password successful'));
  506. // } else {
  507. // $this->error($this->auth->getError());
  508. // }
  509. // }
  510. /**
  511. * 基本信息填写
  512. *
  513. * @ApiMethod (POST)
  514. * @param string $gender 性别
  515. * @param string $marriage 婚姻状态
  516. * @param string $birthday 生日
  517. * @param string $height 身高
  518. * @param string $education 学历id
  519. * @param string $school 毕业学校
  520. * @param string $work 工作
  521. * @param string $max_income 收入
  522. * @param string $region_province 家乡所在省份
  523. * @param string $region_city 家乡所在市区
  524. * @param string $region_area 家乡所在区域
  525. * @param string $futurehometown 未来定居城市
  526. * @param string $marriedtime 计划结婚id
  527. * @param string $objecteducation ta的学历id
  528. * @param string $min_age ta的年龄最小值
  529. * @param string $max_age ta的年龄最大值
  530. * @param string $min_height ta的身高最小值
  531. * @param string $max_height ta的身高最大值
  532. * @param string $wx 微信号码
  533. * @param string $image 图片
  534. */
  535. public function userinfo(){
  536. $rule = [
  537. 'gender|性别'=>'require',
  538. 'marriage|婚姻状态'=>'require',
  539. 'birthday|生日'=>'require',
  540. 'height|身高'=>'require',
  541. 'education|学历'=>'require',
  542. 'school|毕业学校'=>'require',
  543. 'work|工作'=>'require',
  544. 'max_income|收入'=>'require',
  545. 'region_province|家乡所在省份'=>'require',
  546. 'region_city|家乡所在市区'=>'require',
  547. 'region_area|家乡所在区域'=>'require',
  548. 'futurehometown|未来定居城市'=>'require',
  549. 'wx|微信号码'=>'require',
  550. 'image|头像'=>'require',
  551. 'objecteducation|ta的学历'=>'require',
  552. 'min_age|ta的年龄'=>'require',
  553. 'max_age|ta的年龄'=>'require',
  554. 'min_height|ta的身高'=>'require',
  555. 'max_height|ta的身高'=>'require'
  556. ];
  557. $data = $this->_validate($rule);
  558. $userinfo = [
  559. 'gender'=>$data['gender'],
  560. 'marriage'=>$data['marriage'],
  561. 'birthday'=>$data['birthday'],
  562. 'height'=>$data['height'],
  563. 'education'=>$data['education'],
  564. 'school'=>$data['school'],
  565. 'work'=>$data['work'],
  566. 'max_income'=>$data['max_income'],
  567. 'region_province'=>$data['region_province'],
  568. 'region_city'=>$data['region_city'],
  569. 'region_area'=>$data['region_area'],
  570. 'futurehometown'=>$data['futurehometown'],
  571. 'wx'=>$data['wx'],
  572. 'avatar_new'=>$data['image'],
  573. 'divorced_no_kids'=>isset($data['divorced_no_kids'])?$data['divorced_no_kids']:'',
  574. 'divorced_have_kids'=>isset($data['divorced_have_kids'])?$data['divorced_have_kids']:'',
  575. ];;
  576. $userinfo['image_audit'] = 0;
  577. $userinfo['is_info'] = 1;
  578. // $marriedtime = Selection::get(['id'=>input('marriedtime')]);
  579. $userinfo['marriedtime'] = input('marriedtime');
  580. // $userinfo['min_marriedtime'] = $marriedtime['min'];
  581. // $userinfo['max_marriedtime'] = $marriedtime['max'];
  582. $user = UserModel::get(['id'=>$this->auth->id]);
  583. //希望对象资料
  584. $userObject = [
  585. 'education'=>$data['objecteducation'],
  586. 'min_age'=>$data['min_age'],
  587. 'max_age'=>$data['max_age'],
  588. 'min_height'=>$data['min_height'],
  589. 'max_height'=>$data['max_height']
  590. ];
  591. $userObject['uid'] = $this->auth->id;
  592. if($user){
  593. Db::startTrans();
  594. try {
  595. $user->save($userinfo);
  596. UserObject::insert($userObject);
  597. Db::commit();
  598. $this->success('上传成功');
  599. }catch (Exception $exception){
  600. $this->error($exception);
  601. Db::rollback();
  602. return false;
  603. }
  604. }else{
  605. $this->error('状态异常');
  606. }
  607. }
  608. /**
  609. * 个人资料编辑
  610. * @ApiMethod (POST)
  611. * @param string $avatar 头像
  612. * @param string $photo 相册
  613. * @param string $username 昵称
  614. * @param string $province 所在省份
  615. * @param string $city 所在市区
  616. * @param string $area 所在区域
  617. * @param string $work 工作
  618. * @param string $max_income 收入最大值
  619. */
  620. public function userinfoedit(){
  621. $data = input('post.');
  622. $user = UserModel::get(['id'=>$this->auth->id]);
  623. if($data['avatar'] != $user['avatar']){
  624. $data['avatar_new'] = $data['avatar'];
  625. unset($data['avatar']);
  626. $data['image_audit'] = 0;
  627. }
  628. $user->save($data);
  629. $this->success('编辑成功',$user);
  630. }
  631. /**
  632. * 关于自己编辑
  633. * @param string $constellation 星座
  634. * @param string $height 身高
  635. * @param string $marriage 婚姻状态
  636. * @param string $children 有无子女
  637. * @param string $marriedtime 计划结婚
  638. * @param string $education 学历
  639. * @param string $school 毕业学校
  640. * @param string $house 房子
  641. * @param string $car 车子
  642. * @param string $father_work 父亲工作
  643. * @param string $mother_work 母亲工作
  644. * @param string $brother 兄弟姐妹
  645. * @param string $birthday 生日
  646. */
  647. public function aboutuser(){
  648. $input = input('post.');
  649. $user = UserModel::get(['id'=>$this->auth->id]);
  650. $user->save($input);
  651. $this->success('请求成功',$input);
  652. }
  653. /**
  654. * 希望对方编辑
  655. * @param string $constellation 星座
  656. * @param string $min_age 最小年龄
  657. * @param string $max_age 最大年龄
  658. * @param string $min_height 最小身高
  659. * @param string $max_height 最大身高
  660. * @param string $education 学历
  661. * @param string $car 车子
  662. * @param string $house 房子
  663. * @param string $marry 婚史
  664. * @param string $children 子女
  665. * @param string $locality 本地
  666. */
  667. public function aboutobject(){
  668. $input = input('post.');
  669. $data = UserObject::update($input,['uid'=>$this->auth->id]);
  670. if($data){
  671. $this->success('请求成功',$data);
  672. }else{
  673. $this->error('请求失败');
  674. }
  675. }
  676. /**
  677. * 标签编辑
  678. * @param string $tag 标签id(逗号分割)
  679. *
  680. */
  681. public function tagedit(){
  682. if($this->request->post()){
  683. $tag = UserModel::update(['tag'=>input('tag'),'id'=>$this->auth->id]);
  684. if($tag)$this->success('保存成功',$tag);
  685. $this->error('保存失败');
  686. }else{
  687. $this->success('',$this->auth->tag);
  688. }
  689. }
  690. /**
  691. * 个性签名编辑
  692. * @param string $signature 个性签名
  693. */
  694. public function signatureEdit(){
  695. $data = $this->_validate(['signature|内容'=>'require']);
  696. $user = UserModel::where('id',$this->auth->id)->findOrFail();
  697. $user->save($data)?$this->success('',$user):$this->error('失败');
  698. }
  699. /**
  700. * 关于我编辑
  701. * @param string $mehow 我的情况
  702. * @param string $objecthow 希望对方情况
  703. * @param string $familyhow 家庭情况
  704. */
  705. public function meHowEdit(){
  706. $data = $this->_validate(
  707. ['mehow|内容'=>'require',
  708. 'objecthow|内容'=>'require',
  709. 'familyhow|内容'=>'require',]
  710. );
  711. $user = UserModel::where('id',$this->auth->id)->findOrFail();
  712. $user->save($data)?$this->success('',$user):$this->error('失败');
  713. }
  714. /**
  715. * 我的认证状态
  716. */
  717. public function authentication(){
  718. $uid = $this->auth->id;
  719. $id_authentication = UserModel::where(['id'=>$uid])->value('id_authentication');
  720. $education_authentication = EducationAuthentication::where(['uid'=>$uid])->find();
  721. $work_authentication = WorkAuthentication::where(['uid'=>$uid])->find();
  722. $res['id_authentication'] = $id_authentication;
  723. if(!$education_authentication || $education_authentication['status']==2){
  724. $res['education_authentication'] = -1;
  725. }else{
  726. $res['education_authentication'] = $education_authentication['status'];
  727. };
  728. if(!$work_authentication || $work_authentication['status']==2){
  729. $res['work_authentication'] = -1;
  730. }else{
  731. $res['work_authentication'] = $work_authentication['status'];
  732. };
  733. $this->success('',$res);
  734. }
  735. /**
  736. * 身份认证
  737. * @ApiMethod (POST)
  738. * @param string $CertName 真实姓名
  739. * @param string $CertNo 证件号码
  740. * @param string $MetaInfo
  741. * @param string $ReturnUrl
  742. */
  743. public function idAuthentication(){
  744. $uid = $this->auth->id;
  745. $CertName = $this->request->post('CertName');
  746. $CertNo = $this->request->post('CertNo');
  747. $MetaInfo = $this->request->post('MetaInfo');
  748. $ReturnUrl = $this->request->post('ReturnUrl');
  749. if(!$CertName && !$CertNo && !$MetaInfo && !$ReturnUrl){
  750. $this->error('参数缺失');
  751. }
  752. // $user = UserModel::get(['id'=>$uid]);
  753. $MetaInfo = str_replace('&quot;','"',$MetaInfo);
  754. $res = InitFaceVerify::main($CertName,$CertNo,$MetaInfo,$ReturnUrl);
  755. $result = json_decode(json_encode($res),true)['body'];
  756. $this->success('获取成功',$result);
  757. }
  758. /**
  759. * 实名认证核验
  760. * @ApiMethod (POST)
  761. */
  762. public function userCertification()
  763. {
  764. $uid = $this->auth->id;
  765. $user = UserModel::get(['id'=>$uid]);
  766. // if ($user['id_authentication']) $this->error('已实名认证');
  767. $rule = [
  768. 'CertName'=>'require',
  769. 'CertNo'=>'require',
  770. 'CertifyId'=>'require',
  771. ];
  772. $data = $this->_validate($rule);
  773. $is_exist = UserModel::get(['real_num'=>$data['CertNo'],'status'=>'normal']);
  774. if($is_exist) $this->error('该身份证号已实名认证过');
  775. // 核验
  776. $res = DescribeFaceVerify::main($data['CertifyId']);
  777. if(!$res) $this->error('认证失败');
  778. $result = json_decode(json_encode($res),true)['body'];
  779. if($result['resultObject']['subCode'] != 200){
  780. $this->error('认证失败');
  781. }
  782. unset($data['CertifyId']);
  783. $materialInfo = json_decode($result['resultObject']['materialInfo'],true);
  784. $real_image = 'https://'.$materialInfo['facialPictureFront']['ossBucketName'].'.oss-cn-shanghai.aliyuncs.com/'.$materialInfo['facialPictureFront']['ossObjectName'];
  785. if ($user->save(['id_authentication'=>1,'real_name'=>$data['CertName'],'real_num'=>$data['CertNo'],'real_image'=>$real_image]) !== false) {
  786. //奖励邀请者狗粮
  787. if($this->auth->inviter_id && $user['image_audit']){
  788. $gain_grain = config('site.gain_grain')['邀请用户注册'];
  789. UserModel::money($gain_grain,$this->auth->inviter_id,'邀请用户奖励');
  790. }
  791. //验证生日
  792. $bir = (new \app\api\controller\Common)->get_birthday($data['CertNo']);
  793. if($bir != $this->auth->birthday){
  794. $user->save(['birthday'=>$bir]);
  795. }
  796. $this->success('实名认证成功!');
  797. } else {
  798. $this->error('实名认证失败!');
  799. }
  800. }
  801. /**
  802. * 学历认证
  803. * @param string $education 学历
  804. * @param string $school 学校
  805. * @param string $authentication_method 认证方式
  806. * @param string $image 照片
  807. */
  808. public function educationAuthentication(){
  809. $uid = $this->auth->id;
  810. $rule = [
  811. 'education|学历'=>'require',
  812. 'school|学校'=>'require',
  813. 'authentication_method|认证方式'=>'require',
  814. 'image|照片'=>'require'
  815. ];
  816. $data = $this->_validate($rule);
  817. $education = EducationAuthentication::get(['uid'=>$uid]);
  818. if($education){
  819. $res = $education->save(
  820. [
  821. 'education'=>$data['education'],
  822. 'school'=>$data['school'],
  823. 'authentication_method'=>$data['authentication_method'],
  824. 'image'=>$data['image'],
  825. 'status'=>0,
  826. 'refuse_cause'=>'',
  827. 'authentication_num'=>$education['authentication_num']+1
  828. ]
  829. );
  830. }else{
  831. $data['uid'] = $uid;
  832. $data['status'] = 0;
  833. $res = EducationAuthentication::insert($data);
  834. }
  835. if ($res){
  836. $this->success('',$res);
  837. }
  838. $this->error('提交失败',$res);
  839. }
  840. /**
  841. * 工作认证
  842. * @param string $work 职业
  843. * @param string $company_name 公司名称
  844. * @param string $authentication_method 认证方式
  845. * @param string $image 照片
  846. */
  847. public function workAuthentication(){
  848. $uid = $this->auth->id;
  849. $rule = [
  850. 'work|工作'=>'require',
  851. 'company_name|公司名称'=>'require',
  852. 'authentication_method|认证方式'=>'require',
  853. 'image|照片'=>'require'
  854. ];
  855. $data = $this->_validate($rule);
  856. $WorkAuthentication = WorkAuthentication::get(['uid'=>$uid]);
  857. if($WorkAuthentication){
  858. $res = $WorkAuthentication->save(
  859. [
  860. 'work'=>$data['work'],
  861. 'company_name'=>$data['company_name'],
  862. 'authentication_method'=>$data['authentication_method'],
  863. 'image'=>$data['image'],
  864. 'status'=>0,
  865. 'refuse_cause'=>'',
  866. 'authentication_num'=>$WorkAuthentication['authentication_num']+1
  867. ]
  868. );
  869. }else{
  870. $data['uid'] = $uid;
  871. $data['status'] = 0;
  872. $res = WorkAuthentication::insert($data);
  873. }
  874. if ($res){
  875. $this->success('',$res);
  876. }
  877. $this->error('提交失败');
  878. }
  879. /**
  880. * 狗粮明细
  881. */
  882. public function moneyDetail(){
  883. $log = MoneyLog::order('id','desc')->where(['user_id'=>$this->auth->id])->select();
  884. foreach ($log as &$value){
  885. $value['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
  886. }
  887. $this->success('',$log);
  888. }
  889. /**
  890. * 做任务赚狗粮
  891. * @ApiMethod (POST)
  892. * @ApiParams (name='type',description='完善资料,身份认证,学历认证,工作认证,邀请用户注册(领取奖励时传)')
  893. * @returnparam (name='[]',description='0未完成 1待领取 2已领取')
  894. */
  895. public function gainMoney(){
  896. $uid = $this->auth->id;
  897. if($this->request->post('type')){
  898. if($this->request->post('type')){
  899. $gain_grain = \config('site.gain_grain')[$this->request->post('type')];
  900. UserModel::money($gain_grain,$uid,$this->request->post('type'));
  901. }
  902. }else{
  903. $gain_grain = \config('site.gain_grain');
  904. MoneyLog::where(['user_id'=>$uid,'memo'=>'新人注册奖励'])->find()?$gain_grain['新人注册奖励']=2:$gain_grain['新人注册奖励']=1;
  905. if(MoneyLog::where(['user_id'=>$uid,'memo'=>'完善资料'])->find()){
  906. $gain_grain['完善资料']=2;
  907. }else{
  908. if($this->integrity() == '100%'){
  909. $gain_grain['完善资料'] = 1;
  910. }else{
  911. $gain_grain['完善资料'] = 0;
  912. }
  913. }
  914. if(MoneyLog::where(['user_id'=>$uid,'memo'=>'身份认证'])->find()){
  915. $gain_grain['身份认证']=2;
  916. }else{
  917. $this->auth->id_authentication=='1'?$gain_grain['身份认证']=1:$gain_grain['身份认证']=0;
  918. }
  919. if(MoneyLog::where(['user_id'=>$uid,'memo'=>'学历认证'])->find()){
  920. $gain_grain['学历认证']=2;
  921. }else{
  922. $this->auth->education_authentication=='1'?$gain_grain['学历认证']=1:$gain_grain['学历认证']=0;
  923. }
  924. if(MoneyLog::where(['user_id'=>$uid,'memo'=>'工作认证'])->find()){
  925. $gain_grain['工作认证']=2;
  926. }else{
  927. $this->auth->work_authentication=='1'?$gain_grain['工作认证']=1:$gain_grain['工作认证']=0;
  928. }
  929. $gain_grain['邀请用户注册'] = 0;
  930. }
  931. $this->success('',$gain_grain);
  932. }
  933. /**
  934. * 狗粮充值
  935. * @ApiMethod (POST)
  936. * @ApiParams (name='money',description='金额')
  937. * @ApiParams (name='openid',description='openid')
  938. */
  939. public function addMoney(){
  940. $uid = $this->auth->id;
  941. $money = $this->request->post('money');
  942. $openid = $this->request->post('openid');
  943. $num = \config('site.money')[$money];
  944. if(!$money && !$openid){
  945. $this->error('参数缺失');
  946. }
  947. if(!$uid && !$num){
  948. $this->error('系统错误');
  949. }
  950. $type = 'wechat';
  951. $orderId = (new \app\api\controller\Common())->getOrderId();
  952. $order = [
  953. 'uid'=>$uid,
  954. 'title'=>'狗粮充值',
  955. 'recharge_amount'=>$money,
  956. 'money'=>$num,
  957. 'type'=>1,
  958. 'orderid'=>$orderId
  959. ];
  960. Order::create($order);
  961. $notifyurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
  962. $returnurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
  963. $params = [
  964. 'amount'=>$money,
  965. 'orderid'=>$orderId,
  966. 'type'=>'wechat',
  967. 'title'=>'狗粮充值',
  968. 'notifyurl'=>$notifyurl,
  969. 'returnurl'=>$returnurl,
  970. 'method'=>"mp",
  971. 'openid'=>$openid
  972. ];
  973. $this->success('',\addons\epay\library\Service::submitOrder($params));
  974. }
  975. /**
  976. * 喜欢额度充值
  977. * @ApiMethod (POST)
  978. * @ApiParams (name='score',desfcription='金额')
  979. * @ApiParams (name='openid',description='openid')
  980. */
  981. public function addScore(){
  982. $uid = $this->auth->id;
  983. $money = $this->request->post('score');
  984. $openid = $this->request->post('openid');
  985. $num = \config('site.score')[$money];
  986. if(!$money && !$openid){
  987. $this->error('参数缺失');
  988. }
  989. if(!$uid && !$num){
  990. $this->error('系统错误');
  991. }
  992. $type = 'wechat';
  993. $orderId = (new \app\api\controller\Common())->getOrderId();
  994. $order = [
  995. 'uid'=>$uid,
  996. 'title'=>'喜欢额度充值',
  997. 'recharge_amount'=>$money,
  998. 'money'=>$num,
  999. 'type'=>2,
  1000. 'orderid'=>$orderId
  1001. ];
  1002. Order::create($order);
  1003. $notifyurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
  1004. $returnurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
  1005. $params = [
  1006. 'amount'=>$money,
  1007. 'orderid'=>$orderId,
  1008. 'type'=>'wechat',
  1009. 'title'=>'喜欢额度充值',
  1010. 'notifyurl'=>$notifyurl,
  1011. 'returnurl'=>$returnurl,
  1012. 'method'=>"mp",
  1013. 'openid'=>$openid
  1014. ];
  1015. $this->success('',\addons\epay\library\Service::submitOrder($params));
  1016. }
  1017. /**
  1018. * 活动列表
  1019. * @param string $id id(获取详情时传)
  1020. */
  1021. public function activity(){
  1022. if(!input('id')){
  1023. $this->success('',Activity::field('content',true)->select());
  1024. }else{
  1025. $this->success('',Activity::find(['id'=>input('id')]));
  1026. }
  1027. }
  1028. /**
  1029. * 更换手机号身份验证初始化
  1030. * @ApiMethod (POST)
  1031. * @param (name="ReturnUrl",description="返回地址")
  1032. * @param (name="MetaInfo",description="MetaInfo")
  1033. */
  1034. public function idVerifyInit(){
  1035. $uid = $this->auth->id;
  1036. $user = UserModel::get($uid);
  1037. $ReturnUrl = $this->request->post('ReturnUrl');
  1038. $MetaInfo = $this->request->post('MetaInfo');
  1039. if(!$ReturnUrl&&!$MetaInfo)$this->error('参数缺失');
  1040. if($user->id_authentication==0)$this->error('您还未进行身份认证');
  1041. $MetaInfo = str_replace('&quot;','"',$MetaInfo);
  1042. $res = InitFaceVerify::main($user->real_name,$user->real_num,$MetaInfo,$ReturnUrl);
  1043. $result = json_decode(json_encode($res),true)['body'];
  1044. $this->success('获取成功',$result);
  1045. }
  1046. /**
  1047. * 更换手机号实名认证核验
  1048. * @ApiMethod (POST)
  1049. * @ApiParams (name='CertifyId',description="CertifyId")
  1050. */
  1051. public function idVerifyCheck()
  1052. {
  1053. $rule = [
  1054. 'CertifyId'=>'require',
  1055. ];
  1056. $data = $this->_validate($rule);
  1057. // 核验
  1058. $res = DescribeFaceVerify::main($data['CertifyId']);
  1059. if(!$res) $this->error('核验失败');
  1060. $result = json_decode(json_encode($res),true)['body'];
  1061. if($result['resultObject']['subCode'] != 200){
  1062. $this->error('核验失败');
  1063. }
  1064. $this->success('实名认证成功!');
  1065. }
  1066. /**
  1067. * 注销操作
  1068. * @ApiMethod (POST)
  1069. * @ApiParams (name='code',description='验证码')
  1070. * @ApiParams (name='reason_cancellation',description='注销原因')
  1071. */
  1072. public function reasonCancellation(){
  1073. $code = $this->request->post('code');
  1074. $reason_cancellation = $this->request->post('reason_cancellation');
  1075. if(!$code && $reason_cancellation)$this->error('参数缺失');
  1076. $uid = $this->auth->id;
  1077. $user = UserModel::get(['id'=>$uid]);
  1078. if($user['status'] == 'destruction')$this->error('非法操作');
  1079. if (!Sms::check($user['mobile'], $code, 'destruction')) {
  1080. $this->error(__('Captcha is incorrect'));
  1081. }
  1082. $user->save(['status'=>'destruction','reason_cancellation'=>$reason_cancellation]);
  1083. $this->success('注销成功');
  1084. }
  1085. /**
  1086. * 屏蔽列表
  1087. * @ApiMethod (POST)
  1088. */
  1089. public function shield(){
  1090. $data = Shield::all(['uid'=>$this->auth->id],['userinfo.areaCity']);
  1091. foreach ($data as $k=>&$v){
  1092. $v['userinfo']['birthday'] = getAge($v['userinfo']['birthday']);
  1093. }
  1094. $this->success('',$data);
  1095. }
  1096. }