123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace JinDouYun\Controller\Market;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Market\MCoupon;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- class ApiCoupon extends BaseController
- {
- private $objMCoupon;
-
- public function __construct($isCheckAcl = false, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMCoupon = new MCoupon($this->onlineUserId, $this->onlineEnterpriseId);
- }
-
- public function couponList()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'grantType' => isset($paramsData['grantType']) ? $paramsData['grantType'] : '',
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- isset($paramsData['payAmount']) && $params['payAmount'] = $paramsData['payAmount'];
- $result = $this->objMCoupon->couponList($params);
- if ($result->isSuccess()) {
- $vipCoupon = $this->objMCoupon->vipCoupon();
- if (!$vipCoupon->isSuccess()) {
- parent::sendOutput($vipCoupon->getData(), $vipCoupon->getErrorCode());
- }
- $allCoupon = array_merge($result->getData(), $vipCoupon->getData());
- $pageData = [
- 'pageIndex' => 0,
- 'pageSize' => 10,
- 'pageTotal' => count($allCoupon),
- ];
- parent::sendOutput($allCoupon, 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function receive()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'couponId' => isset($paramsData['couponId']) ? $paramsData['couponId'] : '',
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $params['vipCardId'] = isset($paramsData['vipCardId']) ? $paramsData['vipCardId'] : 0;
- $result = $this->objMCoupon->receive($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function oneKeyReceive()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'couponId' => isset($paramsData['couponId']) ? $paramsData['couponId'] : '',
- 'vipCardId' => isset($paramsData['vipCardId']) ? $paramsData['vipCardId'] : '',
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMCoupon->oneKeyReceive($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
-
- public function selectAll()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'type' => isset($paramsData['type']) ? $paramsData['type'] : '',
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $pageParams = pageToOffset(isset($paramsData['page']) ? $paramsData['page'] : 1, isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $result = $this->objMCoupon->selectAll($params);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($paramsData['page']) ? $paramsData['page'] : 1,
- 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
|