168 lines
4.8 KiB
PHP
168 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\app\agent;
|
|
|
|
use app\common\controller\Api;
|
|
use think\Db;
|
|
/**
|
|
* 提现
|
|
*/
|
|
class Withdraw extends Api
|
|
{
|
|
|
|
protected $noNeedLogin = [];
|
|
// 无需鉴权的接口,*表示全部
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
\app\common\model\fill\Handle::check('app_config','agent');
|
|
$this->withdrawCardModel = new \app\api\model\app\agent\WithdrawCard();
|
|
$this->memberModel = new \app\common\model\app\agent\Member();
|
|
$this->withdrawModel = new \app\api\model\app\agent\Withdraw();
|
|
}
|
|
|
|
/**
|
|
* 提交申请
|
|
* @return void
|
|
*/
|
|
public function submit(){
|
|
$money = $this->request->post('money');
|
|
|
|
$this->check($money);
|
|
|
|
$cardDetail = $this->withdrawCardModel->getCard($this->auth->id);
|
|
|
|
|
|
Db::startTrans();
|
|
try {
|
|
$changeRet = \app\api\model\app\agent\Money::changeMoney($this->auth->id,'money',($money * -1),true,'用户提现,冻结资金');
|
|
|
|
if(!$changeRet){
|
|
$this->error("余额变更失败,请刷新重试");
|
|
}
|
|
$data = [
|
|
'user_id' => $this->auth->id,
|
|
'money' => $money,
|
|
'status' => 'waiting',
|
|
'uniacid'=>UNIACID,
|
|
'createtime' => time(),
|
|
'card_name'=>$cardDetail['name'],
|
|
'card_no'=>$cardDetail['card_no'],
|
|
'card_address'=>$cardDetail['address']
|
|
];
|
|
$ret = $this->withdrawModel->create($data);
|
|
|
|
Db::commit();
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
}
|
|
|
|
if(!$ret){
|
|
$this->error("可提现金额不足");
|
|
}
|
|
|
|
$this->success("提现申请已提交,请等待处理");
|
|
}
|
|
|
|
|
|
/**
|
|
* 检查
|
|
* @param $money
|
|
* @return void
|
|
*/
|
|
public function check($money){
|
|
|
|
$config = \app\common\model\app\Config::getConfig('agent');
|
|
if($config['withdraw_status'] != '1'){
|
|
$this->error("提现功能暂时关闭");
|
|
}
|
|
|
|
if($config['withdraw_minmoney'] && $money < $config['withdraw_minmoney']){
|
|
$this->error("提现最小金额为:{$config['withdraw_minmoney']}元");
|
|
}
|
|
|
|
//每月可提现次数
|
|
if($config['withdraw_monthlimit']){
|
|
$monthTime = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
|
|
$monthTime = strtotime($monthTime);
|
|
$withdrawCount = $this->withdrawModel->where([
|
|
'user_id'=>$this->auth->id,
|
|
'createtime'=>['>',$monthTime]
|
|
])->count();
|
|
|
|
if($withdrawCount >= $config['withdraw_monthlimit']){
|
|
$this->error("已超出每月可提现次数{$config['withdraw_monthlimit']}次,请下月再提现");
|
|
}
|
|
}
|
|
|
|
$waiting = $this->withdrawModel->where([
|
|
'user_id' => $this->auth->id,
|
|
'status'=>'waiting'
|
|
])->field('id')->find();
|
|
|
|
if($waiting){
|
|
$this->error("尚有未处理的提现申请,请等待处理完毕后再提交");
|
|
}
|
|
|
|
$cardDetail = $this->withdrawCardModel->getCard($this->auth->id);
|
|
if(!$cardDetail){
|
|
$this->error("请完善提现银行卡信息");
|
|
}
|
|
|
|
$memberInfo = $this->memberModel->getMember($this->auth->id);
|
|
if($money > $memberInfo['money']){
|
|
$this->error("可提现金额不足");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取提现记录
|
|
* @return void
|
|
*/
|
|
public function getLog(){
|
|
$limit = input('limit',10);
|
|
$page = input('page',1);
|
|
$mode = input('mode',0);
|
|
$time = input('time',time());
|
|
|
|
$where = [
|
|
'user_id'=>$this->auth->id
|
|
];
|
|
|
|
$startOfMonth = strtotime(date('Y-m-01',$time)); // 获取当前月份的第一天的时间戳
|
|
$endOfMonth = strtotime(date('Y-m-t 23:59:59',$time)); // 获取当前月份的最后一天的时间戳
|
|
|
|
switch ($mode){
|
|
case 1:
|
|
$where['status'] = 'waiting';
|
|
break;
|
|
case 2:
|
|
$where['status'] = 'success';
|
|
break;
|
|
case 3:
|
|
$where['status'] = 'refuse';
|
|
break;
|
|
}
|
|
|
|
$list = $this->withdrawModel
|
|
->where($where)
|
|
->limit($limit)->page($page)
|
|
->where('createtime', 'BETWEEN', [$startOfMonth, $endOfMonth])
|
|
->order('createtime','desc')
|
|
->select();
|
|
|
|
|
|
if(!empty($list)){
|
|
foreach ($list as $item){
|
|
$item['status'] = __($item['status']);
|
|
}
|
|
}
|
|
|
|
$this->success('获取成功', $list);
|
|
}
|
|
} |