123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- /**
- * 案例管理Model
- * Created by PhpStorm.
- * User: 小威
- * Date: 2020/03/28
- * Time: 16:07
- */
- namespace JinDouYun\Model\Manage;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Manage\DCase;
- use JinDouYun\Dao\Manage\DCategory;
- class MCase
- {
- private $objDCase;
- private $objDCategory;
- public function __construct()
- {
- $this->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);
- }
- }
|