代码初始化
This commit is contained in:
299
application/adminapi/controller/Withdrawal.php
Normal file
299
application/adminapi/controller/Withdrawal.php
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller;
|
||||
|
||||
use app\common\controller\adminApi;
|
||||
use think\Db;
|
||||
use Yzh\YunPay;
|
||||
|
||||
class Withdrawal extends adminApi
|
||||
{
|
||||
public $withdraw_type = [
|
||||
1=>'微信',
|
||||
2=>'支付宝',
|
||||
3=>'银行卡',
|
||||
];
|
||||
public $withd_type = [
|
||||
1=>'微信',
|
||||
2=>'支付宝',
|
||||
3=>'银行卡',
|
||||
4=>'云账户',
|
||||
5=>'其他'
|
||||
];
|
||||
//初始化
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
//提现列表
|
||||
public function get_withdraw_list(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$search_order_sn = input('search_order_sn', '');
|
||||
$search_order_status = input('search_order_status', '');
|
||||
$search_uid = input('search_uid', '');
|
||||
$search_nickname = input('search_nickname', '');
|
||||
$search_type = input('search_type', '');
|
||||
$search_withd_type = input('search_withd_type', '');
|
||||
$search_stime = input('search_stime', '');
|
||||
$search_etime = input('search_etime', '');
|
||||
$where=[];
|
||||
if($search_order_sn !== ''){
|
||||
$where['a.order_sn'] = $search_order_sn;
|
||||
}
|
||||
if($search_order_status !== ''){
|
||||
$where['a.status'] = $search_order_status;
|
||||
}
|
||||
if($search_uid !== ''){
|
||||
$where['b.user_code'] = $search_uid;
|
||||
}
|
||||
if($search_nickname !== ''){
|
||||
$where['b.nickname'] = ['like', '%'.$search_nickname.'%'];
|
||||
}
|
||||
if($search_type !== ''){
|
||||
$where['a.type'] = $search_type;
|
||||
}
|
||||
if($search_withd_type !== ''){
|
||||
$where['a.withd_type'] = $search_withd_type;
|
||||
}
|
||||
if($search_stime !== ''){
|
||||
$where['a.createtime'] = ['>=', strtotime($search_stime)];
|
||||
}
|
||||
if($search_etime !== ''){
|
||||
$where['a.createtime'] = ['<=', strtotime($search_etime.' 23:59:59')];
|
||||
}
|
||||
if(!empty($search_stime) && !empty($search_etime)){
|
||||
$where['a.createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime.' 23:59:59')]];
|
||||
}
|
||||
$count = db::name('vs_user_withdrawal')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id', 'left')
|
||||
->field('a.*,b.nickname')
|
||||
->where($where)
|
||||
->count();
|
||||
$lists = db::name('vs_user_withdrawal')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id', 'left')
|
||||
->field('a.*,b.nickname,b.user_code')
|
||||
->order('a.createtime desc')
|
||||
->where($where)
|
||||
->select();
|
||||
$data_lists = [];
|
||||
foreach ($lists as $key => $value) {
|
||||
$data_lists[$key]['id'] = $value['wid'];
|
||||
$data_lists[$key]['order_sn'] = $value['order_sn'];
|
||||
$data_lists[$key]['nickname'] = $value['user_code'].'-'.$value['nickname'];
|
||||
$data_lists[$key]['money'] = $value['money'];
|
||||
$data_lists[$key]['general_money'] = $value['general_money'];
|
||||
$data_lists[$key]['server_money'] = $value['server_money'];
|
||||
//支付宝账号
|
||||
$data_lists[$key]['real_name'] = $value['real_name'];
|
||||
$data_lists[$key]['alipay_account'] = $value['alipay_account'];
|
||||
$data_lists[$key]['bank_card'] = $value['bank_card'];
|
||||
$data_lists[$key]['open_bank'] = $value['open_bank'];
|
||||
$data_lists[$key]['bank_card'] = $value['bank_card'];
|
||||
$data_lists[$key]['bank_card_number'] = $value['bank_card_number'];
|
||||
$data_lists[$key]['remarke'] = $value['remarke'];
|
||||
$data_lists[$key]['status'] = $value['status'];
|
||||
$pay_message = '';
|
||||
if(in_array($value['status'],[5,4])){
|
||||
$pay_message = $value['pay_message'] ? "【".$value['pay_message']."】":'';
|
||||
}
|
||||
$data_lists[$key]['status_str'] = Model('api/UserWithdrawal')->withdraw_status[$value['status']].$pay_message;
|
||||
$data_lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
}
|
||||
//统计
|
||||
|
||||
//待审核数量
|
||||
$wait_num = db::name('vs_user_withdrawal')->where('status',1)->count();
|
||||
//今日提现
|
||||
$today_money = db::name('vs_user_withdrawal')->whereIn('status',[2,6])->whereTime('createtime', 'today')->sum('money');
|
||||
//昨日提现
|
||||
$yesterday_money = db::name('vs_user_withdrawal')->whereIn('status',[2,6])->whereTime('createtime', 'yesterday')->sum('money');
|
||||
//已完成提现总额
|
||||
$complete_money = db::name('vs_user_withdrawal')->whereIn('status',[2,6])->sum('money');
|
||||
//手续费收入
|
||||
$server_money = db::name('vs_user_withdrawal')->whereIn('status',[2,6])->sum('server_money');
|
||||
//提现总额
|
||||
$total_money = $complete_money+$server_money;
|
||||
|
||||
//订单状态列表
|
||||
$i = 0;
|
||||
$withdraw_status_array = [];
|
||||
foreach (Model('api/UserWithdrawal')->withdraw_status as $key => $value){
|
||||
$withdraw_status_array[$i]['id'] = $key;
|
||||
$withdraw_status_array[$i]['name'] = $value;
|
||||
$i++;
|
||||
}
|
||||
//提现方式
|
||||
$withdraw_type_array = [];
|
||||
$i = 0;
|
||||
foreach ($this->withdraw_type as $key => $value){
|
||||
$withdraw_type_array[$i]['id'] = $key;
|
||||
$withdraw_type_array[$i]['name'] = $value;
|
||||
$i++;
|
||||
}
|
||||
//平台处理方式
|
||||
$withd_type_array = [];
|
||||
$i = 0;
|
||||
foreach ($this->withd_type as $key => $value){
|
||||
$withd_type_array[$i]['id'] = $key;
|
||||
$withd_type_array[$i]['name'] = $value;
|
||||
$i++;
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $data_lists,
|
||||
'total_data' => [
|
||||
'total_money' => $total_money,
|
||||
'wait_num' => $wait_num,
|
||||
'today_money' => $today_money,
|
||||
'yesterday_money' => $yesterday_money,
|
||||
'complete_money' => $complete_money,
|
||||
'server_money' => $server_money
|
||||
],
|
||||
'withdraw_status' => $withdraw_status_array,
|
||||
'withdraw_type' => $withdraw_type_array,
|
||||
'withd_type' => $withd_type_array,
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
/*
|
||||
* 提现发放
|
||||
*/
|
||||
public function withdraw_send(){
|
||||
$wid = input('id', '');
|
||||
$status = input('status', '');
|
||||
$withd_type = input('withd_type', '');
|
||||
$remarke = input('remarke', '');
|
||||
$secondary_password = input('secondary_password', '');
|
||||
$check_pass = model('adminapi/admin')->check_secondary_password($secondary_password);
|
||||
if($check_pass['code']==0){
|
||||
return v($check_pass['code'], $check_pass['msg'], $check_pass['data']);
|
||||
}
|
||||
if($wid == ''){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
$withdraw_info = db::name('vs_user_withdrawal')->where('wid', $wid)->find();
|
||||
if($withdraw_info['status'] != 1){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
if($withdraw_info['status'] != 1){
|
||||
return V(0,"该提现已处理");
|
||||
}
|
||||
|
||||
DB::startTrans();
|
||||
try{
|
||||
if($status == 2){
|
||||
$data['status']= 2;
|
||||
$deal_type =1;
|
||||
if($withd_type==1){//微信
|
||||
$transfer_type = 2;
|
||||
return V(0,"功能暂未开放,请选用云账户");
|
||||
} elseif($withd_type==2){//支付宝
|
||||
$transfer_type = 2;
|
||||
return V(0,"功能暂未开放,请选用云账户");
|
||||
} elseif($withd_type==3){//银行卡
|
||||
$transfer_type = 2;
|
||||
return V(0,"功能暂未开放,请选用云账户");
|
||||
} elseif($withd_type==4){//云账户
|
||||
$transfer_type = 2;
|
||||
$deal_type =2;
|
||||
$result_yun = $this->submit_yun($withdraw_info);
|
||||
if($result_yun['code'] == 1){
|
||||
$data['status'] = 4;
|
||||
$data['submit_yun_time'] = time();
|
||||
}else{
|
||||
Db::rollback();
|
||||
return V(0,$result_yun['msg']);
|
||||
}
|
||||
} elseif($withd_type==5){//其他
|
||||
$transfer_type = 1;
|
||||
} else{
|
||||
Db::rollback();
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
$data['withd_type']= $withd_type;
|
||||
$data['remarke']= $remarke;
|
||||
$data['transfer_type']= $transfer_type;
|
||||
$data['deal_type']= $deal_type;
|
||||
$data['deal_time']= time();
|
||||
$data['updatetime']= time();
|
||||
$result = db::name('vs_user_withdrawal')->where('wid', $wid)->update($data);
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return V(0,"操作失败");
|
||||
}
|
||||
}else{
|
||||
$result = db::name('vs_user_withdrawal')->where('wid', $wid)->update([
|
||||
'status' => 3,
|
||||
'remarke' => $remarke,
|
||||
'deal_time' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return V(0,"操作失败");
|
||||
}
|
||||
$res = model('api/UserWithdrawal')->withdrawal_fail($withdraw_info['order_sn']);
|
||||
if($res['code'] == 0){
|
||||
Db::rollback();
|
||||
return V(0,$res['msg']);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return V(0,$e->getMessage());
|
||||
}
|
||||
return V(1,"操作成功");
|
||||
}
|
||||
/*
|
||||
* 云账户提现
|
||||
*/
|
||||
public function submit_yun($withdraw_info){
|
||||
//查询该用户云账户提现金额
|
||||
$had_money = db::name('vs_user_withdrawal')->where(['user_id'=>$withdraw_info['user_id'],'deal_type'=>2,'status'=>6])->where('pay_time','month')->sum('general_money');
|
||||
$max_month_money = 98000;
|
||||
if(($had_money+$withdraw_info['general_money']) >= 98000){
|
||||
return ['code' => 0, 'msg' => '单人单月云账户提现金额最大为98000元!', 'data' => null];
|
||||
}
|
||||
//查询该用户信息
|
||||
$user_info = model('api/user')->get_user_info($withdraw_info['user_id']);
|
||||
if(empty($user_info)){
|
||||
return ['code' => 0, 'msg' => '用户信息错误!', 'data' => null];
|
||||
}
|
||||
$real_name = $user_info['real_name'];
|
||||
$id_card = $user_info['card_id'];
|
||||
$order_id = $withdraw_info['order_sn'];
|
||||
$order_amount = $withdraw_info['general_money'];
|
||||
$phone = $user_info['mobile'];
|
||||
if (empty($real_name) || empty($id_card)) {
|
||||
return ['code' => 0, 'msg' => '请先实名认证', 'data' => null];
|
||||
}
|
||||
if($withdraw_info['type'] == 1){
|
||||
return ['code' => 0, 'msg' => '暂未对接微信', 'data' => null];
|
||||
// $yun_pay = new YunPay($order_id, $real_name, $id_card, $card_no, $order_amount,$phone);
|
||||
// $result = $yun_pay->Wxpay($user_info['wx_openid']);
|
||||
} elseif ($withdraw_info['type'] == 2) {
|
||||
if(empty($user_info['alipay_account'])){
|
||||
return ['code' => 0, 'msg' => '请先绑定支付宝账号', 'data' => null];
|
||||
}
|
||||
$card_no = $user_info['alipay_account'];
|
||||
$yun_pay = new YunPay($order_id, $real_name, $id_card, $card_no, $order_amount,$phone);
|
||||
$result = $yun_pay->alipay();
|
||||
} elseif ($withdraw_info['type'] == 3) {
|
||||
if(empty($user_info['bank_card_number'])){
|
||||
return ['code' => 0, 'msg' => '请先绑定银行卡号', 'data' => null];
|
||||
}
|
||||
$card_no = $user_info['bank_card_number'];
|
||||
$yun_pay = new YunPay($order_id, $real_name, $id_card, $card_no, $order_amount,$phone);
|
||||
$result = $yun_pay->bank();
|
||||
}
|
||||
if ($result['code'] == 1) {
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user