xjc 2 mēneši atpakaļ
vecāks
revīzija
042b218ffe
3 mainītis faili ar 147 papildinājumiem un 0 dzēšanām
  1. 88 0
      src/weixin/controls.py
  2. 4 0
      src/weixin/urls_backstage.py
  3. 55 0
      src/weixin/views.py

+ 88 - 0
src/weixin/controls.py

@@ -45,6 +45,8 @@ from utils.wxpay.pay import WechatPayDAL
 #log = logging.getLogger("myerror")
 from utils.upload_to_oss import get_signature
 
+from weixin.wzhifuSDK_V3 import refund_order
+
 def async(f):
     def wrapper(*args, **kwargs):
         thr = Thread(target=f, args=args, kwargs=kwargs)
@@ -3786,3 +3788,89 @@ def get_user_markscore_week_avg(request):
             
 
 
+def refund_out_trade_order(**kwargs):
+    """
+    """
+    _id = kwargs.get("id")
+    signup_order = cm.SignupOrder.objects.filter(id=_id).first()
+    if signup_order:
+        out_trade_no = signup_order.out_trade_no
+        transaction_id = signup_order.transaction_id
+        total_fee = signup_order.total_fee
+        amount = str(int(total_fee*100))
+        print(amount)
+        result = refund_order(transaction_id,out_trade_no,out_trade_no,amount)
+        if result.get("result_code") == "SUCCESS":
+            signup_order.order_status = -1
+            signup_order.save()
+            return "success"
+        else:
+            raise ce.TipException(result.get("err_code_des"))
+    else:
+        raise ce.TipException(u"该订单不存在退款失败!")
+
+
+def signup_old_user(**kwargs):
+    """
+    """
+    order_id = kwargs.get("id")
+    signup_type = kwargs.get("signup_type")
+    match_group = kwargs.get("match_group")
+    player_type = kwargs.get("player_type")
+    role_type = kwargs.get("role_type")
+
+    order = cm.SignupOrder.objects.filter(id=order_id).first()
+    if order:
+        user_id = order.user_id
+        match_id = order.match_id
+        signup_name = order.signup_name
+
+        user = cm.UserInfo.objects.filter(id=user_id).first()
+        match_group_name = cm.MatchGroup.objects.filter(id=match_group).first().name
+        match = cm.Match.objects.filter(id=match_id).first()
+
+        user.player_type = player_type
+        user.phone = order.phone
+        user.username = signup_name
+        user.save()
+
+
+        order.signup_type = signup_type
+        order.match_group = match_group
+        order.match_group_name = match_group_name
+        order.order_status = 1
+        order.save()
+        
+        #生产选手信息
+        player,flag = cm.Player.objects.get_or_create(
+            user_id = user_id, 
+            match_id = match_id
+        )
+        player.match_name = match.name
+        player.match_group = match_group
+        player.match_group_name = match_group_name
+        player.username = signup_name 
+        player.usercode = user.usercode
+        player.role = role_type
+        player.match_status = 1
+        player.save()
+
+
+def get_user_signup_order(request):
+    """#获取用户订单号
+    """
+    try:
+        user_id = request.user.get("id",0)
+    except:
+        user_id = 0
+    qdata = request.json
+    pay_status = qdata.get("pay_status")
+    if not user_id:
+        user_id = qdata.get("user_id")
+    match_id = ccc.get_cur_match().id
+
+    qset = cm.SignupOrder.objects.filter(user_id=user_id,match_id=match_id,pay_status=pay_status)
+    qdata = qset.values().first()
+
+    return qdata
+

+ 4 - 0
src/weixin/urls_backstage.py

@@ -123,5 +123,9 @@ urlpatterns = [
     url(r'^v3/match/group/list$', views.MatchGroupListView.as_view()),
     
     url(r'^v3/user/markscore/weekavg$', views.UserMarkWekkAvgView.as_view()),
+
+    url(r'^v3/wxpay/refund$', views.WXPayRefundView.as_view()),
+    url(r'^v3/signup/olduser$', views.SignupOldUserView.as_view()),
+    url(r'^v3/user/signup/order$', views.UserSignupOrder.as_view()),
 ]
 

+ 55 - 0
src/weixin/views.py

@@ -1792,3 +1792,58 @@ class UserMarkWekkAvgView(cv.BaseView):
         except Exception as e:
             cv.tracefail()
             return cv.to_fail(e)
+
+
+class WXPayRefundView(cv.AuthView):
+    def post(self,request):
+        """#微信退款(平台管理后台)
+        @id:"订单id"
+        """
+        qdata = request.json
+        need_params = ["id"]
+        mse = ccf.check_params(*need_params,**qdata)
+        if mse:
+            raise ce.TipException(mse)
+        try:
+            vals = ccf.get_need_params(*need_params,**qdata)
+            rst = ctl.refund_out_trade_order(**vals)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class SignupOldUserView(cv.AuthView):
+    def put(self,request):
+        """#老用户处理(平台管理后台)
+        @id:"1"
+        @match_group:1
+        @player_type:""
+        @role_type:""
+        """
+        qdata = request.json
+        need_params = ["id","signup_type","match_group"]
+        mse = ccf.check_params(*need_params,**qdata)
+        if mse:
+            raise ce.TipException(mse)
+        try:
+            need_params.extend(["player_type","role_type","match_id"])
+            vals = ccf.get_need_params(*need_params,**qdata)
+            rst = ctl.signup_old_user(**vals)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class UserSignupOrder(cv.BaseView):
+    def get(self, request):
+        """#获取用户当前赛事报名信息
+        """
+        try:
+            rst = ctl.get_user_signup_order(request)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+