<?php
/** 店铺登录
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <570035208@qq.com>
 */

namespace App\Model;
use Think\Model;
class TakeoutModel extends Model{
    protected $tableName = 'goods';
    // 获取商品列表
    public function location_index($postdata){
        $return=D('Goods')->goods_list($postdata);
        return $return;
    }
    public function goods_info($goods_sn){
        $result = $data = array();
        $result['status'] = 1;
        if(empty($goods_sn)){
            $result['status'] = 3;
            $result['msg']='未获取到商品信息';
        }
        $maps=$map = array();
        $maps['goods_attr_sn'] = $goods_sn;
        $goods_stock = M('GoodsAttrStock')->where($maps)->field('goods_id,attr_key')->find();
        $map['status'] = 1;
        if($goods_stock){
            $map['id'] = $goods_stock['goods_id'];
        }else{
            $map['goods_sn'] = $goods_sn;
        }

        $field = 'id,goods_name,goods_sn,market_price';
        $data = M('Goods')->where($map)->field($field)->find();
        if($goods_stock){
            $data['attr'] = attr_key2name($goods_stock['attr_key'],$goods_stock['goods_id']);
            $data['attr_key'] = $goods_stock['attr_key'];
            $data['key'] = $goods_stock['goods_id'].'-'.$goods_stock['attr_key'];
        }else{
            if($data){
                $data['key'] = $data['id'].'-';
            }else{
                $result['status'] = 3;
                $result['msg']='该商品已下架或不存在';
                return $result;
            }
        }

        $result['data'] = $data;
        return $result;

    }
}
?>