ShopCard.Class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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\Shop\MShopCard;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Cache\ShopCache;
  15. use JinDouYun\Controller\BaseController;
  16. use JinDouYun\Cache\TempSaveCache;
  17. class ShopCard extends BaseController
  18. {
  19. private $obj;
  20. private $objShopCache;
  21. private $objTempSaveCache;
  22. public function __construct($isCheckAcl = true, $isMustLogin = true)
  23. {
  24. parent::__construct($isCheckAcl, $isMustLogin);
  25. $this->obj = new MShopCard($this->onlineEnterpriseId, $this->onlineUserId);
  26. $this->objShopCache = new ShopCache();
  27. $this->objTempSaveCache = new TempSaveCache();
  28. }
  29. /**
  30. * 添加和编辑商铺管理公共字段处理方法
  31. *
  32. * @return array
  33. */
  34. public function commonFieldFilter(){
  35. $params = $this->request->getRawJson();
  36. if( empty($params) ){
  37. $this->sendOutput('参数为空', ErrorCode::$paramError );
  38. }
  39. $shopData = [
  40. 'name' => isset($params['name']) ? $params['name'] : '',
  41. 'price' => isset($params['price']) ? $params['price'] : '',
  42. 'ot_price' => isset($params['ot_price']) ? $params['ot_price'] : '',
  43. 'image' => isset($params['image']) ? $params['image'] : '',
  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. $shopData['info']= isset($params['info']) ? $params['info'] : false;
  54. $shopData['introduce']= isset($params['introduce']) ? $params['introduce'] : false;
  55. $shopData['status']= isset($params['status']) ? $params['status'] : 1;
  56. return $shopData;
  57. }
  58. /**
  59. * 列表
  60. */
  61. public function list()
  62. {
  63. $params = $this->request->getRawJson();
  64. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  65. $selectParams['limit'] = $pageParams['limit'];
  66. $selectParams['offset'] = $pageParams['offset'];
  67. //uid
  68. if(isset($params['name']) && !empty($params['name'])){
  69. $selectParams['name'] = $params['name'];
  70. }
  71. $selectParams['enterprise_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['enterprise_id'] = $this->onlineEnterpriseId;
  94. $result = $this->obj->insert($addStaffData);
  95. if ($result->isSuccess()) {
  96. parent::sendOutput($result->getData());
  97. } else {
  98. parent::sendOutput($result->getData(), $result->getErrorCode());
  99. }
  100. }
  101. /**
  102. * 详情
  103. * @return void
  104. */
  105. public function details()
  106. {
  107. $where = [];
  108. $id = $this->request->param('id');
  109. if(!empty($id)){
  110. $where['id'] = $id;
  111. }
  112. $result = $this->obj->details($where);
  113. if ($result->isSuccess()) {
  114. parent::sendOutput($result->getData());
  115. } else {
  116. parent::sendOutput($result->getData(), $result->getErrorCode());
  117. }
  118. }
  119. /**
  120. * 修改
  121. * @return void
  122. */
  123. public function update()
  124. {
  125. $id['id'] = $this->request->param('id');
  126. if (empty($id['id'])) {
  127. $this->sendOutput('参数为空', ErrorCode::$paramError);
  128. }
  129. $params = $this->commonFieldFilter();
  130. $result = $this->obj->update($params, $id);
  131. if ($result->isSuccess()) {
  132. parent::sendOutput($result->getData());
  133. } else {
  134. parent::sendOutput($result->getData(), $result->getErrorCode());
  135. }
  136. }
  137. public function delete()
  138. {
  139. $id['id'] = $this->request->param('id');
  140. if (empty($id['id'])) {
  141. $this->sendOutput('参数为空', ErrorCode::$paramError);
  142. }
  143. $result = $this->obj->delete($id);
  144. if ($result->isSuccess()) {
  145. parent::sendOutput($result->getData());
  146. } else {
  147. parent::sendOutput($result->getData(), $result->getErrorCode());
  148. }
  149. }
  150. }