Article.Class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Controller\Enterprise;
  10. use JinDouYun\Model\Enterprise\MArticle;
  11. use JinDouYun\Model\Enterprise\MPersonnel;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\ResultWrapper;
  14. use Mall\Framework\Core\StatusCode;
  15. use JinDouYun\Cache\ShopCache;
  16. use JinDouYun\Controller\BaseController;
  17. use JinDouYun\Cache\TempSaveCache;
  18. class Article extends BaseController
  19. {
  20. private $obj;
  21. private $objShopCache;
  22. private $objTempSaveCache;
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->obj = new MArticle($this->onlineEnterpriseId, $this->onlineUserId);
  27. $this->objShopCache = new ShopCache();
  28. $this->objTempSaveCache = new TempSaveCache();
  29. }
  30. /**
  31. * 添加和编辑商铺管理公共字段处理方法
  32. *
  33. * @return array
  34. */
  35. public function commonFieldFilter(){
  36. $params = $this->request->getRawJson();
  37. if( empty($params) ){
  38. $this->sendOutput('参数为空', ErrorCode::$paramError );
  39. }
  40. $shopData = [
  41. 'title' => isset($params['title']) ? $params['title'] : '',
  42. 'content' => isset($params['content']) ? $params['content'] : '',
  43. 'type' => isset($params['type']) ? $params['type'] : '',
  44. ];
  45. //非暂存则验空
  46. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  47. foreach($shopData as $key => $value){
  48. if(empty($value) && $value !== 0){
  49. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  50. }
  51. }
  52. }
  53. return $shopData;
  54. }
  55. /**
  56. * 列表
  57. */
  58. public function list()
  59. {
  60. $params = $this->request->params();
  61. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  62. $selectParams['limit'] = $pageParams['limit'];
  63. $selectParams['offset'] = $pageParams['offset'];
  64. //uid
  65. if(isset($params['name']) && !empty($params['name'])){
  66. $selectParams['name'] = $params['name'];
  67. }
  68. if(isset($params['type']) && !empty($params['type'])){
  69. $selectParams['type'] = $params['type'];
  70. }
  71. $selectParams['en_id'] = $this->onlineEnterpriseId;
  72. $result = $this->obj->list($selectParams);
  73. if ($result->isSuccess()) {
  74. $returnData = $result->getData();
  75. $pageData = [
  76. 'pageIndex' => $params['page'],
  77. 'pageSize' => $params['pageSize'],
  78. 'pageTotal' => $returnData['total'],
  79. ];
  80. parent::sendOutput($returnData['data'], 0, $pageData);
  81. } else {
  82. parent::sendOutput($result->getData( ), ErrorCode::$dberror);
  83. }
  84. }
  85. /**
  86. * 添加
  87. * @throws \Exception
  88. */
  89. public function add()
  90. {
  91. $addStaffData = $this->commonFieldFilter();
  92. // $addStaffData['shop_id'] = $this->shopId;
  93. $addStaffData['en_id'] = $this->onlineEnterpriseId;
  94. $result = $this->obj->details(['type' => $addStaffData['type']]);
  95. if ($result) $this->sendOutput('相关文章已添加', ErrorCode::$paramError);
  96. $result = $this->obj->insert($addStaffData);
  97. if ($result->isSuccess()) {
  98. parent::sendOutput($result->getData());
  99. } else {
  100. parent::sendOutput($result->getData(), $result->getErrorCode());
  101. }
  102. }
  103. /**
  104. * 详情
  105. * @return void
  106. */
  107. public function details()
  108. {
  109. $where = [];
  110. $id = $this->request->param('id');
  111. $type = $this->request->param('type');
  112. if(!empty($id)){
  113. $where['id'] = $id;
  114. }
  115. if(!empty($type)){
  116. $where['type'] = $type;
  117. }
  118. $result = $this->obj->details($where);
  119. if ($result->isSuccess()) {
  120. parent::sendOutput($result->getData());
  121. } else {
  122. parent::sendOutput($result->getData(), $result->getErrorCode());
  123. }
  124. }
  125. /**
  126. * 修改
  127. * @return void
  128. */
  129. public function update()
  130. {
  131. $id['id'] = $this->request->param('id');
  132. if (empty($id['id'])) {
  133. $this->sendOutput('参数为空', ErrorCode::$paramError);
  134. }
  135. $params = $this->commonFieldFilter();
  136. $result = $this->obj->update($params, $id);
  137. if ($result->isSuccess()) {
  138. parent::sendOutput($result->getData());
  139. } else {
  140. parent::sendOutput($result->getData(), $result->getErrorCode());
  141. }
  142. }
  143. public function delete()
  144. {
  145. $id['id'] = $this->request->param('id');
  146. if (empty($id['id'])) {
  147. $this->sendOutput('参数为空', ErrorCode::$paramError);
  148. }
  149. $result = $this->obj->delete($id);
  150. if ($result->isSuccess()) {
  151. parent::sendOutput($result->getData());
  152. } else {
  153. parent::sendOutput($result->getData(), $result->getErrorCode());
  154. }
  155. }
  156. }