agent_edit.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. layui.use(['form', 'mhttp', 'jquery', 'table'], function () {
  2. let form = layui.form;
  3. let http = layui.mhttp;
  4. let table = layui.table;
  5. let $ = layui.jquery;
  6. let loading = layer.msg('加载数据中...', {icon: 16, time: 0, shade: 0.3, shadeClose: false});
  7. let agent_uid = GetQueryString('agent_uid');
  8. let postData = {uid: agent_uid};
  9. // 查询应用
  10. let appRet = http.ajax({
  11. url: '/app/all'
  12. });
  13. appRet.then((data) => {
  14. if (data.code === 200) {
  15. let html = '';
  16. for (let i in data.data) {
  17. html += '<input type="checkbox" value="' + data.data[i].uid + '" class="che_' + data.data[i].uid + '" name="own_app_uids" title="' + data.data[i].name + '">';
  18. }
  19. $('.own_app_uids').html(html);
  20. form.render();
  21. // 执行完app请求在执行查询信息,避免回显选择问题
  22. let ret = http.ajax({
  23. url: '/agent/detail',
  24. data: postData
  25. });
  26. ret.then((data) => {
  27. layer.close(loading);
  28. // 成功显示数据
  29. if (data.code === 200) {
  30. $('.uid').val(data.data.uid);
  31. $('.nick').val(data.data.nick);
  32. $('.username').val(data.data.username);
  33. $('.commission_ratio').val(data.data.commission_ratio);
  34. $('.preferential_order').val(data.data.preferential_order);
  35. $('.cpa_price').val(data.data.cpa_price);
  36. $('.cpa_deduction_rule').val(data.data.cpa_deduction_rule);
  37. // withdraw_amount: data.field.withdraw_amount,
  38. // withdraw_usdt: data.field.withdraw_usdt,
  39. if (data.data.withdraw_amount !==0){
  40. $('.withdraw_amount').val(data.data.withdraw_amount);
  41. }
  42. if (data.data.withdraw_usdt !==0){
  43. $('.withdraw_usdt').val(data.data.withdraw_usdt);
  44. }
  45. // 银行卡
  46. if (data.data.bank_info.length > 0) {
  47. for (let i in data.data.bank_info){
  48. let item = data.data.bank_info[i];
  49. if(item.type === 1){
  50. // 银行卡
  51. $('#type_1 .bank_card').html(item.bank_card);
  52. $('#type_1 .bank_account').text(item.bank_account);
  53. $('#type_1 .bank_mark').text(item.bank_mark);
  54. $('#type_1 .type').text(item.type_name);
  55. $('#type_1 .bank_edit').attr('uid',item.uid);
  56. $('#type_1 .bank_edit').html('<a>删除</a>');
  57. $('#type_1').css('display','revert');
  58. }else if (item.type === 2){
  59. // usdt
  60. $('#type_2 .bank_mark').html(item.ustd_network);
  61. $('#type_2 .bank_account').text(item.ustd_account);
  62. $('#type_2 .type').text(item.type_name);
  63. $('#type_2 .bank_edit').attr('uid',item.uid);
  64. $('#type_2 .bank_edit').html('<a>删除</a>');
  65. $('#type_2').css('display','revert');
  66. }else if (item.type === 3){
  67. $('#type_3 .bank_card').html(item.alipay_username);
  68. $('#type_3 .bank_account').text(item.alipay_account);
  69. $('#type_3 .type').text(item.type_name);
  70. $('#type_3 .bank_edit').attr('uid',item.uid);
  71. $('#type_3 .bank_edit').html('<a>删除</a>');
  72. $('#type_3').css('display','revert');
  73. }
  74. }
  75. }
  76. if (data.data.status === 1) {
  77. $('.status').attr('checked', 'checked')
  78. }
  79. switch (data.data.deduction_switch) {
  80. case 0:
  81. $('#deductionSwitch0').prop("checked", true);
  82. break;
  83. case 1:
  84. $('#deductionSwitch1').prop("checked", true);
  85. break;
  86. case 2:
  87. $('#deductionSwitch2').prop("checked", true);
  88. break;
  89. case 3:
  90. $('#deductionSwitch3').prop("checked", true);
  91. break;
  92. }
  93. jdata = JSON.parse(data.data.jdata);
  94. let deduction_price_obg = jdata.deduction_price;
  95. let deduction_number_obg = jdata.deduction_number;
  96. if (typeof(deduction_price_obg) != 'undefined') {
  97. if (deduction_price_obg.length > 0) {
  98. let priceHtml = '';
  99. for (let i in deduction_price_obg) {
  100. if (i == 0) {
  101. priceHtml = deduction_price_obg[i].min_price + '-' + deduction_price_obg[i].max_price;
  102. } else {
  103. priceHtml += ',' + deduction_price_obg[i].min_price + '-' + deduction_price_obg[i].max_price;
  104. }
  105. }
  106. $('.deduction_price').val(priceHtml);
  107. }
  108. if (deduction_number_obg.length > 0) {
  109. let numberHtml = '';
  110. for (let i in deduction_number_obg) {
  111. if (i == 0) {
  112. numberHtml = deduction_number_obg[i].number + '-' + deduction_number_obg[i].deduction;
  113. } else {
  114. numberHtml += ',' + deduction_number_obg[i].number + '-' + deduction_number_obg[i].deduction;
  115. }
  116. }
  117. $('.deduction_number').val(numberHtml);
  118. }
  119. }
  120. form.render();
  121. // app选中处理
  122. let app_uids = data.data.own_app_uids.split(',');
  123. for (let index in app_uids) {
  124. $('.own_app_uids .che_' + app_uids[index]).attr('checked', 'checked');
  125. }
  126. form.render();
  127. } else {
  128. layer.msg(data.message, {
  129. // 失败关闭父窗口
  130. icon: 2,
  131. time: 1000
  132. }, function () {
  133. let index = parent.layer.getFrameIndex(window.name);
  134. parent.layer.close(index);
  135. });
  136. }
  137. });
  138. } else {
  139. $('.own_app_uids').append('<span class="app-error">获取应用失败,刷新重试!</span>');
  140. }
  141. });
  142. $('#back_info').on('click','.bank_edit',function () {
  143. let uid = $(this).attr('uid');
  144. if (uid) {
  145. let msg = layer.confirm('确定要删除该提现方式?', {
  146. icon: 3,
  147. title: '请确认'
  148. }, function () {
  149. let load = layer.msg('删除中请稍等!');
  150. let postData = {
  151. uid: uid
  152. };
  153. let ret = http.ajax({
  154. url: '/finance/withdraw/bank/del',
  155. data: postData,
  156. });
  157. ret.then((data) => {
  158. layer.close(load);
  159. if (data.code === 200) {
  160. layer.msg(data.message, {icon: 1, time: 1000});
  161. $(this).parent('tr').remove()
  162. layer.msg(data.message, {
  163. icon: 1,
  164. time: 1000
  165. }, function () {
  166. let index = parent.layer.getFrameIndex(window.name);
  167. parent.layer.close(index);
  168. });
  169. } else {
  170. layer.msg(data.message, {icon: 2, time: 1000});
  171. }
  172. });
  173. });
  174. }
  175. });
  176. form.on('submit(agent-save)', function (data) {
  177. if (data.field.password || data.field.rePassword) {
  178. if (data.field.password !== data.field.rePassword) {
  179. layer.msg('两次密码不一致 !');
  180. return false;
  181. }
  182. if (data.field.password < 6) {
  183. layer.msg('密码长度在6位以上 !');
  184. return false;
  185. }
  186. }
  187. if (data.field.withdraw_pwd) {
  188. if (data.field.withdraw_pwd < 6) {
  189. layer.msg('提现密码长度在6位以上 !');
  190. return false;
  191. }
  192. }
  193. let commission_ratio = parseInt(data.field.commission_ratio);
  194. if (commission_ratio > 100 || commission_ratio < 0) {
  195. layer.msg('分成比例在0-100!');
  196. return false;
  197. }
  198. let own_app_uids = '';
  199. $('.own_app_uids input:checked').each(function (index) {
  200. if (index === 0) {
  201. own_app_uids = $(this).val();
  202. } else {
  203. own_app_uids += ',' + $(this).val();
  204. }
  205. });
  206. if (own_app_uids.length <= 0) {
  207. layer.msg('应用必须选择一个!');
  208. return false;
  209. }
  210. let deduction_switch = data.field.deduction_switch;
  211. if (deduction_switch == 1) {
  212. if (!data.field.deduction_price || !data.field.deduction_number) {
  213. layer.msg('请核对扣量价格和扣量数量!');
  214. return false;
  215. } else {
  216. if (data.field.deduction_price.search(',') != -1) {
  217. layer.confirm('检测到扣量价格有","是否替换为以","分隔?', {
  218. icon: 3,
  219. title: '提示'
  220. }, function (index) {
  221. layer.close(index);
  222. $('.deduction_price').val(data.field.deduction_price.replace(/,/g, ","));
  223. layer.msg('已替换请再次确认!');
  224. });
  225. return false;
  226. }
  227. if (data.field.deduction_number.search(',') != -1) {
  228. layer.confirm('检测扣量数量格有","是否替换为以","分隔?', {
  229. icon: 3,
  230. title: '提示'
  231. }, function (index) {
  232. layer.close(index);
  233. $('.deduction_number').val(data.field.deduction_price.replace(/,/g, ","));
  234. layer.msg('已替换请再次确认!');
  235. });
  236. return false;
  237. }
  238. }
  239. }
  240. if (deduction_switch == 2 && (!data.field.cpa_deduction_rule || !data.field.cpa_price)) {
  241. layer.msg('选择cpa类型后,请填写对应的cpa扣量规则和cpa单价价格!');
  242. return false;
  243. }
  244. let deductionPriceObg = [];
  245. if (data.field.deduction_price) {
  246. let priceArray = data.field.deduction_price.split(',');
  247. for (let i in priceArray) {
  248. let priceArrayItem = priceArray[i].split('-');
  249. deductionPriceObg.push({
  250. min_price: priceArrayItem[0],
  251. max_price: priceArrayItem[1],
  252. })
  253. }
  254. }
  255. let deductionNumberObg = [];
  256. if (data.field.deduction_number) {
  257. let numberArray = data.field.deduction_number.split(',');
  258. for (let i in numberArray) {
  259. let numberArrayItem = numberArray[i].split('-');
  260. deductionNumberObg.push({
  261. number: numberArrayItem[0],
  262. deduction: numberArrayItem[1],
  263. })
  264. }
  265. }
  266. if (deductionPriceObg.length !== deductionNumberObg.length) {
  267. layer.msg('扣量价格与扣量数量对映不上!');
  268. return false;
  269. }
  270. let createLoading = layer.load();
  271. let postData = {
  272. uid: data.field.uid,
  273. username: data.field.username,
  274. nick: data.field.nick,
  275. preferential_order: data.field.preferential_order,
  276. withdraw_pwd: data.field.withdraw_pwd,
  277. role_id: 1,
  278. status: data.field.status === 'on' ? 1 : 2,
  279. deduction_switch: deduction_switch,
  280. deduction_price: JSON.stringify(deductionPriceObg),
  281. deduction_number: JSON.stringify(deductionNumberObg),
  282. jdata:JSON.stringify({deduction_price:deductionPriceObg,deduction_number:deductionNumberObg}),
  283. own_app_uids: own_app_uids,
  284. commission_ratio: parseInt(data.field.commission_ratio),
  285. password: data.field.password,
  286. cpa_price:data.field.cpa_price,
  287. cpa_deduction_rule:data.field.cpa_deduction_rule,
  288. withdraw_amount: data.field.withdraw_amount,
  289. withdraw_usdt: data.field.withdraw_usdt,
  290. };
  291. let ret = http.ajax({
  292. url: '/agent/modify',
  293. data: postData
  294. });
  295. ret.then((data) => {
  296. layer.close(createLoading);
  297. if (data.code === 200) {
  298. layer.msg(data.message, {icon: 1, time: 1000}, function () {
  299. // 成功刷父页面
  300. // window.parent.location.reload();
  301. // 成功关闭父窗口
  302. let index = parent.layer.getFrameIndex(window.name);
  303. parent.layer.close(index);
  304. parent.layui.table.reload("agent-table");
  305. });
  306. } else {
  307. layer.msg(data.message, {icon: 2, time: 1000});
  308. }
  309. });
  310. return false;
  311. });
  312. });