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

namespace Uapp\Model;
use Think\Model;
class TakeoutModel extends Model{
    protected $tableName = 'member';
    public function _initialize(){
        parent::_initialize ();
    }
    /**
       *小店编辑商品
       *@return array
       */
    public function update_goods($data=array()){
        $return['status']=3;
        if(empty($data)){
            $return['msg']='参数错误';
            return $return;
        }
        $map['shop_id']=$data['shop_id']; //小店id
        $map['goods_id']=$data['goods_id']; //商品id
        $goodsinfo=M('LittleShopGoods')->where($map)->field(true)->find();
        $adddata=$savedata=array();
        if(!$goodsinfo){
            $adddata['shop_id']=$data['shop_id'];
            $adddata['goods_id']=$data['goods_id'];
            $adddata['uid']=$data['uid'];
            $adddata['addtime']=NOW_TIME;
            $adddata['updatetime']=NOW_TIME;
            $result=M('LittleShopGoods')->add($adddata);
        }else{
            $savedata['updatetime']=NOW_TIME;
            if($data['type']<=1){//上下架
                if($goodsinfo['is_putaway']==1 && $data['type']==0){
                    $savedata['is_putaway']=0;
                }else{
                    $savedata['is_putaway']=1;
                }
            }else{
                if($goodsinfo['is_show']==1){//推荐首页
                    $return['data']['is_show']=$savedata['is_show']=0;
                }else{
                    $return['data']['is_show']=$savedata['is_show']=1;
                }
            }
            $result=M('LittleShopGoods')->where($map)->save($savedata);
        }
        
        if($result!=false){
            unset($map['goods_id']);
            $map['is_putaway']=1; //下架
            $return['data']['down_num']=M('LittleShopGoods')->where($map)->count();
            unset($map['is_putaway']);
            $map['is_putaway']=0; //上架
            $return['data']['up_num']=M('LittleShopGoods')->where($map)->count();
            $return['url']=U('Mobile/LittleShop/index',array('eid'=>MID,'shop_id'=>$data['shop_id']));
            $return['status']=1;
            $return['msg']='操作成功';
        }else {
            $return['msg']='操作失败';
        }
        return $return;
    }
    // 图文分享
    public function cont_tgercode($param){
        $return=array('status'=>1);
        if(empty($param['id'])){
            $return['status']=3;
            $return['msg']='参数错误';
            return $return;
        }        
        $img = goods_shots($param['uid'],1,$param['id'],$param['lshop_id']);
        return $img;
    }
}