index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <template>
  2. <div
  3. class="login-container"
  4. >
  5. <!-- v-loading="loading"
  6. element-loading-text="Loading..."
  7. element-loading-svg-view-box="-10, -10, 50, 50"
  8. element-loading-background="rgba(0, 0, 0, 0.8)" -->
  9. <el-form ref="dataForm" :model="dataForm" :rules="ruleForm">
  10. <el-row :gutter="30">
  11. <el-col :span="4">
  12. <el-form-item label="游戏平台" prop="pid">
  13. <el-select v-model="dataForm.pid" placeholder="Select" class="filter-item">
  14. <el-option
  15. v-for="item in rechargePlatform"
  16. :key="item.pid"
  17. :label="item.platform"
  18. :value="item.pid"
  19. />
  20. </el-select>
  21. </el-form-item>
  22. <!-- <el-form-item label="渠道余额" style="width: 300px;">
  23. <el-input v-model="balanceMoney" type="number" class="inline-input filter-item" disabled style="width: 160px;" />&nbsp;元
  24. </el-form-item> -->
  25. <el-form-item label="渠道账号" prop="cid">
  26. <el-select v-model="dataForm.cid" placeholder="Select" class="filter-item">
  27. <el-option
  28. v-for="item in rechargeChannelPlatform"
  29. :key="item.cid"
  30. :label="item.account"
  31. :value="item.cid"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item label="选择游戏" prop="gfid">
  36. <el-select v-model="dataForm.gfid" placeholder="Select" class="filter-item">
  37. <el-option
  38. v-for="item in rechargeGame"
  39. :key="item.id"
  40. :label="item.name"
  41. :value="item.id"
  42. />
  43. </el-select>
  44. </el-form-item>
  45. </el-col>
  46. <el-col :span="3">
  47. <el-form-item label="充值账户" prop="username" class="filter-item">
  48. <span style="font-size: 5px; color: #67C23A;">:{{ accountNum }}</span>
  49. <el-input
  50. v-model="dataForm.username"
  51. type="textarea"
  52. placeholder="请输入充值账户."
  53. :autosize="{ minRows: 15, maxRows: 60 }"
  54. @change="setAccountNum"
  55. />
  56. </el-form-item>
  57. </el-col>
  58. <el-col v-show="repeatNumList" :span="3">
  59. <el-form-item label="重复账号:" class="filter-item">
  60. <span style="font-size: 5px; color: #F56C6C;">:{{ repeatNumNum }}</span>
  61. <el-input
  62. v-model="repeatNumList"
  63. type="textarea"
  64. :autosize="{ minRows: 15, maxRows: 60 }"
  65. />
  66. </el-form-item>
  67. </el-col>
  68. <el-col :span="4">
  69. <el-form-item label="账户余额">
  70. <span>{{ user_money }}元</span>
  71. </el-form-item>
  72. <el-form-item label="充值金额" prop="money">
  73. <el-input v-model="dataForm.money" type="number" min="0" :max="maxMoney" class="filter-item" />
  74. <span style="font-size: var(--el-font-size-extra-small); color: #909399;">最大充值金额:{{ maxMoney }}</span>
  75. </el-form-item>
  76. <!-- <el-form-item label="平台折扣">
  77. <span>9.8折</span>
  78. </el-form-item>
  79. <el-form-item label="游戏折扣">
  80. <span>9.8折</span>
  81. </el-form-item> -->
  82. <el-form-item label="支付方式">
  83. <el-radio-group v-model="dataForm.payway" prop="payway" class="filter-item">
  84. <el-radio :label="1">久币支付</el-radio>
  85. <!-- <el-radio :label="2">商务币支付</el-radio> -->
  86. </el-radio-group>
  87. </el-form-item>
  88. <el-form-item label="总支付金额">
  89. <span>{{ rechargeMoney }} 元</span>
  90. </el-form-item>
  91. <el-form-item label="账号检测">
  92. <el-radio-group v-model="dataForm.payway" prop="payway" class="filter-item">
  93. <el-switch v-model="onCheck" />
  94. </el-radio-group>
  95. </el-form-item>
  96. <el-form-item>
  97. <el-button type="primary" @click="onSubmit()">立即支付</el-button>
  98. </el-form-item>
  99. </el-col>
  100. <el-col :span="9">
  101. 处理时间:<span>{{ startTime }}</span> -- <span>{{ endTime }}</span>
  102. <el-row :gutter="10">
  103. <el-col :span="8">
  104. <span style="font-size: 5px; color: #67C23A;">成功账户:{{ thenAccountNum }}</span>
  105. <el-input
  106. v-model="thenAccount"
  107. type="textarea"
  108. :autosize="{ minRows: 15, maxRows: 60 }"
  109. />
  110. </el-col>
  111. <el-col :span="8">
  112. <span style="font-size: 5px; color: #F56C6C;">失败账户:{{ catchAccountNum }}</span>
  113. <el-input
  114. v-model="catchAccount"
  115. type="textarea"
  116. :autosize="{ minRows: 15, maxRows: 60 }"
  117. />
  118. </el-col>
  119. <el-col :span="8">
  120. <span style="font-size: 5px; color: #F56C6C;">账户不存在:{{ noExistenceNum }}</span>
  121. <el-input
  122. v-model="noExistence"
  123. type="textarea"
  124. :autosize="{ minRows: 15, maxRows: 60 }"
  125. />
  126. </el-col>
  127. </el-row>
  128. </el-col>
  129. </el-row>
  130. </el-form>
  131. </div>
  132. </template>
  133. <script>
  134. var LodashArray = require('lodash/array')
  135. import { Message, MessageBox, Loading } from 'element-ui'
  136. import { rechargeChannelPlatformAccount } from '@/api/common'
  137. export default {
  138. name: 'Recharge',
  139. data() {
  140. return {
  141. loading: false,
  142. dataForm: {
  143. pid: 'd65aa6d7614589bffe62456b88e98811', // 游戏平台ID;默认魅族平台
  144. cid: '', // 渠道账号ID
  145. gfid: '', // 游戏ID
  146. paypwd: '', // 支付密码
  147. username: '', // 充值账户
  148. money: 1, // 充值金额(单位:元)
  149. recharge: 2, //
  150. payway: 1, // 充值方式
  151. type: 3 //
  152. },
  153. ruleForm: {
  154. pid: [{ required: true, message: '请选择平台.', trigger: 'change' }],
  155. cid: [{ required: true, message: '请选择渠道账号.', trigger: 'change' }],
  156. gfid: [{ required: true, message: '请选择游戏.', trigger: 'change' }],
  157. username: [{ required: true, message: '缺少充值账户.', trigger: 'blur' }],
  158. money: [{ required: true, message: '请输入充值金额,最低一元.', trigger: 'blur' }]
  159. },
  160. // 游戏平台列表
  161. rechargePlatform: [
  162. {
  163. 'pid': 'd65aa6d7614589bffe62456b88e98811',
  164. 'platform': 'MM',
  165. 'disRate': 9.8,
  166. 'rate': 9.7,
  167. 'type': 0,
  168. 'length': 2
  169. }
  170. ],
  171. // balanceMoney: 0, // 渠道余额
  172. user_money: 0, // 账户余额
  173. maxMoney: 0, // 最大充值金额
  174. rechargeChannelPlatform: [], // 渠道账号
  175. rechargeGame: [], // 游戏列表
  176. accountNum: 0, // 总账户个数
  177. repeatNumList: '', // 重复账号列表
  178. repeatNumNum: 0, // 重复账号个数
  179. thenAccount: '', // 成功账户
  180. thenAccountNum: 0, // 成功个数
  181. catchAccount: '', // 失败账户
  182. catchAccountNum: 0, // 失败个数
  183. noExistence: '', // 不存在账户
  184. noExistenceNum: 0, // 不存在账户个数
  185. startTime: 0, // 开始时间
  186. endTime: 0, // 结束时间
  187. onCheck: false, // 是否需要检测账号()
  188. rechargeMoney: 0 // 支付总金额
  189. }
  190. },
  191. watch: {
  192. 'dataForm.money': {
  193. handler(val, oldVal) {
  194. this.checkMoney(val)
  195. }
  196. }
  197. },
  198. created() {
  199. // this.getBalanceMoney(this.dataForm.pid)
  200. this.getRechargePlatform(this.dataForm.pid)
  201. this.getRechargeGame(this.dataForm.pid)
  202. this.updateUserMoney()
  203. this.$store.dispatch('user/getF5').then((res) => {
  204. if (!res) {
  205. this.$store.dispatch('user/setF5')
  206. location.reload()
  207. }
  208. })
  209. },
  210. methods: {
  211. // 判断充值金额
  212. checkMoney(money) {
  213. this.rechargeMoney = this.accountNum * money
  214. if ((this.user_money - this.rechargeMoney) < 0) {
  215. // this.rechargeMoney = this.accountNum * oldVal
  216. return Message({
  217. type: 'warning',
  218. message: '账户余额不足以充值!'
  219. })
  220. }
  221. },
  222. // 更新用户余额
  223. updateUserMoney() {
  224. this.$store.dispatch('user/getInfo').then((res) => {
  225. const { data } = res
  226. this.user_money = data.user_money
  227. if (this.accountNum > 0) {
  228. this.maxMoney = Math.floor(data.user_money / this.accountNum)
  229. } else {
  230. this.maxMoney = Math.floor(data.user_money)
  231. }
  232. })
  233. },
  234. // 统计充值账户数量并处理行数是否账号
  235. setAccountNum() {
  236. if (!this.dataForm.username) {
  237. return false
  238. }
  239. this.accountNum = 0
  240. this.repeatNumList = []
  241. this.repeatNumNum = 0
  242. var newQuestion = this.dataForm.username.replace(/\n\n/, '\n')
  243. const list = newQuestion.split('\n')
  244. var newList = []
  245. for (var i = 0; i < list.length; i++) {
  246. if (list[i] === '') {
  247. continue
  248. }
  249. // 账户去重,并提示
  250. if (newList.indexOf(list[i]) === -1) {
  251. this.accountNum++
  252. newList.push(list[i])
  253. } else {
  254. if (this.repeatNumList.indexOf(list[i]) === -1) {
  255. this.repeatNumNum++
  256. this.repeatNumList.push(list[i])
  257. }
  258. }
  259. }
  260. this.repeatNumList = this.repeatNumList.join().replace(new RegExp(',', 'g'), '\n')
  261. this.dataForm.username = newList.join().replace(new RegExp(',', 'g'), '\n')
  262. this.rechargeMoney = this.accountNum * this.dataForm.money
  263. this.maxMoney = Math.floor(this.user_money / this.accountNum)
  264. },
  265. /**
  266. * 发起提交 游戏账号检测/提交充值 数据
  267. */
  268. onSubmit() {
  269. // this.setAccountNum()
  270. this.thenAccount = ''
  271. this.thenAccountNum = 0
  272. this.catchAccount = ''
  273. this.catchAccountNum = 0
  274. this.noExistence = ''
  275. this.noExistenceNum = 0
  276. this.startTime = ''
  277. this.endTime = ''
  278. // TODO: 正式服务器未上线,暂时不需要
  279. // if ((this.balanceMoney - this.dataForm.money) < 0) {
  280. // return Message({
  281. // type: 'info',
  282. // message: '余额不足以充值.'
  283. // })
  284. // }
  285. if ((this.user_money - this.rechargeMoney) < 0) {
  286. return Message({
  287. type: 'warning',
  288. message: '账户余额不足以充值!'
  289. })
  290. }
  291. this.$refs['dataForm'].validate((valid) => {
  292. if (valid) {
  293. // 截取账号
  294. var accountLists = this.dataForm.username.split('\n')
  295. // console.log('# accountLists: ', accountLists)
  296. MessageBox.prompt('输入支付密码', 'Tip', {
  297. confirmButtonText: '确认',
  298. cancelButtonText: '取消'
  299. }).then(({ value }) => {
  300. this.sublmeRecharge(accountLists, value)
  301. }).catch(() => {
  302. return Message({
  303. type: 'info',
  304. message: '取消充值.'
  305. })
  306. })
  307. } else {
  308. return Message({
  309. type: 'error',
  310. message: '请完善提交内容.'
  311. })
  312. }
  313. })
  314. },
  315. // 提交检测和充值
  316. sublmeRecharge(accountLists, paypwd) {
  317. this.startTime = new Date().getHours() + ':' + new Date().getMinutes() + ':' + new Date().getSeconds()
  318. // 是否需要验证账户
  319. // 提取第一条账号数据,进行提交测试
  320. const oneAccount = accountLists[0]
  321. const oneData = { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: paypwd, username: oneAccount, money: this.dataForm.money, recharge: this.dataForm.recharge, payway: this.dataForm.payway, type: this.dataForm.type }
  322. const loadingNum = accountLists.length - 2
  323. if (this.onCheck) {
  324. // 账号检测
  325. this.$store.dispatch('common/rechargePlayerType', { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, username: oneAccount }).then((res) => {
  326. const { code, status, message } = res
  327. if (code === 200 && status === true) {
  328. // 充值
  329. this.$store.dispatch('common/rechargePlayer', oneData).then((res) => {
  330. const { code, status, message } = res
  331. if (code === 200 && status === true) {
  332. this.thenAccount = this.thenAccount + oneAccount + '\n'
  333. this.thenAccountNum++
  334. if (loadingNum > 1) {
  335. // 遮屏
  336. this.loading = Loading.service({
  337. lock: true,
  338. text: '处理中, 请稍等...',
  339. background: 'rgba(0, 0, 0, 0.7)'
  340. })
  341. // 成功后处理剩下账号数据
  342. accountLists = LodashArray.drop(accountLists) // 删除第一个账户
  343. accountLists.forEach(async(item, index) => {
  344. await this.rechargePlayer(
  345. { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: paypwd, username: item, money: this.dataForm.money, recharge: this.dataForm.recharge, type: this.dataForm.type },
  346. index,
  347. this.onCheck,
  348. loadingNum
  349. )
  350. })
  351. }
  352. } else {
  353. this.catchAccount = this.catchAccount + oneAccount + '\n'
  354. this.catchAccountNum++
  355. return Message({
  356. type: 'warning',
  357. message: message
  358. })
  359. }
  360. }).catch((error) => {
  361. this.catchAccount = this.catchAccount + oneAccount + '\n'
  362. this.catchAccountNum++
  363. return Message({
  364. type: 'error',
  365. message: error.message
  366. })
  367. })
  368. } else {
  369. this.noExistence = this.noExistence + oneAccount + '\n'
  370. this.noExistenceNum++
  371. Message({
  372. type: 'error',
  373. message: '检测:' + message
  374. })
  375. }
  376. }).catch((error) => {
  377. console.log('# catch-message:', error.message)
  378. this.catchAccount = this.catchAccount + oneAccount + '\n'
  379. this.catchAccountNum++
  380. Message({
  381. type: 'error',
  382. message: '检测:' + error.message
  383. })
  384. })
  385. } else {
  386. this.$store.dispatch('common/rechargePlayer', oneData).then((res) => {
  387. const { code, status, message } = res
  388. if (code === 200 && status === true) {
  389. this.thenAccount = this.thenAccount + oneAccount + '\n'
  390. this.thenAccountNum++
  391. if (loadingNum > 1) {
  392. // 遮屏
  393. this.loading = Loading.service({
  394. lock: true,
  395. text: '处理中, 请稍等...',
  396. background: 'rgba(0, 0, 0, 0.7)'
  397. })
  398. // 成功后处理剩下账号数据
  399. accountLists = LodashArray.drop(accountLists) // 删除第一个账户
  400. accountLists.forEach(async(item, index) => {
  401. await this.rechargePlayer(
  402. { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: paypwd, username: item, money: this.dataForm.money, recharge: this.dataForm.recharge, type: this.dataForm.type },
  403. index,
  404. this.onCheck,
  405. loadingNum
  406. )
  407. })
  408. }
  409. } else {
  410. this.catchAccount = this.catchAccount + oneAccount + '\n'
  411. this.catchAccountNum++
  412. return Message({
  413. type: 'warning',
  414. message: message
  415. })
  416. }
  417. }).catch((error) => {
  418. this.catchAccount = this.catchAccount + oneAccount + '\n'
  419. this.catchAccountNum++
  420. return Message({
  421. type: 'error',
  422. message: error.message
  423. })
  424. })
  425. }
  426. // // ## 测试(去除第一个账户单独测试)
  427. // // 是否需要验证账户
  428. // const loadingNum = accountLists.length - 1
  429. // // 遮屏
  430. // this.loading = Loading.service({
  431. // lock: true,
  432. // text: '处理中, 请稍等...',
  433. // background: 'rgba(0, 0, 0, 0.7)'
  434. // })
  435. // // 成功后处理剩下账号数据
  436. // accountLists.forEach(async(item, index) => {
  437. // await this.rechargePlayer(
  438. // { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: paypwd, username: item, money: this.dataForm.money, recharge: this.dataForm.recharge, type: this.dataForm.type },
  439. // index,
  440. // this.onCheck,
  441. // loadingNum
  442. // )
  443. // })
  444. },
  445. // 关闭加载页面
  446. cloneLoading() {
  447. // this.loading = false
  448. this.loading.close()
  449. this.updateUserMoney()
  450. this.endTime = new Date().getHours() + ':' + new Date().getMinutes() + ':' + new Date().getSeconds()
  451. },
  452. // 异步进行账户充值
  453. rechargePlayer(data, index, onCheck, count) {
  454. // 延迟一秒处理
  455. setTimeout((data, index, onCheck, count) => {
  456. return new Promise((resolve, reject) => {
  457. // 继续延迟
  458. setTimeout((_data, onCheck, { index, count }) => {
  459. if (index === count || index > count) {
  460. this.cloneLoading()
  461. }
  462. // 是否需要账号检测
  463. if (onCheck === true) {
  464. // 账号检测
  465. this.$store.dispatch('common/rechargePlayerType', { pid: _data.pid, cid: _data.cid, gfid: _data.gfid, username: _data.username }).then((res) => {
  466. const { code, status, message } = res
  467. if (code === 200 && status !== true) {
  468. // this.thenAccount = this.thenAccount + _data.username + '\n'
  469. // this.thenAccountNum++
  470. // 充值
  471. this.$store.dispatch('common/rechargePlayer', _data).then((res) => {
  472. const { code, status, message } = res
  473. if (code === 200 && status === true) {
  474. this.thenAccount = this.thenAccount + _data.username + '\n'
  475. this.thenAccountNum++
  476. } else {
  477. this.catchAccount = this.catchAccount + _data.username + '\n'
  478. this.catchAccountNum++
  479. Message({
  480. type: 'warning',
  481. message: 'Player:' + message
  482. })
  483. }
  484. }).catch((error) => {
  485. this.catchAccount = this.catchAccount + _data.username + '\n'
  486. this.catchAccountNum++
  487. Message({
  488. type: 'error',
  489. message: 'Player:' + error.message
  490. })
  491. })
  492. } else {
  493. if (code === 10001) {
  494. this.catchAccount = this.catchAccount + _data.username + '\n'
  495. this.catchAccountNum++
  496. } else {
  497. this.noExistence = this.noExistence + _data.username + '\n'
  498. this.noExistenceNum++
  499. }
  500. Message({
  501. type: 'error',
  502. message: '检测:' + message
  503. })
  504. }
  505. }).catch((error) => {
  506. this.catchAccount = this.catchAccount + _data.username + '\n'
  507. this.catchAccountNum++
  508. Message({
  509. type: 'error',
  510. message: '检测:' + error.message
  511. })
  512. resolve()
  513. })
  514. } else {
  515. // 充值
  516. this.$store.dispatch('common/rechargePlayer', _data).then((res) => {
  517. const { code, status, message } = res
  518. if (code === 200 && status === true) {
  519. this.thenAccount = this.thenAccount + _data.username + '\n'
  520. this.thenAccountNum++
  521. } else {
  522. this.catchAccount = this.catchAccount + _data.username + '\n'
  523. this.catchAccountNum++
  524. Message({
  525. type: 'warning',
  526. message: '充值:' + message
  527. })
  528. }
  529. }).catch((error) => {
  530. this.catchAccount = this.catchAccount + _data.username + '\n'
  531. this.catchAccountNum++
  532. Message({
  533. type: 'error',
  534. message: '充值:' + error.message
  535. })
  536. resolve()
  537. })
  538. }
  539. }, 1800 * (index + 1), data, onCheck, { index, count })
  540. // }, (1600 + Math.round(Math.random() * 300)) * (index + 1), data, onCheck)
  541. // 1500 * (index + 1): +1的原因是,这里是从第二条数据开始处理的,异步处理之前单独处理了一个,所以时间久点。
  542. })
  543. }, 1000, data, index, onCheck, count)
  544. },
  545. // 渠道账号列表
  546. getRechargePlatform(val) {
  547. rechargeChannelPlatformAccount(val).then(response => {
  548. // console.log('# getRechargePlatform:', response)
  549. this.rechargeChannelPlatform = response.data.data
  550. this.dataForm.cid = response.data.data[0]['cid']
  551. }).catch(res => {
  552. return Message({
  553. message: res,
  554. type: 'error',
  555. duration: 5 * 1000
  556. })
  557. })
  558. },
  559. // 游戏列表
  560. getRechargeGame(pid) {
  561. this.$store.dispatch('common/rechargeGame', pid).then((res) => {
  562. this.rechargeGame = res
  563. // 设置默认游戏
  564. if (res.find(item => item.id === 54252)) {
  565. this.dataForm.gfid = 54252
  566. }
  567. }).catch((res) => {
  568. return Message({
  569. message: res,
  570. type: 'error',
  571. duration: 5 * 1000
  572. })
  573. })
  574. }
  575. }
  576. }
  577. </script>
  578. <style lang="scss">
  579. .login-container{
  580. margin: 20px;
  581. background-color: #FFFFFF;
  582. .el-bg-border{
  583. border: 2px dashed #909399;
  584. padding: 10px;
  585. }
  586. }
  587. </style>