CommissionGoods.Class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace JinDouYun\Controller\Commission;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\Commission\MCommissionCalculate;
  5. use JinDouYun\Model\Commission\MCommissionGoods;
  6. use Mall\Framework\Core\ErrorCode;
  7. use Mall\Framework\Core\StatusCode;
  8. /**
  9. * 分销商品控制器
  10. * Description:
  11. * Class CommissionGoods
  12. */
  13. class CommissionGoods extends BaseController
  14. {
  15. /**
  16. * @var MCommissionGoods
  17. */
  18. private $objMCommissionGoods;
  19. /**
  20. * CommissionGoods constructor.
  21. * @param bool $isCheckAcl
  22. * @param bool $isMustLogin
  23. * @param bool $checkToken
  24. * @param bool $getAreaCode
  25. * @throws \Exception
  26. */
  27. public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false)
  28. {
  29. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
  30. $this->objMCommissionGoods = new MCommissionGoods($this->onlineEnterpriseId,$this->onlineUserId);
  31. }
  32. public function __destruct()
  33. {
  34. // TODO: Implement __destruct() method.
  35. }
  36. /**
  37. * Doc: (des="分销商品列表")
  38. * User: XMing
  39. * Date: 2020/7/22
  40. * Time: 11:56 上午
  41. */
  42. public function getAll()
  43. {
  44. $params = $this->request->getRawJson();
  45. $page = isset($params['page']) ? $params['page'] : 1;
  46. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  47. $offset = ($page - 1) * $pageSize;
  48. $params['limit'] = $pageSize;
  49. $params['offset'] = $offset;
  50. $dbResult = $this->objMCommissionGoods->getAll($params);
  51. if ($dbResult->isSuccess()) {
  52. $returnData = $dbResult->getData();
  53. $pageData = [
  54. 'pageIndex' => $page,
  55. 'pageSize' => $pageSize,
  56. 'pageTotal' => $returnData['total']
  57. ];
  58. parent::sendOutput($returnData['data'], 0, $pageData);
  59. }
  60. parent::sendOutput($dbResult->getData(), ErrorCode::$dberror);
  61. }
  62. /**
  63. * Doc: (des="设置商品佣金")
  64. * User: XMing
  65. * Date: 2020/7/22
  66. * Time: 12:20 下午
  67. * @example {"id":131,"isDefine":5,"isJoinCommission":5,"commission_rule":[{"skuId":1036,"rule":{"0":{"oneRate":1,"twoRate":2,"threeRate":3},"2":{"oneRate":4,"twoRate":5,"threeRate":6},"3":{"oneRate":7,"twoRate":8,"threeRate":9},"4":{"oneRate":10,"twoRate":11,"threeRate":12}}},{"skuId":1037,"rule":{"0":{"oneRate":1,"twoRate":2,"threeRate":3},"2":{"oneRate":4,"twoRate":5,"threeRate":6},"3":{"oneRate":7,"twoRate":8,"threeRate":9},"4":{"oneRate":10,"twoRate":11,"threeRate":12}}},{"skuId":1038,"rule":{"0":{"oneRate":1,"twoRate":2,"threeRate":3},"2":{"oneRate":4,"twoRate":5,"threeRate":6},"3":{"oneRate":7,"twoRate":8,"threeRate":9},"4":{"oneRate":10,"twoRate":11,"threeRate":12}}}]}
  68. */
  69. public function setCommission()
  70. {
  71. $params = $this->request->getRawJson();
  72. $data = [
  73. 'id' => isset($params['id']) ? $params['id'] : null,
  74. 'isDefine' => isset($params['isDefine']) ? $params['isDefine'] : null,
  75. 'retType' => isset($params['retType']) ? $params['retType'] : StatusCode::$delete,
  76. 'isJoinCommission' => isset($params['isJoinCommission']) ? $params['isJoinCommission'] : null
  77. ];
  78. foreach ($data as $key => $value) {
  79. if (empty($value)) {
  80. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  81. }
  82. }
  83. $data['commission_rule'] = isset($params['commission_rule']) ? $params['commission_rule'] : null;
  84. $result = $this->objMCommissionGoods->setCommission($data);
  85. if ($result->isSuccess()) {
  86. parent::sendOutput($result->getData());
  87. }
  88. parent::sendOutput($result->getData(), $result->getErrorCode());
  89. }
  90. /**
  91. * Doc: (des="分销商品详情")
  92. * User: XMing
  93. * Date: 2020/7/22
  94. * Time: 12:03 下午
  95. */
  96. public function getInfo()
  97. {
  98. $id = $this->request->param('request_id');
  99. if (empty($id)) {
  100. $this->sendOutput('参数错误', ErrorCode::$paramError);
  101. }
  102. $result = $this->objMCommissionGoods->getInfo($id);
  103. if ($result->isSuccess()) {
  104. parent::sendOutput($result->getData());
  105. }
  106. parent::sendOutput($result->getData(), $result->getErrorCode());
  107. }
  108. /**
  109. * Doc: (des="商品批量设置是否参与分销")
  110. * User: XMing
  111. * Date: 2020/7/22
  112. * Time: 12:25 下午
  113. */
  114. public function updateIsJoin()
  115. {
  116. $params = $this->request->getRawJson();
  117. $data = [
  118. 'id' => isset($params['id']) ? $params['id'] : null,
  119. 'isJoinCommission' => isset($params['isJoinCommission']) ? $params['isJoinCommission'] : null,
  120. ];
  121. foreach ($data as $key => $value) {
  122. if (empty($value)) {
  123. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  124. }
  125. }
  126. $result = $this->objMCommissionGoods->updateIsJoin($data);
  127. if ($result->isSuccess()) {
  128. parent::sendOutput($result->getData());
  129. }
  130. parent::sendOutput($result->getData(), $result->getErrorCode());
  131. }
  132. public function test()
  133. {
  134. // $obj = new MCommissionCalculate(1,1);
  135. // try {
  136. // //$test = $obj->createCommission(8, 891);
  137. // $test = $obj->upgrade();
  138. // if (!$test->isSuccess()){
  139. // parent::sendOutput($test->getData(),$test->getErrorCode());
  140. // }
  141. // parent::sendOutput($test->getData());
  142. // } catch (\Exception $e) {
  143. // }
  144. $objMCommissionGoods = new MCommissionGoods(1,1);
  145. $test = $objMCommissionGoods->formatGoods([
  146. [
  147. 'skuId' => '1027',
  148. 'goodsId' => '130'
  149. ]
  150. ]);
  151. print_r($test);die;
  152. }
  153. }