Cover.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\admin\controller\manage;
  3. use app\common\controller\Backend;
  4. use think\Controller;
  5. use think\Request;
  6. /**
  7. * 运营管理-封面管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Cover extends Backend
  12. {
  13. /**
  14. * ManageCover模型对象
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = model('ManageCover');
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("sexList", $this->model->getSexList());
  23. $this->view->assign("typeList", $this->model->getTypeList());
  24. }
  25. /**
  26. * 查看
  27. */
  28. public function index()
  29. {
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags']);
  32. if ($this->request->isAjax())
  33. {
  34. //如果发送的来源是Selectpage,则转发到Selectpage
  35. if ($this->request->request('pkey_name'))
  36. {
  37. return $this->selectpage();
  38. }
  39. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  40. $whereArr = [];
  41. if (strtolower($this->request->action()) == 'select') {
  42. $whereArr[] = ['status', '=', 'normal'];
  43. $whereArr = function($query) use ($whereArr) {
  44. foreach ($whereArr as $k => $v)
  45. {
  46. if (is_array($v))
  47. {
  48. call_user_func_array([$query, 'where'], $v);
  49. }
  50. else
  51. {
  52. $query->where($v);
  53. }
  54. }
  55. };
  56. }
  57. $total = $this->model
  58. ->where($where)
  59. ->where($whereArr)
  60. ->order($sort, $order)
  61. ->count();
  62. $list = $this->model
  63. ->where($where)
  64. ->where($whereArr)
  65. ->order($sort, $order)
  66. ->limit($offset, $limit)
  67. ->select();
  68. $result = array("total" => $total, "rows" => $list);
  69. return json($result);
  70. }
  71. return $this->view->fetch();
  72. }
  73. /**
  74. * 选择封面图片
  75. */
  76. public function select()
  77. {
  78. if ($this->request->isAjax()) {
  79. return $this->index();
  80. }
  81. return $this->view->fetch();
  82. }
  83. /**
  84. * ajax方法转发index,用于渠道商/代理商API请求
  85. * @return string|\think\response\Json
  86. */
  87. public function ajax()
  88. {
  89. return $this->index();
  90. }
  91. }