Commit a5d8bd78 authored by twj's avatar twj

余额提现和期权提现

parent 9fa88147
......@@ -34,20 +34,39 @@ class Withdraw extends Common
public function index()
{
$money = \app\money\model\Money::getMoney(MID);
$money['account'] =bcdiv($money['account'],100,2);
$money['operate_account'] = bcdiv($money['operate_account'],100,2);
$money['operate_account'] = bcdiv($money['operate_account'],100,2);
$money['account'] = bcdiv($money['account'], 100, 2);
$money['operate_account'] = bcdiv($money['operate_account'], 100, 2);
$money['operate_account'] = bcdiv($money['operate_account'], 100, 2);
$banks = BankModel::getBank(MID);
if(empty($banks)) ajaxmsg('您未绑定银行卡,请先绑定银行卡',0);
if (empty($banks)) ajaxmsg('您未绑定银行卡,请先绑定银行卡', 0);
$data['money'] = $money;
$data['banks'] = $banks;
$data['default_bank'] = $banks[0];
$data['bankSetting'] = preg_replace('/\|img/', '',config("web_bank"));
ajaxmsg('线下提现信息',1,$data);
$data['bankSetting'] = preg_replace('/\|img/', '', config("web_bank"));
ajaxmsg('线下提现信息', 1, $data);
}
/**
* 提现规则说明
*/
public function withdrawRule()
{
//最低提现金额
$minimum = config('withdraw_minimum');
//最高提现金额
$maximum = config('withdraw_maximum');
//提现手续费比例
$rate = config('withdraw_rate');
//提现审核时间
$withdraw_audit_time = config('withdraw_audit_time');
$rule = [];
$rule[0] = "1.单笔提现最低金额:" . $minimum;
$rule[1] = "2.单笔提现最高金额:" . $maximum;
$rule[2] = "3.提现手续费" . $rate . "%";
$rule[4] = "4.提现审核时间" . $withdraw_audit_time;
ajaxmsg('提现规则说明', 1, $rule);
}
/*
* 操作提现操作
......@@ -58,37 +77,37 @@ class Withdraw extends Common
$data = $this->request->post();
$data['mid'] = MID;
$result = $this->validate($data, "Withdraw.create");
if(true !== $result){
ajaxmsg($result,0);
if (true !== $result) {
ajaxmsg($result, 0);
//$this->error($result);
}
if($data['money']<0){
ajaxmsg('提现金额错误!',0);
if ($data['money'] < 0) {
ajaxmsg('提现金额错误!', 0);
}
$money_res=Db::name('money')->where(['mid'=>MID])->find();
if(empty($money_res['account'])){
ajaxmsg('查询账户资金出错!',0);
$money_res = Db::name('money')->where(['mid' => MID])->find();
if (empty($money_res['account'])) {
ajaxmsg('查询账户资金出错!', 0);
}
if(isset($money_res['account'])&&$money_res['account']<$data['money']){
ajaxmsg('提现金额已经大于可用余额!',0);
if (isset($money_res['account']) && $money_res['account'] < $data['money']) {
ajaxmsg('提现金额已经大于可用余额!', 0);
}
$withdraw_info=Db::name('money_withdraw')
->where(['mid'=>MID])
->where(['status'=>0])
$withdraw_info = Db::name('money_withdraw')
->where(['mid' => MID])
->where(['status' => 0])
->find();
if(!empty($withdraw_info)){
ajaxmsg('您已有提现申请,请耐心等待审核。',0);
if (!empty($withdraw_info)) {
ajaxmsg('您已有提现申请,请耐心等待审核。', 0);
}
$c = Db::name('member')->where(["id"=>MID])->find();
if(Hash::check((string)$data['paywd'], $c['paywd'])){
$c = Db::name('member')->where(["id" => MID])->find();
if (Hash::check((string)$data['paywd'], $c['paywd'])) {
$res = WithdrawModel::saveData($data);
}else{
ajaxmsg('支付密码错误',0);
} else {
ajaxmsg('支付密码错误', 0);
}
if($res['status']){
ajaxmsg('提现申请已提交,请耐心等待审核',1);
}else{
ajaxmsg('提现申请提交失败',0);
if ($res['status']) {
ajaxmsg('提现申请已提交,请耐心等待审核', 1);
} else {
ajaxmsg('提现申请提交失败', 0);
}
}
}
......@@ -83,7 +83,7 @@ class Esopplan extends Admin
$data['create_time'] = time();
$data['plan_account'] = $data['plan_account'] * 100;
$data['remain_account'] = $data['plan_account'] * 100;
$data['create_ip'] = get_client_ip(1);
$data['create_ip'] = get_client_ip(0);
//业务逻辑处理
$result_up = Db::name("esop_plan")->insert($data);
if ($result_up === 1) {
......
......@@ -112,7 +112,7 @@ class EsopplanRecord extends Admin
'type' => 1,
'info' => "自动行权,期权增加" . ($affect / 100),
'create_time' => time(),
'create_ip' => get_client_ip(1)
'create_ip' => get_client_ip(0)
];
EsopPlanRecordModel::create($arr);
}
......
......@@ -67,7 +67,9 @@ class Withdraw extends Admin
['order_no', '订单号'],
['mobile', '手机号'],
['name', '姓名'],
['money', '金额'],
['money', '申请金额'],
['fee','手续费'],
['real_money','到账金额'],
['bank', '银行信息'],
['status', '状态'],
['create_time', '申请时间', 'datetime'],
......
......@@ -66,9 +66,10 @@ class EsopPlan extends Model
$data['bank'] = $bank['bank'] . "|" . $bank['card'] . '|' . $bank['province'] . $bank['city'] . $bank['branch'] . "|" . $names['name'];
$data['mid'] = $parameter['mid'];
$data['money'] = $parameter['money'] * 100;
$data['fee'] = $parameter['money'] * 100 * config('withdraw_rate');
$data['order_no'] = 'tx' . generate_rand_str(10, 3);
$data['create_time'] = time();
$data['create_ip'] = get_client_ip(1);
$data['create_ip'] = get_client_ip(0);
Db::startTrans();
//查看当前期权的信息
......@@ -89,7 +90,7 @@ class EsopPlan extends Model
'type' => 3,
'info' => "期权申请提现,金额:" . $parameter['money'],
'create_time' => time(),
'create_ip' => get_client_ip(1)
'create_ip' => get_client_ip(0)
];
$res2 = EsopPlanRecordModel::create($arr);
//更新期权信息
......
<?php
namespace app\money\model;
use think\helper\Hash;
use app\money\model\Role as RoleModel;
use app\money\model\Record;
use app\member\model\Bank as BankModel;
use app\member\model\MemberMessage as MemberMessageModel;
use think\Model;
use think\Db;
use think\Exception;
class Withdraw extends Model
{
namespace app\money\model;
use think\helper\Hash;
use app\money\model\Role as RoleModel;
use app\money\model\Record;
use app\member\model\Bank as BankModel;
use app\member\model\MemberMessage as MemberMessageModel;
use think\Model;
use think\Db;
use think\Exception;
class Withdraw extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = '__MONEY_WITHDRAW__';
......@@ -30,23 +32,22 @@
public function getStatusAttr($value, $data)
{
$status = [0=>'待处理', 1=>'成功', 2=>'失败', 3=>'退回'];
$status = [0 => '待处理', 1 => '成功', 2 => '失败', 3 => '退回'];
return $status[$data['status']];
}
public static function getAll($map=[], $order='')
public static function getAll($map = [], $order = '')
{
$data_list = self::view('money_withdraw', true)
$data_list = self::view('money_withdraw', 'id,mid,order_no,money,fee,(money-fee) as real_money,status,create_time')
->view('member', 'mobile, name, id_card', 'member.id=money_withdraw.mid', 'left')
->where($map)
->order($order)
->paginate()
->each( function($item, $key){
->each(function ($item, $key) {
$item->money = money_convert($item->money);
$item->fee = money_convert($item->fee);
});
return $data_list;
}
/**
......@@ -59,48 +60,46 @@
$status = input('post.status');
$id = input('post.id');
$remark = input('post.remark');
if(!$id){
if (!$id) {
return false;
}
$withdraw = Db('money_withdraw')->where('id', $id)->find();
$user_mobile = Db('member')->where('id',$withdraw['mid'])->value('mobile');
$user_mobile = Db('member')->where('id', $withdraw['mid'])->value('mobile');
$up_withdraw['status'] = $status;
$up_withdraw['id'] = $id;
Db::startTrans();
try{
try {
$record = new record;
$money_info = Db('money')->where('id', $withdraw['mid'])->lock(true)->find();
if($status==1){// 提现通过 减去冻结金额
if ($status == 1) { // 提现通过 减去冻结金额
self::sms_withdraw('stock_withdraw_auditing_success',$user_mobile,$withdraw['money']);
$contents="提现审核通过";
self::sms_withdraw('stock_withdraw_auditing_success', $user_mobile, $withdraw['money']);
$contents = "提现审核通过";
$up_money['freeze'] = bcsub($money_info['freeze'], $withdraw['money']);
$info = "提现单号:".$withdraw['order_no'];
$info = "提现单号:" . $withdraw['order_no'];
$affect = $withdraw['money'];
$type = 3;
$account = $money_info['account'];
}elseif($status==2){ // 提现失败 解冻冻结金额
self::sms_withdraw('stock_withdraw_auditing_fail',$user_mobile,$withdraw['money']);
$contents="提现审核未通过";
} elseif ($status == 2) { // 提现失败 解冻冻结金额
self::sms_withdraw('stock_withdraw_auditing_fail', $user_mobile, $withdraw['money']);
$contents = "提现审核未通过";
$up_money['freeze'] = bcsub($money_info['freeze'], $withdraw['money']);
$up_money['account'] = bcadd($money_info['account'], $withdraw['money']);
$info = "解冻金额".($withdraw['money']/100)."元,提现单号:".$withdraw['order_no'];
$info = "解冻金额" . ($withdraw['money'] / 100) . "元,提现单号:" . $withdraw['order_no'];
$affect = $withdraw['money'];
$type = 4;
$account = $up_money['account'];
}elseif($status==3){// 提现退回 补充可用金额
} elseif ($status == 3) { // 提现退回 补充可用金额
$up_money['account'] = bcadd($money_info['account'], $withdraw['money']);
$info = "退回金额".($withdraw['money']/100)."元,提现单号:".$withdraw['order_no'];
$info = "退回金额" . ($withdraw['money'] / 100) . "元,提现单号:" . $withdraw['order_no'];
$affect = $withdraw['money'];
$type = 6;
$account = $up_money['account'];
}else{
} else {
return '状态有误';
}
......@@ -108,34 +107,32 @@
$res3 = $record->saveData($withdraw['mid'], $affect, $account, $type, $info);
$res2 = self::update($up_withdraw);
if($res1 && $res2 && $res3){
if ($res1 && $res2 && $res3) {
Db::commit();
//添加站内信信息
$MemberMessageModel = new MemberMessageModel();
$MemberMessageModel->addInnerMsg($withdraw['mid'],'提现审核通知',$contents);//站内信
}else{
$MemberMessageModel->addInnerMsg($withdraw['mid'], '提现审核通知', $contents); //站内信
} else {
Db::rollback();
return '数据更新失败';
}
}catch(\Exception $e){
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
$mobile = Db('member')->where('id', $withdraw['mid'])->value('mobile');
$details = $mobile.' 字段(status),原值:(0)新值:(' . $status . ') 备注:'.$remark.$info;
$details = $mobile . ' 字段(status),原值:(0)新值:(' . $status . ') 备注:' . $remark . $info;
action_log('withdraw_edit', 'money_withdraw', $id, UID, $details);
return true;
}
static public function sms_withdraw($type,$mobile,$money){
$contentarr = getconfigSms_status(['name'=>$type]);
$content = str_replace(array("#var#","#amount#"),array($mobile,money_convert($money)), $contentarr['value']);
$res=false;
if($contentarr['status']==1){
$res = sendsms_mandao($mobile,$content,'');
static public function sms_withdraw($type, $mobile, $money)
{
$contentarr = getconfigSms_status(['name' => $type]);
$content = str_replace(array("#var#", "#amount#"), array($mobile, money_convert($money)), $contentarr['value']);
$res = false;
if ($contentarr['status'] == 1) {
$res = sendsms_mandao($mobile, $content, '');
}
return $res;
}
......@@ -143,15 +140,16 @@
{
$bank_id = $parameter['bank_id'];
$bank = BankModel::bankInfo($bank_id);
$where1['id'] = $parameter['mid'];//会员ID
$where1['status'] = 1;//会员状态
$where1['id'] = $parameter['mid']; //会员ID
$where1['status'] = 1; //会员状态
$names = Db::name('member')->field('name')
->where($where1)
->find();
$data['bank'] = $bank['bank']."|".$bank['card'].'|'.$bank['province'].$bank['city'].$bank['branch']."|".$names['name'];
$data['bank'] = $bank['bank'] . "|" . $bank['card'] . '|' . $bank['province'] . $bank['city'] . $bank['branch'] . "|" . $names['name'];
$data['mid'] = $parameter['mid'];
$data['money'] = $parameter['money']*100;
$data['order_no'] = 'tx'.generate_rand_str(10, 3);
$data['money'] = $parameter['money'] * 100;
$data['fee'] = $parameter['money'] * 100 * config('withdraw_rate');
$data['order_no'] = 'tx' . generate_rand_str(10, 3);
$data['create_time'] = time();
$data['create_ip'] = get_client_ip(1);
......@@ -163,23 +161,21 @@
$up_money['freeze'] = bcadd($money_info['freeze'], $data['money']);
$up_money['account'] = $account;
$info = "提现冻结金额".($data['money']/100)."元,提现单号:".$data['order_no'];
try{
$info = "提现冻结金额" . ($data['money'] / 100) . "元,提现单号:" . $data['order_no'];
try {
$res1 = self::create($data);
$res2 = $record->saveData($data['mid'], -$data['money'], $account, 2, $info);
$res3 = Db('money')->where('mid', $data['mid'])->update($up_money);
if($res1 && $res2 && $res3){
if ($res1 && $res2 && $res3) {
Db::commit();
return ['status'=>1, 'message'=>'提交成功'];
}else{
return ['status' => 1, 'message' => '提交成功'];
} else {
Db::rollback();
return ['status'=>0, 'message'=>'提交失败'];
return ['status' => 0, 'message' => '提交失败'];
}
}catch(\Exception $e){
} catch (\Exception $e) {
Db::rollback();
return ['status'=>0, 'message'=>'数据异常'];
}
return ['status' => 0, 'message' => '数据异常'];
}
}
?>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment