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.

make_hotel_order.js 21 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /**
  2. * Created by luocj on 2016/12/6.
  3. */
  4. // var start_date = '';
  5. // var end_date = '';
  6. // var hotel_id = '';
  7. // var room_type = '';
  8. // var org_id = '';
  9. var hotel_name = getPar('hotel_name');
  10. var product_name = getPar('product_name');
  11. var hotel_id = getPar('hotel_id');
  12. var parent_room_type = getPar('parent_type'); //基础房型
  13. var room_type = getPar('room_type');
  14. var start_date = '';
  15. var end_date = '';
  16. // var start_date = '2016-12-05';
  17. // var end_date = '2016-12-08';
  18. // var hotel_id = 294;
  19. // var room_type = 1;
  20. // var org_id = 4;
  21. //总佣金,总结算,总利润
  22. var all_yongj = 0;
  23. var all_jiesuan = 0;
  24. var all_profit = 0;
  25. //得到替换行
  26. var tr = $('.tr_str').prop('outerHTML');
  27. window.onload = function () {
  28. $('#hotel_name').text(hotel_name);
  29. $('#product_name').text(product_name);
  30. //初始时间不需要给默认值
  31. // $("#start_date").val(getDateTime(0));
  32. // $("#end_date").val(after(getDateTime(0)));
  33. // start_date = $('#start_date').val();
  34. // end_date = $('#end_date').val();
  35. //获取渠道
  36. getOrgList();
  37. // //获取可下订单
  38. // getRoomStock();
  39. //最晚到店时间
  40. getTimeList();
  41. };
  42. // 获取渠道
  43. function getOrgList() {
  44. var url = base_api + "?type=order_MakeHTOrder&op=org_list";
  45. $.getJSON(url, function (data) {
  46. ZZLog(data);
  47. if (data['code'] != "0") {
  48. alert(data['info']);
  49. } else {
  50. var outHTML = '<option selected=selected id=0 value="0" style=font-size: 12px;>请选择</option>';
  51. org_list = data['org_list'];
  52. for (var i = 0; i < org_list.length; i++) {
  53. var HTML = '<option id=0>请选择</option>';
  54. var dict = org_list[i];
  55. HTML = HTML.replace('请选择', dict['org_name']);
  56. HTML = HTML.replace("id=0", "id=" + dict['org_id'] + " value=" + dict['org_id']);
  57. outHTML += HTML
  58. }
  59. $('#org_id').html(outHTML);
  60. $('.select_line').comboSelect();
  61. }
  62. })
  63. }
  64. //获取可下库存
  65. function getRoomStock() {
  66. var url = base_api + "?type=order_MakeHTOrder&op=order_list&hotel_id=" + hotel_id + "&room_type=" + room_type + "&parent_room_type=" + parent_room_type + "&org_id=" + org_id + "&start_date=" + start_date + "&end_date=" + end_date;
  67. // ZZLog(url);
  68. $.getJSON(url, function (data) {
  69. ZZLog(data);
  70. if (data['code'] != 0) {
  71. ZZAlertInfo(data['info'], function () {
  72. return;
  73. });
  74. } else {
  75. setDataHTML(data)
  76. }
  77. }).error(function (data) {
  78. })
  79. }
  80. //页面数据替换
  81. function setDataHTML(data) {
  82. var sumHTML = '';
  83. for (var i = 0; i < data['order_list'][0].length; i++) {
  84. var dict = data['order_list'][0][i];
  85. var HTML = tr;
  86. //替换入住日期
  87. HTML = HTML.replace('[入住日期]', dict['run_date']);
  88. //end 替换入住日期
  89. //替换数量
  90. //得到替换数量,逻辑:先判断超售oversell_flag,1为可以超售,如果可以超售则取data['order_list'][1]中的该天所有库存,超了不能下单。
  91. var count = 0;
  92. if (dict['oversell_flag'] == 1 && dict['remaining_count'] != -1) {
  93. for (var j = 0; j < data['order_list'][1].length; j++) {
  94. var dict1 = data['order_list'][1][j];
  95. if (dict['run_date'] == dict1['run_date']) {
  96. count += parseInt(dict1['remaining_count']);
  97. // ZZLog(dict1);
  98. //将调用超售库存的信息放入data-json-baoliu,maiduan,xianxun
  99. if (dict1['stock_type'] == '228') {//买断
  100. HTML = HTML.replace('[data-json-maiduan]', setJsonHtml(dict1))
  101. } else if (dict1['stock_type'] == '229') {//现询
  102. HTML = HTML.replace('[data-json-xianxun]', setJsonHtml(dict1))
  103. } else if (dict1['stock_type'] == '230') {//保留
  104. HTML = HTML.replace('[data-json-baoliu]', setJsonHtml(dict1))
  105. } else {
  106. ZZAlertInfo('没有该库存类型');
  107. }
  108. }
  109. }
  110. } else {
  111. for (var j = 0; j < data['order_list'][1].length; j++) {
  112. var dict1 = data['order_list'][1][j];
  113. if (dict['run_date'] == dict1['run_date']) {
  114. // ZZLog(dict1);
  115. //将调用超售库存的信息放入data-json-baoliu,maiduan,xianxun
  116. if (dict1['stock_type'] == '228') {//买断
  117. HTML = HTML.replace('[data-json-maiduan]', setJsonHtml(dict1))
  118. } else if (dict1['stock_type'] == '229') {//现询
  119. HTML = HTML.replace('[data-json-xianxun]', setJsonHtml(dict1))
  120. } else if (dict1['stock_type'] == '230') {//保留
  121. HTML = HTML.replace('[data-json-baoliu]', setJsonHtml(dict1))
  122. } else {
  123. ZZAlertInfo('没有该库存类型');
  124. }
  125. }
  126. }
  127. count = parseInt(dict['remaining_count'] == -1 ? 0 : dict['remaining_count'])
  128. }
  129. // ZZLog(count);
  130. //end 得到替换数量
  131. //循环替换数量
  132. var selHTML = '<select onchange="changeCount(this)" class="prod_count" style="width: 40px">';
  133. for (var m = 0; m <= count; m++) {
  134. if (m > 20) {
  135. break;
  136. }
  137. var temp = "<option value='" + m + "'>" + m + "</option>";
  138. selHTML += temp;
  139. }
  140. selHTML += '</select>';
  141. HTML = HTML.replace('[数量]', selHTML);
  142. //end 替换数量
  143. //结算价替换
  144. HTML = HTML.replace('[结算价]', '<input type="text" oninput="changeCount(this)" class="prod_price" style="width: 60px" value="' + dict['price'] + '">')
  145. //end 结算价替换
  146. //佣金规则
  147. var ling = 0;
  148. var ling1 = ling.toFixed(2);
  149. if (dict['commision_flag'] == 0) {//为0不返佣,为1返佣
  150. HTML = HTML.replace('[佣金]', '-');
  151. } else {
  152. HTML = HTML.replace('[佣金]', ling1);
  153. }
  154. //end 佣金规则
  155. HTML = HTML.replace('[结算价总额]', ling1);
  156. HTML = HTML.replace('[销售利润]', ling1);
  157. //将非超卖库存存入data-json
  158. HTML = HTML.replace('[data-json]', setJsonHtml(dict));
  159. sumHTML += HTML
  160. }
  161. $('#make_order_list').html(sumHTML);
  162. if (sumHTML) {
  163. $('#make_table').show();
  164. } else {
  165. $('#make_table').hide();
  166. }
  167. //刷新总计
  168. all_sum();
  169. }
  170. //数量与结算单价改变对应的渠道佣金,结算总价,销售利润的变化
  171. function changeCount(obj) {
  172. // 房间数量
  173. var room_count = $(obj).closest('tr').find('.prod_count').val();
  174. // 结算单价
  175. var room_price = $(obj).closest('tr').find('.prod_price').val();
  176. // 佣金规则
  177. var dict = getJsonHtml($(obj).closest('tr').attr('data-json'));
  178. var dict_maiduan = getJsonHtml($(obj).closest('tr').attr('data-json-maiduan'));
  179. var dict_baoliu = getJsonHtml($(obj).closest('tr').attr('data-json-baoliu'));
  180. var dict_xianxun = getJsonHtml($(obj).closest('tr').attr('data-json-xianxun'));
  181. var commision_price = 0;
  182. if (dict['commision_flag'] == '1') {//有佣金规则
  183. if (dict['back_commision_method'] == '309') {//308 按销售金额309 按结算金额
  184. commision_price = dict['back_value']
  185. } else if (dict['back_commision_method'] == '308') {
  186. commision_price = room_count * room_price * parseFloat(dict['back_percent']) / 100;
  187. }
  188. } else {//无佣金规则
  189. commision_price = 0;
  190. }
  191. //end 佣金规则
  192. //结算总价
  193. var jiesuan_price = room_count * room_price;
  194. //end 结算总价
  195. //库存类型与成本
  196. var maiduan_count = dict_maiduan['remaining_count'] ? dict_maiduan['remaining_count'] : 0;
  197. var baoliu_count = dict_baoliu['remaining_count'] ? dict_baoliu['remaining_count'] : 0;
  198. var xianxun_count = dict_xianxun['remaining_count'] ? dict_xianxun['remaining_count'] : 0;
  199. var maiduan_price = dict_maiduan['cost_price'] ? dict_maiduan['cost_price'] : 0;
  200. var baoliu_price = dict_baoliu['cost_price'] ? dict_baoliu['cost_price'] : 0;
  201. var xianxun_price = dict_xianxun['cost_price'] ? dict_xianxun['cost_price'] : 0;
  202. //end 库存类型与成本
  203. //销售利润
  204. var profit = 0;
  205. if (parseInt(room_count) <= parseInt(maiduan_count)) {//所选房间数小于等于买断数
  206. profit = jiesuan_price - commision_price - maiduan_price * room_count
  207. } else if (parseInt(room_count) > parseInt(maiduan_count) && parseInt(room_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count))) { //所选房间数大于买断数,小于等于保留数+买断数
  208. profit = jiesuan_price - commision_price - maiduan_price * maiduan_count - baoliu_price * (room_count - maiduan_count)
  209. } else if (parseInt(room_count) > (parseInt(maiduan_count) + parseInt(baoliu_count)) && parseInt(room_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count) + parseInt(xianxun_count))) {
  210. profit = jiesuan_price - commision_price - maiduan_price * maiduan_count - baoliu_price * baoliu_count - xianxun_price * (room_count - maiduan_count - baoliu_count)
  211. }
  212. //end 销售利润
  213. //佣金显示
  214. var commision_price1 = parseFloat(commision_price).toFixed(2);
  215. if (dict['commision_flag'] == 1) {
  216. $(obj).closest('tr').find('.yongj_sum').text(commision_price1);
  217. } else {
  218. $(obj).closest('tr').find('.yongj_sum').text('-');
  219. }
  220. //结算总价显示
  221. var jiesuan_price1 = parseFloat(jiesuan_price).toFixed(2);
  222. if (jiesuan_price1) {
  223. $(obj).closest('tr').children().eq(4).text(jiesuan_price1);
  224. }
  225. //销售利润显示
  226. var profit1 = parseFloat(profit).toFixed(2);
  227. if (profit1) {
  228. $(obj).closest('tr').children().eq(5).text(profit1);
  229. }
  230. //总计
  231. all_sum();
  232. }
  233. // 获取1至23小时
  234. function getTimeList() {
  235. var outHTML = '<option selected="selected" value="-1">请选择</option>'
  236. for (var i = 1; i <= 23; i++) {
  237. var HTML = '<option>24:00</option>';
  238. var time = i;
  239. HTML = HTML.replace('<option>24:00</option>', '<option selected="selected" value=' + i + ':00>' + i + ':00</option>');
  240. outHTML += HTML
  241. }
  242. $('#time').html(outHTML);
  243. }
  244. //获取时差并获取相应时间的订单
  245. function timeDiff() {
  246. var start = $("#start_date").val();
  247. var end = $("#end_date").val();
  248. start = start.replace(/-/g, "/");
  249. var startdate = new Date(start);
  250. end = end.replace(/-/g, "/");
  251. var enddate = new Date(end);
  252. var time = enddate.getTime() - startdate.getTime();
  253. var days = parseInt(time / (1000 * 60 * 60 * 24));
  254. $('#datediff').html('共 ' + days + ' 晚');
  255. start_date = $('#start_date').val();
  256. end_date = $('#end_date').val();
  257. org_id = $('#org_id').val();
  258. getRoomStock()
  259. }
  260. //日历点击事件
  261. function timeDiffStart() {
  262. timeDiff();
  263. $('#end_date').focus();
  264. }
  265. //添加备注
  266. function addNote(e) {
  267. var note = '<div style="margin-top: 20px" class="note"><span style="width: 100px;display: inline-block"></span>';
  268. //不同用户登录,显示不同内容
  269. var display = 'none';
  270. var user_org_id = getCookie('user_org_id');
  271. if (user_org_id == 0) {
  272. display = 'inline-block';
  273. }
  274. note += ' <select name="note[type][]" style=" display: ' + display + ';"><option value="0">公共备注</option><option value="1">内部备注</option></select>';
  275. note += ' <input name="note[text][]" style="width: 300px;height: 30px;font-size: 13px;color: inherit" placeholder="填写备注" />';
  276. var user_id = getCookie('user_id');
  277. if ($.inArray(user_id, [1, 35, 160]))
  278. note += ' <a href="javascript:;" onclick="removeNote(this)" >删除</a>';
  279. note += '</div>';
  280. $(".note:last").after(note);
  281. }
  282. //提交订单
  283. function commit(identify) {
  284. if ($('#button').text() == '保存中' || $('#button_send').text() == '保存中') {
  285. return;
  286. }
  287. $('#button').text('保存中');
  288. $('#button').css('background', 'darkgray');
  289. $('#button_send').text('保存中');
  290. $('#button_send').css('background', 'darkgray');
  291. //获取联系人,联系方式,备注
  292. var contacts = $('#contacts').val().replace(/\,/g, ' ').trim();
  293. var phone = $('#phone').val();
  294. var more = '';
  295. //拒单标识0为不能拒单,1为可以拒单
  296. var if_cancel = 0;
  297. //备注要拼接字符串
  298. $.each($("[name^='note[type]']"), function (key, item) {
  299. var text = $(item).next().val().replace(/[\|,]/g, ' ').trim();
  300. if (text != '') {
  301. if (more != '')
  302. more += '||';
  303. more += getCookie('user_id') + '|' + parseInt(Date.now() / 1000) + '|' + item.value + '|' + text;
  304. }
  305. });
  306. //end 备注要拼接字符串
  307. var cus_list = "{" + contacts + "," + phone + "," + more + "}";
  308. //end 获取联系人,联系方式,备注
  309. //获取最晚到店时间
  310. var checkin_time = $('#time').val().toString();
  311. //渠道订单号
  312. var org_num = $('#org_num').val();
  313. //渠道id
  314. var org_id = $('#org_id').val();
  315. //获取房型列表
  316. var room_list = '';
  317. $('.tr_str').each(function () {
  318. var start_date = $(this).find('td').eq(0).text();
  319. var all_count = $(this).find('.prod_count').val();
  320. if (all_count == 0) {
  321. /*$('#button').text("保存");
  322. $('#button').attr('disabled',"false");*/
  323. ZZAlertInfo('请选择库存', function () {
  324. return;
  325. })
  326. }
  327. var dan_jiesuan = $(this).find('.prod_price').val();
  328. if ($(this).find('.yongj_sum').text() == '-') {
  329. var dan_yongj = 0
  330. } else {
  331. var dan_yongj = (parseFloat($(this).find('.yongj_sum').text()) / parseInt(all_count)).toFixed(2);
  332. }
  333. //获得买断,保留,现询的价格与库存
  334. var dict_maiduan = getJsonHtml($(this).attr('data-json-maiduan'));
  335. var dict_baoliu = getJsonHtml($(this).attr('data-json-baoliu'));
  336. var dict_xianxun = getJsonHtml($(this).attr('data-json-xianxun'));
  337. //库存类型与成本
  338. var maiduan_count = dict_maiduan == 0 ? 0 : dict_maiduan['remaining_count'];
  339. var baoliu_count = dict_baoliu == 0 ? 0 : dict_baoliu['remaining_count'];
  340. var xianxun_count = dict_xianxun == 0 ? 0 : dict_xianxun['remaining_count'];
  341. var maiduan_price = dict_maiduan == 0 ? 0 : dict_maiduan['cost_price'];
  342. var baoliu_price = dict_baoliu == 0 ? 0 : dict_baoliu['cost_price'];
  343. var xianxun_price = dict_xianxun == 0 ? 0 : dict_xianxun['cost_price'];
  344. if (maiduan_price == 0 && baoliu_price == 0 && xianxun_price == 0) {
  345. ZZAlertInfo('存在成本价为零,请至对应房型列表确认', function () {
  346. })
  347. }
  348. //end 库存类型与成本
  349. //end 获得买断,保留,现询的价格与库存
  350. //判断库存
  351. var maiduan_field = '';
  352. var baoliu_field = '';
  353. var xianxun_field = '';
  354. var sum_field = '';
  355. if (parseInt(all_count) <= parseInt(maiduan_count)) {//小于等于买断库存228
  356. sum_field = '228' + ',' + all_count + ',' + maiduan_price
  357. } else if (parseInt(all_count) > parseInt(maiduan_count) && parseInt(all_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count))) {
  358. maiduan_field = '228' + ',' + maiduan_count + ',' + maiduan_price;
  359. baoliu_field = '230' + ',' + (all_count - maiduan_count) + ',' + baoliu_price;
  360. sum_field = maiduan_field + '|' + baoliu_field
  361. } else if (parseInt(all_count) > (parseInt(maiduan_count) + parseInt(baoliu_count)) && parseInt(all_count) <= (parseInt(maiduan_count) + parseInt(baoliu_count) + parseInt(xianxun_count))) {
  362. if_cancel = 1;
  363. maiduan_field = '228' + ',' + maiduan_count + ',' + maiduan_price;
  364. baoliu_field = '230' + ',' + baoliu_count + ',' + baoliu_price;
  365. xianxun_field = '229' + ',' + (all_count - baoliu_count - maiduan_count) + ',' + xianxun_price;
  366. sum_field = maiduan_field + '|' + baoliu_field + '|' + xianxun_field
  367. } else {
  368. /*ZZAlertInfo('获取库存信息失败', function () {
  369. return false;
  370. })*/
  371. }
  372. // ZZLog(sum_field);
  373. room_list += '{\'\'' + start_date + '\'\',' + all_count + ',' + dan_jiesuan + ',' + dan_yongj + '}';
  374. //end 判断库存
  375. });
  376. //end 获取房型列表
  377. var param = {
  378. type: "order_MakeHTOrder",
  379. op: "make_order",
  380. hotel_id: hotel_id,
  381. room_type: room_type,
  382. org_id: org_id,
  383. org_num: org_num,
  384. room_list: room_list,
  385. cus_list: cus_list,
  386. checkin_time: checkin_time,
  387. if_cancel: if_cancel,
  388. order_id: 0,
  389. total_commission: all_yongj,
  390. benefit: all_profit
  391. };
  392. ZZLog(param);
  393. //最晚到店不为空,联系人不为空,订单渠道不为空,渠道订单号不为空,入住日期得连续,库存不问空
  394. if (hotel_id == '' || room_type == '' || org_id == '' || room_list == '' || checkin_time == '' || if_cancel === '' || contacts === '') {
  395. /*$('#button').text("保存");
  396. $('#button').attr('disabled',"false");*/
  397. ZZAlertInfo('请完整填写数据', function () {
  398. $('#button').text('提交');
  399. $('#button').css('background', '#428bca!important');
  400. $('#button_send').text('提交并发单');
  401. $('#button_send').css('background', '#428bca!important');
  402. })
  403. return false;
  404. } else {
  405. loading();
  406. $.ajax({
  407. url: base_api,
  408. type: 'post',
  409. dataTye: 'json',
  410. data: param,
  411. success: function (res_data) {
  412. closeLoading();
  413. res_data = JSON.parse(res_data);
  414. if (res_data['code'] != "0") {
  415. $('#button').text('提交');
  416. $('#button').css('background', '#428bca!important');
  417. $('#button_send').text('提交并发单');
  418. $('#button_send').css('background', '#428bca!important');
  419. ZZAlertInfo('下单失败', function () {
  420. })
  421. } else {
  422. $('#button').text('提交');
  423. $('#button').css('background', '#428bca!important');
  424. $('#button_send').text('提交并发单');
  425. $('#button_send').css('background', '#428bca!important');
  426. if (identify == 1) { // 继续发单
  427. var url = base_api;
  428. var param = {
  429. type: "order_HotelOrderList",
  430. op: "billing",
  431. order_id: res_data['order_id']
  432. };
  433. $.ajax({
  434. url: url,
  435. type: "post",
  436. dataType: "json",
  437. data: param,
  438. success: function (send_data) {
  439. ZZLog(send_data);
  440. if (send_data['code'] != "0") {
  441. ZZAlertInfo('下单成功!订单号为' + res_data['order_id'] + ';自动发单失败:' + send_data['info'] + ',请到酒店订单列表进行手动发单操作', function () {
  442. window.location.href = "./hotel_order_list.html";
  443. });
  444. } else {
  445. ZZAlertInfo('下单成功!订单号为' + res_data['order_id'], function () {
  446. window.location.href = "./hotel_order_list.html";
  447. });
  448. }
  449. }, error: function (error) {
  450. ZZLog(error);
  451. }
  452. })
  453. } else {
  454. ZZAlertInfo('下单成功!订单号为' + res_data['order_id'], function () {
  455. window.location.href = "./hotel_order_list.html";
  456. });
  457. }
  458. }
  459. },
  460. error: function (msg) {
  461. closeLoading();
  462. }
  463. })
  464. }
  465. }
  466. //获取总计
  467. function all_sum() {
  468. all_yongj = 0;
  469. all_jiesuan = 0;
  470. all_profit = 0;
  471. var all_yongj1 = 0;
  472. var all_jiesuan1 = 0;
  473. var all_profit1 = 0;
  474. $('.yongj_sum').each(function () {
  475. all_yongj += parseFloat($(this).text())
  476. });
  477. if (isNaN(all_yongj)) {
  478. all_yongj = 0
  479. }
  480. $('.jiesuan_sum').each(function () {
  481. all_jiesuan += parseFloat($(this).text())
  482. });
  483. if (isNaN(all_jiesuan)) {
  484. all_jiesuan = 0
  485. }
  486. $('.benefit_sum').each(function () {
  487. all_profit += parseFloat($(this).text())
  488. });
  489. if (isNaN(all_profit)) {
  490. all_profit = 0
  491. }
  492. all_yongj1 = all_yongj.toFixed(2);
  493. all_jiesuan1 = all_jiesuan.toFixed(2);
  494. all_profit1 = all_profit.toFixed(2);
  495. $('#all_yongj').text(all_yongj1 + '元');
  496. $('#all_jiesuan').text(all_jiesuan1 + '元');
  497. $('#all_profit').text(all_profit1 + '元');
  498. }