obj = new MArticle($this->onlineEnterpriseId, $this->onlineUserId); $this->objShopCache = new ShopCache(); $this->objTempSaveCache = new TempSaveCache(); } /** * 添加和编辑商铺管理公共字段处理方法 * * @return array */ public function commonFieldFilter(){ $params = $this->request->getRawJson(); if( empty($params) ){ $this->sendOutput('参数为空', ErrorCode::$paramError ); } $shopData = [ 'title' => isset($params['title']) ? $params['title'] : '', 'content' => isset($params['content']) ? $params['content'] : '', 'type' => isset($params['type']) ? $params['type'] : '', ]; //非暂存则验空 if (!isset($params['tempSave']) || $params['tempSave'] == false) { foreach($shopData as $key => $value){ if(empty($value) && $value !== 0){ $this->sendOutput($key.'参数错误', ErrorCode::$paramError ); } } } return $shopData; } /** * 列表 */ public function list() { $params = $this->request->params(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; //uid if(isset($params['name']) && !empty($params['name'])){ $selectParams['name'] = $params['name']; } if(isset($params['type']) && !empty($params['type'])){ $selectParams['type'] = $params['type']; } $selectParams['en_id'] = $this->onlineEnterpriseId; $result = $this->obj->list($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($result->getData( ), ErrorCode::$dberror); } } /** * 添加 * @throws \Exception */ public function add() { $addStaffData = $this->commonFieldFilter(); // $addStaffData['shop_id'] = $this->shopId; $addStaffData['en_id'] = $this->onlineEnterpriseId; $result = $this->obj->details(['type' => $addStaffData['type']]); if ($result) $this->sendOutput('相关文章已添加', ErrorCode::$paramError); $result = $this->obj->insert($addStaffData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 详情 * @return void */ public function details() { $where = []; $id = $this->request->param('id'); $type = $this->request->param('type'); if(!empty($id)){ $where['id'] = $id; } if(!empty($type)){ $where['type'] = $type; } $result = $this->obj->details($where); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 修改 * @return void */ public function update() { $id['id'] = $this->request->param('id'); if (empty($id['id'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $params = $this->commonFieldFilter(); $result = $this->obj->update($params, $id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } public function delete() { $id['id'] = $this->request->param('id'); if (empty($id['id'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->obj->delete($id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } }