<?php

namespace app\models\company;

use think\facade\Db;
use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;

class DesignerModel extends BaseModel
{
	/**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'designer';

    use ModelTrait;

    /**
     * 新增或编辑设计师
     */
    public static function saveDesigner($indata, $cid)
    {
        $ids = array();
        foreach($indata as $value){
            if(!$value){
                return $this->fail('请输入正确的案例');
            }
            if(!empty($value['id'])){
                $ids[] = $value['id'];
                self::edit($value, $value['id']);
            }else{
                $ids[] = self::insertGetId($value);
            }
        }
        $data[] = ['id', 'not in', $ids];
        $data[] = ['cid', '=', $cid];
        $overs = self::where($data)->select();
        foreach($overs as $over){
            self::destroy($over['id']);
        }
    }

}