Care.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\user\controller;
  15. use app\base\BaseController;
  16. use app\user\model\Care as CareModel;
  17. use app\user\validate\CareValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Care extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new CareModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. if (request()->isAjax()) {
  38. $param = get_params();
  39. $where=[];
  40. $where[]=['delete_time','=',0];
  41. if (!empty($param['keywords'])) {
  42. $where[] = ['id|thing|remark', 'like', '%' . $param['keywords'] . '%'];
  43. }
  44. if (!empty($param['status'])) {
  45. $where[] = ['status', '=', $param['status']];
  46. }
  47. if (!empty($param['care_cate'])) {
  48. $where[] = ['care_cate', '=', $param['care_cate']];
  49. }
  50. if (!empty($param['uid'])) {
  51. $where[] = ['uid', '=', $param['uid']];
  52. }
  53. if (!empty($param['diff_time'])) {
  54. $diff_time =explode('~', $param['diff_time']);
  55. $where[] = ['care_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1]))]];
  56. }
  57. $list = $this->model->datalist($where, $param);
  58. return table_assign(0, '', $list);
  59. }
  60. else{
  61. return view();
  62. }
  63. }
  64. /**
  65. * 添加/编辑
  66. */
  67. public function add()
  68. {
  69. $param = get_params();
  70. if (request()->isAjax()) {
  71. $param['care_time'] = isset($param['care_time']) ? strtotime($param['care_time']) : 0;
  72. if (!empty($param['id']) && $param['id'] > 0) {
  73. try {
  74. validate(CareValidate::class)->scene('edit')->check($param);
  75. } catch (ValidateException $e) {
  76. // 验证失败 输出错误信息
  77. return to_assign(1, $e->getError());
  78. }
  79. $this->model->edit($param);
  80. } else {
  81. try {
  82. validate(CareValidate::class)->scene('add')->check($param);
  83. } catch (ValidateException $e) {
  84. // 验证失败 输出错误信息
  85. return to_assign(1, $e->getError());
  86. }
  87. $param['admin_id'] = $this->uid;
  88. $this->model->add($param);
  89. }
  90. }else{
  91. $id = isset($param['id']) ? $param['id'] : 0;
  92. if ($id>0) {
  93. $detail = $this->model->getById($id);
  94. $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
  95. View::assign('detail', $detail);
  96. }
  97. View::assign('id', $id);
  98. return view();
  99. }
  100. }
  101. /**
  102. * 查看
  103. */
  104. public function view($id)
  105. {
  106. $detail = $this->model->getById($id);
  107. if (!empty($detail)) {
  108. $detail['cate'] = Db::name('CareCate')->where('id',$detail['care_cate'])->value('title');
  109. $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
  110. $detail['admin_name'] = Db::name('Admin')->where('id',$detail['admin_id'])->value('name');
  111. View::assign('detail', $detail);
  112. return view();
  113. }
  114. else{
  115. throw new \think\exception\HttpException(404, '找不到页面');
  116. }
  117. }
  118. /**
  119. * 删除
  120. */
  121. public function del()
  122. {
  123. $param = get_params();
  124. $id = isset($param['id']) ? $param['id'] : 0;
  125. $this->model->delById($id);
  126. }
  127. }