User.php 30 KB

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