Groupbuy.php 4.4 KB

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