You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

235 lines
12 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tianlionfire
  5. * Date: 2017/11/14
  6. * Time: 10:44
  7. */
  8. namespace backend\modules\zzcs\logic;
  9. use backend\modules\zzcs\models\OperaTickets;
  10. use backend\modules\zzcs\models\OperaTicketsDesign;
  11. use backend\modules\zzcs\models\OrderMain;
  12. use Exception;
  13. use Yii;
  14. class OperaTicketsManage
  15. {
  16. /**
  17. * Function Description:查询票种信息
  18. * Function Name: getTicketInfos
  19. * @param $ticket_ids
  20. * @return array|\yii\db\ActiveRecord[]
  21. * @author 田玲菲
  22. */
  23. public function getTicketInfos($ticket_ids){
  24. $data = [];
  25. $data['code'] = '0';
  26. $data['info'] = '获取数据成功';
  27. $operaTickets = new OperaTickets();
  28. $result = $operaTickets->getTicketInfo($ticket_ids);
  29. if(count($result) == 0){
  30. $data['code'] = 1;
  31. $data['info'] = '该票种没有站点信息';
  32. }
  33. $data['tickets'] = $result;
  34. // $data['tickets_design_wildcard'] = '{订单号}{出发地}{上车站点}{目的地}{下车站点}{出发日期}{出发时间}{乘客姓名}{身份证号}{乘客电话}';
  35. $params = Yii::$app->params;
  36. $data['tickets_design_wildcard'] = $params['tickets_design_wildcard'];
  37. //票种设计通配符预览效果,给的死数据:
  38. // $orderInfo = [
  39. // 'order_id'=>10086,
  40. // 'prod_start_station_area_name'=>'南京市',
  41. // 'prod_start_station_res_name'=>'长途东站',
  42. // 'prod_end_station_area_name'=>'南通市',
  43. // 'prod_end_station_res_name'=>'南通长途客运站',
  44. // 'prod_start_station_date'=>'2017-01-01',
  45. // 'prod_start_station_time'=>'12:40',
  46. // 'cus_name'=>'张建',
  47. // 'cus_id_no'=>'320124199003212387',
  48. // 'customer_mobile'=>'13348095647'
  49. // ];
  50. $orderInfo = $params['tickets_designs_default_value'];
  51. $data['orderInfo'] = $orderInfo;
  52. //传第一个ticket_id的票样设计信息
  53. $ticket_id_array = explode(',',$ticket_ids);
  54. $ticket_id = $ticket_id_array[0];
  55. $rst = $this->getTicketDsg($ticket_id);
  56. // if(count($rst) == 0){
  57. // $data['code'] = 0;
  58. // $data['info'] = $ticket_id.'没有票种设计信息';
  59. // }
  60. $data['firstTicketDesign'] = $rst;
  61. return $data;
  62. }
  63. /**
  64. * Function Description:根据ticket_id查询票种设计信息
  65. * Function Name: getTicketDsg
  66. * @param $ticket_id
  67. * @return array|\yii\db\ActiveRecord[]
  68. * @author 田玲菲
  69. */
  70. public function getTicketDsg($ticket_id){
  71. $operaTicketDesign = new OperaTicketsDesign();
  72. $result = $operaTicketDesign->getTicketDesign($ticket_id);
  73. return $result;
  74. }
  75. /**
  76. * Function Description:修改/新增票种设计信息
  77. * Function Name: saveTicketDesign
  78. * @param $ticket1_content
  79. * @param $ticket2_content
  80. * @param $ticket3_content
  81. * @param $ticket4_content
  82. * @param $bar_code_1
  83. * @param $bar_code_2
  84. * @param $bar_code_3
  85. * @param $bar_code_4
  86. * @param $ticket_id
  87. * @return array
  88. * @author 田玲菲
  89. */
  90. 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){
  91. $ticket_id = is_array($ticket_id)?$ticket_id:explode(',',$ticket_id);
  92. $data = [];
  93. $transaction = \Yii::$app->db->beginTransaction();
  94. try {
  95. //循环$ticket_id数组,每一个分别保存
  96. foreach($ticket_id as $v){
  97. //1判断是否存在票种设计信息
  98. $operaTicketsDesign = new OperaTicketsDesign();
  99. $res = $operaTicketsDesign->existTicketDesign($v);
  100. if($res){
  101. //2.如果存在,就update
  102. $result = $operaTicketsDesign->changeTicketDesign($ticket1_content,$ticket2_content,$ticket3_content,$ticket4_content,$bar_code_1,$bar_code_2,$bar_code_3,$bar_code_4,$v);
  103. }else{
  104. //3.如果不存在,就insert
  105. $result = $operaTicketsDesign->addTicketDesign($ticket1_content,$ticket2_content,$ticket3_content,$ticket4_content,$bar_code_1,$bar_code_2,$bar_code_3,$bar_code_4,$v);
  106. }
  107. if(!$result){
  108. $transaction->rollBack();
  109. $data['code']=1;
  110. $data['info']='操作失败';
  111. return $data;
  112. }
  113. }
  114. $transaction->commit();
  115. $data['code']=0;
  116. $data['info']='操作成功';
  117. return $data;
  118. } catch (Exception $e) {
  119. $transaction->rollBack();
  120. $data['code']=2;
  121. $data['info']='操作失败';
  122. return $data;
  123. }
  124. }
  125. /**
  126. * Function Description:模版替换,打印票的信息
  127. * Function Name: replaceTicketDesign
  128. * @param $order_ids
  129. * @return array
  130. * @author 田玲菲
  131. */
  132. public function replaceTicketDesign($order_ids){
  133. //1.根据order_ids查询子订单的prod_id(ticket_id),如果有不存在票种设计模版的,直接驳回打印票的信息
  134. $orderMain = new OrderMain();
  135. $result = $orderMain->getReplaceInfo($order_ids);
  136. $data = [];
  137. if(empty($result)){
  138. $data['code'] = 2;
  139. $data['info'] = '未查到相关数据';
  140. $data['data'] = $result;
  141. return $data;
  142. }
  143. $arr1 = array();
  144. foreach($result as $v){
  145. $operaTicketsDesign = new OperaTicketsDesign();
  146. if (!$operaTicketsDesign->existTicketDesign($v['prod_id'])){
  147. array_push($arr1,$v['order_id']);
  148. }
  149. }
  150. if(count($arr1)>0){
  151. $data['code'] = 1;
  152. $data['info'] = '订单号为'.json_encode($arr1).'的票样没有票样模版';
  153. return $data;
  154. }
  155. //2.如果都有设计模版,循环数组,取出该数组对应的设计模版,替换模版,然后给$v增加content
  156. foreach($result as &$v){
  157. $operaTicketsDesign = new OperaTicketsDesign();
  158. $replaceInfo = $operaTicketsDesign->getTicketDesign($v['prod_id']);
  159. $v['bar_code_1'] = $replaceInfo[0]['bar_code_1'];
  160. $v['bar_code_2'] = $replaceInfo[0]['bar_code_2'];
  161. $v['bar_code_3'] = $replaceInfo[0]['bar_code_3'];
  162. $v['bar_code_4'] = $replaceInfo[0]['bar_code_4'];
  163. $ticket1_content = $replaceInfo[0]['ticket1_content'];
  164. $ticket1_content = str_replace("{订单号}", $v['order_id'], $ticket1_content);
  165. $ticket1_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket1_content);
  166. $ticket1_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket1_content);
  167. $ticket1_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket1_content);
  168. $ticket1_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket1_content);
  169. $ticket1_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket1_content);
  170. $ticket1_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket1_content);
  171. $ticket1_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket1_content);
  172. $ticket1_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket1_content);
  173. $ticket1_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket1_content);
  174. $ticket1_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket1_content);
  175. $v['ticket1_content'] = $ticket1_content;
  176. $ticket2_content = $replaceInfo[0]['ticket2_content'];
  177. $ticket2_content = str_replace("{订单号}", $v['order_id'], $ticket2_content);
  178. $ticket2_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket2_content);
  179. $ticket2_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket2_content);
  180. $ticket2_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket2_content);
  181. $ticket2_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket2_content);
  182. $ticket2_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket2_content);
  183. $ticket2_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket2_content);
  184. $ticket2_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket2_content);
  185. $ticket2_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket2_content);
  186. $ticket2_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket2_content);
  187. $ticket2_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket2_content);
  188. $v['ticket2_content'] = $ticket2_content;
  189. $ticket3_content = $replaceInfo[0]['ticket3_content'];
  190. $ticket3_content = str_replace("{订单号}", $v['order_id'], $ticket3_content);
  191. $ticket3_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket3_content);
  192. $ticket3_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket3_content);
  193. $ticket3_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket3_content);
  194. $ticket3_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket3_content);
  195. $ticket3_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket3_content);
  196. $ticket3_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket3_content);
  197. $ticket3_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket3_content);
  198. $ticket3_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket3_content);
  199. $ticket3_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket3_content);
  200. $ticket3_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket3_content);
  201. $v['ticket3_content'] = $ticket3_content;
  202. $ticket4_content = $replaceInfo[0]['ticket4_content'];
  203. $ticket4_content = str_replace("{订单号}", $v['order_id'], $ticket4_content);
  204. $ticket4_content = str_replace("{出发地}", $v['prod_start_station_area_name'], $ticket4_content);
  205. $ticket4_content = str_replace("{上车站点}", $v['prod_start_station_res_name'], $ticket4_content);
  206. $ticket4_content = str_replace("{下车站点}", $v['prod_end_station_res_name'], $ticket4_content);
  207. $ticket4_content = str_replace("{目的地}", $v['prod_end_station_area_name'], $ticket4_content);
  208. $ticket4_content = str_replace("{出发日期}", $v['prod_start_station_date'], $ticket4_content);
  209. $ticket4_content = str_replace("{出发时间}", $v['prod_start_station_time'], $ticket4_content);
  210. $ticket4_content = str_replace("{乘客姓名}", $v['cus_name'], $ticket4_content);
  211. $ticket4_content = str_replace("{身份证号}", $v['cus_id_no'], $ticket4_content);
  212. $ticket4_content = str_replace("{乘客电话}", $v['customer_mobile'], $ticket4_content);
  213. $ticket4_content = str_replace("{座位号}", $v['run_bus_seat_name'], $ticket4_content);
  214. $v['ticket4_content'] = $ticket4_content;
  215. $v['ticket1_bar_code'] = $v['order_id'].'4';
  216. $v['ticket2_bar_code'] = $v['order_id'].'3';
  217. $v['ticket3_bar_code'] = $v['order_id'].'2';
  218. $v['ticket4_bar_code'] = $v['order_id'].'1';
  219. }
  220. $data['code'] = 0;
  221. $data['info'] = '获取成功';
  222. $data['data'] = $result;
  223. return $data;
  224. }
  225. }