diff --git a/models/pricing_item.xlsx b/models/pricing_item.xlsx new file mode 100644 index 0000000..b9942ed Binary files /dev/null and b/models/pricing_item.xlsx differ diff --git a/models/pricing_program.xlsx b/models/pricing_program.xlsx new file mode 100644 index 0000000..640797c Binary files /dev/null and b/models/pricing_program.xlsx differ diff --git a/models/pricing_spec.xlsx b/models/pricing_spec.xlsx new file mode 100644 index 0000000..7cf502d Binary files /dev/null and b/models/pricing_spec.xlsx differ diff --git a/models/pricing_type.xlsx b/models/pricing_type.xlsx new file mode 100644 index 0000000..b1bbf4e Binary files /dev/null and b/models/pricing_type.xlsx differ diff --git a/pricing/__init__.py b/pricing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pricing/init.py b/pricing/init.py new file mode 100644 index 0000000..e69de29 diff --git a/pricing/pricing.py b/pricing/pricing.py new file mode 100644 index 0000000..27b2f86 --- /dev/null +++ b/pricing/pricing.py @@ -0,0 +1,63 @@ + +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 + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..59514a1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[build-system] +requires = ["setuptools>=61", "wheel"] +build-backend = "setuptools.build_meta" + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..59ae3c6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[metadata] +name=pricing +version = 0.0.1 +description = A pricing module for online store +author = "yu moqing" +author_email = "yumoqing@gmail.com" +readme = "README.md" +license = "MIT" +[options] +packages = find: +requires_python = ">=3.8" +install_requires = + apppublic + ahserver + sqlor