|
@@ -10,6 +10,7 @@ from apps.exceptions import CustomError
|
|
|
from apps.account.models import Branch
|
|
|
from apps.customer.models import Customer, CustomerWechat
|
|
|
from util.wechatpay import WechatPay, WeChatResponse, SplitAccountFuc
|
|
|
+from util.format import Formater
|
|
|
|
|
|
|
|
|
class Activity(models.Model):
|
|
@@ -108,7 +109,7 @@ class SplitAccount(models.Model):
|
|
|
spc = SplitAccountFuc(app.authorizer_appid, app.agent_num, app.private_key, app.cert_serial_no, app.apiv3_key, cert_dir=app.cert_dir, proxy=None)
|
|
|
# 状态是"待分账" 的查询分账 (状态是默认的怎么处理?没有申请过的 查询分账结果会报错--如果返回错误信息根据错误信息 如果没有发现该订单就重新申请 其他原因就不再申请)
|
|
|
if spd.status == SplitAccountDetail.PENDING:
|
|
|
- self.splictAccountQuery(spc, pay.no, self.no, spd)
|
|
|
+ self.splictAccountQuery(spc, pay.transaction_id, self.no, spd)
|
|
|
|
|
|
if spd.status == SplitAccountDetail.SUCCESS:
|
|
|
raise CustomError(u'该分账已成功!')
|
|
@@ -122,7 +123,7 @@ class SplitAccount(models.Model):
|
|
|
self.splictAccountAddReceiver(spc, spr)
|
|
|
# 分账申请
|
|
|
receivers = [{'account': spd.account, 'amount': spd.amount, 'description': "支付推荐佣金"}]
|
|
|
- success, data = spc.splitaccount_order(pay.no, self.no, receivers)
|
|
|
+ success, data = spc.splitaccount_order(pay.transaction_id, self.no, receivers)
|
|
|
if not success:
|
|
|
raise CustomError(u'分账申请失败!')
|
|
|
# 分账请求成功 结果不一定成功
|
|
@@ -195,7 +196,7 @@ class SplitAccount(models.Model):
|
|
|
spr.save()
|
|
|
|
|
|
receivers = [{'account': spd.account, 'amount': spd.amount, 'description': "支付推荐佣金"}]
|
|
|
- success, data = spc.splitaccount_order(pay.no, self.no, receivers)
|
|
|
+ success, data = spc.splitaccount_order(pay.transaction_id, self.no, receivers)
|
|
|
if not success:
|
|
|
# 分账请求失败 不再继续
|
|
|
return
|
|
@@ -320,6 +321,7 @@ class Pay(models.Model):
|
|
|
|
|
|
branch = models.ForeignKey(Branch, verbose_name=u"门店", on_delete=models.PROTECT, editable=False)
|
|
|
no = models.CharField(max_length=64, verbose_name=u"单号")
|
|
|
+ transaction_id = models.CharField(max_length=100, verbose_name=u"微信支付订单号", null=True)
|
|
|
create_time = models.DateTimeField(verbose_name=u"创建时间", default=timezone.now)
|
|
|
customer = models.ForeignKey(Customer, verbose_name=u'客户', on_delete=models.PROTECT)
|
|
|
status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u"支付状态")
|
|
@@ -346,12 +348,13 @@ class Pay(models.Model):
|
|
|
self.status = Pay.CLOSED
|
|
|
self.save()
|
|
|
|
|
|
- def payConfirm(self, amount):
|
|
|
+ def payConfirm(self, amount, transaction_id):
|
|
|
if self.status != Pay.WAIT:
|
|
|
return
|
|
|
|
|
|
self.status = Pay.CONFIRM
|
|
|
- self.amount = amount
|
|
|
+ self.amount = Formater.formatPrice(amount)
|
|
|
+ self.transaction_id = transaction_id
|
|
|
self.save()
|
|
|
order = Order.objects.filter(pay=self).first()
|
|
|
if order:
|