|
- <?php
- /**
- * 财务应收管理控制器
- * Created by PhpStorm.
- * User: admin
- * Date: 2017/5/31
- * Time: 9:15
- */
-
- namespace backend\modules\zzcs\controllers;
-
-
- use backend\modules\zzcs\models\BaseSupplier;
- use backend\modules\zzcs\service\Gathering;
- use backend\modules\zzcs\service\Payment;
- use yii\db\Exception;
- use yii\web\Controller;
- use backend\modules\zzcs\models\BaseUser;
- use Yii;
-
- class GatheringController extends Controller
- {
- public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
- public $enableCsrfValidation = false;
- public $service = null;
-
- /**
- * Des:获取service类初始化
- * Name: service
- * @return Gathering
- * @author 倪宗锋
- */
- public function service()
- {
- if ($this->service == null) {
- $this->service = new Gathering();
- }
- return $this->service;
- }
-
- /**
- * Des:管理页面
- * Name: actionCopeManager
- * @return string
- * @author 倪宗锋
- */
- public function actionReceivableManager()
- {
- // 获取main_corp_id
- $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"];
-
- // 获取渠道商
- $base_supplier = new BaseSupplier();
- $result = $base_supplier->getChannelList();
- $data['channel_list'] = $result;
-
- // 获取列表页
- $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'];
- $order_list = $this->service()->getList($getWhere);//获取列表
- $data['list'] = $order_list;
-
- $page_size_arr = [10=>10,50=>50, 100=>100,'all'=>$total_row];
- $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['sum_info']=$result['sum_info'];
- return $this->render('receivable_management_list', $data);
- }
-
- /**
- * Function Description:账单界面
- * Function Name: actionReceivableAccount
- *
- * @return string
- * @throws Exception
- *
- * @author 李健
- */
- public function actionReceivableAccount()
- {
-
- // 获取渠道商
- $data['channel_list'] = $this->service()->getChannel();
- // 获取列表
- $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('receivable_account_statement',$data);
- }
-
- /**
- * 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);
- }
-
- /**
- * Des:关账
- * Name: actionClosesAmount
- * @return string
- * @author 倪宗锋
- */
- public function actionClosesAmount()
- {
- $param = $this->service()->getParam();//获取参数
- $getWhere = $this->service()->getWhere($param);//获取查询条件
- $checkFlag = $this->service()->checkClosesAmount($getWhere);//校验是否可以关账
- if ($checkFlag == false) {
- $json['code'] = '1';
- $json['info'] = '关账失败!所选订单中有非待结算状态的订单!';
- return json_encode($json);
- }
-
- $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
- $model_user = new BaseUser();
- $user_info = $model_user->getUserInfo($user_id);
- $getWhere["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"];
- $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
- * @throws Exception
- * @author 倪宗锋
- */
- public function actionAddBalance()
- {
- $param = $this->service()->getParam();//获取参数
- $getWhere = $this->service()->getWhere($param);//获取查询条件
- $checkFlag = $this->service()->checkIsAllCloses($getWhere);//检测是否所有记录状态都是关账状态
- if ($checkFlag == false) {
- $json['code'] = '1';
- $json['info'] = '生成对账单失败!所选订单中有非已关账状态的订单!';
- return json_encode($json);
- }
- $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
- $model_user = new BaseUser();
- $user_info = $model_user->getUserInfo($user_id);
- $getWhere["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"];
- $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
- * @throws Exception
- * @author 倪宗锋
- */
- public function actionCancelCloses()
- {
- $param = $this->service()->getParam();//获取参数
- $getWhere = $this->service()->getWhere($param);//获取查询条件
- $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);
- }
-
- /**
- * 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: actionGetBalance
- * @return string
- * @throws Exception
- * @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);
- }
-
- /**
- * Des:取消对账
- * Name: cancelBalance
- * @return string
- * @throws Exception
- * @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
- * @throws Exception
- * @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
- * @throws Exception
- * @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);//获取列表
- $fin_list = [];
- foreach ($list as $k => $v) {
- $fin_list[$k]['order_id'] = $v['order_id'];
- $fin_list[$k]['cus_name'] = $v['cus_name'];
- $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]['order_price'] = $v['order_price'];
- $fin_list[$k]['reparations_price'] = $v['reparations_price'];
- $fin_list[$k]['total_commission'] = $v['total_commission'];
- $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: actionCheckId
- *
- * @return string
- * @throws Exception
- *
- * @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);
- }
- }
|