0
0

HouseLock.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class HouseLock extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->table='house_lock';
  10. $this->model= new \app\common\model\HouseLock();
  11. }
  12. public function index(){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','id','trim'); //排序列
  20. $sort = input('sord','desc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort;
  22. $status = input('status','','trim');
  23. if($status != ''){
  24. $map[] = ['status','=',$status];
  25. }
  26. $b = input('start','','trim');
  27. $e = input('end','','trim');
  28. if($b){
  29. $b = date('Y-m-d 00:00:00',strtotime($b));
  30. $map[] = ['create_time','>=',$b];
  31. }
  32. if($e){
  33. $e = date('Y-m-d 23:59:59',strtotime($e));
  34. $map[] = ['create_time','<=',$e];
  35. }
  36. $map[] = ['org_id','=',$this->orgId];
  37. $map[] = ['user_id','=',$this->userId];
  38. $map= empty($map) ? true: $map;
  39. //数据查询
  40. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  41. foreach ($lists as $k=>$v){
  42. $lists[$k]['real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
  43. $lists[$k]['deal_real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
  44. $lists[$k]['cur_user_id'] = $this->userId;
  45. }
  46. //数据返回
  47. $totalCount = db($this->table)->where($map)->count();
  48. $totalPage = ceil($totalCount/$length);
  49. $result['page'] = $page;
  50. $result['total'] = $totalPage;
  51. $result['records'] = $totalCount;
  52. $result['rows'] = $lists;
  53. return json($result);
  54. }else{
  55. return $this->fetch();
  56. }
  57. }
  58. public function add()
  59. {
  60. $start = input('start');
  61. $end = input('end');
  62. if(!$start){
  63. // 获取开始时间,为空的没有数据
  64. $start = $this->model->getStartTime($this->userId);
  65. $end = date('Y-m-d H:i:s');
  66. }
  67. $data = $this->model->getDataInfo($start,$end,$this->userId,$this->orgId);
  68. $error = '';
  69. if(!$data){
  70. $error = $this->model->getError();
  71. }
  72. $this->assign('data',$data);
  73. $this->assign('error',$error);
  74. $this->assign('start',$start);
  75. $this->assign('end',$end);
  76. return $this->fetch();
  77. }
  78. public function addSave(){
  79. $start = input('start');
  80. $end = input('end');
  81. $remark = input('remark');
  82. $userId = $this->userId;
  83. $orgId = $this->orgId;
  84. $ret = $this->model->addSave($start,$end,$remark,$userId,$orgId);
  85. if(!$ret){
  86. $error = $this->model->getError();
  87. $this->error($error);
  88. }else{
  89. $this->success('操作成功');
  90. }
  91. }
  92. public function cancel($id){
  93. $ret = $this->model->deal($id,3,$this->userId);
  94. if(!$ret){
  95. $this->error($this->model->getError());
  96. }else{
  97. $this->success('操作是吧');
  98. }
  99. }
  100. public function detail($id)
  101. {
  102. $data = $this->model->getDataById($id);
  103. if(!$data){
  104. $this->error('记录不存在',url('HouseLock/index'));
  105. }
  106. $this->assign('data',$data);
  107. return $this->fetch();
  108. }
  109. public function edit($id)
  110. {
  111. $data = $this->model->getDataById($id);
  112. if(!$data){
  113. $this->error('记录不存在',url('HouseLock/index'));
  114. }
  115. $this->assign('data',$data);
  116. return $this->fetch();
  117. }
  118. public function apply(){
  119. if(request()->isAjax()){
  120. //分页参数
  121. $length = input('rows',10,'intval'); //每页条数
  122. $page = input('page',1,'intval'); //第几页
  123. $start = ($page - 1) * $length; //分页开始位置
  124. //排序
  125. $sortRow = input('sidx','id','trim'); //排序列
  126. $sort = input('sord','desc','trim'); //排序方式
  127. $order = $sortRow.' '.$sort;
  128. $status = input('status','','trim');
  129. if($status != ''){
  130. $map[] = ['status','=',$status];
  131. }
  132. $b = input('start','','trim');
  133. $e = input('end','','trim');
  134. if($b){
  135. $b = date('Y-m-d 00:00:00',strtotime($b));
  136. $map[] = ['create_time','>=',$b];
  137. }
  138. if($e){
  139. $e = date('Y-m-d 23:59:59',strtotime($e));
  140. $map[] = ['create_time','<=',$e];
  141. }
  142. $map[] = ['org_id','=',$this->orgId];
  143. $map= empty($map) ? true: $map;
  144. //数据查询
  145. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  146. foreach ($lists as $k=>$v){
  147. $lists[$k]['real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
  148. $lists[$k]['deal_real_name'] = $this->getTableField('user',['id'=>$v['user_id']],'real_name');
  149. }
  150. //数据返回
  151. $totalCount = db($this->table)->where($map)->count();
  152. $totalPage = ceil($totalCount/$length);
  153. $result['page'] = $page;
  154. $result['total'] = $totalPage;
  155. $result['records'] = $totalCount;
  156. $result['rows'] = $lists;
  157. return json($result);
  158. }else{
  159. return $this->fetch();
  160. }
  161. }
  162. public function detail2($id)
  163. {
  164. $data = $this->model->getDataById($id);
  165. if(!$data){
  166. $this->error('记录不存在',url('HouseLock/apply'));
  167. }
  168. $this->assign('data',$data);
  169. return $this->fetch();
  170. }
  171. public function agree($id){
  172. $ret = $this->model->deal($id,1,$this->userId);
  173. if(!$ret){
  174. $this->error($this->model->getError());
  175. }else{
  176. $this->success('操作成功');
  177. }
  178. }
  179. public function disagree($id){
  180. $ret = $this->model->deal($id,2,$this->userId);
  181. if(!$ret){
  182. $this->error($this->model->getError());
  183. }else{
  184. $this->success('操作成功');
  185. }
  186. }
  187. public function detail2print($id){
  188. $data = $this->model->getDataById($id);
  189. if(!$data){
  190. $this->error('记录不存在',url('HouseLock/apply'));
  191. }
  192. $data['count_logs'] = count($data['logs']);
  193. $this->assign('data',$data);
  194. return $this->fetch();
  195. }
  196. }