64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
|
|
class PricingType:
|
|
|
|
|
|
class PricingProgram
|
|
def __init__(self, ppid, sor):
|
|
self.ppid = ppid
|
|
self.sor = sor
|
|
|
|
async def init(self):
|
|
await self.get_program()
|
|
await self.get_pricing_type(self.ptid)
|
|
|
|
async def get_program():
|
|
recs = await self.sor.R('pricing_program', {'id': self.ppid})
|
|
if len(recs):
|
|
self.__dict__.update(recs[0])
|
|
|
|
async def get_pricing_type(self, ptid):
|
|
self.pricing_type = await self.sor.R('pricing_type',
|
|
{'id': ptid})
|
|
|
|
async def get_items(self):
|
|
recs = await self.sor.R('program_item', {'ppid': self.id})
|
|
return recs
|
|
|
|
async def get_spec(self, psid):
|
|
recs = await self.sor.R('program_spec', {'id', psid})
|
|
return recs
|
|
|
|
pricing_program_charging(sor, pricing_program_id, data):
|
|
pp = PricingProgram(pricing_program_id)
|
|
await pp.init()
|
|
pp_items = pp.get_items()
|
|
specs = pt.get_spec()
|
|
charges = []
|
|
for item in pp_items:
|
|
charge = item.copy()
|
|
spec = await pp.get_spec(item.psid)
|
|
d = data.get(spec.spec_name)
|
|
if d is None:
|
|
continue
|
|
cnt = data.get(spec.count_name, 1)
|
|
if spec.pricing_spec_mode == 'spec_name':
|
|
if d == item.spec_value:
|
|
charge.amount = item.pricing_amount * cnt
|
|
charges.append(charge)
|
|
elif spec.pricing_spec_mode == 'spec_amount':
|
|
if charge.pricing_unit is None or charge.pricing_unit < 1:
|
|
charge.pricing_unit = 1
|
|
charge.amount = d * charge_amount / charge.pricing_unit
|
|
charges.append(charge)
|
|
elif spec.pricing_spec_mode == 'remote_pricing':
|
|
charge.amount = await get_remote_pricing(charge.uappid,
|
|
charge.apiname, params=d)
|
|
charges.append(charge)
|
|
elif spec.pricing_spec_mode == 'sub_pricing':
|
|
sub_charges = await pricing_program_chargeing(self.sor,
|
|
charge.subppid, d)
|
|
charges += sub_charges
|
|
|
|
return charges
|
|
|