Groupbuy.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. * ============================================================================
  5. *
  6. * ============================================================================
  7. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  8. * 网站地址: https://www.valimart.net/
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 拼团控制器
  13. */
  14. class Groupbuy extends MobileMall {
  15. public function initialize() {
  16. parent::initialize();
  17. $groupbuy_model = model('groupbuy');
  18. $this->groupbuy_price = rkcache('groupbuyprice', true);
  19. if (input('param.groupbuy_is_vr', 0)) {
  20. $this->groupbuy_classes = $groupbuy_model->getGroupbuyVrClasses();
  21. } else {
  22. $this->groupbuy_classes = $groupbuy_model->getGroupbuyClasses();
  23. }
  24. }
  25. /**
  26. * @api {POST} api/Groupbuy/index 获取抢购列表
  27. * @apiVersion 1.0.0
  28. * @apiGroup GroupBuy
  29. *
  30. * @apiHeader {String} X-DS-KEY 用户授权token
  31. *
  32. * @apiParam {Int} page 页码
  33. * @apiParam {Int} per_page 每页数量
  34. *
  35. * @apiSuccess {String} code 返回码,10000为成功
  36. * @apiSuccess {String} message 返回消息
  37. * @apiSuccess {Object} result 返回数据
  38. * @apiSuccess {Object[]} result.groupbuy_list 抢购列表 (返回字段参考groupbuy表)
  39. * @apiSuccess {Int} result.page_total 总页数
  40. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  41. */
  42. public function index() {
  43. $groupbuy_model = model('groupbuy');
  44. $groupbuy_is_vr = input('param.groupbuy_is_vr', 0); //是否是虚拟抢购 1为虚拟
  45. $groupbuy_type = input('param.sort_key');
  46. switch ($groupbuy_type) {
  47. case 'soon':
  48. $function_name = 'getGroupbuySoonList';
  49. break;
  50. case 'history':
  51. $function_name = 'getGroupbuyHistoryList';
  52. break;
  53. default:
  54. $function_name = 'getGroupbuyOnlineList';
  55. break;
  56. }
  57. $condition = array();
  58. $condition[] = array('groupbuy_is_vr', '=', $groupbuy_is_vr);
  59. $order = '';
  60. // 分类筛选条件
  61. if (($gclass_id = (int) input('class')) > 0) {
  62. $condition[] = array('gclass_id', '=', $gclass_id);
  63. if (($s_gclass_id = (int) input('s_class')) > 0)
  64. $condition[] = array('s_gclass_id', '=', $s_gclass_id);
  65. }
  66. // 价格区间筛选条件
  67. if (($price_id = intval(input('groupbuy_price'))) > 0 && isset($this->groupbuy_price[$price_id])) {
  68. $p = $this->groupbuy_price[$price_id];
  69. $condition[] = array('groupbuy_price', 'between', array($p['gprange_start'], $p['gprange_end']));
  70. }
  71. // 排序
  72. $groupbuy_order_key = trim(input('groupbuy_order_key'));
  73. $groupbuy_order = input('groupbuy_order') == '2' ? 'desc' : 'asc';
  74. if (!empty($groupbuy_order_key)) {
  75. switch ($groupbuy_order_key) {
  76. case '1':
  77. $order = 'groupbuy_price ' . $groupbuy_order;
  78. break;
  79. case '2':
  80. $order = 'groupbuy_rebate ' . $groupbuy_order;
  81. break;
  82. case '3':
  83. $order = 'groupbuy_buyer_count ' . $groupbuy_order;
  84. break;
  85. }
  86. }
  87. $cache_key = 'api-groupbuy' . md5(serialize($condition).$function_name) . '-' . intval(input('param.page'));
  88. $result = rcache($cache_key);
  89. if (empty($result)) {
  90. $groupbuy_list = $groupbuy_model->$function_name($condition, 10, $order);
  91. foreach ($groupbuy_list as $key => $groupbuy) {
  92. $groupbuy_list[$key]['groupbuy_image'] = groupbuy_thumb($groupbuy['groupbuy_image'], 240);
  93. }
  94. $page_count = $groupbuy_model->page_info;
  95. $result = array_merge(array('groupbuy_list' => $groupbuy_list,), mobile_page($page_count));
  96. wcache($cache_key, $result);
  97. }
  98. ds_json_encode(10000, '', $result);
  99. }
  100. public function filter() {
  101. $groupbuy_price = $this->groupbuy_price;
  102. if (empty($groupbuy_price)) {
  103. $groupbuy_price = false;
  104. }
  105. $groupbuy_classes = $this->groupbuy_classes;
  106. if (empty($groupbuy_classes)) {
  107. $groupbuy_classes = false;
  108. }
  109. ds_json_encode(10000, '', array('groupbuy_price' => $groupbuy_price, 'groupbuy_classes' => $groupbuy_classes));
  110. }
  111. }