(self, result, signal=True, verify=True)
根据参数更新订单状态
根据参数更新订单状态
根据参数更新订单状态
def update(self, result, signal=True, verify=True):
        """根据参数更新订单状态"""
        verify and self.order.verify(result)
        # TODO: 支付成功后写入用户
        excludes = ("transaction_id",) if self.transaction_id else tuple()
        all_fields = model_fields(UnifiedOrderResult, excludes=excludes)
        ignore_fields = ("return_code", "return_msg", "appid", "mch_id",
                         "device_info", "nonce_str", "sign", "result_code",
                         "openid", "trade_type", "fee_type", "out_trade_no")
        for k, v in result.items():
            if k not in ignore_fields:
                if k in all_fields:
                    if isinstance(self._meta.get_field(k), PayDateTimeField):
                        v = PayDateTimeField.str2dt(v)
                    setattr(self, k, v)
                else:
                    self.ext_info[k] = v
        self.save()
        if signal:
            order_updated.send(sender=self.order.pay.staticname, result=self,
                               order=self.order, state=self.trade_state,
                               attach=result.get("attach"))
def update ( self , result , signal = True , verify = True ) : verify and self . order . verify ( result ) # TODO: 支付成功后写入用户 excludes = ( "transaction_id" , ) if self . transaction_id else tuple ( ) all_fields = model_fields ( UnifiedOrderResult , excludes = excludes ) ignore_fields = ( "return_code" , "return_msg" , "appid" , "mch_id" , "device_info" , "nonce_str" , "sign" , "result_code" , "openid" , "trade_type" , "fee_type" , "out_trade_no" ) for k , v in result . items ( ) : if k not in ignore_fields : if k in all_fields : if isinstance ( self . _meta . get_field ( k ) , PayDateTimeField ) : v = PayDateTimeField . str2dt ( v ) setattr ( self , k , v ) else : self . ext_info [ k ] = v self . save ( ) if signal : order_updated . send ( sender = self . order . pay . staticname , result = self , order = self . order , state = self . trade_state , attach = result . get ( "attach" ) )