ApiIntegralGoods.Class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * 积分商品Controller
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2021/03/25
  7. * Time: 16:00
  8. */
  9. namespace JinDouYun\Controller\Integral;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Integral\MIntegralGoods;
  14. class ApiIntegralGoods extends BaseController
  15. {
  16. private $objMIntegralGoods;
  17. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken=true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  20. $this->objMIntegralGoods = new MIntegralGoods($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 积分商品兑换添加
  24. */
  25. public function addIntegralGoodsExchange()
  26. {
  27. $params = $this->request->getRawJson();
  28. if (empty($params)) {
  29. parent::sendOutput('参数为空', ErrorCode::$paramError);
  30. }
  31. $data = [
  32. 'goodsId' => isset($params['goodsId']) ? $params['goodsId'] : '',
  33. 'num' => isset($params['num']) ? $params['num'] : [],
  34. 'address' => isset($params['address']) ? json_encode($params['address']) : [],
  35. ];
  36. foreach($data as $key => $value){
  37. if(empty($value)){
  38. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  39. }
  40. }
  41. $data['shopId'] = $this->shopId ? $this->shopId : 0;
  42. $data['userCenterId'] = isset($params['userCenterId']) ? $params['userCenterId'] : '';
  43. if(empty($data['userCenterId'])){
  44. $data['userCenterId'] = $this->onlineUserId;
  45. }
  46. $data['remark'] = isset($params['remark']) ? $params['remark'] : '';
  47. $result = $this->objMIntegralGoods->addIntegralGoodsExchange($data);
  48. if ($result->isSuccess()) {
  49. parent::sendOutput($result->getData());
  50. } else {
  51. parent::sendOutput($result->getData(), $result->getErrorCode());
  52. }
  53. }
  54. /**
  55. * 积分商品列表
  56. */
  57. public function getAllIntegralGoods()
  58. {
  59. $params = $this->request->getRawJson();
  60. if (empty($params)) {
  61. parent::sendOutput('参数为空', ErrorCode::$paramError);
  62. }
  63. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  64. $selectParams['limit'] = $pageParams['limit'];
  65. $selectParams['offset'] = $pageParams['offset'];
  66. if(isset($params['search']) && !empty($params['search'])){
  67. $selectParams['search'] = $params['search'];
  68. }
  69. if(!empty($this->shopId)){
  70. $selectParams['shopId'] = $this->shopId;
  71. }
  72. $result = $this->objMIntegralGoods->getAllIntegralGoods($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. */
  88. public function getIntegralGoodsInfo()
  89. {
  90. $params['id'] = $this->request->param('request_id');
  91. if (empty($params['id'])) {
  92. $this->sendOutput('参数为空', ErrorCode::$paramError);
  93. }
  94. $result = $this->objMIntegralGoods->getIntegralGoodsInfo($params);
  95. if ($result->isSuccess()) {
  96. parent::sendOutput($result->getData());
  97. } else {
  98. parent::sendOutput($result->getData(), $result->getErrorCode());
  99. }
  100. }
  101. /**
  102. * 积分商品兑换列表
  103. */
  104. public function getAllIntegralGoodsExchange()
  105. {
  106. $params = $this->request->getRawJson();
  107. if (empty($params)) {
  108. parent::sendOutput('参数为空', ErrorCode::$paramError);
  109. }
  110. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  111. $selectParams['limit'] = $pageParams['limit'];
  112. $selectParams['offset'] = $pageParams['offset'];
  113. if(isset($params['search']) && !empty($params['search'])){
  114. $selectParams['search'] = $params['search'];
  115. }
  116. if(isset($params['status']) && !empty($params['status'])){
  117. $selectParams['status'] = $params['status'];
  118. }
  119. if(!empty($this->shopId)){
  120. $selectParams['shopId'] = $this->shopId;
  121. }
  122. $selectParams['userCenterId'] = $this->onlineUserId;
  123. $result = $this->objMIntegralGoods->getAllIntegralGoodsExchange($selectParams);
  124. if ($result->isSuccess()) {
  125. $returnData = $result->getData();
  126. $pageData = [
  127. 'pageIndex' => $params['page'],
  128. 'pageSize' => $params['pageSize'],
  129. 'pageTotal' => $returnData['total'],
  130. ];
  131. parent::sendOutput($returnData['data'], 0, $pageData);
  132. } else {
  133. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  134. }
  135. }
  136. /**
  137. * 积分商品兑换详情
  138. */
  139. public function getIntegralGoodsExchangeInfo()
  140. {
  141. $params['id'] = $this->request->param('request_id');
  142. if (empty($params['id'])) {
  143. $this->sendOutput('参数为空', ErrorCode::$paramError);
  144. }
  145. $result = $this->objMIntegralGoods->getIntegralGoodsExchangeInfo($params);
  146. if ($result->isSuccess()) {
  147. parent::sendOutput($result->getData());
  148. } else {
  149. parent::sendOutput($result->getData(), $result->getErrorCode());
  150. }
  151. }
  152. }