Eyemarginp.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\admin\controller\applys;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 眼缘管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Eyemarginp extends Backend
  11. {
  12. /**
  13. * Eyemargin模型对象
  14. * @var \app\admin\model\applys\Eyemargin
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\applys\Eyemarginp;
  21. $this->view->assign("eyeTypeList", $this->model->getEyeTypeList());
  22. $this->view->assign("isMainList", $this->model->getIsMainList());
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. public function import()
  26. {
  27. parent::import();
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. /**
  35. * 查看
  36. */
  37. public function index()
  38. {
  39. //当前是否为关联查询
  40. $this->relationSearch = true;
  41. //设置过滤方法
  42. $this->request->filter(['strip_tags', 'trim']);
  43. if ($this->request->isAjax()) {
  44. //如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  49. $list = $this->model
  50. ->with(['user'])
  51. ->where($where)
  52. ->where(['eye_type'=>2])
  53. ->order($sort, $order)
  54. ->paginate($limit);
  55. foreach ($list as $row) {
  56. $row->getRelation('user')->visible(['nickname','province_name','city_name']);
  57. }
  58. foreach ($list as $k => $v) {
  59. $list[$k]['city'] = $v['user']['province_name'].".".$v['user']['city_name'];
  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 edit($ids = null)
  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)) {
  77. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  78. $this->error(__('You have no permission'));
  79. }
  80. }
  81. if ($this->request->isPost()) {
  82. $params = $this->request->post("row/a");
  83. if ($params) {
  84. $params = $this->preExcludeFields($params);
  85. $result = false;
  86. Db::startTrans();
  87. try {
  88. if($row['status'] == 0) {
  89. if($row['eye_type'] == 1) {
  90. if($params['status'] == 1) {
  91. $title = '短视频审核成功!';
  92. $content = '恭喜您,您发布的短视频发布审核成功啦!';
  93. \app\common\model\SysMsg::sendSysMsg($row['user_id'],3,$title,$content);
  94. }
  95. if($params['status'] == 0) {
  96. $title = '短视频审核失败!';
  97. $content = '非常抱歉,您发布的短视频由于不符合平台规范,管理员已审核拒绝!';
  98. \app\common\model\SysMsg::sendSysMsg($row['user_id'],3,$title,$content);
  99. }
  100. }
  101. if($row['eye_type'] == 2) {
  102. if($params['status'] == 1) {
  103. $title = '影集审核成功!';
  104. $content = '恭喜您,您发布的影集发布审核成功啦!';
  105. \app\common\model\SysMsg::sendSysMsg($row['user_id'],4,$title,$content);
  106. }
  107. if($params['status'] == 0) {
  108. $title = '影集审核失败!';
  109. $content = '非常抱歉,您发布的影集由于不符合平台规范,管理员已审核拒绝!';
  110. \app\common\model\SysMsg::sendSysMsg($row['user_id'],4,$title,$content);
  111. }
  112. }
  113. }
  114. //是否采用模型验证
  115. if ($this->modelValidate) {
  116. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  117. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  118. $row->validateFailException(true)->validate($validate);
  119. }
  120. $result = $row->allowField(true)->save($params);
  121. delUserInfo($params['user_id']);
  122. Db::commit();
  123. } catch (ValidateException $e) {
  124. Db::rollback();
  125. $this->error($e->getMessage());
  126. } catch (PDOException $e) {
  127. Db::rollback();
  128. $this->error($e->getMessage());
  129. } catch (Exception $e) {
  130. Db::rollback();
  131. $this->error($e->getMessage());
  132. }
  133. if ($result !== false) {
  134. $this->success();
  135. } else {
  136. $this->error(__('No rows were updated'));
  137. }
  138. }
  139. $this->error(__('Parameter %s can not be empty', ''));
  140. }
  141. $this->view->assign("row", $row);
  142. return $this->view->fetch();
  143. }
  144. }