123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\api\controller;
- class Groupbuy extends MobileMall
- {
- public function initialize()
- {
- parent::initialize();
- $groupbuy_model = model('groupbuy');
- $this->groupbuy_price = rkcache('groupbuyprice', true);
- if (input('param.groupbuy_is_vr', 0)) {
- $this->groupbuy_classes = $groupbuy_model->getGroupbuyVrClasses();
- } else {
- $this->groupbuy_classes = $groupbuy_model->getGroupbuyClasses();
- }
- }
-
- public function index()
- {
- $groupbuy_model = model('groupbuy');
- $groupbuy_is_vr = input('param.groupbuy_is_vr', 0);
- $groupbuy_type = input('param.sort_key');
- switch ($groupbuy_type) {
- case 'soon':
- $function_name = 'getGroupbuySoonList';
- break;
- case 'history':
- $function_name = 'getGroupbuyHistoryList';
- break;
- default:
- $function_name = 'getGroupbuyOnlineList';
- break;
- }
- $condition = array();
- $condition[] = array('groupbuy_is_vr', '=', $groupbuy_is_vr);
- $order = '';
-
- if (($gclass_id = (int) input('class')) > 0) {
- $condition[] = array('gclass_id', '=', $gclass_id);
- if (($s_gclass_id = (int) input('s_class')) > 0)
- $condition[] = array('s_gclass_id', '=', $s_gclass_id);
- }
-
- if (($price_id = intval(input('groupbuy_price'))) > 0 && isset($this->groupbuy_price[$price_id])) {
- $p = $this->groupbuy_price[$price_id];
- $condition[] = array('groupbuy_price', 'between', array($p['gprange_start'], $p['gprange_end']));
- }
-
- $groupbuy_order_key = trim(input('groupbuy_order_key'));
- $groupbuy_order = input('groupbuy_order') == '2' ? 'desc' : 'asc';
- if (!empty($groupbuy_order_key)) {
- switch ($groupbuy_order_key) {
- case '1':
- $order = 'groupbuy_price ' . $groupbuy_order;
- break;
- case '2':
- $order = 'groupbuy_rebate ' . $groupbuy_order;
- break;
- case '3':
- $order = 'groupbuy_buyer_count ' . $groupbuy_order;
- break;
- }
- }
- $cache_key = 'api-groupbuy' . md5(serialize($condition) . $function_name) . '-' . intval(input('param.page'));
- $result = rcache($cache_key);
- if (empty($result)) {
- $groupbuy_list = $groupbuy_model->$function_name($condition, 10, $order);
- foreach ($groupbuy_list as $key => $groupbuy) {
- $groupbuy_list[$key]['groupbuy_image'] = groupbuy_thumb($groupbuy['groupbuy_image'], 240);
- }
- $page_count = $groupbuy_model->page_info;
- $result = array_merge(array('groupbuy_list' => $groupbuy_list,), mobile_page($page_count));
- wcache($cache_key, $result);
- }
- ds_json_encode(10000, '', $result);
- }
- public function filter()
- {
- $groupbuy_price = $this->groupbuy_price;
- if (empty($groupbuy_price)) {
- $groupbuy_price = false;
- }
- $groupbuy_classes = $this->groupbuy_classes;
- if (empty($groupbuy_classes)) {
- $groupbuy_classes = false;
- }
- ds_json_encode(10000, '', array('groupbuy_price' => $groupbuy_price, 'groupbuy_classes' => $groupbuy_classes));
- }
- }
|