model = new \app\admin\model\massager\Visa; $this->view->assign("statusList", $this->model->getStatusList()); } protected $noNeedRight = ["check"]; private function fetchWhere() { $admin = $this->auth->getUserInfo(); if (!$admin) $this->error("error"); $p_where = []; if (\E_ADMIN_TYPE::Store === $admin["type"]) { array_push($p_where, ["massager.store_id", "=", $admin["store_id"]]); } else if (\E_ADMIN_TYPE::Agency === $admin["type"]) { array_push($p_where, ["massager.city_code", "in", is_null($admin["city_codes"]) ? [] : explode(",", $admin["city_codes"])]); } return $p_where; } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); $c_where = $this->fetchWhere(); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->c_selectpage($c_where); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $query = $this->model ->with(['massager']) ->where($where); foreach ($c_where as $item) { $query->where($item[0], $item[1], $item[2]); } $list = $query ->order($sort, $order) ->paginate($limit); foreach ($list as &$row) { $row->visible(['id', 'massager_id', 'old_area_code', 'new_area_code', 'description', 'status', 'updatetime']); $row->visible(['massager']); $row->getRelation('massager')->visible(['name']); } $rows = collection($list->items())->toArray(); foreach ($rows as &$row) { $old_area = (new Area())->where("area_code", $row["old_area_code"])->find(); $new_area = (new Area())->where("area_code", $row["new_area_code"])->find(); $row["old_area_name"] = $old_area ? $old_area["mergename"] : null; $row["new_area_name"] = $new_area ? $new_area["mergename"] : null; } $result = array("total" => $list->total(), "rows" => $rows); return json($result); } return $this->view->fetch(); } public function check($id = null, $check = null) { if (!$id || !$check) $this->error("参数错误!"); $record = $this->model->where([ "id" => $id, "status" => \E_MASSAGER_STATUS::Default, ])->find(); if (!$record) $this->error("申请记录不存在!"); $new_area = (new Area())->where([ "area_code" => $record["new_area_code"], "use" => 1, "level" => 2 ])->find(); if (!$new_area) $this->error("申请迁入的地址不存在!"); $is_pass = $check === "pass"; $this->model->update([ "updatetime" => time(), "status" => $is_pass ? "pass" : "reject" ], ["id" => $id]); if ($is_pass) { (new \app\admin\model\Massager())->update([ "updatetime" => time(), "city_code" => $new_area["area_code"], "lng" => $record["lng"], "lat" => $record["lat"], ], ["id" => $record["massager_id"]] ); } Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $record["massager_id"]], "异地签证提醒", "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $this->success("审核成功!"); } }