User.php 39 KB

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