123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- <?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 = ['*'];
- // /**
- // * 余额提现
- // * @return string
- // */
- // public function withdraw()
- // {
- // $config = get_addon_config('withdraw');
- // $this->view->assign('addonConfig', $config);
- // $this->view->assign('title', __('Withdraw'));
- // return $this->view->fetch();
- // }
- //
- // /**
- // * 余额日志
- // * @return string
- // */
- // public function withdrawlog()
- // {
- // $withdrawloglist = \addons\withdraw\model\Withdraw::where(['user_id' => $this->auth->id])
- // ->order('id desc')
- // ->paginate(10);
- //
- // $this->view->assign('title', __('Withdraw log'));
- // $this->view->assign('withdrawloglist', $withdrawloglist);
- // return $this->view->fetch();
- // }
- // /**
- // * 创建订单并发起支付请求
- // * @throws \think\exception\DbException
- // */
- // public function submit()
- // {
- // $money = $this->request->request('money');
- // $account = $this->request->request('account');
- // $name = $this->request->request('name');
- // $type = $this->request->request('type','alipay');
- //// $type = 'alipay';
- //
- //
- // if ($money <= 0) {
- // $this->error('提现金额不正确');
- // }
- // if ($money > $this->auth->money) {
- // $this->error('提现金额超出可提现额度');
- // }
- // if (!$account) {
- // $this->error("提现账户不能为空");
- // }
- // if (!$name) {
- // $this->error("真实姓名不能为空");
- // }
- // if (!Validate::is($account, "email") && !Validate::is($account, "/^1\d{10}$/")) {
- // $this->error("提现账户只能是手机号或Email");
- // }
- //
- // $config = get_addon_config('withdraw');
- // if (isset($config['minmoney']) && $money < $config['minmoney']) {
- // $this->error('提现金额不能低于' . $config['minmoney'] . '元');
- // }
- // if ($config['monthlimit']) {
- // $count = \addons\withdraw\model\Withdraw::where('user_id', $this->auth->id)->whereTime('createtime', 'month')->count();
- // if ($count >= $config['monthlimit']) {
- // $this->error("已达到本月最大可提现次数");
- // }
- // }
- // Db::startTrans();
- // try {
- // $data = [
- // 'orderid' => date("YmdHis") . sprintf("%08d", $this->auth->id) . mt_rand(1000, 9999),
- // 'user_id' => $this->auth->id,
- // 'money' => $money,
- // 'type' => $type,
- // 'account' => $account,
- // 'name' => $name,
- // ];
- // \addons\withdraw\model\Withdraw::create($data);
- // \app\common\model\User::money(-$money, $this->auth->id, "提现");
- // Db::commit();
- // } catch (Exception $e) {
- // Db::rollback();
- // $this->error($e->getMessage());
- // }
- // $this->success("提现申请成功!请等待后台审核!", url("withdraw/withdrawlog"));
- // return;
- // }
- //
- // /**
- // * 企业支付通知和回调
- // * @throws \think\exception\DbException
- // */
- // public function epay()
- // {
- // $type = $this->request->param('type');
- // $paytype = $this->request->param('paytype');
- // if ($type == 'notify') {
- // $pay = \addons\epay\library\Service::checkNotify($paytype);
- // if (!$pay) {
- // echo '签名错误';
- // return;
- // }
- // $data = $pay->verify();
- // try {
- // $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
- // \addons\recharge\model\Order::settle($data['out_trade_no'], $payamount);
- // } catch (Exception $e) {
- // }
- // echo $pay->success();
- // } else {
- // $pay = \addons\epay\library\Service::checkReturn($paytype);
- // if (!$pay) {
- // $this->error('签名错误');
- // }
- // //微信支付没有返回链接
- // if ($pay === true) {
- // $this->success("请返回网站查看支付状态!", "");
- // }
- //
- // //你可以在这里定义你的提示信息,但切记不可在此编写逻辑
- // $this->success("恭喜你!充值成功!", url("user/index"));
- // }
- // return;
- // }
- /**
- * 根据手机号获取用户信息
- */
- 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');// 银行账号
- //$idCard = $this->request->request('id_card');// 身份证号
- /*$bank_name = $this->request->request('bank_name');// 银行名称
- $open_address = $this->request->request('open_address');// 开户地*/
- $open_bank = $this->request->request('open_bank');// 开户行
- /*$bank_mobile = $this->request->request('bank_mobile');// 银行预留手机号
- $captcha = $this->request->request('captcha'); // 验证码
- $mobile = $this->request->request('mobile'); // 手机号*/
- $userId = $this->auth->id;
- //|| !$bank_name || !$open_address || !$bank_mobile || !$captcha || !$mobile
- if(!$bank_no || !$open_bank ) {
- throw new Exception("请将信息填写完整");
- }
- $userAuthWhere['user_id'] = $userId;
- $userAuth = model('UserAuth')->where($userAuthWhere)->find();
- if (empty($userAuth)) {
- throw new Exception('请先实名认证');
- }
- if ($userAuth['status'] != 1) {
- throw new Exception('请先实名认证通过');
- }
- $realname = $userAuth['realname'];
- $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']);
- }
- // 获取用户信息
- //$userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
- /*if($userInfo->mobile !== $mobile) $this->error("请输入账号绑定的手机号码!");
- if (!Sms::check($mobile, $captcha, 'binkBank')) {
- $this->error(__('验证码不正确!'));
- }*/
- // 查询是否有过绑定
- $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;
- /*$data["bank_name"] = $bank_name;
- $data["open_address"] = $open_address;
- $data["mobile"] = $bank_mobile;*/
- 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();
- //if(!$bankInfo) $this->error("银行卡信息获取失败!");
- $this->success("获取成功!",$bankInfo);
- }
- /**
- * 绑定支付宝
- */
- public function bindAlipay() {
- //$realname = $this->request->request('realname');//真实姓名
- $payNo = $this->request->request('pay_no');//支付宝账号
- //$cardNo = $this->request->request('card_no');//身份证号
- //$mobile = $this->request->request('mobile'); //手机号
- //$captcha = $this->request->request('captcha'); //验证码
- $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("请将信息填写完整");
- }
- // 获取用户信息
- //$userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
- /*if (!Sms::check($mobile, $captcha, 'binkAli')) {
- $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) {
- //Sms::flush($mobile, 'binkBank');
- $this->success("支付宝绑定成功!");
- } else {
- $this->error("网络异常,请稍后重试!");
- }
- }
- /**
- * 获取绑定银行卡信息
- */
- public function getAlipayInfo() {
- // 查询是否有过绑定
- $alipayInfo = UserAlipay::where(["user_id"=>$this->auth->id])->find();
- //if(!$alipayInfo) $this->error("支付宝信息获取失败!");
- $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);
- }
- /**
- * 手机验证码获取用户信息
- *
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- 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);
- }
- /**
- * 设置交易密码
- * @return void
- */
- 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());
- }
- }
- /**
- * 修改交易密码
- * @return void
- */
- 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());
- }
- }
-
- /**
- * 验证改密码
- * @return void
- */
- public function checkSms()
- {
- try {
- $mobile = $this->request->param('mobile','');
- $code = $this->request->param('code','');
- //$event = $this->request->param('event','');//事件editpaypwd=修改支付密码,forgetpaypwd=忘记支付密码
- 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['event'] = $event;
- $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());
- }
- }
- }
|