vipactivity.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. $(document).on('click','.btn-edit-row',function(){
  11. //btn-edit-row
  12. Fast.api.open($(this).data('href'), "编辑活动", {
  13. callback: function (data) {
  14. if(data.code){
  15. window.location.reload();
  16. }
  17. }
  18. });
  19. });
  20. var Controller = {
  21. showActivityField:function(table){
  22. var field = new Array();
  23. field.push({checkbox: true});
  24. field.push({field: 'id', title: __('Id')});
  25. field.push({field: 'name', title: __('活动名称'), operate: 'LIKE %...%'});
  26. field.push({field: 'copywriting', title: __('活动文案'), operate: 'LIKE %...%'});
  27. field.push({field: 'starttime', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime});
  28. field.push({field: 'endtime', title: __('结束时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime});
  29. field.push({field:'status', title:'活动状态',formatter: Controller.api.formatter.activitstatus, operate:false});
  30. field.push({field:'money',title:'今日充值',formatter:Controller.api.formatter.money, operate:false});
  31. field.push({field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney, operate:false});
  32. field.push({field: 'operate', title: __('Operate'), table: table, events: Controller.api.events.operate, buttons: [
  33. {
  34. name: 'operate',
  35. text: __('添加渠道账号'),
  36. title: __('添加渠道账号'),
  37. classname: 'btn btn-xs btn-primary btn-add-channels',
  38. icon: 'fa fa-list',
  39. },
  40. {
  41. name: 'operate',
  42. text: __('指定渠道分组'),
  43. title: __('指定渠道分组'),
  44. classname: 'btn btn-xs btn-success btn-add-group',
  45. icon: 'fa fa-pencil',
  46. }
  47. ],
  48. formatter: Table.api.formatter.buttons
  49. });
  50. field.push({field: 'chakan', title: __("查看"), operate: false,
  51. formatter: function (value, row, index) {
  52. var str = '';
  53. if (row.endtime > Config.time && row.starttime > Config.time) {
  54. //未开始的
  55. str += '<a data-href="/admin/activity/edit?type=1&ids='+row.id+'" href="javascript:;" class="btn btn-xs btn-success btn-edit-row" title="" data-table-id="table" data-field-index="12" data-row-index="0" data-button-index="1"><i class="fa fa-pencil"></i></a>';
  56. }
  57. return str +'<a style="float:left;margin-left: 10%" href="vipactivity/viewdata?ids=' + row.id + '" class="btn btn-xs btn-success book_but">查看</a>';
  58. },
  59. })
  60. return field;
  61. },
  62. showChannelActivityField:function(table){
  63. var field = new Array();
  64. field.push({checkbox: true});
  65. field.push({field: 'id', title: __('Id')});
  66. field.push({field: 'admin_id', title: __('渠道ID')});
  67. field.push({field: 'name', title: __('活动名称')});
  68. field.push({field: 'copywriting', title: __('活动文案')});
  69. field.push({field: 'starttime', title: __('开始时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime});
  70. field.push({field: 'endtime', title: __('结束时间'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime});
  71. field.push({field:'money',title:'今日充值',formatter:Controller.api.formatter.money});
  72. field.push({field:'allmoney',title:'累计充值',formatter:Controller.api.formatter.allmoney});
  73. field.push({field:'status', title:'活动状态',formatter: Controller.api.formatter.activitstatus});
  74. return field;
  75. },
  76. index: function () {
  77. // 初始化表格参数配置
  78. Table.api.init({
  79. extend: {
  80. index_url: 'vipactivity/index',
  81. add_url: 'activity/add?type='+Config.activity_type,
  82. table: 'activity',
  83. do_choose: 'vipactivity/doChoose',
  84. select_url: 'referral/vipreferral/selectchannel',
  85. disable_url: 'referral/referral/disable?isVip=1'
  86. }
  87. });
  88. var table = $("#table");
  89. // 初始化表格
  90. table.bootstrapTable({
  91. url: $.fn.bootstrapTable.defaults.extend.index_url,
  92. pk: 'id',
  93. sortName: 'id',
  94. columns: [Controller.showActivityField(table)]
  95. });
  96. // 为表格绑定事件
  97. Table.api.bindevent(table);
  98. },
  99. viewdata: function () {
  100. // 初始化表格参数配置
  101. Table.api.init({
  102. extend: {
  103. index_url: 'vipactivity/viewdata?ids='+ Config.id,
  104. add_url: 'referral/vipreferral/selectchannel',
  105. },
  106. showToggle: false,
  107. showColumns: false,
  108. visible: false,
  109. commonSearch: false,
  110. showExport: false,
  111. searchFormVisible: false,
  112. search: false
  113. });
  114. var table = $("#table");
  115. // 初始化表格
  116. // 初始化表格
  117. table.bootstrapTable({
  118. url: $.fn.bootstrapTable.defaults.extend.index_url,
  119. pk: 'id',
  120. sortName: 'id',
  121. columns: [Controller.showChannelActivityField(table)]
  122. });
  123. //获取选中数据
  124. $(document).on('click', ".btn-open-choose", function () {
  125. var url = 'referral/vipreferral/selectchannel';
  126. Fast.api.open(url, __('Add'), {
  127. callback: function (data) {
  128. if (data.length > 0) {
  129. var qdsIds = '';
  130. var doUrl = 'vipactivity/doChoose/ids/'+Config.referral_id;
  131. for (var i in data) {
  132. qdsIds += data[i].qds_id + ',';
  133. }
  134. $.ajax({
  135. url: doUrl + '/qdsIds/' + qdsIds,
  136. type: 'get',
  137. success: function (res) {
  138. Toastr.success('操作成功');
  139. //刷新页面
  140. table.bootstrapTable('refresh');
  141. }
  142. });
  143. }
  144. }
  145. });
  146. });
  147. // 为表格绑定事件
  148. Table.api.bindevent(table);
  149. },
  150. selectchannel: function() {
  151. // 初始化表格参数配置
  152. Table.api.init({
  153. extend: {
  154. index_url: 'referral/vipreferral/selectchannel'
  155. },
  156. searchFormVisible: true,
  157. search: false,
  158. });
  159. var table = $("#table");
  160. // 初始化表格
  161. table.bootstrapTable({
  162. url: $.fn.bootstrapTable.defaults.extend.index_url,
  163. pk: 'id',
  164. sortName: 'vip_admin_bind.id',
  165. sortOrder: 'desc',
  166. columns: [
  167. [
  168. {checkbox: true},
  169. {field: 'bind_id', title: __('Id'), visible: false, operate: false},
  170. {field: 'wx_nickname', title: __('公众号名称')},
  171. {field: 'qds_id', title: __('账号ID'), operate: false},
  172. {field: 'qds_username', title: __('用户名')},
  173. {field: 'qds_nickname', title: __('用户昵称')},
  174. {field: 'operate', title: __('Operate'),
  175. events: {
  176. 'click .btn-chooseone': function (e, value, row, index) {
  177. Fast.api.close([row]);
  178. },
  179. }, formatter: function () {
  180. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  181. }
  182. }
  183. ]
  184. ]
  185. });
  186. // 为表格绑定事件
  187. Table.api.bindevent(table);
  188. //获取选中数据
  189. $(document).on('click', "#btn-chooseone", function () {
  190. var data = table.bootstrapTable('getSelections');
  191. if (data.length < 1) {
  192. Toastr.error('请选择公众号');
  193. } else {
  194. Fast.api.close(data);
  195. }
  196. });
  197. },
  198. add: function () {
  199. Controller.api.bindevent();
  200. },
  201. edit: function () {
  202. Controller.api.bindevent();
  203. },
  204. api: {
  205. bindevent: function () {
  206. Form.api.bindevent($("form[role=form]"));
  207. },
  208. formatter: {
  209. activitstatus: function (value, row, index) {
  210. if(row.starttime > Config.time){
  211. return '未开始';
  212. }else if (row.starttime<Config.time && row.endtime>Config.time){
  213. return '进行中';
  214. }else if (row.endtime < Config.time){
  215. return '已结束';
  216. }
  217. },
  218. money:function(value, row, index) {
  219. if (value){
  220. return value;
  221. }else{
  222. return '0.00';
  223. }
  224. },
  225. allmoney:function(value, row, index) {
  226. if (value){
  227. return value;
  228. }else{
  229. return '0.00';
  230. }
  231. },
  232. },
  233. source_url_1: function (value, row, index) {
  234. var html = [];
  235. html.push((row.wx_type == 1 ? '<b>认证公众号</b>' : '<b>未认证公众号</b>'));
  236. if (row.short_id > 0) {
  237. value = row.short_url;
  238. } else {
  239. if (Config.url_referral) {
  240. value = Config.url_referral + '/t/' + row.id;
  241. } else {
  242. value = row.url_referral;
  243. }
  244. }
  245. if (row.limited == 1) {
  246. html.push('<div class="link_txt">公众号阅读原文必选</div><div class="url_text">' + value);
  247. 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>');
  248. } else {
  249. if (row.state == "1") {
  250. 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>');
  251. 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>');
  252. 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>');
  253. } else {
  254. html.push('<div class="link_txt">当前链接已失效,请禁止使用</div><div class="url_text">' + value + '</div>');
  255. }
  256. }
  257. return html.join('<br>');
  258. },
  259. entry_page_1: function (value, row, index) {
  260. var html = [];
  261. if (row.type == 1) {
  262. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  263. html.push(row.chapter_name);
  264. if (row.guide_chapter_idx) {
  265. html.push('关注章节:' + row.guide_chapter_idx);
  266. } else {
  267. html.push('关注章节:默认');
  268. }
  269. } else if (row.type == 3) {
  270. html.push('落地页推广');
  271. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  272. html.push(row.chapter_name);
  273. if (row.guide_chapter_idx) {
  274. html.push('关注章节:' + row.guide_chapter_idx);
  275. } else {
  276. html.push('关注章节:默认');
  277. }
  278. } else {
  279. html.push('书城首页推广');
  280. }
  281. return html.join('<br>');
  282. },
  283. events: {
  284. operate: {
  285. 'click .btn-editone': function (e, value, row, index) {
  286. e.stopPropagation();
  287. e.preventDefault();
  288. var table = $(this).closest('table');
  289. var options = table.bootstrapTable('getOptions');
  290. var ids = row[options.pk];
  291. row = $.extend({}, row ? row : {}, {ids: ids});
  292. var url = options.extend.edit_url;
  293. Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
  294. },
  295. 'click .btn-add-channels': function (e, value, row, index) {
  296. e.stopPropagation();
  297. e.preventDefault();
  298. var table = $(this).closest('table');
  299. var options = table.bootstrapTable('getOptions');
  300. var ids = row[options.pk];
  301. row = $.extend({}, row ? row : {}, {ids: ids});
  302. var url = options.extend.select_url+'?not_in_qds='+row.channel_ids;
  303. Fast.api.open(Table.api.replaceurl(url, row, table), __('Add'), {
  304. callback: function (data) {
  305. if (data.length > 0) {
  306. var qdsIds = '';
  307. var doUrl = options.extend.do_choose;
  308. doUrl = Table.api.replaceurl(doUrl, row, table);
  309. for (var i in data) {
  310. qdsIds += data[i].qds_id + ',';
  311. }
  312. $.ajax({
  313. url: doUrl + '/qdsIds/' + qdsIds,
  314. type: 'get',
  315. success: function (res) {
  316. var data = JSON.parse(res);
  317. if (data.fail) {
  318. console.log(data.fail);
  319. Toastr.error(data.fail);
  320. } else {
  321. Toastr.success('操作成功');
  322. }
  323. //刷新页面
  324. table.bootstrapTable('refresh');
  325. }
  326. });
  327. }
  328. }
  329. });
  330. },
  331. 'click .btn-add-group':function (e, value, row, index) {
  332. e.stopPropagation();
  333. e.preventDefault();
  334. var table = $(this).closest('table');
  335. var options = table.bootstrapTable('getOptions');
  336. var ids = row[options.pk];
  337. row = $.extend({}, row ? row : {}, {ids: ids});
  338. var url = '/admin/vip/admin/group/select?not_in_ids=';
  339. Fast.api.open(Table.api.replaceurl(url, row, table), __('Add'), { callback: function (data) {
  340. if (data.length > 0) {
  341. var groupIds = '';
  342. for (var i in data) {
  343. groupIds += data[i].id + ',';
  344. }
  345. var doUrl = options.extend.do_choose;
  346. doUrl = Table.api.replaceurl(doUrl, row, table);
  347. $.ajax({
  348. url: doUrl + '/groupIds/' + groupIds,
  349. type: 'get',
  350. success: function (res) {
  351. var data = JSON.parse(res);
  352. if (data.fail) {
  353. console.log(data.fail);
  354. Toastr.error(data.fail);
  355. } else {
  356. Toastr.success('操作成功');
  357. }
  358. //刷新页面
  359. table.bootstrapTable('refresh');
  360. }
  361. });
  362. }
  363. }
  364. });
  365. }
  366. }
  367. },
  368. source_url: function (value, row, index) {
  369. var html = [];
  370. value = row.short_url;
  371. if (row.state == 0) {
  372. html.push('<div class="link_txt">当前链接已失效,请禁止使用</div><div class="url_text">');
  373. } else {
  374. if(value.length < 10) {
  375. html.push('<div class="link_txt">请先选择渠道</div><div class="url_text">');
  376. } else {
  377. if (row.limited == 1) {
  378. html.push('<div class="link_txt">公众号阅读原文必选</div><div class="url_text">' + value);
  379. 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>');
  380. } else {
  381. if (row.state == "1") {
  382. 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>');
  383. } else {
  384. html.push('<div class="link_txt">当前链接已失效,请禁止使用</div><div class="url_text">' + value + '</div>');
  385. }
  386. }
  387. }
  388. }
  389. return html.join('<br>');
  390. },
  391. entry_page: function (value, row, index) {
  392. var html = [];
  393. if (row.type == 1) {
  394. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  395. html.push(row.chapter_name);
  396. if (row.guide_chapter_idx) {
  397. html.push('关注章节:' + row.guide_chapter_idx);
  398. } else {
  399. html.push('关注章节:默认');
  400. }
  401. } else if (row.type == 3) {
  402. html.push('落地页推广');
  403. html.push('<a href="/admin/referral/book/info?id=' + row.book_id + '">' + row.book_name + '</a>');
  404. html.push(row.chapter_name);
  405. if (row.guide_chapter_idx) {
  406. html.push('关注章节:' + row.guide_chapter_idx);
  407. } else {
  408. html.push('关注章节:默认');
  409. }
  410. } else {
  411. html.push('书城首页推广');
  412. }
  413. return html.join('<br>');
  414. },
  415. index_operate: function (value, row, index) {
  416. var row_id = row.id
  417. return
  418. }
  419. }
  420. };
  421. return Controller;
  422. });