|
- <?php
- /**
- * Created by PhpStorm.
- * User: tianlionfire
- * Date: 2017/11/14
- * Time: 10:44
- */
-
- namespace backend\modules\zzcs\logic;
-
-
- use backend\modules\zzcs\models\OperaTickets;
- use backend\modules\zzcs\models\OperaTicketsDesign;
- use backend\modules\zzcs\models\OrderMain;
- use Exception;
- use Yii;
-
- class OperaTicketsManage
- {
- /**
- * Function Description:查询票种信息
- * Function Name: getTicketInfos
- * @param $ticket_ids
- * @return array|\yii\db\ActiveRecord[]
- * @author 田玲菲
- */
- public function getTicketInfos($ticket_ids){
- $data = [];
- $data['code'] = '0';
- $data['info'] = '获取数据成功';
- $operaTickets = new OperaTickets();
- $result = $operaTickets->getTicketInfo($ticket_ids);
- if(count($result) == 0){
- $data['code'] = 1;
- $data['info'] = '该票种没有站点信息';
- }
- $data['tickets'] = $result;
- // $data['tickets_design_wildcard'] = '{订单号}{出发地}{上车站点}{目的地}{下车站点}{出发日期}{出发时间}{乘客姓名}{身份证号}{乘客电话}';
- $params = Yii::$app->params;
- $data['tickets_design_wildcard'] = $params['tickets_design_wildcard'];
- //票种设计通配符预览效果,给的死数据:
- // $orderInfo = [
- // 'order_id'=>10086,
- // 'prod_start_station_area_name'=>'南京市',
- // 'prod_start_station_res_name'=>'长途东站',
- // 'prod_end_station_area_name'=>'南通市',
- // 'prod_end_station_res_name'=>'南通长途客运站',
- // 'prod_start_station_date'=>'2017-01-01',
- // 'prod_start_station_time'=>'12:40',
- // 'cus_name'=>'张建',
- // 'cus_id_no'=>'320124199003212387',
- // 'customer_mobile'=>'13348095647'
- // ];
- $orderInfo = $params['tickets_designs_default_value'];
- $data['orderInfo'] = $orderInfo;
- //传第一个ticket_id的票样设计信息
- $ticket_id_array = explode(',',$ticket_ids);
- $ticket_id = $ticket_id_array[0];
- $rst = $this->getTicketDsg($ticket_id);
- // if(count($rst) == 0){
- // $data['code'] = 0;
- // $data['info'] = $ticket_id.'没有票种设计信息';
- // }
- $data['firstTicketDesign'] = $rst;
- return $data;
- }
-
-
- /**
- * Function Description:根据ticket_id查询票种设计信息
- * Function Name: getTicketDsg
- * @param $ticket_id
- * @return array|\yii\db\ActiveRecord[]
- * @author 田玲菲
- */
- public function getTicketDsg($ticket_id){
- $operaTicketDesign = new OperaTicketsDesign();
- $result = $operaTicketDesign->getTicketDesign($ticket_id);
- return $result;
- }
-
-
- /**
- * Function Description:修改/新增票种设计信息
- * Function Name: saveTicketDesign
- * @param $ticket1_content
- * @param $ticket2_content
- * @param $ticket3_content
- * @param $ticket4_content
- * @param $bar_code_1
- * @param $bar_code_2
- * @param $bar_code_3
- * @param $bar_code_4
- * @param $ticket_id
- * @return array
- * @author 田玲菲
- */
- public function saveTicketDesign($ticket1_content,$ticket2_content,$ticket3_content,$ticket4_content,$bar_code_1,$bar_code_2,$bar_code_3,$bar_code_4,$ticket_id){
- $ticket_id = is_array($ticket_id)?$ticket_id:explode(',',$ticket_id);
- $data = [];
- $transaction = \Yii::$app->db->beginTransaction();
- try {
- //循环$ticket_id数组,每一个分别保存
- foreach($ticket_id as $v){
- //1判断是否存在票种设计信息
- $operaTicketsDesign = new OperaTicketsDesign();
- $res = $operaTicketsDesign->existTicketDesign($v);
- if($res){
- //2.如果存在,就update
- $result = $operaTicketsDesign->changeTicketDesign($ticket1_content,$ticket2_content,$ticket3_content,$ticket4_content,$bar_code_1,$bar_code_2,$bar_code_3,$bar_code_4,$v);
- }else{
- //3.如果不存在,就insert
- $result = $operaTicketsDesign->addTicketDesign($ticket1_content,$ticket2_content,$ticket3_content,$ticket4_content,$bar_code_1,$bar_code_2,$bar_code_3,$bar_code_4,$v);
- }
- if(!$result){
- $transaction->rollBack();
- $data['code']=1;
- $data['info']='操作失败';
- return $data;
- }
- }
- $transaction->commit();
- $data['code']=0;
- $data['info']='操作成功';
- return $data;
- } catch (Exception $e) {
- $transaction->rollBack();
- $data['code']=2;
- $data['info']='操作失败';
- return $data;
- }
- }
-
-
- /**
- * Function Description:模版替换,打印票的信息
- * Function Name: replaceTicketDesign
- * @param $order_ids
- * @return array
- * @author 田玲菲
- */
- public function replaceTicketDesign($order_ids){
- //1.根据order_ids查询子订单的prod_id(ticket_id),如果有不存在票种设计模版的,直接驳回打印票的信息
- $orderMain = new OrderMain();
- $result = $orderMain->getReplaceInfo($order_ids);
- $data = [];
- if(empty($result)){
- $data['code'] = 2;
- $data['info'] = '未查到相关数据';
- $data['data'] = $result;
- return $data;
- }
- $arr1 = array();
- foreach($result as $v){
- $operaTicketsDesign = new OperaTicketsDesign();
- if (!$operaTicketsDesign->existTicketDesign($v['prod_id'])){
- array_push($arr1,$v['order_id']);
- }
- }
- if(count($arr1)>0){
- $data['code'] = 1;
- $data['info'] = '订单号为'.json_encode($arr1).'的票样没有票样模版';
- return $data;
- }
- //2.如果都有设计模版,循环数组,取出该数组对应的设计模版,替换模版,然后给$v增加content
- foreach($result as &$v){
- $operaTicketsDesign = new OperaTicketsDesign();
- $replaceInfo = $operaTicketsDesign->getTicketDesign($v['prod_id']);
- $v['bar_code_1'] = $replaceInfo[0]['bar_code_1'];
- $v['bar_code_2'] = $replaceInfo[0]['bar_code_2'];
- $v['bar_code_3'] = $replaceInfo[0]['bar_code_3'];
- $v['bar_code_4'] = $replaceInfo[0]['bar_code_4'];
- $ticket1_content = $replaceInfo[0]['ticket1_content'];
- $ticket1_content = str_replace("{订单号}", $v['order_id'], $ticket1_content);
- $ticket1_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket1_content);
- $ticket1_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket1_content);
- $ticket1_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket1_content);
- $ticket1_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket1_content);
- $ticket1_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket1_content);
- $ticket1_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket1_content);
- $ticket1_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket1_content);
- $ticket1_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket1_content);
- $ticket1_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket1_content);
- $ticket1_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket1_content);
- $v['ticket1_content'] = $ticket1_content;
- $ticket2_content = $replaceInfo[0]['ticket2_content'];
- $ticket2_content = str_replace("{订单号}", $v['order_id'], $ticket2_content);
- $ticket2_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket2_content);
- $ticket2_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket2_content);
- $ticket2_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket2_content);
- $ticket2_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket2_content);
- $ticket2_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket2_content);
- $ticket2_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket2_content);
- $ticket2_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket2_content);
- $ticket2_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket2_content);
- $ticket2_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket2_content);
- $ticket2_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket2_content);
- $v['ticket2_content'] = $ticket2_content;
- $ticket3_content = $replaceInfo[0]['ticket3_content'];
- $ticket3_content = str_replace("{订单号}", $v['order_id'], $ticket3_content);
- $ticket3_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket3_content);
- $ticket3_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket3_content);
- $ticket3_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket3_content);
- $ticket3_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket3_content);
- $ticket3_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket3_content);
- $ticket3_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket3_content);
- $ticket3_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket3_content);
- $ticket3_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket3_content);
- $ticket3_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket3_content);
- $ticket3_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket3_content);
- $v['ticket3_content'] = $ticket3_content;
- $ticket4_content = $replaceInfo[0]['ticket4_content'];
- $ticket4_content = str_replace("{订单号}", $v['order_id'], $ticket4_content);
- $ticket4_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket4_content);
- $ticket4_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket4_content);
- $ticket4_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket4_content);
- $ticket4_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket4_content);
- $ticket4_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket4_content);
- $ticket4_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket4_content);
- $ticket4_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket4_content);
- $ticket4_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket4_content);
- $ticket4_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket4_content);
- $ticket4_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket4_content);
- $v['ticket4_content'] = $ticket4_content;
- $v['ticket1_bar_code'] = $v['order_id'].'4';
- $v['ticket2_bar_code'] = $v['order_id'].'3';
- $v['ticket3_bar_code'] = $v['order_id'].'2';
- $v['ticket4_bar_code'] = $v['order_id'].'1';
- }
- $data['code'] = 0;
- $data['info'] = '获取成功';
- $data['data'] = $result;
- return $data;
- }
- }
|