objDCase = new DCase('manage'); $this->objDCategory = new DCategory('manage'); } /** * 案例添加 * @param $params * @return ResultWrapper */ public function addCase($params) { $dbResult = $this->objDCase->insert($params); if($dbResult === false){ return ResultWrapper::fail($this->objDCase->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 案例列表 * @param $params * @return ResultWrapper */ public function getAllCase($params) { $dbResult = $this->objDCase->select([], '*', 'id desc', $params['limit'], $params['offset']); if($dbResult === false){ return ResultWrapper::fail($this->objDCase->error(), ErrorCode::$dberror); } if(empty($dbResult)){ return ResultWrapper::success($dbResult); } $caseData = $dbResult; unset($dbResult); $total = $this->objDCase->count(); $dbResult = $this->objDCategory->select(['type' => StatusCode::$standard, 'enableStatus' => StatusCode::$standard], 'id,categoryName', 'sort desc'); if($dbResult === false){ return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror); } if(empty($dbResult)){ return ResultWrapper::success($dbResult); } $format = []; foreach($dbResult as $value){ $format[$value['id']] = $value['categoryName']; } $returnData = []; $returnData['total'] = $total ? $total : 0; foreach($caseData as $value){ $data = $value; $data['categoryName'] = isset($format[$value['caseCategoryId']]) ? $format[$value['caseCategoryId']] : ''; $returnData['data'][] = $data; } return ResultWrapper::success($returnData); } /** * 增加点击量 * @param $id * @return ResultWrapper */ public function addCaseClicks($id) { $dbResult = $this->objDCase->set_inc('clicks', ['id' => $id]); if($dbResult === false){ return ResultWrapper::fail($this->objDCase->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 案例详情 * @param $id * @return ResultWrapper */ public function caseInfo($id) { $dbResult = $this->objDCase->get(['id' => $id]); if(!empty($dbResult['content'])){ $dbResult['content'] = html_entity_decode($dbResult['content']); } $dbResult['categoryName'] = ''; $categoryResult = $this->objDCategory->get(['id' => $dbResult['caseCategoryId'], 'enableStatus' => StatusCode::$standard]); if($categoryResult === false){ return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror); } $dbResult['categoryName'] = $categoryResult; if($dbResult === false){ return ResultWrapper::fail($this->objDCase->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 案例编辑 * @param $params * @param $id * @return ResultWrapper */ public function updateCase($params, $id) { $dbResult = $this->objDCase->update($params, ['id' => $id]); if($dbResult === false){ return ResultWrapper::fail($this->objDCase->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 案例删除 * @param $id * @return ResultWrapper */ public function delCase($id) { $dbResult = $this->objDCase->delete(['id' => $id]); if($dbResult === false){ return ResultWrapper::fail($this->objDCase->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } }