Gallery.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\controller\admin;
  3. use laytp\controller\Backend;
  4. use think\facade\Config;
  5. use laytp\library\CommonFun;
  6. use laytp\library\UploadDomain;
  7. /**
  8. * 幻灯轮播
  9. */
  10. class Gallery extends Backend
  11. {
  12. /**
  13. * slider模型对象
  14. * @var \app\model\Gallery
  15. */
  16. protected $model;
  17. protected $hasSoftDel=1;//是否拥有软删除功能
  18. protected $noNeedLogin = []; // 无需登录即可请求的方法
  19. protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法
  20. public function _initialize()
  21. {
  22. $this->model = new \app\model\Gallery();
  23. }
  24. //查看和搜索列表
  25. public function index(){
  26. global $_W;
  27. // $where = $this->buildSearchParams();
  28. $order = $this->buildOrder();
  29. $where[] = ['uniacid','=',$_W['uniacid']];
  30. $where[] = ['done','=',1];
  31. $order = ['sort'=>'desc','id'=>'desc'];
  32. $data = $this->model->order($order)->where($where)->with(['userInfo','modelsInfo']);
  33. $paging = $this->request->param('paging', false);
  34. if ($paging) {
  35. $limit = $this->request->param('limit', Config::get('paginate.limit'));
  36. $data = $data->paginate($limit)->toArray();
  37. $data['data'] = $this->getSelectedData($data['data']);
  38. } else {
  39. $data = $data->select()->toArray();
  40. }
  41. return $this->success('数据获取成功', $data);
  42. }
  43. //查看详情
  44. public function info()
  45. {
  46. $id = $this->request->param('id');
  47. $info = $this->model->with(['img_file'])->find($id);
  48. return $this->success('获取成功', $info);
  49. }
  50. //设置排序
  51. public function setSort()
  52. {
  53. $id = $this->request->post('id');
  54. $fieldVal = $this->request->post('field_val');
  55. $isRecycle = $this->request->post('is_recycle');
  56. $update['sort'] = $fieldVal;
  57. try {
  58. if($isRecycle) {
  59. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  60. } else {
  61. $updateRes = $this->model->where('id', '=', $id)->update($update);
  62. }
  63. if ($updateRes) {
  64. return $this->success('操作成功');
  65. } else if ($updateRes === 0) {
  66. return $this->success('未作修改');
  67. } else {
  68. return $this->error('操作失败');
  69. }
  70. } catch (\Exception $e) {
  71. return $this->error('数据库异常,操作失败');
  72. }
  73. }
  74. //设置账号状态
  75. public function setStatus()
  76. {
  77. $id = $this->request->post('id');
  78. $fieldVal = $this->request->post('field_val');
  79. $isRecycle = $this->request->post('is_recycle');
  80. $update['status'] = $fieldVal;
  81. try {
  82. if($isRecycle) {
  83. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  84. } else {
  85. $updateRes = $this->model->where('id', '=', $id)->update($update);
  86. }
  87. if ($updateRes) {
  88. return $this->success('操作成功');
  89. } else if ($updateRes === 0) {
  90. return $this->success('未作修改');
  91. } else {
  92. return $this->error('操作失败');
  93. }
  94. } catch (\Exception $e) {
  95. return $this->error('数据库异常,操作失败');
  96. }
  97. }
  98. //设置账号状态
  99. public function setIsOpen()
  100. {
  101. $id = $this->request->post('id');
  102. $fieldVal = $this->request->post('field_val');
  103. $isRecycle = $this->request->post('is_recycle');
  104. $update['is_open'] = $fieldVal;
  105. try {
  106. if($isRecycle) {
  107. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  108. } else {
  109. $updateRes = $this->model->where('id', '=', $id)->update($update);
  110. }
  111. if ($updateRes) {
  112. return $this->success('操作成功');
  113. } else if ($updateRes === 0) {
  114. return $this->success('未作修改');
  115. } else {
  116. return $this->error('操作失败');
  117. }
  118. } catch (\Exception $e) {
  119. return $this->error('数据库异常,操作失败');
  120. }
  121. }
  122. //初始化
  123. public function init(){
  124. global $_W;
  125. $where = ['uniacid' => $_W['uniacid']];
  126. try{
  127. if ($this->model->destroy($where)) {
  128. $list = [
  129. ['uniacid' => $_W['uniacid'],'title'=>'你可以这样对AI说:','type'=>'sentence']
  130. ];
  131. $this->model->saveAll($list);
  132. return $this->success('初始化成功');
  133. } else {
  134. return $this->error('数据删除失败');
  135. }
  136. }catch (\Exception $e){
  137. return $this->exceptionError($e);
  138. }
  139. // return $this->success('获取成功', $_W);
  140. }
  141. }