collect.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','bootstrap-daterangepicker','dateyearmonth'], function ($, undefined, Backend, Table, Form) {
  2. var wait=60;
  3. if (Config.groupId != 8) {
  4. $(function () {
  5. time();
  6. });
  7. }
  8. //$('#ajaxkandian').click(function(){
  9. // $.post('/index/book/ajaxFee',{userId:1,bookId:30,chapter_id:50,chapter_name:"下啊是事实"},function(data){
  10. // console.log(data);
  11. // })
  12. //});
  13. function time() {
  14. if (wait == 0) {
  15. //执行ajax拉新数据
  16. $.post('/admin/user/collect/ajaxtoday',{ids:Config.ids},function(data){
  17. //console.log(data);
  18. if (data){
  19. $('#increase_m').text(data.increase_m);
  20. $('#increase_f').text(data.increase_f);
  21. $('#increase').text(data.increase);
  22. $('#increase_fllow').text(data.increase_fllow);
  23. $('#increase_recharge').text(data.increase_recharge);
  24. $('#day_recharge_user_count').text(data.day_recharge_user_count);
  25. $('#guide_follow_num').text(data.guide_follow_num);
  26. $('#unfollow_num').text(data.unfollow_num);
  27. $('#net_follow_num').text(data.net_follow_num);
  28. $('#new_user_recharge').text(data.day_recharge_user_money);
  29. }
  30. });
  31. wait = 60;
  32. time();
  33. } else {
  34. $('.flush').text(wait+'秒后刷新');
  35. wait--;
  36. setTimeout(function() {
  37. time()
  38. }, 1000)
  39. }
  40. }
  41. var Controller = {
  42. index: function () {
  43. // 初始化表格参数配置
  44. Table.api.init({
  45. extend: {
  46. index_url: 'user/collect/index?ids='+Config.ids,
  47. recharge_new: 'user/collect/recharge_new?ids='+Config.ids,
  48. add_url: 'user/collect/add',
  49. edit_url: 'user/collect/edit',
  50. del_url: 'user/collect/del',
  51. multi_url: 'user/collect/multi',
  52. table: 'user_collect',
  53. },
  54. showToggle: false,
  55. showColumns: false,
  56. showExport: false,
  57. commonSearch: false,
  58. operate: false,
  59. search:false,
  60. onLoadSuccess: function (data) {
  61. $("[data-toggle='tooltip']").tooltip({trigger: 'focus hover',html : true});
  62. var startDate, endDate;
  63. if (data['begin_date']) {
  64. startDate = data['begin_date'];
  65. } else {
  66. startDate = Moment().subtract(1, 'day');
  67. }
  68. if (data['end_date']) {
  69. endDate = data['end_date'];
  70. } else {
  71. endDate = Moment().subtract(1, 'day');
  72. }
  73. $('.rangeday').daterangepicker({
  74. // autoUpdateInput: false,
  75. startDate: startDate,
  76. endDate: endDate,
  77. maxDate: Moment().subtract(1, 'day'),
  78. minDate: Moment().subtract(12, 'month'),
  79. locale: {
  80. format: 'YYYY-MM-DD',
  81. applyLabel: '确认',
  82. cancelLabel: '取消',
  83. fromLabel: '从',
  84. toLabel: '到',
  85. weekLabel: 'W',
  86. customRangeLabel: '选择时间',
  87. daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
  88. monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  89. }
  90. });
  91. }
  92. });
  93. //绑定事件
  94. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  95. var panel = $($(this).attr("href"));
  96. if (panel.size() > 0) {
  97. Controller.table[panel.attr("id")].call(this);
  98. }
  99. //移除绑定的事件
  100. $(this).unbind('shown.bs.tab');
  101. });
  102. $(document).on('click','.layer-open',function () {
  103. Fast.api.open($(this).attr('href'), $(this).data('title')?$(this).data('title'):'查看渠道明细', {});
  104. return false;
  105. });
  106. //必须默认触发shown.bs.tab事件
  107. $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  108. //#endregion
  109. },
  110. table: {
  111. first:function(){
  112. var table = $("#table1");
  113. // 初始化表格
  114. table.bootstrapTable({
  115. url: $.fn.bootstrapTable.defaults.extend.index_url,
  116. pk: 'id',
  117. sortName: 'createdate',
  118. columns: [
  119. [
  120. {field: 'createdate', title: __('日期'),formatter: Controller.api.formatter.createtime},
  121. {field: 'increase', title: __('新增用户')},
  122. {field: 'increase_fllow', title: __('主号关注'),operate:false,formatter: Controller.api.formatter.follow},
  123. {field: 'guide_follow_num', title: __('导粉关注'), visible: false, formatter: Controller.api.formatter.guide},
  124. {field: 'unfollow_num', title: __('主号取关'),formatter: Controller.api.formatter.unfollow},
  125. {field: 'net_follow_num', title: __('净关注'),formatter: Controller.api.formatter.netfollow},
  126. {field: 'increase_recharge', title: __('已付费'),operate:false,formatter: Controller.api.formatter.recharge},
  127. {field: 'day_recharge_user_count', title: __('新增用户的充值人数'),operate:false},
  128. {field: 'day_recharge_user_money', title: __('新增用户的充值金额'),operate:false},
  129. {field: 'increase_m', title: __('男性')},
  130. {field: 'increase_f', title: __('女性')},
  131. ]
  132. ]
  133. });
  134. // 为表格绑定事件
  135. Table.api.bindevent(table);
  136. $(document).on('click', '.flush', function () {
  137. window.location.reload();
  138. });
  139. },
  140. second: function () {
  141. var table = $("#table2");
  142. $.fn.bootstrapTable.defaults.commonSearch = true
  143. // 初始化表格
  144. table.bootstrapTable({
  145. url: $.fn.bootstrapTable.defaults.extend.recharge_new,
  146. pk: 'id',
  147. sortName: 'date',
  148. columns: [
  149. [
  150. {field: 'reg_date', title: '日期', operate: 'RANGE', addclass: 'rangeday', formatter: function(value){
  151. return value.substr(0,4)+'-'+value.substr(4,2)+'-'+value.substr(6,2);
  152. }},
  153. {field:'new',title:'新增用户',operate:false},
  154. {field:'recharge_total',title:'累计充值',operate:false, formatter: function(value, row){
  155. var sum = 0;
  156. for (var index in row) {
  157. if (index.indexOf('day') != -1 && row[index]) {
  158. sum += parseFloat(row[index])
  159. }
  160. }
  161. return sum.toFixed(2);
  162. }},
  163. {field:'cost',title:'成本',operate:false, formatter: function(value, row){
  164. value = value == null ? '-' : value;
  165. return value + '<i class="fa fa-pencil edit-cost" data-cost="'+value+'" data-id="'+row.id+'" style="cursor: pointer"></i>'
  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. {field:'day1',title:'第1日充值',operate:false},
  181. {field:'day2',title:'第2日充值',operate:false},
  182. {field:'day3',title:'第3日充值',operate:false},
  183. // {field:'day4',title:'第4日充值',operate:false},
  184. {field:'day5',title:'第5日充值',operate:false},
  185. // {field:'day6',title:'第6日充值',operate:false},
  186. {field:'day7',title:'第7日充值',operate:false},
  187. // {field:'day8',title:'第8日充值',operate:false},
  188. // {field:'day9',title:'第9日充值',operate:false},
  189. // {field:'day10',title:'第10日充值',operate:false},
  190. // {field:'day11',title:'第11日充值',operate:false},
  191. // {field:'day12',title:'第12日充值',operate:false},
  192. // {field:'day13',title:'第13日充值',operate:false},
  193. // {field:'day14',title:'第14日充值',operate:false},
  194. {field:'day15',title:'第15日充值',operate:false},
  195. // {field:'day16',title:'第16日充值',operate:false},
  196. // {field:'day17',title:'第17日充值',operate:false},
  197. // {field:'day18',title:'第18日充值',operate:false},
  198. // {field:'day19',title:'第19日充值',operate:false},
  199. // {field:'day20',title:'第20日充值',operate:false},
  200. // {field:'day21',title:'第21日充值',operate:false},
  201. // {field:'day22',title:'第22日充值',operate:false},
  202. // {field:'day23',title:'第23日充值',operate:false},
  203. // {field:'day24',title:'第24日充值',operate:false},
  204. // {field:'day25',title:'第25日充值',operate:false},
  205. // {field:'day26',title:'第26日充值',operate:false},
  206. // {field:'day27',title:'第27日充值',operate:false},
  207. // {field:'day28',title:'第28日充值',operate:false},
  208. // {field:'day29',title:'第29日充值',operate:false},
  209. {field:'day30',title:'第30日充值',operate:false}
  210. ]
  211. ]
  212. });
  213. $(document).delegate('.edit-cost','click',function(){
  214. var cost = $(this).data('cost');
  215. var id = $(this).data('id');
  216. Layer.open({
  217. type: 1,
  218. title: '修改金额',
  219. maxmin: false,
  220. area: ['300px', '200px'],
  221. btn: ['确认', '取消'],
  222. shadeClose: true,
  223. resize: false,
  224. // skin: 'layui-layer-rim',
  225. content: '<input id="cost" type="text" value="'+cost+'" style="margin: 10px 10px;">',
  226. yes: function (index, layero) {
  227. $.ajax({
  228. url: 'user/collect/recharge_cost',
  229. data: {cost: $('#cost').val(), id: id},
  230. type: 'get',
  231. success: function(){
  232. layer.close(index);
  233. table.bootstrapTable('refresh');
  234. }
  235. });
  236. },
  237. btn2: function (index, node) {
  238. layer.close(index)
  239. }
  240. });
  241. })
  242. }
  243. },
  244. add: function () {
  245. Controller.api.bindevent();
  246. },
  247. edit: function () {
  248. Controller.api.bindevent();
  249. },
  250. api: {
  251. bindevent: function () {
  252. Form.api.bindevent($("form[role=form]"));
  253. },formatter: {
  254. follow: function (value, row, index) {
  255. return value;
  256. },
  257. recharge: function (value, row, index) {
  258. return value;
  259. },
  260. guide: function (value, row, index) {
  261. return value;
  262. },
  263. unfollow: function (value, row, index) {
  264. return value;
  265. },
  266. netfollow: function (value, row, index) {
  267. return value;
  268. },
  269. createtime:function(value,row,index){
  270. return value.substring(0,4)+'-'+ value.substring(4,6)+'-'+value.substring(6,8);
  271. },
  272. }
  273. }
  274. };
  275. return Controller;
  276. });