Пример #1
0
	def calculation_amount_sum(self, mer_code, amount):
		result = WOlinetrideService.calculation_amount_zuida(mer_code,amount)
		sxf = 0
		for res in result:
			sxf_g = decimal.Decimal(str(res['sxf_g']))
			sxf_q = decimal.Decimal(str(res['sxf']))
			am = sxf_g + sxf_q
			sxf += am
		# sxf = float('%.3f' % keep_two_del(sxf))
		agentpayQuerylogger.info('代理手续费总额%s'%sxf)
		return sxf
Пример #2
0
 def get_sign(self, m_str):
     try:
         agentpayQuerylogger.info("加密前 : %s" % (m_str))
         md = hashlib.md5()
         md.update((m_str).encode())
         m_sign = md.hexdigest()
         agentpayQuerylogger.info("加密后 : %s" % (m_sign))
         return m_sign
     except Exception as e:
         agentpayQuerylogger.exception(e)
         agentpayQuerylogger.error("签名错误:%s" % (format(e)))
         return None
Пример #3
0
	def calculation_amount_zuida(mer_code,amount):
		res = db.session.query(DfAgentRate.id.label('id'),
							DfAgentRate.agent_code.label('agent_code'),
							DfAgentRate.agent_name.label('agent_name'),
							DfAgentRate.mer_code.label('mer_code'),
							DfAgentRate.rate_prop.label('rate_prop'),
							DfAgentRate.rate_amount.label('rate_amount'),
							DfAgentRate.mer_username.label('mer_username')
							,MerchantDao.state).filter(MerchantDao.code == DfAgentRate.agent_code , MerchantDao.state == 1 ,DfAgentRate.mer_code == mer_code,).all()
		asm = db.session.query(func.sum(DfTradeDao.amount)).filter(
			and_(DfTradeDao.mer_code == mer_code, DfTradeDao.state == 2)).scalar()
		if asm is None:
			asm = 0
		asm = asm + amount
		rs = {}
		rs_g = {}
		rs_name = {}
		res_r = []
		for i in res:
			yhjeDict = {}
			yhLists = []
			# 根据存款金额进行排序
			for args in i.rate_amount:
				yhLists.append(args)
			yhLists.sort(key=lambda x: float(x["amount"]))
			yhLists.reverse()
			rs['%s' % i.agent_code] = yhLists
			rs_g['%s' % i.agent_code] = i.rate_prop
			rs_name['%s' % i.agent_code] = i.agent_name
			res_r.append(i.agent_code)
		sxf_sum = 0
		result = []
		for i in res_r:
			res_di = {}
			if asm is not None:
				asm = float('%.3f' % asm)
			rate = rs[i]
			agent_name = rs_name[i]
			# rate_g = float('%.3f' % rs_g[i])
			rate_g = rs_g[i]
			sxf_on = 0
			# sxf_g = decimal.Decimal(str(res['rate_g']))
			sxf_g = amount * rate_g
			res_di['agents_code'] = i
			res_di['agents_name'] = agent_name
			res_di['sxf_g'] = sxf_g
			for j in rate:
				sxf = 0
				sxf += j['amount']
				res_di['sxf'] = str(formatDecimal_two(sxf))
				break
			result.append(res_di)
			sxf = decimal.Decimal(str(sxf))
			sxf_sum += sxf + sxf_g
			agentpayQuerylogger.info('返回字段:%s' % result)
			agentpayQuerylogger.info('代理%s的固定手续费:%s' % (i, sxf_g))
			agentpayQuerylogger.info('代理%s的区间手续费:%s' % (i, sxf))
			agentpayQuerylogger.info('该商户的总成交的订单金额%s' % asm)

		return result
Пример #4
0
 def insert_dfNotify_notice(self, m_data, success, status_code, m_res):
     m_ar = {}
     m_ar['expansion_data'] = m_data
     m_ar['status_code'] = status_code
     m_ar['response'] = m_res
     m_ar['action_time'] = int(time.time())
     m_ar['order_no'] = m_data['order_no']
     m_ar['success'] = success
     m_ar['mer_code'] = m_data['mer_code']
     try:
         no = DfNotifyDao(**m_ar)
         db.session.add(no)
         db.session.commit()
         agentpayQuerylogger.info('同步df_notify')
     except Exception as e:
         db.session.rollback()
         db.session.remove()
         agentpayQuerylogger.exception(e)
Пример #5
0
 def cash_post(self, data_args, pay_url):
     try:
         res_json = None
         agentpayQuerylogger.info("下游请求地址 %s,请求参数 %s" %
                                  (pay_url, data_args))
         headers = {'content-type': 'application/json'}
         r = requests.post(pay_url,
                           data=json.dumps(data_args),
                           headers=headers)
         status_code = r.status_code
         res = r.text
         if (status_code >= 400):
             agentpayQuerylogger.error("接口返回错误 : %s" % (res))
             raise Exception('下游接口返回错误 : %s' % (res_json))
         agentpayQuerylogger.info("接口返回正确 : %s" % (res))
         res_json = json.loads(res)
         return res_json
     except Exception as e:
         agentpayQuerylogger.exception(e)
         agentpayQuerylogger.error("下游查询订单错误 : %s" % (format(e)))
         raise Exception('下游接口返回错误 : %s' % (res_json))
Пример #6
0
 def update(self, res_json, trade, audit_time):
     agentpayQuerylogger.info("%s订单更新" % (trade.order_no))
     self.__merchantDao.dongjie_amount = self.__merchantDao.dongjie_amount - trade.amount - trade.sxf
     try:
         res_state = int(res_json['paySt'])
         trade_down = DfTradeAgentsDao().get_data_by_order_no(
             trade.order_no)
         trade.state = res_state
         trade_down.state = res_state
         if res_json['fee']:
             trade.free = formatDecimal(res_json['fee'])
             trade_down.free = formatDecimal(res_json['fee'])
         if res_json['txnDt']:
             timesp = date_to_int(res_json['txnDt'])
             trade.audit_time = timesp
             trade_down.audit_time = timesp
         if res_json['txnId']:
             trade.bank_order_no = res_json['txnId']
             trade_down.bank_order_no = res_json['txnId']
         if res_json['destAmount']:
             trade.real_amount = formatDecimal(res_json['destAmount']) / 100
             trade_down.real_amount = formatDecimal(
                 res_json['destAmount']) / 100
         if trade.state == 3:
             self.__merchantDao.amount = self.__merchantDao.amount + trade.amount + trade.sxf
         if trade.state == 2:
             agentpayQuerylogger.info("重新计算手续费")
             sxf_list = WOlinetrideService.calculation_amount(
                 trade.mer_code, trade.amount)
             real_sxf = 0
             if len(sxf_list) > 0:
                 for sxf in sxf_list:
                     agent_sxf = 0
                     if 'sxf_g' in sxf:
                         real_sxf += decimal.Decimal(sxf['sxf_g'])
                         agent_sxf += decimal.Decimal(sxf['sxf_g'])
                         self.insert_sxf_detail(sxf, 1, trade, audit_time)
                     if 'sxf' in sxf:
                         real_sxf += decimal.Decimal(sxf['sxf'])
                         agent_sxf += decimal.Decimal(sxf['sxf'])
                         self.insert_sxf_detail(sxf, 2, trade, audit_time)
                     if agent_sxf > 0:
                         agent_dao = getDataByCode(sxf['agents_code'])
                         agent_dao.amount += agent_sxf
                         db.session.add(agent_dao)
                 trade.sxf_detail = sxf_list
             trade.real_sxf = real_sxf
             if trade.sxf != trade.real_sxf:
                 m_limit = trade.sxf - trade.real_sxf
                 agentpayQuerylogger.info("手续费差值 : %s" % (m_limit))
                 self.__merchantDao.amount += m_limit
             db.session.add(trade)
         db.session.add(trade)
         db.session.add(trade_down)
         db.session.commit()
     except Exception as e:
         db.session.rollback()
         db.session.remove()
         agentpayQuerylogger.exception(e)
         agentpayQuerylogger.error("%s订单更新失败" % (trade.order_no))
Пример #7
0
	def calculation_amount(mer_code,amount):
		agentpayQuerylogger.info("计算手续费 . 代付商户 %s , 代付金额 %s "%(mer_code,amount))
		res = db.session.query(DfAgentRate.id.label('id'),
							DfAgentRate.agent_code.label('agent_code'),
							DfAgentRate.agent_name.label('agent_name'),
							DfAgentRate.mer_code.label('mer_code'),
							DfAgentRate.rate_prop.label('rate_prop'),
							DfAgentRate.rate_amount.label('rate_amount'),
							DfAgentRate.mer_username.label('mer_username')
							,MerchantDao.state).filter(MerchantDao.code == DfAgentRate.agent_code , MerchantDao.state == 1 ,DfAgentRate.mer_code == mer_code,).all()
		asm = db.session.query(func.sum(DfTradeDao.amount)).filter(and_(DfTradeDao.mer_code == mer_code,DfTradeDao.state == 2)).scalar()
		agentpayQuerylogger.info("商户当前总成交  :  %s"%(asm))
		if asm is None:
			asm = 0
		asm = asm + amount
		rs = {}
		rs_g = {}
		rs_name = {}
		res_r = []
		for i in res:
			yhjeDict = {}
			yhLists = []
			for args in i.rate_amount:
				yhLists.append(args)
			yhLists.sort(key=lambda x: float(x["ratelower"]))
			rs['%s' % i.agent_code] = yhLists
			rs_g['%s' % i.agent_code] = i.rate_prop
			rs_name['%s' % i.agent_code] = i.agent_name
			res_r.append(i.agent_code)
		sxf_sum = 0
		result = []
		for i in res_r:
			res_di = {}
			rate = rs[i]
			agent_name = rs_name[i]
			# rate_g = float('%.3f' % rs_g[i])
			rate_g = rs_g[i]
			sxf_on = 0
			# sxf_g = decimal.Decimal(str(res['rate_g']))
			sxf_g = amount * rate_g
			agentpayQuerylogger.info('代理%s的固定手续费%s' % (i, sxf_g))
			res_di['agents_code'] = i
			res_di['agents_name'] = agent_name
			res_di['sxf_g'] = str(formatDecimal_two(sxf_g))
			for j in rate:
				sxf = 0
				res_di['sxf'] = str(formatDecimal_two(sxf))
				if j['ratelower'] != '' and j['rateupper'] != '':
					if asm >= j['ratelower'] and asm < j['rateupper']:
						sxf += j['amount']
						res_di['sxf'] = str(formatDecimal_two(sxf))
						agentpayQuerylogger.info('代理%s的手续费%s' % (i, sxf))
						break
				elif not j['ratelower'] and j['rateupper'] != '':
					pass
				elif j['ratelower'] != '' and not j['rateupper']:
					if asm >= j['ratelower']:
						sxf += j['amount']
						res_di['sxf'] = str(formatDecimal_two(sxf))
						agentpayQuerylogger.info('代理%s的手续费%s' % (i, sxf))
						break
				else:
					sxf_on += sxf
			result.append(res_di)
			sxf = decimal.Decimal(str(sxf))
			sxf_sum += sxf + sxf_g
		agentpayQuerylogger.info('代付总手续费%s' % sxf_sum)
		return result
Пример #8
0
 def updateDetailByAdmin(self):
     audit_time = int(time.time())
     self.__merchantDao = getDataByCode(self.__args_up['mer_code'])
     if not self.__merchantDao:
         self.success = False
         self.error_msg = '账户号错误'
         self.error_code = 8101
         return
     self.__tradedataDao = DfTradeDao().get_data_state1_by_orderno(
         self.__merchantDao.code, self.__args_up['order_no'])
     m_size = len(self.__tradedataDao)
     if m_size != 1:
         self.success = False
         self.error_msg = '订单号错误'
         self.error_code = 8102
         agentpayQuerylogger.info("订单号错误 : %s" %
                                  (self.__args_up['order_no']))
         return
     trade = self.__tradedataDao[0]
     self.__merchantDao.dongjie_amount = self.__merchantDao.dongjie_amount - trade.amount - trade.sxf
     if self.__args_up['state'] == 3 and trade.state != 3:
         self.__merchantDao.amount = self.__merchantDao.amount + trade.amount + trade.sxf
     elif self.__args_up['state'] == 2 and trade.state == 1:
         agentpayQuerylogger.info("重新计算手续费")
         sxf_list = WOlinetrideService.calculation_amount(
             trade.mer_code, trade.amount)
         real_sxf = 0
         if len(sxf_list) > 0:
             for sxf in sxf_list:
                 agent_sxf = 0
                 if 'sxf_g' in sxf:
                     real_sxf += decimal.Decimal(sxf['sxf_g'])
                     agent_sxf += decimal.Decimal(sxf['sxf_g'])
                     self.insert_sxf_detail(sxf, 1, trade, audit_time)
                 if 'sxf' in sxf:
                     real_sxf += decimal.Decimal(sxf['sxf'])
                     agent_sxf += decimal.Decimal(sxf['sxf'])
                     self.insert_sxf_detail(sxf, 2, trade, audit_time)
                 if agent_sxf > 0:
                     agent_dao = getDataByCode(sxf['agents_code'])
                     agent_dao.amount += agent_sxf
                     db.session.add(agent_dao)
             trade.sxf_detail = sxf_list
         trade.real_sxf = real_sxf
         if trade.sxf != trade.real_sxf:
             m_limit = trade.sxf - trade.real_sxf
             agentpayQuerylogger.info("手续费差值 : %s" % (m_limit))
             self.__merchantDao.amount += m_limit
     else:
         self.success = False
         self.error_msg = '更新失败'
         self.error_code = 8199
         agentpayQuerylogger.error(
             "%s订单更新失败 , 从state %s 更新到 %s" %
             (trade.order_no, trade.state, self.__args_up['state']))
     trade.state = self.__args_up['state']
     trade.audit_time = audit_time
     db.session.add(trade)
     db.session.add(self.__merchantDao)
     try:
         db.session.commit()
     except Exception as e:
         db.session.rollback()
         db.session.remove()
         agentpayQuerylogger.exception(e)
         agentpayQuerylogger.error("%s订单更新失败" % (trade.order_no))
         self.success = False
         self.error_msg = '更新失败'
         self.error_code = 8199
Пример #9
0
    def queryDetail(self):
        try:
            self.__merchantDao = getDataByCode(self.__args_up['mer_code'])
            if not self.__merchantDao:
                self.success = False
                self.error_msg = '账户号错误'
                self.error_code = 8101
                return
            self.__tradedataDao = DfTradeDao().get_data_state1(
                self.__merchantDao.code, self.__args_up['org_order_no'])
            m_size = len(self.__tradedataDao)
            if m_size != 1:
                self.success = False
                self.error_msg = '订单号错误'
                self.error_code = 8102
                agentpayQuerylogger.info("订单号错误 : %s" %
                                         (self.__args_up['org_order_no']))
                return
            sign = self.__args_up.pop('sign')
            m_sign = self.credit_sign(self.__args_up,
                                      self.__merchantDao.secret_key)
            m_sign = self.get_sign(m_sign)
            if m_sign != sign:
                self.success = False
                self.error_msg = '签名不正确'
                self.error_code = 8103
                agentpayQuerylogger.info("签名不正确 .%s,%s" % (sign, m_sign))
                return
            audit_time = int(time.time())
            trade = self.__tradedataDao[0]
            m_result = {}
            m_result['mer_code'] = self.__args_up['mer_code']
            m_result['order_no'] = trade.order_no
            m_result['org_order_no'] = trade.org_order_no
            m_result['state'] = trade.state
            m_result['audit_time'] = trade.audit_time
            m_result['amount'] = str(keep_two_del(trade.amount))
            m_result['sxf'] = str(keep_two_del(trade.real_sxf))
            m_sign = self.credit_sign(m_result, self.__merchantDao.secret_key)
            m_sign = self.get_sign(m_sign)
            m_result['sign'] = m_sign
            return m_result
#             if trade.state == 1:
#                 self.____subdataDao = DfSubData().get_data()
#                 df_query_url =  self.____subdataDao.query_url
#                 df_query_skey =  self.____subdataDao.select_key
#                 df_quer_mcode =  self.____subdataDao.code
#                 agentpayQuerylogger.info("%s 订单号查询"%(trade.order_no))
#                 mdata = {}
#                 mdata['mchntCd'] = df_quer_mcode
#                 mdata['mchntPayforSsn'] = trade.order_no
#                 mstr = "mchntCd=%s&mchntPayforSsn=%s%s"%(df_quer_mcode,trade.order_no,df_query_skey)
#                 mdata['sign'] = self.get_sign(mstr)
#                 #代付交易查询
#                 agentpayQuerylogger.info("向下游发送查询请求")
#                 res_json = self.cash_post(mdata, df_query_url)
#                 res_sign = res_json.pop('sign')
#                 m_sign = self.credit_sign(res_json, df_query_skey)
#                 m_sign = self.get_sign(m_sign)
#                 if res_sign != m_sign:
#                     raise Exception('下游接口验签失败  :  res_sign = %s , m_sign = %s'%(res_sign,m_sign))
#                 #判断交易状态是否更新
#                 if int(res_json['paySt']) == trade.state or int(res_json['paySt'] == 0) :
#                     agentpayQuerylogger.error("%s订单状态没有改变,不需要更新"%(trade.order_no))
#                 else:
#                     agentpayQuerylogger.error("%s订单状态改变,进行更新"%(trade.order_no))
#                     self.insert_query_detail(res_json, trade, audit_time)
#                     self.update(res_json, trade, audit_time)
#             m_result = {}
#             m_result['mer_code'] = self.__args_up['mer_code']
#             m_result['order_no'] = trade.order_no
#             m_result['org_order_no'] = trade.org_order_no
#             m_result['state'] = trade.state
#             m_result['audit_time'] = trade.audit_time
#             m_result['amount'] = str(keep_two_del(trade.amount))
#             m_result['sxf'] = str(keep_two_del(trade.real_sxf))
#             m_sign = self.credit_sign(m_result, self.__merchantDao.secret_key)
#             m_sign = self.get_sign(m_sign)
#             m_result['sign'] = m_sign
#             return m_result
        except Exception as e:
            agentpayQuerylogger.exception(e)
            agentpayQuerylogger.error(format(e))
            self.success = False
            self.error_msg = '代付通道维护'
            self.error_code = 8199
            return