Banner.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 Banner extends Backend
  11. {
  12. /**
  13. * slider模型对象
  14. * @var \app\model\Banner
  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\Banner();
  23. }
  24. //查看和搜索列表
  25. public function index(){
  26. global $_W;
  27. $where = $this->buildSearchParams();
  28. $where[] = ['uniacid','=',$_W['uniacid']];
  29. $order = $this->buildOrder();
  30. $order = ['sort'=>'desc','id' => 'desc'];
  31. $data = $this->model->where($where)->order($order)->with(['img_file']);
  32. $paging = $this->request->param('paging', false);
  33. if ($paging) {
  34. $limit = $this->request->param('limit', Config::get('paginate.limit'));
  35. $data = $data->paginate($limit)->toArray();
  36. $data['data'] = $this->getSelectedData($data['data']);
  37. } else {
  38. $data = $data->select()->toArray();
  39. }
  40. return $this->success('数据获取成功', $data);
  41. }
  42. //查看详情
  43. public function info()
  44. {
  45. $id = $this->request->param('id');
  46. $info = $this->model->with(['img_file'])->find($id);
  47. return $this->success('获取成功', $info);
  48. }
  49. //设置排序
  50. public function setSort()
  51. {
  52. $id = $this->request->post('id');
  53. $fieldVal = $this->request->post('field_val');
  54. $isRecycle = $this->request->post('is_recycle');
  55. $update['sort'] = $fieldVal;
  56. try {
  57. if($isRecycle) {
  58. $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update);
  59. } else {
  60. $updateRes = $this->model->where('id', '=', $id)->update($update);
  61. }
  62. if ($updateRes) {
  63. return $this->success('操作成功');
  64. } else if ($updateRes === 0) {
  65. return $this->success('未作修改');
  66. } else {
  67. return $this->error('操作失败');
  68. }
  69. } catch (\Exception $e) {
  70. return $this->error('数据库异常,操作失败');
  71. }
  72. }
  73. }