model = new \app\admin\model\service\shop\Applyshop; $this->view->assign("applytypeList", $this->model->getApplytypeList()); $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("stateList", $this->model->getStateList()); $this->view->assign("toShopList", $this->model->getToShopList()); } 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',0) ->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', '')); } ($row->state == 1 && $params['state'] != 1) && $this->error('请勿重复审核'); $params = $this->preExcludeFields($params); if($params['state'] == 1) { $params['code'] = str_pad($row->user_id,8,Random::alnum(8-strlen($row->user_id))); } $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) { $this->model->where('id',$row->id)->update(['applytype'=>1]); model('app\admin\model\service\User')->where('user_id',$row->user_id)->update(['is_shop'=>1]); $data = db('service_apply_shop')->where('id',$row->id)->find(); $count = model('app\admin\model\service\shop\Shop')->where('state',1)->count(); $data['code'] = str_pad(date('d').$count,8,0); $data['accept_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('shop_accept_nums'); $shop = new Shop($data); $shop->allowField(true)->save(); } 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); 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); $row->applytype != 0 && $this->error('请勿重复审核'); $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); $this->model->where('id',$row->id)->update(['applytype'=>1]); model('app\admin\model\service\User')->where('user_id',$row->user_id)->update(['is_shop'=>1]); $data = db('service_apply_shop')->where('id',$row->id)->find(); $data['percent'] = $params['percent']; $data['to_shop'] = $params['to_shop']; $data['settle_day'] = $params['settle_day']; $count = model('app\admin\model\service\shop\Shop')->where('state',1)->count(); $data['day'] = 1; $data['accept_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('shop_accept_nums'); $data['service_nums'] = \app\api\model\service\ProjectConfig::getProjectConfig('service_nums'); $data['code'] = str_pad(date('d').$count,8,0); $data['updatetime'] = time(); unset($data['id']); $shop = new Shop($data); $shop->allowField(true)->save(); 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(); } }