ordercollect.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-datetimepicker', 'bootstrap-daterangepicker','dateyearmonth'], function ($, undefined, Backend, Table, Form, Datetimepicker, Daterangepicker, dateyearmonth) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'vip/admin/ordercollect/index',
  8. table: 'orders_collect'
  9. },
  10. search: false,
  11. searchFormVisible: true,
  12. showExport: false,
  13. onLoadSuccess: function (data) {
  14. $("[data-toggle='tooltip']").tooltip({trigger: 'focus hover', html: true});
  15. var startDate, endDate;
  16. if (data['begin_date']) {
  17. startDate = data['begin_date'];
  18. } else {
  19. startDate = Moment().subtract(1, 'day');
  20. }
  21. if (data['end_date']) {
  22. endDate = data['end_date'];
  23. } else {
  24. endDate = Moment().subtract(1, 'day');
  25. }
  26. $('#day,#day_sum').daterangepicker({
  27. // autoUpdateInput: false,
  28. startDate: startDate,
  29. endDate: endDate,
  30. maxDate: Moment().subtract(1, 'day'),
  31. minDate: Moment().subtract(12, 'month'),
  32. locale: {
  33. format: 'YYYY-MM-DD',
  34. applyLabel: '确认',
  35. cancelLabel: '取消',
  36. fromLabel: '从',
  37. toLabel: '到',
  38. weekLabel: 'W',
  39. customRangeLabel: '选择时间',
  40. daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
  41. monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  42. }
  43. });
  44. $('#month').datetimepicker({
  45. maxDate: Moment(),
  46. format: 'YYYY-MM'
  47. });
  48. if($('#month_sum').length){
  49. if(!$('#month_sum').val()){
  50. $('#month_sum').val(Moment().subtract(0, 'month').format('YYYY-MM')+' - '+Moment().format('YYYY-MM'));
  51. $(document).delegate('.kui-datepicker-range-footer .select','click',function(){
  52. $('.commonsearch-table button[type="submit"]').trigger('click');
  53. });
  54. }
  55. new dateyearmonth({
  56. id:'month_sum',
  57. format:'yyyy-mm - yyyy-mm',
  58. endYear:Moment().year(),
  59. startYear:Moment().subtract(1,'year').year(),
  60. });
  61. }
  62. if(($('.nima').length > 0)){
  63. $('.nima').remove();
  64. $('.fixed-table-toolbar').prepend('<div class="columns-left pull-left nima" style="margin-top:10px;"><a class="btn btn-success btn-exports" href="javascript:;"><i class="fa fa-user"></i> 导出</a></div>');
  65. }else{
  66. $('.fixed-table-toolbar').prepend('<div class="columns-left pull-left nima" style="margin-top:10px;"><a class="btn btn-success btn-exports" href="javascript:;"><i class="fa fa-user"></i> 导出</a></div>');
  67. }
  68. }
  69. });
  70. //绑定事件
  71. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  72. var panel = $($(this).attr("href"));
  73. if (panel.size() > 0) {
  74. Controller.table[panel.attr("id")].call(this);
  75. $(this).on('click', function (e) {
  76. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  77. });
  78. }
  79. //移除绑定的事件
  80. $(this).unbind('shown.bs.tab');
  81. // var html= '<div id="toolbar" class="toolbar"><a class="btn btn-success btn-exports" href="javascript:;"><i class="fa fa-user"></i> 导出</a></div>';
  82. // $('#export').prepend(html);
  83. });
  84. //必须默认触发shown.bs.tab事件
  85. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  86. $(document).on('click', '.flush', function () {
  87. $.post('vip/admin/ordercollect/ajaxtoday', {}, function (data) {
  88. if (data) {
  89. $('#increase').text('¥' + data.today);
  90. Toastr.success('刷新成功');
  91. } else {
  92. Toastr.error('刷新失败');
  93. }
  94. });
  95. });
  96. $(document).on('click','.btn-exports',function () {
  97. var tab_index = $('.panel-heading .nav-tabs').find('li.active').index()
  98. var map = ['day', 'day_sum', 'month', 'month_sum'];
  99. var url = '/admin/vip/admin/ordercollect/export?tab=' + map[tab_index];
  100. var data = $('.panel-body.tab-content>.tab-pane.fade.active .form-commonsearch').serializeArray();
  101. var params = {filter:{},op:{}};
  102. $.each(data, function(index, val) {
  103. if(val.name.substr(0,6) == 'field-'){
  104. var key = val.name.substr(6,val.name.length);
  105. params.op[key] = val.value;
  106. }else{
  107. if(val.value == ""){
  108. delete params.op[val.name];
  109. }else{
  110. params.filter[val.name] = val.value;
  111. }
  112. }
  113. });
  114. if(url.indexOf("?") != -1){
  115. url = url + "&filter="+JSON.stringify(params.filter)+"&op="+JSON.stringify(params.op);
  116. }else{
  117. url = url + "?filter="+JSON.stringify(params.filter)+"&op="+JSON.stringify(params.op);
  118. }
  119. top.location.href=url;
  120. });
  121. },
  122. table: {
  123. first: function () {
  124. var table = $("#table");
  125. // 初始化渠道商表格
  126. table.bootstrapTable({
  127. url: 'vip/admin/ordercollect/index?tab=day',
  128. pk: 'id',
  129. sortName: 'createdate',
  130. columns: [
  131. [
  132. {
  133. field: 'createdate',
  134. id: 'day',
  135. title: __('日期'),
  136. formatter: Controller.api.formatter.createtime, width: '100px'
  137. },
  138. {
  139. field: 'username',
  140. title: __('渠道商账号')
  141. // operate: false
  142. },
  143. {field: 'wx_nickname', title: __('公众号'), operate: false, width: '150px'},
  144. {field: 'recharge_money', title: __('总充值'), operate: false},
  145. {
  146. field: 'normal_recharge_money',
  147. title: __('总充值笔数'),
  148. formatter: Controller.api.formatter.sum_recharge_orders,
  149. operate: false
  150. },
  151. {
  152. field: 'normal_recharge_money',
  153. title: __('普通充值'),
  154. formatter: Controller.api.formatter.money,
  155. operate: false
  156. },
  157. {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
  158. {
  159. field: '',
  160. title: __('普通充值人均'),
  161. formatter: Controller.api.formatter.normal_recharge_str_avg,
  162. operate: false
  163. },
  164. {
  165. field: 'vip_recharge_money',
  166. title: __('年费VIP充值'),
  167. formatter: Controller.api.formatter.money,
  168. operate: false
  169. },
  170. {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
  171. {
  172. field: '',
  173. title: __('年费VIP人均'),
  174. formatter: Controller.api.formatter.vip_recharge_str_avg,
  175. operate: false
  176. },
  177. {
  178. field: 'self_recharge',
  179. title: __('渠道商充值'),
  180. formatter: Controller.api.formatter.money,
  181. operate: false
  182. },
  183. {
  184. field: 'self_recharge_benefit',
  185. title: __('渠道商的分成收益'),
  186. formatter: Controller.api.formatter.money,
  187. operate: false
  188. },
  189. {
  190. field: 'agent_recharge',
  191. title: __('代理商充值金额'),
  192. formatter: Controller.api.formatter.money,
  193. operate: false
  194. },
  195. {
  196. field: 'agent_benefit',
  197. title: __('代理商分成收益'),
  198. formatter: Controller.api.formatter.money,
  199. operate: false
  200. },
  201. {
  202. field: 'total_benefit',
  203. title: __('实际收益'),
  204. formatter: Controller.api.formatter.money,
  205. operate: false
  206. }
  207. ]
  208. ]
  209. });
  210. // 为表格1绑定事件
  211. Table.api.bindevent(table);
  212. Controller.api.bindevent();
  213. },
  214. second: function () {
  215. var table2 = $("#table2");
  216. // 初始化渠道商表格
  217. table2.bootstrapTable({
  218. url: 'vip/admin/ordercollect/index?tab=month',
  219. pk: 'id',
  220. sortName: 'createdate',
  221. columns: [
  222. [
  223. {
  224. field: 'create_month',
  225. id: 'month',
  226. title: __('月份'),
  227. formatter: Controller.api.formatter.createmonthtime,
  228. width: '100px'
  229. },
  230. {
  231. field: 'username',
  232. title: __('渠道商账号'),
  233. // operate: false
  234. },
  235. {field: 'wx_nickname', title: __('公众号'), operate: false, width: '150px'},
  236. {field: 'recharge_money', title: __('总充值'), operate: false},
  237. {
  238. field: 'normal_recharge_money',
  239. title: __('总充值笔数'),
  240. formatter: Controller.api.formatter.sum_recharge_orders,
  241. operate: false
  242. },
  243. {
  244. field: 'normal_recharge_money',
  245. title: __('普通充值'),
  246. formatter: Controller.api.formatter.money,
  247. operate: false
  248. },
  249. {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
  250. {
  251. field: '',
  252. title: __('普通充值人均'),
  253. formatter: Controller.api.formatter.normal_recharge_str_avg,
  254. operate: false
  255. },
  256. {
  257. field: 'vip_recharge_money',
  258. title: __('年费VIP充值'),
  259. formatter: Controller.api.formatter.money,
  260. operate: false
  261. },
  262. {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
  263. {
  264. field: '',
  265. title: __('年费VIP人均'),
  266. formatter: Controller.api.formatter.vip_recharge_str_avg,
  267. operate: false
  268. },
  269. {
  270. field: 'self_recharge',
  271. title: __('充值'),
  272. formatter: Controller.api.formatter.money,
  273. operate: false
  274. },
  275. {
  276. field: 'self_recharge_benefit',
  277. title: __('分成收益'),
  278. formatter: Controller.api.formatter.money,
  279. operate: false
  280. },
  281. {
  282. field: 'agent_recharge',
  283. title: __('代理商充值'),
  284. formatter: Controller.api.formatter.money,
  285. operate: false
  286. },
  287. {
  288. field: 'agent_benefit',
  289. title: __('代理商分成收益'),
  290. formatter: Controller.api.formatter.money,
  291. operate: false
  292. },
  293. {
  294. field: 'total_benefit',
  295. title: __('实际收益'),
  296. formatter: Controller.api.formatter.money,
  297. operate: false
  298. }
  299. ]
  300. ]
  301. });
  302. // 为表格1绑定事件
  303. Table.api.bindevent(table2);
  304. Controller.api.bindevent();
  305. },
  306. third: function () {
  307. var table3 = $("#table3");
  308. // 初始化渠道商表格
  309. table3.bootstrapTable({
  310. url: 'vip/admin/ordercollect/index?tab=day_sum',
  311. pk: 'id',
  312. sortName: 'createday',
  313. columns: [
  314. [
  315. {
  316. field: 'createdate',
  317. id: 'day_sum',
  318. title: __('日期'),
  319. formatter: Controller.api.formatter.createtime, width: '100px'
  320. },
  321. {field: 'recharge_money', title: __('总充值'), operate: false},
  322. {
  323. field: 'normal_recharge_money',
  324. title: __('总充值笔数'),
  325. formatter: Controller.api.formatter.sum_recharge_orders,
  326. operate: false
  327. },
  328. {
  329. field: 'normal_recharge_money',
  330. title: __('普通充值'),
  331. formatter: Controller.api.formatter.money,
  332. operate: false
  333. },
  334. {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
  335. {
  336. field: '',
  337. title: __('普通充值人均'),
  338. formatter: Controller.api.formatter.normal_recharge_str_avg,
  339. operate: false
  340. },
  341. {
  342. field: 'vip_recharge_money',
  343. title: __('年费VIP充值'),
  344. formatter: Controller.api.formatter.money,
  345. operate: false
  346. },
  347. {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
  348. {
  349. field: '',
  350. title: __('年费VIP人均'),
  351. formatter: Controller.api.formatter.vip_recharge_str_avg,
  352. operate: false
  353. },
  354. {
  355. field: 'self_recharge',
  356. title: __('充值'),
  357. formatter: Controller.api.formatter.money,
  358. operate: false
  359. },
  360. {
  361. field: 'self_recharge_benefit',
  362. title: __('分成收益'),
  363. formatter: Controller.api.formatter.money,
  364. operate: false
  365. },
  366. {
  367. field: 'agent_recharge',
  368. title: __('代理商充值'),
  369. formatter: Controller.api.formatter.money,
  370. operate: false
  371. },
  372. {
  373. field: 'agent_benefit',
  374. title: __('代理商分成收益'),
  375. formatter: Controller.api.formatter.money,
  376. operate: false
  377. },
  378. {
  379. field: 'total_benefit',
  380. title: __('实际收益'),
  381. formatter: Controller.api.formatter.money,
  382. operate: false
  383. }
  384. ]
  385. ]
  386. });
  387. // 为表格1绑定事件
  388. Table.api.bindevent(table3);
  389. Controller.api.bindevent();
  390. },
  391. forth: function () {
  392. var table4 = $("#table4");
  393. // 初始化渠道商表格
  394. table4.bootstrapTable({
  395. url: 'vip/admin/ordercollect/index?tab=month_sum',
  396. pk: 'id',
  397. sortName: 'create_month',
  398. columns: [
  399. [
  400. {
  401. field: 'create_month',
  402. id: 'month_sum',
  403. title: __('月份'),
  404. formatter: Controller.api.formatter.createmonthtime,
  405. width: '100px'
  406. },
  407. {field: 'recharge_money', title: __('总充值'), operate: false},
  408. {
  409. field: 'normal_recharge_money',
  410. title: __('总充值笔数'),
  411. formatter: Controller.api.formatter.sum_recharge_orders,
  412. operate: false
  413. },
  414. {
  415. field: 'normal_recharge_money',
  416. title: __('普通充值'),
  417. formatter: Controller.api.formatter.money,
  418. operate: false
  419. },
  420. {field: 'normal_recharge_orders', title: __('普通充值笔数'), operate: false},
  421. {
  422. field: '',
  423. title: __('普通充值人均'),
  424. formatter: Controller.api.formatter.normal_recharge_str_avg,
  425. operate: false
  426. },
  427. {
  428. field: 'vip_recharge_money',
  429. title: __('年费VIP充值'),
  430. formatter: Controller.api.formatter.money,
  431. operate: false
  432. },
  433. {field: 'vip_recharge_orders', title: __('年费VIP充值笔数'), operate: false},
  434. {
  435. field: '',
  436. title: __('年费VIP人均'),
  437. formatter: Controller.api.formatter.vip_recharge_str_avg,
  438. operate: false
  439. },
  440. {
  441. field: 'self_recharge',
  442. title: __('充值'),
  443. formatter: Controller.api.formatter.money,
  444. operate: false
  445. },
  446. {
  447. field: 'self_recharge_benefit',
  448. title: __('分成收益'),
  449. formatter: Controller.api.formatter.money,
  450. operate: false
  451. },
  452. {
  453. field: 'agent_recharge',
  454. title: __('代理商充值'),
  455. formatter: Controller.api.formatter.money,
  456. operate: false
  457. },
  458. {
  459. field: 'agent_benefit',
  460. title: __('代理商分成收益'),
  461. formatter: Controller.api.formatter.money,
  462. operate: false
  463. },
  464. {
  465. field: 'total_benefit',
  466. title: __('实际收益'),
  467. formatter: Controller.api.formatter.money,
  468. operate: false
  469. }
  470. ]
  471. ]
  472. });
  473. // 为表格1绑定事件
  474. Table.api.bindevent(table4);
  475. Controller.api.bindevent();
  476. }
  477. },
  478. api: {
  479. bindevent: function () {
  480. Form.api.bindevent($("form[role=form]"));
  481. }, formatter: {
  482. sum_recharge_orders: function (value, row, index) {
  483. normal_recharge_orders = Number(row.normal_recharge_orders ? row.normal_recharge_orders : 0);
  484. vip_recharge_orders = Number(row.vip_recharge_orders ? row.vip_recharge_orders : 0);
  485. return normal_recharge_orders + vip_recharge_orders;
  486. },
  487. money: function (value, row, index) {
  488. if (value) {
  489. return '¥' + Number(value).toFixed(2);
  490. } else {
  491. return '¥0.00';
  492. }
  493. },
  494. normal_recharge_str_avg: function (value, row, index) {
  495. var normal_recharge_str_avg = 0;
  496. if (row.normal_recharge_orders > 0) {
  497. normal_recharge_str_avg = Number(row.normal_recharge_money / row.normal_recharge_orders) * 1.00;
  498. normal_recharge_str_avg = Number(normal_recharge_str_avg.toFixed(2));
  499. }
  500. return '¥' + normal_recharge_str_avg;
  501. },
  502. vip_recharge_str_avg: function (value, row, index) {
  503. var vip_recharge_str_avg = 0;
  504. if (row.vip_recharge_orders > 0) {
  505. vip_recharge_str_avg = Number(row.vip_recharge_money / row.vip_recharge_orders) * 1.00;
  506. vip_recharge_str_avg = Number(vip_recharge_str_avg.toFixed(2));
  507. }
  508. return '¥' + vip_recharge_str_avg;
  509. },
  510. createtime: function (value, row, index) {
  511. if (value) {
  512. return value.substring(0, 4) + '-' + value.substring(4, 6) + '-' + value.substring(6, 8);
  513. } else {
  514. return '';
  515. }
  516. },
  517. createmonthtime: function (value, row, index) {
  518. return value.substring(0, 4) + '-' + value.substring(4, 6);
  519. },
  520. }
  521. }
  522. };
  523. return Controller;
  524. });