gamebackend/application/admin/controller/CheckOutController.php

117 lines
4.0 KiB
PHP
Raw Normal View History

<?php
// +----------------------------------------------------------------------
// | 作者:修缘 联系QQ278896498 QQ群1054861244
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
// | 另接php业务网站制作、代理后台、gm后台、支付对接等
// +----------------------------------------------------------------------
// | 创建时间: 2022/1/9 16:53
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\AgencyUser;
use app\common\model\BankAccount;
use think\facade\Config;
use think\Request;
use app\common\model\CheckOut;
use app\common\validate\CheckOutValidate;
class CheckOutController extends Controller
{
protected function initialize(): void
{
parent::initialize(); // TODO: Change the autogenerated stub
$this->get_son_agency_account();
}
//列表
public function index(Request $request, CheckOut $model)
{
$son_agency = $this->son_agency . ",{$this->user->username}";
$param = $request->param();
$model = $model->son($son_agency)->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(),
'agency' => AgencyUser::Progeny($this->user)->scope('role')->field('id,username,invite')->all(),
'user' => $this->user,
]);
return $this->fetch();
}
public function param_add($agency_id, Request $request, CheckOut $model, CheckOutValidate $validate)
{
if (!$agency_id) {
exception(lang('agency_select_error'));
}
$agency = AgencyUser::whereIn('id', $agency_id)->field('id,username,money')->find();
$bank_account = BankAccount::whereIn('agency_id', $agency_id)->find();
$enabled_money = round($agency['money'] - Config::get('game.retain'), 2);
if ($request->isPost()) {
$param = $request->param();
if ($param['money'] > $enabled_money) {
admin_error(lang("balance_money_lack",[$enabled_money]));
}
$param['money'] = round($param['money'], 2);
$param['tax'] = round(($param['money'] / 100) * Config::get('game.commission'), 2);
$param['amount'] = round($param['money'] - $param['tax'], 2);
$result = AgencyUser::whereIn('id', $agency_id)->setDec('money', $param['money']);
if ($result) {
$model::create($param) ? admin_success() : admin_error();
}
}
$this->assign([
'agency' => $agency,
'bank_account' => $bank_account,
'enabled_money' => $enabled_money
]);
return $this->fetch('add');
}
//删除
public function del($id, CheckOut $model)
{
if (count($model->noDeletionId) > 0) {
if (is_array($id)) {
if (array_intersect($model->noDeletionId, $id)) {
return admin_error('ID为' . implode(',', $model->noDeletionId) . '的数据无法删除');
}
} else if (in_array($id, $model->noDeletionId)) {
return admin_error('ID为' . $id . '的数据无法删除');
}
}
if ($model->softDelete) {
$result = $model->whereIn('id', $id)->useSoftDelete('delete_time', time())->delete();
} else {
$result = $model->whereIn('id', $id)->delete();
}
return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
}
public function enable($id, CheckOut $model)
{
$result = $model->whereIn('id', $id)->update(['status' => 1, 'update_time' => time()]);
return $result ? admin_success('操作成功', URL_RELOAD) : admin_error();
}
}