model = new \app\admin\model\service\shop\Perfect; $this->view->assign("applytypeList", $this->model->getApplytypeList()); $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("stateList", $this->model->getStateList()); } public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->where($where) ->where('applytype',1) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->categoryname = $row->category_ids?model('app\admin\model\service\Category')->getCategoryList($row->category_ids):''; $row->goodsname = $row->goods_ids?model('app\admin\model\service\Goods')->getGoodsList($row->goods_ids):''; $row->create_time = date("Y-m-d H:i",$row->createtime); $row->update_time = $row->updatetime ? date("Y-m-d H:i",$row->updatetime):''; } $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); if($params['state'] == 1) { $data = db('service_apply_shop')->where('id',$row->id)->find(); $shop = new Shop(); $shop->allowField(true)->save($data,['user_id'=>$row->user_id]); } Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } public function agree($ids = null) { $row = $this->model->get($ids); $params['state'] = 1; $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); $data = db('service_apply_shop')->where('id',$row->id)->find(); unset($data['id']); $data['goods_ids'] = \app\api\model\service\Shop::updateShopGoodsIds($row->user_id,$row->goods_ids); $shop = new Shop(); $shop->allowField(true)->save($data,['user_id'=>$row->user_id]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } public function refuse($ids = null) { $row = $this->model->get($ids); if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $params['state'] = -1; $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } }