<?php
/**
 * 分类
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaol <1094186793@sina.cn>
 */
namespace Mobile\Model;
use Think\Model;
class ShopsModel extends Model{
    protected $tableName = 'goods';
    public function get_index() {
    }
    public function get_list($param){
        $model='Common/Shops';
		$data=array();
		$data['status']=1;
        $shops_list=D($model)->get_shops_list($param);
        $data['shops_list']=$shops_list;
        return $data;
    }
	public function get_location($id){
        $model='Common/Takeout';$data=array();$data['status']=1;
        $location_info=D($model)->get_location_info($id);
        if($location_info['status']==0){$data['status']=0;$data['info']=$location_info['info'];return $data;}
        $data['location_info']=$location_info['location_info'];
        $category_list=D($model)->get_location_takeout_cate($id);
        $data['category_list']=$category_list;
        $takeout_list=D($model)->get_location_takeout_list($id);
        $data['takeout_list']=$takeout_list;
        $cate_goods_list=array();
        foreach($takeout_list as $k=>$v){
            if(empty($cate_goods_list[$v['shop_cat_id']])) {
                if ($category_list[$v['shop_cat_id']]) {
                    $cate_goods_list[$v['shop_cat_id']] = $category_list[$v['shop_cat_id']];
                } else {
                    $category_list[$v['shop_cat_id']]['id'] = 0;
                    $category_list[$v['shop_cat_id']]['name'] = '其他';
                    $cate_goods_list[$v['shop_cat_id']] = $category_list[$v['shop_cat_id']];
                }
            }
            $cate_goods_list[$v['shop_cat_id']]['goods_list'][$v['id']]=$v;
        }
        $data['cate_goods_list']=$cate_goods_list;
        $data['delivery']=D($model)->get_location_delivery($id);
        return $data;
    }
    public function get_goods($id,$location_id){
        $model='Common/Takeout';$data=array();$data['status']=1;
        $goods_info=D($model)->get_goods_info($id,$location_id);
        if($goods_info['status']==0){$data['status']=0;$data['info']=$goods_info['info'];return $data;}
        $data['goods_info']=$goods_info['goods_info'];
        $data['delivery']=D($model)->get_location_delivery($location_id);
        return $data;
    }
    public function get_cart_list($location_id){
        $model='Common/Takeout';$data=array();
        if(!$location_id){return $data;}
        $data=D($model)->get_cart_goods_list($location_id);
        return $data;
    }
    public function add_cart($param){
        $model='Common/Takeout';$data=array();$data['status']=1;
        if(!$param){$data['status']=0;$data['info']='请选择商品';return $data;}
        $data=D($model)->add_cart_item($param);
        return $data;
    }
    public function clear_cart($param){
        $model='Common/Takeout';
        $data=D($model)->clear_cart_item($param);
        return $data;
    }
    public function get_order($location_id){
        $model='Common/Takeout';$data=array();$data['status']=1;
        if(!$location_id){$data['status']=0;$data['info']='参数错误';return $data;}
        $data=D($model)->get_order_info($location_id);
        return $data;
    }
    public function count_order_price($param){
        $model='Common/OrderInfo';
        $data=D($model)->count_total($param);
        return $data;
    }
    public function sub_order($param){
        $model='Common/OrderInfo';
        $data=D($model)->sub_order($param);
        return $data;
    }
}