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.

export.php 12 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:Spiders Travel
  5. */
  6. require_once '../../Common/Mysql.php';
  7. if (ALLOW_ORIGIN)
  8. header("Access-Control-Allow-Origin:*");
  9. $condition = array();
  10. $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '';
  11. $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : '';
  12. $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : '';
  13. $ordersource = isset($_GET['ordersource']) ? $_GET['ordersource'] : 0;
  14. $typelimit = isset($_GET['typelimit']) ? $_GET['typelimit'] : '';
  15. $moresearch = isset($_GET['moresearch']) ? trim($_GET['moresearch']) : '';
  16. $orderstatus = isset($_GET['orderstatus']) ? $_GET['orderstatus'] : 0;
  17. if ($orderstatus) {
  18. $condition[] = " a.order_status =" . $orderstatus;
  19. }
  20. if ($timelimit == 0) {
  21. empty($starttime) ? null : $condition[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
  22. empty($endtime) ? null : $condition[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
  23. } elseif ($timelimit == 1) {
  24. empty($starttime) ? null : $condition[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
  25. empty($endtime) ? null : $condition[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
  26. }
  27. if ($ordersource == '-1') {
  28. } else {
  29. empty($ordersource) ? null : $condition[] = ' a.outside_sale_org_id = ' . $ordersource;
  30. }
  31. if ($typelimit == 1) {
  32. $condition[] = ' a.order_prod_type in (258,259,282,311)';
  33. } else {
  34. empty($typelimit) ? $condition[] = ' a.order_prod_type in (258,259)' : $condition[] = ' a.order_prod_type= ' . $typelimit;
  35. }
  36. empty($moresearch) ? $condition2 = 1 : $condition2 = ' a.order_id like "%' . $moresearch . '%" or a.customer_name like "%' . $moresearch . '%" or a.customer_mobile like "%' . $moresearch . '%" or a.outside_order_no like "%' . $moresearch . '%"';
  37. $condition = implode(' AND ', $condition);
  38. //状态筛选环境
  39. $condition1 = array();
  40. if ($timelimit == 0) {
  41. empty($starttime) ? null : $condition1[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
  42. empty($endtime) ? null : $condition1[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
  43. } elseif ($timelimit == 1) {
  44. empty($starttime) ? null : $condition1[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
  45. empty($endtime) ? null : $condition1[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
  46. }
  47. if ($ordersource == '-1') {
  48. } else {
  49. empty($ordersource) ? null : $condition1[] = ' a.org_id = ' . $ordersource;
  50. }
  51. if ($typelimit == 1) {
  52. $condition1[] = ' a.order_prod_type in (258,259,282,311)';
  53. } else {
  54. empty($typelimit) ? $condition1[] = ' a.order_prod_type in (258,259)' : $condition1[] = ' a.order_prod_type= ' . $typelimit;
  55. }
  56. $condition1 = implode(' AND ', $condition1);
  57. //结束
  58. $orderstatus = isset($_POST['orderstatus']) ? (empty($_POST['orderstatus']) ? 0 : $_POST['orderstatus']) : 0;
  59. $paystatus = isset($_POST['paystatus']) ? (empty($_POST['paystatus']) ? -1 : $_POST['paystatus']) : -1;
  60. $billingstatus = isset($_POST['billingstatus']) ? $_POST['billingstatus'] : '';
  61. $mealbounce = isset($_POST['mealbounce']) ? $_POST['mealbounce'] : '';
  62. $refund = isset($_POST['refund']) ? $_POST['refund'] : '';
  63. $export = isset($_POST['export']) ? $_POST['export'] : '';
  64. //2016-07-15新增
  65. $start_area = isset($_POST['start_area']) ? $_POST['start_area'] : '';
  66. $end_area = isset($_POST['end_area']) ? $_POST['end_area'] : '';
  67. $line = isset($_POST['line']) ? $_POST['line'] : '';
  68. //..暂未加入存储过程
  69. $currpage = 1;
  70. $pagesize = 100000;
  71. $pdo = conn();
  72. if ($condition2 != 1) {
  73. $condition2 = " where " . $condition2." AND ".$condition1;
  74. } else {
  75. $condition2 = " where ".$condition1;
  76. }
  77. $sql = "select a.order_id "
  78. . "from order_main as a "
  79. . $condition2;
  80. //echo $sql;die;
  81. $result = $pdo->query($sql);
  82. $json22 = array();
  83. do {
  84. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  85. if ($rowset) {
  86. $json22 = $rowset;
  87. }
  88. } while ($result->nextRowset());
  89. if (empty($json22)) {
  90. die;
  91. }
  92. foreach ($json22 as $v) {
  93. $arr_o[] = $v['order_id'];
  94. }
  95. $arr_o = implode(',', $arr_o);
  96. $sql_org = "select org_id,org_name from base_organization ";
  97. $result_org = $pdo->query($sql_org);
  98. $org_list = $result_org->fetchAll(PDO::FETCH_ASSOC);
  99. $o_list = array();
  100. foreach ($org_list as $v) {
  101. $o_list[$v['org_id']] = array('org_name' => $v['org_name'], 'org_id' => $v['org_id']);
  102. }
  103. $sql = "select a.prod_name,a.order_prod_type,a.order_description,a.run_date,a.ORDER_PAY_MAIN_ID,a.order_id,a.customer_name,a.customer_mobile,a.customer_id_type,a.customer_id_no,a.order_price,a.order_status,a.create_time,a.prod_id,a.customer_memo,a.main_create_user_id,a.outside_sale_org_id,a.outside_order_no "
  104. . "from order_main as a "
  105. . "where a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and a.order_id in (" . $arr_o . ") AND " . $condition. " order by a.create_time desc";
  106. $result = $pdo->query($sql);
  107. if( false != $result ) {
  108. $json = array();
  109. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  110. if ($rowset) {
  111. $json = $rowset;
  112. }
  113. $result->closeCursor();
  114. }
  115. if (empty($json)) {
  116. die;
  117. }
  118. //获取销售渠道信息
  119. $json_id = array();
  120. foreach ($json as $v) {
  121. $json_id[] = $v['order_id'];
  122. $json2[] = $v['order_id'];
  123. $org[$v['order_id']] = $v['main_create_user_id'];
  124. if ( $v['outside_sale_org_id'] == 0 || !isset($o_list[$v['outside_sale_org_id']])) {
  125. $v['org_name'] = 'CS平台下单';
  126. } else {
  127. $v['org_name'] = $o_list[$v['outside_sale_org_id']]["org_name"];
  128. }
  129. $org_name[$v['order_id']] = $v['org_name'];
  130. $outside_order_no[$v['order_id']] = $v['outside_order_no'];
  131. $order_info[$v['order_id']] = $v; //价格手机 姓名 run_time pay_time
  132. }
  133. $array_order_desc = array();
  134. foreach ($order_info as $v) {
  135. $arr_temp = explode('|', $v['order_description']);
  136. $arr = array();
  137. foreach ($arr_temp as $k => $v2) {
  138. if (!empty($v2))
  139. $arr[] = explode(',', $v2);
  140. }
  141. $array_order_desc[$v['order_id']] = $arr;
  142. }
  143. //var_dump($array_order_desc);die;
  144. $sql3 = "select parent_order_id,run_date,run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME "
  145. . "from order_main "
  146. . "where parent_order_id in (" . implode(",", $json_id) . ")";
  147. $result3 = $pdo->query($sql3);
  148. $rowset3 = $result3->fetchAll(PDO::FETCH_ASSOC);
  149. foreach ($rowset3 as $v) {
  150. $station[$v['parent_order_id']] = $v;//上车站下车站 详情
  151. }
  152. //获取支付方式
  153. $sql2 = "select a.ORDER_ID,b.PAY_TYPE_ID_1,c.TYPE_NAME from (ORDER_MAIN a left join ORDER_PAY_DETAIL b on a.ORDER_PAY_MAIN_ID=b.pay_main_id)
  154. left join dict_type c on c.id=b.PAY_TYPE_ID_1 "
  155. . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
  156. $result2 = $pdo->query($sql2);
  157. do {
  158. $rowset2 = $result2->fetchAll(PDO::FETCH_ASSOC);
  159. if ($rowset2) {
  160. $pay_type[] = $rowset2;
  161. }
  162. } while ($result2->nextRowset());
  163. foreach ($pay_type[0] as $v) {
  164. $pay_type_arr[$v['ORDER_ID']] = $v['TYPE_NAME']; //支付方式
  165. }
  166. //支付状态
  167. $sql4 = "select a.ORDER_ID,a.order_status,c.TYPE_NAME from (ORDER_MAIN a left join ORDER_PAY_DETAIL b on a.ORDER_PAY_MAIN_ID=b.pay_main_id)
  168. left join dict_type c on c.id=a.ORDER_STATUS "
  169. . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
  170. $result4 = $pdo->query($sql4);
  171. do {
  172. $rowset4 = $result4->fetchAll(PDO::FETCH_ASSOC);
  173. if ($rowset4) {
  174. $order_sta[] = $rowset4;
  175. }
  176. } while ($result4->nextRowset());
  177. foreach ($order_sta[0] as $v) {
  178. $order_status[$v['ORDER_ID']] = $v['TYPE_NAME']; //订单的状态
  179. }
  180. $array_order_list = array();
  181. //echo count($pay_type_arr),'--', count($json_id);
  182. //var_dump($array_order_desc);die;
  183. foreach ($json_id as $v) {
  184. $tic = '';
  185. if ($order_info[$v]['order_prod_type'] == 258 || $order_info[$v]['order_prod_type'] == 259) {
  186. foreach ($array_order_desc[$v] as $v1) {
  187. $tic .= str_replace('迪士尼剧场', '', $v1[0]) . '×' . $v1[2] . ' ';
  188. if (isset($v1['ifback']))
  189. $ifback = $v1['ifback'];
  190. }
  191. $product_info = $order_info[$v]['prod_name'] . "\r\n" . $tic;
  192. $ifdisn = 0;
  193. } elseif ($order_info[$v]['order_prod_type'] == 282) {
  194. foreach ($array_order_desc[$v] as $v1) {
  195. if( !isset($v1[0]) || !isset($v1[2]) || strlen($v1[2]) <= 0 ) { break;}
  196. $tic .= str_replace('周庄门票', '', $v1[0]) . '×' . $v1[2] . ' ';
  197. if (isset($v1['ifback']))
  198. $ifback = $v1['ifback'];
  199. }
  200. $product_info = $order_info[$v]['prod_name'] . '' . $tic;
  201. if ($order_info[$v]['run_date'] <= date('Y-m-d', time()) || $order_info[$v]['order_status'] != 146) {
  202. $ifdisn = 0;
  203. } else {
  204. $ifdisn = 1;
  205. }
  206. } else {
  207. foreach ($array_order_desc[$v] as $v1) {
  208. $tic .= $v1[0] . '×' . $v1[2] . ' ';
  209. if (isset($v1['ifback']))
  210. $ifback = $v1['ifback'];
  211. }
  212. $product_info = $order_info[$v]['prod_name'] . '' . $tic;
  213. if ($order_info[$v]['run_date'] <= date('Y-m-d', time()) || $order_info[$v]['order_status'] != 146) {
  214. $ifdisn = 0;
  215. } else {
  216. $ifdisn = 1;
  217. }
  218. }
  219. $array_order_list[] = array(
  220. 'order_id' => $v,
  221. 'create_time' => $order_info[$v]['create_time'],
  222. 'org_name' => $org_name[$v],
  223. 'product_info' => $product_info,
  224. 'outside_order_no' => $outside_order_no[$v],
  225. 'ifdisney' => $ifdisn,
  226. 'ifzhouzhuang' => $ifdisn,
  227. 'run_time' => $station[$v]['run_date'] . ' ' . $station[$v]['run_time'],
  228. 'customer_info' => $order_info[$v]['customer_name'] . "\r\n" . $order_info[$v]['customer_mobile'] . "\r\n" . $order_info[$v]['customer_id_no'],
  229. 'order_pay' => $order_info[$v]['order_price'],
  230. 'customer_memo' => $order_info[$v]['customer_memo'],
  231. 'order_pay_type' => $pay_type_arr[$v],
  232. 'order_status' => $order_status[$v],
  233. );
  234. }
  235. $str = "订单编号,预订时间,订单渠道,预订产品,支付金额,出发时间, 联系人,状态,支付方式,备注" . "\n";
  236. foreach( $array_order_list as $order_info_temp) {
  237. $str .= "{$order_info_temp["order_id"]},{$order_info_temp["create_time"]},\"{$order_info_temp["org_name"]}\",\"{$order_info_temp["product_info"]}\",\"{$order_info_temp["order_pay"]}\",\"{$order_info_temp["run_time"]}\",\"{$order_info_temp["customer_info"]}\",\"{$order_info_temp["order_status"]}\",\"{$order_info_temp["order_pay_type"]}\",\"{$order_info_temp["customer_memo"]}\"" . "\n";
  238. }
  239. //设置文件名
  240. $filename = date('Ymd') . '.csv';
  241. //echo $str;
  242. export_csv($filename, $str);
  243. //导出
  244. function export_csv($filename, $data) {
  245. header("Content-type:text/csv");
  246. header("Content-Disposition:attachment;filename=门票订单" . $filename);
  247. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  248. header('Expires:0');
  249. header('Pragma:public');
  250. $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data;
  251. // $data = iconv("utf-8","gb2312",$data);
  252. writeLog('export success');
  253. echo $data;
  254. }