model = new InspectionApplication; $this->view->assign("auditStatusList", $this->model->getAuditStatusList()); } /** * 查看列表 */ public function index() { if ($this->request->isAjax()) { // 设置关联查询 $this->relationSearch = true; // 构建查询条件 list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['user']) ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $item) { $item->append(['audit_status_text', 'apply_time_text', 'audit_time_text']); $item->user->visible(['id', 'username', 'nickname', 'mobile']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 查看详情 */ public function detail($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $row->append(['audit_status_text', 'apply_time_text', 'audit_time_text']); $this->view->assign("row", $row); return $this->view->fetch(); } /** * 审核申请 */ public function audit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } if ($row->audit_status != InspectionApplication::AUDIT_STATUS_PENDING) { $this->error('该申请已被审核,无法重复操作'); } if ($this->request->isPost()) { $auditStatus = $this->request->post('audit_status'); $rejectReason = $this->request->post('reject_reason', '', 'trim'); try { InspectionService::auditApplication($ids, $auditStatus, $rejectReason); $this->success('审核成功'); } catch (\Exception $e) { $this->error($e->getMessage()); } } $row->append(['audit_status_text', 'apply_time_text']); $this->view->assign("row", $row); $this->view->assign("auditStatusList", $this->model->getAuditStatusList()); return $this->view->fetch(); } /** * 批量审核通过 */ public function batchPass($ids = null) { if (!$this->request->isPost()) { $this->error(__("Invalid parameters")); } $ids = $ids ? $ids : $this->request->post("ids"); if (!$ids) { $this->error(__('Parameter %s can not be empty', 'ids')); } $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } $list = $this->model->where($pk, 'in', $ids)->select(); $count = 0; $successIds = []; \think\Db::startTrans(); try { foreach ($list as $item) { if ($item->audit_status == InspectionApplication::AUDIT_STATUS_PENDING) { $item->audit_status = InspectionApplication::AUDIT_STATUS_PASSED; $item->audit_time = time(); $item->reject_reason = ''; $item->save(); $count++; $successIds[] = $item->id; } } \think\Db::commit(); } catch (\Exception $e) { \think\Db::rollback(); $this->error($e->getMessage()); } $this->success("成功审核通过{$count}个申请"); } /** * 批量审核驳回 */ public function batchReject($ids = null) { if (!$this->request->isPost()) { $this->error(__("Invalid parameters")); } $ids = $ids ? $ids : $this->request->post("ids"); $rejectReason = $this->request->post("reject_reason", '', 'trim'); if (!$ids) { $this->error(__('Parameter %s can not be empty', 'ids')); } if (empty($rejectReason)) { $this->error('驳回原因不能为空'); } $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } $list = $this->model->where($pk, 'in', $ids)->select(); $count = 0; \think\Db::startTrans(); try { foreach ($list as $item) { if ($item->audit_status == InspectionApplication::AUDIT_STATUS_PENDING) { $item->audit_status = InspectionApplication::AUDIT_STATUS_REJECTED; $item->audit_time = time(); $item->reject_reason = $rejectReason; $item->save(); $count++; } } \think\Db::commit(); } catch (\Exception $e) { \think\Db::rollback(); $this->error($e->getMessage()); } $this->success("成功驳回{$count}个申请"); } /** * 删除 */ public function del($ids = "") { if (!$this->request->isPost()) { $this->error(__("Invalid parameters")); } $ids = $ids ? $ids : $this->request->post("ids"); if ($ids) { $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } $list = $this->model->where($pk, 'in', $ids)->select(); $count = 0; \think\Db::startTrans(); try { foreach ($list as $k => $v) { $count += $v->delete(); } \think\Db::commit(); } catch (\PDOException $e) { \think\Db::rollback(); $this->error($e->getMessage()); } catch (\Exception $e) { \think\Db::rollback(); $this->error($e->getMessage()); } if ($count) { $this->success(); } else { $this->error(__('No rows were deleted')); } } $this->error(__('Parameter %s can not be empty', 'ids')); } }