GiftcardRecords.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\giftcard\Media;
  13. use app\api\controller\BaseApi;
  14. use app\model\shop\Shop;
  15. /**
  16. * 礼品卡
  17. */
  18. class GiftcardRecords extends BaseApi
  19. {
  20. /**
  21. * 列表信息
  22. */
  23. public function lists()
  24. {
  25. $card_type = isset($this->params[ 'card_type' ]) ? $this->params[ 'card_type' ] : '';
  26. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  27. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  28. $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : '';
  29. $category_id = isset($this->params[ 'category_id' ]) ? $this->params[ 'category_id' ] : 0;
  30. $condition = array (
  31. [ 'site_id', '=', $this->site_id ],
  32. [ 'status', '', '1' ]
  33. );
  34. if (!empty($search_text)) {
  35. $condition[] = [ 'card_name', 'like', '%' . $search_text . '%' ];
  36. }
  37. if (!empty($card_type)) {
  38. $condition[] = [ 'card_type', '=', $card_type ];
  39. }
  40. if ($category_id > 0) {
  41. $condition[] = [ 'category_id', '=', $category_id ];
  42. }
  43. $giftcard_model = new GiftCardModel();
  44. $list = $giftcard_model->getGiftcardDetailPageList($condition, $page, $page_size, 'sort desc');
  45. return $this->response($list);
  46. }
  47. /**
  48. * 活动详情
  49. */
  50. public function detail()
  51. {
  52. $giftcard_id = isset($this->params[ 'giftcard_id' ]) ? $this->params[ 'giftcard_id' ] : 0;
  53. $giftcard_model = new GiftCardModel();
  54. $media_model = new Media();
  55. $detail = $giftcard_model->getGiftcardDetail([ 'giftcard_id' => $giftcard_id, 'site_id' => $this->site_id ])[ 'data' ] ?? [];
  56. $detail[ 'media_list' ] = $media_model->getList([ [ 'media_id', 'in', $detail[ 'media_ids' ] ] ])[ 'data' ] ?? [];
  57. $detail[ 'mobile' ] = ( new Shop() )->getShopInfo([ [ 'site_id', '=', $this->site_id ] ], 'mobile')[ 'data' ][ 'mobile' ] ?? '';
  58. $detail[ 'giftcard_desc' ] = $giftcard_model->giftcardDesc($detail) ?? '';
  59. return $this->response($this->success($detail));
  60. }
  61. }