an> 123
+
124
+    # JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付,统一下单接口trade_type的传参可参考这里
125
+    trade_type = 'JSAPI'
126
+
127
+    # 根据 trade_type 获取 wechat 配置
128
+    wxcfg = WECHAT.get(trade_type, {})
129
+    # WeChatPay 初始化
130
+    wxpay = WeChatPay(wxcfg.get('appID'), wxcfg.get('apiKey'), wxcfg.get('mchID'))
131
+
132
+    # 生成订单
133
+    order = RoomOrderInfo.objects.create(
134
+        user_id=user_id,
135
+        room_id=room_id,
136
+        anchor_id=anchor_id,
137
+        goods_id=goods_id,
138
+        share_openid=share_openid,
139
+        amount=amount,
140
+        total_fee=total_fee,
141
+        trade_type=trade_type,
142
+        name=name,
143
+        phone=phone,
144
+        address=address,
145
+    )
146
+
147
+    try:
148
+        prepay_data = wxpay.order.create(
149
+            body=body,
150
+            notify_url=settings.API_DOMAIN + 'live/pay/notify_url',
151
+            out_trade_no=order.order_id,
152
+            total_fee=total_fee,
153
+            trade_type=trade_type,
154
+            openid=user.openid,  # 可选,用户在商户appid下的唯一标识。trade_type=JSAPI,此参数必传
155
+        )
156
+    except WeChatPayException as e:
157
+        order.unifiedorder_result = e.args
158
+        order.save()
159
+        return response(OrderStatusCode.UNIFIED_ORDER_FAIL)
160
+
161
+    prepay_id = prepay_data.get('prepay_id', '')
162
+    order.prepay_id = prepay_id
163
+    order.save()
164
+
165
+    wxpay_params = wxpay.jsapi.get_jsapi_params(prepay_id)
166
+    
167
+
168
+    return response(200, 'Order Create Success', '订单创建成功', {
169
+        'order_id': order.order_id,
170
+        'prepay_id': prepay_id,
171
+        'wxpay_params': wxpay_params,
172
+    })
173
+
174
+def live_order_cancel(request):
175
+    user_id = request.POST.get('user_id', '')
176
+    order_id = request.POST.get('order_id', '')
177
+    prepay_id = request.POST.get('prepay_id', '')
178
+
179
+    try:
180
+        order = RoomOrderInfo.objects.get(user_id=user_id, order_id=order_id, prepay_id=prepay_id)
181
+    except:
182
+        return response(400001, 'Order Not Found', description='直播间订单不存在')
183
+    
184
+    if order.pay_status == RoomOrderInfo.FAIL:
185
+        return response(200, 'Order Cancel Success', '订单取消成功')
186
+    
187
+    order.pay_status = RoomOrderInfo.FAIL
188
+    order.save()
189
+    
190
+    try:
191
+        goods_info = RoomGoodsInfo.objects.get(room_id=order.room_id, goods_id=order.goods_id, anchor_id=order.anchor_id)
192
+        goods_info.inventory += order.amount
193
+        goods_info.save()
194
+    except:
195
+        return response(400001, 'Room Goods Not Found', description='直播间商品不存在')
196
+    
197
+    return response(200, 'Order Cancel Success', '订单取消成功')
198
+
199
+def order_paid_success(order):
200
+    if order.pay_status == RoomOrderInfo.PAID:
201
+        return
202
+
203
+    order.pay_status = RoomOrderInfo.PAID
204
+    order.paid_at = tc.utc_datetime()
205
+    order.save()
206
+
207
+    try:
208
+        goods_info = RoomGoodsInfo.objects.get(room_id=order.room_id, goods_id=order.goods_id, anchor_id=order.anchor_id)
209
+        goods_info.sale_infos += [order.order_id]
210
+        goods_info.save()
211
+    except:
212
+        return
213
+
214
+def order_paid_fail(order):
215
+    if order.pay_status == RoomGoodsInfo.FAIL:
216
+        return
217
+
218
+    order.pay_status = RoomGoodsInfo.FAIL
219
+    order.save()
220
+
221
+    try:
222
+        goods_info = RoomGoodsInfo.objects.get(room_id=order.room_id, goods_id=order.goods_id, anchor_id=order.anchor_id)
223
+        goods_info.inventory += order.amount
224
+        goods_info.save()
225
+    except:
226
+        return
227
+
228
+@logit
229
+@transaction.atomic
230
+def notify_url_api(request):
231
+    """ 支付异步通知回调地址 """
232
+    notify_data, success = check_pay_notify(request.body, wx_configs=settings.WECHAT)
233
+    if not success:
234
+        return HttpResponse(WXPAY_NOTIFY_FAIL)
235
+
236
+    order = RoomOrderInfo.objects.select_for_update().get(order_id=notify_data.get('out_trade_no', ''), status=True)
237
+
238
+    order.notify_msg = request.body
239
+    order.transaction_id = notify_data.get('transaction_id', '')
240
+    order.save()
241
+
242
+    result_code = notify_data.get('result_code', '')
243
+    if result_code == 'SUCCESS':
244
+        live_views.order_paid_success(order)
245
+    else:
246
+        live_views.order_paid_fail(order)
247
+
248
+    return HttpResponse(WXPAY_NOTIFY_SUCCESS)

+ 16 - 10
pay/views.py

@@ -18,8 +18,11 @@ from account.models import UserInfo
18 18
 from goods.models import GoodsInfo, PackGoodsInfo, PackGoodsSaleInfo, PackInfo
19 19
 from kol.models import KOLInfo
20 20
 from pay.models import OrderInfo
21
+from live.models import RoomOrderInfo
21 22
 from utils.error.errno_utils import KOLStatusCode, OrderStatusCode, PackGoodsStatusCode, PackStatusCode, UserStatusCode
22 23
 
24
+from live import views as live_views
25
+
23 26
 
24 27
 WECHAT = settings.WECHAT
25 28
 
@@ -215,19 +218,22 @@ def wx_notify_url_api(request):
215 218
     if not success:
216 219
         return HttpResponse(WXPAY_NOTIFY_FAIL)
217 220
 
221
+    #尖货接龙订单
218 222
     try:
219 223
         order = OrderInfo.objects.select_for_update().get(order_id=notify_data.get('out_trade_no', ''), status=True)
220
-    except OrderInfo.DoesNotExist:
221
-        return HttpResponse(WXPAY_NOTIFY_FAIL)
224
+        order.notify_msg = request.body
225
+        order.transaction_id = notify_data.get('transaction_id', '')
226
+        order.save()
222 227
 
223
-    order.notify_msg = request.body
224
-    order.transaction_id = notify_data.get('transaction_id', '')
225
-    order.save()
228
+        result_code = notify_data.get('result_code', '')
229
+        if result_code == 'SUCCESS':
230
+            order_paid_success(order)
231
+        else:
232
+            order_paid_fail(order)
233
+        
234
+        return HttpResponse(WXPAY_NOTIFY_SUCCESS)
235
+    except:
236
+        return HttpResponse(WXPAY_NOTIFY_FAIL)
226 237
 
227
-    result_code = notify_data.get('result_code', '')
228
-    if result_code == 'SUCCESS':
229
-        order_paid_success(order)
230
-    else:
231
-        order_paid_fail(order)
232 238
 
233 239
     return HttpResponse(WXPAY_NOTIFY_SUCCESS)

kodo - Gogs: Go Git Service

Нет описания

FFIB: 39290e111b ConsumeInfoSubmitLogInfo 记录用户积分 лет %!s(int64=4): %!d(string=назад)
..
0001_initial.py aa31a5f59a Add kodo лет %!s(int64=8): %!d(string=назад)
0002_auto_20180104_0414.py 018d52f61d Update package django_xxx лет %!s(int64=7): %!d(string=назад)
0003_auto_20180104_0428.py 9ec76d526a TextField => CharField лет %!s(int64=8): %!d(string=назад)
0004_latestappinfo.py 018d52f61d Update package django_xxx лет %!s(int64=7): %!d(string=назад)
0005_auto_20180115_0021.py 49634dc097 Add api operator login лет %!s(int64=8): %!d(string=назад)
0006_auto_20180115_0047.py 49634dc097 Add api operator login лет %!s(int64=8): %!d(string=назад)
0007_consumeinfosubmitloginfo.py 1b1f0192f8 ConsumeInfoSubmitLogInfo лет %!s(int64=8): %!d(string=назад)
0008_auto_20180129_0422.py a77c4993f8 FloatField лет %!s(int64=8): %!d(string=назад)
0009_auto_20180129_0426.py e04f95dc5e long => lon лет %!s(int64=8): %!d(string=назад)
0010_modelinfo_integral.py 71993af1e4 Add integral for ModelInfo лет %!s(int64=7): %!d(string=назад)
0011_modelinfo_model_full_name.py 145973f8f0 Add brand_full_name for BrandInfo лет %!s(int64=7): %!d(string=назад)
0012_auto_20180401_2012.py f1260953bf Move image/url from ModelImageInfo to ModelInfo лет %!s(int64=7): %!d(string=назад)
0013_consumeinfosubmitloginfo_test_user.py e47aa7f8c4 Add field test_user лет %!s(int64=7): %!d(string=назад)
0014_auto_20180508_1058.py c7b55979c0 Add province code/name for DistributorInfo лет %!s(int64=7): %!d(string=назад)
0015_auto_20180508_1433.py d10bd672ea AdministratorInfo/BrandModelDistributorPriceInfo лет %!s(int64=7): %!d(string=назад)
0016_auto_20180508_1507.py d10bd672ea AdministratorInfo/BrandModelDistributorPriceInfo лет %!s(int64=7): %!d(string=назад)
0017_auto_20180508_1830.py 537c495621 Statistic лет %!s(int64=7): %!d(string=назад)
0018_auto_20180514_1519.py 62948fb5c3 Operator add/delete/update/list лет %!s(int64=7): %!d(string=назад)
0019_saleclerkinfo.py 137ed6dee2 Clerk add/delete/update/list лет %!s(int64=7): %!d(string=назад)
0020_auto_20180517_1819.py 2988703c52 Update лет %!s(int64=7): %!d(string=назад)
0021_auto_20180522_1100.py e7dcf47e22 SaleclerkInfo лет %!s(int64=7): %!d(string=назад)
0022_auto_20180522_1355.py b90bf186bc brand_domain лет %!s(int64=7): %!d(string=назад)
0023_auto_20180826_0448.py 3f9969cafc Support scan jancode лет %!s(int64=7): %!d(string=назад)
0024_latestappscreeninfo.py 900c3fd386 Makemigrations лет %!s(int64=7): %!d(string=назад)
0025_auto_20180917_1554.py 9c585b197e Mch migrations лет %!s(int64=7): %!d(string=назад)
0026_auto_20180930_1159.py 66a598b30c Makemigrations лет %!s(int64=7): %!d(string=назад)
0027_distributorinfo_distributor_short_name.py deb84bfcb5 Makemigrations лет %!s(int64=7): %!d(string=назад)
0028_consumeinfosubmitloginfo_dupload.py e9f8a35b9d Makemigrations лет %!s(int64=7): %!d(string=назад)
0029_auto_20181117_0052.py b8784eee8a Makemigrations лет %!s(int64=7): %!d(string=назад)
0030_auto_20190301_1402.py ff3a23ccf0 Activity лет %!s(int64=6): %!d(string=назад)
0031_activityinfo_model_uni_names.py ded4db2cda activityinfo_model_uni_names лет %!s(int64=6): %!d(string=назад)
0032_auto_20190521_1544.py 5a8859fa5e Makemigrations лет %!s(int64=6): %!d(string=назад)
0033_consumeinfosubmitloginfo_activity_id.py 3ade638ea3 Makemigrations лет %!s(int64=6): %!d(string=назад)
0034_auto_20190620_1709.py d666c88eac COUPON_EXPIRED_TIME_TUPLE лет %!s(int64=6): %!d(string=назад)
0035_auto_20190625_1443.py 219acdedb1 Add field has_used лет %!s(int64=6): %!d(string=назад)
0036_auto_20190701_1441.py 77c612316a queryusedsn лет %!s(int64=6): %!d(string=назад)
0037_auto_20190826_1537.py 8d998319f7 Makemigrations лет %!s(int64=6): %!d(string=назад)
0038_auto_20190826_1625.py 9db41fee66 default False лет %!s(int64=6): %!d(string=назад)
0039_auto_20191119_1348.py 3d0d214667 :sparkles: Member Infos лет %!s(int64=6): %!d(string=назад)
0040_modelinfo_shot_member_name.py 4ce7f5c87b :art: Member Relative APIs лет %!s(int64=6): %!d(string=назад)
0041_activityinfo_coupon_id.py a8239c077f :art: CouponInfo for coupon app лет %!s(int64=6): %!d(string=назад)
0042_auto_20200113_1832.py 212f24c882 MarketCode лет %!s(int64=6): %!d(string=назад)
0043_modelcamerabodyinfo.py 72656ceaff :art: model/cameras лет %!s(int64=5): %!d(string=назад)
0044_modelcamerabodyinfo_camera_brand_name.py 9619c195e6 :art: Makemigrations лет %!s(int64=5): %!d(string=назад)
0045_auto_20200304_1826.py dccd94c448 :art: Opt api model/cameras лет %!s(int64=5): %!d(string=назад)
0046_cameramodelinfo.py dccd94c448 :art: Opt api model/cameras лет %!s(int64=5): %!d(string=назад)
0047_auto_20200304_1848.py dccd94c448 :art: Opt api model/cameras лет %!s(int64=5): %!d(string=назад)
0048_modelcamerabodyinfo_is_important.py 43455cdf4e :art: Support is_important лет %!s(int64=5): %!d(string=назад)
0049_modelcamerabodyinfo_camera_market_time.py da799e7af6 :art: Add field camera_market_time for CameraModelInfo/ModelCameraBodyInfo лет %!s(int64=5): %!d(string=назад)
0050_cameramodelinfo_camera_market_time.py da799e7af6 :art: Add field camera_market_time for CameraModelInfo/ModelCameraBodyInfo лет %!s(int64=5): %!d(string=назад)
0051_auto_20200314_2340.py 7dc0b7fc6b :art: Makemigrations лет %!s(int64=5): %!d(string=назад)
0052_consumeinfosubmitloginfo_code_version.py 03631cb847 add code_version лет %!s(int64=5): %!d(string=назад)
0053_auto_20200407_1118.py 608bdf8508 makemigrations лет %!s(int64=5): %!d(string=назад)
0054_auto_20200411_2143.py 58c38a0546 整理 优惠券 лет %!s(int64=5): %!d(string=назад)
0055_auto_20200601_1634.py 89c3cefcc7 saleclerk migrate лет %!s(int64=5): %!d(string=назад)
0056_auto_20200601_1640.py 3872355991 add department_name лет %!s(int64=5): %!d(string=назад)
0057_auto_20200602_1403.py 11df57b63d support qy login лет %!s(int64=5): %!d(string=назад)
0058_auto_20201202_1203.py 6a9e324f6f :art: Re Makemigrations лет %!s(int64=5): %!d(string=назад)
0059_auto_20201221_1115.py 4ba79f76cd 后台管理,添加运营人员角色 лет %!s(int64=5): %!d(string=назад)
0060_modelinfo_is_show_shot.py 45f886651e 添加 is_show_shot 用于控制是否在前端显示 лет %!s(int64=5): %!d(string=назад)
0061_consumeinfosubmitloginfo_integral.py 39290e111b ConsumeInfoSubmitLogInfo 记录用户积分 лет %!s(int64=4): %!d(string=назад)
__init__.py aa31a5f59a Add kodo лет %!s(int64=8): %!d(string=назад)