Burst.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Burst extends Auth
  5. {
  6. public function index(){
  7. if(request()->isAjax()){
  8. //分页参数
  9. $length = input('rows',10,'intval'); //每页条数
  10. $page = input('page',1,'intval'); //第几页
  11. $start = ($page - 1) * $length; //分页开始位置
  12. //排序
  13. $sortRow = input('sidx','id','trim'); //排序列
  14. $sort = input('sord','desc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort;
  16. $title = input('title','','trim');
  17. if($title){
  18. $map[] = ['title','like','%'.$title.'%'];
  19. }
  20. $enable = input('enable','','trim');
  21. if($enable != ''){
  22. $map[] = ['enable','=',$enable];
  23. }
  24. $map[] = ['org_id','=',$this->orgId];
  25. $map[] = ['del','=',0];
  26. $map= empty($map) ? true: $map;
  27. //数据查询
  28. $lists = db('burst')->where($map)->limit($start,$length)->order($order)->select();
  29. //数据返回
  30. $totalCount = db('burst')->where($map)->count();
  31. $totalPage = ceil($totalCount/$length);
  32. $result['page'] = $page;
  33. $result['total'] = $totalPage;
  34. $result['records'] = $totalCount;
  35. $result['rows'] = $lists;
  36. return json($result);
  37. }else{
  38. return $this->fetch();
  39. }
  40. }
  41. /**
  42. * 新增/编辑
  43. */
  44. public function add($id=0){
  45. if(request()->isPost()){
  46. $res = model('Burst')->updates();
  47. if($res){
  48. $this->success('操作成功',url('index'));
  49. }else{
  50. $this->error(model('Burst')->getError());
  51. }
  52. }else{
  53. $meta_title = '新增';
  54. if($id){
  55. $info = db('burst')->where('id',$id)->find();
  56. $this->assign('info',$info);
  57. $meta_title = '编辑';
  58. }
  59. $this->assign('meta_title',$meta_title);
  60. return $this->fetch();
  61. }
  62. }
  63. /**
  64. * 删除记录
  65. * @param int $id
  66. */
  67. public function del($id=0){
  68. if(!$id){
  69. $this->error('参数错误');
  70. }
  71. $res = db('burst')->where('id',$id)->setField('del',1);
  72. if($res){
  73. $this->success('删除成功');
  74. }else{
  75. $this->error('删除失败');
  76. }
  77. }
  78. /**
  79. * 改变字段值
  80. * @param int $fv
  81. * @param string $fn
  82. * @param int $fv
  83. */
  84. public function changeField($id=0,$fn='',$fv=0){
  85. if(!$fn||!$id){
  86. $this->error('参数错误');
  87. }
  88. $res = db('burst')->where('id',$id)->setField($fn,$fv);
  89. if($res){
  90. $this->success('操作成功');
  91. }else{
  92. $this->error('操作失败');
  93. }
  94. }
  95. public function start($id = 0){
  96. $info = Db::name('burst')->where('id',$id)->where('del',0)->find();
  97. if(!$info){
  98. $this->error('数据不存在');
  99. }
  100. // 检查是否有未完成的任务
  101. $ret = Db::name('burst_record')
  102. ->where('user_id',$this->userId)
  103. ->where('status',1)
  104. ->where('del',0)
  105. ->find();
  106. if($ret){
  107. $this->error('你还有进行中的事件未结束');
  108. }
  109. $content = json_decode($info['content'],true);
  110. $content[0]['status'] = 1;
  111. $data = [
  112. 'burst_id' => $info['id'],
  113. 'user_id' => $this->userId,
  114. 'org_id' => $this->orgId,
  115. 'content' => json_encode($content),
  116. 'status' => 1,
  117. 'create_time' => date('Y-m-d H:i:s')
  118. ];
  119. $res = Db::name('burst_record')->insertGetId($data);
  120. if($res){
  121. $this->success('操作成功');
  122. }else{
  123. $this->error('操作失败');
  124. }
  125. }
  126. //显示列表
  127. public function record()
  128. {
  129. if(request()->isAjax()){
  130. //分页参数
  131. $length = input('rows',10,'intval'); //每页条数
  132. $page = input('page',1,'intval'); //第几页
  133. $start = ($page - 1) * $length; //分页开始位置
  134. //排序
  135. $sortRow = input('sidx','br.id','trim'); //排序列
  136. $sort = input('sord','desc','trim'); //排序方式
  137. $order = $sortRow.' '.$sort;
  138. $title = input('title','','trim');
  139. if($title){
  140. $map[] = ['b.title','like','%'.$title.'%'];
  141. }
  142. $title = input('uname','','trim');
  143. if($title){
  144. $map[] = ['u.real_name','like','%'.$title.'%'];
  145. }
  146. $enable = input('status','','trim');
  147. if($enable != ''){
  148. $map[] = ['br.status','=',$enable];
  149. }
  150. $map[] = ['br.del','=',0];
  151. $map[] = ['br.org_id','=',$this->orgId];
  152. $map= empty($map) ? true: $map;
  153. //数据查询
  154. $lists = Db::name('burst_record')
  155. ->alias('br')
  156. ->join('burst b','b.id = br.burst_id')
  157. ->join('user u','u.id = br.user_id')
  158. ->field('br.*,u.real_name,b.title')
  159. ->where($map)->limit($start,$length)->order($order)->select();
  160. //数据返回
  161. $totalCount = Db::name('burst_record')
  162. ->alias('br')
  163. ->join('burst b','b.id = br.burst_id')
  164. ->join('user u','u.id = br.user_id')
  165. ->where($map)->count();
  166. $totalPage = ceil($totalCount/$length);
  167. $result['page'] = $page;
  168. $result['total'] = $totalPage;
  169. $result['records'] = $totalCount;
  170. $result['rows'] = $lists;
  171. return json($result);
  172. }else{
  173. return $this->fetch();
  174. }
  175. }
  176. }