本文整理汇总了Python中sellcard.common.Method.updateCard方法的典型用法代码示例。如果您正苦于以下问题:Python Method.updateCard方法的具体用法?Python Method.updateCard怎么用?Python Method.updateCard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sellcard.common.Method
的用法示例。
在下文中一共展示了Method.updateCard方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
def update(request):
operator_id = request.session.get('s_uid', '')
depart = request.session.get('s_depart','')
res = {}
# 出卡列表
cardOutStr = request.POST.get('cardOutStr', '')
cardOutList = json.loads(cardOutStr)
# 出卡合计
cardOutTotalNum = request.POST.get('cardOutTotalNum', 0)
cardOutTotalVal = request.POST.get('cardOutTotalVal', 0.00)
order_sn = request.POST.get('order_sn', '')
paymoney = request.POST.get('paymoney', '')
try:
with transaction.atomic():
#更新订单信息
OrderUpCard.objects.filter(order_sn=order_sn)\
.update(fill_amount=cardOutTotalNum,fill_price=cardOutTotalVal,diff_price=paymoney,state=0,operator_id=operator_id,depart=depart,modified_time=datetime.datetime.today())
# 订单明细:入卡,待补的卡即待作废的卡
cardIdOutList = []
for card in cardOutList:
info = OrderUpCardInfo()
info.order_sn = order_sn
info.card_no = card["cardId"].strip()
info.card_value = card["cardVal"]
info.card_balance = card["balance"]
info.card_attr =2
info.created_time = datetime.datetime.today()
info.save()
cardIdOutList.append(card['cardId'])
# 激活新卡
cardOutNum = len(cardIdOutList)
resCardOut = CardInventory.objects.filter(card_no__in=cardIdOutList).update(card_status=2,card_action=0)
if resCardOut != cardOutNum:
raise MyError('CardInventory状态更新失败')
# 更新Guest
updateConfList = []
updateConfList.append({'ids': cardIdOutList, 'mode': '1', 'count': cardOutNum})
resGuest = mtu.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res["status"] = 1
res['urlRedirect'] = '/kg/sellcard/fornt/cardfill/query/'
ActionLog.objects.create(action='补卡-领卡',u_name=request.session.get('s_uname'),cards_out=cardOutStr,add_time=datetime.datetime.now())
except Exception as e:
res["status"] = 0
if hasattr(e,'value'):
res['msg'] = e.value
ActionLog.objects.create(action='补卡-领卡',u_name=request.session.get('s_uname'),cards_out=cardOutStr,add_time=datetime.datetime.now(),err_msg=e)
return HttpResponse(json.dumps(res))
示例2: save
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
def save(request):
cardsStr = request.POST.get('cardStr','')
cardList = json.loads(cardsStr)
orderSnStr = request.POST.get('orderSnList','')
orderSnList = json.loads(orderSnStr)
cardnoList = []
for card in cardList:
cardnoList.append(card['cardId'])
now = datetime.datetime.now()
res = {}
try:
# 检测session中Token值,判断用户提交动作是否合法
Token = request.session.get('postToken', default=None)
# 获取用户表单提交的Token值
userToken = request.POST.get('postToken', '')
if userToken != Token:
raise MyError('表单重复提交,刷新页面后,重试!')
with transaction.atomic():
cardsNum = len(cardnoList)
resCard = CardInventory.objects.filter(card_no__in=cardnoList).update(card_status='1',card_action='1')
if resCard != cardsNum:
raise MyError('CardInventory状态更新失败')
resBorrow = OrderBorrowInfo.objects.filter(card_no__in=cardnoList,order_sn__in=orderSnList,is_back=None).update(is_back='1',back_time=now)
if resBorrow != cardsNum:
raise MyError('OrderBorrowInfo更新失败')
for orderSn in orderSnList :
cardList = OrderBorrowInfo.objects.filter(order_sn=orderSn,is_back=None)
if cardList.count()==0:
OrderBorrow.objects.filter(order_sn=orderSn).update(is_paid='3')
#更新Guest
updateConfList = []
updateConfList.append({'ids': cardnoList, 'mode': '9', 'count': cardsNum})
resGuest = mth.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res['status'] = 1
res['urlRedirect'] = '/kg/sellcard/fornt/borrow/back/index/'
ActionLog.objects.create(action='借卡-还卡',u_name=request.session.get('s_uname'),cards_in=cardsStr,add_time=datetime.datetime.now())
del request.session['postToken']
except Exception as e:
res['status'] = 0
if hasattr(e,'value'):
res['msg'] = e.value
ActionLog.objects.create(action='借卡-还卡',u_name=request.session.get('s_uname'),cards_in=cardsStr,add_time=datetime.datetime.now(),err_msg=e)
return HttpResponse(json.dumps(res))
示例3: saveOrder
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
#.........这里部分代码省略.........
if pay['payId'] =='3':
is_pay = '0'
elif pay['payId'] =='4':
is_pay = '0'
orderPay.received_time = pay['received_time']
elif pay['payId'] == '6':
isThird = True
is_pay = '0'
discountRate = payDiscDict[pay['payId']]
discountVal = Ycash = float(pay['payVal']) * float(discountRate)
elif pay['payId'] in ('7','8','10','11'):
isThird = True
discountRate = payDiscDict[pay['payId']]
discountVal = Ycash = float(pay['payVal']) * float(discountRate)
# if pay['payId'] == '9':
# isThird = True
# mth.upChangeCode(hjsList,shopcode)
orderPay.is_pay = is_pay
orderPay.pay_value = pay['payVal']
orderPay.remarks = pay['payRmarks']
oderPaymentList.append(orderPay)
OrderPaymentInfo.objects.bulk_create(oderPaymentList)
# 保存OrderInfo
orderInfoList = []
for card in cardList:
orderInfo = OrderInfo()
orderInfo.order_id = order_sn
orderInfo.card_id = card['cardId'].strip()
orderInfo.card_balance = float(card['cardVal'])
orderInfo.card_action = '0'
orderInfo.card_attr = '1'
orderInfoList.append(orderInfo)
if not isThird:
for Ycard in YcardList:
YorderInfo = OrderInfo()
YorderInfo.order_id = order_sn
YorderInfo.card_id = Ycard['cardId'].strip()
YorderInfo.card_balance = float(Ycard['cardVal'])
YorderInfo.card_action = '0'
YorderInfo.card_attr = '2'
orderInfoList.append(YorderInfo)
OrderInfo.objects.bulk_create(orderInfoList)
order = Orders()
order.buyer_name = buyerName
order.buyer_tel = buyerPhone
order.buyer_company = buyerCompany
order.total_amount = float(totalVal)+float(discountVal)
order.paid_amount = float(totalVal)+float(Ybalance)#实付款合计=售卡合计+优惠补差
order.disc_amount = discountVal#优惠合计
order.diff_price = Ybalance
order.shop_code = shopcode
order.depart = depart
order.operator_id = operator
order.action_type = actionType
order.add_time = datetime.datetime.now()
order.discount_rate = discountRate
order.order_sn = order_sn
order.y_cash = Ycash
order.save()
#获取所有出卡列表
cardListTotal = cardList+YcardList
cardIdList = []
for card in cardListTotal:
cardIdList.append(card['cardId'])
cardsNum = len(cardIdList)
# 更新kggroup内部卡状态
resCard = CardInventory.objects.filter(card_no__in=cardIdList,card_status='1',is_store='0')\
.update(card_status='2',card_action='0')
if resCard != cardsNum:
raise MyError('CardInventory状态更新失败')
#更新折扣授权码校验码状态
if disCode:
resCode = mth.updateDisCode(disCode,shopcode,order_sn)
if resCode == 0:
raise MyError('折扣授权码状态更新失败')
# 更新Guest
updateConfList = []
updateConfList.append({'ids': cardIdList, 'mode': '1', 'count': cardsNum})
resGuest = mth.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res["status"] = 1
res["urlRedirect"] ='/kg/sellcard/fornt/cardsale/orderInfo/?orderSn='+order_sn
ActionLog.objects.create(url=path,u_name=request.session.get('s_uname'),cards_out=json.dumps(cardIdList),add_time=datetime.datetime.now())
del request.session['postToken']
except Exception as e:
if hasattr(e,'value'):
res['msg'] = e.value
res["status"] = 0
ActionLog.objects.create(url=path,u_name=request.session.get('s_uname'),add_time=datetime.datetime.now(),err_msg=e)
return HttpResponse(json.dumps(res))
示例4: save
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
#.........这里部分代码省略.........
if pay['payId'] == '9':
isThird = True
mth.upChangeCode(hjsList, shopCode)
orderPay.pay_value = pay['payVal']
orderPay.remarks = pay['payRmarks']
ChangePaymentList.append(orderPay)
OrderChangeCardPayment.objects.bulk_create(ChangePaymentList)
#3、保存order信息
order = OrderChangeCard()
order.order_sn = order_sn
order.operator_id = operator
order.depart = depart
order.shop_code = shopCode
order.user_name = buyerName
order.user_phone = buyerPhone
order.total_in_amount = totalNumIn
order.total_in_price = totalValIn
order.total_out_amount = totalNumOut
order.total_out_price = totalValOut
order.disc_rate = disRate
order.disc = disc
order.disc_cash = discCash
order.disc_pay = discPay
order.add_time = created_time
order.save()
#4、分别创建orderInfo列表
cardOutInfoList =[]
changeCardInfoList = []
cardInIdList = []
cardCommonIdList=[]
cardIsStoreIdList = []
cardCommonInNum=cardIsStoreInNum = 0
if len(cardCommonList):
infoCommon = createChangInfoList(cardCommonList,order_sn,'1')
changeCardInfoList += infoCommon
cardCommonIdList = [card['cardId'] for card in cardCommonList]
cardInIdList += cardCommonIdList
cardCommonInNum = len(cardCommonIdList)
if len(cardIsStoreList):
infoIsStore = createChangInfoList(cardIsStoreList, order_sn,'1','2')
changeCardInfoList += infoIsStore
cardIsStoreIdList = [card['cardId'] for card in cardIsStoreList]
cardInIdList += cardIsStoreIdList
cardIsStoreInNum = len(cardIsStoreIdList)
if len(cardListOut):
infoOut = createChangInfoList(cardListOut,order_sn,'0')
changeCardInfoList += infoOut
cardOutInfoList += cardListOut
if not isThird and len(discList):
infoDisc = createChangInfoList(cardIsStoreList, discList,'0','1')
changeCardInfoList += infoDisc
cardOutInfoList += discList
#5、保存orderInfo
OrderChangeCardInfo.objects.bulk_create(changeCardInfoList)
#6、更新CardInventory出库卡状态
cardOutIdList = [card['cardId'] for card in cardOutInfoList]
cardsOutNum = len(cardOutIdList)
resCardOut = CardInventory.objects\
.filter(card_status='1',card_no__in=cardOutIdList,card_value=F('card_blance'),is_store='0')\
.update(card_status='2',card_action='0')
if resCardOut != cardsOutNum:
raise MyError('CardInventory状态更新失败')
#7、更新折扣授权码信息
if discCode:
resCode = mth.updateDisCode(discCode,shopCode,order_sn)
if resCode == 0:
raise MyError('折扣授权码状态更新失败')
# 8、更新Guest信息
updateConfList = []
updateConfList.append({'ids':cardIsStoreIdList,'mode':'7','count':cardIsStoreInNum})
updateConfList.append({'ids': cardCommonIdList, 'mode': '9', 'count': cardCommonInNum})
updateConfList.append({'ids':cardOutIdList,'mode':'1','count':cardsOutNum})
resGuest = mth.updateCard(updateConfList)
if resGuest['status']==0:
raise MyError(resGuest['msg'])
res["status"] = 1
ActionLog.objects.create(
action='换卡-单卡', u_name=request.session.get('s_uname'), cards_in=json.dumps(cardInIdList),
cards_out=json.dumps(cardOutIdList), add_time=datetime.datetime.now()
)
del request.session['postToken']
except Exception as e:
res["status"] = 0
if hasattr(e, 'value'):
res['msg'] = e.value
ActionLog.objects.create(
action='换卡-单卡', u_name=request.session.get('s_uname'),
add_time=datetime.datetime.now(), err_msg=e
)
return HttpResponse(json.dumps(res))
示例5: save
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
def save(request):
path = request.path
operator = request.session.get('s_uid', '')
shopcode = request.session.get('s_shopcode', '')
depart = request.session.get('s_depart', '')
actionType = request.POST.get('actionType', '')
# 售卡列表
orderSns = request.POST.getlist('orderSns[]', '')
# 支付方式
payStr = request.POST.get('payStr', '')
payList = json.loads(payStr)
# 合计信息
totalVal = float(request.POST.get('totalVal', 0.00))
# 折扣
discountRate = float(request.POST.get('discount', 0.00)) / 100
disCode = request.POST.get('disCode', '')
discountVal = float(request.POST.get('discountVal', ''))
Ybalance = float(request.POST.get('Ybalance', 0.00))
YcardStr = request.POST.get('YcardStr', '')
YcardList = json.loads(YcardStr)
Ycash = request.POST.get('Ycash', '')
# 顾客信息
vip_person = request.POST.get('buyerName', '')
vip_tel = request.POST.get('buyerPhone', '')
vip_company = request.POST.get('buyerCompany', '')
vip_id = int(request.POST.get('vipId', ''))
order_sn = ''
res = {}
try:
Token = request.session.get('postToken', default=None)
userToken = request.POST.get('postToken', '')
if userToken != Token:
raise MyError('表单重复提交,刷新页面后,重试!')
with transaction.atomic():
order_sn = 'S' + mth.setOrderSn()
# OrderPaymentInfo
oderPaymentList, isThird, discountVal, Ycash = cardMethod.createPaymentList(payList, order_sn, discountVal, Ycash)
OrderPaymentInfo.objects.bulk_create(oderPaymentList)
# 保存OrderInfo
orderInfoList = cardMethod.createOrderInfoList([], order_sn, isThird, YcardList)
OrderInfo.objects.bulk_create(orderInfoList)
#Order
orderData = {
'buyerName': vip_person, 'buyerPhone': vip_tel, 'buyerCompany': vip_company,
'totalVal': totalVal, 'discountVal': discountVal, 'Ybalance': Ybalance,
'shopcode': shopcode, 'depart': depart, 'operator': operator, 'actionType': actionType,
'discountRate': discountRate, 'order_sn': order_sn, 'Ycash': Ycash
}
order = cardMethod.createOrder(orderData)
order.save()
# 获取所有出卡列表
cardIdList = []
for card in YcardList:
cardIdList.append(card['cardId'])
cardsNum = len(cardIdList)
# 更新kggroup内部卡状态
resCard = CardInventory.objects.filter(card_no__in=cardIdList, card_status='1', is_store='0') \
.update(card_status='2', card_action='0')
if resCard != cardsNum:
raise MyError('CardInventory状态更新失败')
# VipOrder
resVip = VipOrder.objects\
.filter(order_sn__in=orderSns,vip_id=vip_id,disc_state='1',order_state='0')\
.update(order_state='1',relate_sn = order_sn)
if resVip != len(orderSns):
raise MyError('VipOrder状态更新失败')
# 更新折扣授权码校验码状态
if disCode:
resCode = mth.updateDisCode(disCode, shopcode, order_sn)
if resCode == 0:
raise MyError('折扣授权码状态更新失败')
# 更新Guest
updateConfList = []
updateConfList.append({'ids': cardIdList, 'mode': '1', 'count': cardsNum})
resGuest = mth.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res["status"] = 1
ActionLog.objects.create(url=path, u_name=request.session.get('s_uname'),
cards_out=json.dumps(cardIdList), add_time=datetime.datetime.now())
del request.session['postToken']
except Exception as e:
if hasattr(e, 'value'):
res['msg'] = e.value
res["status"] = 0
ActionLog.objects.create(url=path, u_name=request.session.get('s_uname'), add_time=datetime.datetime.now(),
err_msg=e)
return HttpResponse(json.dumps(res))
示例6: saveOrder
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
def saveOrder(request):
operator = request.session.get('s_uid','')
shopcode = request.session.get('s_shopcode','')
depart = request.session.get('s_depart','')
#售卡列表
cardStr = request.POST.get('cardsStr','')
cardList = json.loads(cardStr)
#合计信息
outTotalVal = request.POST.get('outTotalVal',0.00)
discVal = request.POST.get('discVal',0.00)
discPay = request.POST.get('discPay',0.00)
remark = request.POST.get('remarks','')
#买卡人信息
buyerName = request.POST.get('buyerName','')
buyerPhone = request.POST.get('buyerPhone','')
buyerCompany = request.POST.get('buyerCompany','')
order_sn = ''
res = {}
try:
# 检测session中Token值,判断用户提交动作是否合法
Token = request.session.get('postToken', default=None)
# 获取用户表单提交的Token值
userToken = request.POST.get('postToken', '')
if userToken != Token:
raise MyError('表单重复提交,刷新页面后,重试!')
with transaction.atomic():
order_sn = 'S'+mtu.setOrderSn()
#order_info表
orderInfoList = []
for card in cardList:
orderInfo = OrderInfo()
orderInfo.order_id = order_sn
orderInfo.card_id = card['cardId'].strip()
orderInfo.card_balance = float(card['cardVal'])
orderInfo.card_action = '0'
orderInfo.card_attr = '2'
orderInfoList.append(orderInfo)
OrderInfo.objects.bulk_create(orderInfoList)
#order_payment_info表
orderPay = OrderPaymentInfo()
orderPay.order_id = order_sn
orderPay.pay_id = 1
orderPay.is_pay = '1'
orderPay.pay_value = float(discPay)
orderPay.save()
#orders表
order = Orders()
order.buyer_name = buyerName
order.buyer_tel = buyerPhone
order.buyer_company = buyerCompany
order.total_amount = float(outTotalVal)
order.paid_amount = float(discPay)
order.disc_amount = float(discVal)
order.diff_price = float(discPay)
order.y_cash =0
order.shop_code = shopcode
order.depart = depart
order.operator_id = operator
order.action_type = '5'
order.add_time = datetime.datetime.now()
order.order_sn = order_sn
order.remark = remark
order.save()
#更新
cardIdList = []
for card in cardList:
cardIdList.append(card['cardId'])
cardNum = len(cardIdList)
resCard = CardInventory.objects.filter(card_no__in=cardIdList,card_status='1',is_store='0').update(card_status=2,card_action='0')
if resCard!= cardNum:
raise MyError('CardInventory状态更新失败')
# 更新Guest
updateConfList = []
updateConfList.append({'ids': cardIdList, 'mode': '1', 'count': cardNum})
resGuest = mtu.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res["status"] = 1
res["urlRedirect"] ='/kg/sellcard/fornt/cardsale/orderInfo/?orderSn='+order_sn
ActionLog.objects.create(action='实物团购返点',u_name=request.session.get('s_uname'),cards_out=cardStr,add_time=datetime.datetime.now())
del request.session['postToken']
except Exception as e:
if hasattr(e,'value'):
res['msg'] = e.value
res["status"] = 0
ActionLog.objects.create(action='实物团购返点',u_name=request.session.get('s_uname'),cards_out=cardStr,add_time=datetime.datetime.now(),err_msg=e)
return HttpResponse(json.dumps(res))
示例7: save
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
#.........这里部分代码省略.........
discountRate = payDiscDict[pay['payId']]
discountVal = Ycash = float(pay['payVal']) * float(discountRate)
orderPay.is_pay = is_pay
# if pay['payId']=='9':
# isThird = True
# mth.upChangeCode(hjsList,shopcode)
orderPay.pay_value = pay['payVal']
orderPay.remarks = pay['payRmarks']
paymentList.append(orderPay)
OrderPaymentInfo.objects.bulk_create(paymentList)
infoList = []
for card in cardList:
orderInfo = OrderInfo()
orderInfo.order_id = order_sn
orderInfo.card_id = card['card_no']
orderInfo.card_balance = float(card['card_balance'])
orderInfo.card_action = '0'
orderInfo.card_attr = '1'
infoList.append(orderInfo)
if not isThird:
for Ycard in YcardList:
YorderInfo = OrderInfo()
YorderInfo.order_id = order_sn
YorderInfo.card_id = Ycard['cardId']
YorderInfo.card_balance = float(Ycard['cardVal'])
YorderInfo.card_action = '0'
YorderInfo.card_attr = '2'
infoList.append(YorderInfo)
OrderInfo.objects.bulk_create(infoList)
order = Orders()
order.buyer_name = buyer['borrow_name']
order.buyer_tel = buyer['borrow_phone']
order.buyer_company = buyer['borrow_depart']
order.total_amount = float(totalVal)+float(discountVal)
order.paid_amount = float(totalVal)+float(Ybalance)#实付款合计=售卡合计+优惠补差
order.disc_amount = discountVal#优惠合计
order.diff_price = Ybalance
order.shop_code = shopcode
order.depart = depart
order.operator_id = operator
order.action_type = actionType
order.add_time = datetime.datetime.now()
order.discount_rate = discountRate
order.order_sn = order_sn
order.y_cash = Ycash
order.save()
#未退回卡列表 chedan
cardIdBorrowList = [card['card_no'] for card in cardList]
#优惠卡列表
cardIdDisclist = [card['cardId'] for card in YcardList]
# 更新kggroup内部优惠赠送卡状态
resCard = CardInventory.objects.filter(card_no__in=cardIdDisclist,card_status='1',is_store='0')\
.update(card_status='2',card_action='0')
if resCard != len(cardIdDisclist):
raise MyError('CardInventory状态更新失败')
#更新折扣授权码校验码状态
if disCode:
resCode = mth.updateDisCode(disCode,shopcode,order_sn)
if resCode == 0:
raise MyError('折扣授权码状态更新失败')
#更新借卡单的结算状态
resBorrow = orderBorrow.update(is_paid='1',paid_time=datetime.datetime.now(),reply_order=order_sn)
if not resBorrow:
raise MyError('OrderBorrow状态更新失败')
resBorrow2 = OrderBorrowInfo.objects.filter(order_sn=orderSnList,card_no__in=cardIdBorrowList, is_back=None).update(is_back='0')
if resBorrow2 != len(cardIdBorrowList):
raise MyError('OrderBorrowInfo数据更新失败')
# 更新ERP内部优惠赠送卡状态
if len(cardIdDisclist)>0:
# 更新Guest
updateConfList = []
updateConfList.append({'ids': cardIdDisclist, 'mode': '1', 'count': len(cardIdDisclist)})
resGuest = mth.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res["status"] = 1
res["urlRedirect"] ='/kg/sellcard/fornt/cardsale/orderInfo/?orderSn='+order_sn
cardOutTotal = cardIdBorrowList + cardIdDisclist
ActionLog.objects.create(action='借卡-结算',u_name=request.session.get('s_uname'),cards_out=json.dumps(cardOutTotal),add_time=datetime.datetime.now())
del request.session['postToken']
except Exception as e:
res["status"] = 0
if hasattr(e,'value'):
res['msg'] = e.value
ActionLog.objects.create(action='借卡-结算',u_name=request.session.get('s_uname'),add_time=datetime.datetime.now(),err_msg=e)
return HttpResponse(json.dumps(res))
示例8: save
# 需要导入模块: from sellcard.common import Method [as 别名]
# 或者: from sellcard.common.Method import updateCard [as 别名]
def save(request):
operator = request.session.get('s_uid','')
shopcode = request.session.get('s_shopcode','')
#售卡列表
cardStr = request.POST.get('cardStr','')
cardList = json.loads(cardStr)
#合计信息
totalNum = request.POST.get('totalNum',0)
totalVal = request.POST.get('totalVal',0.00)
#借卡人信息
borrowDepart = (request.POST.get('borrowDepart','')).strip()
borrowName = (request.POST.get('borrowName','')).strip()
borrowDepartCode = (request.POST.get('borrowDepartCode','')).strip()
borrowPhone = (request.POST.get('borrowPhone','')).strip()
order_sn = ''
res = {}
try:
# 检测session中Token值,判断用户提交动作是否合法
Token = request.session.get('postToken', default=None)
# 获取用户表单提交的Token值
userToken = request.POST.get('postToken', '')
if userToken != Token:
raise MyError('表单重复提交,刷新页面后,重试!')
with transaction.atomic():
order_sn = 'B'+mth.setOrderSn(OrderBorrow)
infoList = []
for card in cardList:
orderInfo = OrderBorrowInfo()
orderInfo.order_sn = order_sn
orderInfo.card_no = card['cardId']
orderInfo.card_type = card['cardVal']
orderInfo.card_balance = card['cardVal']
infoList.append(orderInfo)
OrderBorrowInfo.objects.bulk_create(infoList)
order = OrderBorrow()
order.borrow_name = borrowName
order.borrow_depart = borrowDepart
order.borrow_depart_code = borrowDepartCode
order.borrow_phone= borrowPhone
order.shopcode = shopcode
order.operator = operator
order.order_val = float(totalVal)
order.order_num = totalNum
order.add_time = datetime.datetime.now()
order.is_paid = '0'
order.order_sn = order_sn
order.save()
#更新卡状态
cardIdList = []
for card in cardList:
cardIdList.append(card['cardId'])
cardNum = len(cardIdList)
resCard = CardInventory.objects.filter(card_no__in=cardIdList,card_status='1',is_store='0')\
.update(card_status='2',card_action='0')
if resCard != cardNum:
raise MyError('CardInventory状态更新失败!')
# 更新Guest
updateConfList = []
updateConfList.append({'ids': cardIdList, 'mode': '1', 'count': cardNum})
resGuest = mth.updateCard(updateConfList)
if resGuest['status'] == 0:
raise MyError(resGuest['msg'])
res["status"] = 1
res["urlRedirect"] = '/kg/sellcard/fornt/borrow/sale/info/?orderSn='+order_sn
ActionLog.objects.create(action='借卡-售卡',u_name=request.session.get('s_uname'),cards_out=cardStr,add_time=datetime.datetime.now())
del request.session['postToken']
except Exception as e:
print(e)
res["status"] = 0
if hasattr(e,'value'):
res['msg'] = e.value
ActionLog.objects.create(action='借卡-售卡',u_name=request.session.get('s_uname'),cards_out=cardStr,add_time=datetime.datetime.now(),err_msg=e)
return HttpResponse(json.dumps(res))