platform.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. Date.prototype.Format = function (fmt) { // author: meizz
  3. var o = {
  4. "M+": this.getMonth() + 1, // 月份
  5. "d+": this.getDate(), // 日
  6. "h+": this.getHours(), // 小时
  7. "m+": this.getMinutes(), // 分
  8. "s+": this.getSeconds(), // 秒
  9. "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
  10. "S": this.getMilliseconds() // 毫秒
  11. };
  12. if (/(y+)/.test(fmt))
  13. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  14. for (var k in o)
  15. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  16. return fmt;
  17. }
  18. //选择平台的js
  19. var Controller = {
  20. index: function () {
  21. // 初始化表格参数配置
  22. Table.api.init({
  23. extend: {
  24. index_url: 'platform/index',
  25. add_url: 'platform/add',
  26. edit_url: 'platform/edit',
  27. // del_url: 'platform/del',
  28. multi_url: 'platform/multi',
  29. table: 'platform',
  30. }
  31. });
  32. var table = $("#table");
  33. // 初始化表格
  34. table.bootstrapTable({
  35. url: $.fn.bootstrapTable.defaults.extend.index_url,
  36. pk: 'id',
  37. sortName: 'id',
  38. columns: [
  39. [
  40. {checkbox: true},
  41. {field: 'id', title: __('Id')},
  42. {field: 'name', title: __('Name')},
  43. {field: 'authhost', title: __('Authhost')},
  44. {field: 'status', title: __('Status'), visible:false, searchList: {"0":__('Status 0'),"1":__('Status 1')}},
  45. {field: 'status_text', title: __('Status'), operate:false, operate:false},
  46. {field: 'isdefault', title: __('Isdefault'), visible:false, searchList: {"0":__('Isdefault 0'),"1":__('Isdefault 1')}},
  47. {field: 'isdefault_text', title: __('Isdefault'), operate:false, operate:false},
  48. {field: 'appid', title: __('Appid')},
  49. {field: 'secret', title: __('Secret'), operate:false},
  50. {field: 'token', title: __('Token'), operate:false},
  51. {field: 'aes_key', title: __('Aes_key'), operate:false},
  52. {field: 'platfile', title: __('Platfile'), operate:false},
  53. {field: 'p_desc', title: __('描述'), operate:false},
  54. {field: 'proxy_config', title: __('代理IP'), visible:true, operate: 'LIKE %...%'},
  55. {field: 'job_proxy_config', title: __('Job推送代理IP'), visible:true, operate: 'LIKE %...%'},
  56. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
  57. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, operate:false},
  58. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  59. ]
  60. ]
  61. });
  62. // 为表格绑定事件
  63. Table.api.bindevent(table);
  64. },
  65. add: function () {
  66. Controller.api.isdefault();
  67. Controller.api.bindevent();
  68. },
  69. edit: function () {
  70. Controller.api.isdefault();
  71. Controller.api.bindevent();
  72. },
  73. // switchmenuhost:function(){
  74. // //选择业务域名&菜单业务域名
  75. // var op_list = [
  76. // {host_key:"c-menuophost_id",pay_key:"c-menuwxpay_id"},
  77. // {host_key:"c-new_menuophost_id",pay_key:"c-new_menuwxpay_id"}
  78. // ];
  79. // $.each(op_list,function(index,data){
  80. // $('#'+data.host_key).change(function () {
  81. // var ophost_id = $(this).val();
  82. // var platform_id =$("#"+data.host_key+" option[value='"+ophost_id+"']").data('platform_id');
  83. // if(ophost_id && ophost_id != undefined && platform_id && platform_id != undefined){
  84. // Controller.api.addOphostPayList(platform_id,ophost_id,data.pay_key);
  85. // }else{
  86. // Controller.api.delWxpayList(data.pay_key);
  87. // }
  88. // });
  89. // });
  90. // Form.api.bindevent($("form[role=form]"),
  91. // function (data,result) {
  92. // Controller.api.showResultWindow(data);
  93. // return false;
  94. // },
  95. // function (data,result) {
  96. // layer.alert(result.msg);
  97. // return false;
  98. // }
  99. // );
  100. // },
  101. // switchophost:function(){
  102. // //选择业务域名&菜单业务域名
  103. // var op_list = [
  104. // {host_key:"c-ophost_id",pay_key:"c-wxpay_id"},
  105. // {host_key:"c-new_ophost_id",pay_key:"c-new_wxpay_id"},
  106. // ];
  107. // $.each(op_list,function(index,data){
  108. // $('#'+data.host_key).change(function () {
  109. // var ophost_id = $(this).val();
  110. // var platform_id =$("#"+data.host_key+" option[value='"+ophost_id+"']").data('platform_id');
  111. // if(ophost_id && ophost_id != undefined && platform_id && platform_id != undefined){
  112. // Controller.api.addOphostPayList(platform_id,ophost_id,data.pay_key);
  113. // }else{
  114. // Controller.api.delWxpayList(data.pay_key);
  115. // }
  116. // });
  117. // });
  118. // Form.api.bindevent($("form[role=form]"),
  119. // function (data,result) {
  120. // Controller.api.showResultWindow(data);
  121. // return false;
  122. // },
  123. // function (data,result) {
  124. // layer.alert(result.msg);
  125. // return false;
  126. // }
  127. // );
  128. // },
  129. switchplatform:function(){
  130. $("form[role=form]").validator({
  131. valid: function(form) {
  132. var is_post = true;
  133. $('#c-create_by-id').isValid(function(v){
  134. if (!v) {is_post = false;}
  135. });
  136. $('#c-nickname').isValid(function(v){
  137. if (!v) {is_post = false;}
  138. });
  139. if(is_post){
  140. var post_data = $(form).serializeArray();
  141. var search_data = $('#search-form').serializeArray();
  142. $.post(location.href,post_data.concat(search_data),function(result){
  143. if(result.code){
  144. Controller.api.showResultWindow(result.data);
  145. }else{
  146. layer.alert(result.msg);
  147. }
  148. })
  149. }
  150. }
  151. });
  152. },
  153. api: {
  154. //添加支付域名列表
  155. addOphostPayList:function(platform_id,ophost_id,wxpayName){
  156. $.get("auth/channel/ajaxgetwxpaylistbyplatformid?platform_id=" + platform_id+'&ophost_id='+ophost_id, function (data) {
  157. if (data.code) {
  158. Controller.api.delWxpayList(wxpayName);
  159. var pay_list = data.data;
  160. for (var key in pay_list) {
  161. $('#'+wxpayName).append("<option data-platform_id='"+ platform_id +"' value='" + pay_list[key]['id'] + "' >" + pay_list[key]['text'] + "</option><br>");
  162. }
  163. }else{
  164. Toastr.error(data.msg);
  165. }
  166. });
  167. },
  168. showResultWindow:function(data){
  169. var html = "<p align='center' style='color:coral'>符合条件的总数为:"+data.total+"个</p>";
  170. html += "<p align='center' style='color:peru;'>没有授权的总数为:"+data.unauthorized+"个</p>";
  171. html += "<p align='center' style='color:peru;'>平台不符的总数为:"+data.platform+"个</p>";
  172. html += "<p align='center' style='color:green;'>切换成功的总数为:"+data.success+"个</p>";
  173. html += "<p align='center' style='color:red;'>切换失败的总数为:"+data.fail+"个</p>";
  174. if(data.export == true){
  175. layer.confirm(html, {
  176. btn: ['导出切换渠道','不导出切换渠道'] //按钮
  177. }, function(){
  178. window.location.href = "/admin/platform/export"
  179. layer.close(layer.index)
  180. }, function(){
  181. });
  182. }else{
  183. layer.alert(html);
  184. }
  185. },
  186. delWxpayList:function(wxpayName){
  187. $("#"+wxpayName+" option").remove();
  188. $("#"+wxpayName).append("<option value='' selected>请选择</option><br>");
  189. },
  190. bindevent: function () {
  191. Form.api.bindevent($("form[role=form]"));
  192. },
  193. isdefault:function (){
  194. $("#c-isdefault").change(function(){
  195. if($(this).val()==1){
  196. if(!confirm("确定修改为默认吗?")){
  197. $(this).val(0);
  198. }
  199. }
  200. });
  201. }
  202. }
  203. };
  204. return Controller;
  205. });