dggjimai/application/admin/controller/WithdrawController.php

150 lines
4.6 KiB
PHP
Executable File

<?php
/**
* 提现申请记录表控制器
*/
namespace app\admin\controller;
use think\Request;
use app\common\model\WithdrawApply;
use app\common\model\AccountLog;
use app\common\model\User;
use app\common\validate\WithdrawApplyValidate;
class WithdrawController extends Controller
{
//列表
public function lists(Request $request, WithdrawApply $model)
{
$WITHDRAW_TYPE=$model->WITHDRAW_TYPE;
$STATUS_TYPE=$model->STATUS_TYPE;
$param = $request->param();
$where = [];
// 会员信息
if (!empty($param['search_key']) && !empty($param['keyword'])) {
$keyword = $param['keyword'];
if ($param['search_key'] == 'user_sn') {
$where[] = ['u.sn', '=', $keyword];
} elseif ($param['search_key'] == 'nickname'){
$where[] = ['u.nickname', 'like', '%' . $keyword . '%'];
}
}
//提现单号
if (isset($param['withdraw_sn']) && $param['withdraw_sn'] != '') {
$where[] = ['w.sn', '=', $param['withdraw_sn']];
}
//提现方式
if (isset($param['type']) && $param['type'] != '') {
$where[] = ['type', '=', $param['type']];
}
//提现状态
if (isset($param['status']) && $param['status'] != '') {
$where[] = ['w.status', '=', $param['status']];
}
// 提现时间
if (isset($param['start_time']) && $param['start_time'] && isset($param['end_time']) && $param['end_time']) {
$where[] = ['w.create_time', 'between', [strtotime($param['start_time']), strtotime($param['end_time'])]];
}
$model = $model
->alias('w')
->field('w.*,u.mobile,u.nickname,u.sn as user_sn,u.avatar')
->join('user u', 'u.id = w.user_id')
->where($where)
->scope('where', $param);
$data = $model->paginate($this->admin['per_page'], false, ['query'=>$request->get()]);
//关键词,排序等赋值
$this->assign($request->get());
$this->assign([
'data' => $data,
'page' => $data->render(),
'total' => $data->total(),
'type_list' =>$WITHDRAW_TYPE,
'status_list'=>$STATUS_TYPE,
]);
return $this->fetch();
}
public function review($id,Request $request, WithdrawApply $model)
{
$this->assign([
'id' => $id,
]);
return $this->fetch();
}
//审核通过
public function confirm(Request $request, WithdrawApply $model)
{
$param = $request->param();
$id = $param['id'];
$withdraw =$model
->where('id', $id)
->find();
// 判断提现单是否为待提现状态 1
if($withdraw['status'] != 1) {
return error('不是待提现申请单');
}
// 启动事务
$model->startTrans();
try{
// 直接标识为审核成功状态
$model
->where('id', $id)
->update(['status' =>2, 'update_time' => time(),'description'=>$param['description']]);
// 提交事务
$model->commit();
}catch(\Exception $e){
// 回滚事务
$model->rollback();
return error($e->getMessage());
}
return success('审核通过');
}
//审核拒绝
public function refuse(Request $request, WithdrawApply $model)
{
$model->startTrans();
$param = $request->param();
try{
$withdraw_apply = WithdrawApply::where('id', $param['id'])->find();
$withdraw_apply->status =3; // 提现失败
$withdraw_apply->description = $param['description'];
$withdraw_apply->update_time = time();
$withdraw_apply->save();
//拒绝提现,回退佣金
$user = User::get($withdraw_apply['user_id']);
$user->integral = ['inc', $withdraw_apply['money']];
$user->save();
//增加账户变动记录
AccountLog::AccountRecord(
$withdraw_apply['user_id'],
$withdraw_apply['money'],
1,
130,
'',
$withdraw_apply['id'],
$withdraw_apply['sn']
);
$model->commit();
} catch (Exception $e){
$model->rollback();
return error($e->getMessage());
}
return success('提现失败已回退用户账户');
}
}