Reward.Class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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\Reward;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Reward\MReward;
  14. class Reward extends BaseController
  15. {
  16. private $objMReward;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMReward = new MReward($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 获取参数
  24. * @return array
  25. */
  26. public function commonFieldFilter()
  27. {
  28. $params = $this->request->getRawJson();
  29. if (empty($params)) {
  30. parent::sendOutput('参数为空', ErrorCode::$paramError);
  31. }
  32. $data = [
  33. 'staff' => isset($params['staff']) ? $params['staff'] : [],
  34. ];
  35. foreach($data as $key => $value){
  36. if(empty($value)){
  37. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  38. }
  39. }
  40. !empty($this->shopId) && $data['shopId'] = $this->shopId;
  41. isset($params['computed']) && $data['computed'] = !empty($params['computed']) ? $params['computed'] : '';
  42. isset($params['title']) && $data['title'] = !empty($params['title']) ? $params['title'] : '';
  43. isset($params['percentage']) && $data['percentage'] = !empty($params['percentage']) ? $params['percentage'] : 0;
  44. isset($params['goods']) && $data['goods'] = !empty($params['goods']) ? json_encode($params['goods']) : null;
  45. return $data;
  46. }
  47. /**
  48. * 提成规则添加
  49. */
  50. public function addRewardRule()
  51. {
  52. $data = $this->commonFieldFilter();
  53. $result = $this->objMReward->addRewardRule($data);
  54. if ($result->isSuccess()) {
  55. parent::sendOutput($result->getData());
  56. } else {
  57. parent::sendOutput($result->getData(), $result->getErrorCode());
  58. }
  59. }
  60. /**
  61. * 提成规则删除
  62. */
  63. public function deleteRewardRule()
  64. {
  65. $id = $this->request->param('request_id');
  66. if (empty($id)) {
  67. $this->sendOutput('参数为空', ErrorCode::$paramError);
  68. }
  69. $result = $this->objMReward->deleteRewardRule(['id' => $id]);
  70. if ($result->isSuccess()) {
  71. parent::sendOutput($result->getData());
  72. } else {
  73. parent::sendOutput($result->getData(), $result->getErrorCode());
  74. }
  75. }
  76. /**
  77. * 提成规则禁用
  78. */
  79. public function enableRewardRule()
  80. {
  81. $params['id'] = $this->request->param('request_id');
  82. if (empty($params)) {
  83. $this->sendOutput('参数为空', ErrorCode::$paramError);
  84. }
  85. $result = $this->objMReward->enableRewardRule($params);
  86. if ($result->isSuccess()) {
  87. parent::sendOutput($result->getData());
  88. } else {
  89. parent::sendOutput($result->getData(), $result->getErrorCode());
  90. }
  91. }
  92. /**
  93. * 提成规则修改
  94. */
  95. public function updateRewardRule()
  96. {
  97. $id = $this->request->param('request_id');
  98. if(empty($id)){
  99. parent::sendOutput('id参数为空', ErrorCode::$paramError);
  100. }
  101. $data = self::commonFieldFilter();
  102. $result = $this->objMReward->updateRewardRule($data, ['id' => $id]);
  103. if ($result->isSuccess()) {
  104. parent::sendOutput($result->getData());
  105. } else {
  106. parent::sendOutput($result->getData(), $result->getErrorCode());
  107. }
  108. }
  109. /**
  110. * 提成规则列表
  111. */
  112. public function getAllRewardRule()
  113. {
  114. $params = $this->request->getRawJson();
  115. if (empty($params)) {
  116. parent::sendOutput('参数为空', ErrorCode::$paramError);
  117. }
  118. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  119. $selectParams['limit'] = $pageParams['limit'];
  120. $selectParams['offset'] = $pageParams['offset'];
  121. if(isset($params['search']) && !empty($params['search'])){
  122. $selectParams['search'] = $params['search'];
  123. }
  124. if(isset($params['enableStatus']) && !empty($params['enableStatus'])){
  125. $selectParams['enableStatus'] = $params['enableStatus'];
  126. }
  127. if(isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])){
  128. $selectParams['star'] = $params['star'];
  129. $selectParams['end'] = $params['end'];
  130. }
  131. if(!empty($this->shopId)){
  132. $selectParams['shopId'] = $this->shopId;
  133. }
  134. $result = $this->objMReward->getAllRewardRule($selectParams);
  135. if ($result->isSuccess()) {
  136. $returnData = $result->getData();
  137. $pageData = [
  138. 'pageIndex' => $params['page'],
  139. 'pageSize' => $params['pageSize'],
  140. 'pageTotal' => $returnData['total'],
  141. ];
  142. parent::sendOutput($returnData['data'], 0, $pageData);
  143. } else {
  144. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  145. }
  146. }
  147. /**
  148. * 提成规则详情
  149. */
  150. public function getRewardRuleInfo()
  151. {
  152. $params['id'] = $this->request->param('request_id');
  153. if (empty($params['id'])) {
  154. $this->sendOutput('参数为空', ErrorCode::$paramError);
  155. }
  156. $result = $this->objMReward->getRewardRuleInfo($params);
  157. if ($result->isSuccess()) {
  158. parent::sendOutput($result->getData());
  159. } else {
  160. parent::sendOutput($result->getData(), $result->getErrorCode());
  161. }
  162. }
  163. }