123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\admin\controller\auth;
- use ba\Random;
- use Throwable;
- use think\facade\Db;
- use app\common\controller\Backend;
- use app\admin\model\Admin as AdminModel;
- class CollegeApproval extends Backend
- {
- /**
- * 模型
- * @var object
- * @phpstan-var AdminModel
- */
- protected object $model;
- protected array|string $preExcludeFields = ['create_time', 'update_time', 'password', 'salt', 'login_failure', 'last_login_time', 'last_login_ip'];
- protected array|string $quickSearchField = ['nickname'];
- public function initialize(): void
- {
- parent::initialize();
- $this->model = new AdminModel();
- }
- /**
- * 查看
- * @throws Throwable
- */
- public function index(): void
- {
- if ($this->request->param('select')) {
- $this->select();
- }
- list($where, $alias, $limit, $order) = $this->queryBuilder();
- // halt($where, $alias, $limit, $order);
- // halt($where, $alias, $limit, $order,$this->withJoinTable);
- $res = $this->model
- ->withoutField('login_failure,password,salt')
- ->leftJoin("admin_group_access group",'admin.id = group.uid')
- ->alias($alias)
- ->where($where)
- ->where('group.group_id',3)
- ->order($order)
- ->paginate($limit);
- $this->success('', [
- 'list' => $res->items(),
- 'total' => $res->total(),
- 'remark' => get_route_remark(),
- ]);
- }
- /**
- * 编辑
- * @throws Throwable
- */
- public function edit($id = null): void
- {
- $row = $this->model->find($id);
- if (!$row) {
- $this->error(__('Record not found'));
- }
- $dataLimitAdminIds = $this->getDataLimitAdminIds();
- if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
- $this->error(__('You have no permission'));
- }
- if ($this->request->isPost()) {
- $data = $this->request->post();
- if (!$data) {
- $this->error(__('Parameter %s can not be empty', ['']));
- }
- if( $data['switch'] == 0 && !isset($data['types'])){
- $this->error('请确保至少有一个学院审批人!');
- }
- $data = $this->excludeFields($data);
- $result = false;
- $this->model->startTrans();
- try {
- if( $data['switch'] == 1 && !isset($data['types'])){
- $this->model->where('switch',1)->update(['switch' => 0]);
- }
- $result = $row->save($data);
- $this->model->commit();
- } catch (Throwable $e) {
- $this->model->rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Update successful'));
- } else {
- $this->error(__('No rows updated'));
- }
- }
- unset($row['salt'], $row['login_failure']);
- $row['password'] = '';
- $this->success('', [
- 'row' => $row
- ]);
- }
- }
|