User.php 41 KB

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