1 , 'PROCESSING' => 2 , 'COMPLETED' => 3 ]; public function _initialize() { parent::_initialize(); $this->model = new \app\admin\model\money\Money; $this->bill = new \app\admin\model\money\Bill(); } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where , $sort , $order , $offset , $limit) = $this->buildparams(); $more_where = [ 'order_status' => 1, 'type' => 2 ]; $total = $this->model ->where($where) ->where($more_where) ->order($sort , $order) ->count(); $list = $this->model ->where($where) ->where($more_where) ->order($sort , $order) ->limit($offset , $limit) ->select(); $list = collection($list)->toArray(); $result = array ( "total" => $total , "rows" => $list ); return json($result); } return $this->view->fetch(); } /** * 生成账单 * @param $disable $ids * @throws DbException * @throws Exception */ public function makePaymentOrder($disable = false) { $params = $this->request->param(); $ids = $params['ids']; $moneys = $this->model->whereIn('id' , $ids)->select(); $ins_id = array_unique(array_column($moneys , 'institution_id')); if (count($ins_id) != 1) { $this->error('选择错误'); } $ins_data = Institution::where('id' , $ins_id[0])->find(); if ($this->request->isPost()) { $admin = Session::get('admin'); // 提交缴费单 $order_num = $this->makeOrderNum(); Db::startTrans(); try { $this->bill->insert([ 'order_num' => $order_num , 'institution_id' => $ins_data['id'] , 'institution_name' => $ins_data['name'] , 'water_ids' => implode(',' , $ids) , 'create_user_id' => $admin['id'] , 'create_user_name' => $admin['nickname'], 'remark' => $params['remark'] ]); $res = $this->model ->whereIn('id', $ids) ->update(['order_status' => $this->order_status['PROCESSING']]); if(!$res){ Db::rollback(); $this->error('修改流水状态失败'); } Db::commit(); $this->success('成功!单号为:'. $order_num); } catch (Exception $e){ Db::rollback(); $this->error($e->getMessage()); } } // 预览缴费单 $data = [ '1' => [ 'ZS' => 0 , 'TK' => 0 , 'HZZF' => 0 , 'YYTG' => 0 , 'YYDS' => 0 , ] , '2' => [ 'ZS' => 0 , 'TK' => 0 , 'HZZF' => 0 , 'YYTG' => 0 , 'YYDS' => 0 , ] ]; $total = 0; foreach ($moneys as $val) { $data[$val['type']]['ZS']++; $money = $val['money'] / 100; if ($val['pay_type'] == '1') { $total += $money; switch ($val['order_type']) { case '1': $data[$val['type']]['HZZF'] += $money; break; case '2': $data[$val['type']]['YYTG'] += $money; break; case '3': $data[$val['type']]['YYDS'] += $money; break; } } else { $data[$val['type']]['TK'] += $money; } } $this->view->disable = $disable; $this->view->result = $data; $this->view->total = $total; $this->view->institution = $ins_data; $html = $this->view->fetch(); $this->success('ok' , '' , $html); } public function downOrder($id) { $params = $this->request->param(); $ids = $this->bill->where('id',$id)->value('water_ids'); $moneys = $this->model->whereIn('id' , $ids)->select(); $ins_id = array_unique(array_column($moneys , 'institution_id')); if (count($ins_id) != 1) { $this->error('选择错误'); } $ins_data = Institution::where('id' , $ins_id[0])->find(); if ($this->request->isPost()) { $admin = Session::get('admin'); // 提交缴费单 $order_num = $this->makeOrderNum(); Db::startTrans(); try { $this->bill->insert([ 'order_num' => $order_num , 'institution_id' => $ins_data['id'] , 'institution_name' => $ins_data['name'] , 'water_ids' => implode(',' , $ids) , 'create_user_id' => $admin['id'] , 'create_user_name' => $admin['nickname'], 'remark' => $params['remark'] ]); $res = $this->model ->whereIn('id', $ids) ->update(['order_status' => $this->order_status['PROCESSING']]); if(!$res){ Db::rollback(); $this->error('修改流水状态失败'); } Db::commit(); $this->success('成功!单号为:'. $order_num); } catch (Exception $e){ Db::rollback(); $this->error($e->getMessage()); } } // 预览缴费单 $data = [ '1' => [ 'ZS' => 0 , 'TK' => 0 , 'HZZF' => 0 , 'YYTG' => 0 , 'YYDS' => 0 , ] , '2' => [ 'ZS' => 0 , 'TK' => 0 , 'HZZF' => 0 , 'YYTG' => 0 , 'YYDS' => 0 , ] ]; $total = 0; foreach ($moneys as $val) { $data[$val['type']]['ZS']++; $money = $val['money'] / 100; if ($val['pay_type'] == '1') { $total += $money; switch ($val['order_type']) { case '1': $data[$val['type']]['HZZF'] += $money; break; case '2': $data[$val['type']]['YYTG'] += $money; break; case '3': $data[$val['type']]['YYDS'] += $money; break; } } else { $data[$val['type']]['TK'] += $money; } } $this->view->disable = true; $this->view->result = $data; $this->view->total = $total; $this->view->institution = $ins_data; $html = $this->makeHtml($ins_data,$data,$total); $this->htmlToPdf($html); // $this->word($html); } public function makeHtml($ins_data,$data,$total) { $html = '