Share.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\model\user\Share as ShareModel;
  5. use app\common\model\User as UserModel;
  6. use app\common\Enum\ShareEnum;
  7. use app\common\Enum\PageTypeEnum;
  8. /**
  9. * 分享记录管理
  10. *
  11. * @icon fa fa-share-alt
  12. */
  13. class Share extends Backend
  14. {
  15. /**
  16. * Share模型对象
  17. * @var \app\common\model\user\Share
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new ShareModel;
  24. $this->view->assign("fromList", ShareEnum::getFromList());
  25. $this->view->assign("platformList", ShareEnum::getPlatformList());
  26. $this->view->assign("pageTypeList", PageTypeEnum::getPageTypeList());
  27. }
  28. public function import()
  29. {
  30. parent::import();
  31. }
  32. /**
  33. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  34. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自定义
  35. * 如果需要自定义必须将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  36. */
  37. /**
  38. * 查看
  39. */
  40. public function index()
  41. {
  42. //当前是否为关联查询
  43. $this->relationSearch = true;
  44. //设置过滤方法
  45. $this->request->filter(['strip_tags', 'trim']);
  46. if ($this->request->isAjax()) {
  47. //如果发送的来源是Selectpage,则转发到Selectpage
  48. if ($this->request->request('keyField')) {
  49. return $this->selectpage();
  50. }
  51. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  52. $list = $this->model
  53. ->with(['user'])
  54. ->where($where)
  55. ->order($sort, $order)
  56. ->paginate($limit);
  57. foreach ($list as $row) {
  58. $row->user->visible(['id','username','nickname','mobile','avatar']);
  59. $row->visible(['id','user_id','share_id','spm','page','query','platform','from','platform_text','from_text','ext','createtime']);
  60. }
  61. $result = array("total" => $list->total(), "rows" => $list->items());
  62. return json($result);
  63. }
  64. return $this->view->fetch();
  65. }
  66. /**
  67. * 详情
  68. */
  69. public function detail($ids)
  70. {
  71. $row = $this->model->get($ids);
  72. if (!$row) {
  73. $this->error(__('No Results were found'));
  74. }
  75. $adminIds = $this->getDataLimitAdminIds();
  76. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  77. $this->error(__('You have no permission'));
  78. }
  79. // 加载关联数据
  80. $row->load(['user']);
  81. // 解析spm参数
  82. $smpParts = explode('.', $row->spm);
  83. $smpInfo = [];
  84. if (count($smpParts) >= 5) {
  85. $smpInfo = [
  86. 'share_id' => $smpParts[0] ?? '',
  87. 'page_type' => $smpParts[1] ?? '',
  88. 'query' => $smpParts[2] ?? '',
  89. 'platform' => $smpParts[3] ?? '',
  90. 'from' => $smpParts[4] ?? '',
  91. ];
  92. // 获取页面类型描述
  93. $smpInfo['page_type_text'] = PageTypeEnum::getPageTypeText($smpParts[1] ?? 0);
  94. }
  95. $this->view->assign("row", $row);
  96. $this->view->assign("smpInfo", $smpInfo);
  97. return $this->view->fetch();
  98. }
  99. }