insatller fee
This commit is contained in:
@@ -337,13 +337,13 @@
|
|||||||
:badge="pendingUsers ? { text: pendingUsers, color: 'danger' } : null"
|
:badge="pendingUsers ? { text: pendingUsers, color: 'danger' } : null"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CSidebarNavItem
|
<!-- <CSidebarNavItem
|
||||||
v-if="hasPermission('gps')"
|
v-if="hasPermission('gps')"
|
||||||
name="دستگاه ها"
|
name="دستگاه ها"
|
||||||
:to="{ name: 'admin-gps-device' }"
|
:to="{ name: 'admin-gps-device' }"
|
||||||
font-icon="fal fa-microchip"
|
font-icon="fal fa-microchip"
|
||||||
:exact="false"
|
:exact="false"
|
||||||
/>
|
/> -->
|
||||||
<CSidebarNavItem
|
<CSidebarNavItem
|
||||||
v-if="hasPermission('gps')"
|
v-if="hasPermission('gps')"
|
||||||
name="دستگاه های ثبت شده"
|
name="دستگاه های ثبت شده"
|
||||||
@@ -352,6 +352,13 @@
|
|||||||
:badge="newInstallDeviceRequest ? { text: newInstallDeviceRequest, color: 'danger' } : null"
|
:badge="newInstallDeviceRequest ? { text: newInstallDeviceRequest, color: 'danger' } : null"
|
||||||
:exact="false"
|
:exact="false"
|
||||||
/>
|
/>
|
||||||
|
<CSidebarNavItem
|
||||||
|
v-if="hasPermission('gps')"
|
||||||
|
name="هزینه نصب"
|
||||||
|
:to="{ name: 'admin-gps-fee' }"
|
||||||
|
font-icon="fal fa-money-bill"
|
||||||
|
:exact="false"
|
||||||
|
/>
|
||||||
<CSidebarNavItem
|
<CSidebarNavItem
|
||||||
v-if="hasPermission('gps')"
|
v-if="hasPermission('gps')"
|
||||||
name="درخواست های برداشت"
|
name="درخواست های برداشت"
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
|
||||||
|
<CustomSubHeader>
|
||||||
|
<CBreadcrumb class="border-0 mb-0"> تنظیم هزینه نصب </CBreadcrumb>
|
||||||
|
</CustomSubHeader>
|
||||||
|
|
||||||
|
<CRow>
|
||||||
|
<CCol xl="6">
|
||||||
|
<CCard>
|
||||||
|
<CCardHeader>
|
||||||
|
<slot name="header">
|
||||||
|
<i class="fas fa-filter"></i>
|
||||||
|
<b>فیلتر ها</b>
|
||||||
|
</slot>
|
||||||
|
</CCardHeader>
|
||||||
|
|
||||||
|
<CCardBody>
|
||||||
|
<CRow>
|
||||||
|
<CCol sm="12">
|
||||||
|
|
||||||
|
</CCol>
|
||||||
|
<CCol sm="12">
|
||||||
|
<el-divider></el-divider>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm="12">
|
||||||
|
<el-form :model="form" :rules="rules" ref="form">
|
||||||
|
<el-form-item label="مبلغ نصب" prop="amount">
|
||||||
|
<el-input v-model="form.amount" placeholder="مبلغ"></el-input>
|
||||||
|
<span v-if="form.amount">{{ formatCurrency(form.amount) }}</span>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item >
|
||||||
|
<el-button type="primary" @click="setFee">ثبت</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</CCol>
|
||||||
|
</CRow>
|
||||||
|
</CCardBody>
|
||||||
|
</CCard>
|
||||||
|
</CCol>
|
||||||
|
</CRow>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'AdminGpsWithdrawList',
|
||||||
|
layout: 'admin',
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
form: {
|
||||||
|
amount: 0
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
amount: [{ required: true, message: 'لطفا مبلغ را وارد کنید', trigger: 'blur' }]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
async setFee() {
|
||||||
|
try {
|
||||||
|
await this.$axios.post('/api/admin/gps/install-fee', this.form)
|
||||||
|
.then(res => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: 'هزینه نصب با موفقیت ثبت شد'
|
||||||
|
})
|
||||||
|
this.$nuxt.refresh()
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async getFee() {
|
||||||
|
try {
|
||||||
|
await this.$axios.get('/api/admin/gps/install-fee')
|
||||||
|
.then(res => {
|
||||||
|
this.form.amount = res.data.amount
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
formatCurrency(amount) {
|
||||||
|
const formatted= new Intl.NumberFormat('fa-IR').format(amount);
|
||||||
|
return `${formatted} تومان`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.getFee()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
.unreadMsgInCv {
|
||||||
|
background: rgba(orange, 0.1) !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -65,6 +65,7 @@
|
|||||||
<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 }}
|
||||||
|
{{ scope?.row?.deviceType }}
|
||||||
</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>
|
||||||
@@ -106,7 +107,7 @@
|
|||||||
</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"
|
||||||
@@ -114,7 +115,7 @@
|
|||||||
@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"
|
||||||
|
|||||||
@@ -143,6 +143,11 @@
|
|||||||
<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="">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{new Date(scope.row.created_at).toLocaleString('fa-IR') }}
|
||||||
|
</template>
|
||||||
|
</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 :key="scope.row._id" color="info" variant="outline" @click="showDialog(scope.row)">
|
<CButton :key="scope.row._id" color="info" variant="outline" @click="showDialog(scope.row)">
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const { body, validationResult } = require('express-validator')
|
||||||
|
const Fee = require('../models/GPS.Fee')
|
||||||
|
const titleKey = 'install_fee'
|
||||||
|
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||||
|
|
||||||
|
module.exports.setFee = [
|
||||||
|
[body('amount').notEmpty().isInt().withMessage('مقدار هزینه را وارد کنید')],
|
||||||
|
checkValidations(validationResult),
|
||||||
|
async (req, res) => {
|
||||||
|
const { amount } = req.body
|
||||||
|
const fee = await Fee.findOne({ title: titleKey })
|
||||||
|
if (fee) {
|
||||||
|
fee.amount = amount
|
||||||
|
await fee.save()
|
||||||
|
return res.status(200).json(fee)
|
||||||
|
}
|
||||||
|
const newFee = await Fee.create({ title: titleKey, amount })
|
||||||
|
res.status(201).json(newFee)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
module.exports.getFee = async (req, res) => {
|
||||||
|
const fee = await Fee.findOne({ title: titleKey })
|
||||||
|
res.status(200).json(fee)
|
||||||
|
}
|
||||||
@@ -4,33 +4,39 @@ const User = require('../models/GPS.User')
|
|||||||
const InstalledDevice = require('../models/GPS.InstalledDevice')
|
const InstalledDevice = require('../models/GPS.InstalledDevice')
|
||||||
const Device = require('../models/GPS.Device')
|
const Device = require('../models/GPS.Device')
|
||||||
const userGPS = require('../models/GPS.User')
|
const userGPS = require('../models/GPS.User')
|
||||||
|
const Fee = require('../models/GPS.Fee')
|
||||||
const Score = require('../models/GPS.Score')
|
const Score = require('../models/GPS.Score')
|
||||||
const { _sr } = require('../plugins/serverResponses')
|
const { _sr } = require('../plugins/serverResponses')
|
||||||
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||||
const { isDeviceRegisteredOnKoja } = require('../kojaWebService')
|
const { findDeviceByImeiOnKoja } = require('../kojaWebService')
|
||||||
|
|
||||||
module.exports.deviceRegistration = [
|
module.exports.deviceRegistration = [
|
||||||
[body('IMEI').notEmpty().isString().withMessage('لطفا IMEI را وارد یا تصحیح کنید')],
|
[body('IMEI').notEmpty().isString().withMessage('لطفا IMEI را وارد یا تصحیح کنید')],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const IMEI = req.body.IMEI
|
const IMEI = req.body.IMEI
|
||||||
|
console.log('IMEI ******************', IMEI)
|
||||||
try {
|
try {
|
||||||
const device = await Device.findOne({ IMEI })
|
const installedDevice = await InstalledDevice.findOne({ IMEI })
|
||||||
if (!device) {
|
// // const installedDevice = false
|
||||||
return res.status(404).json({ msg: 'این IMEI وجود ندارد' })
|
if (installedDevice) {
|
||||||
}
|
|
||||||
if (device.status === 1) {
|
|
||||||
return res.status(400).json({ msg: 'این IMEI قبلا ثبت شده ' })
|
return res.status(400).json({ msg: 'این IMEI قبلا ثبت شده ' })
|
||||||
}
|
}
|
||||||
const isRegistered = await isDeviceRegisteredOnKoja(IMEI)
|
// const isRegisteredOnKoja = true
|
||||||
|
const RegisteredDevice = await findDeviceByImeiOnKoja(IMEI)
|
||||||
if (isRegistered) {
|
if (!RegisteredDevice) {
|
||||||
|
return res.status(400).json({ msg: 'هنوز در سامانه ردیاب ثبت نشده است.' })
|
||||||
|
}
|
||||||
let installedDeviceId = null
|
let installedDeviceId = null
|
||||||
try {
|
try {
|
||||||
|
const fee = await Fee.findOne({ title: 'install_fee' })
|
||||||
|
if (!fee) {
|
||||||
|
return res.status(400).json({ msg: 'هزینه نصب یافت نشد' })
|
||||||
|
}
|
||||||
const data = {
|
const data = {
|
||||||
deviceId: device.id,
|
// deviceId: RegisteredDevice.deviceId,
|
||||||
status: 0,
|
deviceType: RegisteredDevice.device_type.name,
|
||||||
|
status: 1,
|
||||||
registerDate: new Date(),
|
registerDate: new Date(),
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
IMEI: req.body.IMEI
|
IMEI: req.body.IMEI
|
||||||
@@ -38,11 +44,9 @@ module.exports.deviceRegistration = [
|
|||||||
// 1.add to installed device
|
// 1.add to installed device
|
||||||
const installedDevice = await InstalledDevice.create(data)
|
const installedDevice = await InstalledDevice.create(data)
|
||||||
installedDeviceId = installedDevice._id
|
installedDeviceId = installedDevice._id
|
||||||
// 2. change status
|
|
||||||
await Device.findOneAndUpdate({ IMEI }, { status: 1 })
|
|
||||||
|
|
||||||
// 3. add to wallet
|
// 2. add to wallet
|
||||||
await userGPS.findByIdAndUpdate(req.user_id, { $inc: { walletBalance: 100_000 } })
|
await userGPS.findByIdAndUpdate(req.user_id, { $inc: { walletBalance:fee.amount } })
|
||||||
|
|
||||||
notifyAdmin('newInstallDeviceRequest')
|
notifyAdmin('newInstallDeviceRequest')
|
||||||
res.status(201).json({ msg: 'مبلغ صد هزار تومان به کیف پول شما اضافه شد' })
|
res.status(201).json({ msg: 'مبلغ صد هزار تومان به کیف پول شما اضافه شد' })
|
||||||
@@ -51,18 +55,13 @@ module.exports.deviceRegistration = [
|
|||||||
if (installedDeviceId) {
|
if (installedDeviceId) {
|
||||||
try {
|
try {
|
||||||
await InstalledDevice.deleteOne({ _id: installedDeviceId })
|
await InstalledDevice.deleteOne({ _id: installedDeviceId })
|
||||||
console.log('Rollback 1/2: InstalledDevice deleted.')
|
console.log('Rollback: InstalledDevice deleted.')
|
||||||
await Device.findOneAndUpdate({ IMEI }, { status: 0 })
|
|
||||||
console.log('Rollback 2/2: Device status reset to 0.')
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('CRITICAL: Rollback failed for some changes. MANUAL INTERVENTION REQUIRED.', error)
|
console.error('CRITICAL: Rollback failed for some changes. MANUAL INTERVENTION REQUIRED.', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res.status(err?.status || 500).json({ msg: err?.msg || 'خطا در تراکنش های دیتابیس ' })
|
return res.status(err?.status || 500).json({ msg: err?.msg || 'خطا در تراکنش های دیتابیس ' })
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
res.status(400).json({ msg: 'هنوز در سامانه ردیاب ثبت نشده است.' })
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('deviceRegistration Error: ', err?.message)
|
console.log('deviceRegistration Error: ', err?.message)
|
||||||
if (err.response) {
|
if (err.response) {
|
||||||
@@ -147,7 +146,7 @@ module.exports.getAllForAdmin = async (req, res) => {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const data = await InstalledDevice.find()
|
const data = await InstalledDevice.find()
|
||||||
// .sort({ [sortField]: sortOrder })
|
.sort({ created_at: -1 })
|
||||||
.populate('deviceId')
|
.populate('deviceId')
|
||||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
||||||
// .skip(skip)
|
// .skip(skip)
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ 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)
|
||||||
|
if (!user) {
|
||||||
|
return res.status(400).json({ msg: 'کاربر یافت نشد' })
|
||||||
|
}
|
||||||
|
if (req.body.amount > user.walletBalance) {
|
||||||
|
return res.status(400).json({ msg: 'موجودی شما کافی نیست' })
|
||||||
|
}
|
||||||
if (user.walletBalance >= 50000) {
|
if (user.walletBalance >= 50000) {
|
||||||
const data = {
|
const data = {
|
||||||
card: req.body.card,
|
card: req.body.card,
|
||||||
|
|||||||
+10
-12
@@ -1,29 +1,27 @@
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const { kojaBaseUrl, kojaAccount } = require('./_env')
|
const { kojaBaseUrl, kojaAccount } = require('./_env')
|
||||||
|
|
||||||
export async function isDeviceRegisteredOnKoja(imei) {
|
export async function findDeviceByImeiOnKoja(imei) {
|
||||||
try {
|
try {
|
||||||
const result = await axios.get(`/devices/imei/${imei}`, {
|
const result = await axios.get(`/devices/imei/${imei}`, {
|
||||||
baseURL: kojaBaseUrl,
|
baseURL: kojaBaseUrl,
|
||||||
auth: kojaAccount
|
auth: kojaAccount
|
||||||
})
|
})
|
||||||
console.log('device registration check result from koja.ir', result)
|
|
||||||
if (result.status === 200) {
|
console.log('result.data from koja.ir******************', result.data.result)
|
||||||
return true
|
return result.data.result
|
||||||
}
|
|
||||||
return result
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
const { status } = error.response
|
const { status } = error.response
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
throw new Error('خطا در اتصال به سامانه ردیاب')
|
throw new Error('خطا در اتصال به سامانه ردیاب')
|
||||||
}
|
}
|
||||||
if (status === 404) {
|
// if (status === 404) {
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
if (status === 403) {
|
// if (status === 403) {
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
throw error
|
throw error
|
||||||
} else {
|
} else {
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
const mongoose = require('mongoose')
|
||||||
|
|
||||||
|
|
||||||
|
const FeeSchema = mongoose.Schema({
|
||||||
|
title: String,
|
||||||
|
amount: Number,
|
||||||
|
createdAt: { type: Date, default: Date.now },
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = mongoose.model('Fee', FeeSchema)
|
||||||
@@ -6,6 +6,7 @@ const InstalledDeviceSchema = mongoose.Schema({
|
|||||||
ref: "Device"
|
ref: "Device"
|
||||||
},
|
},
|
||||||
IMEI:String,
|
IMEI:String,
|
||||||
|
deviceType:String,
|
||||||
status: {
|
status: {
|
||||||
type: Number,
|
type: Number,
|
||||||
enum: [
|
enum: [
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const award = require('../controllers/GPS.Award')
|
|||||||
const awardRequest = require('../controllers/GPS.AwardRequest')
|
const awardRequest = require('../controllers/GPS.AwardRequest')
|
||||||
const userGPS = require('../controllers/GPS.User')
|
const userGPS = require('../controllers/GPS.User')
|
||||||
const renewal = require('../controllers/GPS.Renewal')
|
const renewal = require('../controllers/GPS.Renewal')
|
||||||
|
const fee = require('../controllers/GPS.Fee')
|
||||||
/// //////////////////////////////////////////////////////// routes
|
/// //////////////////////////////////////////////////////// routes
|
||||||
|
|
||||||
/// ///////////////////////////// GPS
|
/// ///////////////////////////// GPS
|
||||||
@@ -81,6 +81,9 @@ router.get('/gps/device/imei/:imei', hasPermission('gps'), device.getOneByIMEI)
|
|||||||
router.get('/gps/device/id/:id', hasPermission('gps'), device.getOne)
|
router.get('/gps/device/id/:id', hasPermission('gps'), device.getOne)
|
||||||
router.put('/gps/device/:id', hasPermission('gps'), device.updateDevice)
|
router.put('/gps/device/:id', hasPermission('gps'), device.updateDevice)
|
||||||
|
|
||||||
|
/// ////////////// Fee
|
||||||
|
router.post('/gps/install-fee', hasPermission('gps'), fee.setFee)
|
||||||
|
router.get('/gps/install-fee', hasPermission('gps'), fee.getFee)
|
||||||
/// /////////////////////////////////////////////////////////
|
/// /////////////////////////////////////////////////////////
|
||||||
/// ///////////// survey
|
/// ///////////// survey
|
||||||
router.get('/surveys', hasPermission('surveys'), surveyController.getAllForAdmin)
|
router.get('/surveys', hasPermission('surveys'), surveyController.getAllForAdmin)
|
||||||
|
|||||||
Reference in New Issue
Block a user