Service.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\controller\service;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. /**
  8. * 服务管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Service extends Backend
  13. {
  14. /**
  15. * Service模型对象
  16. * @var \app\admin\model\service\Service
  17. */
  18. protected $model = null;
  19. protected $noNeedRight = ['commonselect'];
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\service\Service;
  24. $this->view->assign("typeList", $this->model->getTypeList());
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //当前是否为关联查询
  38. $this->relationSearch = true;
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if ($this->request->isAjax()) {
  42. //如果发送的来源是Selectpage,则转发到Selectpage
  43. if ($this->request->request('keyField')) {
  44. return $this->c_selectpage([["type", "=", \E_SERVICE_TYPE::App]]);
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $list = $this->model
  48. ->with(['category'])
  49. ->where("service.type", \E_SERVICE_TYPE::App)
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->visible(['id', 'name', 'cover_image', 'description', 'real_price', 'duration_minute', 'introduce_images', 'hot', 'sift', 'count', 'sort', 'status', 'updatetime']);
  55. $row->visible(['category']);
  56. $row->getRelation('category')->visible(['name']);
  57. }
  58. $result = array("total" => $list->total(), "rows" => $list->items());
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. public function add()
  64. {
  65. return parent::c_add(["type" => \E_SERVICE_TYPE::App]);
  66. }
  67. public function commonselect() {
  68. return $this->c_selectpage([["type", "=", \E_SERVICE_TYPE::App]]);
  69. }
  70. }