|
@@ -825,29 +825,100 @@ class CloudStorageView(View):
|
|
|
|
|
|
response = ResponseObject()
|
|
|
data = request.POST.dict()
|
|
|
+ try:
|
|
|
+ signature = data["sign"]
|
|
|
+ data.pop('sign')
|
|
|
+ orderID = data['out_trade_no']
|
|
|
|
|
|
- signature = data["sign"]
|
|
|
- data.pop('sign')
|
|
|
- orderID = data['out_trade_no']
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
+ print(order_qs)
|
|
|
+ self.callback_dostatus(orderID)
|
|
|
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
- print(order_qs)
|
|
|
+ if not order_qs.exists():
|
|
|
+ return response.json(404)
|
|
|
|
|
|
- if not order_qs.exists():
|
|
|
- return response.json(404)
|
|
|
-
|
|
|
- self.callback_dostatus(orderID)
|
|
|
- print(json.dumps(data))
|
|
|
- print(signature)
|
|
|
- # verify
|
|
|
- aliPayObj = AliPayObject()
|
|
|
- alipay = aliPayObj.conf()
|
|
|
- success = alipay.verify(data, signature)
|
|
|
- if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
|
|
|
- print("trade succeed")
|
|
|
+
|
|
|
+ print(json.dumps(data))
|
|
|
+ print(signature)
|
|
|
+ # verify
|
|
|
+ aliPayObj = AliPayObject()
|
|
|
+ alipay = aliPayObj.conf()
|
|
|
+ success = alipay.verify(data, signature)
|
|
|
+ if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
|
|
|
+ print("trade succeed")
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=orderID)
|
|
|
+ nowTime = int(time.time())
|
|
|
+ order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts", "userID__userID", "userID__username")
|
|
|
+ userid = order_list[0]['userID__userID']
|
|
|
+ username = order_list[0]['userID__username']
|
|
|
+ UID = order_list[0]['UID']
|
|
|
+ channel = order_list[0]['channel']
|
|
|
+ rank = order_list[0]['rank']
|
|
|
+ smqs = Store_Meal.objects.filter(id=rank). \
|
|
|
+ values("day", "bucket_id", "bucket__storeDay", "expire")
|
|
|
+ bucketId = smqs[0]['bucket_id']
|
|
|
+ if not smqs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ ubqs = UID_Bucket.objects.filter(bucket__id=bucketId, uid=UID, channel=channel, endTime__gte=nowTime). \
|
|
|
+ values("id", "bucket__storeDay", "bucket__region", "endTime").order_by('addTime')[:1]
|
|
|
+ nowTime = int(time.time())
|
|
|
+ expire = smqs[0]['expire']
|
|
|
+ if order_list[0]['isSelectDiscounts'] == 1:
|
|
|
+ expire = smqs[0]['expire'] * 2
|
|
|
+ if ubqs.exists():
|
|
|
+ ubq = ubqs[0]
|
|
|
+ endTime = CommonService.calcMonthLater(expire, ubq['endTime'])
|
|
|
+ ub_cqs = UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
+ (uid=UID, channel=channel, bucket_id=bucketId,
|
|
|
+ endTime=endTime,updateTime=nowTime)
|
|
|
+ uid_bucket_id = ubq['id']
|
|
|
+ else:
|
|
|
+ endTime = CommonService.calcMonthLater(expire)
|
|
|
+ ub_cqs = UID_Bucket.objects.create \
|
|
|
+ (uid=UID, channel=channel, bucket_id=bucketId, endTime=endTime, addTime=nowTime, updateTime=nowTime)
|
|
|
+ uid_bucket_id = ub_cqs.id
|
|
|
+
|
|
|
+ dvq = Device_Info.objects.filter(UID=UID, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
|
+ if dvq.exists():
|
|
|
+ dvq_set_update_dict = {
|
|
|
+ 'vodPrimaryUserID': userid,
|
|
|
+ 'vodPrimaryMaster': username
|
|
|
+ }
|
|
|
+ dvq.update(**dvq_set_update_dict)
|
|
|
+
|
|
|
+ order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id)
|
|
|
+ red_url = "{SERVER_DOMAIN}cloudstorage/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return HttpResponseRedirect(red_url)
|
|
|
+ return response.json(0, signature)
|
|
|
+ except Exception as e:
|
|
|
+ if order_qs:
|
|
|
+ order_qs.update(status=10)
|
|
|
+ red_url = "{SERVER_DOMAIN}cloudstorage/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return HttpResponseRedirect(red_url)
|
|
|
+
|
|
|
+ def do_pay_by_paypal_callback(self, request_dict, response):
|
|
|
+ paymentId = request_dict.get('paymentId', None)
|
|
|
+ PayerID = request_dict.get('PayerID', None)
|
|
|
+ orderID = request_dict.get('orderID', None)
|
|
|
+
|
|
|
+ try:
|
|
|
+ self.callback_dostatus(orderID)
|
|
|
+ if not paymentId or not PayerID or not orderID:
|
|
|
+ red_url = "{SERVER_DOMAIN}cloudstorage/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return HttpResponseRedirect(red_url)
|
|
|
+ paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
+ # ID of the payment. This ID is provided when creating payment.
|
|
|
+ payment = paypalrestsdk.Payment.find(paymentId)
|
|
|
+ payres = payment.execute({"payer_id": PayerID})
|
|
|
+ print(payres)
|
|
|
+ if not payres:
|
|
|
+ red_url = "{SERVER_DOMAIN}cloudstorage/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return HttpResponseRedirect(red_url)
|
|
|
+ print("Payment execute successfully")
|
|
|
order_qs = Order_Model.objects.filter(orderID=orderID)
|
|
|
nowTime = int(time.time())
|
|
|
- order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts", "userID__userID", "userID__username")
|
|
|
+ order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts", "userID__userID",
|
|
|
+ "userID__username")
|
|
|
userid = order_list[0]['userID__userID']
|
|
|
username = order_list[0]['userID__username']
|
|
|
UID = order_list[0]['UID']
|
|
@@ -858,15 +929,15 @@ class CloudStorageView(View):
|
|
|
bucketId = smqs[0]['bucket_id']
|
|
|
if not smqs.exists():
|
|
|
return response.json(173)
|
|
|
+ # ##
|
|
|
ubqs = UID_Bucket.objects.filter(bucket__id=bucketId, uid=UID, channel=channel, endTime__gte=nowTime). \
|
|
|
values("id", "bucket__storeDay", "bucket__region", "endTime").order_by('addTime')[:1]
|
|
|
- nowTime = int(time.time())
|
|
|
expire = smqs[0]['expire']
|
|
|
if order_list[0]['isSelectDiscounts'] == 1:
|
|
|
expire = smqs[0]['expire'] * 2
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
|
- endTime = CommonService.calcMonthLater(expire, ubq['endTime'])
|
|
|
+ endTime = CommonService.calcMonthLater(expire,ubq['endTime'])
|
|
|
ub_cqs = UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId,
|
|
|
endTime=endTime,updateTime=nowTime)
|
|
@@ -884,87 +955,30 @@ class CloudStorageView(View):
|
|
|
'vodPrimaryMaster': username
|
|
|
}
|
|
|
dvq.update(**dvq_set_update_dict)
|
|
|
-
|
|
|
order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id)
|
|
|
- red_url = "{SERVER_DOMAIN}cloudstorage/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
- return response.json(0, signature)
|
|
|
|
|
|
- def do_pay_by_paypal_callback(self, request_dict, response):
|
|
|
- paymentId = request_dict.get('paymentId', None)
|
|
|
- PayerID = request_dict.get('PayerID', None)
|
|
|
- orderID = request_dict.get('orderID', None)
|
|
|
- if not paymentId or not PayerID or not orderID:
|
|
|
- red_url = "{SERVER_DOMAIN}cloudstorage/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ # return response.json(0)
|
|
|
+ red_url = "{SERVER_DOMAIN}cloudstorage/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
+ except Exception as e:
|
|
|
+ if order_qs:
|
|
|
+ order_qs.update(status=10)
|
|
|
|
|
|
- self.callback_dostatus(orderID)
|
|
|
- paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
- # ID of the payment. This ID is provided when creating payment.
|
|
|
- payment = paypalrestsdk.Payment.find(paymentId)
|
|
|
- payres = payment.execute({"payer_id": PayerID})
|
|
|
- print(payres)
|
|
|
- if not payres:
|
|
|
red_url = "{SERVER_DOMAIN}cloudstorage/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
- print("Payment execute successfully")
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID)
|
|
|
- nowTime = int(time.time())
|
|
|
- order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts", "userID__userID",
|
|
|
- "userID__username")
|
|
|
- userid = order_list[0]['userID__userID']
|
|
|
- username = order_list[0]['userID__username']
|
|
|
- UID = order_list[0]['UID']
|
|
|
- channel = order_list[0]['channel']
|
|
|
- rank = order_list[0]['rank']
|
|
|
- smqs = Store_Meal.objects.filter(id=rank). \
|
|
|
- values("day", "bucket_id", "bucket__storeDay", "expire")
|
|
|
- bucketId = smqs[0]['bucket_id']
|
|
|
- if not smqs.exists():
|
|
|
- return response.json(173)
|
|
|
- # ##
|
|
|
- ubqs = UID_Bucket.objects.filter(bucket__id=bucketId, uid=UID, channel=channel, endTime__gte=nowTime). \
|
|
|
- values("id", "bucket__storeDay", "bucket__region", "endTime").order_by('addTime')[:1]
|
|
|
- expire = smqs[0]['expire']
|
|
|
- if order_list[0]['isSelectDiscounts'] == 1:
|
|
|
- expire = smqs[0]['expire'] * 2
|
|
|
- if ubqs.exists():
|
|
|
- ubq = ubqs[0]
|
|
|
- endTime = CommonService.calcMonthLater(expire,ubq['endTime'])
|
|
|
- ub_cqs = UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
- (uid=UID, channel=channel, bucket_id=bucketId,
|
|
|
- endTime=endTime,updateTime=nowTime)
|
|
|
- uid_bucket_id = ubq['id']
|
|
|
- else:
|
|
|
- endTime = CommonService.calcMonthLater(expire)
|
|
|
- ub_cqs = UID_Bucket.objects.create \
|
|
|
- (uid=UID, channel=channel, bucket_id=bucketId, endTime=endTime, addTime=nowTime, updateTime=nowTime)
|
|
|
- uid_bucket_id = ub_cqs.id
|
|
|
-
|
|
|
- dvq = Device_Info.objects.filter(UID=UID, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
|
- if dvq.exists():
|
|
|
- dvq_set_update_dict = {
|
|
|
- 'vodPrimaryUserID': userid,
|
|
|
- 'vodPrimaryMaster': username
|
|
|
- }
|
|
|
- dvq.update(**dvq_set_update_dict)
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id)
|
|
|
-
|
|
|
- # return response.json(0)
|
|
|
- red_url = "{SERVER_DOMAIN}cloudstorage/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
|
|
|
def do_pay_by_wechat_callback(self, request, response):
|
|
|
|
|
|
logger = logging.getLogger('log')
|
|
|
|
|
|
- pay = WechatPayObject()
|
|
|
- data = pay.weixinpay_call_back(request.body)
|
|
|
|
|
|
- trade_status = data['result_code'] # 业务结果 SUCCESS/FAIL
|
|
|
- out_trade_no = data['out_trade_no'] # 商户订单号
|
|
|
- order_qs =None
|
|
|
try:
|
|
|
+ pay = WechatPayObject()
|
|
|
+ data = pay.weixinpay_call_back(request.body)
|
|
|
+
|
|
|
+ trade_status = data['result_code'] # 业务结果 SUCCESS/FAIL
|
|
|
+ out_trade_no = data['out_trade_no'] # 商户订单号
|
|
|
+ order_qs = None
|
|
|
if trade_status == "SUCCESS":
|
|
|
logger.info('微信回调返回值 进来了。')
|
|
|
check_sign = pay.get_notifypay(data)
|
|
@@ -1021,7 +1035,7 @@ class CloudStorageView(View):
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '参数格式校验错误'}))
|
|
|
except Exception as e:
|
|
|
if order_qs:
|
|
|
- order_qs.update(status=0)
|
|
|
+ order_qs.update(status=10)
|
|
|
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': repr(e)}))
|
|
|
|