1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- !defined('BASEPATH') && exit('No direct script access allowed');
- class Api extends MY_Main_Controller
- {
- public function __construct()
- {
- parent::__construct();
- $this->load->model('product_model','product');
- $this->load->model('type_model','type');
- }
- // public function hehe(){
- // $sql = "CREATE TABLE `product` (
- // `id` int(11) NOT NULL AUTO_INCREMENT,
- // `type` varchar(255) NOT NULL DEFAULT '',
- // `title` varchar(255) NOT NULL DEFAULT '',
- // `pid` varchar(255) NOT NULL DEFAULT '',
- // `level` tinyint(4) NOT NULL DEFAULT '0',
- // `img` text NOT NULL,
- // `desc` text NOT NULL,
- // `sence` text NOT NULL,
- // `addtime` int(10) NOT NULL DEFAULT '0',
- // `publishtime` int(10) NOT NULL DEFAULT '0',
- // `ord` int(11) NOT NULL DEFAULT '0',
- // `status` int(4) NOT NULL DEFAULT '0',
- // PRIMARY KEY (`id`)
- // ) ENGINE=InnoDB DEFAULT CHARSET=utf8";
- // $this->db->query($sql);
- // echo $this->db->last_query();
- // }
- public function getProducts()
- {
- $types = $this->type->all();
- $products = $this->product->all();
- foreach($products as &$product) {
- $t = $product['type'];
- $t_arr = explode(',', $t);
- $product['type'] = implode(', ', $t_arr);
- $product['img'] = json_decode($product['img'], true);
- }
- $item['types'] = $types;
- $item['products'] = $products;
- $data = $item;
- $this->echoJson($data);
- }
- public function getProductDetail()
- {
- $id = $this->input->get('id', true);
- $data = $this->product->get($id);
- $type = $this->type->get($data['type']);
- $data['type_name'] = $type['name'];
- $data['img'] = json_decode($data['img'], true);
- $this->echoJson($data);
- }
- private function fetchWebSetting($name){
- $item = $this->web_setting->getValueByName($name);
- $data = json_decode($item[0]['value'] , true);
- return $data;
- }
- private function fetchWebSetting2($name){
- $item = $this->web_setting->getValueByName($name);
- $data = $item[0]['value'];
- return $data;
- }
- private function echoJson($data){
- if($data){
- $code = 200;
- $msg = 'success';
- }
- else{
- $code = 500;
- $msg = 'fails';
- }
- $res['code'] = $code;
- $res['msg'] = $msg;
- $res['data'] = $data;
- header('Content-type:text/json');
- echo json_encode($res);
- }
- }
- ?>
|