CostBillMouth.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. namespace app\admin\controller\cost;
  3. use app\admin\model\village\Village;
  4. use app\common\controller\Backend;
  5. use app\admin\model\cost\CostItem;
  6. /**
  7. * 物业账单
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class CostBillMouth extends Backend
  12. {
  13. /**
  14. * CostBillMouth模型对象
  15. * @var \app\admin\model\cost\CostBillMouth
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\cost\CostBillMouth;
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. // printer_open
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags']);
  36. if ($this->request->isAjax()) {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. $get=$this->request->get('filter');
  42. $where_and=['is_delete'=>'0','pay_status'=>'1'];
  43. if (!empty($this->auth->village)){
  44. $where_and['village_id']=['in',$this->auth->village];
  45. // dump($where_and);
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. if (!empty($get)){
  49. $get=json_decode($get,true);
  50. if (isset($get['village_id'])){
  51. $where_and['village_id']=['eq',$get['village_id']];
  52. }
  53. if (isset($get['item_id'])){
  54. $where_and['item_id']=['eq',$get['item_id']];
  55. }
  56. if (isset($get['hu.usesr_name'])){
  57. $get_huid=\app\admin\model\village\VillageHu::where('usesr_name','like','%'.$get['hu.usesr_name'].'%')->field('id')->select();
  58. $hu_id=array_column($get_huid,'id');
  59. $where_and['hu_id']=['in',$hu_id];
  60. }
  61. $total = $this->model
  62. ->where($where_and)
  63. // ->where($where)
  64. ->order('pay_time desc')
  65. ->count();
  66. $list = $this->model
  67. ->where($where_and)
  68. //->where($where)
  69. ->with(['village','dong','danyuan','hu','item'])
  70. ->order('pay_time desc')
  71. ->limit($offset, $limit)
  72. ->select();
  73. }else{
  74. $total = $this->model
  75. ->where($where)
  76. ->where($where_and)
  77. ->order('pay_time desc')
  78. ->count();
  79. $list = $this->model
  80. ->where($where)
  81. ->where($where_and)
  82. ->with(['village','dong','danyuan','hu','item','village.property'])
  83. ->order('pay_time desc')
  84. ->limit($offset, $limit)
  85. ->select();
  86. }
  87. foreach ($list as $k=>$v){
  88. $list[$k]['house']=$v['village']['property']['p_name']." ".$v['village']['name']." ".$v['dong']['name']." ".$v['danyuan']['name'];
  89. }
  90. $list = collection($list)->toArray();
  91. $result = array("total" => $total, "rows" => $list);
  92. return json($result);
  93. }
  94. return $this->view->fetch();
  95. }
  96. public function village(){
  97. if (!empty($this->auth->village)){
  98. $where_and['village_id']=['in',$this->auth->village];
  99. // dump($where_and);
  100. }
  101. $where_and['is_delete']=['eq','0'];
  102. $groupList =Village::where($where_and)->field('id as value,v_name as name')->order('id asc')->select();
  103. $this->success('', null, $groupList);
  104. }
  105. public function item_id(){
  106. $id = $this->request->get('id');
  107. if (!empty($this->auth->village)){
  108. $where_and['village_id']=['in',$this->auth->village];
  109. // dump($where_and);
  110. }
  111. $get_item=CostItem::where(['village_id'=>$id,'is_delete'=>'0'])->field('id as value,item')->select();
  112. foreach ($get_item as $k=>$v){
  113. if ($v['item']=='1'){
  114. $get_item[$k]['name']='物业费';
  115. }elseif($v['item']=='2'){
  116. $get_item[$k]['name']='生活垃圾处理费';
  117. }elseif($v['item']=='3'){
  118. $get_item[$k]['name']='车位服务费';
  119. }else{
  120. $get_item[$k]['name']='未知';
  121. }
  122. }
  123. $data = [
  124. [
  125. 'value'=>1,'item'=>'1','name'=>'水费',
  126. ],
  127. [
  128. 'value'=>2,'item'=>'2','name'=>'电费',
  129. ],
  130. [
  131. 'value'=>999999999,'item'=>'999999999','name'=>'车位服务费',
  132. ]
  133. ];
  134. $data=array_merge($data,$get_item);
  135. $this->success('', null, $data);
  136. }
  137. public function mouth($ids = null){
  138. // cost/cost_bill_mouth/mouth?select=1&area-operate=%3D&village_id=&hu.usesr_name-operate=LIKE&hu.usesr_name=&pay_time-operate=RANGE&pay_time=
  139. // cost/cost_bill_mouth/mouth?select=0&id=91,1
  140. $select=$this->request->get('select');
  141. $where_and=['is_delete'=>'0','pay_status'=>'1'];
  142. if ($select=='1'){//需要自己检索
  143. $get=$this->request->get();
  144. if (!empty($get['village_id']) && !empty($get['village_id'])){
  145. $where_and['village_id']=$get['village_id'];
  146. }
  147. if (isset($get['item_id']) && !empty($get['item_id'])){
  148. $where_and['item_id']=['eq',$get['item_id']];
  149. }
  150. if (isset($get['pay_time'])&& !empty($get['pay_time'])){
  151. //echo $get['pay_time'];exit;
  152. $pay_time=explode(' - ',$get['pay_time']);
  153. $where_and['pay_time']=['between',[strtotime($pay_time['0']),strtotime($pay_time['1'])]];
  154. }
  155. if (isset($get['hu.usesr_name']) && !empty($get['hu.usesr_name'])){
  156. $get_huid=\app\admin\model\village\VillageHu::where('usesr_name','like','%'.$get['hu.usesr_name'].'%')->field('id')->select();
  157. $hu_id=array_column($get_huid,'id');
  158. $where_and['hu_id']=['in',$hu_id];
  159. }
  160. }else{//传值id
  161. $id=$this->request->get('id');
  162. $ids=explode(',',$id);
  163. $where_and['id']=['in',$ids];
  164. }
  165. $list = $this->model
  166. ->where($where_and)
  167. ->with(['village','dong','danyuan','hu','item','village.property'])
  168. ->order('pay_time desc')
  169. ->select();
  170. foreach ($list as $k=>$v){
  171. if ($v['item_id']=='1'){
  172. $list[$k]['item_name']='水费';
  173. }elseif($v['item_id']=='2'){
  174. $list[$k]['item_name']='电费';
  175. }elseif($v['item_id']=='9999999999'){
  176. $list[$k]['item_name']='车位服务费';
  177. }else{
  178. // $get_itme=CostItem::where('id',$row['item_id'])->field('item')->find();
  179. if ($v['item']['item']=='1'){
  180. $list[$k]['item_name']='物业费';
  181. }elseif ($v['item']['item']=='2'){
  182. $list[$k]['item_name']='生活垃圾处理费';
  183. }elseif ($v['item']['item']=='3'){
  184. $list[$k]['item_name']='车位服务费';
  185. }else{
  186. $list[$k]['item_name']='未知';
  187. }
  188. }
  189. $list[$k]['pay_date']=date('Y-m-d H:i:s',$v['pay_time']);
  190. }
  191. $time=date('Y-m-d H:i:s');
  192. $this->view->assign('time',$time);
  193. $this->view->assign('list',$list);
  194. return $this->view->fetch();
  195. }
  196. }