vipreferral.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'qrcode'], function ($, undefined, Backend, Table, Form, Qrcode) {
  2. $(document).on('click', '.short_link_but', function () {
  3. var $this = $(this);
  4. $this.hide().siblings('.short_link').show();
  5. });
  6. $(document).on("click", '.qrcode', function () {
  7. var qrUrl = $(this).data("qrcode");
  8. Fast.api.open('referral/referral/show_tpl?url='+qrUrl, '图片二维码', {});
  9. });
  10. var Controller = {
  11. index: function () {
  12. // 初始化表格参数配置
  13. Table.api.init({
  14. extend: {
  15. index_url: 'referral/vipreferral/index?state='+Config.state,
  16. add_url: 'referral/vipreferral/add',
  17. edit_url: 'referral/referral/edit?from=vipreferral',
  18. del_url: 'referral/vipreferral/del',
  19. multi_url: 'referral/vipreferral/multi',
  20. table: 'referral_library',
  21. do_choose: 'referral/vipreferral/doChoose',
  22. select_url: 'referral/vipreferral/selectchannel',
  23. disable_url: 'referral/referral/disable?isVip=1'
  24. }
  25. });
  26. var table = $("#table");
  27. var selectRowIndex = 0;
  28. // 初始化表格
  29. table.bootstrapTable({
  30. url: $.fn.bootstrapTable.defaults.extend.index_url,
  31. pk: 'referral_id',
  32. sortName: 'referral_library.id',
  33. sortOrder: 'desc',
  34. commonSearch: true,
  35. searchFormVisible: true,
  36. search: false,
  37. columns: [
  38. [
  39. {checkbox: true},
  40. {field: 'referral_library.id', title: __('Id')},
  41. {field: 'referral.book_id', title: __('书籍ID'), visible:false},
  42. {field: 'book.name', title: __('书籍名称'),visible:false, operate: 'LIKE %...%'},
  43. {field: 'source_url', title: '推广链接', formatter: Controller.api.source_url, operate: false},
  44. {field: 'entry_page', title: '入口页面', formatter: Controller.api.entry_page, operate: false},
  45. {field: 'referral.name', title: __('派单渠道'), operate: 'LIKE %...%'},
  46. {field: 'uv', title: '总阅读人数(今日)', operate:false,formatter:function(value,row,index){
  47. return '<span style="font-size:18px;color:#f33;white-space: nowrap;">' + value+' <span style="font-size:18px;color:#00f;">('+row.dayuv+')</span></span>';
  48. }},
  49. {field: 'follow', title: '总关注人数(今日)', operate:false,formatter:function(value,row,index){
  50. return '<span style="font-size:18px;color:#f33;white-space: nowrap;">' + value+' <span style="font-size:18px;color:#00f;">('+row.dayut+')</span></span>';
  51. }},
  52. {
  53. field: 'net_follow_num',
  54. title: '总净关注人数(今日)',
  55. operate: false,
  56. formatter: function (value, row, index) {
  57. return '<span style="font-size:18px;color:#f33;white-space: nowrap;">' + value+' <span style="font-size:18px;color:#00f;">('+row.dayjt+')</span></span>';
  58. //return value + "(" + row.dayjt + ")";
  59. }
  60. },
  61. {field: 'money', title: '总充值金额(今日)', operate:false,formatter:function(value,row,index){
  62. return '<span style="font-size:18px;color:#f33;white-space: nowrap;">' + value+' <span style="font-size:18px;color:#00f;">('+row.daymt+')</span></span>';
  63. }},
  64. {field: 'cost',title:'推广成本', operate:false},
  65. {
  66. field: 'referral_library.createtime',
  67. title: '创建时间',
  68. operate: 'RANGE',
  69. addclass: 'datetimerange',
  70. formatter: Table.api.formatter.datetime
  71. },
  72. {
  73. field: 'state',
  74. title: '状态',
  75. searchList: {'0': '禁用', '1': '正常'},
  76. operate: false,
  77. formatter: function (value, row, index) {
  78. return value == 1 ? "<span style='color: green;'>正常</span>" : "<span style='color: red;'>禁用</span>";
  79. }
  80. },
  81. {field: 'operate', title: __('Operate'), table: table, events: Controller.api.events.operate, buttons: [
  82. {
  83. name: 'operate',
  84. text: __('添加分流账号'),
  85. title: __('添加分流账号'),
  86. classname: 'btn btn-xs btn-primary btn-add-channels',
  87. icon: 'fa fa-list',
  88. },
  89. {
  90. name: 'operate',
  91. text: __('编辑'),
  92. title: __('编辑'),
  93. classname: 'btn btn-xs btn-success btn-editone',
  94. icon: 'fa fa-pencil',
  95. },
  96. {
  97. name: 'disable',
  98. text: '',
  99. title: '禁用',
  100. icon: 'fa fa-ban',
  101. classname: 'btn btn-xs btn-danger btn-ajax btn-disable',
  102. confirm: "一旦禁用,用户将无法访问链接,确定禁用?",
  103. url: $.fn.bootstrapTable.defaults.extend.disable_url,
  104. success: function (data) {
  105. table.bootstrapTable('refresh');
  106. }
  107. },
  108. {
  109. name: 'disable',
  110. text: '',
  111. title: '解禁',
  112. icon: 'fa fa-share',
  113. classname: 'btn btn-xs btn-success btn-ajax btn-goable',
  114. confirm: "一旦解除禁用,用户将正常访问链接,确定恢复?",
  115. url: $.fn.bootstrapTable.defaults.extend.disable_url,
  116. success: function (data) {
  117. table.bootstrapTable('refresh');
  118. }
  119. },
  120. ],
  121. formatter: Table.api.formatter.buttons
  122. },
  123. {field: 'tongji', title: __("查看"), operate: false,
  124. formatter: function (value, row, index) {
  125. return '<a style="float:left;margin-left: 10%" href="/admin/referral/vipreferral/viewdata?ids=' + row.id + '" class="btn btn-xs btn-success book_but">查看分流链接</a>';
  126. },
  127. },
  128. ]
  129. ],
  130. onPostBody: function () {
  131. //隐藏禁用操作按钮
  132. $.each(table.bootstrapTable("getData"), function (index, row) {
  133. if (row.state == "0") {
  134. //隐藏禁用按钮 显示解禁按钮
  135. $("a.btn-disable").eq(index).hide();
  136. $("a.btn-add-channels").eq(index).hide();
  137. $("a.btn-editone").eq(index).hide();
  138. } else {
  139. //隐藏解禁按钮 显示禁用按钮
  140. $("a.btn-goable").eq(index).hide();
  141. }
  142. });
  143. }
  144. });
  145. // 为表格绑定事件
  146. Table.api.bindevent(table);
  147. },
  148. viewdata: function () {
  149. // 初始化表格参数配置
  150. Table.api.init({
  151. extend: {
  152. index_url: 'referral/vipreferral/viewdata?ids='+ Config.id,
  153. add_url: 'referral/vipreferral/selectchannel',
  154. del_url: 'referral/vipreferral/del',
  155. export_url: '/admin/referral/vipreferral/viewdataexport?ids='+ Config.id,
  156. },
  157. showToggle: false,
  158. showColumns: false,
  159. visible: false,
  160. commonSearch: false,
  161. showExport: false,
  162. searchFormVisible: false,
  163. search: false
  164. });
  165. var table = $("#table");
  166. // 初始化表格
  167. table.bootstrapTable({
  168. url: $.fn.bootstrapTable.defaults.extend.index_url,
  169. pk: 'id',
  170. sortName: 'id',
  171. sortOrder: 'desc',
  172. columns: [
  173. [
  174. {field: 'id', title: 'ID'},
  175. {field: 'gzhname', title: '公众号名称'},
  176. {field: 'username', title: '用户名'},
  177. {field: 'nickname', title: '用户昵称'},
  178. {field: 'source_url', title: '推广链接', formatter: Controller.api.source_url_1, operate: false},
  179. {field: 'entry_page', title: '入口页面', formatter: Controller.api.entry_page_1, operate: false},
  180. {field: 'book_id', title: '书籍ID'},
  181. {field: 'book.name', title: '书籍名称', visible: false, operate: 'LIKE %...%'},
  182. {field: 'chapter_idx', title: '章节序号', visible: false, operate: false},
  183. {field: 'admin_id', title: __('Admin_id'), visible: false, operate: false},
  184. {field: 'name', title: __('Name'), operate: 'LIKE %...%'},
  185. {
  186. field: 'wx_type',
  187. title: __('Wx_type'),
  188. visible: false,
  189. searchList: {"wx_type 1": __('Wx_type 1'), "wx_type 2": __('Wx_type 2')},
  190. operate: false
  191. },
  192. {field: 'wx_type_text', title: __('Wx_type'), visible: false, operate: false},
  193. {
  194. field: 'type',
  195. title: __('Type'),
  196. visible: false,
  197. searchList: {"type 1": '阅读页推广', "type 2": '首页推广', 'type 3': '落地页推广'},
  198. operate: false
  199. },
  200. {field: 'type_text', title: __('Type'), visible: false, operate: false},
  201. {
  202. field: 'uv',
  203. title: '总阅读人数(今日)',
  204. operate: false,
  205. formatter: function (value, row, index) {
  206. return value + "(" + row.dayuv + ")";
  207. }
  208. },
  209. {
  210. field: 'follow',
  211. title: '总关注人数(今日)',
  212. operate: false,
  213. formatter: function (value, row, index) {
  214. var percent = daypercent= '0.0%';
  215. if (row.uv > 0) {
  216. percent = (value/row.uv) * 100;
  217. percent = percent.toFixed(1)+'%';
  218. }
  219. if (row.dayuv > 0) {
  220. daypercent = (row.dayut/row.dayuv) * 100;
  221. daypercent = daypercent.toFixed(1)+'%';
  222. }
  223. if (percent == '0.0%') {
  224. return value + "(" + row.dayut + ")";
  225. }
  226. return str = value + "(" + row.dayut + ")" + "<br> 关注率 "+percent+"("+daypercent+")";
  227. }
  228. },
  229. {
  230. field: 'net_follow_num',
  231. title: '总净关注人数(今日净关注人数)',
  232. operate: false,
  233. formatter: function (value, row, index) {
  234. return value + "(" + row.dayjt + ")";
  235. }
  236. },
  237. {
  238. field: 'guide_follow_num',
  239. title: '承接功能关注人数(今日)',
  240. operate: false,
  241. formatter: function (value, row, index) {
  242. return value + "(" + row.daydt + ")";
  243. }
  244. },
  245. {
  246. field: 'money',
  247. title: '总充值金额(今日)',
  248. operate: false,
  249. formatter: function (value, row, index) {
  250. return value + "(" + row.daymt + ")";
  251. }
  252. },
  253. {
  254. field: 'order_nums',
  255. title: '充值笔数/充值比例(今日)',
  256. operate: false,
  257. formatter: function (value, row, index) {
  258. var percent = daypercent= '0.0%';
  259. if (row.follow > 0) {
  260. percent = (value/row.follow) * 100;
  261. percent = percent.toFixed(1)+'%';
  262. }
  263. if (row.dayut > 0) {
  264. daypercent = (row.day_order_nums/row.dayut) * 100;
  265. daypercent = daypercent.toFixed(1)+'%';
  266. }
  267. return ''+ value + ' 笔/'+ percent +' <br>('+ row.day_order_nums+ ' 笔/'+daypercent+')';
  268. }
  269. },
  270. {field: 'cost', title: '推广成本', operate: false},
  271. {
  272. field: 'money',
  273. title: '利润',
  274. operate: false,
  275. formatter: function (value, row, index) {
  276. if (row.cost >0) {
  277. var lirun = value-row.cost;
  278. var percent = '0.00%';
  279. if (value > 0) {
  280. var percent = (value/row.cost) * 100;
  281. percent = percent.toFixed(2)+'%';
  282. }
  283. return lirun.toFixed(2) + "<br>回本率 " + percent;
  284. }
  285. return '-';
  286. }
  287. },
  288. {
  289. field: 'createtime',
  290. title: '创建时间',
  291. operate: 'RANGE',
  292. addclass: 'datetimerange',
  293. formatter: Table.api.formatter.datetime
  294. },
  295. {
  296. field: 'updatetime',
  297. title: '更新时间',
  298. visible: false,
  299. operate: false,
  300. addclass: 'datetimerange',
  301. formatter: Table.api.formatter.datetime
  302. },
  303. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
  304. ]
  305. ]
  306. });
  307. //获取选中数据
  308. $(document).on('click', ".btn-open-choose", function () {
  309. var url = 'referral/vipreferral/selectchannel';
  310. Fast.api.open(url, __('Add'), {
  311. callback: function (data) {
  312. if (data.length > 0) {
  313. var qdsIds = '';
  314. var doUrl = 'referral/vipreferral/doChoose/ids/'+Config.referral_id;
  315. for (var i in data) {
  316. qdsIds += data[i].qds_id + ',';
  317. }
  318. $.ajax({
  319. url: doUrl + '/qdsIds/' + qdsIds,
  320. type: 'get',
  321. success: function (res) {
  322. Toastr.success('操作成功');
  323. //刷新页面
  324. table.bootstrapTable('refresh');
  325. }
  326. });
  327. }
  328. }
  329. });
  330. });
  331. // $(document).on("click", '.qrcode', function () {
  332. // var qrUrl = $(this).data("qrcode");
  333. // $('#tong').html("");
  334. // $('#tong').qrcode(qrUrl);
  335. // layer.open({
  336. // type: 1,
  337. // title: false,
  338. // area: '258px',
  339. // skin: 'layui-layer-nobg', //没有背景色
  340. // shadeClose: true,
  341. // content: $('#tong')
  342. // });
  343. //
  344. // });
  345. // 为表格绑定事件
  346. Table.api.bindevent(table);
  347. },
  348. selectchannel: function() {
  349. // 初始化表格参数配置
  350. Table.api.init({
  351. extend: {
  352. index_url: 'referral/vipreferral/selectchannel?not_in_qds='+Config.not_in_qds
  353. },
  354. searchFormVisible: true,
  355. search: false,
  356. });
  357. var table = $("#table");
  358. // 初始化表格
  359. table.bootstrapTable({
  360. url: $.fn.bootstrapTable.defaults.extend.index_url,
  361. pk: 'id',
  362. sortName: 'vip_admin_bind.id',
  363. sortOrder: 'desc',
  364. columns: [
  365. [
  366. {checkbox: true},
  367. {field: 'bind_id', title: __('Id'), visible: false, operate: false},
  368. {field: 'wx_nickname', title: __('公众号名称')},
  369. {field: 'qds_id', title: __('账号ID'), operate: false},
  370. {field: 'qds_username', title: __('用户名')},
  371. {field: 'qds_nickname', title: __('用户昵称')},
  372. {field: 'operate', title: __('Operate'),
  373. events: {
  374. 'click .btn-chooseone': function (e, value, row, index) {
  375. Fast.api.close([row]);
  376. },
  377. }, formatter: function () {
  378. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  379. }
  380. }
  381. ]
  382. ]
  383. });
  384. // 为表格绑定事件
  385. Table.api.bindevent(table);
  386. //获取选中数据
  387. $(document).on('click', "#btn-chooseone", function () {
  388. var data = table.bootstrapTable('getSelections');
  389. if (data.length < 1) {
  390. Toastr.error('请选择公众号');
  391. } else {
  392. Fast.api.close(data);
  393. }
  394. });
  395. },
  396. add: function () {
  397. Controller.api.bindevent();
  398. },
  399. edit: function () {
  400. Controller.api.bindevent();
  401. },
  402. api: {
  403. bindevent: function () {
  404. Form.api.bindevent($("form[role=form]"));
  405. },
  406. source_url_1: function (value, row, index) {
  407. var html = [];
  408. html.push((row.wx_type == 1 ? '<b>认证公众号</b>' : '<b>未认证公众号</b>'));
  409. if (row.short_id > 0) {
  410. value = row.short_url;
  411. } else {
  412. if (Config.url_referral) {
  413. value = Config.url_referral + '/t/' + row.id;
  414. } else {
  415. value = row.url_referral;
  416. }
  417. }
  418. if (row.limited == 1) {
  419. html.push('<div class="link_txt">公众号阅读原文必选</div><div class="url_text">' + value);
  420. html.push('<div class="link_txt" style="padding:0 10px;background-color:red;color:#fff;font-weight:normal;display:inline-block;height:auto;">该链接对新用户已失效,无法进行推广</div></div>');
  421. } else {
  422. if (row.state == "1") {
  423. html.push('<div class="link_txt">公众号阅读原文必选</div><div class="url_text">' + value + '&nbsp;<i class="fa fa-copy copy" data-clipboard-text="' + value + '"></i>&nbsp;&nbsp;<i class="fa fa-qrcode qrcode" data-qrcode="' + value + '"></i>');
  424. html.push('<a href="javascript:;" class="short_link_but">点击显示短链</a><div class="short_link"><strong>腾讯短链:</strong>&nbsp;' + row.short_url_qq + '&nbsp;<i class="fa fa-copy copy" data-clipboard-text="' + row.short_url_qq + '"></i>&nbsp;&nbsp;<i class="fa fa-qrcode qrcode" data-qrcode="' + row.short_url_qq + '"></i>');
  425. html.push('<strong>微博短链:</strong>&nbsp;' + row.short_url_weibo + '&nbsp;<i class="fa fa-copy copy" data-clipboard-text="' + row.short_url_weibo + '"></i>&nbsp;&nbsp;<i class="fa fa-qrcode qrcode" data-qrcode="' + row.short_url_weibo + '"></i></div></div>');
  426. } else {
  427. html.push('<div class="link_txt">当前链接已失效,请禁止使用</div><div class="url_text">' + value + '</div>');
  428. }
  429. }
  430. return html.join('<br>');
  431. },
  432. entry_page_1: function (value, row, index) {
  433. var html = [];
  434. if (row.type == 1) {
  435. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  436. html.push(row.chapter_name);
  437. if (row.guide_chapter_idx) {
  438. html.push('关注章节:' + row.guide_chapter_idx);
  439. } else {
  440. html.push('关注章节:默认');
  441. }
  442. } else if (row.type == 3) {
  443. html.push('落地页推广');
  444. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  445. html.push(row.chapter_name);
  446. if (row.guide_chapter_idx) {
  447. html.push('关注章节:' + row.guide_chapter_idx);
  448. } else {
  449. html.push('关注章节:默认');
  450. }
  451. } else {
  452. html.push('书城首页推广');
  453. }
  454. return html.join('<br>');
  455. },
  456. events: {
  457. operate: {
  458. 'click .btn-editone': function (e, value, row, index) {
  459. e.stopPropagation();
  460. e.preventDefault();
  461. var table = $(this).closest('table');
  462. var options = table.bootstrapTable('getOptions');
  463. var ids = row[options.pk];
  464. row = $.extend({}, row ? row : {}, {ids: ids});
  465. var url = options.extend.edit_url;
  466. Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
  467. },
  468. 'click .btn-add-channels': function (e, value, row, index) {
  469. e.stopPropagation();
  470. e.preventDefault();
  471. var table = $(this).closest('table');
  472. var options = table.bootstrapTable('getOptions');
  473. var ids = row[options.pk];
  474. row = $.extend({}, row ? row : {}, {ids: ids});
  475. var url = options.extend.select_url;
  476. Fast.api.open(Table.api.replaceurl(url, row, table), __('Add'), {
  477. callback: function (data) {
  478. if (data.length > 0) {
  479. var qdsIds = '';
  480. var doUrl = options.extend.do_choose;
  481. doUrl = Table.api.replaceurl(doUrl, row, table);
  482. for (var i in data) {
  483. qdsIds += data[i].qds_id + ',';
  484. }
  485. $.ajax({
  486. url: doUrl + '/qdsIds/' + qdsIds,
  487. type: 'get',
  488. success: function (res) {
  489. Toastr.success('操作成功');
  490. //刷新页面
  491. table.bootstrapTable('refresh');
  492. }
  493. });
  494. }
  495. }
  496. });
  497. },
  498. }
  499. },
  500. source_url: function (value, row, index) {
  501. var html = [];
  502. value = row.short_url;
  503. if (row.state == 0) {
  504. html.push('<div class="link_txt">当前链接已失效,请禁止使用</div><div class="url_text">');
  505. } else {
  506. if(value.length < 10) {
  507. html.push('<div class="link_txt">请先选择渠道</div><div class="url_text">');
  508. } else {
  509. if (row.limited == 1) {
  510. html.push('<div class="link_txt">公众号阅读原文必选</div><div class="url_text">' + value);
  511. html.push('<div class="link_txt" style="padding:0 10px;background-color:red;color:#fff;font-weight:normal;display:inline-block;height:auto;">该链接对新用户已失效,无法进行推广</div></div>');
  512. } else {
  513. if (row.state == "1") {
  514. html.push('<div class="link_txt">公众号阅读原文必选</div><div class="url_text">' + value + '&nbsp;<i class="fa fa-copy copy" data-clipboard-text="' + value + '"></i>&nbsp;&nbsp;<i style="margin:5px 0;" class="fa fa-qrcode qrcode" data-qrcode="'+value+'"></i>');
  515. } else {
  516. html.push('<div class="link_txt">当前链接已失效,请禁止使用</div><div class="url_text">' + value + '</div>');
  517. }
  518. }
  519. }
  520. }
  521. return html.join('<br>');
  522. },
  523. entry_page: function (value, row, index) {
  524. var html = [];
  525. if (row.type == 1) {
  526. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  527. html.push(row.chapter_name);
  528. if (row.guide_chapter_idx) {
  529. html.push('关注章节:' + row.guide_chapter_idx);
  530. } else {
  531. html.push('关注章节:默认');
  532. }
  533. } else if (row.type == 3) {
  534. html.push('落地页推广');
  535. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  536. html.push(row.chapter_name);
  537. if (row.guide_chapter_idx) {
  538. html.push('关注章节:' + row.guide_chapter_idx);
  539. } else {
  540. html.push('关注章节:默认');
  541. }
  542. } else {
  543. html.push('书城首页推广');
  544. }
  545. return html.join('<br>');
  546. },
  547. index_operate: function (value, row, index) {
  548. var row_id = row.id
  549. return
  550. }
  551. }
  552. };
  553. return Controller;
  554. });