123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- namespace app\controller\admin;
- use app\service\api\UserServiceFacade;
- use laytp\controller\Backend;
- use laytp\library\CommonFun;
- use laytp\library\UploadDomain;
- use think\facade\Db;
- /**
- * 会员管理
- */
- class Models extends Backend
- {
- protected $model;//当前模型对象
- protected $noNeedLogin = [];
- protected $noNeedAuth = [];
- protected function _initialize()
- {
- $this->model = new \app\model\Models();
- }
- //查看
- public function index()
- {
- global $_W;
- $where = $this->buildSearchParams();
- $where[] = ['uniacid','=',$_W['uniacid']];
- // $order = $this->buildOrder();
- $order = ['sort'=>'desc','id'=>'desc'];
- $data = $this->model->where($where)->order($order);
- $allData = $this->request->param('all_data');
- if ($allData) {
- $data = $data->select();
- } else {
- $limit = $this->request->param('limit', 10);
- $data = $data->paginate($limit)->toArray();
- }
- return $this->success('数据获取成功', $data);
- }
- //添加
- public function add()
- {
- global $_W;
- Db::startTrans();
- try {
- $post = CommonFun::filterPostData($this->request->post());
- $post['uniacid'] = $_W['uniacid'];
- $result = $this->model->save($post);
- if(!$result) throw new \Exception("添加失败");
- Db::commit();
- return $this->success('添加成功');
- } catch (\Exception $e) {
- Db::rollback();
- return $this->exceptionError($e);
- }
- }
- //查看详情
- public function info()
- {
- $id = $this->request->param('id');
- $info = $this->model->findOrEmpty($id)->toArray();
- return $this->success('获取成功', $info);
- }
- //编辑
- public function edit()
- {
- Db::startTrans();
- try {
- $post = CommonFun::filterPostData($this->request->post());
- $navmenu = $this->model->findOrEmpty($post['id']);
- if (!$navmenu) throw new \Exception("id参数错误");
- $updateWords = $navmenu->update($post);
- if (!$updateWords) throw new \Exception("菜单基本信息保存失败");
- Db::commit();
- return $this->success('操作成功');
- } catch (\Exception $e) {
- Db::rollback();
- return $this->exceptionError($e);
- }
- }
- //删除
- public function del()
- {
- $ids = array_filter($this->request->param('ids'));
- if (!$ids) {
- return $this->error('参数ids不能为空');
- }
- try{
- if ($this->model->destroy($ids)) {
- return $this->success('数据删除成功');
- } else {
- return $this->error('数据删除失败');
- }
- }catch (\Exception $e){
- return $this->exceptionError($e);
- }
- }
- //设置状态
- public function setStatus()
- {
- $id = $this->request->post('id');
- $fieldVal = $this->request->post('field_val');
- $isRecycle = $this->request->post('is_recycle');
- $update['status'] = $fieldVal;
- try {
- if($isRecycle) {
- $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
- } else {
- $updateRes = $this->model->where('id', '=', $id)->update($update);
- }
- if ($updateRes) {
- return $this->success('操作成功');
- } else if ($updateRes === 0) {
- return $this->success('未作修改');
- } else {
- return $this->error('操作失败');
- }
- } catch (\Exception $e) {
- return $this->error('数据库异常,操作失败');
- }
- }
- //回收站
- public function recycle(){
- $where = $this->buildSearchParams();
- $order = $this->buildOrder();
- $limit = $this->request->param('limit', 10);
- $data = $this->model->onlyTrashed()
- ->order($order)->where($where)->paginate($limit)->toArray();
- return $this->success('回收站数据获取成功', $data);
- }
- //设置排序
- public function setSort()
- {
- $id = $this->request->post('id');
- $fieldVal = $this->request->post('field_val');
- $isRecycle = $this->request->post('is_recycle');
- $update['sort'] = $fieldVal;
- try {
- if($isRecycle) {
- $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
- } else {
- $updateRes = $this->model->where('id', '=', $id)->update($update);
- }
- if ($updateRes) {
- return $this->success('操作成功');
- } else if ($updateRes === 0) {
- return $this->success('未作修改');
- } else {
- return $this->error('操作失败');
- }
- } catch (\Exception $e) {
- return $this->error('数据库异常,操作失败');
- }
- }
- //初始化
- public function init(){
- global $_W;
- $where = ['uniacid' => $_W['uniacid']];
- try{
- if ($this->model->destroy($where)) {
- $list = [
- ['uniacid' => $_W['uniacid'],'model_id'=>'lowpoly-diffusion','name'=>'低多边形','intro'=>'可以生成低多边形风格的图片','status'=>1,'imgs'=>$this->addFile('lowpoly-diffusion'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'arcane-diffusion','name'=>'arcane模型','intro'=>'这是在电视节目Arcane的图像上训练的微调稳定扩散模型。','status'=>1,'imgs'=>$this->addFile('arcane-diffusion'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'mo-di-diffusion','name'=>'迪士尼风格','intro'=>'生成迪士尼风格图片','status'=>1,'imgs'=>$this->addFile('mo-di-diffusion'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'waifu-diffusion','name'=>'二次元动漫模型waifu','intro'=>'高质量二次元动漫风格图片生成','status'=>1,'imgs'=>$this->addFile('waifu-diffusion'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'redshift-diffusion','name'=>'CG感动漫模型','intro'=>'高品质3D渲染作品','status'=>1,'imgs'=>$this->addFile('redshift-diffusion'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'midjourney','name'=>'仿MidJourney V4风格','intro'=>'仿MidJourney风格图片生成','status'=>1,'imgs'=>$this->addFile('midjourney'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'pixel-art-v3','name'=>'像素艺术','intro'=>'生成像素风图片','status'=>1,'imgs'=>$this->addFile('pixel-art-v3'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'anything-v3','name'=>'经典二次元模型3.0','intro'=>'二次元模型 高质量的插图','status'=>1,'imgs'=>$this->addFile('anything-v3'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'anything-v5','name'=>'二次元模型5.0','intro'=>'二次元模型 相比3.0上限更高 描述词准确度更好','status'=>1,'imgs'=>$this->addFile('anything-v5'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'chilloutmix','name'=>'韩风真人2.5d','intro'=>'精致的面部细节','status'=>1,'imgs'=>$this->addFile('chilloutmix'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'guofeng3','name'=>'国风V3','intro'=>'国风V3 涵盖国风、古风、汉服的真人模型','status'=>1,'imgs'=>$this->addFile('guofeng3'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile('bro623jbfe32'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'sdv2','name'=>'通用模型','intro'=>'官方sd原版','status'=>1,'imgs'=>$this->addFile('sdv2'),'engine'=>'sd'],
- ['uniacid' => $_W['uniacid'],'model_id'=>'mj','name'=>'Midjourney官方v5.1','intro'=>'Midjourney 最新版模型','status'=>1,'imgs'=>$this->addFile('mj'),'engine'=>'mj','version'=>'v5.1'],
- // ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile(15)],'engine'=>'mj'],
- // ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile(15)],'engine'=>'mj']
- ];
- $this->model->saveAll($list);
- return $this->success('初始化成功');
- } else {
- return $this->error('数据删除失败');
- }
- }catch (\Exception $e){
- return $this->exceptionError($e);
- }
- // return $this->success('获取成功', $_W);
- }
- public function addFile($modelId)
- {
- global $_W;
- $modelFiles = new \app\model\Files();
- $saveName1 = 'presets/'.$modelId.'/' . 1 . ".png";
- $saveName2 = 'presets/'.$modelId.'/' . 2 . ".png";
- $saveName3 = 'presets/'.$modelId.'/' . 3 . ".png";
- $fileId1 = $modelFiles->insertGetId([
- 'category_id' => 0,
- 'name' => time(),
- 'file_type' => 'image',
- 'path' => $saveName1,
- 'upload_type' => 'local',
- 'size' => 1,
- 'create_admin_user_id' => 0,
- 'update_admin_user_id' => 0,
- 'create_time' => date('Y-m-d H:i:s'),
- 'update_time' => date('Y-m-d H:i:s'),
- 'uniacid' =>$_W['uniacid'],
- 'ext' =>'png'
- ]);
- $fileId2 = $modelFiles->insertGetId([
- 'category_id' => 0,
- 'name' => time(),
- 'file_type' => 'image',
- 'path' => $saveName2,
- 'upload_type' => 'local',
- 'size' => 1,
- 'create_admin_user_id' => 0,
- 'update_admin_user_id' => 0,
- 'create_time' => date('Y-m-d H:i:s'),
- 'update_time' => date('Y-m-d H:i:s'),
- 'uniacid' =>$_W['uniacid'],
- 'ext' =>'png'
- ]);
- $fileId3 = $modelFiles->insertGetId([
- 'category_id' => 0,
- 'name' => time(),
- 'file_type' => 'image',
- 'path' => $saveName3,
- 'upload_type' => 'local',
- 'size' => 1,
- 'create_admin_user_id' => 0,
- 'update_admin_user_id' => 0,
- 'create_time' => date('Y-m-d H:i:s'),
- 'update_time' => date('Y-m-d H:i:s'),
- 'uniacid' =>$_W['uniacid'],
- 'ext' =>'png'
- ]);
- return $fileId1.','.$fileId2.','.$fileId3;
- }
- }
|