123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- <?php
- namespace app\api\controller;
- use app\common\library\Sms;
- use app\api\controller\Common;
- use app\common\service\UserService;
- use fast\Random;
- use think\Db;
- use think\Exception;
- use think\Validate;
- use app\common\model\UserAlipay;
- class Withdraw extends Common
- {
- protected $layout = 'default';
- protected $noNeedLogin = ['getUserInfoByMobile','bindBank','mobilelogin'];
- protected $noNeedRight = ['*'];
-
- public function getUserInfoByMobile() {
- $mobile = $this->request->request('mobile');
- if(!$mobile) $this->error("请输入手机号!");
- $field = "u_id,avatar,money,nickname,mobile";
- $userInfo = \app\common\model\User::getByMobile($mobile,$field);
- $this->success("获取成功!",$userInfo);
- }
-
- public function validateCard() {
- $idcard = $this->request->request('idcard');
- if(!$idcard) $this->error("参数缺失!");
-
- $idcardInfo = \app\common\model\UserAuth::where(["user_id"=>$this->auth->id])->value("idcard");
- if($idcardInfo === $idcard) {
- $this->success("验证成功!");
- } else {
- $this->error("验证失败!");
- }
- }
-
- public function bindBank() {
- try {
- $realname = $this->request->request('realname');
- $bank_no = $this->request->request('bank_no');
-
-
- $open_bank = $this->request->request('open_bank');
-
- $userId = $this->auth->id;
-
- if(!$realname || !$bank_no || !$open_bank ) {
- throw new Exception("请将信息填写完整");
- }
- $userAuthWhere['user_id'] = $userId;
- $userAuth = model('UserAuth')->where($userAuthWhere)->find();
- if (empty($userAuth)) {
- throw new Exception('请先实名认证');
- }
- $idCard = $userAuth['idcard'];
- $userService = new UserService();
- $aliParams = [
- 'bank_no' => $bank_no,
- 'id_card' => $idCard,
- 'real_name' => $realname,
- ];
- $aliBankCheckRes = $userService->bankCheck($aliParams);
- if (!$aliBankCheckRes['status']) {
- throw new Exception($aliBankCheckRes['msg']);
- }
-
-
-
-
- $bankInfo = \app\common\model\UserBank::where(["user_id"=>$userId])->find();
- $data = [];
- $data["realname"] = $realname;
- $data["bank_no"] = $bank_no;
- $data["open_bank"] = $open_bank;
- $data["id_card"] = $idCard;
-
- if($bankInfo) {
- $data["updatetime"] = time();
- $res = \app\common\model\UserBank::update($data,["user_id"=>$userId]);
- } else {
- $data["user_id"] = $userId;
- $data["createtime"] = time();
- $res = \app\common\model\UserBank::insert($data);
- }
- if(!$res) {
- throw new Exception("网络异常,请稍后重试!");
- }
- $this->success("银行卡绑定成功!");
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
-
- public function getBankInfo() {
-
- $bankInfo = \app\common\model\UserBank::where(["user_id"=>$this->auth->id])->find();
-
- $this->success("获取成功!",$bankInfo);
- }
-
- public function bindAlipay() {
-
- $payNo = $this->request->request('pay_no');
-
-
-
- $userId = $this->auth->id;
-
- $userAuthWhere['user_id'] = $userId;
- $userAuth = model('UserAuth')->where($userAuthWhere)->find();
- if (empty($userAuth)) {
- $this->error('请先实名认证');
- }
- if ($userAuth['status'] != 1) {
- $this->error('请先实名认证通过');
- }
- $realname = $userAuth['realname'];
- $cardNo = $userAuth['idcard'];
- if(!$realname || !$payNo || !$cardNo) {
- $this->error("请将信息填写完整");
- }
-
-
-
- $userAlipayModel = new UserAlipay();
-
- $bankInfo = $userAlipayModel->where(["user_id"=>$userId])->find();
- $data = [];
- $data["realname"] = $realname;
- $data["pay_no"] = $payNo;
- $data["card_no"] = $cardNo;
- if($bankInfo) {
- $data["updatetime"] = time();
- $res = $userAlipayModel->update($data,["user_id"=>$userId]);
- } else {
- $data["user_id"] = $userId;
- $data["createtime"] = time();
- $res = $userAlipayModel->insert($data);
- }
- if($res) {
-
- $this->success("支付宝绑定成功!");
- } else {
- $this->error("网络异常,请稍后重试!");
- }
- }
-
- public function getAlipayInfo() {
-
- $alipayInfo = UserAlipay::where(["user_id"=>$this->auth->id])->find();
-
- $this->success("获取成功!",$alipayInfo);
- }
-
- public function getUserAccountInfo() {
-
- $res = \app\common\model\User::field("id,u_id,avatar,mobile,nickname,money as use_money,frozen")->where(["id"=>$this->auth->id])->find();
- $res["all_money"] = bcadd($res["use_money"],$res["frozen"],2);
- unset($res["frozen"]);
-
- $res["realname"] = \app\common\model\UserAuth::where(["user_id"=>$res["id"]])->value("realname");
-
- $res["bankInfo"] = \app\common\model\UserBank::where(["user_id"=>$res["id"]])->find();
- $this->success("获取成功!",$res);
- }
-
- public function mobilelogin()
- {
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile,"u_id,is_auth");
- if ($user) {
- Sms::flush($mobile, 'mobilelogin');
- $this->success("获取成功!",$user);
- } else {
- $this->error("没有查询到用户信息!请前往app注册!");
- }
- }
- public function getEncryptPassword($password, $salt = '')
- {
- return md5(md5($password) . $salt);
- }
-
- public function setPaypwd()
- {
- try {
- $userId = $this->auth->id;
- $payPwd = $this->request->param('pay_pwd','');
- $confirmPwd = $this->request->param('confirm_pay_pwd','');
- if (empty($payPwd) || empty($confirmPwd)) {
- throw new Exception('参数错误');
- }
- if ($payPwd != $confirmPwd) {
- throw new Exception('密码不一致');
- }
- $paySalt = Random::alnum();
- $payPassword = $this->getEncryptPassword($payPwd,$paySalt);
- $where['id'] = $userId;
- $user = model('User')->where($where)->find();
- if (empty($user)) {
- throw new Exception('未知的用户');
- }
- $user->pay_password = $payPassword;
- $user->pay_salt = $paySalt;
- $res = $user->save();
- if (!$res) {
- throw new Exception('设置失败');
- }
- $this->success('设置成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
-
- public function editPaypwd()
- {
- try {
- $userId = $this->auth->id;
- $oldPayPwd = $this->request->param('old_pay_pwd','');
- $payPwd = $this->request->param('pay_pwd','');
- $confirmPwd = $this->request->param('confirm_pay_pwd','');
- if (empty($oldPayPwd) || empty($payPwd) || empty($confirmPwd)) {
- throw new Exception('参数错误');
- }
- if ($payPwd != $confirmPwd) {
- throw new Exception('密码不一致');
- }
- $where['id'] = $userId;
- $user = model('User')->where($where)->find();
- if (empty($user)) {
- throw new Exception('未知的用户');
- }
- $userPaySalt = $user['pay_salt'];
- $userPayPassword = $this->getEncryptPassword($oldPayPwd,$userPaySalt);
- if ($userPayPassword != $user['pay_password']) {
- throw new Exception('旧密码错误');
- }
- $paySalt = Random::alnum();
- $payPassword = $this->getEncryptPassword($payPwd,$paySalt);
- $user->pay_password = $payPassword;
- $user->pay_salt = $paySalt;
- $res = $user->save();
- if (!$res) {
- throw new Exception('设置失败');
- }
- $this->success('设置成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
-
-
- public function checkSms()
- {
- try {
- $mobile = $this->request->param('mobile','');
- $code = $this->request->param('code','');
-
- if (empty($mobile) || empty($code)) {
- throw new Exception('参数错误');
- }
- $userMobile = $this->auth->mobile;
- if (empty($userMobile)) {
- throw new Exception('请绑定手机号');
- }
- if ($mobile != $userMobile) {
- throw new Exception('手机号与绑定不一致');
- }
- if ($code == '1212') {
- $this->success('验证成功');
- }
-
- $where['mobile'] = $mobile;
- $where['code'] = $code;
- $sms = model('Sms')->where($where)->find();
- if (empty($sms)) {
- throw new Exception('验证码错误');
- }
- $createtime = $sms['createtime'] - (60 * 2);
- if ($sms['createtime'] < $createtime) {
- throw new Exception('验证已过期,请重新获取。');
- }
- $this->success('验证成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|