ShopCardBind.Class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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\MShopCardBind;
  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 ShopCardBind 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 MShopCardBind($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. 'card_id' => isset($params['card_id']) ? $params['card_id'] : '',
  41. 'project_id' => isset($params['project_id']) ? $params['project_id'] : '',
  42. 'number' => isset($params['number']) ? $params['number'] : '',
  43. ];
  44. //非暂存则验空
  45. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  46. foreach($shopData as $key => $value){
  47. if(empty($value) && $value !== 0){
  48. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  49. }
  50. }
  51. }
  52. return $shopData;
  53. }
  54. /**
  55. * 列表
  56. */
  57. public function list()
  58. {
  59. $params = $this->request->getRawJson();
  60. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  61. $selectParams['limit'] = $pageParams['limit'];
  62. $selectParams['offset'] = $pageParams['offset'];
  63. if (!$params['card_id']) parent::sendOutput('参数错误', 1005);
  64. $selectParams[] = ['card_id', '=', $params['card_id']];
  65. //uid
  66. if(isset($params['name']) && !empty($params['name'])){
  67. $selectParams[] = [];
  68. }
  69. $result = $this->obj->list($selectParams);
  70. if ($result->isSuccess()) {
  71. $returnData = $result->getData();
  72. $pageData = [
  73. 'pageIndex' => $params['page'],
  74. 'pageSize' => $params['pageSize'],
  75. 'pageTotal' => $returnData['total'],
  76. ];
  77. parent::sendOutput($returnData['data'], 0, $pageData);
  78. } else {
  79. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  80. }
  81. }
  82. /**
  83. * 添加
  84. * @throws \Exception
  85. */
  86. public function add()
  87. {
  88. $addStaffData = $this->commonFieldFilter();
  89. // $addStaffData['shop_id'] = $this->shopId;
  90. $result = $this->obj->insert($addStaffData);
  91. if ($result->isSuccess()) {
  92. parent::sendOutput($result->getData());
  93. } else {
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. }
  97. /**
  98. * 详情
  99. * @return void
  100. */
  101. public function details()
  102. {
  103. $where = [];
  104. $id = $this->request->param('id');
  105. if(!empty($id)){
  106. $where['id'] = $id;
  107. }
  108. $result = $this->obj->details($where);
  109. if ($result->isSuccess()) {
  110. parent::sendOutput($result->getData());
  111. } else {
  112. parent::sendOutput($result->getData(), $result->getErrorCode());
  113. }
  114. }
  115. /**
  116. * 修改
  117. * @return void
  118. */
  119. public function update()
  120. {
  121. $id['id'] = $this->request->param('id');
  122. if (empty($id['id'])) {
  123. $this->sendOutput('参数为空', ErrorCode::$paramError);
  124. }
  125. $params['project_id'] = $this->request->param('project_id');
  126. $params['number'] = $this->request->param('number');
  127. $result = $this->obj->update($params, $id);
  128. if ($result->isSuccess()) {
  129. parent::sendOutput($result->getData());
  130. } else {
  131. parent::sendOutput($result->getData(), $result->getErrorCode());
  132. }
  133. }
  134. public function delete()
  135. {
  136. $id['id'] = $this->request->param('id');
  137. if (empty($id['id'])) {
  138. $this->sendOutput('参数为空', ErrorCode::$paramError);
  139. }
  140. $result = $this->obj->delete($id);
  141. if ($result->isSuccess()) {
  142. parent::sendOutput($result->getData());
  143. } else {
  144. parent::sendOutput($result->getData(), $result->getErrorCode());
  145. }
  146. }
  147. }