Withdraw Page

This commit is contained in:
Mr Swift
2024-08-25 17:19:25 +03:30
parent b0566dd807
commit 617f596b72
4 changed files with 298 additions and 262 deletions
+1 -1
View File
@@ -358,7 +358,7 @@
<CSidebarNavItem <CSidebarNavItem
v-if="hasPermission('gps')" v-if="hasPermission('gps')"
name="درخواست های برداشت" name="درخواست های برداشت"
:to="{ name: 'admin-admins-admin', params: { admin: 'new' } }" :to="{ name: 'admin-gps-withdraw', query: { filter: 'all' }}"
font-icon="fal fa-credit-card" font-icon="fal fa-credit-card"
:exact="false" :exact="false"
/> />
+1 -1
View File
@@ -218,7 +218,7 @@ export default {
console.log(err) console.log(err)
return this.$message({ return this.$message({
type: 'warning', type: 'warning',
message: err.data.msg message: err.msg
}) })
} }
}) })
+257 -223
View File
@@ -1,234 +1,268 @@
<template> <template>
<div> <div>
<CustomSubHeader> <el-dialog title="اطلاعات کاربر" :visible.sync="centerDialogVisible" width="40%" center>
<CBreadcrumb class="border-0 mb-0"> دستگاه های نصب شده</CBreadcrumb> <el-descriptions title="" direction="vertical" :column="4" border>
</CustomSubHeader> <el-descriptions-item label="نام و نام خانودگی">{{
requestData.userId?.first_name + ' ' + requestData.userId?.last_name
<CRow> }}</el-descriptions-item>
<CCol xl="6"> <el-descriptions-item label="شماره همراه">{{ requestData.userId?.mobile_number }}</el-descriptions-item>
<CCard> <el-descriptions-item label="استان">{{ requestData.userId?.province_name }}</el-descriptions-item>
<CCardHeader> <el-descriptions-item label="شهر">{{ requestData.userId?.city_name }}</el-descriptions-item>
<slot name="header"> <el-descriptions-item label="کد ملی ">{{ requestData.userId?.national_code }}</el-descriptions-item>
<i class="fas fa-filter"></i> <el-descriptions-item label="نام فروشگاه">{{ requestData.userId?.shopName }}</el-descriptions-item>
<b>فیلتر ها</b> </el-descriptions>
</slot> <CCardBody>
</CCardHeader> <el-table :data="[requestData?.card]" style="width: 100%">
<el-table-column type="index" label="#"> </el-table-column>
<CCardBody> <el-table-column prop="holderName" label="نام صاحب کارت" width="200px"> </el-table-column>
<CRow> <el-table-column prop="PAN" label="شماره حساب" width="200px"> </el-table-column>
<CCol sm="12"> <el-table-column prop="IBAN" label="شماره شبا" width=""> </el-table-column>
<CButtonGroup> </el-table>
<CButton color="primary" :class="filterType === 'all' && 'selected'" @click="filterType = 'all'" </CCardBody>
>همه</CButton
> <el-input
<CButton color="danger" :class="filterType === 'rej' && 'selected'" @click="filterType = 'rej'" v-if="requestData.status === 1"
>رد شده</CButton v-model="trackingNumber"
> placeholder="شماره پیگیری"
<CButton style="display: inline-block; max-width: 500px; margin-top: 8px"
color="success" ></el-input>
:class="filterType === 'accept' && 'selected'" <span slot="footer" class="dialog-footer">
@click="filterType = 'accept'" <el-button @click="centerDialogVisible = false">بستن</el-button>
>تایید شده</CButton <el-button type="primary" @click="patchIt(requestData._id, requestData.status, {trackingNumber})">{{
> requestData.status == 1 ? 'تایید واریز' : 'تایید'
<CButton color="warning" :class="filterType === 'pend' && 'selected'" @click="filterType = 'pend'" }}</el-button>
>درانتظار تایید</CButton </span>
> </el-dialog>
</CButtonGroup>
</CCol> <CustomSubHeader>
<CCol sm="12"> <CBreadcrumb class="border-0 mb-0"> دستگاه های نصب شده</CBreadcrumb>
<el-divider></el-divider> </CustomSubHeader>
</CCol>
<CCol sm="12"> <CRow>
<h4>جستجو در لیست:</h4> <CCol xl="6">
<el-input <CCard>
v-model="filterText" <CCardHeader>
clearable <slot name="header">
placeholder="" <i class="fas fa-filter"></i>
style="display: inline-block; max-width: 500px; margin-top: 8px" <b>فیلتر ها</b>
></el-input> </slot>
</CCol> </CCardHeader>
</CRow>
</CCardBody> <CCardBody>
</CCard> <CRow>
</CCol> <CCol sm="12">
</CRow> <CButtonGroup>
<CButton color="primary" :class="filterType === 'all' && 'selected'" @click="filterType = 'all'"
<CCard> >همه</CButton
<CCardHeader> >
<slot name="header"> <CButton color="success" :class="filterType === 'dep' && 'selected'" @click="filterType = 'dep'">
<CIcon name="cil-grid" /> واریز شده</CButton
دستگاه های نصب شده >
</slot> <CButton color="success" :class="filterType === 'accept' && 'selected'" @click="filterType = 'accept'"
</CCardHeader> >تایید شده</CButton
>
<CCardBody> <CButton color="warning" :class="filterType === 'pend' && 'selected'" @click="filterType = 'pend'"
<el-table :data="filteredItems" :row-class-name="hasUnread" style="width: 100%"> >درانتظار
<el-table-column type="index" label="#"> </el-table-column> </CButton>
</CButtonGroup>
<el-table-column label="مدل" width="150px"> </CCol>
<template slot-scope="scope"> <CCol sm="12">
{{ scope.row.deviceId.model }} <el-divider></el-divider>
</template> </CCol>
</el-table-column> <CCol sm="12">
<el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column> <h4>جستجو در لیست:</h4>
<el-input
<el-table-column label="نام فروشگاه" width=""> v-model="filterText"
<template slot-scope="scope"> clearable
{{ scope.row.userId.shopName }} placeholder=""
</template> style="display: inline-block; max-width: 500px; margin-top: 8px"
</el-table-column> ></el-input>
<el-table-column label="کدملی فروشنده" width=""> </CCol>
<template slot-scope="scope"> </CRow>
{{ scope.row.userId.national_code }} </CCardBody>
</template> </CCard>
</el-table-column> </CCol>
<el-table-column label=" نام و نام خانوادگی" width=""> </CRow>
<template slot-scope="scope">
{{ scope.row.userId.first_name + " " + scope.row.userId.last_name }} <CCard>
</template> <CCardHeader>
</el-table-column> <slot name="header">
<el-table-column label=" شماره همراه" width=""> <CIcon name="cil-grid" />
<template slot-scope="scope"> دستگاه های نصب شده
{{ scope.row.userId.mobile_number }} </slot>
</template> </CCardHeader>
</el-table-column>
<CCardBody>
<el-table-column label="محل سکونت" width=""> <el-table :data="filteredItems" :row-class-name="hasUnread" style="width: 100%">
<template slot-scope="scope"> <el-table-column type="index" label="#"> </el-table-column>
{{ scope.row.userId.province_name + ", "+ scope.row.userId.city_name }}
</template> <el-table-column label="مبلغ تومانی " width="150px">
</el-table-column> <template slot-scope="scope">
{{ scope.row.amount }}
<el-table-column label="وضعیت" width=""> </template>
<template slot-scope="scope"> </el-table-column>
<el-tag v-if="scope.row.status == 2" type="danger"> رد شده</el-tag> <el-table-column prop="dollarAmount" label=" مبلغ دلاری" width="150px"> </el-table-column>
<el-tag v-if="scope.row.status == 1" type="success">تایید شده</el-tag>
<el-table-column label="نام فروشگاه" width="">
<el-tag v-if="scope.row.status == 0" type="warning"> درانتظار تایید</el-tag> <template slot-scope="scope">
</template> {{ scope.row.userId.shopName }}
</el-table-column> </template>
<el-table-column label="تایید" width="110" align="center"> </el-table-column>
<template slot-scope="scope"> <el-table-column label="کدملی فروشنده" width="">
<CButton <template slot-scope="scope">
v-if="scope.row.status == 0 || scope.row.status == 2" {{ scope.row.userId.national_code }}
:key="scope.row._id" </template>
color="success" </el-table-column>
variant="outline" <el-table-column label=" نام و نام خانوادگی" width="">
@click="post(scope.row._id, 'accept')" <template slot-scope="scope">
> {{ scope.row.userId.first_name + ' ' + scope.row.userId.last_name }}
<i class="fa fa-check-square"></i> </template>
</CButton> </el-table-column>
<CButton <el-table-column label=" شماره همراه" width="">
v-if="scope.row.status == 0 || scope.row.status == 1" <template slot-scope="scope">
:key="scope.row._id" {{ scope.row.userId.mobile_number }}
color="danger" </template>
variant="outline" </el-table-column>
@click="post(scope.row._id, 'reject')"
> <el-table-column label="محل سکونت" width="">
<i class="fa fa-window-close"></i> <template slot-scope="scope">
</CButton> {{ scope.row.userId.province_name + ', ' + scope.row.userId.city_name }}
</template> </template>
</el-table-column> </el-table-column>
</el-table>
</CCardBody> <el-table-column label="وضعیت" width="">
</CCard> <template slot-scope="scope">
</div> <el-tag v-if="scope.row.status == 2" color="info"> واریز شده</el-tag>
</template> <el-tag v-if="scope.row.status == 1" type="success">تایید شده</el-tag>
<el-tag v-if="scope.row.status == 0" type="warning"> درانتظار</el-tag>
<script> </template>
export default { </el-table-column>
name: 'AdminGpsInstalledDevicesList', <el-table-column label="بررسی" width="110" align="center">
layout: 'admin', <template slot-scope="scope">
async asyncData({ $axios, error, query }) { <CButton :key="scope.row._id" color="info" variant="outline" @click="showDialog(scope.row)">
try { <i class="fa fa-eye"></i>
const { data } = await $axios.get('/api/admin/gps/register-device') </CButton>
</template>
return { </el-table-column>
devices: data.data </el-table>
} </CCardBody>
} catch (error) { </CCard>
console.log(error) </div>
} </template>
},
data() { <script>
export default {
name: 'AdminGpsWithdrawList',
layout: 'admin',
async asyncData({ $axios, error, query }) {
try {
const { data } = await $axios.get('/api/admin/gps/withdraw')
return { return {
devices: [], requestsData: data.data
device: {},
filterText: '',
} }
} catch (error) {
console.log(error)
}
},
data() {
return {
requestsData: [],
centerDialogVisible: false,
requestData: {},
filterText: '',
trackingNumber: null
}
},
computed: {
config() {
return this.$config
}, },
filteredItems() {
computed: { const filterUsersByType = this.requestsData.filter(item => {
config() { if (this.filterType === 'all') return item
return this.$config // eslint-disable-next-line eqeqeq
}, else if (this.filterType === 'dep') return item.status == 2
filteredItems() { // eslint-disable-next-line eqeqeq
const filterUsersByType = this.devices.filter(item => { else if (this.filterType === 'accept') return item.status == 1
if (this.filterType === 'all') return item // eslint-disable-next-line eqeqeq
// eslint-disable-next-line eqeqeq else if (this.filterType === 'pend') return item.status == 0
else if (this.filterType === 'rej') return item.status == 2 else return null
// eslint-disable-next-line eqeqeq })
else if (this.filterType === 'accept') return item.status == 1 const filterText = this.filterText
// eslint-disable-next-line eqeqeq if (!this.filterText.length) return filterUsersByType
else if (this.filterType === 'pend') return item.status == 0 else {
else return null return this.requestsData.filter(item => {
return item.IMEI.includes(filterText) || item.deviceId.model.includes(filterText)
}) })
const filterText = this.filterText
if (!this.filterText.length) return filterUsersByType
else {
return this.devices.filter(item => {
return item.IMEI.includes(filterText) || item.deviceId.model.includes(filterText)
})
}
},
filterType: {
get() {
return this.$route.query?.filter
},
set(val) {
this.$router.push({ name: 'admin-gps-installed-device', query: { filter: val } })
}
} }
}, },
methods: { filterType: {
hasUnread({ row, rowIndex }) { get() {
return row.status === 0 ? 'unreadMsgInCv' : null return this.$route.query?.filter
}, },
post(id, status) { set(val) {
this.$axios this.$router.push({ name: 'admin-gps-withdraw', query: { filter: val } })
.patch(`/api/admin/gps/register-device/${id}/${status}`, {})
.then(res => {
this.$message({
type: 'success',
message: res.data.msg
})
this.$nuxt.refresh()
})
.catch(err => {
if (err.response.data.status === 401) {
return this.$message({
type: 'warning',
message: 'لطفا دوباره وارد حساب خود شوید'
})
}
if (err.response.status === 422) this.validation = err.response.data.validation
else {
console.log(err)
return this.$message({
type: 'warning',
message: err.data.msg
})
}
})
} }
} }
},
methods: {
showDialog(data) {
console.log(data)
this.requestData = data
this.centerDialogVisible = true
},
hasUnread({ row, rowIndex }) {
return row.status === 0 ? 'unreadMsgInCv' : null
},
patchIt(id, status, data) {
let st
// eslint-disable-next-line eqeqeq
if (status == 1) {
st = 'deposit'
if (!data?.trackingNumber) {
return this.$message({
type: 'warning',
message: 'لطفا شماره پیگیری را وارد کنید'
})
}
} else {
st = 'accept'
}
this.$axios
.patch(`/api/admin/gps/withdraw/${id}/${st}`, data)
.then(res => {
this.$message({
type: 'success',
message: res.data.msg
})
this.$nuxt.refresh()
})
.catch(err => {
if (err.response.data.status === 401) {
return this.$message({
type: 'warning',
message: 'لطفا دوباره وارد حساب خود شوید'
})
}
if (err.response.status === 422) this.validation = err.response.data.validation
else {
console.log(err)
return this.$message({
type: 'warning',
message: err.msg
})
}
})
}
} }
</script> }
<style> </script>
.unreadMsgInCv { <style>
background: rgba(orange, 0.1) !important; .unreadMsgInCv {
} background: rgba(orange, 0.1) !important;
</style> }
</style>
+39 -37
View File
@@ -17,20 +17,24 @@ module.exports.createRequest = [
res.status(400).json({ msg: 'شما درخواست درحال بررسی دارید' }) res.status(400).json({ msg: 'شما درخواست درحال بررسی دارید' })
}else{ }else{
const user = await User.findById(req.user_id) const user = await User.findById(req.user_id)
const data = { if(user.walletBalance < 50000){
card: req.body.card, const data = {
userId: req.user_id, card: req.body.card,
amount: user.walletBalance, userId: req.user_id,
dollarAmount: user.dollarBalance, amount: user.walletBalance,
status: 0 dollarAmount: user.dollarBalance,
status: 0
}
const request = await Withdraw.create(data)
user.dollarBalance = 0;
user.walletBalance = 0;
user.save()
// res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
res.status(201).json(request)
}else{
res.status(400).json({ msg: 'حداقل موجودی باید 50 هزار تومان باشد' })
} }
const request = await Withdraw.create(data)
user.dollarBalance = 0;
user.walletBalance = 0;
user.save()
// res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
res.status(201).json(request)
} }
@@ -76,25 +80,25 @@ module.exports.getAllForUser = async (req, res) => {
} }
module.exports.getAllForAdmin = async (req, res) => { module.exports.getAllForAdmin = async (req, res) => {
let page; // let page;
let rows; // let rows;
if (!req.query?.rows || req.query?.rows <= 5) { // if (!req.query?.rows || req.query?.rows <= 5) {
rows = 10 // rows = 10
} else { // } else {
rows = parseInt(req.query.rows) // rows = parseInt(req.query.rows)
} // }
if (!req.query?.page) { // if (!req.query?.page) {
page = 0 // page = 0
// eslint-disable-next-line eqeqeq // // eslint-disable-next-line eqeqeq
} else if (req.query.page <= 1) { // } else if (req.query.page <= 1) {
page = 0 // page = 0
} else { // } else {
page = req.query.page // page = req.query.page
page = page * rows - rows // page = page * rows - rows
} // }
const data = await Withdraw.find().sort({ status: 1 }).skip(page).limit(rows) const data = await Withdraw.find().sort({ status: 1 })
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic') .populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
const total = Math.ceil((await Withdraw.estimatedDocumentCount())) const total = Math.ceil((await Withdraw.estimatedDocumentCount()))
res.status(200).json({ data, total }) res.status(200).json({ data, total })
} }
@@ -115,9 +119,8 @@ module.exports.updateReq = [
case "accept": { case "accept": {
request.status = 1; request.status = 1;
request.save() request.save()
// res.status(201).json({ msg: _sr.fa.response.success_save, data: request }) res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
res.status(201).json(request)
break; break;
} }
case "deposit": { case "deposit": {
@@ -125,9 +128,8 @@ module.exports.updateReq = [
request.depositDate = new Date(); request.depositDate = new Date();
request.trackingNumber = req.body.trackingNumber || 0; request.trackingNumber = req.body.trackingNumber || 0;
request.save() request.save()
// res.status(201).json({ msg: _sr.fa.response.success_save, data: request }) res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
res.status(201).json(request)
break; break;
} }
default: { default: {