|
|
@@ -331,12 +331,14 @@ def wx_notify_url_api(request):
|
331
|
331
|
return HttpResponse(settings.WXPAY_NOTIFY_SUCCESS)
|
332
|
332
|
|
333
|
333
|
|
|
334
|
+@logit
|
|
335
|
+@transaction.atomic
|
334
|
336
|
def wx_balance_withdraw_api(request):
|
335
|
337
|
user_id = request.POST.get('user_id', '')
|
336
|
338
|
|
337
|
339
|
# 用户校验
|
338
|
340
|
try:
|
339
|
|
- user = UserInfo.objects.get(user_id=user_id)
|
|
341
|
+ user = UserInfo.objects.select_for_update().get(user_id=user_id)
|
340
|
342
|
except UserInfo.DoesNotExist:
|
341
|
343
|
return response(UserStatusCode.USER_NOT_FOUND)
|
342
|
344
|
|
|
|
@@ -358,9 +360,9 @@ def wx_balance_withdraw_api(request):
|
358
|
360
|
wxpay = WeChatPay(wechat.get('appID'), wechat.get('apiKey'), wechat.get('mchID'), mch_cert=wechat.get('mch_cert'), mch_key=wechat.get('mch_key'))
|
359
|
361
|
|
360
|
362
|
if withdraw_type == 'TRANSFER':
|
361
|
|
- wxpay.transfer.transfer(user.wx_uid, amount, u'摄影师余额提现,企业付款', check_name='NO_CHECK')
|
|
363
|
+ ret_data = wxpay.transfer.transfer(user.wx_uid, amount, u'摄影师余额提现,企业付款', check_name='NO_CHECK')
|
362
|
364
|
elif withdraw_type == 'PACKET':
|
363
|
|
- wxpay.redpack.send(
|
|
365
|
+ ret_data = wxpay.redpack.send(
|
364
|
366
|
user.wx_uid,
|
365
|
367
|
amount,
|
366
|
368
|
send_name=wechat.get('redpacket', {}).get('SEND_NAME'),
|
|
|
@@ -370,4 +372,8 @@ def wx_balance_withdraw_api(request):
|
370
|
372
|
remark=wechat.get('redpacket', {}).get('REMARK'),
|
371
|
373
|
)
|
372
|
374
|
|
|
375
|
+ # 根据 ret_data 判断是否提现成功, 成功则减余额, 失败则提示
|
|
376
|
+ user.balance -= amount
|
|
377
|
+ user.save()
|
|
378
|
+
|
373
|
379
|
return response(200, 'Withdraw Success', u'提现成功', {})
|