ApiVipCard.Class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * 会员卡管理模块
  4. * Created by PhpStorm.
  5. * User: tpl
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\Market;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Market\MVipCard;
  14. class ApiVipCard extends BaseController
  15. {
  16. private $objMVipCard;
  17. public function __construct($isCheckAcl = false, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMVipCard = new MVipCard($this->onlineEnterpriseId, $this->onlineUserId, true);
  21. }
  22. /**
  23. * 添加,编辑会员卡订单公共数据
  24. * @return array
  25. */
  26. public function commonFieldFilter()
  27. {
  28. $params = $this->request->getRawJson();
  29. if (empty($params)) {
  30. $this->sendOutput('参数为空', ErrorCode::$paramError);
  31. }
  32. $orderData = [
  33. 'payType' => isset($params['payType']) ? $params['payType'] : StatusCode::$payType['cashPay'],
  34. 'source' => isset($params['source']) ? $params['source'] : 0,//订单来源
  35. 'vipCardId' => isset($params['vipCardId']) ? $params['vipCardId'] : '',//会员卡id
  36. ];
  37. foreach ($orderData as $key => $value) {
  38. if (empty($value) && $value !== 0) {
  39. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  40. }
  41. }
  42. $orderData['remark'] = isset($params['remark']) ? $params['remark'] : '';//订单备注
  43. return $orderData;
  44. }
  45. /**
  46. * 购买会员卡
  47. */
  48. public function createVipCardOrder() {
  49. $orderData = $this->commonFieldFilter();
  50. $ip = $this->request->get_onlineip();
  51. $result = $this->objMVipCard->createVipCardOrder($orderData, $ip);
  52. if ($result->isSuccess()) {
  53. parent::sendOutput($result->getData());
  54. }
  55. parent::sendOutput($result->getData(), $result->getErrorCode());
  56. }
  57. //会员卡详情
  58. public function getVipInfo() {
  59. $vipCardId = $this->request->param('request_id');
  60. if ( !$vipCardId ) {
  61. $this->sendOutput('参数错误', ErrorCode::$paramError );
  62. }
  63. $result = $this->objMVipCard->getVipCardInfo($vipCardId);
  64. if($result->isSuccess()){
  65. $this->sendOutput($result->getData());
  66. }else{
  67. $this->sendOutput($result->getData(), $result->getErrorCode());
  68. }
  69. }
  70. /**
  71. * 前台所有会员卡列表
  72. */
  73. public function getAllVipCard()
  74. {
  75. $params = $this->request->getRawJson();
  76. if( empty($params) ){
  77. $this->sendOutput('参数为空', ErrorCode::$paramError );
  78. }
  79. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  80. $selectParams['limit'] = $pageParams['limit'];
  81. $selectParams['offset'] = $pageParams['offset'];
  82. $result = $this->objMVipCard->getAllFrontVipCard($selectParams);
  83. if($result->isSuccess()){
  84. $returnData = $result->getData();
  85. $pageData = [
  86. 'pageIndex' => $params['page'],
  87. 'pageSize' => $params['pageSize'],
  88. 'pageTotal' => $returnData['total'],
  89. 'received' => $returnData['received']
  90. ];
  91. parent::sendOutput($returnData['data'], 0, $pageData);
  92. }else{
  93. parent::sendOutput($result->getData(), $result->getErrorCode());
  94. }
  95. }
  96. /**
  97. * 获取会员购买的所有会员卡
  98. */
  99. public function getMyVipCards() {
  100. $params = $this->request->getRawJson();
  101. if( empty($params) ){
  102. $this->sendOutput('参数为空', ErrorCode::$paramError );
  103. }
  104. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  105. $selectParams['limit'] = $pageParams['limit'];
  106. $selectParams['offset'] = $pageParams['offset'];
  107. $result = $this->objMVipCard->getMyVipCards($selectParams);
  108. if($result->isSuccess()){
  109. $returnData = $result->getData();
  110. $pageData = [
  111. 'pageIndex' => $params['page'],
  112. 'pageSize' => $params['pageSize'],
  113. 'pageTotal' => $returnData['total'],
  114. 'received' => $returnData['received']
  115. ];
  116. parent::sendOutput($returnData['data'], 0, $pageData);
  117. }else{
  118. parent::sendOutput($result->getData(), $result->getErrorCode());
  119. }
  120. }
  121. }