agent_create.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. layui.use(['form', 'jquery', 'layer', 'mhttp'], function () {
  2. let form = layui.form;
  3. let $ = layui.jquery;
  4. let http = layui.mhttp;
  5. let layer = layui.layer;
  6. // 查询应用
  7. let ret = http.ajax({
  8. url: '/app/all'
  9. });
  10. ret.then((data) => {
  11. if (data.code === 200) {
  12. let html = '';
  13. for (let i in data.data) {
  14. html += '<input type="checkbox" value="' + data.data[i].uid + '" class="che_' + data.data[i].uid + '" name="own_app_uids" title="' + data.data[i].name + '">';
  15. }
  16. $('.own_app_uids').html(html);
  17. form.render();
  18. } else {
  19. $('.own_app_uids').append('<span class="app-error">获取应用失败,刷新重试!</span>');
  20. }
  21. });
  22. $('.username').focus(function () {
  23. $('.checkUsername').html('');
  24. });
  25. $('.username').blur(function () {
  26. let username = $(this).val();
  27. if (username.length < 6) {
  28. $('.checkUsername').html('<span class="help">账号长度在6位以上</span>');
  29. return false;
  30. }
  31. let ret1 = http.ajax({
  32. url: 'agent/check/username',
  33. data: {username: username}
  34. });
  35. ret1.then((data) => {
  36. let html = '';
  37. if (data.code === 200) {
  38. html = '<span class="check">' + data.message + '</span>';
  39. } else {
  40. html = '<span class="help">' + data.message + '</span>';
  41. }
  42. $('.checkUsername').html(html);
  43. });
  44. });
  45. form.on('submit(agent-save)', function (data) {
  46. if (data.field.password !== data.field.rePassword) {
  47. layer.msg('两次密码不一致 !');
  48. return false;
  49. }
  50. if (data.field.username.length < 6) {
  51. layer.msg('账号长度在6位以上 !');
  52. return false;
  53. }
  54. if (data.field.password.length < 6) {
  55. layer.msg('密码长度在6位以上 !');
  56. return false;
  57. }
  58. if (data.field.withdraw_pwd) {
  59. if (data.field.withdraw_pwd.length < 6) {
  60. layer.msg('提现密码长度在6位以上 !');
  61. return false;
  62. }
  63. }
  64. let commission_ratio = parseInt(data.field.commission_ratio);
  65. if (commission_ratio > 100 || commission_ratio < 0) {
  66. layer.msg('分成比例在0-100!');
  67. return false;
  68. }
  69. let own_app_uids = '';
  70. $('.own_app_uids input:checked').each(function (index) {
  71. if (index === 0) {
  72. own_app_uids = $(this).val();
  73. } else {
  74. own_app_uids += ',' + $(this).val();
  75. }
  76. });
  77. if (own_app_uids.length <= 0) {
  78. layer.msg('应用必须选择一个!');
  79. return false;
  80. }
  81. let deduction_switch = data.field.deduction_switch;
  82. if (deduction_switch == 1) {
  83. if (!data.field.deduction_price || !data.field.deduction_number) {
  84. layer.msg('请核对扣量价格和扣量数量!');
  85. return false;
  86. } else {
  87. if (data.field.deduction_price.search(',') != -1) {
  88. layer.confirm('检测到扣量价格有","是否替换为以","分隔?', {
  89. icon: 3,
  90. title: '提示'
  91. }, function (index) {
  92. layer.close(index);
  93. $('.deduction_price').val(data.field.deduction_price.replace(/,/g, ","));
  94. layer.msg('已替换请再次确认!');
  95. });
  96. return false;
  97. }
  98. if (data.field.deduction_number.search(',') != -1) {
  99. layer.confirm('检测扣量数量格有","是否替换为以","分隔?', {
  100. icon: 3,
  101. title: '提示'
  102. }, function (index) {
  103. layer.close(index);
  104. $('.deduction_number').val(data.field.deduction_price.replace(/,/g, ","));
  105. layer.msg('已替换请再次确认!');
  106. });
  107. return false;
  108. }
  109. }
  110. }
  111. if (deduction_switch == 2 && (!data.field.cpa_deduction_rule || !data.field.cpa_price)) {
  112. layer.msg('选择cpa类型后,请填写对应的cpa扣量规则和cpa单价价格!');
  113. return false;
  114. }
  115. let deductionPriceObg = [];
  116. if (data.field.deduction_price) {
  117. let priceArray = data.field.deduction_price.split(',');
  118. for (let i in priceArray) {
  119. let priceArrayItem = priceArray[i].split('-');
  120. deductionPriceObg.push({
  121. min_price: priceArrayItem[0],
  122. max_price: priceArrayItem[1],
  123. })
  124. }
  125. }
  126. let deductionNumberObg = [];
  127. if (data.field.deduction_number) {
  128. let numberArray = data.field.deduction_number.split(',');
  129. for (let i in numberArray) {
  130. let numberArrayItem = numberArray[i].split('-');
  131. deductionNumberObg.push({
  132. number: numberArrayItem[0],
  133. deduction: numberArrayItem[1],
  134. })
  135. }
  136. }
  137. if (deductionPriceObg.length !== deductionNumberObg.length) {
  138. layer.msg('扣量价格与扣量数量对映不上!');
  139. return false;
  140. }
  141. let createLoading = layer.load();
  142. let postData = {
  143. username: data.field.username,
  144. nick: data.field.nick,
  145. withdraw_pwd: data.field.withdraw_pwd,
  146. preferential_order: data.field.preferential_order,
  147. role_id: 1,
  148. status: data.field.status === 'on' ? 1 : 2,
  149. own_app_uids: own_app_uids,
  150. deduction_switch: deduction_switch,
  151. deduction_price: JSON.stringify(deductionPriceObg),
  152. deduction_number: JSON.stringify(deductionNumberObg),
  153. jdata:JSON.stringify({deduction_price:deductionPriceObg,deduction_number:deductionNumberObg}),
  154. commission_ratio: parseInt(data.field.commission_ratio),
  155. cpa_price:data.field.cpa_price,
  156. cpa_deduction_rule:data.field.cpa_deduction_rule,
  157. password: data.field.password,
  158. withdraw_amount: data.field.withdraw_amount,
  159. withdraw_usdt: data.field.withdraw_usdt,
  160. };
  161. let ret = http.ajax({
  162. url: '/agent/create',
  163. data: postData
  164. });
  165. ret.then((data) => {
  166. layer.close(createLoading);
  167. if (data.code === 200) {
  168. layer.msg(data.message, {icon: 1, time: 1000}, function () {
  169. // 成功刷父页面
  170. // window.parent.location.reload();
  171. // 成功关闭父窗口
  172. let index = parent.layer.getFrameIndex(window.name);
  173. parent.layer.close(index);
  174. parent.layui.table.reload("agent-table");
  175. });
  176. } else {
  177. layer.msg(data.message, {icon: 2, time: 1000});
  178. }
  179. });
  180. return false;
  181. });
  182. })