Models.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace app\controller\admin;
  3. use app\service\api\UserServiceFacade;
  4. use laytp\controller\Backend;
  5. use laytp\library\CommonFun;
  6. use laytp\library\UploadDomain;
  7. use think\facade\Db;
  8. /**
  9. * 会员管理
  10. */
  11. class Models extends Backend
  12. {
  13. protected $model;//当前模型对象
  14. protected $noNeedLogin = [];
  15. protected $noNeedAuth = [];
  16. protected function _initialize()
  17. {
  18. $this->model = new \app\model\Models();
  19. }
  20. //查看
  21. public function index()
  22. {
  23. global $_W;
  24. $where = $this->buildSearchParams();
  25. $where[] = ['uniacid','=',$_W['uniacid']];
  26. // $order = $this->buildOrder();
  27. $order = ['sort'=>'desc','id'=>'desc'];
  28. $data = $this->model->where($where)->order($order);
  29. $allData = $this->request->param('all_data');
  30. if ($allData) {
  31. $data = $data->select();
  32. } else {
  33. $limit = $this->request->param('limit', 10);
  34. $data = $data->paginate($limit)->toArray();
  35. }
  36. return $this->success('数据获取成功', $data);
  37. }
  38. //添加
  39. public function add()
  40. {
  41. global $_W;
  42. Db::startTrans();
  43. try {
  44. $post = CommonFun::filterPostData($this->request->post());
  45. $post['uniacid'] = $_W['uniacid'];
  46. $result = $this->model->save($post);
  47. if(!$result) throw new \Exception("添加失败");
  48. Db::commit();
  49. return $this->success('添加成功');
  50. } catch (\Exception $e) {
  51. Db::rollback();
  52. return $this->exceptionError($e);
  53. }
  54. }
  55. //查看详情
  56. public function info()
  57. {
  58. $id = $this->request->param('id');
  59. $info = $this->model->findOrEmpty($id)->toArray();
  60. return $this->success('获取成功', $info);
  61. }
  62. //编辑
  63. public function edit()
  64. {
  65. Db::startTrans();
  66. try {
  67. $post = CommonFun::filterPostData($this->request->post());
  68. $navmenu = $this->model->findOrEmpty($post['id']);
  69. if (!$navmenu) throw new \Exception("id参数错误");
  70. $updateWords = $navmenu->update($post);
  71. if (!$updateWords) throw new \Exception("菜单基本信息保存失败");
  72. Db::commit();
  73. return $this->success('操作成功');
  74. } catch (\Exception $e) {
  75. Db::rollback();
  76. return $this->exceptionError($e);
  77. }
  78. }
  79. //删除
  80. public function del()
  81. {
  82. $ids = array_filter($this->request->param('ids'));
  83. if (!$ids) {
  84. return $this->error('参数ids不能为空');
  85. }
  86. try{
  87. if ($this->model->destroy($ids)) {
  88. return $this->success('数据删除成功');
  89. } else {
  90. return $this->error('数据删除失败');
  91. }
  92. }catch (\Exception $e){
  93. return $this->exceptionError($e);
  94. }
  95. }
  96. //设置状态
  97. public function setStatus()
  98. {
  99. $id = $this->request->post('id');
  100. $fieldVal = $this->request->post('field_val');
  101. $isRecycle = $this->request->post('is_recycle');
  102. $update['status'] = $fieldVal;
  103. try {
  104. if($isRecycle) {
  105. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  106. } else {
  107. $updateRes = $this->model->where('id', '=', $id)->update($update);
  108. }
  109. if ($updateRes) {
  110. return $this->success('操作成功');
  111. } else if ($updateRes === 0) {
  112. return $this->success('未作修改');
  113. } else {
  114. return $this->error('操作失败');
  115. }
  116. } catch (\Exception $e) {
  117. return $this->error('数据库异常,操作失败');
  118. }
  119. }
  120. //回收站
  121. public function recycle(){
  122. $where = $this->buildSearchParams();
  123. $order = $this->buildOrder();
  124. $limit = $this->request->param('limit', 10);
  125. $data = $this->model->onlyTrashed()
  126. ->order($order)->where($where)->paginate($limit)->toArray();
  127. return $this->success('回收站数据获取成功', $data);
  128. }
  129. //设置排序
  130. public function setSort()
  131. {
  132. $id = $this->request->post('id');
  133. $fieldVal = $this->request->post('field_val');
  134. $isRecycle = $this->request->post('is_recycle');
  135. $update['sort'] = $fieldVal;
  136. try {
  137. if($isRecycle) {
  138. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  139. } else {
  140. $updateRes = $this->model->where('id', '=', $id)->update($update);
  141. }
  142. if ($updateRes) {
  143. return $this->success('操作成功');
  144. } else if ($updateRes === 0) {
  145. return $this->success('未作修改');
  146. } else {
  147. return $this->error('操作失败');
  148. }
  149. } catch (\Exception $e) {
  150. return $this->error('数据库异常,操作失败');
  151. }
  152. }
  153. //初始化
  154. public function init(){
  155. global $_W;
  156. $where = ['uniacid' => $_W['uniacid']];
  157. try{
  158. if ($this->model->destroy($where)) {
  159. $list = [
  160. ['uniacid' => $_W['uniacid'],'model_id'=>'lowpoly-diffusion','name'=>'低多边形','intro'=>'可以生成低多边形风格的图片','status'=>1,'imgs'=>$this->addFile('lowpoly-diffusion'),'engine'=>'sd'],
  161. ['uniacid' => $_W['uniacid'],'model_id'=>'arcane-diffusion','name'=>'arcane模型','intro'=>'这是在电视节目Arcane的图像上训练的微调稳定扩散模型。','status'=>1,'imgs'=>$this->addFile('arcane-diffusion'),'engine'=>'sd'],
  162. ['uniacid' => $_W['uniacid'],'model_id'=>'mo-di-diffusion','name'=>'迪士尼风格','intro'=>'生成迪士尼风格图片','status'=>1,'imgs'=>$this->addFile('mo-di-diffusion'),'engine'=>'sd'],
  163. ['uniacid' => $_W['uniacid'],'model_id'=>'waifu-diffusion','name'=>'二次元动漫模型waifu','intro'=>'高质量二次元动漫风格图片生成','status'=>1,'imgs'=>$this->addFile('waifu-diffusion'),'engine'=>'sd'],
  164. ['uniacid' => $_W['uniacid'],'model_id'=>'redshift-diffusion','name'=>'CG感动漫模型','intro'=>'高品质3D渲染作品','status'=>1,'imgs'=>$this->addFile('redshift-diffusion'),'engine'=>'sd'],
  165. ['uniacid' => $_W['uniacid'],'model_id'=>'midjourney','name'=>'仿MidJourney V4风格','intro'=>'仿MidJourney风格图片生成','status'=>1,'imgs'=>$this->addFile('midjourney'),'engine'=>'sd'],
  166. ['uniacid' => $_W['uniacid'],'model_id'=>'pixel-art-v3','name'=>'像素艺术','intro'=>'生成像素风图片','status'=>1,'imgs'=>$this->addFile('pixel-art-v3'),'engine'=>'sd'],
  167. ['uniacid' => $_W['uniacid'],'model_id'=>'anything-v3','name'=>'经典二次元模型3.0','intro'=>'二次元模型 高质量的插图','status'=>1,'imgs'=>$this->addFile('anything-v3'),'engine'=>'sd'],
  168. ['uniacid' => $_W['uniacid'],'model_id'=>'anything-v5','name'=>'二次元模型5.0','intro'=>'二次元模型 相比3.0上限更高 描述词准确度更好','status'=>1,'imgs'=>$this->addFile('anything-v5'),'engine'=>'sd'],
  169. ['uniacid' => $_W['uniacid'],'model_id'=>'chilloutmix','name'=>'韩风真人2.5d','intro'=>'精致的面部细节','status'=>1,'imgs'=>$this->addFile('chilloutmix'),'engine'=>'sd'],
  170. ['uniacid' => $_W['uniacid'],'model_id'=>'guofeng3','name'=>'国风V3','intro'=>'国风V3 涵盖国风、古风、汉服的真人模型','status'=>1,'imgs'=>$this->addFile('guofeng3'),'engine'=>'sd'],
  171. ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile('bro623jbfe32'),'engine'=>'sd'],
  172. ['uniacid' => $_W['uniacid'],'model_id'=>'sdv2','name'=>'通用模型','intro'=>'官方sd原版','status'=>1,'imgs'=>$this->addFile('sdv2'),'engine'=>'sd'],
  173. ['uniacid' => $_W['uniacid'],'model_id'=>'mj','name'=>'Midjourney官方v5.1','intro'=>'Midjourney 最新版模型','status'=>1,'imgs'=>$this->addFile('mj'),'engine'=>'mj','version'=>'v5.1'],
  174. // ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile(15)],'engine'=>'mj'],
  175. // ['uniacid' => $_W['uniacid'],'model_id'=>'bro623jbfe32','name'=>'真实模型V4','intro'=>'超好看的美女图生成','status'=>1,'imgs'=>$this->addFile(15)],'engine'=>'mj']
  176. ];
  177. $this->model->saveAll($list);
  178. return $this->success('初始化成功');
  179. } else {
  180. return $this->error('数据删除失败');
  181. }
  182. }catch (\Exception $e){
  183. return $this->exceptionError($e);
  184. }
  185. // return $this->success('获取成功', $_W);
  186. }
  187. public function addFile($modelId)
  188. {
  189. global $_W;
  190. $modelFiles = new \app\model\Files();
  191. $saveName1 = 'presets/'.$modelId.'/' . 1 . ".png";
  192. $saveName2 = 'presets/'.$modelId.'/' . 2 . ".png";
  193. $saveName3 = 'presets/'.$modelId.'/' . 3 . ".png";
  194. $fileId1 = $modelFiles->insertGetId([
  195. 'category_id' => 0,
  196. 'name' => time(),
  197. 'file_type' => 'image',
  198. 'path' => $saveName1,
  199. 'upload_type' => 'local',
  200. 'size' => 1,
  201. 'create_admin_user_id' => 0,
  202. 'update_admin_user_id' => 0,
  203. 'create_time' => date('Y-m-d H:i:s'),
  204. 'update_time' => date('Y-m-d H:i:s'),
  205. 'uniacid' =>$_W['uniacid'],
  206. 'ext' =>'png'
  207. ]);
  208. $fileId2 = $modelFiles->insertGetId([
  209. 'category_id' => 0,
  210. 'name' => time(),
  211. 'file_type' => 'image',
  212. 'path' => $saveName2,
  213. 'upload_type' => 'local',
  214. 'size' => 1,
  215. 'create_admin_user_id' => 0,
  216. 'update_admin_user_id' => 0,
  217. 'create_time' => date('Y-m-d H:i:s'),
  218. 'update_time' => date('Y-m-d H:i:s'),
  219. 'uniacid' =>$_W['uniacid'],
  220. 'ext' =>'png'
  221. ]);
  222. $fileId3 = $modelFiles->insertGetId([
  223. 'category_id' => 0,
  224. 'name' => time(),
  225. 'file_type' => 'image',
  226. 'path' => $saveName3,
  227. 'upload_type' => 'local',
  228. 'size' => 1,
  229. 'create_admin_user_id' => 0,
  230. 'update_admin_user_id' => 0,
  231. 'create_time' => date('Y-m-d H:i:s'),
  232. 'update_time' => date('Y-m-d H:i:s'),
  233. 'uniacid' =>$_W['uniacid'],
  234. 'ext' =>'png'
  235. ]);
  236. return $fileId1.','.$fileId2.','.$fileId3;
  237. }
  238. }