dataRange() ->catchSearch() ->append(['wind_name', 'model_name']) ->field('*') ->catchOrder() ->creator() ->paginate(); } public function getFanList() { return $this->dataRange() ->catchSearch() ->field('id as value,number as name') ->catchOrder() ->select(); } //根据风场的id,获取风机的机位号 public function getFanListByWindId($wind_id) { $data = $this->where('wind_id', $wind_id)->select(); return $data; } /** * 风机下发内容 */ public function addContent(&$obj) { $data = null; $content = null; $data = [ 'id' => intval($obj->id), 'wnum' => Wind::where('id', $obj->wind_id)->value('number'), 'number' => intval($this->number), ]; $content['data'] = $data; $content['type'] = 'Fan'; return $content; } /** * @Descripttion: 风机的id * @name: likang * @param {*} $wind_num * @return {*} */ public function IssuedFanModel($wind_id) { //获取风场编号 //分组查询当前风场所有的风机模型 $array = []; //差集 $diff_array = []; $content = []; $diff_array1 = []; $fan_model = $this->where('wind_id', $wind_id)->group('fan_model')->column('fan_model'); //获取风机名称 $wind_num = Wind::where('id', $wind_id)->value('number'); $wheres[] = ['device_type', '=', 4]; $wheres[] = ['id', 'in', $fan_model]; $model_name = ModelDeviceMold::where($wheres)->column('name'); $where[] = ['ContentType', '=', 'FanModel']; $where[] = ['ContentId', 'like', '%' . $wind_num . '_%']; $where[] = ['Type', '=', 'add']; //获取当前风场下发的风机模型 $list = Db::name('publish')->where($where)->field('ContentId')->select(); //截取ContentId 获取模型名称 foreach ($list as $item) { $array[] = substr(strstr($item['ContentId'], '_'), 1); } $diff_array = array_diff($array, $model_name); foreach ($diff_array as $item) { Db::name('publish')->where('ContentType', 'FanModel')->where("ContentId", $wind_num . '_' . $item)->update( [ "Type" => 'delete', 'Version' => msectime() ] ); } $diff_array1 = array_diff($model_name, $array); foreach ($diff_array1 as $item) { $time = msectime(); $json = json_encode([ 'id' => $wind_num . '_' . $item, 'wunm' => $wind_num, 'model' => $item ]); $content[] = [ 'Type' => 'add', 'ContentType' => 'FanModel', 'Version' => $time, 'ContentId' => $wind_num . '_' . $item, 'Content' => $json, 'AddTime' => $time, 'Status' => 1 ]; } Db::name('publish')->insertAll($content); //风机 模型id } }