collect.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','bootstrap-daterangepicker'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'vip/admin/collect/index?ids='+Config.ids,
  8. index_month_url: 'vip/admin/collect/index?ids='+Config.ids+'&type=month',
  9. add_url: 'vip/admin/collect/add',
  10. edit_url: 'vip/admin/collect/edit',
  11. del_url: 'vip/admin/collect/del',
  12. multi_url: 'vip/admin/collect/multi',
  13. table: 'vip/admin_collect',
  14. recharge_new: 'vip/admin/collect/recharge_new',
  15. },
  16. showToggle: false,
  17. showColumns: false,
  18. showExport: false,
  19. commonSearch: false,
  20. operate: false,
  21. search:false,
  22. onLoadSuccess: function (data) {
  23. $("[data-toggle='tooltip']").tooltip({trigger: 'focus hover',html : true});
  24. var startDate, endDate;
  25. if (data['begin_date']) {
  26. startDate = data['begin_date'];
  27. } else {
  28. startDate = Moment().subtract(1, 'day');
  29. }
  30. if (data['end_date']) {
  31. endDate = data['end_date'];
  32. } else {
  33. endDate = Moment().subtract(1, 'day');
  34. }
  35. $('#rangeday').daterangepicker({
  36. // autoUpdateInput: false,
  37. startDate: startDate,
  38. endDate: endDate,
  39. maxDate: Moment().subtract(1, 'day'),
  40. minDate: Moment().subtract(12, 'month'),
  41. locale: {
  42. format: 'YYYY-MM-DD',
  43. applyLabel: '确认',
  44. cancelLabel: '取消',
  45. fromLabel: '从',
  46. toLabel: '到',
  47. weekLabel: 'W',
  48. customRangeLabel: '选择时间',
  49. daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
  50. monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  51. }
  52. });
  53. }
  54. });
  55. //#region
  56. // Tab 切换
  57. //绑定事件
  58. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  59. var panel = $($(this).attr("href"));
  60. if (panel.size() > 0) {
  61. Controller.table[panel.attr("id")].call(this);
  62. $(this).on('click', function (e) {
  63. $($(this).attr("href")).find(".btn-refresh").trigger("click");
  64. });
  65. }
  66. //移除绑定的事件
  67. $(this).unbind('shown.bs.tab');
  68. });
  69. //必须默认触发shown.bs.tab事件
  70. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  71. //#endregion
  72. $(document).on('click', '.flush', function () {
  73. window.location.reload();
  74. });
  75. $(document).on('click','.layer-open',function () {
  76. Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'查看渠道明细', {});
  77. return false;
  78. });
  79. },
  80. table: {
  81. first: function () {
  82. var table = $("#table");
  83. // 初始化渠道商表格
  84. table.bootstrapTable({
  85. url: $.fn.bootstrapTable.defaults.extend.index_url,
  86. pk: 'id',
  87. sortName: 'createdate',
  88. columns: [
  89. [
  90. {field: 'wx_nickname', title: __('公众号')},
  91. {field: 'increase', title: __('今日新增')},
  92. {field: 'increase_fllow', title: __('主号关注'),operate:false,formatter: Controller.api.formatter.follow},
  93. //{field: 'guide_follow_num', title: __('导粉关注'),formatter: Controller.api.formatter.guide},
  94. {field: 'unfollow_num', title: __('主号取关'),formatter: Controller.api.formatter.unfollow},
  95. {field: 'net_follow_num', title: __('净关注'),formatter: Controller.api.formatter.netfollow},
  96. {field: 'increase_recharge', title: __('已付费'),operate:false,formatter: Controller.api.formatter.recharge},
  97. {field: 'day_recharge_user_count', title: __('新增用户的充值人数'),operate:false},
  98. {field: 'day_recharge_user_money', title: __('新增用户的充值金额'),operate:false},
  99. {field: 'increase_m', title: __('男性')},
  100. {field: 'increase_f', title: __('女性')},
  101. ]
  102. ]
  103. });
  104. // 为表格1绑定事件
  105. Table.api.bindevent(table);
  106. Controller.api.bindevent();
  107. },
  108. second: function () {
  109. var table2 = $("#table2");
  110. // 初始化渠道商表格
  111. table2.bootstrapTable({
  112. url: $.fn.bootstrapTable.defaults.extend.index_month_url,
  113. pk: 'id',
  114. sortName: 'createdate',
  115. columns: [
  116. [
  117. {field: 'createdate', title: __('日期')},
  118. {field: 'increase', title: __('新增数量')},
  119. {field: 'increase_fllow', title: __('主号关注'),operate:false,formatter: Controller.api.formatter.follow},
  120. {field: 'unfollow_num', title: __('主号取关'),formatter: Controller.api.formatter.unfollow},
  121. {field: 'net_follow_num', title: __('净关注'),formatter: Controller.api.formatter.netfollow},
  122. {field: 'increase_recharge', title: __('已付费'),operate:false,formatter: Controller.api.formatter.recharge},
  123. {field: 'day_recharge_user_count', title: __('新增用户的充值人数'),operate:false},
  124. {field: 'day_recharge_user_money', title: __('新增用户的充值金额'),operate:false},
  125. {field: 'increase_m', title: __('男性')},
  126. {field: 'increase_f', title: __('女性')},
  127. ]
  128. ]
  129. });
  130. // 为表格1绑定事件
  131. Table.api.bindevent(table2);
  132. Controller.api.bindevent();
  133. },
  134. three: function () {
  135. var table5 = $("#table3");
  136. $.fn.bootstrapTable.defaults.commonSearch = true
  137. $.fn.bootstrapTable.defaults.searchFormVisible = false
  138. $.fn.bootstrapTable.defaults.showExport = false
  139. // 初始化表格
  140. table5.bootstrapTable({
  141. url: $.fn.bootstrapTable.defaults.extend.recharge_new,
  142. sortName: 'reg_date',
  143. columns: [
  144. [
  145. {field: 'reg_date', title: '日期', operate: 'RANGE', id: 'rangeday', formatter: function(value){
  146. return value.substr(0,4)+'-'+value.substr(4,2)+'-'+value.substr(6,2);
  147. }},
  148. {field: 'new', title: '新增用户', operate: false},
  149. {
  150. field: 'recharge_total',
  151. title: '累计充值',
  152. operate: false,
  153. formatter: function (value, row) {
  154. var sum = 0;
  155. for (var index in row) {
  156. if (index.indexOf('day') != -1 && row[index]) {
  157. sum += parseFloat(row[index])
  158. }
  159. }
  160. return sum.toFixed(2);
  161. }
  162. },
  163. {
  164. field: 'cost', title: '成本', operate: false
  165. },
  166. {
  167. field: 'recover_rate', title: '回本率', operate: false, formatter: function (value, row) {
  168. if (row.cost) {
  169. var sum = 0;
  170. for (var index in row) {
  171. if (index.indexOf('day') != -1 && row[index]) {
  172. sum += parseFloat(row[index])
  173. }
  174. }
  175. return (sum / row.cost * 100).toFixed(2) + '%';
  176. } else{
  177. return '-';
  178. }
  179. }
  180. },
  181. {field: 'day1', title: '第1日充值', operate: false},
  182. {field: 'day2', title: '第2日充值', operate: false},
  183. {field: 'day3', title: '第3日充值', operate: false},
  184. {field: 'day4', title: '第4日充值', operate: false},
  185. {field: 'day5', title: '第5日充值', operate: false},
  186. {field: 'day6', title: '第6日充值', operate: false},
  187. {field: 'day7', title: '第7日充值', operate: false},
  188. {field: 'day8', title: '第8日充值', operate: false},
  189. {field: 'day9', title: '第9日充值', operate: false},
  190. {field: 'day10', title: '第10日充值', operate: false},
  191. {field: 'day11', title: '第11日充值', operate: false},
  192. {field: 'day12', title: '第12日充值', operate: false},
  193. {field: 'day13', title: '第13日充值', operate: false},
  194. {field: 'day14', title: '第14日充值', operate: false},
  195. {field: 'day15', title: '第15日充值', operate: false},
  196. {field: 'day16', title: '第16日充值', operate: false},
  197. {field: 'day17', title: '第17日充值', operate: false},
  198. {field: 'day18', title: '第18日充值', operate: false},
  199. {field: 'day19', title: '第19日充值', operate: false},
  200. {field: 'day20', title: '第20日充值', operate: false},
  201. {field: 'day21', title: '第21日充值', operate: false},
  202. {field: 'day22', title: '第22日充值', operate: false},
  203. {field: 'day23', title: '第23日充值', operate: false},
  204. {field: 'day24', title: '第24日充值', operate: false},
  205. {field: 'day25', title: '第25日充值', operate: false},
  206. {field: 'day26', title: '第26日充值', operate: false},
  207. {field: 'day27', title: '第27日充值', operate: false},
  208. {field: 'day28', title: '第28日充值', operate: false},
  209. {field: 'day29', title: '第29日充值', operate: false},
  210. {field: 'day30', title: '第30日充值', operate: false},
  211. {
  212. field: 'operate',
  213. title: __('Operate'),
  214. formatter: function (value, row, index) {
  215. return '<a href="/admin/vip/admin/collect/recharge_detail/reg_date/'+row.reg_date+'" class="btn btn-xs btn-success btn-editone layer-open" data-title="查看渠道明细">查看渠道明细</a>';
  216. }
  217. }
  218. ]
  219. ]
  220. });
  221. Table.api.bindevent(table5);
  222. Controller.api.bindevent();
  223. }
  224. },
  225. add: function () {
  226. Controller.api.bindevent();
  227. },
  228. edit: function () {
  229. Controller.api.bindevent();
  230. },
  231. recharge_detail: function () {
  232. // 初始化表格参数配置
  233. Table.api.init({
  234. extend: {
  235. recharge_detail: 'vip/admin/collect/recharge_detail?reg_date='+Config.reg_date,
  236. },
  237. search: false,
  238. commonSearch: false,
  239. searchFormVisible: false,
  240. showExport: false,
  241. });
  242. var recharge_detail = $("#recharge_detail");
  243. // 初始化表格
  244. recharge_detail.bootstrapTable({
  245. url: $.fn.bootstrapTable.defaults.extend.recharge_detail,
  246. pk: 'reg_date',
  247. sortName: 'reg_date',
  248. columns: [
  249. [
  250. {field: 'reg_date', title: '日期', operate: false, formatter: function(value){
  251. return value.substr(0,4)+'-'+value.substr(4,2)+'-'+value.substr(6,2);
  252. }},
  253. {field: 'nickname', title: '公众号名称', operate: false},
  254. {field: 'new', title: '新增用户', operate: false},
  255. {
  256. field: 'recharge_total',
  257. title: '累计充值',
  258. operate: false,
  259. formatter: function (value, row) {
  260. var sum = 0;
  261. for (var index in row) {
  262. if (index.indexOf('day') != -1 && row[index]) {
  263. sum += parseFloat(row[index])
  264. }
  265. }
  266. return sum.toFixed(2);
  267. }
  268. },
  269. {
  270. field: 'cost', title: '成本', operate: false
  271. },
  272. {
  273. field: 'recover_rate', title: '回本率', operate: false, formatter: function (value, row) {
  274. if (row.cost) {
  275. var sum = 0;
  276. for (var index in row) {
  277. if (index.indexOf('day') != -1 && row[index]) {
  278. sum += parseFloat(row[index])
  279. }
  280. }
  281. return (sum / row.cost * 100).toFixed(2) + '%';
  282. } else {
  283. return '-';
  284. }
  285. }
  286. },
  287. {field: 'day1', title: '第1日充值', operate: false},
  288. {field: 'day2', title: '第2日充值', operate: false},
  289. {field: 'day3', title: '第3日充值', operate: false},
  290. {field: 'day4', title: '第4日充值', operate: false},
  291. {field: 'day5', title: '第5日充值', operate: false},
  292. {field: 'day6', title: '第6日充值', operate: false},
  293. {field: 'day7', title: '第7日充值', operate: false},
  294. {field: 'day8', title: '第8日充值', operate: false},
  295. {field: 'day9', title: '第9日充值', operate: false},
  296. {field: 'day10', title: '第10日充值', operate: false},
  297. {field: 'day11', title: '第11日充值', operate: false},
  298. {field: 'day12', title: '第12日充值', operate: false},
  299. {field: 'day13', title: '第13日充值', operate: false},
  300. {field: 'day14', title: '第14日充值', operate: false},
  301. {field: 'day15', title: '第15日充值', operate: false},
  302. {field: 'day16', title: '第16日充值', operate: false},
  303. {field: 'day17', title: '第17日充值', operate: false},
  304. {field: 'day18', title: '第18日充值', operate: false},
  305. {field: 'day19', title: '第19日充值', operate: false},
  306. {field: 'day20', title: '第20日充值', operate: false},
  307. {field: 'day21', title: '第21日充值', operate: false},
  308. {field: 'day22', title: '第22日充值', operate: false},
  309. {field: 'day23', title: '第23日充值', operate: false},
  310. {field: 'day24', title: '第24日充值', operate: false},
  311. {field: 'day25', title: '第25日充值', operate: false},
  312. {field: 'day26', title: '第26日充值', operate: false},
  313. {field: 'day27', title: '第27日充值', operate: false},
  314. {field: 'day28', title: '第28日充值', operate: false},
  315. {field: 'day29', title: '第29日充值', operate: false},
  316. {field: 'day30', title: '第30日充值', operate: false}
  317. ]
  318. ]
  319. });
  320. },
  321. api: {
  322. bindevent: function () {
  323. Form.api.bindevent($("form[role=form]"));
  324. },formatter: {
  325. follow: function (value, row, index) {
  326. return value;
  327. },
  328. recharge: function (value, row, index) {
  329. return value;
  330. },
  331. unfollow: function (value, row, index) {
  332. return value;
  333. },
  334. netfollow: function (value, row, index) {
  335. return value;
  336. },
  337. createtime:function(value,row,index){
  338. return value.substring(0,4)+'-'+ value.substring(4,6)+'-'+value.substring(6,8);
  339. },
  340. }
  341. }
  342. };
  343. return Controller;
  344. });