|
@@ -108,6 +108,8 @@ class CloudStorageView(View):
|
|
|
return self.do_vod_msg_end(request_dict)
|
|
|
elif operation == 'vodMsgNotice': # 云存操作系统消息
|
|
|
return self.do_vod_msg_Notice(request_dict)
|
|
|
+ elif operation == 'doRefund': # 退款
|
|
|
+ return self.do_refund(request_dict, response)
|
|
|
|
|
|
else:
|
|
|
token = request_dict.get('token', None)
|
|
@@ -1671,6 +1673,48 @@ class CloudStorageView(View):
|
|
|
res = aliSms.send_code_sms_cloud(phone=phone, params = params, sign_name=sign_ms,
|
|
|
temp_msg=temp_msg)
|
|
|
|
|
|
+ def do_refund(self, request_dict, response):
|
|
|
+ orderID = request_dict.get('orderID', None) # 商户订单号
|
|
|
+ if not orderID:
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=orderID).values('status', 'payType', 'price')
|
|
|
+ if not order_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+
|
|
|
+ # 支付状态不为支付成功和退款失败
|
|
|
+ status = order_qs[0]['status']
|
|
|
+ if status != 1 and status != 4:
|
|
|
+ return response.json(805)
|
|
|
+
|
|
|
+ now_time = int(time.time())
|
|
|
+ payType = order_qs[0]['payType']
|
|
|
+ refund_amount = order_qs[0]['price'] # 退款金额
|
|
|
+ out_request_no = str(time.strftime('%Y%m%d%H%M%S', time.localtime(now_time))) # 退款请求号
|
|
|
+ # 根据支付类型处理退款
|
|
|
+ if payType == 1: # PayPal
|
|
|
+ pass
|
|
|
+ elif payType == 2: # 支付宝
|
|
|
+ aliPayObj = AliPayObject()
|
|
|
+ alipay = aliPayObj.conf()
|
|
|
+ refund_response = alipay.api_alipay_trade_refund(refund_amount=refund_amount, out_trade_no=orderID,
|
|
|
+ out_request_no=out_request_no)
|
|
|
+ # 退款成功,修改订单支付状态为'退款成功',否则改为'退款失败'
|
|
|
+ status = 5 if refund_response['code'] == '10000' else 4
|
|
|
+ order_qs.update(status=status, updTime=now_time)
|
|
|
+ elif payType == 3: # 微信
|
|
|
+ wechatPayObj = WechatPayObject()
|
|
|
+ refund_amount = int(float(refund_amount) * 100) # 退款金额,单位为分,只能为整数
|
|
|
+ refund_success = wechatPayObj.refund(out_trade_no=orderID, out_refund_no=out_request_no,
|
|
|
+ total_fee=refund_amount, refund_fee=refund_amount)
|
|
|
+ status = 5 if refund_success else 4
|
|
|
+ order_qs.update(status=status, updTime=now_time)
|
|
|
+ else: # 不支持退款的支付类型
|
|
|
+ return response.json(805)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
|
|
|
# 删除过期云存播放列表
|