Example.Class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * 案例管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/03/28
  7. * Time: 16:09
  8. */
  9. namespace JinDouYun\Controller\Manage;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Manage\MCase;
  14. class Example extends BaseController
  15. {
  16. private $objMCase;
  17. public function __construct($isCheckAcl = false, $isMustLogin = false, $checkToken = false)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  20. $this->objMCase = new MCase();
  21. }
  22. /**
  23. * 案例添加
  24. */
  25. public function addCase()
  26. {
  27. $params = $this->request->getRawJson();
  28. $data = [
  29. 'title' => isset($params['title']) ? $params['title'] : '',
  30. 'thumbnail' => isset($params['thumbnail']) ? $params['thumbnail'] : '',
  31. 'caseCategoryId' => isset($params['caseCategoryId']) ? $params['caseCategoryId'] : '',
  32. 'slogan' => isset($params['slogan']) ? $params['slogan'] : '',
  33. 'time' => isset($params['time']) ? $params['time'] : '',
  34. 'content' => isset($params['content']) ? $params['content'] : '',
  35. 'createTime' => time(),
  36. 'updateTime' => time(),
  37. ];
  38. foreach($data as $key => $value){
  39. if(empty($value)){
  40. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  41. }
  42. }
  43. $data['clicks'] = 0;
  44. $modelResult = $this->objMCase->addCase($data);
  45. if(!$modelResult->isSuccess()){
  46. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  47. }
  48. parent::sendOutput($modelResult->getData());
  49. }
  50. /**
  51. * 案例列表
  52. * @throws \Exception
  53. */
  54. public function getAllCase()
  55. {
  56. $params = $this->request->getRawJson();
  57. $data = [
  58. 'page' => isset($params['page']) ? $params['page'] : 1,
  59. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  60. ];
  61. $selectParams = [
  62. 'offset' => ($data['page'] - 1) * $data['pageSize'],
  63. 'limit' => $data['pageSize'],
  64. ];
  65. $result = $this->objMCase->getAllCase($selectParams);
  66. if ($result->isSuccess()) {
  67. parent::sendOutput($result->getData());
  68. } else {
  69. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  70. }
  71. }
  72. /**
  73. * 增加点击量
  74. */
  75. public function addCaseClicks()
  76. {
  77. $id = $this->request->param('request_id');
  78. if(empty($id)){
  79. parent::sendOutput('参数为空', ErrorCode::$paramError);
  80. }
  81. $result = $this->objMCase->addCaseClicks($id);
  82. if ($result->isSuccess()) {
  83. parent::sendOutput($result->getData());
  84. } else {
  85. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  86. }
  87. }
  88. /**
  89. * 案例详情
  90. */
  91. public function caseInfo()
  92. {
  93. $id = $this->request->param('request_id');
  94. if(empty($id)){
  95. parent::sendOutput('参数为空', ErrorCode::$paramError);
  96. }
  97. $result = $this->objMCase->caseInfo($id);
  98. if ($result->isSuccess()) {
  99. parent::sendOutput($result->getData());
  100. } else {
  101. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  102. }
  103. }
  104. /**
  105. * 案例编辑
  106. */
  107. public function updateCase()
  108. {
  109. $id = $this->request->param('request_id');
  110. if(empty($id)){
  111. parent::sendOutput('参数为空', ErrorCode::$paramError);
  112. }
  113. $params = $this->request->getRawJson();
  114. $data = [
  115. 'title' => isset($params['title']) ? $params['title'] : '',
  116. 'thumbnail' => isset($params['thumbnail']) ? $params['thumbnail'] : '',
  117. 'caseCategoryId' => isset($params['caseCategoryId']) ? $params['caseCategoryId'] : '',
  118. 'time' => isset($params['time']) ? $params['time'] : '',
  119. 'slogan' => isset($params['slogan']) ? $params['slogan'] : '',
  120. 'content' => isset($params['content']) ? $params['content'] : '',
  121. 'updateTime' => time(),
  122. ];
  123. foreach($data as $key => $value){
  124. if(empty($value)){
  125. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  126. }
  127. }
  128. $modelResult = $this->objMCase->updateCase($data, $id);
  129. if(!$modelResult->isSuccess()){
  130. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  131. }
  132. parent::sendOutput($modelResult->getData());
  133. }
  134. /**
  135. * 案例删除
  136. */
  137. public function delCase()
  138. {
  139. $id = $this->request->param('request_id');
  140. if(empty($id)){
  141. parent::sendOutput('参数为空', ErrorCode::$paramError);
  142. }
  143. $modelResult = $this->objMCase->delCase($id);
  144. if(!$modelResult->isSuccess()){
  145. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  146. }
  147. parent::sendOutput($modelResult->getData());
  148. }
  149. }