|
@@ -13,108 +13,36 @@ class Money extends Api
|
|
protected $noNeedLogin = [];
|
|
protected $noNeedLogin = [];
|
|
protected $noNeedRight = '*';
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
- //提现账号添加
|
|
|
|
- public function bankadd() {
|
|
|
|
- $realname = input('realname', '', 'trim'); //账户真实姓名
|
|
|
|
- $banknumber = input('banknumber', '', 'trim'); //卡号或账号
|
|
|
|
- $bankname = input('bankname', '', 'trim'); //银行名称
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
|
|
|
|
- $this->error('账号姓名1-30位');
|
|
|
|
- }
|
|
|
|
- if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
|
|
|
|
- $this->error('账号1-50位');
|
|
|
|
- }
|
|
|
|
- if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
|
|
|
|
- $this->error('银行名称1-50位');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //添加
|
|
|
|
- $count = Db::name('user_bank')->where(['user_id' => $this->auth->id])->count('id');
|
|
|
|
- if ($count) {
|
|
|
|
- $this->error('您已经拥有该类型账号,不能再添加');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $data['user_id'] = $this->auth->id;
|
|
|
|
- $data['realname'] = $realname;
|
|
|
|
- $data['banknumber'] = $banknumber;
|
|
|
|
- $data['bankname'] = $bankname;
|
|
|
|
- $data['createtime'] = time();
|
|
|
|
-
|
|
|
|
- $rs = Db::name('user_bank')->insertGetId($data);
|
|
|
|
- if (!$rs) {
|
|
|
|
- $this->error('添加失败');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $this->success('添加成功');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //提现账号编辑
|
|
|
|
- public function bankedit(){
|
|
|
|
- $id = input('id', 0, 'intval'); //账号id
|
|
|
|
- $realname = input('realname', '', 'trim'); //账户真实姓名
|
|
|
|
- $banknumber = input('banknumber', '', 'trim'); //卡号或账号
|
|
|
|
- $bankname = input('bankname', '', 'trim'); //银行名称
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
|
|
|
|
- $this->error('账号姓名1-30位');
|
|
|
|
- }
|
|
|
|
- if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
|
|
|
|
- $this->error('账号1-50位');
|
|
|
|
- }
|
|
|
|
- if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
|
|
|
|
- $this->error('银行名称1-50位');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //查询账号是否存在
|
|
|
|
- $info = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
|
|
|
|
- if (!$info) {
|
|
|
|
- $this->error('账号不存在');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $data['realname'] = $realname;
|
|
|
|
- $data['banknumber'] = $banknumber;
|
|
|
|
- $data['bankname'] = $bankname;
|
|
|
|
- $data['updatetime'] = time();
|
|
|
|
-
|
|
|
|
- $rs = Db::name('user_bank')->where(['id' => $id])->update($data);
|
|
|
|
- if ($rs === false) {
|
|
|
|
- $this->error('修改失败');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $this->success('修改成功');
|
|
|
|
|
|
+ //配置
|
|
|
|
+ public function withdraw_config(){
|
|
|
|
+ $data = [
|
|
|
|
+ 'score' => model('wallet')->getWallet($this->auth->id,'score'),
|
|
|
|
+ 'min_withdrawal_money' => config('site.min_withdrawal_money'),
|
|
|
|
+ 'max_withdrawal_money' => config('site.max_withdrawal_money'),
|
|
|
|
+ 'type_1' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',1)->where('status',1)->field('realname,banknumber,bankname')->find(),
|
|
|
|
+ 'type_2' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',2)->where('status',1)->field('realname,banknumber,bankname')->find(),
|
|
|
|
+ 'type_3' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',3)->where('status',1)->field('realname,banknumber,bankname')->find(),
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $this->success(1,$data);
|
|
}
|
|
}
|
|
|
|
|
|
- //提现账号信息
|
|
|
|
- public function bankinfo() {
|
|
|
|
|
|
+ //提现
|
|
|
|
+ public function scorewithdraw() {
|
|
|
|
+ $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行
|
|
|
|
+ $money = input('score', '', 'intval');
|
|
|
|
|
|
- $info = Db::name('user_bank')->where(['user_id' => $this->auth->id])->find();
|
|
|
|
- if (!$info) {
|
|
|
|
- $info = (object)[];
|
|
|
|
|
|
+ if ($money <= 0) {
|
|
|
|
+ $this->error('请输入正确兑换金额');
|
|
}
|
|
}
|
|
|
|
|
|
- $this->success('账户信息', $info);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //提现
|
|
|
|
- public function moneywithdraw() {
|
|
|
|
- $id = input('id', 0, 'intval'); //提现账号id
|
|
|
|
- $money = input('money', '', 'trim');
|
|
|
|
- if (!$id) {
|
|
|
|
- $this->error('请选择提现账号');
|
|
|
|
- }
|
|
|
|
- $bankinfo = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
|
|
|
|
- if (!$bankinfo) {
|
|
|
|
- $this->error('账号不存在');
|
|
|
|
- }
|
|
|
|
- if (!preg_match('/^[0-9]+(.[0-9]{1,8})?$/', $money) || $money <= 0) {
|
|
|
|
- $this->error('请输入正确提现金额');
|
|
|
|
|
|
+ $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
|
|
|
|
+ if($check){
|
|
|
|
+ $this->error('目前还有兑换在审核中,请稍后在兑换');
|
|
}
|
|
}
|
|
|
|
|
|
//余额查询
|
|
//余额查询
|
|
- $user_money = model('wallet')->getWallet($this->auth->id,'money');
|
|
|
|
|
|
+ $user_money = model('wallet')->getWallet($this->auth->id,'score');
|
|
if ($user_money < $money) {
|
|
if ($user_money < $money) {
|
|
$this->error('余额不足');
|
|
$this->error('余额不足');
|
|
}
|
|
}
|
|
@@ -129,24 +57,17 @@ class Money extends Api
|
|
$this->error('最高提现金额' . $max_withdrawal_money . '元');
|
|
$this->error('最高提现金额' . $max_withdrawal_money . '元');
|
|
}
|
|
}
|
|
|
|
|
|
- //查询提现手续费百分比
|
|
|
|
- $withdrawal_service_fee = (int)config('site.withdrawal_service_fee') ? : 0;
|
|
|
|
- if ($withdrawal_service_fee < 0 || $withdrawal_service_fee >= 100) {
|
|
|
|
- $this->error('提现手续费异常');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_service_fee)),100);
|
|
|
|
|
|
|
|
$data['order_no'] = createUniqueNo('T',$this->auth->id);
|
|
$data['order_no'] = createUniqueNo('T',$this->auth->id);
|
|
- $data['user_id'] = $this->auth->id;
|
|
|
|
- $data['amount'] = $money;
|
|
|
|
- $data['money'] = $real_money;
|
|
|
|
- $data['user_bank_id'] = $id;
|
|
|
|
- $data['realname'] = $bankinfo['realname'];
|
|
|
|
- $data['banknumber'] = $bankinfo['banknumber'];
|
|
|
|
- $data['bankname'] = $bankinfo['bankname'];
|
|
|
|
- $data['status'] = 0;
|
|
|
|
|
|
+ $data['user_id'] = $this->auth->id;
|
|
|
|
+ $data['score'] = $money;
|
|
|
|
+ $data['type'] = $type;
|
|
|
|
+ $data['realname'] = input('realname','');
|
|
|
|
+ $data['banknumber'] = input('banknumber','');
|
|
|
|
+ $data['bankname'] = input('bankname','');
|
|
$data['createtime'] = time();
|
|
$data['createtime'] = time();
|
|
|
|
+ $data['status'] = 0;
|
|
|
|
+
|
|
|
|
|
|
//开启事务
|
|
//开启事务
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
@@ -154,22 +75,22 @@ class Money extends Api
|
|
$log_id = Db::name('user_withdraw')->insertGetId($data);
|
|
$log_id = Db::name('user_withdraw')->insertGetId($data);
|
|
if (!$log_id) {
|
|
if (!$log_id) {
|
|
Db::rollback();
|
|
Db::rollback();
|
|
- $this->error('申请提现失败');
|
|
|
|
|
|
+ $this->error('申请兑换失败');
|
|
}
|
|
}
|
|
|
|
|
|
- $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'money',$money,4,'提现','user_withdraw',$log_id);
|
|
|
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$money,2,'积分兑换','user_withdraw',$log_id);
|
|
if ($rs_wallet['status'] == false) {
|
|
if ($rs_wallet['status'] == false) {
|
|
$this->error($rs_wallet['msg']);
|
|
$this->error($rs_wallet['msg']);
|
|
Db::rollback();
|
|
Db::rollback();
|
|
}
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
Db::commit();
|
|
- $this->success('申请提现成功,请等待审核');
|
|
|
|
|
|
+ $this->success('申请兑换成功,请等待审核');
|
|
}
|
|
}
|
|
|
|
|
|
//用户钱包流水
|
|
//用户钱包流水
|
|
- public function moneylog(){
|
|
|
|
- $list = Db::name('user_money_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->page($this->page,$this->listrow)->select();
|
|
|
|
|
|
+ public function scorelog(){
|
|
|
|
+ $list = Db::name('user_score_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->autopage()->order('id desc')->select();
|
|
foreach($list as $key => &$val){
|
|
foreach($list as $key => &$val){
|
|
$val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
|
|
$val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
|
|
}
|
|
}
|