增加订单功能

pull/12/head
youngS 4 years ago
parent 1fcf10575d
commit fb973da90e
  1. 65
      fir_client/src/components/FirApps.vue
  2. 13
      fir_client/src/components/FirHeader.vue
  3. 7
      fir_client/src/components/FirSuperSignBase.vue
  4. 352
      fir_client/src/components/FirUserOrders.vue
  5. 30
      fir_client/src/restful/index.js
  6. 31
      fir_client/src/router/index.js
  7. 2
      fir_ser/api/admin.py
  8. 50
      fir_ser/api/models.py
  9. 4
      fir_ser/api/urls.py
  10. 12
      fir_ser/api/utils/serializer.py
  11. 13
      fir_ser/api/utils/storage/caches.py
  12. 10
      fir_ser/api/utils/utils.py
  13. 135
      fir_ser/api/views/order.py
  14. 8
      fir_ser/api/views/supersign.py

@ -27,7 +27,9 @@
</div> </div>
</div> </div>
<div class="package-actions"> <div class="package-actions">
<button type="button" class="btn" @click="buy(packages)">购买</button> <button type="button" class="btn" @click="buy(packages)" :disabled="buy_button_disable">
购买
</button>
</div> </div>
</div> </div>
@ -334,7 +336,7 @@
</div> </div>
<div> <div>
<el-button class="action" size="small" icon="el-icon-shopping-cart-1" <el-button class="action" size="small" icon="el-icon-shopping-cart-1"
@click="show_buy_download_times=true"></el-button> @click="show_package_prices"></el-button>
</div> </div>
</el-col> </el-col>
@ -472,7 +474,7 @@
</template> </template>
<script> <script>
import {getapps, apputils, analyseApps, getuploadurl} from "../restful"; import {getapps, apputils, analyseApps, getuploadurl, get_package_prices, my_order} from "../restful";
import { import {
getScrollHeight, getScrollHeight,
getScrollTop, getScrollTop,
@ -511,33 +513,42 @@
uploadsuccess: 0, uploadsuccess: 0,
loadingobj: null, loadingobj: null,
show_buy_download_times: false, show_buy_download_times: false,
data_package_prices: [{ data_package_prices: [],
"name": "1k_times", buy_button_disable: false,
"title": "1k_times",
"description": "1k_times",
"price": 2500,
"package_size": 1000,
"download_count_gift": 111
}, {
"name": "10k_times",
"title": "10k_times",
"description": "10k_times",
"price": 22500,
"package_size": 10000,
"download_count_gift": 222
}, {
"name": "100k_times",
"title": "100k_times",
"description": "100k_times",
"price": 200000,
"package_size": 100000,
"download_count_gift": 333
}]
} }
}, methods: { }, methods: {
show_package_prices() {
get_package_prices(res => {
if (res.code === 1000) {
this.show_buy_download_times = true;
this.data_package_prices = res.data;
} else {
this.$message.error("获取价格异常");
this.show_buy_download_times = false;
}
}, {})
},
buy(packages) { buy(packages) {
// eslint-disable-next-line no-console this.buy_button_disable = true;
console.log(packages) my_order(res => {
if (res.code === 1000) {
this.$message.success("下订单成功,正在跳转,请去我的订单进行支付");
// eslint-disable-next-line no-unused-vars
this.timmer = setTimeout(data => {
this.$router.push({"name": 'FirUserOrders'});
this.buy_button_disable = false;
}, 2000);
} else {
this.$message.error("异常" + res.msg);
this.buy_button_disable = false;
}
}, {
methods: 'POST', data: {
price_id: packages.name
}
})
}, },
showUDID(appinfo) { showUDID(appinfo) {
let udidstr = ''; let udidstr = '';

@ -51,7 +51,7 @@
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item command="supersign" v-if="$store.state.userinfo.supersign_active">超级签名 <el-dropdown-item command="supersign" v-if="$store.state.userinfo.supersign_active">超级签名
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item command="myorder">订单信息</el-dropdown-item>
<el-dropdown-item command="exit">退出</el-dropdown-item> <el-dropdown-item command="exit">退出</el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
@ -89,6 +89,8 @@
type: 'success', type: 'success',
message: '重新生成成功!' message: '重新生成成功!'
}); });
} else {
this.$message.error("失败了 " + data.msg)
} }
}, {methods: 'PUT', token: this.token}); }, {methods: 'PUT', token: this.token});
}, },
@ -103,15 +105,18 @@
this.$store.dispatch('doucurrentapp', {}); this.$store.dispatch('doucurrentapp', {});
this.$router.push({"name": 'FirSuperSignBase', params: {act: "iosdeveloper"}}) this.$router.push({"name": 'FirSuperSignBase', params: {act: "iosdeveloper"}})
} else if (command === 'apitoken') { } else if (command === 'apitoken') {
this.dialogVisible = true;
apitoken(data => { apitoken(data => {
if (data.code === 1000) { if (data.code === 1000) {
this.token = data.data.token; this.token = data.data.token;
this.dialogVisible = true;
} else {
this.dialogVisible = false;
this.$message.error("获取失败了 " + data.msg)
} }
}, {methods: 'GET', token: this.token}); }, {methods: 'GET', token: this.token});
} else if (command === 'myorder') {
this.$router.push({"name": 'FirUserOrders'})
} else if (command === 'exit') { } else if (command === 'exit') {
logout(data => { logout(data => {
if (data.code === 1000) { if (data.code === 1000) {

@ -755,12 +755,5 @@
border-radius: 1%; border-radius: 1%;
} }
/*.goback {*/
/* display: block;*/
/* cursor: pointer;*/
/* position: absolute;*/
/* top: 0;*/
/* right: 0;*/
/*}*/
</style> </style>

@ -0,0 +1,352 @@
<template>
<el-main>
<el-dialog
:visible.sync="show_order_info"
width="780px"
:close-on-click-modal="false"
:close-on-press-escape="false"
title="订单详情"
top="6vh"
center>
<div>
<el-form :model="current_order_info"
label-width="80px" style="margin:0 auto;">
<el-form-item label-width="110px" label="平台订单ID">
<el-input :value="current_order_info.order_number"/>
</el-form-item>
<el-form-item label-width="110px" label="第三方订单ID">
<el-input :value="current_order_info.payment_number"/>
</el-form-item>
<el-form-item label-width="110px" label="付款方式">
<el-input :value="format_payment_type(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="订单状态">
<el-input :value="format_status_type(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="订单类型">
<el-input :value="format_order_type(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="实付金额">
<el-input :value="format_actual_amount(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="购买数量">
<el-input
v-model="current_order_info.actual_download_times"/>
</el-form-item>
<el-form-item label-width="110px" label="赠送数量">
<el-input
v-model="current_order_info.actual_download_gift_times"/>
</el-form-item>
<el-form-item label-width="110px" label="订单创建时间">
<el-input :value="format_create_time(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="订单支付时间">
<el-input :value="format_pay_time(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="订单取消时间">
<el-input :value="format_cancel_time(current_order_info)"/>
</el-form-item>
<el-form-item label-width="110px" label="备注">
<el-input :value="current_order_info.description"/>
</el-form-item>
</el-form>
</div>
<span slot="footer">
如对订单有疑问请联系 nineven@qq.com
</span>
</el-dialog>
<div>
<el-input
style="width: 30%;margin-right: 30px;margin-bottom: 10px"
v-model="order_id_seach"
clearable
placeholder="输入订单ID"/>
<el-button type="primary" icon="el-icon-search" @click="handleCurrentChange(pagination.currentPage)">
搜索
</el-button>
<el-table
:data="order_info_list"
border
stripe
style="width: 100%">
<el-table-column
fixed
prop="order_number"
label="系统订单ID">
</el-table-column>
<el-table-column
prop="status"
label="状态"
align="center"
width="130">
<template slot-scope="scope">
<div v-if="scope.row.status === 1">
<el-button @click="goto_pay(scope.row)"
type="primary" size="small"> 去支付
</el-button>
</div>
<div v-else-if="scope.row.status === 0">
<el-button @click="click_order_info(scope.row)"
type="success" size="small"> {{ format_status_type(scope.row)}}
</el-button>
</div>
<div v-else-if="scope.row.status === 4 || scope.row.status ===5">
<el-button @click="click_order_info(scope.row)"
type="danger" size="small"> {{ format_status_type(scope.row)}}
</el-button>
</div>
<div v-else>
<el-button @click="click_order_info(scope.row)"
type="warning" size="small"> {{ format_status_type(scope.row)}}
</el-button>
</div>
</template>
</el-table-column>
<el-table-column
:formatter="format_actual_amount"
prop="actual_amount"
label="实付金额"
width="100">
</el-table-column>
<el-table-column
prop="actual_download_times"
label="购买数量"
width="120">
</el-table-column>
<el-table-column
prop="actual_download_gift_times"
label="赠送数量"
width="100">
</el-table-column>
<el-table-column
:formatter="format_create_time"
prop="created_time"
label="订单创建时间"
>
</el-table-column>
<el-table-column
fixed="right"
label="查看详细"
width="100">
<template slot-scope="scope">
<el-button
size="mini"
@click="click_order_info(scope.row)">详情
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div style="margin-top: 20px;margin-bottom: 20px">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="pagination.currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="pagination.pagesize"
layout="total,sizes, prev, pager, next"
:total="pagination.total">
</el-pagination>
</div>
</el-main>
</template>
<script>
import {my_order, userinfos} from "../restful";
export default {
name: "FirUserOrders",
data() {
return {
order_info_list: [],
order_id_seach: "",
pagination: {"currentPage": 1, "total": 0, "pagesize": 10},
order_type_choices: [],
status_choices: [],
payment_type_choices: [],
show_order_info: false,
current_order_info: {},
}
},
methods: {
goto_pay(order) {
// eslint-disable-next-line no-console
console.log(order)
my_order(res => {
//
if (res.code === 1000) {
this.$message.success("支付成功");
this.get_data_from_tabname();
} else {
this.$message.error("失败了 " + res.msg)
}
}, {
methods: 'PUT', data: {order_number: order.order_number},
})
},
click_order_info(order) {
this.show_order_info = true;
this.current_order_info = order;
},
handleSizeChange(val) {
this.pagination.pagesize = val;
this.get_data_from_tabname({
"size": this.pagination.pagesize,
"page": this.pagination.currentPage
})
},
handleCurrentChange(val) {
this.pagination.currentPage = val;
this.get_data_from_tabname({
"size": this.pagination.pagesize,
"page": this.pagination.currentPage
})
},
get_data_from_tabname(data = {}) {
data.order_id = this.order_id_seach.replace(/^\s+|\s+$/g, "");
this.MyOrderFun(data)
},
format_choices(key, obj) {
for (let i = 0; i < obj.length; i++) {
if (key === obj[i].id) {
return obj[i].name
}
}
return "未知"
},
format_payment_type(row) {
return this.format_choices(row.payment_type, this.payment_type_choices)
},
format_status_type(row) {
return this.format_choices(row.status, this.status_choices)
},
format_order_type(row) {
return this.format_choices(row.order_type, this.order_type_choices)
},
format_actual_amount(row) {
return '¥ ' + (row.actual_amount / 100).toString()
},
format_create_time(row) {
return this.format_time(row.created_time)
},
format_pay_time(row) {
return this.format_time(row.pay_time)
},
format_cancel_time(row) {
return this.format_time(row.cancel_time)
},
format_time(stime) {
if (stime) {
stime = stime.split(".")[0].split("T");
return stime[0] + " " + stime[1]
} else
return '';
},
MyOrderFun(params) {
const loading = this.$loading({
lock: true,
text: '执行中,请耐心等待...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
my_order(data => {
if (data.code === 1000) {
this.order_info_list = data.data;
this.pagination.total = data.count;
this.payment_type_choices = data.payment_type_choices;
this.status_choices = data.status_choices;
this.order_type_choices = data.order_type_choices;
} else if (data.code === 1008) {
this.$message.error(data.msg);
} else {
this.$message.error("操作失败")
}
loading.close();
}, {methods: 'GET', data: params})
},
getUserInfoFun() {
userinfos(data => {
if (data.code === 1000) {
this.$store.dispatch("doUserinfo", data.data);
} else {
this.$message.error("用户信息获取失败")
}
}, {"methods": "GET"})
},
}, mounted() {
this.getUserInfoFun();
this.get_data_from_tabname()
}, filters: {}
}
</script>
<style scoped>
.el-main {
margin: 10px auto 100px;
width: 1166px;
position: relative;
padding-bottom: 1px;
background-color: #bfe7f9;
color: #9b9b9b;
-webkit-font-smoothing: antialiased;
border-radius: 1%;
}
</style>

@ -483,3 +483,33 @@ export function iosdevicesudid(callBack, params, load = true) {
true true
); );
} }
/**获取充值价格信息 */
export function get_package_prices(callBack, params, load = true) {
getData(
'GET',
USERSEVER + '/package_prices',
params,
data => {
callBack(data);
},
load,
true,
true
);
}
/**用户订单 */
export function my_order(callBack, params, load = true) {
getData(
params.methods,
USERSEVER + '/orders',
params.data,
data => {
callBack(data);
},
load,
true,
true
);
}

@ -11,25 +11,6 @@ VueRouter.prototype.push = function push(location) {
}; };
// import FirIndex from "@/components/FirIndex";
// import FirApps from "@/components/FirApps";
// import FirLogin from "@/components/FirLogin";
// import FirRegist from "@/components/FirRegist";
// import FirDownload from "@/components/FirDownload";
// import FirAppBase from "@/components/FirAppBase";
// import FirAppInfosBase from "@/components/FirAppInfosBase";
// import FirAppInfostimeline from "@/components/FirAppInfostimeline";
// import FirAppInfosbaseinfo from "@/components/FirAppInfosbaseinfo";
// import FirAppInfossecurity from "@/components/FirAppInfossecurity";
// import FirAppInfosdevices from "@/components/FirAppInfosdevices";
// import FirAppInfoscombo from "@/components/FirAppInfoscombo";
// import FirUserProfileBase from "@/components/FirUserProfileBase";
// import FirUserProfileInfo from "@/components/FirUserProfileInfo";
// import FirUserProfileChangePwd from "@/components/FirUserProfileChangePwd";
// import FirUserProfileStorage from "@/components/FirUserProfileStorage";
//
// import FirSuperSignBase from "@/components/FirSuperSignBase";
const router = new VueRouter({ const router = new VueRouter({
mode: 'history', mode: 'history',
routes: [ routes: [
@ -175,6 +156,18 @@ const router = new VueRouter({
} }
] ]
}, },
{
path: '/orders',
component: () => import("@/components/FirAppBase"),
children: [
{
path: '',
name: 'FirUserOrders',
component: () => import("@/components/FirUserOrders"),
}
]
},
{ {
path: '/register', path: '/register',
name: 'FirRegist', name: 'FirRegist',

@ -14,3 +14,5 @@ admin.site.register(AppIOSDeveloperInfo)
admin.site.register(APPSuperSignUsedInfo) admin.site.register(APPSuperSignUsedInfo)
admin.site.register(APPToDeveloper) admin.site.register(APPToDeveloper)
admin.site.register(UDIDsyncDeveloper) admin.site.register(UDIDsyncDeveloper)
admin.site.register(Price)
admin.site.register(Order)

@ -344,3 +344,53 @@ class DeveloperDevicesID(models.Model):
def __str__(self): def __str__(self):
return "%s-%s-%s-%s" % (self.id, self.app_id, self.developerid, self.udid) return "%s-%s-%s-%s" % (self.id, self.app_id, self.developerid, self.udid)
######################################## 订单表 ########################################
class Order(models.Model):
"""订单"""
payment_type_choices = ((0, '微信'), (1, '支付宝'), (2, '优惠码'), (4, '银联'))
payment_type = models.SmallIntegerField(choices=payment_type_choices)
payment_number = models.CharField(max_length=128, verbose_name="支付第3方订单号", null=True, blank=True)
order_number = models.CharField(max_length=128, verbose_name="订单号", unique=True) # 考虑到订单合并支付的问题
account = models.ForeignKey("UserInfo", on_delete=models.CASCADE)
actual_amount = models.BigIntegerField(verbose_name="实付金额,单位分")
actual_download_times = models.BigIntegerField(verbose_name="实际购买的数量", default=0)
actual_download_gift_times = models.BigIntegerField(verbose_name="实际赠送的数量", default=0)
status_choices = ((0, '交易成功'), (1, '待支付'), (2, '退费申请中'), (3, '已退费'), (4, '主动取消'), (5, '超时取消'))
status = models.SmallIntegerField(choices=status_choices, verbose_name="状态")
order_type_choices = ((0, '用户下单'), (1, '后台充值'),)
order_type = models.SmallIntegerField(choices=order_type_choices, default=0, verbose_name="订单类型")
pay_time = models.DateTimeField(blank=True, null=True, verbose_name="付款时间")
cancel_time = models.DateTimeField(blank=True, null=True, verbose_name="订单取消时间")
created_time = models.DateTimeField(verbose_name="订单创建时间", auto_now_add=True)
description = models.TextField('备注', blank=True, null=True, default='')
def __str__(self):
return "%s-%s-%s" % (self.account, self.order_number, self.actual_amount / 100)
class Price(models.Model):
name = models.CharField(max_length=128, unique=True, verbose_name="下载包唯一名称")
title = models.CharField(max_length=128, verbose_name="下载包名称")
description = models.CharField(max_length=128, verbose_name="下载包描述")
price = models.BigIntegerField(null=False, verbose_name="下载包价格,单位分")
package_size = models.BigIntegerField(null=False, verbose_name="下载包次数")
download_count_gift = models.IntegerField(default=0, null=False, verbose_name="赠送下载次数")
is_enable = models.BooleanField(default=True, verbose_name="是否启用该价格")
updated_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
class Meta:
verbose_name = '价格列表'
verbose_name_plural = "价格列表"
unique_together = ('price', 'package_size')
def save(self, *args, **kwargs):
if Price.objects.filter(is_enable=True).count() > 3: # 最多3个启用的价格表
raise
super(Price, self).save(*args, **kwargs)
def __str__(self):
return "%s-%s-%s-%s" % (self.name, self.price, self.package_size, self.download_count_gift)

@ -23,7 +23,7 @@ from api.views.download import ShortDownloadView
from api.views.uploads import AppAnalyseView, UploadView from api.views.uploads import AppAnalyseView, UploadView
from api.views.storage import StorageView from api.views.storage import StorageView
from api.views.receiveudids import IosUDIDView from api.views.receiveudids import IosUDIDView
from api.views.order import PriceView, OrderView
from api.views.supersign import DeveloperView, SuperSignUsedView, AppUDIDUsedView from api.views.supersign import DeveloperView, SuperSignUsedView, AppUDIDUsedView
# router=DefaultRouter() # router=DefaultRouter()
@ -49,5 +49,7 @@ urlpatterns = [
re_path("^supersign/developer$", DeveloperView.as_view()), re_path("^supersign/developer$", DeveloperView.as_view()),
re_path("^supersign/devices$", SuperSignUsedView.as_view()), re_path("^supersign/devices$", SuperSignUsedView.as_view()),
re_path("^supersign/udid$", AppUDIDUsedView.as_view()), re_path("^supersign/udid$", AppUDIDUsedView.as_view()),
re_path("^package_prices$", PriceView.as_view()),
re_path("^orders$", OrderView.as_view()),
] ]

@ -320,3 +320,15 @@ class DeviceUDIDSerializer(serializers.ModelSerializer):
def get_bundle_name(self, obj): def get_bundle_name(self, obj):
return obj.app_id.name return obj.app_id.name
class PriceSerializer(serializers.ModelSerializer):
class Meta:
model = models.Price
exclude = ["id"]
class OrdersSerializer(serializers.ModelSerializer):
class Meta:
model = models.Order
exclude = ["id"]

@ -350,5 +350,18 @@ def consume_user_download_times(user_id, app_id, amount=1):
return True return True
def add_user_download_times(user_id, download_times=0):
with cache.lock("%s_%s" % ('consume_user_download_times', user_id)):
try:
UserInfo.objects.filter(pk=user_id).update(download_times=F('download_times') + download_times)
enable_user_download_times_flag(user_id)
for app_obj in Apps.objects.filter(pk=user_id):
del_cache_response_by_short(app_obj.app_id)
return True
except Exception as e:
logger.error("%s download_times less then 0. Exception:%s" % (user_id, e))
return False
def check_user_has_all_download_times(user_id): def check_user_has_all_download_times(user_id):
return get_user_free_download_times(user_id) > 0 or check_user_can_download(user_id) return get_user_free_download_times(user_id) > 0 or check_user_can_download(user_id)

@ -3,7 +3,7 @@
# project: 5月 # project: 5月
# author: liuyu # author: liuyu
# date: 2020/5/7 # date: 2020/5/7
import os, re, json, requests import os, re, json, requests, datetime, random
from fir_ser.settings import SUPER_SIGN_ROOT, SERVER_DOMAIN, CAPTCHA_LENGTH, MEDIA_ROOT from fir_ser.settings import SUPER_SIGN_ROOT, SERVER_DOMAIN, CAPTCHA_LENGTH, MEDIA_ROOT
from api.models import APPSuperSignUsedInfo, APPToDeveloper, \ from api.models import APPSuperSignUsedInfo, APPToDeveloper, \
UDIDsyncDeveloper, UserInfo, AppReleaseInfo, AppScreenShot UDIDsyncDeveloper, UserInfo, AppReleaseInfo, AppScreenShot
@ -335,3 +335,11 @@ def clean_storage_data(user_obj, storage_obj=None):
for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all():
storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type) storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type)
return True return True
def get_order_num(order_type=1):
now = datetime.datetime.now()
date_str = "{0}{1}{2}{3}{4}{5}{6}".format(order_type, now.year, now.month, now.day, now.hour, now.minute,
now.second)
return date_str + str(random.randint(1000, 9999)) + str(random.randint(1000, 9999)) + str(
random.randint(1000, 9999))

@ -0,0 +1,135 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# project: 3月
# author: NinEveN
# date: 2021/3/29
from rest_framework.views import APIView
from api.utils.response import BaseResponse
from api.utils.auth import ExpiringTokenAuthentication
from rest_framework.response import Response
from api.models import UserInfo, Price, Order
from api.utils.serializer import PriceSerializer, OrdersSerializer
from rest_framework.pagination import PageNumberPagination
from api.utils.utils import get_order_num
from api.utils.storage.caches import add_user_download_times
import logging
from django.utils import timezone
logger = logging.getLogger(__name__)
class PageNumber(PageNumberPagination):
page_size = 10 # 每页显示多少条
page_size_query_param = 'size' # URL中每页显示条数的参数
page_query_param = 'page' # URL中页码的参数
max_page_size = None # 最大页码数限制
class OrderView(APIView):
authentication_classes = [ExpiringTokenAuthentication, ]
def get(self, request):
res = BaseResponse()
order_id = request.query_params.get("order_id", None)
order_obj_lists = Order.objects.filter(account=request.user)
if order_id:
order_obj_lists = order_obj_lists.filter(order_number=order_id)
page_obj = PageNumber()
order_info_serializer = page_obj.paginate_queryset(queryset=order_obj_lists.order_by("-created_time"),
request=request,
view=self)
order_info = OrdersSerializer(order_info_serializer, many=True, )
res.data = order_info.data
res.count = order_obj_lists.count()
res.payment_type_choices = []
choices_list = list(Order.payment_type_choices)
for auth_t in choices_list:
res.payment_type_choices.append({'id': auth_t[0], 'name': auth_t[1]})
res.status_choices = []
choices_list = list(Order.status_choices)
for auth_t in choices_list:
res.status_choices.append({'id': auth_t[0], 'name': auth_t[1]})
res.order_type_choices = []
choices_list = list(Order.order_type_choices)
for auth_t in choices_list:
res.order_type_choices.append({'id': auth_t[0], 'name': auth_t[1]})
return Response(res.dict)
def post(self, request):
res = BaseResponse()
price_id = request.data.get("price_id", None)
if price_id:
price_obj = Price.objects.filter(name=price_id).first()
if price_obj:
try:
Order.objects.create(payment_type=0, order_number=get_order_num(),
account=request.user, status=1, order_type=0, actual_amount=price_obj.price,
actual_download_times=price_obj.package_size,
actual_download_gift_times=price_obj.download_count_gift)
return Response(res.dict)
except Exception as e:
logger.error("%s 订单 %s 保存失败 Exception:%s" % (request.user, price_id, e))
res.code = 1003
res.msg = "订单保存失败"
else:
logger.error("%s 价格 %s 获取失败" % (request.user, price_id))
res.code = 1002
res.msg = "价格获取失败"
else:
res.code = 1001
res.msg = "错误的价格"
return Response(res.dict)
def put(self, request):
res = BaseResponse()
order_number = request.data.get("order_number", None)
if order_number:
order_obj = Order.objects.filter(account=request.user, order_number=order_number, status=1).first()
if order_obj:
download_times = order_obj.actual_download_times + order_obj.actual_download_gift_times
try:
order_obj.status = 0
now = timezone.now()
if not timezone.is_naive(now):
now = timezone.make_naive(now, timezone.utc)
order_obj.pay_time = now
n_download_times = UserInfo.objects.filter(pk=request.user.id).values('download_times').first()
order_obj.description = "充值成功,充值下载次数 %s ,现总共可用次数 %s" % (
download_times, n_download_times.get("download_times", 0))
order_obj.save()
add_user_download_times(request.user.id, download_times)
except Exception as e:
logger.error("%s 订单 %s 更新失败 Exception:%s" % (request.user, order_number, e))
res.code = 1003
return Response(res.dict)
else:
logger.error("%s 订单 %s 获取失败" % (request.user, order_number))
res.code = 1003
res.msg = "订单获取失败,或订单已经支付"
else:
res.code = 1001
res.msg = "订单有误"
return Response(res.dict)
class PriceView(APIView):
authentication_classes = [ExpiringTokenAuthentication, ]
def get(self, request):
res = BaseResponse()
price_obj_lists = Price.objects.filter(is_enable=True).all().order_by("updated_time").order_by("price")
res.data = PriceSerializer(price_obj_lists, many=True).data
return Response(res.dict)
def delete(self, request, price_id):
res = BaseResponse()
return Response(res.dict)
def put(self, request, price_id):
res = BaseResponse()
return Response(res.dict)

@ -19,7 +19,7 @@ import logging
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
class AppsPageNumber(PageNumberPagination): class PageNumber(PageNumberPagination):
page_size = 10 # 每页显示多少条 page_size = 10 # 每页显示多少条
page_size_query_param = 'size' # URL中每页显示条数的参数 page_size_query_param = 'size' # URL中每页显示条数的参数
page_query_param = 'page' # URL中页码的参数 page_query_param = 'page' # URL中页码的参数
@ -42,7 +42,7 @@ class DeveloperView(APIView):
developer_obj2 = developer_obj.filter(issuer_id=appid) developer_obj2 = developer_obj.filter(issuer_id=appid)
developer_obj = developer_obj1 | developer_obj2 developer_obj = developer_obj1 | developer_obj2
page_obj = AppsPageNumber() page_obj = PageNumber()
app_page_serializer = page_obj.paginate_queryset(queryset=developer_obj.order_by("-updated_time"), app_page_serializer = page_obj.paginate_queryset(queryset=developer_obj.order_by("-updated_time"),
request=request, request=request,
view=self) view=self)
@ -238,7 +238,7 @@ class SuperSignUsedView(APIView):
if bundleid: if bundleid:
SuperSignUsed_obj = SuperSignUsed_obj.filter(app_id__bundle_id=bundleid) SuperSignUsed_obj = SuperSignUsed_obj.filter(app_id__bundle_id=bundleid)
page_obj = AppsPageNumber() page_obj = PageNumber()
app_page_serializer = page_obj.paginate_queryset(queryset=SuperSignUsed_obj.order_by("-created_time"), app_page_serializer = page_obj.paginate_queryset(queryset=SuperSignUsed_obj.order_by("-created_time"),
request=request, request=request,
view=self) view=self)
@ -263,7 +263,7 @@ class AppUDIDUsedView(APIView):
if bundleid: if bundleid:
AppUDID_obj = AppUDID_obj.filter(app_id__bundle_id=bundleid) AppUDID_obj = AppUDID_obj.filter(app_id__bundle_id=bundleid)
page_obj = AppsPageNumber() page_obj = PageNumber()
app_page_serializer = page_obj.paginate_queryset(queryset=AppUDID_obj.order_by("-created_time"), app_page_serializer = page_obj.paginate_queryset(queryset=AppUDID_obj.order_by("-created_time"),
request=request, request=request,
view=self) view=self)

Loading…
Cancel
Save