service == null) { $this->service = new Payment(); } return $this->service; } /** * Des:管理页面 * Name: actionCopeManager * @return string * @author 倪宗锋 */ public function actionCopeManager() { $user_id = Yii::$app->request->cookies->getValue('user_id', 2); $model_user = new BaseUser(); $user_info = $model_user->getUserInfo($user_id); $data['main_corp_id'] = $user_info[0]["MAIN_CORP_ID"]; //获取供应商 $baseSupplier = new BaseSupplier(); $getList = $baseSupplier->getSupplierList(); $data['supplier_list'] = $getList; // 获取列表 $start_date = date('Y-m-01 00:00:00'); $end_date = date('Y-m-d 23:59:59', strtotime(date('Y-m-1') . " +1 month -1 day")); $param = $this->service()->getGetParam();//获取参数 通过get方式 if (empty($param['date_type'])) { $param['date_type'] = 1; } if (empty($param['start_date'])) { $param['start_date'] = $start_date; $param['end_date'] = $end_date; } $getWhere = $this->service()->getWhere($param);//获取查询条件 $result = $this->service()->getTotal($getWhere);//获取统计数据 $total_row = $result['page']['total_count']; $total_page = $result['page']['total_page']; $page_size = $getWhere['param']['page_size']; $current_page = $getWhere['param']['current_page']; $data['list'] = $this->service()->getList($getWhere);//获取列表 $data['purchase'] = $result['sum_info']['total_price']; $data['indemnity'] = $result['sum_info']['reparations_price']; $page_size_arr = [10=>10, 20=>20, 30=>30, 50=>50, 100=>100,$total_row=>'all']; $page_arr = $this->service()->getPage($total_row, $page_size, $current_page); $page = [ 'page_size' => $page_size, 'current_page' => $current_page, 'total_row' => $total_row, 'total_page' => $total_page ]; $data['page_arr'] = $page_arr; $data['page'] = $page; $data['page_size'] = $page_size; $data['page_size_arr'] = $page_size_arr; $data["where"] = json_encode($getWhere); return $this->render('cope_manager', $data); } /** * Des:账单界面 * Name: actionCopeManager * @return string * @author 倪宗锋 */ public function actionCopeAccount() { // 获取供应商列表 $base_supplier=new BaseSupplier(); $result=$base_supplier->getSupplierList(); $data['supplier_list'] = $result; // 获取数据列表 $param = array( 'current_page' => Yii::$app->request->get('current_page', '1'),//当前页 'page_size' => Yii::$app->request->get('page_size', '10'),//每页展示条数 'org_id' => Yii::$app->request->get('org_id', ''),//供应商ID 'batch_id' => Yii::$app->request->get('batch_id', ''),//对账单号 'status' => Yii::$app->request->get('status', ''),//对账状态1待核对,2待结算,3已结算,4已取消 ); $user_id = Yii::$app->request->cookies->getValue('user_id', 2); $model_user = new BaseUser(); $user_info = $model_user->getUserInfo($user_id); $param["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"]; $getList = $this->service()->getBalance($param); // 分页信息 $current_page = $param['current_page']; $page_size = $param['page_size']; $total_row = $getList['page']['total_count']; $total_page = $getList['page']['total_page']; $data['list'] = $getList['order_list']; $page_size_arr = [10, 20, 30, 50, 100]; $page_arr = $this->service()->getPage($total_row, $page_size, $current_page); $page = [ 'page_size' => $page_size, 'current_page' => $current_page, 'total_row' => $total_row, 'total_page' => $total_page ]; $data['page_arr'] = $page_arr; $data['page'] = $page; $data['page_size'] = $page_size; $data['page_size_arr'] = $page_size_arr; return $this->render('cope_account_statement',$data); } /** * Des:获取供应商列表 * Name: actionGetSupplier * @return string * @author 倪宗锋 */ public function actionGetSupplier() { $baseSupplier = new BaseSupplier(); $getList = $baseSupplier->getSupplierList(); return json_encode(['code' => 0, 'list' => $getList]); } /** * Des:获取列表 * Name: actionGetList * @return string * @author 倪宗锋 */ public function actionGetList() { $param = $this->service()->getParam();//获取参数 $getWhere = $this->service()->getWhere($param);//获取查询条件 try { if ($getWhere['param']['current_page'] == 1) {//第一页时才获取统计数据 $data = $this->service()->getTotal($getWhere);//获取统计数据 $data['page']['page_size'] = $getWhere['param']['page_size']; $data['page']['current_page'] = $getWhere['param']['current_page']; } $data['order_list'] = $this->service()->getList($getWhere);//获取列表 } catch (Exception $e) { $json['code'] = '1'; $json['info'] = '获取列表失败'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '获取列表成功'; $json['data'] = $data; return json_encode($json); } /** * Function Description:检查列表 * Function Name: actionCheckId * * @return string * * @author 李健 */ public function actionCheckId() { $type = Yii::$app->request->post('type', ''); $id = Yii::$app->request->post('id', ''); $status = Yii::$app->request->post('status', ''); $order_ids = explode(',', trim($id, ',')); $str_id = ''; foreach ($order_ids as $order_id) { $res = $this->service()->getStatus($order_id); if(!$res){ if($type==1){ continue; } $str_id .= $order_id . ','; } if ($type == 1) { if ($res[$status] != 1) { $str_id .= $res['order_id'] . ', '; } } elseif ($type == 2 || $type == 3) { if ($res[$status] != 2) { $str_id .= $res['order_id'] . ','; } } } if ($str_id != '') { $str_id = rtrim($str_id, ', '); $json['code'] = 1; $json['info'] = ' 订单编号为' . $str_id . '的数据结算状态异常!请重新选择'; } else { $json['code'] = 0; $json['info'] = ''; } return json_encode($json); } /** * Des:关账 * Name: actionClosesAmount * @return string * @author 倪宗锋 */ public function actionCloseByOrderId() { $base_user=new BaseUser(); $main_corp_id=$base_user->getMainCorp(); $str = trim(Yii::$app->request->post('order_id_str', ''), ','); $getWhere=[ 'main_corp_id'=>$main_corp_id, 'bus_where'=>" a.id in ($str)", 'order_where'=>" a.order_id in ($str)", ]; $checkFlag = $this->service()->checkClosesAmount($getWhere);//校验是否可以关账 if ($checkFlag == false) { $json['code'] = '1'; $json['info'] = '关账失败!所选订单中有非待结算状态的订单!'; return json_encode($json); } $closeFlag = $this->service()->closesAmount($getWhere);//执行关账操作 if ($closeFlag == false) { $json['code'] = '1'; $json['info'] = '关账失败!数据处理失败!'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '关账成功!'; return json_encode($json); } /** * Function Description:关账 * Function Name: actionCloseByOrderId * * @return string * @throws Exception * * @author 李健 */ // public function actionCloseByOrderId() // { // $str = trim(Yii::$app->request->post('order_id_str', ''), ','); // // $res = $this->service()->closeByOrderId($str); // if ($res == false) { // $json['code'] = '1'; // $json['info'] = '关账失败!数据处理失败!'; // return json_encode($json); // } // $json['code'] = '0'; // $json['info'] = '关账成功!'; // return json_encode($json); // } /** * Des:生成对账单 * Name: ActionAddBalance * @return string * @author 倪宗锋 */ public function actionAddBalanceByOrderId() { // $param = $this->service()->getParam();//获取参数 // $getWhere = $this->service()->getWhere($param);//获取查询条件 $base_user=new BaseUser(); $main_corp_id=$base_user->getMainCorp(); $str = trim(Yii::$app->request->post('order_id_str', ''), ','); $start_date = Yii::$app->request->post('start_date', ''); $end_date = Yii::$app->request->post('end_date', ''); $getWhere=[ 'start_date'=>$start_date, 'end_date'=>$end_date, 'main_corp_id'=>$main_corp_id, 'bus_where'=>" a.id in ($str)", 'order_where'=>" a.order_id in ($str) and a.cancel_flag=0", ]; $checkFlag = $this->service()->checkIsAllCloses($getWhere);//检测是否所有记录状态都是关账状态 if ($checkFlag == false) { $json['code'] = '1'; $json['info'] = '生成对账单失败!所选订单中有非已关账状态的订单!'; return json_encode($json); } $addFlag = $this->service()->addBalance($getWhere);//生成对账单 if ($addFlag == false) { $json['code'] = '1'; $json['info'] = '生成对账单失败!数据处理失败!'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '生成对账单成功!'; return json_encode($json); } /** * Function Description:生成对账单 * Function Name: actionAddBalanceByOrderId * * @return string * @throws Exception * * @author 李健 */ // public function actionAddBalanceByOrderId() // { // $str = trim(Yii::$app->request->post('order_id_str', ''), ','); // $start_date = Yii::$app->request->post('start_date', ''); // $end_date = Yii::$app->request->post('end_date', ''); // // $user_id = Yii::$app->request->cookies->getValue('user_id', 2); // $model_user = new BaseUser(); // $user_info = $model_user->getUserInfo($user_id); // $main_corp_id = $user_info[0]["MAIN_CORP_ID"]; // $addFlag = $this->service()->addBalanceByOrderId($str, $start_date, $end_date, $main_corp_id);//生成对账单 // if ($addFlag == false) { // $json['code'] = '1'; // $json['info'] = '生成对账单失败!数据处理失败!'; // return json_encode($json); // } // $json['code'] = '0'; // $json['info'] = '生成对账单成功!'; // return json_encode($json); // } /** * Des:取消关账 * Name: actionCancelCloses * @return string * @author 倪宗锋 */ public function actionCancelByOrderId() { // $param = $this->service()->getParam();//获取参数 // $getWhere = $this->service()->getWhere($param);//获取查询条件 $base_user=new BaseUser(); $main_corp_id=$base_user->getMainCorp(); $str = trim(Yii::$app->request->post('order_id_str', ''), ','); $getWhere=[ 'main_corp_id'=>$main_corp_id, 'bus_where'=>" a.id in ($str)", 'order_where'=>" a.order_id in ($str)", ]; $checkFlag = $this->service()->checkIsAllCloses($getWhere);//检测是否所有记录状态都是关账状态 if ($checkFlag == false) { $json['code'] = '1'; $json['info'] = '取消关账失败!所选订单中有非已关账状态的订单!'; return json_encode($json); } $addFlag = $this->service()->cancelCloses($getWhere);//执行取消关账操作 if ($addFlag == false) { $json['code'] = '1'; $json['info'] = '取消关账失败!数据处理失败!'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '取消关账成功!'; return json_encode($json); } /** * Des:获取对账单列表 * Name: actionGetBalance * @return string * @author 倪宗锋 */ public function actionGetBalance() { $param = array( 'current_page' => Yii::$app->request->post('current_page', ''),//当前页 'page_size' => Yii::$app->request->post('page_size', ''),//每页展示条数 'org_id' => Yii::$app->request->post('org_id', ''),//供应商ID 'batch_id' => Yii::$app->request->post('batch_id', ''),//对账单号 'status' => Yii::$app->request->post('status', ''),//对账状态1待核对,2待结算,3已结算,4已取消 ); $user_id = Yii::$app->request->cookies->getValue('user_id', 2); $model_user = new BaseUser(); $user_info = $model_user->getUserInfo($user_id); $param["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"]; $getList = $this->service()->getBalance($param); $json['code'] = '0'; $json['info'] = '获取列表成功'; $getList['page']['page_size'] = $param['page_size']; $getList['page']['current_page'] = $param['current_page']; $json['data'] = $getList; return json_encode($json); } /** * Function Description:取消关账通过id * Function Name: actionCancelByOrderId * * @return string * @throws Exception * * @author 李健 */ // public function actionCancelByOrderId() // { // $str = trim(Yii::$app->request->post('order_id_str', ''), ','); // // $res = $this->service()->cancelByOrderId($str); // if ($res == false) { // $json['code'] = '1'; // $json['info'] = '取消关账失败!数据处理失败!'; // return json_encode($json); // } // $json['code'] = '0'; // $json['info'] = '生成对账单成功!'; // return json_encode($json); // } /** * Des:取消对账 * Name: cancelBalance * @return string * @author 倪宗锋 */ public function actionCancelBalance() { $id = Yii::$app->request->post('id', ''); //校验对账单状态 $flag = $this->service()->checkBalanceStatus($id, array(1)); if ($flag == false) { $json['code'] = '2'; $json['info'] = '失败!待核对的账单才可以执行取消操作!'; return json_encode($json); } $flag = $this->service()->cancelBalance($id); if ($flag == false) { $json['code'] = '2'; $json['info'] = '取消对账失败!'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '取消对账成功'; return json_encode($json); } /** * Des:确认对账单 * Name: actionConfirmedBalance * @return string * @author 倪宗锋 */ public function actionConfirmedBalance() { $id = Yii::$app->request->post('id', ''); //校验对账单状态 $flag = $this->service()->checkBalanceStatus($id, array(1)); if ($flag == false) { $json['code'] = '2'; $json['info'] = '失败!待核对的账单才可以确认核对!'; return json_encode($json); } $flag = $this->service()->confirmedBalance($id); if ($flag == false) { $json['code'] = '2'; $json['info'] = '确认对账单状态失败!'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '确认对账单状态成功'; return json_encode($json); } /** * Des:确认结算 * Name: actionBalancing * @return string * @author 倪宗锋 */ public function actionBalancing() { $id = Yii::$app->request->post('id', ''); //校验对账单状态 $flag = $this->service()->checkBalanceStatus($id, array(2)); if ($flag == false) { $json['code'] = '2'; $json['info'] = '失败!已核对的账单才可以结算!'; return $json; } $flag = $this->service()->balancing($id); if ($flag == false) { $json['code'] = '2'; $json['info'] = '结算订单失败!system error'; return json_encode($json); } $json['code'] = '0'; $json['info'] = '结算订单成功'; return json_encode($json); } /** * Des:导出excel * Name: excelBalance * @return string * @author 倪宗锋 */ public function actionExcelBalance() { $id = Yii::$app->request->get('id', ''); $info = $this->service()->getAccountInfo($id); if ($info == false) { echo '导出excel失败!'; die; } $list = $this->service()->getListForExcel($info); /**======生成excel=========**/ ob_clean(); $fileName = '【' . $info['org_name'] . '】应付账单-' . $info['start_date'] . '~' . $info['end_date'] . '.csv'; $fileName = iconv("utf-8", "gb2312", $fileName); header("Content-type:text/csv"); header("Content-Disposition:attachment;filename=" . $fileName); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); $data = ''; foreach ($list as $key => $val) { if ($key == 0) { $data .= implode(',', array_keys($val)) . "\n"; } $data .= '"' . implode('","', array_values($val)) . "\"\n"; } $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data; echo $data; return ''; } /** * Function Description:未关账前导出 * Function Name: actionBeforeExcelBalance * * * @author LUOCJ */ public function actionBeforeExcelBalance() { $param = $this->service()->getGetParam();//获取参数 $getWhere = $this->service()->getWhere($param);//获取查询条件 $list = $this->service()->getList($getWhere,1);//获取列表 1为导出 $fin_list = []; foreach ($list as $k => $v) { $fin_list[$k]['order_id'] = $v['order_id']; $fin_list[$k]['outside_order_no'] = $v['outside_order_no']; $fin_list[$k]['run_date'] = $v['run_date']; $fin_list[$k]['create_time'] = $v['create_time']; $fin_list[$k]['parent_prod_name'] = $v['parent_prod_name']; $fin_list[$k]['prod_type_des'] = $v['prod_type_des']; $fin_list[$k]['prodName'] = $v['prodName']; $fin_list[$k]['prodNum'] = $v['prodNum']; $fin_list[$k]['base_price'] = $v['base_price']; $fin_list[$k]['reparations_price'] = $v['reparations_price']; $fin_list[$k]['supplier_name'] = $v['supplier_name']; $fin_list[$k]['prodNum'] = $v['prodNum']; } $title = ['订单ID', '渠道订单ID', '出游时间', '预订时间', '产品名称', '产品类型', '房型/票种', '间夜/票数', '成本', '赔款', '供应商']; $file_name ='应付账单'; /**======生成excel=========**/ Payment::to_excel($file_name,$title, $fin_list); } /** * Function Description:修改账单备注 * Function Name: actionChangeRemark * * @return string * * @author 娄梦宁 */ public function actionChangeRemark(){ $account_id=Yii::$app->request->post('account_id',0);//账单id $remark=Yii::$app->request->post('remark','');//备注 $result=$this->service()->changeRemark($account_id,$remark); return json_encode($result); } }