|
@@ -0,0 +1,311 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\controller\cost;
|
|
|
+
|
|
|
+use app\admin\model\cost\CostEdit;
|
|
|
+use app\admin\model\house\HuList;
|
|
|
+use app\common\controller\Backend;
|
|
|
+use think\Db;
|
|
|
+use think\exception\PDOException;
|
|
|
+use think\exception\ValidateException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 物业账单
|
|
|
+ *
|
|
|
+ * @icon fa fa-circle-o
|
|
|
+ */
|
|
|
+class CostBillShouyin extends Backend
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * CostBillShouyin模型对象
|
|
|
+ * @var \app\admin\model\cost\CostBillShouyin
|
|
|
+ */
|
|
|
+ protected $model = null;
|
|
|
+
|
|
|
+ public function _initialize()
|
|
|
+ {
|
|
|
+ parent::_initialize();
|
|
|
+ $this->model = new \app\admin\model\cost\CostBillShouyin;
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
+ * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
+ * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 查看
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ // printer_open
|
|
|
+
|
|
|
+ //设置过滤方法
|
|
|
+ $this->request->filter(['strip_tags']);
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
+ }
|
|
|
+ $get=$this->request->get('filter');
|
|
|
+ $where_and=['is_delete'=>'0'];
|
|
|
+ $where_and['item_id']=['not in',['1','2']];
|
|
|
+ if (!empty($this->auth->village)){
|
|
|
+ $where_and['village_id']=['in',$this->auth->village];
|
|
|
+ // dump($where_and);
|
|
|
+ }
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($get)){
|
|
|
+ // echo $get;exit;
|
|
|
+ $get=json_decode($get,true);
|
|
|
+
|
|
|
+
|
|
|
+ if (isset($get['village_id'])){
|
|
|
+ $where_and['village_id']=['eq',$get['village_id']];
|
|
|
+ }
|
|
|
+ if (isset($get['hu.usesr_name'])){
|
|
|
+
|
|
|
+ $get_huid=\app\admin\model\village\VillageHu::where('usesr_name','like','%'.$get['hu.usesr_name'].'%')->field('id')->select();
|
|
|
+ $hu_id=array_column($get_huid,'id');
|
|
|
+ $where_and['hu_id']=['in',$hu_id];
|
|
|
+ }
|
|
|
+ $total = $this->model
|
|
|
+ ->where($where_and)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ $list = $this->model
|
|
|
+
|
|
|
+ ->where($where_and)
|
|
|
+ ->with(['village','dong','danyuan','hu','item'])
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->limit($offset, $limit)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $total = $this->model
|
|
|
+ ->where($where)
|
|
|
+ ->where($where_and)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ $list = $this->model
|
|
|
+ ->where($where)
|
|
|
+ ->where($where_and)
|
|
|
+ ->with(['village','dong','danyuan','hu','item'])
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->limit($offset, $limit)
|
|
|
+ ->select();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $list = collection($list)->toArray();
|
|
|
+ $result = array("total" => $total, "rows" => $list);
|
|
|
+
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ */
|
|
|
+ public function edit($ids = null)
|
|
|
+ {
|
|
|
+ $row = $this->model->get($ids,['village','dong','danyuan','hu','item']);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if ($params) {
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $result = false;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
+ $row->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($row['pay_status']=='0'){//未付款的情况
|
|
|
+ if ($params['true_price'] !=$row['true_price']){//修改价格
|
|
|
+ if ($params['pay_status']=='1'){
|
|
|
+ $this->error(__('您好,修改物业费,需要上级同意之后方可付款', ''));
|
|
|
+ }else{
|
|
|
+ $insert['true_price_old']=$row['true_price'];
|
|
|
+ $insert['true_price_new']=$params['true_price'];
|
|
|
+ $insert['property_id']=$this->auth->property_id;
|
|
|
+ $insert['bill_id']=$row['id'];
|
|
|
+ $insert['status']='1';
|
|
|
+ $insert['mark']=$params['mark'];
|
|
|
+ $insert['createtime']=$insert['updatetime']=time();
|
|
|
+ CostEdit::insert($insert);
|
|
|
+ $params['true_price'] = $row['true_price'];
|
|
|
+ }
|
|
|
+ }elseif ($params['pay_status'] !=$row['pay_status']){//修改成已付款
|
|
|
+ if ($params['pay_status']=='1'){
|
|
|
+ $params['pay_time']=time();
|
|
|
+ $order_number=time().rand('1000','9999');
|
|
|
+ $params['order_number']=$order_number;
|
|
|
+ HuList::where('id',$row['hu_id'])->update(['last_date'=>date('Y-m-d')]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if ($params['true_price'] !=$row['true_price'] || $params['pay_status'] != $row['pay_status']){
|
|
|
+ $this->error(__('您好,已付款的账单,不可以修改', ''));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = $row->allowField(true)->save($params);
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were updated'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ if ($row['item_id']=='1'){
|
|
|
+ $row['item_name']='水费';
|
|
|
+ }elseif($row['item_id']=='2'){
|
|
|
+ $row['item_name']='电费';
|
|
|
+ }else{
|
|
|
+ // $get_itme=CostItem::where('id',$row['item_id'])->field('item')->find();
|
|
|
+ if ($row['item']['item']=='1'){
|
|
|
+ $row['item_name']='物业费';
|
|
|
+ }elseif ($row['item']['item']=='2'){
|
|
|
+ $row['item_name']='垃圾处理费';
|
|
|
+ }elseif ($row['item']['item']=='3'){
|
|
|
+ $row['item_name']='车位费';
|
|
|
+ }else{
|
|
|
+ $row['item_name']='未知';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $row['house']=$row['village']['name']." ".$row['dong']['name']." ".$row['danyuan']['name']." ".$row['hu']['name'];
|
|
|
+// $get_edit=CostEdit::where('bill_id',$row['id'])->where('is_delete','0')->select();
|
|
|
+// $this->view->assign("get_edit", $get_edit);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $this->view->assign("row", $row);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ public function del($ids = "")
|
|
|
+ {
|
|
|
+ if ($ids) {
|
|
|
+ $pk = $this->model->getPk();
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ $this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
|
+ }
|
|
|
+ $list = $this->model->where($pk, 'in', $ids)->select();
|
|
|
+
|
|
|
+ $count = 0;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ $count += $v->save(['is_delete'=>1]);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($count) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were deleted'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量更新
|
|
|
+ */
|
|
|
+ public function multi($ids = "")
|
|
|
+ {
|
|
|
+ $ids = $ids ? $ids : $this->request->param("ids");
|
|
|
+ if ($ids) {
|
|
|
+ if ($this->request->has('params')) {
|
|
|
+ parse_str($this->request->post("params"), $values);
|
|
|
+
|
|
|
+ $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
|
|
|
+ if ($values) {
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ $this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
|
+ }
|
|
|
+ $count = 0;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
|
|
|
+ foreach ($list as $index => $item) {
|
|
|
+ if ($values['pay_status']=='1'){
|
|
|
+ $values['pay_time']=time();
|
|
|
+ }else{
|
|
|
+ $values['pay_time']='';
|
|
|
+ }
|
|
|
+
|
|
|
+ $count += $item->allowField(true)->isUpdate(true)->save($values);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($count) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were updated'));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
+ }
|
|
|
+}
|