ShopTemplate.Class.php 4.7 KB

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