123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace app\admin\controller\inspection;
- use app\common\controller\Backend;
- use app\common\Service\InspectionService;
- use app\common\model\inspection\InspectionApplication;
- /**
- * 验货员申请管理
- */
- class Application extends Backend
- {
- /**
- * InspectionApplication模型对象
- */
- protected $model = null;
- protected $relationSearch = true;
- protected $searchFields = 'name,phone';
- public function _initialize()
- {
- parent::_initialize();
- $this->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'));
- }
- }
|