Membercard.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\giftcard\api\controller;
  11. use addon\giftcard\model\giftcard\GiftCard as GiftCardModel;
  12. use addon\giftcard\model\membercard\MemberCard as MemberCardModel;
  13. use addon\giftcard\model\membercard\Poster;
  14. use addon\giftcard\model\transfer\Blessing;
  15. use app\api\controller\BaseApi;
  16. use app\model\shop\Shop;
  17. use addon\giftcard\model\card\CardUse as CardUseModel;
  18. /**
  19. * 礼品卡
  20. */
  21. class Membercard extends BaseApi
  22. {
  23. /**
  24. * 列表信息
  25. */
  26. public function lists()
  27. {
  28. $token = $this->checkToken();
  29. if ($token[ 'code' ] < 0) return $this->response($token);
  30. $page = $this->params[ 'page' ] ?? 1;
  31. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  32. $is_transfer = $this->params[ 'is_transfer' ] ?? 'all';
  33. $status = $this->params[ 'status' ] ?? 'all';
  34. $source = $this->params[ 'source' ] ?? 'all';
  35. $order = $this->params[ 'order' ] ?? 'get_time';
  36. $order_id = $this->params[ 'order_id' ] ?? 0;
  37. $condition = array (
  38. [ 'gc.site_id', '=', $this->site_id ],
  39. [ 'gmc.member_id', '=', $this->member_id ]
  40. );
  41. if ($status != 'all') {
  42. $condition[] = [ 'gc.status', '=', $status ];
  43. }
  44. if ($is_transfer != 'all') {
  45. $condition[] = [ 'gmc.is_transfer', '=', $is_transfer ];
  46. }
  47. if ($source != 'all') {
  48. $condition[] = [ 'gmc.source', '=', $source ];
  49. }
  50. if (!empty($order_id)) {
  51. $condition[] = [ 'gc.order_id', '=', $order_id ];
  52. $condition[] = [ 'gmc.source', '=', 'order' ];
  53. }
  54. $member_card_model = new MemberCardModel();
  55. $order_by = 'gmc.' . $order . ' desc';
  56. $list = $member_card_model->getMemberCardDetailPageList($condition, $page, $page_size, $order_by);
  57. return $this->response($list);
  58. }
  59. /**
  60. * 活动详情
  61. */
  62. public function detail()
  63. {
  64. $token = $this->checkToken();
  65. // if ($token['code'] < 0) return $this->response($token);
  66. $member_card_id = $this->params[ 'member_card_id' ] ?? 0;
  67. $member_card_model = new MemberCardModel();
  68. $params = array (
  69. 'site_id' => $this->site_id,
  70. // 'member_id' => $this->member_id,
  71. 'member_card_id' => $member_card_id
  72. );
  73. $detail = $member_card_model->getMemberCardDetail($params)[ 'data' ] ?? [];
  74. if (!empty($detail)) {
  75. $detail[ 'is_self' ] = $detail[ 'member_id' ] == $this->member_id ? 1 : 0;
  76. $detail[ 'mobile' ] = ( new Shop() )->getShopInfo([ [ 'site_id', '=', $this->site_id ] ], 'mobile')[ 'data' ][ 'mobile' ] ?? '';
  77. $giftcard_model = new GiftCardModel();
  78. $giftcard_info = $giftcard_model->getGiftcardInfo([ [ 'giftcard_id', '=', $detail[ 'giftcard_id' ] ] ], 'instruction')[ 'data' ] ?? [];
  79. $detail[ 'giftcard_desc' ] = $giftcard_model->giftcardDesc($detail) ?? '';
  80. $detail[ 'instruction' ] = $giftcard_info[ 'instruction' ] ?? '';
  81. if ($detail[ 'status' ] == 'used') {
  82. $card_use_model = new CardUseModel();
  83. $card_use_condition = array (
  84. [ 'card_id', '=', $detail[ 'card_id' ] ]
  85. );
  86. $card_use_info = $card_use_model->getCardUseRecordsInfo($card_use_condition, 'order_id')[ 'data' ] ?? [];
  87. if (!empty($card_use_info)) {
  88. $detail[ 'use_order_id' ] = $card_use_info[ 'order_id' ];
  89. }
  90. }
  91. if ($detail[ 'to_member_id' ] > 0) {
  92. $blessing_model = new Blessing();
  93. $blessing_info = $blessing_model->getMemberCardBlessingInfo([ [ 'card_id', '=', $detail[ 'card_id' ] ], [ 'to_member_id', '=', $detail[ 'to_member_id' ] ] ], 'blessing')[ 'data' ] ?? [];
  94. $detail[ 'blessing' ] = $blessing_info[ 'blessing' ] ?? '';
  95. }
  96. }
  97. return $this->response($this->success($detail));
  98. }
  99. /**
  100. * 祝福
  101. * @return false|string
  102. */
  103. public function blessing()
  104. {
  105. $token = $this->checkToken();
  106. if ($token[ 'code' ] < 0) return $this->response($token);
  107. $member_card_id = $this->params[ 'member_card_id' ] ?? 0;
  108. $blessing = $this->params[ 'blessing' ] ?? '';
  109. $blessing_model = new Blessing();
  110. $params = array (
  111. 'blessing' => $blessing,
  112. 'member_id' => $this->member_id,
  113. 'member_card_id' => $member_card_id,
  114. 'site_id' => $this->site_id
  115. );
  116. $result = $blessing_model->blessing($params);
  117. return $this->response($result);
  118. }
  119. /**
  120. * 获取商品海报
  121. */
  122. public function poster()
  123. {
  124. $this->checkToken();
  125. $promotion_type = 'giftcard';
  126. $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
  127. $qrcode_param[ 'source_member' ] = $this->member_id;
  128. $poster = new Poster();
  129. $res = $poster->poster($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
  130. return $this->response($res);
  131. }
  132. }