groupBy("type"); return $r; } public function bannerPaginate($params) { $p = Setting::query()->where("type", Setting::TYPE_BANNER)->when($params['status'], function (Builder $query) use ($params) { return $query->where("status", $params['status']); })->when($params['name'], function (Builder $query) use ($params) { return $query->where("key", "like", "%{$params['name']}%"); })->orderByDesc("id")->paginate($params['page_size']); return [ "total" => $p->total(), "page_total" => $p->lastPage(), "list" => array_map(function (Setting $u) { return array_merge([ "id" => $u->id, "name" => $u->key, "created_at" => $u->created_at->format("Y-m-d H:i:s"), ], $u->value ?? []); }, $p->items()), ]; } public function store($params) { $id = $params['id']; if ($id) { $m = Setting::find($id); } else { $m = new Setting(); } $m->type = Setting::TYPE_BANNER; $m->key = Arr::get($params, "name"); $m->value = [ "sort" => $params['sort'] ?? 0, "imageUrl" => $params['imageUrl'], "is_use" => $params['is_use'] ?? 1, ]; $m->save(); return true; } public function settingSave($data) { //{"hot_keywords":{"id":2,"values":["文本1","文本2","test","test2"]}} foreach ($data as $k => $v) { $id = Arr::get($v, "id"); if ($id) { $setting = Setting::find($id); $setting->value = Arr::get($v, "values"); $setting->save(); } } return true; } }