index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="login-container">
  3. <el-form ref="dataForm" :model="dataForm" :rules="ruleForm">
  4. <el-row :gutter="30" class="el-bg-border">
  5. <el-col :span="5">
  6. <el-form-item label="游戏平台" prop="pid">
  7. <el-select v-model="dataForm.pid" placeholder="Select" class="filter-item">
  8. <el-option
  9. v-for="item in rechargePlatform"
  10. :key="item.pid"
  11. :label="item.platform"
  12. :value="item.pid"
  13. />
  14. </el-select>
  15. </el-form-item>
  16. <!-- <el-form-item label="渠道余额" style="width: 300px;">
  17. <el-input v-model="balanceMoney" type="number" class="inline-input filter-item" disabled style="width: 160px;" />&nbsp;元
  18. </el-form-item> -->
  19. <el-form-item label="渠道账号" prop="cid">
  20. <el-select v-model="dataForm.cid" placeholder="Select" class="filter-item">
  21. <el-option
  22. v-for="item in rechargeChannelPlatform"
  23. :key="item.cid"
  24. :label="item.account"
  25. :value="item.cid"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="选择游戏" prop="gfid">
  30. <el-select v-model="dataForm.gfid" placeholder="Select" class="filter-item">
  31. <el-option
  32. v-for="item in rechargeGame"
  33. :key="item.id"
  34. :label="item.name"
  35. :value="item.id"
  36. />
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="3">
  41. <el-form-item label="充值账户" prop="username" class="filter-item">
  42. <span style="font-size: 5px; color: #67C23A;">:{{ accountNum }}</span>
  43. <el-input
  44. v-model="dataForm.username"
  45. type="textarea"
  46. placeholder="请输入充值账户."
  47. :autosize="{ minRows: 15, maxRows: 100 }"
  48. @change="setAccountNum"
  49. />
  50. </el-form-item>
  51. </el-col>
  52. <el-col v-show="repeatNumList" :span="3">
  53. <el-form-item label="重复账号:" class="filter-item">
  54. <span style="font-size: 5px; color: #F56C6C;">:{{ repeatNumNum }}</span>
  55. <el-input
  56. v-model="repeatNumList"
  57. type="textarea"
  58. :autosize="{ minRows: 15, maxRows: 100 }"
  59. />
  60. </el-form-item>
  61. </el-col>
  62. <el-col :span="5">
  63. <el-form-item label="账户余额">
  64. <span>{{ user_money }}元</span>
  65. </el-form-item>
  66. <el-form-item label="充值金额" prop="money">
  67. <el-input v-model="dataForm.money" type="number" min="0" class="filter-item" />
  68. </el-form-item>
  69. <!-- <el-form-item label="平台折扣">
  70. <span>9.8折</span>
  71. </el-form-item>
  72. <el-form-item label="游戏折扣">
  73. <span>9.8折</span>
  74. </el-form-item> -->
  75. <el-form-item label="支付方式">
  76. <el-radio-group v-model="dataForm.payway" prop="payway" class="filter-item">
  77. <el-radio :label="1">久币支付</el-radio>
  78. <!-- <el-radio :label="2">商务币支付</el-radio> -->
  79. </el-radio-group>
  80. </el-form-item>
  81. <el-form-item label="支付金额">
  82. <span>{{ dataForm.money }} 元</span>
  83. </el-form-item>
  84. <el-form-item>
  85. <el-button type="primary" @click="onSubmit">立即支付</el-button>
  86. </el-form-item>
  87. </el-col>
  88. <el-col :span="6">
  89. <el-row :gutter="30">
  90. <el-col :span="12">
  91. <span style="font-size: 5px; color: #67C23A;">成功账户:{{ thenAccountNum }}</span>
  92. <el-input
  93. v-model="thenAccount"
  94. type="textarea"
  95. :autosize="{ minRows: 15, maxRows: 100 }"
  96. />
  97. </el-col>
  98. <el-col :span="12">
  99. <span style="font-size: 5px; color: #F56C6C;">失败账户:{{ catchAccountNum }}</span>
  100. <el-input
  101. v-model="catchAccount"
  102. type="textarea"
  103. :autosize="{ minRows: 15, maxRows: 100 }"
  104. />
  105. </el-col>
  106. </el-row>
  107. </el-col>
  108. </el-row>
  109. </el-form>
  110. </div>
  111. </template>
  112. <script>
  113. var LodashArray = require('lodash/array')
  114. import { Message, MessageBox, Loading } from 'element-ui'
  115. import { rechargeChannelPlatformAccount } from '@/api/common'
  116. // import { validMobile } from '@/utils/validate'
  117. export default {
  118. name: 'Recharge',
  119. data() {
  120. return {
  121. // accountHandleSuccess: '', // 处理成功账号
  122. dataForm: {
  123. pid: 'd65aa6d7614589bffe62456b88e98811', // 游戏平台ID;默认魅族平台
  124. cid: '', // 渠道账号ID
  125. gfid: '', // 游戏ID
  126. paypwd: '', // 支付密码
  127. // username: '13121776520\n13121776521\n13121776522\n\n13121776523\n13121776524\n13121776525', // 充值账户
  128. username: '', // 充值账户
  129. money: 1, // 充值金额(单位:元)
  130. recharge: 2, //
  131. payway: 1, // 充值方式
  132. type: 3 //
  133. },
  134. ruleForm: {
  135. pid: [{ required: true, message: '请选择平台.', trigger: 'change' }],
  136. cid: [{ required: true, message: '请选择渠道账号.', trigger: 'change' }],
  137. gfid: [{ required: true, message: '请选择游戏.', trigger: 'change' }],
  138. username: [{ required: true, message: '缺少充值账户.', trigger: 'blur' }],
  139. money: [{ required: true, message: '请输入充值金额,最低一元.', trigger: 'blur' }]
  140. },
  141. // 游戏平台列表
  142. rechargePlatform: [
  143. {
  144. 'pid': 'd65aa6d7614589bffe62456b88e98811',
  145. 'platform': 'MM',
  146. 'disRate': 9.8,
  147. 'rate': 9.7,
  148. 'type': 0,
  149. 'length': 2
  150. }
  151. ],
  152. // balanceMoney: 0, // 渠道余额
  153. user_money: 0, // 账户余额
  154. rechargeChannelPlatform: [], // 渠道账号
  155. rechargeGame: [], // 游戏列表
  156. accountNum: 0, // 总账户个数
  157. repeatNumList: '', // 重复账号列表
  158. repeatNumNum: 0, // 重复账号个数
  159. thenAccount: '', // 成功账户
  160. thenAccountNum: 0, // 成功个数
  161. catchAccount: '', // 失败账户
  162. catchAccountNum: 0 // 失败个数
  163. // loadingText: '处理中,请稍等。。。',
  164. // loadingTextNum: 0 // 操作百分比
  165. }
  166. },
  167. created() {
  168. // this.getBalanceMoney(this.dataForm.pid)
  169. this.getRechargePlatform(this.dataForm.pid)
  170. this.getRechargeGame(this.dataForm.pid)
  171. this.updateUserMoney()
  172. },
  173. methods: {
  174. // 更新用户余额
  175. updateUserMoney() {
  176. this.$store.dispatch('user/getInfo').then((res) => {
  177. const { data } = res
  178. this.user_money = data.user_money
  179. })
  180. },
  181. // 统计充值账户数量并处理行数不是账号的
  182. setAccountNum() {
  183. if (!this.dataForm.username) {
  184. return false
  185. }
  186. this.accountNum = 0
  187. this.repeatNumList = []
  188. this.repeatNumNum = 0
  189. var newQuestion = this.dataForm.username.replace(/\n\n/, '\n')
  190. const list = newQuestion.split('\n')
  191. var newList = []
  192. for (var i = 0; i < list.length; i++) {
  193. if (list[i] === '') {
  194. continue
  195. }
  196. // 账户去重,并提示
  197. if (newList.indexOf(list[i]) === -1) {
  198. this.accountNum++
  199. newList.push(list[i])
  200. } else {
  201. if (this.repeatNumList.indexOf(list[i]) === -1) {
  202. this.repeatNumNum++
  203. this.repeatNumList.push(list[i])
  204. }
  205. }
  206. }
  207. this.repeatNumList = this.repeatNumList.join().replace(new RegExp(',', 'g'), '\n')
  208. this.dataForm.username = newList.join().replace(new RegExp(',', 'g'), '\n')
  209. },
  210. async onSubmit() {
  211. // this.setAccountNum()
  212. this.thenAccount = ''
  213. this.catchAccount = ''
  214. // TODO: 正式服务器未上线,暂时不需要
  215. // if ((this.balanceMoney - this.dataForm.money) < 0) {
  216. // return Message({
  217. // type: 'info',
  218. // message: '余额不足以充值.'
  219. // })
  220. // }
  221. this.$refs['dataForm'].validate((valid) => {
  222. if (valid) {
  223. // 截取数据
  224. var userLists = this.dataForm.username.split('\n')
  225. MessageBox.prompt('输入支付密码', 'Tip', {
  226. confirmButtonText: '确认',
  227. cancelButtonText: '取消'
  228. }).then(({ value }) => {
  229. // 提取第一条账号数据,针对接口提交判断数据是否有误
  230. var oneData = { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: value, username: userLists[0], money: this.dataForm.money, recharge: this.dataForm.recharge, payway: this.dataForm.payway, type: this.dataForm.type }
  231. this.$store.dispatch('common/rechargePlayer', oneData).then((res) => {
  232. const { code, status } = res
  233. if (code === 200 && status === true) {
  234. this.thenAccount = this.thenAccount + oneData.username + '\n'
  235. this.thenAccountNum++
  236. // 遮屏
  237. const loading = Loading.service({
  238. lock: true,
  239. text: '处理中, 请稍等...',
  240. background: 'rgba(0, 0, 0, 0.7)'
  241. })
  242. // 成功后处理剩下账号数据
  243. const loadingNum = userLists.length - 2
  244. userLists = LodashArray.drop(userLists)
  245. userLists.forEach(async(item, index) => {
  246. var _data = { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: value, username: item, money: this.dataForm.money, recharge: this.dataForm.recharge, payway: this.dataForm.payway, type: this.dataForm.type }
  247. await this.rechargePlayer(_data, index)
  248. // console.log('# forEach:', loadingNum, index)
  249. if (loadingNum === index) {
  250. loading.close()
  251. this.updateUserMoney()
  252. }
  253. })
  254. } else {
  255. this.catchAccount = this.catchAccount + oneData.username + '\n'
  256. this.catchAccountNum++
  257. }
  258. }).catch((res) => {
  259. this.catchAccount = this.catchAccount + oneData.username + '\n'
  260. this.catchAccountNum++
  261. })
  262. }).catch(() => {
  263. return Message({
  264. type: 'info',
  265. message: '取消充值.'
  266. })
  267. })
  268. } else {
  269. return Message({
  270. type: 'error',
  271. message: '请完善提交内容.'
  272. })
  273. }
  274. })
  275. },
  276. // 异步进行账户充值
  277. rechargePlayer(data, index) {
  278. return new Promise((resolve, reject) => {
  279. setTimeout((_data) => {
  280. this.$store.dispatch('common/rechargePlayer', _data).then((res) => {
  281. const { code, status } = res
  282. if (code === 200 && status === true) {
  283. this.thenAccount = this.thenAccount + _data.username + '\n'
  284. this.thenAccountNum++
  285. resolve()
  286. } else {
  287. this.catchAccount = this.catchAccount + _data.username + '\n'
  288. this.catchAccountNum++
  289. resolve()
  290. }
  291. }).catch((res) => {
  292. this.catchAccount = this.catchAccount + _data.username + '\n'
  293. this.catchAccountNum++
  294. resolve()
  295. })
  296. }, 2000 * index, data)
  297. })
  298. },
  299. // 账户余额 -- 弃用
  300. getBalanceMoney(val) {
  301. this.$store.dispatch('common/getMainChannelMoney', val).then((res) => {
  302. this.balanceMoney = res
  303. }).catch((res) => {
  304. return Message({
  305. message: res,
  306. type: 'error',
  307. duration: 5 * 1000
  308. })
  309. })
  310. },
  311. // 渠道账号列表
  312. getRechargePlatform(val) {
  313. rechargeChannelPlatformAccount(val).then(response => {
  314. // console.log('# getRechargePlatform:', response)
  315. this.rechargeChannelPlatform = response.data.data
  316. this.dataForm.cid = response.data.data[0]['cid']
  317. }).catch(res => {
  318. return Message({
  319. message: res,
  320. type: 'error',
  321. duration: 5 * 1000
  322. })
  323. })
  324. },
  325. // 游戏列表
  326. getRechargeGame(pid) {
  327. this.$store.dispatch('common/rechargeGame', pid).then((res) => {
  328. this.rechargeGame = res
  329. // 设置默认游戏
  330. if (res.find(item => item.id === 54252)) {
  331. this.dataForm.gfid = 54252
  332. }
  333. }).catch((res) => {
  334. return Message({
  335. message: res,
  336. type: 'error',
  337. duration: 5 * 1000
  338. })
  339. })
  340. }
  341. }
  342. }
  343. </script>
  344. <style lang="scss">
  345. .login-container{
  346. margin: 20px;
  347. background-color: #FFFFFF;
  348. .el-bg-border{
  349. border: 2px dashed #909399;
  350. padding: 10px;
  351. }
  352. }
  353. </style>