Material.Class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * 素材库Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2020/04/27
  7. * Time: 14:20
  8. */
  9. namespace JinDouYun\Controller\Material;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Material\MMaterial;
  15. class Material extends BaseController
  16. {
  17. private $objMMaterial;
  18. public function __construct($isCheckAcl = false, $isMustLogin = true)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin);
  21. $this->objMMaterial = new MMaterial($this->onlineEnterpriseId, $this->onlineUserId);
  22. }
  23. /**
  24. * 素材内容添加
  25. * @throws Exception
  26. */
  27. public function addMaterialContent()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. parent::sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $data = [
  34. 'name' => isset($params['name']) ? $params['name'] : '',
  35. 'content' => isset($params['content']) ? $params['content'] : '',
  36. ];
  37. foreach($data as $key => $value){
  38. if(empty($value)){
  39. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  40. }
  41. }
  42. $this->shopId && $data['shopId'] = $this->shopId;
  43. $data['categoryId'] = isset($params['categoryId']) ? $params['categoryId'] : 0;
  44. $result = $this->objMMaterial->addMaterialContent($data);
  45. if ($result->isSuccess()) {
  46. parent::sendOutput($result->getData());
  47. } else {
  48. parent::sendOutput($result->getData(), $result->getErrorCode());
  49. }
  50. }
  51. /**
  52. * 素材分类添加
  53. * @throws Exception
  54. */
  55. public function addMaterialCategory()
  56. {
  57. $params = $this->request->getRawJson();
  58. if (empty($params)) {
  59. parent::sendOutput('参数为空', ErrorCode::$paramError);
  60. }
  61. $data = [
  62. 'title' => isset($params['title']) ? $params['title'] : '',
  63. ];
  64. foreach($data as $key => $value){
  65. if(empty($value)){
  66. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  67. }
  68. }
  69. $data['pid'] = isset($params['pid']) ? $params['pid'] : 0;
  70. $this->shopId && $data['shopId'] = $this->shopId;
  71. $result = $this->objMMaterial->addMaterialCategory($data);
  72. if ($result->isSuccess()) {
  73. parent::sendOutput($result->getData());
  74. } else {
  75. parent::sendOutput($result->getData(), $result->getErrorCode());
  76. }
  77. }
  78. /**
  79. * 素材内容编辑
  80. * @throws Exception
  81. */
  82. public function updateMaterialContent()
  83. {
  84. $params = $this->request->getRawJson();
  85. if (empty($params)) {
  86. parent::sendOutput('参数为空', ErrorCode::$paramError);
  87. }
  88. $data = [
  89. 'categoryId' => isset($params['categoryId']) ? $params['categoryId'] : '',
  90. 'id' => isset($params['id']) ? $params['id'] : '',
  91. ];
  92. $result = $this->objMMaterial->updateMaterialContent($data);
  93. if ($result->isSuccess()) {
  94. parent::sendOutput($result->getData());
  95. } else {
  96. parent::sendOutput($result->getData(), $result->getErrorCode());
  97. }
  98. }
  99. /**
  100. * 素材分类编辑
  101. * @throws Exception
  102. */
  103. public function updateMaterialCategory()
  104. {
  105. $params = $this->request->getRawJson();
  106. if (empty($params)) {
  107. parent::sendOutput('参数为空', ErrorCode::$paramError);
  108. }
  109. $data = [
  110. 'title' => isset($params['title']) ? $params['title'] : '',
  111. 'id' => isset($params['id']) ? $params['id'] : '',
  112. ];
  113. $result = $this->objMMaterial->updateMaterialCategory($data);
  114. if ($result->isSuccess()) {
  115. parent::sendOutput($result->getData());
  116. } else {
  117. parent::sendOutput($result->getData(), $result->getErrorCode());
  118. }
  119. }
  120. /**
  121. * 素材内容删除
  122. */
  123. public function delMaterialContent()
  124. {
  125. $params = $this->request->getRawJson();
  126. if (empty($params)) {
  127. $this->sendOutput('参数为空', ErrorCode::$paramError);
  128. }
  129. if (!isset($params['id']) || empty($params['id'])) {
  130. $this->sendOutput('参数为空', ErrorCode::$paramError);
  131. }
  132. $result = $this->objMMaterial->delMaterialContent($params);
  133. if ($result->isSuccess()) {
  134. parent::sendOutput($result->getData());
  135. } else {
  136. parent::sendOutput($result->getData(), $result->getErrorCode());
  137. }
  138. }
  139. /**
  140. * 素材分类删除
  141. */
  142. public function delMaterialCategory()
  143. {
  144. $params['id'] = $this->request->param('request_id');
  145. if (empty($params)) {
  146. $this->sendOutput('参数为空', ErrorCode::$paramError);
  147. }
  148. $result = $this->objMMaterial->delMaterialCategory($params);
  149. if ($result->isSuccess()) {
  150. parent::sendOutput($result->getData());
  151. } else {
  152. parent::sendOutput($result->getData(), $result->getErrorCode());
  153. }
  154. }
  155. /**
  156. * 素材分类列表
  157. */
  158. public function getAllMaterialCategory()
  159. {
  160. $params = [];
  161. $this->shopId && $params['shopId'] = $this->shopId;
  162. $result = $this->objMMaterial->getAllMaterialCategory($params);
  163. if ($result->isSuccess()) {
  164. parent::sendOutput($result->getData());
  165. } else {
  166. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  167. }
  168. }
  169. /**
  170. * 素材内容列表
  171. */
  172. public function getAllMaterialContent()
  173. {
  174. $params = $this->request->getRawJson();
  175. if (empty($params)) {
  176. parent::sendOutput('参数为空', ErrorCode::$paramError);
  177. }
  178. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  179. $selectParams['limit'] = $pageParams['limit'];
  180. $selectParams['offset'] = $pageParams['offset'];
  181. $selectParams['categoryId'] = isset($params['categoryId']) ? $params['categoryId'] : 0;
  182. $selectParams['name'] = isset($params['name']) ? $params['name'] : '';
  183. $this->shopId && $selectParams['shopId'] = $this->shopId;
  184. $result = $this->objMMaterial->getAllMaterialContent($selectParams);
  185. if ($result->isSuccess()) {
  186. $returnData = $result->getData();
  187. $pageData = [
  188. 'pageIndex' => $params['page'],
  189. 'pageSize' => $params['pageSize'],
  190. 'pageTotal' => $returnData['total'],
  191. ];
  192. parent::sendOutput($returnData['data'], 0, $pageData);
  193. } else {
  194. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  195. }
  196. }
  197. }