User.php 33 KB

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