update: remove dollor from wallet and unit

This commit is contained in:
mahyargdz
2024-12-30 16:03:02 +03:30
parent 0d8ba394b1
commit cd61741d06
13 changed files with 462 additions and 490 deletions
+7 -1
View File
@@ -2,7 +2,7 @@
<CFooter :fixed="false"> <CFooter :fixed="false">
<div class="mfs-auto"> <div class="mfs-auto">
<span class="mr-1" target="_blank">Powered by</span> <span class="mr-1" target="_blank">Powered by</span>
<a href="https://negarehagency.com/" target="_blank" class="copy-right">Negareh Agency</a> <a href="https://danakcorp.com/" target="_blank" class="copy-right textblack">Danak Corp</a>
</div> </div>
</CFooter> </CFooter>
</template> </template>
@@ -12,3 +12,9 @@ export default {
name: 'TheFooter' name: 'TheFooter'
} }
</script> </script>
<style>
.textblack {
color: #000 !important;
}
</style>
+7 -11
View File
@@ -2,9 +2,7 @@
<div> <div>
<CustomSubHeader> <CustomSubHeader>
<CBreadcrumb class="border-0 mb-0"> دستگاه ها</CBreadcrumb> <CBreadcrumb class="border-0 mb-0"> دستگاه ها</CBreadcrumb>
<CButton size="sm" color="success" @click="download" class="mr-auto" <CButton size="sm" color="success" class="mr-auto" @click="download">خروجی اکسل</CButton>
>خروجی اکسل</CButton
>
</CustomSubHeader> </CustomSubHeader>
<CRow> <CRow>
@@ -23,8 +21,9 @@
<el-divider></el-divider> <el-divider></el-divider>
<p> <p>
برای اضافه کردن دستگاه جدید فقط کافی است فایل نمونه رو دانلود کنید و به ترتیب مقادیر رو وارد کنید . برای اضافه کردن دستگاه جدید فقط کافی است فایل نمونه رو دانلود کنید و به ترتیب مقادیر رو وارد کنید .
<br> <br />
برای به روزرسانی یک دستگاه به صورت تکی یا عمده داخل فایل نمونه IMEI را قرار داده و مقادیر جدید آن را ثبت کنید و آپلود کنید برای به روزرسانی یک دستگاه به صورت تکی یا عمده داخل فایل نمونه IMEI را قرار داده و مقادیر جدید آن را
ثبت کنید و آپلود کنید
</p> </p>
<a <a
download download
@@ -72,7 +71,6 @@
<CIcon name="cil-grid" /> <CIcon name="cil-grid" />
دستگاه ها دستگاه ها
</slot> </slot>
</CCardHeader> </CCardHeader>
<CCardBody> <CCardBody>
@@ -83,7 +81,7 @@
<el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column> <el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column>
<el-table-column prop="tomanPrice" label="قیمت دستگاه(تومان)" width=""> </el-table-column> <el-table-column prop="tomanPrice" label="قیمت دستگاه(تومان)" width=""> </el-table-column>
<el-table-column prop="dollarProfit" label="سود دلاری فروشنده" width=""> </el-table-column> <!-- <el-table-column prop="dollarProfit" label="سود دلاری فروشنده" width=""> </el-table-column> -->
<el-table-column prop="score" label="امتیاز فروش" width=""> </el-table-column> <el-table-column prop="score" label="امتیاز فروش" width=""> </el-table-column>
<el-table-column prop="renewalProfit" label="سود تمدید" width=""> </el-table-column> <el-table-column prop="renewalProfit" label="سود تمدید" width=""> </el-table-column>
@@ -167,10 +165,8 @@ export default {
}) })
}, },
async download() { async download() {
const x = await this.$axios const x = await this.$axios.get('/api/admin/gps/device/exel')
.get('/api/admin/gps/device/exel') FileDownload(x.data, 'device.csv')
FileDownload(x.data, 'device.csv');
} }
} }
} }
+17 -21
View File
@@ -24,10 +24,7 @@
<CButton color="danger" :class="filterType === 'rej' && 'selected'" @click="filterType = 'rej'" <CButton color="danger" :class="filterType === 'rej' && 'selected'" @click="filterType = 'rej'"
>رد شده</CButton >رد شده</CButton
> >
<CButton <CButton color="success" :class="filterType === 'accept' && 'selected'" @click="filterType = 'accept'"
color="success"
:class="filterType === 'accept' && 'selected'"
@click="filterType = 'accept'"
>تایید شده</CButton >تایید شده</CButton
> >
<CButton color="warning" :class="filterType === 'pend' && 'selected'" @click="filterType = 'pend'" <CButton color="warning" :class="filterType === 'pend' && 'selected'" @click="filterType = 'pend'"
@@ -67,63 +64,63 @@
<el-table-column label="مدل" width="150px"> <el-table-column label="مدل" width="150px">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.deviceId.model }} {{ scope?.row?.deviceId?.model }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column> <el-table-column prop="IMEI" label=" IMEI" width="150px"> </el-table-column>
<el-table-column label="نام فروشگاه" width=""> <el-table-column label="نام فروشگاه" width="">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.userId.shopName }} {{ scope?.row?.userId?.shopName }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="کدملی فروشنده" width=""> <el-table-column label="کدملی فروشنده" width="">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.userId.national_code }} {{ scope?.row?.userId?.national_code }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label=" نام و نام خانوادگی" width=""> <el-table-column label=" نام و نام خانوادگی" width="">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.userId.first_name + " " + scope.row.userId.last_name }} {{ scope?.row?.userId?.first_name + ' ' + scope?.row?.userId?.last_name }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label=" شماره همراه" width=""> <el-table-column label=" شماره همراه" width="">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.userId.mobile_number }} {{ scope?.row?.userId?.mobile_number }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="محل سکونت" width=""> <el-table-column label="محل سکونت" width="">
<template slot-scope="scope"> <template slot-scope="scope">
{{ scope.row.userId.province_name + ", "+ scope.row.userId.city_name }} {{ scope?.row?.userId?.province_name + ', ' + scope?.row?.userId?.city_name }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="وضعیت" width=""> <el-table-column label="وضعیت" width="">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag v-if="scope.row.status == 2" type="danger"> رد شده</el-tag> <el-tag v-if="scope?.row?.status == 2" type="danger"> رد شده</el-tag>
<el-tag v-if="scope.row.status == 1" type="success">تایید شده</el-tag> <el-tag v-if="scope?.row?.status == 1" type="success">تایید شده</el-tag>
<el-tag v-if="scope.row.status == 0" type="warning"> درانتظار تایید</el-tag> <el-tag v-if="scope?.row?.status == 0" type="warning"> درانتظار تایید</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="تایید" width="110" align="center"> <el-table-column label="تایید" width="110" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<CButton <CButton
v-if="scope.row.status == 0 || scope.row.status == 2" v-if="scope?.row?.status == 0 || scope?.row?.status == 2"
:key="scope.row._id" :key="scope?.row?._id"
color="success" color="success"
variant="outline" variant="outline"
@click="post(scope.row._id, 'accept')" @click="post(scope?.row?._id, 'accept')"
> >
<i class="fa fa-check-square"></i> <i class="fa fa-check-square"></i>
</CButton> </CButton>
<CButton <CButton
v-if="scope.row.status == 0 || scope.row.status == 1" v-if="scope?.row?.status == 0 || scope?.row?.status == 1"
:key="scope.row._id" :key="scope?.row?._id"
color="danger" color="danger"
variant="outline" variant="outline"
@click="post(scope.row._id, 'reject')" @click="post(scope?.row?._id, 'reject')"
> >
<i class="fa fa-window-close"></i> <i class="fa fa-window-close"></i>
</CButton> </CButton>
@@ -155,8 +152,7 @@ export default {
devices: [], devices: [],
device: {}, device: {},
filterText: '', filterText: ''
} }
}, },
+13 -6
View File
@@ -10,7 +10,9 @@
<el-descriptions-item label="شهر">{{ requestData.userId?.city_name }}</el-descriptions-item> <el-descriptions-item label="شهر">{{ requestData.userId?.city_name }}</el-descriptions-item>
<el-descriptions-item label="کد ملی ">{{ requestData.userId?.national_code }}</el-descriptions-item> <el-descriptions-item label="کد ملی ">{{ requestData.userId?.national_code }}</el-descriptions-item>
<el-descriptions-item label="نام فروشگاه">{{ requestData.userId?.shopName }}</el-descriptions-item> <el-descriptions-item label="نام فروشگاه">{{ requestData.userId?.shopName }}</el-descriptions-item>
<el-descriptions-item v-if=" requestData.status == 2" label="شماره پیگیری ">{{ requestData.trackingNumber }}</el-descriptions-item> <el-descriptions-item v-if="requestData.status == 2" label="شماره پیگیری ">{{
requestData.trackingNumber
}}</el-descriptions-item>
</el-descriptions> </el-descriptions>
<CCardBody> <CCardBody>
<el-table :data="[requestData?.card]" style="width: 100%"> <el-table :data="[requestData?.card]" style="width: 100%">
@@ -29,9 +31,12 @@
></el-input> ></el-input>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="centerDialogVisible = false">بستن</el-button> <el-button @click="centerDialogVisible = false">بستن</el-button>
<el-button v-if=" requestData.status !== 2" type="primary" @click="patchIt(requestData._id, requestData.status, { trackingNumber })">{{ <el-button
requestData.status == 1 ? 'تایید واریز' : 'تایید' v-if="requestData.status !== 2"
}}</el-button> type="primary"
@click="patchIt(requestData._id, requestData.status, { trackingNumber })"
>{{ requestData.status == 1 ? 'تایید واریز' : 'تایید' }}</el-button
>
</span> </span>
</el-dialog> </el-dialog>
@@ -102,7 +107,7 @@
{{ scope.row.amount }} {{ scope.row.amount }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="dollarAmount" label=" مبلغ دلاری" width="150px"> </el-table-column> <!-- <el-table-column prop="dollarAmount" label=" مبلغ دلاری" width="150px"> </el-table-column> -->
<el-table-column label="نام فروشگاه" width=""> <el-table-column label="نام فروشگاه" width="">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -195,10 +200,12 @@ export default {
if (!this.filterText.length) return filterUsersByType if (!this.filterText.length) return filterUsersByType
else { else {
return this.requestsData.filter(item => { return this.requestsData.filter(item => {
return item.userId.mobile_number.includes(filterText) || return (
item.userId.mobile_number.includes(filterText) ||
item.userId.national_code.includes(filterText) || item.userId.national_code.includes(filterText) ||
item.userId.last_name.includes(filterText) || item.userId.last_name.includes(filterText) ||
item.userId.first_name.includes(filterText) item.userId.first_name.includes(filterText)
)
}) })
} }
}, },
+13 -13
View File
@@ -21,7 +21,7 @@ module.exports.addCode = [
} }
}), }),
body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage('قیمت دستگاه را به تومتن وارد کنید'), body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage('قیمت دستگاه را به تومتن وارد کنید'),
body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به دلار وارد کنید'), // body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به دلار وارد کنید'),
body('profit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به تومان وارد کنید'), body('profit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به تومان وارد کنید'),
body('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'), body('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'),
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید') body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید')
@@ -68,7 +68,7 @@ module.exports.downloadAll = [
{ label: 'IMEI', value: 'IMEI' }, { label: 'IMEI', value: 'IMEI' },
{ label: 'مدل', value: 'model' }, { label: 'مدل', value: 'model' },
{ label: 'قیمت به تومان', value: 'tomanPrice' }, { label: 'قیمت به تومان', value: 'tomanPrice' },
{ label: 'سود به دلار', value: 'dollarProfit' }, // { label: 'سود به دلار', value: 'dollarProfit' },
{ label: 'سود به تومان', value: 'profit' }, { label: 'سود به تومان', value: 'profit' },
{ label: 'امتیاز', value: 'score' }, { label: 'امتیاز', value: 'score' },
{ label: 'سود از تمدید', value: 'renewalProfit' }, { label: 'سود از تمدید', value: 'renewalProfit' },
@@ -138,20 +138,20 @@ module.exports.updateDevice = [
}), }),
body('model').notEmpty().isString().withMessage(_sr.fa.required.name), body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage('قیمت دستگاه را به تومتن وارد کنید'), body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage('قیمت دستگاه را به تومتن وارد کنید'),
body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به دلار وارد کنید'), // body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به دلار وارد کنید'),
body('profit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به تومان وارد کنید'), body('profit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به تومان وارد کنید'),
body('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'), body('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'),
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید') body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید')
], ],
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
const { model, tomanPrice, dollarProfit, profit, score, renewalProfit } = req.body const { model, tomanPrice, profit, score, renewalProfit } = req.body
const data = await Device.findByIdAndUpdate( const data = await Device.findByIdAndUpdate(
req.params.id, req.params.id,
{ {
model, model,
tomanPrice, tomanPrice,
dollarProfit, // dollarProfit,
profit, profit,
score, score,
renewalProfit renewalProfit
@@ -176,20 +176,20 @@ const creator = exel => {
device.model = row[1] device.model = row[1]
device.tomanPrice = row[2] device.tomanPrice = row[2]
device.dollarProfit = row[3] || 1 // device.dollarProfit = row[3] || 1
device.profit = row[4] || 1 device.profit = row[3] || 1
device.score = row[5] || 1 device.score = row[4] || 1
device.renewalProfit = row[6] || 1 device.renewalProfit = row[5] || 1
device.save() device.save()
} else { } else {
await Device.create({ await Device.create({
IMEI: row[0].toString().trim(), IMEI: row[0].toString().trim(),
model: row[1], model: row[1],
tomanPrice: row[2], tomanPrice: row[2],
dollarProfit: row[3] || 1, // dollarProfit: row[3] || 1,
profit: row[4] || 1, profit: row[3] || 1,
score: row[5] || 1, score: row[4] || 1,
renewalProfit: row[6] || 1 renewalProfit: row[5] || 1
}) })
} }
} else { } else {
+5 -5
View File
@@ -56,9 +56,9 @@ module.exports.getAllForUser = async (req, res) => {
let sort = {} let sort = {}
if (req.query?.deviceId_dollarProfit) { // if (req.query?.deviceId_dollarProfit) {
sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit) // sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit)
} // }
if (req.query?.status) { if (req.query?.status) {
sort.status = parseInt(req.query.status) sort.status = parseInt(req.query.status)
} }
@@ -136,7 +136,7 @@ module.exports.updateInstalled = [
if (!installedDevice) { if (!installedDevice) {
throw res.status(404).json({ msg: 'این ایدی وجود ندارد' }) throw res.status(404).json({ msg: 'این ایدی وجود ندارد' })
} else { } else {
const user = await User.findById(installedDevice.userId).select('walletBalance dollarBalance score') const user = await User.findById(installedDevice.userId).select('walletBalance score')
const device = await Device.findById(installedDevice.deviceId) const device = await Device.findById(installedDevice.deviceId)
switch (req.params.type) { switch (req.params.type) {
case 'accept': { case 'accept': {
@@ -145,7 +145,7 @@ module.exports.updateInstalled = [
device.status = 1 device.status = 1
user.walletBalance += device.profit user.walletBalance += device.profit
user.dollarBalance += device.dollarProfit // user.dollarBalance += device.dollarProfit
user.score += device.score user.score += device.score
await Score.create({ await Score.create({
+6 -7
View File
@@ -1,18 +1,17 @@
const User = require('../models/GPS.User'); const User = require('../models/GPS.User')
const InstalledDevice = require('../models/GPS.InstalledDevice'); const InstalledDevice = require('../models/GPS.InstalledDevice')
const Withdraw = require('../models/GPS.Withdraw'); const Withdraw = require('../models/GPS.Withdraw')
module.exports.mainPage = async (req, res) => { module.exports.mainPage = async (req, res) => {
const device = await InstalledDevice.countDocuments({ userId: req.user_id }) const device = await InstalledDevice.countDocuments({ userId: req.user_id })
const user = await User.findById(req.user_id).select('walletBalance dollarBalance score') const user = await User.findById(req.user_id).select('walletBalance score')
res.status(200).json({ installedDevice: device, user }) res.status(200).json({ installedDevice: device, user })
} }
module.exports.walletPage = async (req, res) => { module.exports.walletPage = async (req, res) => {
const withdraw = await Withdraw.findOne({ userId: req.user_id, status: 0 }) const withdraw = await Withdraw.findOne({ userId: req.user_id, status: 0 })
const user = await User.findById(req.user_id).select('walletBalance dollarBalance score') const user = await User.findById(req.user_id).select('walletBalance score')
let pending; let pending
if (withdraw) { if (withdraw) {
pending = true pending = true
+30 -44
View File
@@ -2,18 +2,16 @@ const { body, validationResult } = require('express-validator')
const { _sr } = require('../plugins/serverResponses') const { _sr } = require('../plugins/serverResponses')
const { checkValidations } = require('../plugins/controllersHelperFunctions') const { checkValidations } = require('../plugins/controllersHelperFunctions')
const Renewal = require('../models/GPS.Renewal') const Renewal = require('../models/GPS.Renewal')
const User = require('../models/GPS.User'); const User = require('../models/GPS.User')
const Score = require('../models/GPS.Score'); const Score = require('../models/GPS.Score')
const InstalledDevice = require('../models/GPS.InstalledDevice'); const InstalledDevice = require('../models/GPS.InstalledDevice')
module.exports.create = [ module.exports.create = [
[ [
body('IMEI').notEmpty().isString().withMessage(_sr.fa.required.field), body('IMEI').notEmpty().isString().withMessage(_sr.fa.required.field),
body('renewDate').notEmpty().withMessage(_sr.fa.required.field), body('renewDate').notEmpty().withMessage(_sr.fa.required.field),
body('renewType').notEmpty().withMessage(_sr.fa.required.field), body('renewType').notEmpty().withMessage(_sr.fa.required.field),
body('price').notEmpty().isInt().withMessage(_sr.fa.required.field), body('price').notEmpty().isInt().withMessage(_sr.fa.required.field)
], ],
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
@@ -36,11 +34,11 @@ module.exports.create = [
deviceId: device.deviceId.id, deviceId: device.deviceId.id,
IMEI, IMEI,
profit, profit,
userId:device.userId, userId: device.userId
} }
await Renewal.create(data) await Renewal.create(data)
await Score.create({ await Score.create({
title: " تمدید اشتراک", title: ' تمدید اشتراک',
deviceId: device.deviceId.id, deviceId: device.deviceId.id,
score: device.deviceId.score, score: device.deviceId.score,
userId: device.userId userId: device.userId
@@ -53,74 +51,63 @@ module.exports.create = [
res.status(200) res.status(200)
throw new Error(_sr.fa.response.success_save + 2) throw new Error(_sr.fa.response.success_save + 2)
} }
} catch (error) { } catch (error) {
res.json({ msg: error.message }) res.json({ msg: error.message })
} }
} }
] ]
module.exports.findAllUser = async (req, res) => { module.exports.findAllUser = 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 || req.query.page <= 1) { if (!req.query?.page || req.query.page <= 1) {
page = 0; page = 0
} else { } else {
page = (req.query.page - 1) * rows; page = (req.query.page - 1) * rows
} }
const search = req.query?.search || null; const search = req.query?.search || null
let sort = {}; let sort = {}
if (req.query?.deviceId_dollarProfit) { // if (req.query?.deviceId_dollarProfit) {
sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit); // sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit);
} // }
if (req.query?.status) { if (req.query?.status) {
sort.status = parseInt(req.query.status); sort.status = parseInt(req.query.status)
} }
if (req.query?.registerDate) { if (req.query?.registerDate) {
sort.registerDate = parseInt(req.query.registerDate); sort.registerDate = parseInt(req.query.registerDate)
} }
if (Object.keys(sort).length === 0) { if (Object.keys(sort).length === 0) {
sort = { 'created_at': -1 }; sort = { created_at: -1 }
} }
const filter = { const filter = {
userId: req.user_id, userId: req.user_id
}; }
if (search) { if (search) {
filter.$or = [ filter.$or = [{ IMEI: { $regex: search, $options: 'i' } }]
{ IMEI: { $regex: search, $options: 'i' } },
];
} }
try { try {
const data = await Renewal.find(filter) const data = await Renewal.find(filter).skip(page).limit(rows).sort(sort).populate('deviceId')
.skip(page)
.limit(rows)
.sort(sort)
.populate('deviceId');
const total = await Renewal.countDocuments(filter); const total = await Renewal.countDocuments(filter)
res.status(200).json({ data, total }); res.status(200).json({ data, total })
} catch (error) { } catch (error) {
res.status(500).json({ message: 'An error occurred', error }); res.status(500).json({ message: 'An error occurred', error })
} }
} }
module.exports.findAllAdmin = async (req, res) => { module.exports.findAllAdmin = async (req, res) => {
@@ -152,10 +139,9 @@ module.exports.findAllAdmin = async (req, res) => {
// const totalDocuments = await InstalledDevice.countDocuments(filter); // const totalDocuments = await InstalledDevice.countDocuments(filter);
// const totalPages = Math.ceil(totalDocuments / rows); // const totalPages = Math.ceil(totalDocuments / rows);
res.status(200).json({ data }); res.status(200).json({ data })
} catch (error) { } catch (error) {
console.error('Error:', error.message); console.error('Error:', error.message)
res.status(500).json({ message: "Server Error", error: error.message }); res.status(500).json({ message: 'Server Error', error: error.message })
} }
} }
+55 -70
View File
@@ -1,15 +1,12 @@
const { body, param, validationResult } = require('express-validator'); const { body, param, validationResult } = require('express-validator')
const { _sr } = require('../plugins/serverResponses'); const { _sr } = require('../plugins/serverResponses')
const { checkValidations } = require('../plugins/controllersHelperFunctions'); const { checkValidations } = require('../plugins/controllersHelperFunctions')
const User = require('../models/GPS.User'); const User = require('../models/GPS.User')
const Withdraw = require('../models/GPS.Withdraw'); const Withdraw = require('../models/GPS.Withdraw')
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController') const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
module.exports.createRequest = [ module.exports.createRequest = [
[ [body('card').notEmpty().isObject().withMessage('گارت ورودی خود را انتخاب کنید')],
body('card').notEmpty().isObject().withMessage('گارت ورودی خود را انتخاب کنید'),
],
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
try { try {
@@ -23,13 +20,13 @@ module.exports.createRequest = [
card: req.body.card, card: req.body.card,
userId: req.user_id, userId: req.user_id,
amount: user.walletBalance, amount: user.walletBalance,
dollarAmount: user.dollarBalance, // dollarAmount: user.dollarBalance,
status: 0 status: 0
} }
const request = await Withdraw.create(data) const request = await Withdraw.create(data)
user.dollarBalance = 0; // user.dollarBalance = 0
user.walletBalance = 0; user.walletBalance = 0
user.save() user.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 })
notifyAdmin('newWithdrawRequest') notifyAdmin('newWithdrawRequest')
@@ -37,86 +34,77 @@ module.exports.createRequest = [
} else { } else {
res.status(400).json({ msg: 'حداقل موجودی باید 50 هزار تومان باشد' }) res.status(400).json({ msg: 'حداقل موجودی باید 50 هزار تومان باشد' })
} }
} }
} catch (error) { } catch (error) {
res.status(500).json({ msg: error }) res.status(500).json({ msg: error })
} }
} }
] ]
module.exports.getAllForUser = async (req, res) => { module.exports.getAllForUser = async (req, res) => {
const rows = (!req.query?.rows || req.query?.rows <= 5) ? 10 : parseInt(req.query.rows); const rows = !req.query?.rows || req.query?.rows <= 5 ? 10 : parseInt(req.query.rows)
let page = 0; let page = 0
if (req.query?.page && req.query.page > 1) { if (req.query?.page && req.query.page > 1) {
page = (req.query.page - 1) * rows; page = (req.query.page - 1) * rows
} }
const search = req.query?.search || null; const search = req.query?.search || null
let sort = {}; let sort = {}
if (req.query?.created_at) { if (req.query?.created_at) {
sort.created_at = parseInt(req.query.created_at); sort.created_at = parseInt(req.query.created_at)
} }
if (req.query?.updated_at) { if (req.query?.updated_at) {
sort.updated_at = parseInt(req.query.updated_at); sort.updated_at = parseInt(req.query.updated_at)
} }
if (req.query?.amount) { if (req.query?.amount) {
sort.amount = parseInt(req.query.amount); sort.amount = parseInt(req.query.amount)
} }
if (req.query?.status) { if (req.query?.status) {
sort.status = parseInt(req.query.status); sort.status = parseInt(req.query.status)
} }
if (Object.keys(sort).length === 0) { if (Object.keys(sort).length === 0) {
sort = { created_at: 1 }; sort = { created_at: 1 }
} }
const filter = { const filter = {
userId: req.user_id, userId: req.user_id
}; }
if (search) { if (search) {
filter.$or = [ filter.$or = [{ amount: search }, { trackingNumber: { $regex: search, $options: 'i' } }]
{ amount: search },
{ dollarAmount: search },
{ trackingNumber: { $regex: search, $options: 'i' } },
];
} }
try { try {
const data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort); const data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort)
const total = await Withdraw.countDocuments(filter); const total = await Withdraw.countDocuments(filter)
res.status(200).json({ data, total }); res.status(200).json({ data, total })
} catch (error) { } catch (error) {
res.status(500).json({ message: 'خطای سرور', error }); res.status(500).json({ message: 'خطای سرور', error })
}
} }
};
module.exports.getAllForAdmin = async (req, res) => { module.exports.getAllForAdmin = async (req, res) => {
try { try {
const page = parseInt(req.query.page) || 1; const page = parseInt(req.query.page) || 1
const rows = parseInt(req.query.rows) || 10; const rows = parseInt(req.query.rows) || 10
const search = req.query.search || ""; const search = req.query.search || ''
const sortField = req.query.sortField || "status"; const sortField = req.query.sortField || 'status'
const sortOrder = req.query.sortOrder === "desc" ? -1 : 1; const sortOrder = req.query.sortOrder === 'desc' ? -1 : 1
const skip = (page - 1) * rows; const skip = (page - 1) * rows
const matchStage = search ? { const matchStage = search
$or: [ ? {
{ IMEI: new RegExp(search, 'i') }, $or: [{ IMEI: new RegExp(search, 'i') }, { trackingNumber: new RegExp(search, 'i') }]
{ trackingNumber: new RegExp(search, 'i') } }
] : {}
} : {};
const aggregationPipeline = [ const aggregationPipeline = [
{ $match: matchStage }, { $match: matchStage },
@@ -128,30 +116,29 @@ module.exports.getAllForAdmin = async (req, res) => {
as: 'userId' as: 'userId'
} }
}, },
{ $unwind: "$userId" }, { $unwind: '$userId' },
{ $sort: { [sortField]: sortOrder } }, { $sort: { [sortField]: sortOrder } },
{ $skip: skip }, { $skip: skip },
{ $limit: rows } { $limit: rows }
]; ]
const [data, totalDocuments] = await Promise.all([ const [data, totalDocuments] = await Promise.all([
Withdraw.aggregate(aggregationPipeline), Withdraw.aggregate(aggregationPipeline),
Withdraw.countDocuments(matchStage) Withdraw.countDocuments(matchStage)
]); ])
const totalPages = Math.ceil(totalDocuments / rows); const totalPages = Math.ceil(totalDocuments / rows)
res.status(200).json({ data, totalDocuments, totalPages }); res.status(200).json({ data, totalDocuments, totalPages })
} catch (error) { } catch (error) {
res.status(500).json({ message: "An error occurred, please try again.", error: error.message }); res.status(500).json({ message: 'An error occurred, please try again.', error: error.message })
} }
} }
module.exports.updateReq = [ module.exports.updateReq = [
[ [
param('id').notEmpty().isMongoId().withMessage('ایدی را باید وارد کنید'), param('id').notEmpty().isMongoId().withMessage('ایدی را باید وارد کنید'),
param('type').notEmpty().isString().withMessage('وضعیت را باید وارد کنید'), param('type').notEmpty().isString().withMessage('وضعیت را باید وارد کنید')
], ],
checkValidations(validationResult), checkValidations(validationResult),
async (req, res) => { async (req, res) => {
@@ -160,33 +147,31 @@ module.exports.updateReq = [
res.status(404).json({ msg: _sr.fa.not_found.item_id }) res.status(404).json({ msg: _sr.fa.not_found.item_id })
} else { } else {
switch (req.params.type) { switch (req.params.type) {
case "accept": { case 'accept': {
request.status = 1; request.status = 1
request.save() request.save()
notifyAdmin('newWithdrawRequest') notifyAdmin('newWithdrawRequest')
res.status(201).json({ msg: _sr.fa.response.success_save, data: request }) res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
break; break
} }
case "deposit": { case 'deposit': {
request.status = 2; request.status = 2
request.depositDate = new Date(); request.depositDate = new Date()
request.trackingNumber = req.body.trackingNumber || 0; request.trackingNumber = req.body.trackingNumber || 0
request.save() request.save()
notifyAdmin('newWithdrawRequest') notifyAdmin('newWithdrawRequest')
res.status(201).json({ msg: _sr.fa.response.success_save, data: request }) res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
break; break
} }
default: { default: {
res.status(404).json({ msg: "استاتوس اشتباه است" }) res.status(404).json({ msg: 'استاتوس اشتباه است' })
break; break
} }
} }
} }
} }
] ]
+6 -6
View File
@@ -4,18 +4,18 @@ const deviceSchema = mongoose.Schema({
model: String, model: String,
IMEI: { IMEI: {
type: String, type: String,
unique: [true, "این ایدی در سامانه موجود است"] unique: [true, 'این ایدی در سامانه موجود است']
}, },
tomanPrice: { tomanPrice: {
type: Number, type: Number,
min: 0, min: 0,
default: 0 default: 0
}, },
dollarProfit: { // dollarProfit: {
type: Number, // type: Number,
min: 0, // min: 0,
default: 0 // default: 0
}, // },
profit: { profit: {
type: Number, type: Number,
min: 0, min: 0,
+8 -10
View File
@@ -3,14 +3,13 @@ const mongoose = require('mongoose')
const BankSchema = mongoose.Schema({ const BankSchema = mongoose.Schema({
holderName: String, holderName: String,
PAN: { PAN: {
type: Number, type: Number
}, },
IBAN: { IBAN: {
type: String, type: String
} }
}) })
const UserSchema = mongoose.Schema({ const UserSchema = mongoose.Schema({
first_name: String, first_name: String,
last_name: String, last_name: String,
@@ -23,7 +22,7 @@ const UserSchema = mongoose.Schema({
password: String, password: String,
profilePic: { profilePic: {
type: String, type: String,
default: "noPic" default: 'noPic'
}, },
shopName: String, shopName: String,
birthDate: String, birthDate: String,
@@ -33,11 +32,11 @@ const UserSchema = mongoose.Schema({
min: 0, min: 0,
default: 0 default: 0
}, },
dollarBalance: { // dollarBalance: {
type: Number, // type: Number,
min: 0, // min: 0,
default: 0 // default: 0
}, // },
score: { score: {
type: Number, type: Number,
min: 0, min: 0,
@@ -46,7 +45,6 @@ const UserSchema = mongoose.Schema({
cardBank: [BankSchema], cardBank: [BankSchema],
active: { type: Boolean, default: false }, active: { type: Boolean, default: false },
/// //////////////////////////////// user confirmations /// //////////////////////////////// user confirmations
seenByAdmin: { type: Boolean, default: false }, seenByAdmin: { type: Boolean, default: false },
+7 -8
View File
@@ -1,13 +1,12 @@
const mongoose = require('mongoose') const mongoose = require('mongoose')
const BankSchema = mongoose.Schema({ const BankSchema = mongoose.Schema({
holderName: String, holderName: String,
PAN: { PAN: {
type: Number, type: Number
}, },
IBAN: { IBAN: {
type: String, type: String
} }
}) })
@@ -18,10 +17,10 @@ const WithdrawSchema = mongoose.Schema({
type: Number, type: Number,
min: 0 min: 0
}, },
dollarAmount: { // dollarAmount: {
type: Number, // type: Number,
min: 0 // min: 0
}, // },
userId: { userId: {
type: String, type: String,
ref: 'UserGPS' ref: 'UserGPS'
@@ -31,7 +30,7 @@ const WithdrawSchema = mongoose.Schema({
enum: [ enum: [
0, // Pending 0, // Pending
1, // Accepted 1, // Accepted
2, // deposited 2 // deposited
] ]
}, },
depositDate: Date, depositDate: Date,
Binary file not shown.