ApiCoupon.Class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * 优惠券
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/12/23
  7. * Time: 9:22
  8. */
  9. namespace JinDouYun\Controller\Market;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Model\Market\MCoupon;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. class ApiCoupon extends BaseController
  15. {
  16. private $objMCoupon;
  17. /**
  18. * ApiCoupon constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = false, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMCoupon = new MCoupon($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 可领取列表
  30. * @throws \Exception
  31. */
  32. public function couponList()
  33. {
  34. $paramsData = $this->request->getRawJson();
  35. $params = [
  36. 'grantType' => isset($paramsData['grantType']) ? $paramsData['grantType'] : '',//发放方式(10主动领取 20定向发放 30注册领取 40在线支付赠送)
  37. ];
  38. foreach ($params as $key => $value) {
  39. if (empty($value)) {
  40. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  41. }
  42. }
  43. isset($paramsData['payAmount']) && $params['payAmount'] = $paramsData['payAmount'];
  44. $result = $this->objMCoupon->couponList($params);
  45. if ($result->isSuccess()) {
  46. $vipCoupon = $this->objMCoupon->vipCoupon();
  47. if (!$vipCoupon->isSuccess()) {
  48. parent::sendOutput($vipCoupon->getData(), $vipCoupon->getErrorCode());
  49. }
  50. $allCoupon = array_merge($result->getData(), $vipCoupon->getData());
  51. $pageData = [
  52. 'pageIndex' => 0,
  53. 'pageSize' => 10,
  54. 'pageTotal' => count($allCoupon),
  55. ];
  56. parent::sendOutput($allCoupon, 0, $pageData);
  57. }
  58. parent::sendOutput($result->getData(), $result->getErrorCode());
  59. }
  60. /**
  61. * 领取优惠券(单个) (如果vipCardId!=0,则此优惠券是会员卡优惠券使用couponId = 如果vipCardId)
  62. * @throws \Exception
  63. */
  64. public function receive()
  65. {
  66. $paramsData = $this->request->getRawJson();
  67. $params = [
  68. 'couponId' => isset($paramsData['couponId']) ? $paramsData['couponId'] : '',
  69. ];
  70. foreach ($params as $key => $value) {
  71. if (empty($value)) {
  72. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  73. }
  74. }
  75. $params['vipCardId'] = isset($paramsData['vipCardId']) ? $paramsData['vipCardId'] : 0;
  76. $result = $this->objMCoupon->receive($params);
  77. if ($result->isSuccess()) {
  78. parent::sendOutput($result->getData());
  79. }
  80. parent::sendOutput($result->getData(), $result->getErrorCode());
  81. }
  82. /**
  83. * 会员卡一键领取优惠券
  84. * @throws \Exception
  85. */
  86. public function oneKeyReceive()
  87. {
  88. $paramsData = $this->request->getRawJson();
  89. $params = [
  90. 'couponId' => isset($paramsData['couponId']) ? $paramsData['couponId'] : '',//id有对个逗号分隔
  91. 'vipCardId' => isset($paramsData['vipCardId']) ? $paramsData['vipCardId'] : '',//一个id
  92. ];
  93. foreach ($params as $key => $value) {
  94. if (empty($value)) {
  95. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  96. }
  97. }
  98. $result = $this->objMCoupon->oneKeyReceive($params);
  99. if ($result->isSuccess()) {
  100. parent::sendOutput($result->getData());
  101. }
  102. parent::sendOutput($result->getData(), $result->getErrorCode());
  103. }
  104. /**
  105. * 优惠券盒子
  106. * @throws \Exception
  107. */
  108. public function selectAll()
  109. {
  110. $paramsData = $this->request->getRawJson();
  111. $params = [
  112. 'type' => isset($paramsData['type']) ? $paramsData['type'] : '',
  113. ];
  114. foreach ($params as $key => $value) {
  115. if (empty($value)) {
  116. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  117. }
  118. }
  119. $pageParams = pageToOffset(isset($paramsData['page']) ? $paramsData['page'] : 1, isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10);
  120. $params['limit'] = $pageParams['limit'];
  121. $params['offset'] = $pageParams['offset'];
  122. $result = $this->objMCoupon->selectAll($params);
  123. if ($result->isSuccess()) {
  124. $returnData = $result->getData();
  125. $pageData = [
  126. 'pageIndex' => isset($paramsData['page']) ? $paramsData['page'] : 1,
  127. 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
  128. 'pageTotal' => $returnData['total'],
  129. ];
  130. parent::sendOutput($returnData['data'], 0, $pageData);
  131. }
  132. parent::sendOutput($result->getData(), $result->getErrorCode());
  133. }
  134. }