public function like_event($uid, $event_id) { $param_array = array('uid' => $uid, 'eid' => $event_id); $res = $this->ci_insert(T_USER_LIKE, $param_array); if ($res != false) { return return_format($res, "收藏一个活动成功"); } else { return return_format(array(), "收藏一个活动失败!", API_DB_ERR); } }
function get_api_data($url, $param = array()) { $url = API_URL . $url; $sign = encrypt($param); $param['sign'] = $sign; $api_str = send_request($url, $param); if (is_json($api_str)) { return json_decode($api_str, TRUE); } else { return return_format(array($api_str), "json_str 解析错误,这是api内部报错!请联系1162097842@qq.com", API_NORMAL_ERR); } }
public function do_login() { // root 是超级管理员,写死在程序里面的 // if($this->post_data['account'] == 'root'){ // if($this->post_data['pwd'] == 'jiebao2015'){ // } // } $res = get_api_data('employee/login', $this->post_data); if ($res['err_num'] == 0) { $this->load->library('session'); $newdata = array('admin_session' => $res['results']['session']); $this->session->set_userdata($newdata); echo json_encode(return_format(array(), "登录成功", 0)); } }
public function st($res = array(), $err_msg = '获取数据成功!', $err_num = 0) { $this->data = return_format($res, $err_msg, $err_num); }
public function records_add($records_info) { $res = $this->ci_insert($this->table, $records_info); if ($res) { return return_format(array('affect_row' => $res), "添加记录成功!"); } return return_format(array(), "添加记录失败!", API_UNKNOW_ERR); }
public function lists() { $must = array(); $this->check_param($must); $this->check_sign(); extract($this->params); do { // 设置分页 if (isset($page_now)) { $this->page_now = $page_now; } if (isset($page_size)) { $this->page_size = $page_size; } // 根据不同的条件查询商铺的 id 了 $store_id_str = ''; // $store_id = array(); do { $this->load->model("Store_model"); //按品牌查询 if (isset($brand_id) && !empty($brand_id)) { $res = $this->Base_model->ci_get(T_STORE, array('brand_id' => $brand_id), array('id')); if ($res == false) { $this->op(return_format(array(), "该品牌下没数据", API_NORMAL_ERR)); } $store_id = array(); foreach ($res as $value) { $store_id[] = $value['id']; } break; } // 只查询某个商铺下面的商铺 if (isset($store_id) && !empty($store_id)) { $store_id = array($store_id); break; } // 查询某个商场楼层下面的商铺 if (isset($mall_floor_id) && !empty($mall_floor_id)) { $store_id = $this->Store_model->store_in_mall_floor($mall_floor_id); if ($store_id == false) { $this->st(array(), "该商场楼层下并没有活动!", API_NORMAL_ERR); $this->op(); } $store_id = array_unique($store_id); break; } // 某个商场下面的商铺 if (isset($mall_id) && !empty($mall_id)) { $store_id = $this->Store_model->store_in_mall($mall_id); if ($store_id == false) { $this->st(array(), "该商场下并没有活动", API_NORMAL_ERR); $this->op(); break; } $store_id = array_unique($store_id); break; } // 某个商圈下面的商铺 if (isset($district_id) && !empty($district_id)) { $store_id = $this->Store_model->store_in_district($district_id); if ($store_id == false) { $this->st(array(), "该商圈下没有活动", API_NORMAL_ERR); $this->op(); break; } $store_id = array_unique($store_id); break; } // 地理位置附近的商圈的下的商铺 if (isset($longitude) && isset($latitude)) { $left_longitude = $longitude - 0.1; $right_longitude = $longitude + 0.1; $top_latitude = $latitude + 0.05; $bottom_latitude = $latitude - 0.05; $sql = "select id from " . T_DISTRICT . " where longitude between {$left_longitude} and {$right_longitude} and latitude between {$bottom_latitude} and {$top_latitude}"; $res = $this->Base_model->ci_query($sql); if (!$res) { $this->st(array(), '该地理位置附近没有活动', API_NORMAL_ERR); $this->op(); break; } $store_id = array(); foreach ($res as $value) { $temp = $this->Store_model->store_in_district($value['id']); if ($temp) { $store_id = array_merge($store_id, $temp); break; } } break; } //获取全部商铺 $sql = "select id from " . T_STORE; $res = $this->Base_model->ci_query($sql); foreach ($res as $value) { $store_id[] = $value['id']; } //获取全部商铺 } while (0); $store_id = array_unique($store_id); $store_id_str = join(',', $store_id); // 如果有商铺,查出该商铺下面的所有活动id $sql = "select id from " . T_EVENT . " where store_id in(" . $store_id_str . ") "; // 查询某个品类的 if (isset($cate_id_str)) { $sql .= "and cate_id_str like '%" . $cate_id_str . "%'"; } // 活动的风格条件 if (isset($style_id_str)) { $sql .= "and style_id_str like '%" . $style_id_str . "%'"; } // 是否获取已经过期的活动 if (!isset($expired)) { $time = time(); $sql .= " and etime + 86400 > {$time} "; } // 是否获取没发布的活动 if (!isset($is_publised)) { $sql .= " and is_publish = 1"; } // 是否获取已经删除的活动 if (!isset($is_del)) { $sql .= " and is_del = 0"; } // 顺序: 按结束时间升序排列,也就说结束 $sql .= " order by etime desc"; // 分页 $page_offset = $this->page_size * ($this->page_now - 1); $total_records = $this->Base_model->ci_query($sql); if (!$total_records) { $this->st(array(), "没有符合条件的活动!", API_NORMAL_ERR); break; } $sql .= " limit {$page_offset},{$this->page_size}"; $res = $this->Base_model->ci_query($sql); $ids = array(); if ($res) { foreach ($res as $value) { $ids[] = $value['id']; } $events_info = $this->_events_info($ids); $this->st(array('pager' => paging(count($total_records), $this->page_now, $this->page_size), 'records' => $events_info), "获取活动列表成功"); } } while (0); $this->op(); }