Rewards.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\Rewards as RewardsModel;
  17. use app\user\validate\RewardsValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Rewards extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new RewardsModel();
  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['types'])) {
  48. $where[] = ['types', '=', $param['types']];
  49. }
  50. if (!empty($param['rewards_cate'])) {
  51. $where[] = ['rewards_cate', '=', $param['rewards_cate']];
  52. }
  53. if (!empty($param['uid'])) {
  54. $where[] = ['uid', '=', $param['uid']];
  55. }
  56. if (!empty($param['diff_time'])) {
  57. $diff_time =explode('~', $param['diff_time']);
  58. $where[] = ['rewards_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1]))]];
  59. }
  60. $list = $this->model->datalist($where, $param);
  61. return table_assign(0, '', $list);
  62. }
  63. else{
  64. return view();
  65. }
  66. }
  67. /**
  68. * 添加/编辑
  69. */
  70. public function add()
  71. {
  72. $param = get_params();
  73. if (request()->isAjax()) {
  74. $param['rewards_time'] = isset($param['rewards_time']) ? strtotime($param['rewards_time']) : 0;
  75. if (!empty($param['id']) && $param['id'] > 0) {
  76. try {
  77. validate(RewardsValidate::class)->scene('edit')->check($param);
  78. } catch (ValidateException $e) {
  79. // 验证失败 输出错误信息
  80. return to_assign(1, $e->getError());
  81. }
  82. $this->model->edit($param);
  83. } else {
  84. try {
  85. validate(RewardsValidate::class)->scene('add')->check($param);
  86. } catch (ValidateException $e) {
  87. // 验证失败 输出错误信息
  88. return to_assign(1, $e->getError());
  89. }
  90. $param['admin_id'] = $this->uid;
  91. $this->model->add($param);
  92. }
  93. }else{
  94. $id = isset($param['id']) ? $param['id'] : 0;
  95. if ($id>0) {
  96. $detail = $this->model->getById($id);
  97. $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
  98. $detail['rewards_time'] = to_date($detail['rewards_time'],'Y-m-d');
  99. View::assign('detail', $detail);
  100. }
  101. View::assign('id', $id);
  102. return view();
  103. }
  104. }
  105. /**
  106. * 查看
  107. */
  108. public function view($id)
  109. {
  110. $detail = $this->model->getById($id);
  111. if (!empty($detail)) {
  112. $detail['cate'] = Db::name('RewardsCate')->where('id',$detail['rewards_cate'])->value('title');
  113. $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
  114. $detail['admin_name'] = Db::name('Admin')->where('id',$detail['admin_id'])->value('name');
  115. $detail['rewards_time'] = to_date($detail['rewards_time'],'Y-m-d');
  116. View::assign('detail', $detail);
  117. return view();
  118. }
  119. else{
  120. throw new \think\exception\HttpException(404, '找不到页面');
  121. }
  122. }
  123. /**
  124. * 删除
  125. */
  126. public function del()
  127. {
  128. $param = get_params();
  129. $id = isset($param['id']) ? $param['id'] : 0;
  130. $this->model->delById($id);
  131. }
  132. }