Sign.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 文章管理
  7. */
  8. namespace app\green\controller;
  9. use app\green\model\GreenSign;
  10. use app\green\model\GreenSignConfig;
  11. use think\facade\Request;
  12. use think\helper\Time;
  13. class Sign extends Common{
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. $this->assign('pathMaps', [['name'=>'签到管理','url'=>url("sign/index")]]);
  18. }
  19. /**
  20. * 列表
  21. */
  22. public function index()
  23. {
  24. $condition = [];
  25. $time = Request::param('time/d', 0);
  26. $starttime = Request::param('starttime/s');
  27. $endtime = Request::param('endtime/s');
  28. if ($time) {
  29. switch ($time) {
  30. case 2:
  31. list($start, $end) = Time::yesterday();
  32. break;
  33. case 30:
  34. list($start, $end) = Time::month();
  35. break;
  36. case 60:
  37. list($start, $end) = Time::lastMonth();
  38. break;
  39. default:
  40. list($start, $end) = Time::today();
  41. break;
  42. }
  43. $condition[] = ['signtime', '>=', $start];
  44. $condition[] = ['signtime', '<=', $end];
  45. } else {
  46. if ($starttime) {
  47. $condition[] = ['signtime', '>=', strtotime($starttime)];
  48. }
  49. if ($endtime) {
  50. $condition[] = ['signtime', '<=', strtotime($endtime)];
  51. }
  52. }
  53. $uid = Request::param('uid/d');
  54. if (!empty($uid)) {
  55. $condition[] = ['uid', '=', $uid];
  56. }
  57. $view['lists'] = GreenSign::where($this->mini_program)->where($condition)->order('id desc')->paginate(20, false, ['query' => ['starttime' => $starttime, 'endtime' => $endtime, 'time' => $time]]);
  58. $view['uid'] = $uid;
  59. $view['time'] = $time;
  60. $view['starttime'] = $starttime;
  61. $view['endtime'] = $endtime;
  62. return view()->assign($view);
  63. }
  64. /**
  65. * 列表
  66. */
  67. public function config(){
  68. $view['lists'] = GreenSignConfig::where($this->mini_program)->order('id')->select();
  69. return view()->assign($view);
  70. }
  71. /**
  72. * 添加
  73. */
  74. public function add(){
  75. if(request()->isAjax()){
  76. $data = [
  77. 'config_id' => input('post.config_id/d'),
  78. 'point' => input('post.point/d'),
  79. ];
  80. $validate = $this->validate($data,'sign.save');
  81. if(true !== $validate){
  82. return enjson(0,$validate);
  83. }
  84. $result = GreenSignConfig::create(['member_miniapp_id' => $this->member_miniapp_id,'config_id' => $data['config_id'],'point' => $data['point']]);
  85. if($result){
  86. return enjson(200,'操作成功',['url' => url('sign/index')]);
  87. }else{
  88. return enjson(0,'操作失败');
  89. }
  90. }else{
  91. $view['info'] =GreenSignConfig::where($this->mini_program)->order('config_id desc,id desc')->find();
  92. return view()->assign($view);
  93. }
  94. }
  95. /**
  96. * 编辑
  97. */
  98. public function edit(){
  99. if(request()->isAjax()){
  100. $data = [
  101. 'id' => input('post.id/d'),
  102. 'config_id' => input('post.config_id/d'),
  103. 'point' => input('post.point/d'),
  104. ];
  105. $validate = $this->validate($data,'sign.save');
  106. if(true !== $validate){
  107. return enjson(0,$validate);
  108. }
  109. $result = GreenSignConfig::where(['id' => $data['id']])->update(['member_miniapp_id' => $this->member_miniapp_id,'point' => $data['point']]);
  110. if($result){
  111. return enjson(200,'操作成功',['url' => url('news/index')]);
  112. }else{
  113. return enjson(0,'操作失败');
  114. }
  115. }else{
  116. $id = input('get.id/d');
  117. $view['info'] = GreenSignConfig::where(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->find();
  118. return view()->assign($view);
  119. }
  120. }
  121. /**
  122. * 删除
  123. */
  124. public function delete(int $id){
  125. $info = GreenSignConfig::where(['id' => $id])->where($this->mini_program)->find();
  126. if($info){
  127. $next = GreenSignConfig::where('config_id','>',$info->config_id)->where($this->mini_program)->find();
  128. if($next){
  129. return enjson(403,'操作失败,请先删除后面的配置');
  130. }else{
  131. $result = $info->delete();
  132. if($result){
  133. return enjson(200,'操作成功');
  134. }else{
  135. return enjson(403,'操作失败');
  136. }
  137. }
  138. }
  139. return enjson(403,'操作失败');
  140. }
  141. }