search_arr = ['url','name']; $_op = $this->field('*'); $_op->order('is_use desc ,id desc'); $data = parent::parentLists($_op); foreach ($data['data'] as $k=>&$item){ $template = Db::table($this->table_template)->where('id',$item['template_id'])->find(); if(empty($template)){ unset($data['dta'][$k]); continue; } $item['template'] = $template; } //执行通用查询 return $data; } /** * 切换当前站点的默认站点 * @param array $_data * @param null $_op 模型链式对象 * @param $id * @return bool|\type * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function changeDefaultTemplate(){ $_data = $this->request->param(); if (empty($_data) || !isset($_data['id']) || intval($_data['id']) == 0) { return false; } $set_template_id = $_data['id']; //获取当前默认id $tempNow = Db::name('site')->where('id',SITE_ID)->find(); if(empty($tempNow)){ return false; } // $template_id = $tempNow['use_template']; $_data['is_use'] = 0; $res = Db::name('site')->where('id',SITE_ID)->save(['use_template'=>$set_template_id,'update_time'=>time()]); if($res){ Db::table($this->table)->where('site_id',SITE_ID) ->save(['is_use'=>0,'update_time'=>time()]); Db::table($this->table)->where('site_id',SITE_ID)->where('template_id',$set_template_id) ->save(['is_use'=>1,'update_time'=>time()]); } return true; } /** * 读取后 * @param Model $model * @return bool|void */ public static function onAfterRead(Model $model) { if (in_array(request()->action(), ['edit', 'delete', 'status'])) { return true; } } }