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.

orderlist.php 16 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. $method = isset($_POST['method']) ? $_POST['method'] : "";
  10. $user_id = getUserId();
  11. //$user_id=1;
  12. if ($user_id == false) {
  13. echo json_encode(array("code" => "1", "info" => "用户未登录"));
  14. exit;
  15. }
  16. //$user_id=450;
  17. //取消订单原因
  18. if (isset($_POST['reason'])) {
  19. $reason = $_POST['reason'];
  20. $order_id = $_POST['order_id'];
  21. $clock = $_POST['clock'];
  22. // $return_data = array();
  23. // $return_data["code"] = 1;
  24. // $return_data["info"] = $reason;
  25. $pdo_insert = conn();
  26. $sql = "insert into order_comment(ORDER_ID,COMMENT_TXT,CREATE_TIME) VALUES ({$order_id},'{$reason}','{$clock}')";
  27. $result = $pdo_insert->exec($sql);
  28. }
  29. if ($method == "cancelOrder") {
  30. } else {
  31. $condition = array();
  32. $timelimit = isset($_POST['timelimit']) ? $_POST['timelimit'] : '';
  33. $starttime = isset($_POST['starttime']) ? $_POST['starttime'] : '';
  34. $endtime = isset($_POST['endtime']) ? $_POST['endtime'] : '';
  35. $ordersource = isset($_POST['ordersource']) ? $_POST['ordersource'] : 0;
  36. $typelimit = isset($_POST['typelimit']) ? $_POST['typelimit'] : '';
  37. $moresearch = isset($_POST['moresearch']) ? trim($_POST['moresearch']) : '';
  38. $orderstatus = isset($_POST['orderstatus']) ? $_POST['orderstatus'] : 0;
  39. if ($orderstatus) {
  40. $condition[] = " a.order_status =" . $orderstatus;
  41. }
  42. if ($timelimit == 0) {
  43. empty($starttime) ? null : $condition[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
  44. empty($endtime) ? null : $condition[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
  45. } elseif ($timelimit == 1) {
  46. empty($starttime) ? null : $condition[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
  47. empty($endtime) ? null : $condition[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
  48. }
  49. if ($ordersource == '-1') {
  50. } else {
  51. empty($ordersource) ? null : $condition[] = ' a.outside_sale_org_id = ' . $ordersource;
  52. }
  53. if ($typelimit == 1) {
  54. $condition[] = ' a.order_prod_type in (258,259,282,311)';
  55. } else {
  56. empty($typelimit) ? $condition[] = ' a.order_prod_type in (258,259)' : $condition[] = ' a.order_prod_type= ' . $typelimit;
  57. }
  58. 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 . '%"';
  59. $condition = implode(' AND ', $condition);
  60. //状态筛选环境
  61. $condition1 = array();
  62. if ($timelimit == 0) {
  63. empty($starttime) ? null : $condition1[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
  64. empty($endtime) ? null : $condition1[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
  65. } elseif ($timelimit == 1) {
  66. empty($starttime) ? null : $condition1[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
  67. empty($endtime) ? null : $condition1[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
  68. }
  69. if ($ordersource == '-1') {
  70. } else {
  71. empty($ordersource) ? null : $condition1[] = ' a.outside_sale_org_id = ' . $ordersource;
  72. }
  73. if ($typelimit == 1) {
  74. $condition1[] = ' a.order_prod_type in (258,259,282,311)';
  75. } else {
  76. empty($typelimit) ? $condition1[] = ' a.order_prod_type in (258,259)' : $condition1[] = ' a.order_prod_type= ' . $typelimit;
  77. }
  78. //2017.3.30 筛选条件新增当前用户运营主体
  79. $sql=''."select main_corp_id from base_user where id=$user_id limit 1";
  80. $user_corp_id=$pdo->query($sql);
  81. $rowset = $user_corp_id->fetchAll(PDO::FETCH_ASSOC);
  82. $main_corp_id=$rowset[0]['main_corp_id'];
  83. if($main_corp_id!=0){
  84. $sql=''."select group_concat(prod_id) as prod_arr from opera_product a where main_corp_id = $main_corp_id and parent_id=0 and cancel_flag=0";
  85. $result=$pdo->query($sql);
  86. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  87. $result=$rowset[0]['prod_arr'];
  88. $condition1[] = " a.prod_id in($result)";
  89. }
  90. $condition1 = implode(' AND ', $condition1);
  91. //结束
  92. $orderstatus = isset($_POST['orderstatus']) ? (empty($_POST['orderstatus']) ? 0 : $_POST['orderstatus']) : 0;
  93. $paystatus = isset($_POST['paystatus']) ? (empty($_POST['paystatus']) ? -1 : $_POST['paystatus']) : -1;
  94. $billingstatus = isset($_POST['billingstatus']) ? $_POST['billingstatus'] : '';
  95. $mealbounce = isset($_POST['mealbounce']) ? $_POST['mealbounce'] : '';
  96. $refund = isset($_POST['refund']) ? $_POST['refund'] : '';
  97. $export = isset($_POST['export']) ? $_POST['export'] : '';
  98. //2016-07-15新增
  99. $start_area = isset($_POST['start_area']) ? $_POST['start_area'] : '';
  100. $end_area = isset($_POST['end_area']) ? $_POST['end_area'] : '';
  101. $line = isset($_POST['line']) ? $_POST['line'] : '';
  102. //..暂未加入存储过程
  103. $currpage = isset($_POST['currpage']) ? (empty($_POST['currpage']) ? 1 : $_POST['currpage']) : 1;
  104. $pagesize = isset($_POST['pagesize']) ? (empty($_POST['pagesize']) ? 10 : $_POST['pagesize']) : 10;
  105. $pdo = conn();
  106. // $sql = "select count(*) as will from order_main as a where a.order_status=145 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . ";
  107. // select count(order_id) as pay from order_main as a where a.order_status=146 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . ";
  108. // select count(order_id) as over from order_main as a where a.order_status=147 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . ";
  109. // select count(order_id) as cancel from order_main as a where a.order_status=148 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1;
  110. //
  111. $sql = "select a.order_status, count(a.order_id) as order_num from order_main as a where a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . " group by a.order_status ";
  112. $result = $pdo->query($sql);
  113. writeLog("--des_order_list:" . __LINE__ . "|" . $sql);
  114. $data_count_list = array("will" => 0, "pay" => 0, "over" => "0", "cancel" => 0);
  115. // $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  116. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  117. $result->closeCursor();
  118. foreach ($rowset as $row_info) {
  119. switch ($row_info["order_status"]) {
  120. case 145:
  121. $row_index = "will";
  122. break;
  123. case 146:
  124. $row_index = "pay";
  125. break;
  126. case 147:
  127. $row_index = "over";
  128. break;
  129. case 148:
  130. $row_index = "cancel";
  131. break;
  132. default:
  133. $row_index = "will";
  134. break;
  135. }
  136. $data_count_list[$row_index] = $row_info["order_num"];
  137. }
  138. if ($condition2 != 1) {
  139. $condition2 = " where " . $condition2 . " AND " . $condition1;
  140. } else {
  141. $condition2 = " where " . $condition1;
  142. }
  143. $sql = "select a.order_id "
  144. . "from order_main as a "
  145. . $condition2;
  146. //echo $sql;die;
  147. $result = $pdo->query($sql);
  148. $json22 = array();
  149. do {
  150. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  151. if ($rowset) {
  152. $json22 = $rowset;
  153. }
  154. } while ($result->nextRowset());
  155. if (empty($json22)) {
  156. $data = (array("code" => "1", "info" => "此条件下没有订单", "list_count" => 0, "searchInfo" => array()));
  157. echo json_encode($data);
  158. die;
  159. }
  160. foreach ($json22 as $v) {
  161. $arr_o[] = $v['order_id'];
  162. }
  163. $arr_o = implode(',', $arr_o);
  164. $sql_org = "select org_id,org_name from base_organization ";
  165. $result_org = $pdo->query($sql_org);
  166. $org_list = $result_org->fetchAll(PDO::FETCH_ASSOC);
  167. $o_list = array();
  168. foreach ($org_list as $v) {
  169. $o_list[$v['org_id']] = array('org_name' => $v['org_name'], 'org_id' => $v['org_id']);
  170. }
  171. //3-28新增查询退款截止日期,退款截止时间--娄梦宁
  172. $sql = "select b.refund_limit_time,b.refund_limit_day,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 "
  173. . "from order_main as a left join opera_product as b on a.prod_id=b.prod_id "
  174. . "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";
  175. $result = $pdo->query($sql);
  176. if (false != $result) {
  177. $json = array();
  178. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  179. if ($rowset) {
  180. $json = $rowset;
  181. }
  182. $result->closeCursor();
  183. }
  184. if (empty($json)) {
  185. $data = (array("code" => "1", "info" => '此条件下没有订单', "list_count" => 0, "searchInfo" => array()));
  186. echo json_encode($data);
  187. die;
  188. }
  189. //获取销售渠道信息
  190. $json_id = array();
  191. foreach ($json as $v) {
  192. $json_id[] = $v['order_id'];
  193. $json2[] = $v['order_id'];
  194. $org[$v['order_id']] = $v['main_create_user_id'];
  195. if ($v['outside_sale_org_id'] == 0 || !isset($o_list[$v['outside_sale_org_id']])) {
  196. $v['org_name'] = 'CS平台下单';
  197. } else {
  198. $v['org_name'] = $o_list[$v['outside_sale_org_id']]["org_name"];
  199. }
  200. $org_name[$v['order_id']] = $v['org_name'];
  201. $outside_order_no[$v['order_id']] = $v['outside_order_no'];
  202. $order_info[$v['order_id']] = $v; //价格手机 姓名 run_time pay_time
  203. }
  204. $array_order_desc = array();
  205. foreach ($order_info as $v) {
  206. $arr_temp = explode('|', $v['order_description']);
  207. $arr = array();
  208. foreach ($arr_temp as $k => $v2) {
  209. if (!empty($v2))
  210. $arr[] = explode(',', $v2);
  211. }
  212. $array_order_desc[$v['order_id']] = $arr;
  213. }
  214. //var_dump($array_order_desc);die;
  215. $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 "
  216. . "from order_main "
  217. . "where parent_order_id in (" . implode(",", $json_id) . ")";
  218. $result3 = $pdo->query($sql3);
  219. $rowset3 = $result3->fetchAll(PDO::FETCH_ASSOC);
  220. foreach ($rowset3 as $v) {
  221. $station[$v['parent_order_id']] = $v;//上车站下车站 详情
  222. }
  223. //获取支付方式
  224. $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)
  225. left join dict_type c on c.id=b.PAY_TYPE_ID_1 "
  226. . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
  227. $result2 = $pdo->query($sql2);
  228. do {
  229. $rowset2 = $result2->fetchAll(PDO::FETCH_ASSOC);
  230. if ($rowset2) {
  231. $pay_type[] = $rowset2;
  232. }
  233. } while ($result2->nextRowset());
  234. foreach ($pay_type[0] as $v) {
  235. $pay_type_arr[$v['ORDER_ID']] = $v['TYPE_NAME']; //支付方式
  236. }
  237. //支付状态
  238. $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)
  239. left join dict_type c on c.id=a.ORDER_STATUS "
  240. . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
  241. $result4 = $pdo->query($sql4);
  242. do {
  243. $rowset4 = $result4->fetchAll(PDO::FETCH_ASSOC);
  244. if ($rowset4) {
  245. $order_sta[] = $rowset4;
  246. }
  247. } while ($result4->nextRowset());
  248. foreach ($order_sta[0] as $v) {
  249. $order_status[$v['ORDER_ID']] = $v['TYPE_NAME']; //订单的状态
  250. }
  251. $array_order_list = array();
  252. //echo count($pay_type_arr),'--', count($json_id);
  253. //var_dump($array_order_desc);die;
  254. foreach ($json_id as $v) {
  255. $tic = '';
  256. $product_info = array();
  257. if ($order_info[$v]['order_prod_type'] == 258 || $order_info[$v]['order_prod_type'] == 259) {
  258. foreach ($array_order_desc[$v] as $v1) {
  259. $tic .= str_replace('迪士尼剧场', '', $v1[0]) . '×' . $v1[2] . ' ';
  260. if (isset($v1['ifback']))
  261. $ifback = $v1['ifback'];
  262. }
  263. $product_info = $order_info[$v]['prod_name'] . '<br> ' . $tic;
  264. $ifdisn = 0;
  265. } elseif ($order_info[$v]['order_prod_type'] == 282) {
  266. foreach ($array_order_desc[$v] as $v1) {
  267. $tic .= str_replace('周庄门票', '', $v1[0]) . '×' . $v1[2] . ' ';
  268. if (isset($v1['ifback']))
  269. $ifback = $v1['ifback'];
  270. }
  271. $product_info = $order_info[$v]['prod_name'] . '' . $tic;
  272. if ($order_info[$v]['run_date'] <= date('Y-m-d', time()) || $order_info[$v]['order_status'] != 146) {
  273. $ifdisn = 0;
  274. } else {
  275. $ifdisn = 1;
  276. }
  277. } else {//不是周庄也不是迪士尼--娄梦宁
  278. foreach ($array_order_desc[$v] as $ky=>$v1) {
  279. $num=count($array_order_desc[$v]);
  280. if($ky!=($num-1)){
  281. $tic .=$v1[0].'×' . $v1[2] . ' ';
  282. }
  283. if (isset($v1['ifback']))
  284. $ifback = $v1['ifback'];
  285. }
  286. $product_info = $order_info[$v]['prod_name'] . '<br> ' . $tic;
  287. //下面这句判断是否可退票
  288. $time1='-'.$order_info[$v]['refund_limit_day'].' day';
  289. $time2=$order_info[$v]['run_date'].' '.$order_info[$v]['refund_limit_time'];
  290. $refund_time=strtotime($time1,strtotime($time2));
  291. if (time()>$refund_time|| $order_info[$v]['order_status'] != 146) {
  292. $ifdisn = 0;
  293. } else {
  294. $ifdisn = 1;
  295. }
  296. }
  297. if ($product_info != array()) {
  298. $array_order_list[] = array(
  299. 'order_id' => $v,
  300. 'create_time' => $order_info[$v]['create_time'],
  301. 'org_name' => $org_name[$v],
  302. 'product_info' => $product_info,
  303. 'outside_order_no' => $outside_order_no[$v],
  304. 'ifdisney' => $ifdisn,
  305. 'ifzhouzhuang' => $ifdisn,
  306. 'run_time' => $station[$v]['run_date'] . ' ' . $station[$v]['run_time'],
  307. 'customer_info' => $order_info[$v]['customer_name'] . ' <br>' . $order_info[$v]['customer_mobile'] . '<br> ' . $order_info[$v]['customer_id_no'],
  308. 'order_pay' => $order_info[$v]['order_price'],
  309. 'customer_memo' => $order_info[$v]['customer_memo'],
  310. 'order_pay_type' => $pay_type_arr[$v],
  311. 'order_status' => $order_status[$v],
  312. );
  313. }
  314. }
  315. $list_count = count($array_order_list);
  316. //echo $list_count;
  317. $sta = ($currpage - 1) * ($pagesize + 0);
  318. $array_order_list = array_slice($array_order_list, $sta, $pagesize);
  319. $data = (array("code" => "0", "info" => "", "list_count" => $list_count, "searchInfo" => $array_order_list));
  320. if (1) {
  321. $json = array("code" => "0", "info" => "");
  322. $json['list_count'] = $list_count;
  323. $json['totalTickets'] = $list_count;
  324. $json['totalPages'] = ceil($list_count / $pagesize);
  325. $json['currentpage'] = $currpage;
  326. $json['pagesize'] = $pagesize;
  327. $json['orderSource'] = $o_list;//销售渠道
  328. $json['orderList'] = $array_order_list; //订单详情
  329. $json['count_list'] = isset($data_count_list) ? $data_count_list : array();
  330. echo json_encode($json);
  331. die;
  332. } else {
  333. echo json_encode(array("code" => "0", "info" => "", "searchInfo" => array()));
  334. }
  335. }
  336. echo json_encode(array("code" => "1", "info" => "出现一些错误", "searchInfo" => array()));
  337. die;