201 lines
6.7 KiB
PHP
201 lines
6.7 KiB
PHP
![]() |
<?php
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
|||
|
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
|||
|
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
// | 创建时间: 2022/1/5 10:50
|
|||
|
// +----------------------------------------------------------------------
|
|||
|
|
|||
|
|
|||
|
namespace app\admin\controller;
|
|||
|
|
|||
|
|
|||
|
use app\admin\model\AgencyUser;
|
|||
|
use app\admin\model\Level;
|
|||
|
use app\admin\validate\AgencyValidate;
|
|||
|
use app\common\model\BankAccount;
|
|||
|
use think\Request;
|
|||
|
|
|||
|
class AgencyController extends Controller
|
|||
|
|
|||
|
{
|
|||
|
|
|||
|
protected function initialize(): void
|
|||
|
{
|
|||
|
parent::initialize(); // TODO: Change the autogenerated stub
|
|||
|
$this->get_son_agency_account();
|
|||
|
}
|
|||
|
|
|||
|
public function index(Request $request, AgencyUser $model)
|
|||
|
{
|
|||
|
$param = $request->param();
|
|||
|
$model = $model->with([
|
|||
|
'agency_level' => function ($query) {
|
|||
|
$query->field('id, name');
|
|||
|
},
|
|||
|
'parent' => function ($query) {
|
|||
|
$query->field('id, username');
|
|||
|
},
|
|||
|
])->progeny($this->user)
|
|||
|
->scope('where,role', $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_level_list' => Level::all(),
|
|||
|
]);
|
|||
|
return $this->fetch();
|
|||
|
}
|
|||
|
|
|||
|
public function bank_info($agency_id, Request $request, BankAccount $model)
|
|||
|
{
|
|||
|
$data = $model::with([
|
|||
|
'agency' => function ($query) {
|
|||
|
$query->field('id, username');
|
|||
|
},
|
|||
|
])->whereIn('agency_id', $agency_id)
|
|||
|
->find();
|
|||
|
|
|||
|
if ($request->isPost()) {
|
|||
|
$param = $request->param();
|
|||
|
if (!$data) {
|
|||
|
$result = $model::create($param);
|
|||
|
} else {
|
|||
|
$result = $model::update($param, ['agency_id' => $agency_id]);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
$result ? admin_success(lang('success'), URL_BACK) : admin_error(lang('erroe'));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$this->assign($request->get());
|
|||
|
$this->assign([
|
|||
|
'data' => $data
|
|||
|
]);
|
|||
|
return $this->fetch();
|
|||
|
}
|
|||
|
|
|||
|
public function add(Request $request, AgencyUser $model, AgencyValidate $validate)
|
|||
|
{
|
|||
|
if ($request->isPost()) {
|
|||
|
$param = $request->param();
|
|||
|
|
|||
|
$validate_result = $validate->scene('add')->check($param);
|
|||
|
if (!$validate_result) {
|
|||
|
return admin_error($validate->getError());
|
|||
|
}
|
|||
|
if (!empty($param['parent_id'])) {
|
|||
|
$parent = $model->whereIn('id',$param['parent_id'])->field('level,tax')->find();
|
|||
|
|
|||
|
if ($param['level'] <= $parent['level']) {
|
|||
|
admin_error(lang('agency_level_error'));
|
|||
|
}
|
|||
|
if ($param['tax'] >= $parent['tax']) {
|
|||
|
admin_error(lang('agency_txa_error', [$parent['tax']]));
|
|||
|
}
|
|||
|
}
|
|||
|
$grandpa = $model::get_agency_relation((int)$param['parent_id']) ;
|
|||
|
$param['grandpa_id'] = (int)$grandpa['parent']['id'] ?? 0;
|
|||
|
$param['role'] = 2;
|
|||
|
$result = $model::create($param);
|
|||
|
$url = URL_BACK;
|
|||
|
if (isset($param['_create']) && $param['_create'] == 1) {
|
|||
|
$url = URL_RELOAD;
|
|||
|
}
|
|||
|
return $result ? admin_success('添加成功', $url) : admin_error();
|
|||
|
}
|
|||
|
|
|||
|
$this->assign([
|
|||
|
'user' => $this->user,
|
|||
|
'agency_level_list' => Level::all(),
|
|||
|
'parent' => AgencyUser::scope('parent')->field('id, level, username,nickname')->select(),
|
|||
|
|
|||
|
]);
|
|||
|
return $this->fetch();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public function edit($id, Request $request, AgencyUser $model, AgencyValidate $validate)
|
|||
|
{
|
|||
|
$data = $model::with([
|
|||
|
'parent' => function ($query) {
|
|||
|
$query->field('id, level, username');
|
|||
|
},
|
|||
|
])->get($id);
|
|||
|
if ($request->isPost()) {
|
|||
|
|
|||
|
$param = $request->param();
|
|||
|
|
|||
|
$validate_result = $validate->scene('edit')->check($param);
|
|||
|
if (!$validate_result) {
|
|||
|
return admin_error($validate->getError());
|
|||
|
}
|
|||
|
|
|||
|
$parent_level = $model->whereIn('id',$param['parent_id'])->value('level');
|
|||
|
if ($data["level"] <= $parent_level) {
|
|||
|
admin_error(lang('agency_level_error'));
|
|||
|
}
|
|||
|
$grandpa = $model::get_agency_relation((int)$param['parent_id']) ;
|
|||
|
$param['grandpa_id'] = $grandpa['parent']['id'] ?? 0;
|
|||
|
$result = $data::update($param);
|
|||
|
$url = URL_BACK;
|
|||
|
if (isset($param['_create']) && $param['_create'] == 1) {
|
|||
|
$url = URL_RELOAD;
|
|||
|
}
|
|||
|
return $result ? admin_success(lang('edit_success'), $url) : admin_error();
|
|||
|
}
|
|||
|
|
|||
|
$this->assign([
|
|||
|
'user' => $this->user,
|
|||
|
'data' => $data,
|
|||
|
'agency_level_list' => Level::all(),
|
|||
|
'parent' => $data::scope('parent')->field('id,level,username,nickname')->select(),
|
|||
|
|
|||
|
]);
|
|||
|
return $this->fetch('add');
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public function del($id, AgencyUser $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(lang('delete_success'), URL_RELOAD) : admin_error();
|
|||
|
}
|
|||
|
|
|||
|
//启用
|
|||
|
public function enable($id, AgencyUser $model)
|
|||
|
{
|
|||
|
$result = $model->whereIn('id', $id)->update(['status' => 1]);
|
|||
|
return $result ? admin_success(lang('status_update_success'), URL_RELOAD) : admin_error(lang('status_update_error'));
|
|||
|
}
|
|||
|
|
|||
|
//禁用
|
|||
|
public function disable($id,AgencyUser $model)
|
|||
|
{
|
|||
|
$result = $model->whereIn('id', $id)->update(['status' => 0]);
|
|||
|
return $result ? admin_success(lang('status_update_success'), URL_RELOAD) : admin_error(lang('status_update_error'));
|
|||
|
}
|
|||
|
|
|||
|
}
|