chenjunkai 6 жил өмнө
parent
commit
8ca92d5bca

+ 55 - 7
Controller/CloudVod.py

@@ -925,9 +925,9 @@ class CloudVodView(View):
                 response.content = success_pay_content
                 response.content = success_pay_content
                 return response
                 return response
             else:
             else:
-                response.content = falil_pay_content
-                return response
-                exit()
+                # response.content = falil_pay_content
+                # return response
+                # exit()
                 # 如果未支付则调用查询订单是否支付成功
                 # 如果未支付则调用查询订单是否支付成功
                 aliPayObj = AliPayObject()
                 aliPayObj = AliPayObject()
                 alipay = aliPayObj.conf()
                 alipay = aliPayObj.conf()
@@ -937,11 +937,59 @@ class CloudVodView(View):
                 result = alipay.api_alipay_trade_query(out_trade_no=orderID)
                 result = alipay.api_alipay_trade_query(out_trade_no=orderID)
                 if result.get("trade_status", "") == "TRADE_SUCCESS":
                 if result.get("trade_status", "") == "TRADE_SUCCESS":
                     print('paid')
                     print('paid')
-                    nowTime = int(time.time())
-                    om_qs.update(status=1, updTime=nowTime)
+                    print("trade succeed")
+                    order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
+                    if order_qs.exists():
+                        nowTime = int(time.time())
+                        order_list = order_qs.values("UID", "rank__id", "channel")
+                        rank_id = order_list[0]['rank__id']
+                        print(rank_id)
+                        UID = order_list[0]['UID']
+                        channel = order_list[0]['channel']
+                        order_qs.update(status=1, updTime=nowTime)
+
+                        smqs = Store_Meal.objects.filter(id=rank_id).values("day", "bucket_id", "bucket__storeDay")
+                        bucketId = smqs[0]['bucket_id']
+                        if not smqs.exists():
+                            response.content = falil_pay_content
+                            return response
+                        addTime = int(smqs[0]["day"]) * 24 * 3600
+                        ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel). \
+                            values("bucket_id", "endTime", "bucket__storeDay")
+                        nowTime = int(time.time())
+                        if ubqs.exists():
+                            # 判断是否过期了
+                            if nowTime > ubqs[0]['endTime']:
+                                ubqs.update(endTime=nowTime + addTime)
+                            else:
+                                # 同一个bucket续费
+                                if bucketId == ubqs[0]['bucket_id']:
+                                    ubqs.update(endTime=ubqs[0]['endTime'] + addTime)
+                                else:
+                                    if ubqs[0]['bucket__storeDay'] > smqs[0]['bucket__storeDay']:
+                                        response.content = falil_pay_content
+                                        return response
+                                    else:
+                                        # 升级
+                                        origin_storeDay = int(ubqs[0]['bucket__storeDay'])
+                                        upgrade_storeDay = int(smqs[0]['bucket__storeDay'])
+                                        ctcTime = ubqs[0]['endTime'] - nowTime
+                                        multiple = math.ceil(upgrade_storeDay / origin_storeDay)
+                                        ubqs.update(endTime=ctcTime / multiple + addTime + ubqs[0]['endTime'],
+                                                    bucket_id=bucketId)
+                                        # 付款成功把oss token删除
+                                        OssCrdModel.objects.filter(uid=UID, channel=channel).delete()
+                        # 新增模式
+                        else:
+                            print('create')
+                            UID_Bucket.objects.create(uid=UID, channel=channel,
+                                                      bucket_id=bucketId, endTime=nowTime + addTime)
 
 
-                    response.content = success_pay_content
-                    return response
+                        response.content = success_pay_content
+                        return response
+                    else:
+                        response.content = falil_pay_content
+                        return response
                 else:
                 else:
                     print("not paid...")
                     print("not paid...")
                     response.content = falil_pay_content
                     response.content = falil_pay_content