VisitorOrder.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\admin\controller;
  3. class VisitorOrder extends Auth
  4. {
  5. public function index(){
  6. if(request()->isAjax()){
  7. //分页参数
  8. $length = input('rows',10,'intval'); //每页条数
  9. $page = input('page',1,'intval'); //第几页
  10. $start = ($page - 1) * $length; //分页开始位置
  11. //排序
  12. $sortRow = input('sidx','id','trim'); //排序列
  13. $sort = input('sort','desc','trim'); //排序方式
  14. $order = $sortRow.' '.$sort;
  15. $type = input('type/d');
  16. if($type){
  17. $map[] = ['type','=',$type];
  18. }
  19. $service_id = input('service_id','','trim');
  20. if($service_id){
  21. $map[] = ['service_id','=',$service_id];
  22. }
  23. $map[] = ['org_id','=',cur_org_id()];
  24. $map[] = ['del','=',0];
  25. $map= empty($map) ? true: $map;
  26. //数据查询
  27. $lists = db('visitor_order')
  28. ->where($map)
  29. ->limit($start,$length)
  30. ->order('id desc')
  31. ->select();
  32. foreach ($lists as $k=>$v){
  33. $lists[$k]['service_name'] = db('service')->where('id',$v['service_id'])->where('del',0)->value('title');
  34. $service_time = db('service_time')->where('id',$v['service_time_id'])->where('del',0)->find();
  35. $lists[$k]['time'] =$service_time?$service_time['day'].' '.$service_time['start'].'~'.$service_time['end']:'';
  36. if($v['service_time_id'] > 0 ){
  37. $v = $this->autoCheck($v,$service_time);
  38. $lists[$k]['status'] = $v['status'];
  39. }
  40. $lists[$k]['form_user'] = db('user')->where('id',$v['from_user_id'])->where('del',0)->value('real_name');
  41. }
  42. //数据返回
  43. $totalCount = db('visitor_order')->where($map)->count();
  44. $totalPage = ceil($totalCount/$length);
  45. $result['page'] = $page;
  46. $result['total'] = $totalPage;
  47. $result['records'] = $totalCount;
  48. $result['rows'] = $lists;
  49. return json($result);
  50. }else{
  51. $service = db('service')->where('org_id',cur_org_id())->where('enable',1)->where('del',0)->select();
  52. $this->assign('service',$service);
  53. return $this->fetch();
  54. }
  55. }
  56. /**
  57. * 状态修改
  58. */
  59. public function change($id=0,$status){
  60. if(!$id){
  61. $this->error('参数错误');
  62. }
  63. $res = db('visitor_order')->where('id',$id)->setField('status',$status);
  64. if($res){
  65. $this->success('操作成功');
  66. }else{
  67. $this->error('操作失败');
  68. }
  69. }
  70. /**
  71. * 删除记录
  72. * @param int $id
  73. */
  74. public function del($id=0){
  75. if(!$id){
  76. $this->error('参数错误');
  77. }
  78. $res = db('visitor_order')->where('id',$id)->setField('del',1);
  79. if($res){
  80. $this->success('删除成功');
  81. }else{
  82. $this->error('删除失败');
  83. }
  84. }
  85. /**
  86. * 改变字段值
  87. * @param int $fv
  88. * @param string $fn
  89. * @param int $fv
  90. */
  91. public function changeField($id=0,$fn='',$fv=0){
  92. if(!$fn||!$id){
  93. $this->error('参数错误');
  94. }
  95. $res = db('visitor_order')->where('id',$id)->setField($fn,$fv);
  96. if($res){
  97. $this->success('操作成功');
  98. }else{
  99. $this->error('操作失败');
  100. }
  101. }
  102. // 自动检测预约已失效
  103. private function autoCheck($info,$time){
  104. if($info['status'] == 1){
  105. $curTime = time();
  106. $endTime = strtotime($time['day'].' '.$time['end']);
  107. if($curTime >= $endTime){
  108. db('visitor_order')->where('id',$info['id'])->update(['status'=>3]);
  109. $info['STATUS'] = 3;
  110. }
  111. }
  112. return $info;
  113. }
  114. public function details($id=0){
  115. if($id < 1){
  116. $this->error('参数错误');
  117. }
  118. $info = db('visitor_order')->where('id',$id)->find();
  119. $info['service_name'] = db('service')->where('id',$info['service_id'])->where('del',0)->value('title');
  120. $service_time = db('service_time')->where('id',$info['service_time_id'])->where('del',0)->find();
  121. $info['time'] =$service_time?$service_time['day'].' '.$service_time['start'].'~'.$service_time['end']:'';
  122. $info['form_user'] = db('user')->where('id',$info['from_user_id'])->where('del',0)->value('real_name');
  123. $this->assign('info',$info);
  124. return $this->fetch();
  125. }
  126. public function share(){
  127. $url = config("app.app_host").config('app.visit_url').cur_org_id();
  128. $code = think_encrypt($url);
  129. $this->assign('code',$code);
  130. $this->assign('url',$url);
  131. return $this->fetch();
  132. }
  133. public function share2(){
  134. $url = config("app.app_host").config('app.visit_url').cur_org_id().'&type=1';
  135. $code = think_encrypt($url);
  136. $this->assign('code',$code);
  137. $this->assign('url',$url);
  138. return $this->fetch();
  139. }
  140. }