def is_auth(*args, **kwargs): request = args[0] username = request.user.username if user_admin(str(username)) != True: print('您不是管理员哦!') return error_(request, 404) return func(*args, **kwargs)
def OrderContract(request, id): ''' 生成合同页View,打印合同等 :param request: :return: ''' try: con = Contracts.objects.get(id=id) so = Suborderlist.objects.get(key=con.key_order) gso = Goodslist.objects.filter(key=so) except: if request.user.is_staff: con = Contracts.objects.get(id=id) so = Suborderlist.objects.get(key=con.key_order) gso = Goodslist.objects.filter(key=so) content = { 'Contracts': con, 'gso': gso } return render(request, 'defaule/home/downloadcontract1.html', content) return error_(request, code=404, title='合同未申请', content='您的合同未申请或者合同不存在') content = { 'Contracts': con, 'gso': gso } return render(request, 'defaule/home/downloadcontract1.html', content) pass
def navaid(request, str_navaid): try: nav = models.Navaid.objects.get(id=str_navaid) image = models.NavaidImages.objects.filter(key=nav) navmd = [] for i in models.NavaidMiddle.objects.filter(key=nav): nm = [] for k in models.NavaidMiddleWareApp.objects.filter(key=i): waress = [] ks = models.WareAppPrefix.objects.filter( Q(classifytheres__contains=k.navaid_Keyword) | Q(classifytwos__contains=k.navaid_Keyword) ) for app in ks: if app.wareApp_key.release == True: print('OK --- ', app.wareApp_key.release) waress.append({ 'name': app.wareApp_key.name, 'money': app.wareApp_key.money, 'characteristic': app.wareApp_key.characteristic, 'commodity_description': app.wareApp_key.commodity_description, 'images': models.images.objects.filter(key=app.wareApp_key)[:1].get(), 'unix': app.wareApp_key.unix, 'time_add': app.wareApp_key.time_add, 'time_now': app.wareApp_key.time_now }) print('END --- ', app.wareApp_key.release) nm.append({ 'id': k.id, 'navaid_name': k.navaid_name, 'navaid_Keyword': k.navaid_Keyword, 'navaid_number': k.navaid_number, 'wareapp': waress }) navmd.append({ 'navaid_name': i.navaid_name, 'navaid_urls': i.navaid_urls, 'navaid_images': i.navaid_images, 'Keyword': nm }) content = { 'nav': nav, 'images': image, 'navmd': navmd } return render(request, 'defaule/navaid/index.html', content) except: return error_(request) pass
def auth_retrieve(request): if request.method == 'GET': auto = request.GET.get('auto') email = request.GET.get('email') if auto and email: all_records = models.UserProfix.objects.filter( email=email, send_type='retrieve', code=auto, code_default=True) if all_records: datetime = nu(all_records[0].addtime) if datetime < 300 and datetime > 0: logger.i(datetime) content = { 'auto': auto, 'email': email, 'username': all_records[0].username } return render(request, 'defaule/auth/retrieve_edit.html', content) return error_(request, 404)
def details(request, tid): ''' 商品详情页面 :param tid: :return: ''' Dic = models.WareParProfix.Dis_CHOICES defaule = False # 是否是国采登录用户 defaule_money = 0 # 国采用户打折 try: U = models.User.objects.get(username=request.user.username) if U.usercode: defaule = True defaule_money = 0 pass except: defaule = False pass try: wareapp = models.WareApp.objects.filter(id=tid)[:1].get() except: return error_(request, code=404, error={}) pass image = models.images.objects.filter(key=wareapp.id) parameter = models.parameter.objects.filter(key=wareapp) try: classify = models.WareAppPrefix.objects.get(wareApp_key=wareapp) except: classify = None if classify: there = classify else: there = None pare = [] Wpf = None if there: there = there.classifythere_key try: Wpf = models.WareParProfix.objects.get(key=there) except: Wpf = None pass ''' 商品规格 ''' if Wpf: for i in Wpf.filter_name: ks = parameter.values(i[0]) if ks: ks = ks[0] ks = ks[i[0]] else: ks = '无' logger.i('商品规格', i[0]) pare.append({'v': Dic[i[0]], 'k': ks}) else: Wpf = None logger.i('APP', Wpf) pass else: there = None pass money = 0 # 租赁Models 配置 Lease = [] for q in models.Lease.objects.filter(ware_key=wareapp, select=0): Lease.append({ 'id': q.id, 'name': q.name, 'money': q.money, 'defaule': q.defaule, }) pass try: Lease_Duration_ = models.Duration.objects.get(defaule=True, ware_key=wareapp) except: Lease_Duration_ = None # 购买Models 配置 purchase = [] for q in models.Lease.objects.filter(ware_key=wareapp, select=1): if q.defaule: money = q.money pass purchase.append({ 'id': q.id, 'name': q.name, 'money': q.money, 'defaule': q.defaule }) pass try: purchase_Lease = models.Lease.objects.get(defaule=True, ware_key=wareapp, select=1) except: purchase_Lease = None pass dismoney = 0 if classify and defaule: theress = classify.classifythere_key logger.i('theress多功能一体机 ', theress.id) try: discon = Discount.objects.get(classif_there=theress) except: discon = None pass if float(money) <= 100000: # a1 if discon: dismoney = discon.a1 else: dismoney = 0 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('float(money) <= 100000', defaule_money) pass elif 100000 < float(money) and float(money) <= 300000: # a2 if discon: dismoney = discon.a2 else: dismoney = 0 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('100000 < float(money) and float(money) <= 300000', defaule_money) pass elif 300000 < float(money) and float(money) <= 600000: # a3 if discon: dismoney = discon.a3 else: dismoney = 0 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('300000 < float(money) and float(money) <= 600000', defaule_money) pass elif 600000 < float(money) and float(money) <= 1000000: # a4 if discon: dismoney = discon.a4 else: dismoney = 0 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('600000 < float(money) and float(money) <= 1000000', defaule_money) pass thereid = classify.classifythere_key.id context = { 'thereid': thereid, 'id': tid, 'defaule': defaule, 'dismoney': dismoney, 'defaule_money': round(defaule_money, 2), 'classify': classify, 'wareapp': wareapp, 'money': money, 'param': pare, "Dic": Dic, "Wpf": Wpf, 'image': image, 'lease': Lease, 'purchase': purchase, 'duration': models.Duration.objects.filter(ware_key=wareapp), 'Lease_Duration_': Lease_Duration_, 'purchase_Lease': purchase_Lease } return render(request, 'defaule/app/details.html', context) pass
def Settlement(request): ''' 下单结算页 [填写并核对订单信息] 只适合单种商品下单,多种商品下单无法计算价格 :param request: :return: ''' if request.method == 'GET': wareid = request.GET.get('id') purchase = request.GET.get('purchase') duration = request.GET.get('duration') number = request.GET.get('number') print('purchase', purchase) username = request.user.username users = models.User.objects.get(username=username) add = Address.objects.filter(key=users, defaule=True) if not add: add = Address.objects.filter(key=users) pass if add: add = add[0] ware = models.WareApp.objects.filter(id=wareid) lease_or = models.Lease.objects.get(ware_key=ware[0], id=purchase, select=1) # select 1 购买/select 0 租赁 money = float(lease_or.money) # '总金额' logger.i('总金额', money) defaule = False # 是否是国采登录用户 defaule_money = 0 # 国采用户打折 try: U = models.User.objects.get(username=request.user.username) if U.usercode: defaule = True defaule_money = 0 pass except: defaule = False pass try: classify = models.WareAppPrefix.objects.get(wareApp_key=ware) except: classify = None dismoney = 0 number_money = float(money) * float(number) if classify and defaule: logger.i('优惠率', classify, defaule) theress = classify.classifythere_key discon = Discount.objects.get(classif_there=theress) if int(number_money) <= 100000: # a1 dismoney = discon.a1 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('int(number_money) <= 100000', defaule_money, money) pass elif 100000 < int(number_money) and int(number_money) <= 300000: # a2 dismoney = discon.a2 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('100000 < int(number_money) and int(number_money) <= 300000', defaule_money) pass elif 300000 < int(number_money) and int(number_money) <= 600000: # a3 dismoney = discon.a3 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('300000 < int(number_money) and int(number_money) <= 600000', defaule_money) pass elif 600000 < int(number_money) and int(number_money) < 1000000: # a4 dismoney = discon.a4 defaule_money = (100 - float(dismoney)) / 100 * float(money) logger.i('600000 < int(number_money) and int(number_money) <= 1000000', defaule_money) elif float(number_money) >= 1000000: return error_(request, code=403, title='订单错误', page='Order error', content='单笔订单不可大于等于100万人民币') pass total = float(number) * float(money) total_defaule_money = float(number) * float(defaule_money) money = Decimal(money).quantize(Decimal('0.00')) total = Decimal(total).quantize(Decimal('0.00')) total_defaule_money = Decimal(total_defaule_money).quantize(Decimal('0.00')) defaule_money = Decimal(defaule_money).quantize(Decimal('0.00')) logger.i('单价', money) logger.i('单价优惠', defaule_money) logger.i('总优惠', total_defaule_money) try: invs = Invoices.objects.get(key=users) logger.i(invs.stype) inv = { 'stype': invs.stype, 'content': invs.content, 'taxpayer': invs.taxpayer, 'phone': invs.phone, 'email': invs.email, 'head': invs.head, 'unitName': invs.unitName, 'registeredAddress': invs.registeredAddress, 'registeredTelephone': invs.registeredTelephone, 'accountOpening': invs.accountOpening, 'account': invs.account } except: inv = {} pass moneytable = [] for i in Discount.objects.filter(defaule=True): moneytable.append({ 'id': i.id, 'name': i.classif_there.name, 'a1': i.a1.to_integral, 'a2': i.a2.to_integral, 'a3': i.a3.to_integral, 'a4': i.a4.to_integral }) content = { 'moneytable': moneytable, 'inv': inv, 'address': add, 'number': number, 'ware': ware, 'total': total, 'dismoney': dismoney, 'defaule': defaule, 'money': money, 'defaule_money': defaule_money, 'total_defaule_money': total_defaule_money, 'wareid': wareid, 'select': 1, 'purchase': purchase, 'duration': duration, } return render(request, 'defaule/home/settlement.html', content) if request.method == 'POST': username = request.user.username wareid = request.POST.get('id') purchase = request.POST.get('purchase') duration = request.POST.get('duration') number = request.POST.get('number') invoices = request.POST.get('invoices') ''' 创建订单 :param request: :return: ''' address = request.POST.get('address') remark = request.POST.get('remark') # 订单备注 paymethod = request.POST.get('paymethod') # '支付方式' logger.i('wareid', wareid) ware = models.WareApp.objects.get(id=wareid) logger.i('WareApp', ware) user = models.User.objects.get(username=username) lease_or = models.Lease.objects.get(ware_key=ware, id=purchase, select=1) # select 1 购买/select 0 租赁 money = float(lease_or.money) # '总金额' duration_or = None # if select == '0': # lease_or = models.Lease.objects.get(ware_key=ware, id=purchase, select=select) # select 1 购买/select 0 租赁 # duration_or = models.Duration.objects.get(ware_key=ware, id=duration) # 租赁配置 - 分类信息[租赁时间] # money = float(lease_or.money) + float(duration_or.money) # '总金额' # elif select == '1': # lease_or = models.Lease.objects.get(ware_key=ware, id=purchase, select=select) # select 1 购买/select 0 租赁 # money = float(lease_or.money) # '总金额' # duration_or = None # else: # lease_or, duration_or = None, None # money = -1 # pass # images = models.images.objects.filter(key=ware)[:1].get().image add = Address.objects.filter(id=address, key=user) if add: province = add[0].province city = add[0].city area = add[0].area deliveryaddress = '{}'.format(add[0].consigneeAddress) linkman = add[0].consigneeName # userinfo.name # 购买人姓名 linkmobile = add[0].consigneeMobile # userinfo.phone # 购买人联系方式 else: return redirect(reverse('home:address')) '''''' defaule = False # 是否是国采登录用户 defaule_money = 0 # 国采用户打折 orderid = _order_num(package_id=ware.id, user_id=user.id) # '创建订单号' suborderid = orderid # 子订单号 try: U = models.User.objects.get(username=request.user.username) if U.usercode: defaule = True defaule_money = 0 pass except: defaule = False pass try: classify = models.WareAppPrefix.objects.get(wareApp_key=ware) except: classify = None dismoney = 0 number_money = float(money) * float(number) if classify and defaule: theress = classify.classifythere_key discon = Discount.objects.get(classif_there=theress) if float(number_money) <= 100000: # a1 dismoney = discon.a1 defaule_money = (100 - float(discon.a1)) / 100 * float(money) logger.i('float(number_money) <= 100000', defaule_money) pass elif 100000 < float(number_money) and float(number_money) <= 300000: # a2 dismoney = discon.a2 defaule_money = (100 - float(discon.a2)) / 100 * float(money) logger.i('100000 < float(number_money) and float(number_money) <= 300000', defaule_money) pass elif 300000 < float(number_money) and float(number_money) <= 600000: # a3 dismoney = discon.a3 defaule_money = (100 - float(discon.a3)) / 100 * float(money) logger.i('300000 < float(number_money) and float(number_money) <= 600000', defaule_money) pass elif 600000 < float(number_money) and float(number_money) <= 1000000: # a4 dismoney = discon.a4 defaule_money = (100 - float(discon.a4)) / 100 * float(money) logger.i('600000 < float(number_money) and float(number_money) < 1000000', defaule_money) elif float(number_money) >= 1000000: return error_(request, code=403, title='订单错误', page='Order error', content='单笔订单不可大于等于100万人民币') pass total_defaule_money = float(number) * float(defaule_money) '''''' total = float(total_defaule_money) # 总订单价钱 Subtotal = total # 子订单总价 ############# price = defaule_money # 商品单价 originalprice = money # 订单原价 '''''' logger.i('订单原价: ', money) logger.i('优惠率', dismoney) logger.i('商品单价优惠: ', defaule_money) logger.i('总订单优惠: ', total_defaule_money) else: total = float(number) * float(money) # 总订单价钱 '''''' Subtotal = total # 子订单总价 ############# price = float(money) # 商品单价 originalprice = float(money) # 订单原价 '''''' money = Decimal(money).quantize(Decimal('0.00')) total = Decimal(total).quantize(Decimal('0.00')) Subtotal = Decimal(Subtotal).quantize(Decimal('0.00')) price = Decimal(price).quantize(Decimal('0.00')) originalprice = Decimal(originalprice).quantize(Decimal('0.00')) logger.i('订单原价: ', money) logger.i('商品单价: ', money) logger.i('总订单价: ', total) spu = ware.name # '细化到商品' goodsclassguid = goodsclassname = goodsbrandname = sku = model = '' if defaule: try: guid = Gusid.objects.get(key=classify.classifythere_key) except: return error_(request, content='商品目录ID不完整,或未分类', code=403) try: per = parameter.objects.get(key=ware) sku = '{} {} {}'.format(per.model, per.productType, per.colorType) # '细化到规格、型号' model = '{}'.format(per.model) # '商品型号、规格' goodsbrandname = per.brands # '品牌名称' goodsclassguid = guid.guid # '商品目录ID 枚举值对照表' goodsclassname = guid.name # '商品类别名' except: return error_(request, content='商品参数不完整,最少具备的参数: 产品型号, 产品类型, 颜色类型') usercode = user.usercode url = '/app/details/{}/'.format(wareid) logger.i('商品目录ID', goodsclassguid) logger.i('商品类别名', goodsclassname) logger.i('品牌名称', goodsbrandname) try: inv = Invoices.objects.get(key=user) except: inv = None if usercode: o = Order( name='{}({})'.format(ware.name, lease_or.name), orderid=orderid, paymethod=paymethod, total=total, money=total, number=number, province=province, city=city, area=area, invoice=invoices, linkman=linkman, linkmobile=linkmobile, deliveryaddress=deliveryaddress, remark=remark, usercode=usercode, createtime=datetimenow(), images=ware.image, url=url, key_inv=inv, key=user ) else: o = Order( name='{}({})'.format(ware.name, lease_or.name), orderid=orderid, paymethod=paymethod, total=total, number=number, province=province, city=city, area=area, invoice=invoices, linkman=linkman, linkmobile=linkmobile, deliveryaddress=deliveryaddress, remark=remark, createtime=datetimenow(), images=ware.image, url=url, key_inv=inv, key=user ) o.save() s = Suborderlist( suborderid=suborderid, url=url, total=Subtotal, key=o ) s.save() Goodslist( goodsname='{}({})'.format(ware.name, lease_or.name), goodsid=ware.id, spu=spu, sku=sku, model=model, goodsclassguid=goodsclassguid, goodsclassname=goodsclassname, goodsbrandname=goodsbrandname, qty=number, total=total, price=price, originalprice=originalprice, imgurl=ware.image, goodsurl=url, key=s ).save() Logistics( info='您提交了订单,请等待卖家系统确认', time=datetimenow(), username='******', key=o ).save() o.lease_or = lease_or if paymethod == '1' or paymethod == '2' or paymethod == '3' or paymethod == '4' or paymethod == '9': o.state = 2 pass o.save() if usercode: auto = AutoRsaGraph(usercode=usercode, orderid=orderid) order_create = auto.order_create() order_logistics = auto.order_logistics() logger.i('央采 创建订单', order_create) logger.i('央采 物流推送接口', order_logistics) else: logger.i('没有usercode') pass return HttpResponseRedirect('/home/success/?orderId={}'.format(orderid)) pass pass
def GET(request, *args, **kwargs): if request.method != 'GET': return error_(request, content='请求错误') return func(request, *args, **kwargs)