<?php
/**
 * 店铺外卖分类模型
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaol <xiaol@sina.cn>
 */
 
namespace Shop\Model;
use Think\Model;
class ShopsCategoryModel extends Model
{

    /**
     * 更新外卖所属门店
     * @param array $postdata 表单提交数据
     * @param int $type 提交的类型:0修改,1添加
     */
    public function update_shopcategory_location($postdata, $type = 0)
    {
        $id = $postdata['id'];$location = $postdata['location_ids'];
        $selectstr = implode(',', $location);$modelname='ShopsCategory';
        if ($type == 0 && !empty($location) && $selectstr != $postdata['selectlocationstr']) {
            $map['category_id'] = $id;
            M($modelname)->where($map)->delete();
            foreach ($location as $k => $v) {
                $map['location_id'] = $v;
                M($modelname)->add($map);
            }
        } elseif ($type == 1) {
            $data['category_id'] = $id;
            foreach ($location as $k => $v) {
                $data['location_id'] = $v;
                M($modelname)->add($data);
            }
        }
        unset($location, $map, $data);
    }
}