| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 | <?phpnamespace app\api\controller;use addons\recharge\model\MoneyLog;use app\common\library\Sms;use app\api\controller\Common;use think\Db;use think\Exception;use think\Validate;/** * */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() {        $realname = $this->request->request('realname');// 真实姓名        $bank_no = $this->request->request('bank_no');// 银行账号        $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'); // 手机号        if(!$realname || !$bank_no || !$bank_name || !$open_address || !$open_bank || !$bank_mobile || !$captcha || !$mobile) {            $this->error("请将信息填写完整");        }        // 获取用户信息        $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"=>$userInfo["id"]])->find();        $data = [];        $data["realname"] = $realname;        $data["bank_no"] = $bank_no;        $data["bank_name"] = $bank_name;        $data["open_address"] = $open_address;        $data["open_bank"] = $open_bank;        $data["mobile"] = $bank_mobile;        if($bankInfo) {            $data["updatetime"] = time();            $res = \app\common\model\UserBank::update($data,["user_id"=>$userInfo["id"]]);        } else {            $data["user_id"] = $userInfo["id"];            $data["createtime"] = time();            $res = \app\common\model\UserBank::insert($data);        }        if($res) {            Sms::flush($mobile, 'binkBank');            $this->success("银行卡信息更新/绑定成功!");        } else {            $this->error("网络异常,请稍后重试!");        }    }    /**     * 获取绑定银行卡信息     */    public function getBankInfo() {        // 查询是否有过绑定        $bankInfo = \app\common\model\UserBank::where(["user_id"=>$this->auth->id])->find();        if(!$bankInfo) $this->error("银行卡信息获取失败!");        $this->success("获取成功!",$bankInfo);    }    /**     * 获取用户账户信息     */    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注册!");        }    }}
 |