123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- # -*- encoding: utf-8 -*-
- """
- @File : AgentCustomerController.py
- @Time : 2024/3/7 16:56
- @Author : stephen
- @Email : zhangdongming@asj6.wecom.work
- @Software: PyCharm
- """
- from django.http import QueryDict
- from django.views import View
- from datetime import datetime
- from AgentModel.models import AgentCustomerInfo, AgentCustomerCard, AgentCustomerPackage, AgentCloudServicePackage
- from Model.models import UnicomCombo, Store_Meal
- from Object.ResponseObject import ResponseObject
- from Object.TokenObject import TokenObject
- class AgentCustomerView(View):
- def get(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.GET, request, operation)
- def post(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- return self.validation(request.POST, request, operation)
- def delete(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- delete = QueryDict(request.body)
- if not delete:
- delete = request.GET
- return self.validation(delete, request, operation)
- def put(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation')
- put = QueryDict(request.body)
- return self.validation(put, request, operation)
- def validation(self, request_dict, request, operation):
- AgentCustomerInfo.objects.filter()
- language = request_dict.get('language', 'en')
- response = ResponseObject(language, 'pc')
- if operation == 'getUnicomAndIcloud':
- return self.get_unicom_and_icloud(response)
- else:
- return response.json(444, 'operation')
- def get_unicom_and_icloud(self, response):
- try:
- # 云存储套餐查询,只包括is_show=1的记录
- store_meal_qs = Store_Meal.objects.filter(is_show=1).values(
- 'id',
- 'bucket__bucket',
- 'day',
- 'expire',
- 'commodity_type',
- 'commodity_code',
- 'is_discounts',
- 'discount_price',
- 'virtual_price',
- 'price',
- 'currency',
- 'symbol',
- 'is_show',
- 'is_ai',
- 'pixel_level',
- 'add_time',
- 'update_time'
- )
- store_meal_list = [{
- 'storeMealID': store_meal['id'],
- 'bucket': store_meal['bucket__bucket'],
- 'day': store_meal['day'],
- 'expire': store_meal['expire'],
- 'commodity_type': store_meal['commodity_type'],
- 'pay_type': [pay_type['id'] for pay_type in
- Store_Meal.objects.get(id=store_meal['id']).pay_type.values('id')],
- 'commodity_code': store_meal['commodity_code'],
- 'is_discounts': store_meal['is_discounts'],
- 'discount_price': store_meal['discount_price'],
- 'virtual_price': store_meal['virtual_price'],
- 'price': store_meal['price'],
- 'currency': store_meal['currency'],
- 'symbol': store_meal['symbol'],
- 'is_show': store_meal['is_show'],
- 'is_ai': store_meal['is_ai'],
- 'pixel_level': store_meal['pixel_level'],
- 'addTime': store_meal['add_time'].strftime("%Y-%m-%d %H:%M:%S"),
- 'updTime': store_meal['update_time'].strftime("%Y-%m-%d %H:%M:%S"),
- } for store_meal in store_meal_qs]
- # 联通套餐查询,只包括is_show=1的记录
- combo_qs = UnicomCombo.objects.filter(is_show=1, is_del=False).values(
- 'id', 'status', 'combo_name',
- 'flow_total', 'combo_type',
- 'expiration_days',
- 'expiration_type', 'price', 'is_unlimited',
- 'updated_time', 'created_time',
- 'remark', 'is_show', 'sort', 'virtual_price'
- )
- combo_list = [{
- 'id': item['id'],
- 'status': item['status'],
- 'comboType': item['combo_type'],
- 'comboName': item['combo_name'],
- 'flowTotal': item['flow_total'],
- 'expirationDays': item['expiration_days'],
- 'expirationType': item['expiration_type'],
- 'price': item['price'],
- 'sort': item['sort'],
- 'isUnlimited': item['is_unlimited'],
- 'updatedTime': datetime.utcfromtimestamp(item['updated_time']).strftime("%Y-%m-%d %H:%M:%S"),
- 'createdTime': datetime.utcfromtimestamp(item['created_time']).strftime("%Y-%m-%d %H:%M:%S"),
- 'remark': item['remark'],
- 'isShow': item['is_show'],
- 'payTypes': [pay_type['id'] for pay_type in
- UnicomCombo.objects.get(id=item['id']).pay_type.values('id')],
- 'virtualPrice': item['virtual_price']
- } for item in combo_qs]
- # 合并结果并返回
- return response.json(0, {
- 'storeMealList': store_meal_list,
- 'comboList': combo_list,
- })
- except Exception as e:
- print(e)
- return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|