ShopKey.Class.php 4.7 KB

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