Bank.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 个人银行账号
  7. */
  8. namespace app\system\controller\api\v1;
  9. use app\system\controller\api\Base;
  10. use app\common\model\SystemUserBank;
  11. class Bank extends Base{
  12. public function initialize() {
  13. parent::initialize();
  14. if(!$this->user){
  15. exit(json_encode(['code'=>401,'msg'=>'用户认证失败']));
  16. }
  17. }
  18. /**
  19. * 绑定个人应用信息
  20. **/
  21. public function bind(){
  22. if (request()->isPost()) {
  23. $data = [
  24. 'name' => $this->request->param('name/s'),
  25. 'bankname' => $this->request->param('bankname/s'),
  26. 'idcard' => $this->request->param('idcard/s'),
  27. 'bankid' => $this->request->param('bankid/s'),
  28. 'bankid_confirm' => $this->request->param('bankid_confirm/s'),
  29. 'safepassword' => $this->request->param('safepassword/s'),
  30. ];
  31. $validate = $this->validate($data, 'UserBank.bind');
  32. if (true !== $validate) {
  33. return json(['code'=>403,'msg'=>$validate]);
  34. }
  35. //判断安全密码是否正确
  36. if(!password_verify(md5($data['safepassword']),$this->user->safe_password)) {
  37. return json(['code'=>403,'msg'=>'安全密码不正确']);
  38. }
  39. //更新银行信息
  40. $rel = SystemUserBank::editer($this->miniapp_id,$this->user->id,$data);
  41. if($rel){
  42. return json(['code'=>200,'msg'=>"成功绑定"]);
  43. }else{
  44. return json(['code'=>403,'msg'=>"绑定失败"]);
  45. }
  46. }
  47. }
  48. /**
  49. * 获取银行信息
  50. */
  51. public function info(){
  52. if(!$this->user->safe_password){
  53. return json(['code'=>302,'msg'=>'请先设置您的安全密码','url'=>'/pages/user/safe']);
  54. }
  55. //更新银行信息
  56. $rel = SystemUserBank::field('name,idcard,bankname,bankid')->where(['member_miniapp_id'=>$this->miniapp_id,'user_id' => $this->user->id])->find();
  57. if($rel){
  58. $data['name'] = $rel['name'];
  59. $data['idcard'] = $rel['idcard'];
  60. $data['bankname'] = $rel['bankname'];
  61. $data['bankid'] = $rel['bankid'];
  62. return json(['code'=>200,'msg'=>"成功",'data' => $data]);
  63. }else{
  64. return json(['code'=>204,'msg'=>"失败"]);
  65. }
  66. }
  67. }