@certd/commercial-core 1.40.4 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/d/controller/sys/index.d.ts +4 -0
- package/dist/d/controller/sys/invite/invite-controller.d.ts +44 -0
- package/dist/d/controller/sys/invite/invite-level-controller.d.ts +31 -0
- package/dist/d/controller/sys/suite/product-activation-code-controller.d.ts +43 -0
- package/dist/d/controller/sys/suite/trade-controller.d.ts +8 -2
- package/dist/d/controller/sys/wallet/wallet-controller.d.ts +32 -0
- package/dist/d/controller/user/index.d.ts +3 -0
- package/dist/d/controller/user/invite/invite-controller.d.ts +57 -0
- package/dist/d/controller/user/suite/product-activation-code-controller.d.ts +13 -0
- package/dist/d/controller/user/suite/trade-controller.d.ts +6 -9
- package/dist/d/controller/user/wallet/wallet-controller.d.ts +47 -0
- package/dist/d/index.d.ts +2 -2
- package/dist/d/modules/index.d.ts +2 -0
- package/dist/d/modules/invite/entity/index.d.ts +5 -0
- package/dist/d/modules/invite/entity/invite-code.d.ts +8 -0
- package/dist/d/modules/invite/entity/invite-commission-log.d.ts +13 -0
- package/dist/d/modules/invite/entity/invite-level.d.ts +12 -0
- package/dist/d/modules/invite/entity/invite-relation.d.ts +8 -0
- package/dist/d/modules/invite/entity/invite-user-plan.d.ts +11 -0
- package/dist/d/modules/invite/index.d.ts +3 -0
- package/dist/d/modules/invite/service/index.d.ts +2 -0
- package/dist/d/modules/invite/service/invite-level-service.d.ts +12 -0
- package/dist/d/modules/invite/service/invite-service.d.ts +136 -0
- package/dist/d/modules/invite/settings.d.ts +10 -0
- package/dist/d/modules/suite/entity/index.d.ts +1 -0
- package/dist/d/modules/suite/entity/product-activation-code.d.ts +18 -0
- package/dist/d/modules/suite/entity/trade.d.ts +2 -0
- package/dist/d/modules/suite/entity/user-suite.d.ts +1 -0
- package/dist/d/modules/suite/service/index.d.ts +1 -0
- package/dist/d/modules/suite/service/product-activation-code-service.d.ts +78 -0
- package/dist/d/modules/suite/service/trade-service.d.ts +8 -0
- package/dist/d/modules/suite/service/user-suite-service.d.ts +4 -4
- package/dist/d/modules/wallet/entity/index.d.ts +3 -0
- package/dist/d/modules/wallet/entity/user-wallet-log.d.ts +13 -0
- package/dist/d/modules/wallet/entity/user-wallet-withdraw.d.ts +18 -0
- package/dist/d/modules/wallet/entity/user-wallet.d.ts +12 -0
- package/dist/d/modules/wallet/index.d.ts +3 -0
- package/dist/d/modules/wallet/service/index.d.ts +1 -0
- package/dist/d/modules/wallet/service/wallet-service.d.ts +114 -0
- package/dist/d/modules/wallet/settings.d.ts +19 -0
- package/dist/index.js +1 -1
- package/package.json +6 -6
- package/logs/app.log +0 -0
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PrimaryGeneratedColumn as e,Column as t,Entity as i,Repository as s,Or as r,Equal as n,MoreThan as o,LessThan as a,In as d}from"typeorm";import{Provide as p,Scope as u,ScopeEnum as y,Inject as c,Logger as m,Configuration as g,Post as l,Body as S,ALL as v,Controller as h,Query as w,Get as f,Param as b}from"@midwayjs/core";import{InjectEntityModel as I}from"@midwayjs/typeorm";import{BaseService as P,ValidateException as T,SysSuiteSetting as x,NeedSuiteException as C,SysSettingsService as N,SysInstallInfo as O,SysPaymentSetting as D,AccessService as F,BaseController as E,SysHeaderMenus as k,SysSiteInfo as B,FileService as _,CrudController as U,Constants as j}from"@certd/lib-server";import M from"dayjs";import{utils as R,logger as $}from"@certd/basic";import{isComm as A,checkComm as q}from"@certd/plus-core";import*as L from"lodash-es";import{merge as G,remove as W}from"lodash-es";import{ApiTags as V}from"@midwayjs/swagger";function J(e,t,i,s){var r,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(n<3?r(o):n>3?r(t,i,o):r(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o}function Y(e,t){return function(i,s){t(i,s,e)}}function z(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;let H=class{id;userId;productId;tradeNo;duration;title;desc;num;price;amount;remark;status;payType;payTime;payNo;endTime;createTime;updateTime};var Q;J([e(),z("design:type",Number)],H.prototype,"id",void 0),J([t({name:"user_id",comment:"用户id"}),z("design:type",Number)],H.prototype,"userId",void 0),J([t({name:"product_id",comment:"商品Id"}),z("design:type",Number)],H.prototype,"productId",void 0),J([t({name:"trade_no",comment:"交易号"}),z("design:type",String)],H.prototype,"tradeNo",void 0),J([t({name:"duration",comment:"时长"}),z("design:type",Number)],H.prototype,"duration",void 0),J([t({name:"title",comment:"商品名称"}),z("design:type",String)],H.prototype,"title",void 0),J([t({name:"desc",comment:"商品描述"}),z("design:type",String)],H.prototype,"desc",void 0),J([t({name:"num",comment:"商品数量"}),z("design:type",Number)],H.prototype,"num",void 0),J([t({name:"price",comment:"单价"}),z("design:type",Number)],H.prototype,"price",void 0),J([t({name:"amount",comment:"总价"}),z("design:type",Number)],H.prototype,"amount",void 0),J([t({name:"remark",comment:"备注"}),z("design:type",String)],H.prototype,"remark",void 0),J([t({name:"status",comment:"状态"}),z("design:type",String)],H.prototype,"status",void 0),J([t({name:"pay_type",comment:"支付类型"}),z("design:type",String)],H.prototype,"payType",void 0),J([t({name:"pay_time",comment:"支付时间"}),z("design:type",Number)],H.prototype,"payTime",void 0),J([t({name:"pay_no",comment:"支付单号"}),z("design:type",String)],H.prototype,"payNo",void 0),J([t({name:"end_time",comment:"结束时间"}),z("design:type",Number)],H.prototype,"endTime",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),z("design:type",Date)],H.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),z("design:type",Date)],H.prototype,"updateTime",void 0),H=J([i("cd_trade")],H);let K=Q=class{id;icon;title;type;content;durationPrices;duration;price;intro;order;supportBuy;disabled;createTime;updateTime;static getSuiteContent(e){return JSON.parse(e.content||"{}")}static setSuiteContent(e,t){e.content=JSON.stringify(t||{})}static getDurationPrices(e){return JSON.parse(e.durationPrices||"[]")}static setDurationPrices(e,t){if(0===t.length)throw new Error("prices must not be empty");e.duration=t[0].duration,e.price=t[0].price,e.durationPrices=JSON.stringify(t)}static getContentStr(e){let t="";const i=Q.getSuiteContent(e);return-1===i.maxDomainCount?t+="域名无限制;":t+=`域名${i.maxDomainCount}个;`,-1===i.maxWildcardDomainCount?t+="泛域名无限制;":t+=`泛域名${i.maxWildcardDomainCount}个;`,-1===i.maxPipelineCount?t+="流水线无限制;":t+=`流水线${i.maxPipelineCount}个;`,-1===i.maxDeployCount?t+="部署次数无限制;":t+=`部署${i.maxDeployCount}次;`,t}};J([e(),z("design:type",Number)],K.prototype,"id",void 0),J([t({name:"icon",comment:"图标"}),z("design:type",String)],K.prototype,"icon",void 0),J([t({name:"title",comment:"套餐名称"}),z("design:type",String)],K.prototype,"title",void 0),J([t({name:"type",comment:"套餐类型,套餐/加量包,suite/addon"}),z("design:type",String)],K.prototype,"type",void 0),J([t({name:"content",comment:"套餐内容"}),z("design:type",String)],K.prototype,"content",void 0),J([t({name:"duration_prices",comment:"时长及单价"}),z("design:type",String)],K.prototype,"durationPrices",void 0),J([t({name:"duration",comment:"时长"}),z("design:type",Number)],K.prototype,"duration",void 0),J([t({name:"price",comment:"单价"}),z("design:type",Number)],K.prototype,"price",void 0),J([t({name:"intro",comment:"说明"}),z("design:type",String)],K.prototype,"intro",void 0),J([t({name:"order",comment:"排序"}),z("design:type",Number)],K.prototype,"order",void 0),J([t({name:"support_buy",comment:"是否支持购买",default:!0}),z("design:type",Boolean)],K.prototype,"supportBuy",void 0),J([t({name:"disabled",comment:"禁用启用"}),z("design:type",Boolean)],K.prototype,"disabled",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),z("design:type",Date)],K.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),z("design:type",Date)],K.prototype,"updateTime",void 0),K=Q=J([i("cd_product")],K);let X=class{id;userId;productId;tradeId;icon;title;productType;content;duration;deployCountUsed;activeTime;expiresTime;disabled;isPresent;isBootstrap;isEmpty;createTime;updateTime;static getContent(e){return JSON.parse(e.content||"{}")}};J([e(),z("design:type",Number)],X.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),z("design:type",Number)],X.prototype,"userId",void 0),J([t({name:"product_id",comment:"套餐ID"}),z("design:type",Number)],X.prototype,"productId",void 0),J([t({name:"trade_id",comment:"订单id"}),z("design:type",Number)],X.prototype,"tradeId",void 0),J([t({name:"icon",comment:"图标"}),z("design:type",String)],X.prototype,"icon",void 0),J([t({name:"title",comment:"套餐名称"}),z("design:type",String)],X.prototype,"title",void 0),J([t({name:"product_type",comment:"套餐类型,套餐/加量包,suite/addon"}),z("design:type",String)],X.prototype,"productType",void 0),J([t({name:"content",comment:"套餐内容"}),z("design:type",String)],X.prototype,"content",void 0),J([t({name:"duration",comment:"有效时长"}),z("design:type",Number)],X.prototype,"duration",void 0),J([t({name:"deploy_count_used",comment:"已使用部署次数"}),z("design:type",Number)],X.prototype,"deployCountUsed",void 0),J([t({name:"active_time",comment:"激活时间"}),z("design:type",Number)],X.prototype,"activeTime",void 0),J([t({name:"expires_time",comment:"有效期"}),z("design:type",Number)],X.prototype,"expiresTime",void 0),J([t({name:"disabled",comment:"启用/禁用",default:!1}),z("design:type",Boolean)],X.prototype,"disabled",void 0),J([t({name:"is_present",comment:"是否赠送",default:!1}),z("design:type",Boolean)],X.prototype,"isPresent",void 0),J([t({name:"is_bootstrap",comment:"是否初始套餐",default:!1}),z("design:type",Boolean)],X.prototype,"isBootstrap",void 0),J([t({name:"is_empty",comment:"是否用完",default:!1}),z("design:type",Boolean)],X.prototype,"isEmpty",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),z("design:type",Date)],X.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),z("design:type",Date)],X.prototype,"updateTime",void 0),X=J([i("cd_user_suite")],X);let Z=class extends P{repository;getRepository(){return this.repository}async add(e){return this.checkSuiteContent(e),await super.add(e)}async update(e){return this.checkSuiteContent(e),await super.update(e)}checkSuiteContent(e){const t=this.parseContent(e.content);if(t&&-1!==t.maxDomainCount&&-1===t.maxWildcardDomainCount)throw new T("域名总数量有限制时,其中泛域名数量不能设置为无限制")}parseContent(e){return null==e?null:"string"==typeof e?JSON.parse(e||"{}"):e}};J([I(K),z("design:type",s)],Z.prototype,"repository",void 0),Z=J([p(),u(y.Request,{allowDowngrade:!0})],Z);class ee{registry={};async createByPaymentType(e,t){return new(await this.getProviderCls(e))(t)}async getProviderCls(e){const t=this.registry[e];if(!t)throw new Error("不支持的支付方式:"+e);return await t()}async getDefine(e){return(await this.getProviderCls(e)).getDefine()}registerProvider(e,t){this.registry[e]=t}}const te=new ee;let ie=class extends P{repository;myCountService;sysSettingsService;productService;getRepository(){return this.repository}async presentGiftSuite(e){if(null==e)return!1;if(!A())return!1;const t=await this.getSuiteSetting();return!!t&&(!!t.enabled&&(!!t.registerGift?.productId&&await R.locker.execute(`presentGiftSuite:${e}`,async()=>{if(await this.getRepository().count({where:{userId:e,isPresent:!0}})>0)return!1;const i=await this.productService.info(t.registerGift.productId);return!!i&&($.info(`注册赠送套餐:userId=${e},suite=${i.title}`),await this.productToUserSuite({userId:e,product:i,duration:t.registerGift.duration,isPresent:!0,isBootstrap:!0}),!0)})))}async productToUserSuite(e){const{duration:t,userId:i,product:s,tradeId:r,entityManager:n}=e,o=M(),a=o.valueOf();let d=0;d=-1===t?-1:o.add(t,"day").endOf("day").valueOf();const p=new X;p.userId=i,p.productId=s.id,p.tradeId=r||0,p.icon="",p.title=s.title,p.productType=s.type,p.content=s.content,p.duration=t,p.deployCountUsed=0,p.disabled=!1,p.activeTime=a,p.expiresTime=d,p.isPresent=e.isPresent||!1,p.isBootstrap=e.isBootstrap||!1,p.isEmpty=!1,n?await n.save(p):await this.getRepository().save(p)}async getMySuiteDetail(e){const t=await this.sysSettingsService.getSetting(x);let i=await this.getMyValidSuiteList(e);if(!i||0===i.length){await this.presentGiftSuite(e)&&(i=await this.getMyValidSuiteList(e))}i&&0!==i.length||(i=[]);const s={max:0,used:0},r={max:0,used:0},n={max:0,used:0},o={max:0,used:0},a={max:0,used:0},d=[];if(i.length>0)for(const e of i){d.push({id:e.id,productId:e.productId,duration:e.duration,title:e.title,expiresTime:e.expiresTime,productType:e.productType});const t=X.getContent(e);-1==s.max||-1==t.maxPipelineCount?s.max=-1:s.max+=t.maxPipelineCount??0,-1==r.max||-1==t.maxDomainCount?r.max=-1:r.max+=t.maxDomainCount??0,-1==n.max||-1==t.maxWildcardDomainCount?n.max=-1:n.max+=t.maxWildcardDomainCount??0,-1==o.max||-1==t.maxDeployCount?o.max=-1:o.max+=t.maxDeployCount??0,-1==a.max||-1==t.maxMonitorCount?a.max=-1:a.max+=t.maxMonitorCount??0,o.used+=e.deployCountUsed??0}const{pipelineCountUsed:p,domainCountUsed:u,wildcardDomainCountUsed:y,monitorCountUsed:c}=await this.myCountService.getUsedCount(e);return s.used=p??0,r.used=u??0,n.used=y??0,a.used=c??0,{enabled:t.enabled,suites:d,expiresTime:0,pipelineCount:s,domainCount:r,wildcardDomainCount:n,deployCount:o,monitorCount:a}}async getMyValidSuiteList(e){if(null==e)throw new Error("用户ID不能为空");const t=M();return[...(await this.getSuiteSetting()).allowSuiteStack?await this.getMyValidSuites(e,t):await this.getMyLatestValidSuiteList(e,t),...await this.getMyValidAddons(e,t)]}async getMyLatestValidSuiteList(e,t){const i=await this.getRepository().findOne({where:{userId:e,expiresTime:r(n(-1),o(t.valueOf())),activeTime:a(t.valueOf()),disabled:!1,productType:"suite"},order:{id:"DESC"}});return i?[i]:[]}async getMyValidSuites(e,t){return await this.getRepository().find({where:{userId:e,expiresTime:r(n(-1),o(t.valueOf())),activeTime:a(t.valueOf()),disabled:!1,productType:"suite"},order:{expiresTime:"ASC",id:"ASC"}})}async getMyValidAddons(e,t){return await this.getRepository().find({where:{userId:e,expiresTime:r(n(-1),o(t.valueOf())),activeTime:a(t.valueOf()),disabled:!1,productType:"addon",isEmpty:!1},order:{expiresTime:"ASC",id:"ASC"}})}async checkHasDeployCount(e,t=1){t<=0&&(t=1);if(!(await this.getSuiteSetting()).enabled)return null;const i=await this.getMyValidSuiteList(e);i.sort((e,t)=>e.expiresTime-t.expiresTime);for(const e of i){const i=X.getContent(e);if(-1==i.maxDeployCount||i.maxDeployCount>=e.deployCountUsed+t)return e}throw new C("部署次数不足,请购买加量包或升级套餐")}async consumeDeployCount(e,t){if(null==e)return;e.deployCountUsed+=t;const i=X.getContent(e);if(-1!=i.maxDeployCount&&e.deployCountUsed>=i.maxDeployCount){this.isOnlyDeployCount(i)&&(e.isEmpty=!0)}const s={deployCountUsed:()=>`deployCountUsed + ${t}`};e.isEmpty&&(s.isEmpty=!0),await this.repository.createQueryBuilder().update(X).set(s).where("id = :suiteId",{suiteId:e.id}).execute()}checkHasInfinite(e){const t=Object.keys(e);for(const i of t)if(i.startsWith("max")&&-1==e[i])return!0;return!1}getSuiteSetting(){return this.sysSettingsService.getSetting(x)}isOnlyDeployCount(e){const t=Object.keys(e);for(const i of t)if(i.startsWith("max")&&"maxDeployCount"!=i&&0!=e[i])return!1;return-1!==e.maxDeployCount}async presentSuite(e){q();if(!(await this.getSuiteSetting()).enabled)throw new Error("套餐功能未开启");const t=await this.productService.info(e.productId);if(!t)throw new Error("产品不存在");const i=K.getDurationPrices(t).find(t=>t.duration===e.duration);if(!i)throw new Error("套餐时长不存在");await this.productToUserSuite({userId:e.userId,product:t,duration:i.duration,isPresent:!0})}};J([I(X),z("design:type",s)],ie.prototype,"repository",void 0),J([c("myCountService"),z("design:type",Object)],ie.prototype,"myCountService",void 0),J([c(),z("design:type",N)],ie.prototype,"sysSettingsService",void 0),J([c(),z("design:type",Z)],ie.prototype,"productService",void 0),ie=J([p("userSuiteService"),u(y.Request,{allowDowngrade:!0})],ie);let se=class extends P{repository;productService;sysSettingsService;accessService;userSuiteService;getRepository(){return this.repository}async createFree(e){const t=await this.getBuyableProduct(e.productId),{price:i}=this.findDurationPrice(t,e.duration);if(0!==i)throw new Error("产品价格不为0");const s=await this.create({productId:e.productId,duration:e.duration,num:e.num,payType:e.payType,userId:e.userId});await this.onPaid({tradeNo:s.tradeNo,status:"paid",amount:0,payNo:"free",remark:"免费赠送",payTime:M().valueOf()})}findDurationPrice(e,t){const i=JSON.parse(e.durationPrices||"[]").find(e=>e.duration===t);if(!i)throw new Error(`产品时长${t}不存在`);return i}async create(e){const t=await this.getBuyableProduct(e.productId),{price:i}=this.findDurationPrice(t,e.duration),s=M(),r="T"+s.format("YYYYMMDD")+s.unix()+R.id.randomNumber(6),n=`购买${t.title} ${e.duration}天`,o=`内含:${K.getContentStr(t)}`,a=new H;return a.title=n,a.desc=o,a.productId=e.productId,a.duration=e.duration,a.num=e.num,a.userId=e.userId,a.tradeNo=r,a.duration=e.duration,a.price=i,a.title=t.title,a.amount=a.price*a.num,a.status="wait_pay",a.payType=e.payType,await this.repository.save(a)}async getBuyableProduct(e){const t=await this.productService.info(e);if(!t)throw new Error("产品不存在");if(t.disabled)throw new Error("该产品已下架");if(!t.supportBuy)throw new Error("该产品不支持购买");return t}async buildPaymentReq(e,t){const i=await this.sysSettingsService.getSetting(O);let s=i?.bindUrl;if(!s)throw new Error("未绑定URL");s.endsWith("/")&&(s=s.slice(0,-1));const r=await this.getPaymentByType(e.payType);return await r.createOrder(e,{bindUrl:s,clientIp:t})}async getPaymentByType(e){const t=(await this.sysSettingsService.getSetting(D))[e];if(!t||!t.enabled)throw new Error(`支付方式${e}未启用`);const i=await this.accessService.getById(t.accessId,0);if(!i)throw new Error(`支付方式${e}未设置授权`);return await te.createByPaymentType(e,i)}async getByTradeNo(e){if(!e)throw new Error("out_trade_no不能为空");return await this.repository.findOne({where:{tradeNo:e}})}async onPaid(e){const t=await this.getByTradeNo(e.tradeNo);if(!t)throw new Error(`订单${e.tradeNo}不存在`);if("paid"!==t.status){if("wait_pay"!==t.status)throw new Error(`订单${e.tradeNo}状态不正确, 当前状态为${t.status}`);if(t.amount!==e.amount)throw new Error(`订单${e.tradeNo}金额不正确, 当前金额为${t.amount},实际支付金额为${e.amount}`);await this.transaction(async i=>{await i.update(H,{id:t.id},{status:"paid",amount:e.amount,remark:e.remark,payNo:e.payNo,payTime:e.payTime||M().valueOf()});const s=await this.productService.info(t.productId);if(!s)throw new Error("产品不存在");const r=t.id,n=t.userId,o=t.duration;await this.userSuiteService.productToUserSuite({duration:o,userId:n,product:s,tradeId:r,entityManager:i})})}}async syncStatus(e){const t=await this.info(e);if(!t)throw new Error("订单不存在");if("paid"===t.status)return;const i=await this.getPaymentByType(t.payType),s=await i.getDetail(t.tradeNo);if(!s)throw new Error("订单不存在");"paid"===s.status?await this.onPaid(s):"closed"===s.status&&await this.transaction(async e=>{await e.update(H,{id:t.id},{status:"closed",remark:s.remark})})}async updatePaid(e,t){const i=await this.info(e);if(!i)throw new Error("订单不存在");"paid"!==i.status&&await this.onPaid({tradeNo:i.tradeNo,status:"paid",amount:i.amount,payNo:"",remark:`手动确认支付:${t}`,payTime:M().valueOf()})}};J([I(H),z("design:type",s)],se.prototype,"repository",void 0),J([c(),z("design:type",Z)],se.prototype,"productService",void 0),J([c(),z("design:type",N)],se.prototype,"sysSettingsService",void 0),J([c(),z("design:type",F)],se.prototype,"accessService",void 0),J([c(),z("design:type",ie)],se.prototype,"userSuiteService",void 0),se=J([p(),u(y.Request,{allowDowngrade:!0})],se);let re=class{logger;async onReady(e){this.logger.info("commercial start")}};J([m(),z("design:type",Object)],re.prototype,"logger",void 0),re=J([g({namespace:"commercial"})],re);let ne=class extends E{sysSettingsService;async paymentGet(){const e=await this.sysSettingsService.getSetting(D);return this.ok(e)}async paymentSave(e){q();const t=new D;return G(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}async suiteGet(){const e=await this.sysSettingsService.getSetting(x);return this.ok(e)}async suiteSave(e){q();const t=new x;return G(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}async headerMenusGet(){const e=await this.sysSettingsService.getSetting(k);return this.ok(e)}async headerMenusSave(e){q();const t=new k;return G(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}};J([c(),z("design:type",N)],ne.prototype,"sysSettingsService",void 0),J([l("/payment/get",{description:"sys:settings:view"}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],ne.prototype,"paymentGet",null),J([l("/payment/save",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ne.prototype,"paymentSave",null),J([l("/suite/get",{description:"sys:settings:view"}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],ne.prototype,"suiteGet",null),J([l("/suite/save",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ne.prototype,"suiteSave",null),J([l("/headerMenus/get",{description:"sys:settings:view"}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],ne.prototype,"headerMenusGet",null),J([l("/headerMenus/save",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ne.prototype,"headerMenusSave",null),ne=J([p(),h("/api/sys/settings")],ne);let oe=class extends E{sysSettingsService;fileService;async saveSiteInfo(e){q();let t=await this.sysSettingsService.getSetting(B);return null==t&&(t=new B),L.merge(t,e),t.logo&&(t.logo=await this.fileService.saveFile(this.getUserId(),t.logo,"public")),t.loginLogo&&(t.loginLogo=await this.fileService.saveFile(this.getUserId(),t.loginLogo,"public")),await this.sysSettingsService.saveSetting(t),this.ok(t)}async getSiteInfo(){q();const e=await this.sysSettingsService.getSetting(B);return this.ok(e)}};J([c(),z("design:type",N)],oe.prototype,"sysSettingsService",void 0),J([c(),z("design:type",_)],oe.prototype,"fileService",void 0),J([l("/save",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],oe.prototype,"saveSiteInfo",null),J([l("/get",{description:"sys:settings:view"}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],oe.prototype,"getSiteInfo",null),oe=J([p(),h("/api/sys/site")],oe);let ae=class extends U{service;getService(){return q(),this.service}async page(e){return await super.page(e)}async list(e){return await super.list(e)}async add(e){return await super.add(e)}async update(e){return await super.update(e)}async info(e){return await super.info(e)}async delete(e){return await super.delete(e)}async syncStatus(e){return await this.service.syncStatus(e),this.ok()}async updatePaid(e){const t=await this.getLoginUser();return await this.service.updatePaid(e,t.id+"_"+t.username),this.ok()}async deleteByIds(e){const t=await this.getUserId();if(!e||0===e.length)throw new Error("ids不能为空");return await this.service.deleteWhere({id:e,userId:t}),this.ok()}};J([c(),z("design:type",se)],ae.prototype,"service",void 0),J([l("/page",{description:"sys:settings:view"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ae.prototype,"page",null),J([l("/list",{description:"sys:settings:view"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ae.prototype,"list",null),J([l("/add",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ae.prototype,"add",null),J([l("/update",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ae.prototype,"update",null),J([l("/info",{description:"sys:settings:view"}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],ae.prototype,"info",null),J([l("/delete",{description:"sys:settings:edit"}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],ae.prototype,"delete",null),J([l("/syncStatus",{description:"sys:settings:edit"}),Y(0,S("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],ae.prototype,"syncStatus",null),J([l("/updatePaid",{description:"sys:settings:edit"}),Y(0,S("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],ae.prototype,"updatePaid",null),J([l("/deleteByIds",{description:"sys:settings:edit"}),Y(0,S("ids")),z("design:type",Function),z("design:paramtypes",[Array]),z("design:returntype",Promise)],ae.prototype,"deleteByIds",null),ae=J([p(),h("/api/sys/suite/trade"),V(["sys-trade"])],ae);let de=class extends U{service;getService(){return q(),this.service}async page(e){return await super.page(e)}async list(e){return await super.list(e)}async add(e){return await super.add(e)}async update(e){return await super.update(e)}async info(e){return await super.info(e)}async delete(e){return await super.delete(e)}async deleteByIds(e){return await super.deleteByIds(e)}};J([c(),z("design:type",Z)],de.prototype,"service",void 0),J([l("/page",{description:"sys:settings:view"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],de.prototype,"page",null),J([l("/list",{description:"sys:settings:view"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],de.prototype,"list",null),J([l("/add",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],de.prototype,"add",null),J([l("/update",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],de.prototype,"update",null),J([l("/info",{description:"sys:settings:view"}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],de.prototype,"info",null),J([l("/delete",{description:"sys:settings:edit"}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],de.prototype,"delete",null),J([l("/deleteByIds",{description:"sys:settings:edit"}),Y(0,S("ids")),z("design:type",Function),z("design:paramtypes",[Array]),z("design:returntype",Promise)],de.prototype,"deleteByIds",null),de=J([p(),h("/api/sys/suite/product"),V(["sys-product"])],de);let pe=class extends U{getService(){return this.userSuiteService}productService;userSuiteService;sysSettingsService;async page(e){return q(),await super.page(e)}async list(e){return await super.list(e)}async add(e){return q(),await super.add(e)}async update(e){return await super.update(e)}async info(e){return await super.info(e)}async delete(e){return await super.delete(e)}async deleteByIds(e){return await super.deleteByIds(e)}async presentSuite(e){return await this.userSuiteService.presentSuite({userId:e.userId,productId:e.productId,duration:e.duration}),this.ok()}};J([c(),z("design:type",Z)],pe.prototype,"productService",void 0),J([c(),z("design:type",ie)],pe.prototype,"userSuiteService",void 0),J([c(),z("design:type",N)],pe.prototype,"sysSettingsService",void 0),J([l("/page",{description:"sys:settings:view"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],pe.prototype,"page",null),J([l("/list",{description:"sys:settings:view"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],pe.prototype,"list",null),J([l("/add",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],pe.prototype,"add",null),J([l("/update",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],pe.prototype,"update",null),J([l("/info",{description:"sys:settings:view"}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],pe.prototype,"info",null),J([l("/delete",{description:"sys:settings:edit"}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],pe.prototype,"delete",null),J([l("/deleteByIds",{description:"sys:settings:edit"}),Y(0,S("ids")),z("design:type",Function),z("design:paramtypes",[Array]),z("design:returntype",Promise)],pe.prototype,"deleteByIds",null),J([l("/presentSuite",{description:"sys:settings:edit"}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],pe.prototype,"presentSuite",null),pe=J([p(),h("/api/sys/suite/user-suite"),V(["sys-user-suite"])],pe);let ue=class extends E{productService;async list(){q();const e=await this.productService.list({query:{disabled:!1,supportBuy:!0},sort:{prop:"order",asc:!0}});for(const t of e)t.durationPrices=JSON.parse(t.durationPrices||"[]"),t.content=JSON.parse(t.content||"{}");return W(e,e=>!0===e.isBootstrap),this.ok(e)}};J([c(),z("design:type",Z)],ue.prototype,"productService",void 0),J([l("/list",{description:j.per.authOnly}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],ue.prototype,"list",null),ue=J([p(),h("/api/suite/product"),V(["suite"])],ue);let ye=class extends E{productService;tradeService;sysSettingsService;async create(e){q();const{productId:t,duration:i,num:s,payType:r}=e,n=await this.tradeService.create({productId:t,duration:i,num:s,payType:r,userId:this.getUserId()}),o=this.ctx.request.ip,a=await this.tradeService.buildPaymentReq(n,o);return this.ok(a)}async createFree(e){q();const{productId:t,duration:i,num:s}=e,r=await this.tradeService.createFree({productId:t,duration:i,num:s,payType:"free",userId:this.getUserId()});return this.ok(r)}async info(e){const t=await this.tradeService.info(e.tradeId);return this.ok(t)}async page(e){e.query=e.query||{};e.query.userId=this.getUserId();const t=await this.tradeService.page(e);return this.ok(t)}async payments(){const e=await this.sysSettingsService.getSetting(D),t=[];return e.yizhifu&&e.yizhifu.enabled&&t.push({value:"yizhifu",label:"易支付",icon:"material-symbols:shield-outline"}),e.alipay&&e.alipay.enabled&&t.push({value:"alipay",label:"支付宝",icon:"ant-design:alipay-circle-filled"}),e.wxpay&&e.wxpay.enabled&&t.push({value:"wxpay",label:"微信",icon:"ant-design:wechat-filled"}),this.ok(t)}async syncStatus(e){const t=await this.tradeService.info(e);return t?t.userId!=this.getUserId()?this.fail("无权操作该交易订单"):("paid"===t.status||await this.tradeService.syncStatus(e),this.ok()):this.fail("交易订单不存在")}async delete(e){const t=this.getUserId();if(!e)throw new Error("id不能为空");return await this.tradeService.deleteWhere({id:e,userId:t}),this.ok()}async deleteByIds(e){const t=this.getUserId();if(!e||0===e.length)throw new Error("id不能为空");return await this.tradeService.deleteWhere({id:d(e),userId:t}),this.ok()}};J([c(),z("design:type",Z)],ye.prototype,"productService",void 0),J([c(),z("design:type",se)],ye.prototype,"tradeService",void 0),J([c(),z("design:type",N)],ye.prototype,"sysSettingsService",void 0),J([l("/create",{description:j.per.authOnly}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ye.prototype,"create",null),J([l("/createFree",{description:j.per.authOnly}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ye.prototype,"createFree",null),J([l("/info",{description:j.per.authOnly}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ye.prototype,"info",null),J([l("/page",{description:j.per.authOnly}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],ye.prototype,"page",null),J([l("/payments",{description:j.per.authOnly}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],ye.prototype,"payments",null),J([l("/syncStatus",{description:j.per.authOnly}),Y(0,S("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],ye.prototype,"syncStatus",null),J([l("/delete",{description:j.per.authOnly}),Y(0,w("id")),z("design:type",Function),z("design:paramtypes",[Number]),z("design:returntype",Promise)],ye.prototype,"delete",null),J([l("/deleteByIds",{description:j.per.authOnly}),Y(0,S("ids")),z("design:type",Function),z("design:paramtypes",[Array]),z("design:returntype",Promise)],ye.prototype,"deleteByIds",null),ye=J([p(),h("/api/suite/trade"),V(["suite"])],ye);let ce=class extends E{sysSettingsService;async get(){const e=await this.sysSettingsService.getSetting(x);return this.ok({intro:e.intro,allowSuiteStack:e.allowSuiteStack})}};J([c(),z("design:type",N)],ce.prototype,"sysSettingsService",void 0),J([l("/get",{description:j.per.authOnly}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],ce.prototype,"get",null),ce=J([p(),h("/api/suite/settings"),V(["suite"])],ce);let me=class extends E{productService;userSuiteService;sysSettingsService;async detail(){const e=await this.userSuiteService.getMySuiteDetail(this.getUserId());return this.ok(e)}async page(e){q(),e.query=e.query||{};e.query.userId=this.getUserId();const t=await this.userSuiteService.page(e);return this.ok(t)}};J([c(),z("design:type",Z)],me.prototype,"productService",void 0),J([c(),z("design:type",ie)],me.prototype,"userSuiteService",void 0),J([c(),z("design:type",N)],me.prototype,"sysSettingsService",void 0),J([l("/detail",{description:j.per.authOnly}),z("design:type",Function),z("design:paramtypes",[]),z("design:returntype",Promise)],me.prototype,"detail",null),J([l("/page",{description:j.per.authOnly}),Y(0,S(v)),z("design:type",Function),z("design:paramtypes",[Object]),z("design:returntype",Promise)],me.prototype,"page",null),me=J([p(),h("/api/mine/suite"),V(["suite"])],me);let ge=class{tradeService;accessService;sysSettingsService;async onNotify(e,t,i){const s=await this.tradeService.getPaymentByType(e);return i&&Object.keys(i).length>1&&(t=i),await s.onNotify(t,async e=>{await this.tradeService.onPaid(e)})}};J([c(),z("design:type",se)],ge.prototype,"tradeService",void 0),J([c(),z("design:type",F)],ge.prototype,"accessService",void 0),J([c(),z("design:type",N)],ge.prototype,"sysSettingsService",void 0),J([f("/:paymentType",{description:j.per.guest}),l("/:paymentType",{description:j.per.guest}),Y(0,b("paymentType")),Y(1,w(v)),Y(2,S(v)),z("design:type",Function),z("design:paramtypes",[String,Object,Object]),z("design:returntype",Promise)],ge.prototype,"onNotify",null),ge=J([p(),h("/api/payment/notify"),V(["suite"])],ge);const le=[X,K,H];export{ne as CommSysSettingsController,re as Configuration,me as MySuiteController,ge as PaymentNotifyController,ee as PaymentProviderFactory,ue as ProductController,K as ProductEntity,Z as ProductService,ce as SuiteSettingsController,de as SysProductController,oe as SysSiteController,ae as SysTradeController,ye as TradeController,H as TradeEntity,se as TradeService,pe as UserSuiteController,X as UserSuiteEntity,ie as UserSuiteService,le as commercialEntities,te as paymentProviderFactory};
|
|
1
|
+
import{PrimaryGeneratedColumn as e,Column as t,Entity as i,Index as n,Repository as r,Or as s,Equal as a,MoreThan as o,LessThan as d}from"typeorm";import{Provide as p,Scope as u,ScopeEnum as m,Inject as y,Logger as c,Configuration as l,Post as g,Body as w,ALL as h,Controller as v,Query as S,Get as f,Param as I}from"@midwayjs/core";import{InjectEntityModel as b}from"@midwayjs/typeorm";import{BaseService as T,ValidateException as P,SysSuiteSetting as _,NeedSuiteException as A,SysSettingsService as N,BaseSettings as C,FileService as R,SysInstallInfo as k,SysPaymentSetting as x,AccessService as O,BaseController as U,SysHeaderMenus as E,SysSiteInfo as D,CrudController as M,Constants as B}from"@certd/lib-server";import F from"dayjs";import{utils as W,logger as L}from"@certd/basic";import{isComm as j,checkComm as q}from"@certd/plus-core";import*as $ from"lodash-es";import{merge as z,remove as G}from"lodash-es";import{ApiTags as Y}from"@midwayjs/swagger";function J(e,t,i,n){var r,s=arguments.length,a=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(s<3?r(a):s>3?r(t,i,a):r(t,i))||a);return s>3&&a&&Object.defineProperty(t,i,a),a}function V(e,t){return function(i,n){t(i,n,e)}}function Q(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;let K=class{id;userId;productId;tradeNo;duration;title;desc;num;price;amount;rebateAmount;thirdPartyPayAmount;remark;status;payType;payTime;payNo;endTime;createTime;updateTime};var H;J([e(),Q("design:type",Number)],K.prototype,"id",void 0),J([t({name:"user_id",comment:"用户id"}),Q("design:type",Number)],K.prototype,"userId",void 0),J([t({name:"product_id",comment:"商品Id"}),Q("design:type",Number)],K.prototype,"productId",void 0),J([t({name:"trade_no",comment:"交易号"}),Q("design:type",String)],K.prototype,"tradeNo",void 0),J([t({name:"duration",comment:"时长"}),Q("design:type",Number)],K.prototype,"duration",void 0),J([t({name:"title",comment:"商品名称"}),Q("design:type",String)],K.prototype,"title",void 0),J([t({name:"desc",comment:"商品描述"}),Q("design:type",String)],K.prototype,"desc",void 0),J([t({name:"num",comment:"商品数量"}),Q("design:type",Number)],K.prototype,"num",void 0),J([t({name:"price",comment:"单价"}),Q("design:type",Number)],K.prototype,"price",void 0),J([t({name:"amount",comment:"总价"}),Q("design:type",Number)],K.prototype,"amount",void 0),J([t({name:"rebate_amount",comment:"返利余额抵扣金额",default:0}),Q("design:type",Number)],K.prototype,"rebateAmount",void 0),J([t({name:"third_party_pay_amount",comment:"第三方实付金额",default:0}),Q("design:type",Number)],K.prototype,"thirdPartyPayAmount",void 0),J([t({name:"remark",comment:"备注"}),Q("design:type",String)],K.prototype,"remark",void 0),J([t({name:"status",comment:"状态"}),Q("design:type",String)],K.prototype,"status",void 0),J([t({name:"pay_type",comment:"支付类型"}),Q("design:type",String)],K.prototype,"payType",void 0),J([t({name:"pay_time",comment:"支付时间"}),Q("design:type",Number)],K.prototype,"payTime",void 0),J([t({name:"pay_no",comment:"支付单号"}),Q("design:type",String)],K.prototype,"payNo",void 0),J([t({name:"end_time",comment:"结束时间"}),Q("design:type",Number)],K.prototype,"endTime",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],K.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],K.prototype,"updateTime",void 0),K=J([i("cd_trade")],K);let X=H=class{id;icon;title;type;content;durationPrices;duration;price;intro;order;supportBuy;disabled;createTime;updateTime;static getSuiteContent(e){return JSON.parse(e.content||"{}")}static setSuiteContent(e,t){e.content=JSON.stringify(t||{})}static getDurationPrices(e){return JSON.parse(e.durationPrices||"[]")}static setDurationPrices(e,t){if(0===t.length)throw new Error("prices must not be empty");e.duration=t[0].duration,e.price=t[0].price,e.durationPrices=JSON.stringify(t)}static getContentStr(e){let t="";const i=H.getSuiteContent(e);return-1===i.maxDomainCount?t+="域名无限制;":t+=`域名${i.maxDomainCount}个;`,-1===i.maxWildcardDomainCount?t+="泛域名无限制;":t+=`泛域名${i.maxWildcardDomainCount}个;`,-1===i.maxPipelineCount?t+="流水线无限制;":t+=`流水线${i.maxPipelineCount}个;`,-1===i.maxDeployCount?t+="部署次数无限制;":t+=`部署${i.maxDeployCount}次;`,t}};J([e(),Q("design:type",Number)],X.prototype,"id",void 0),J([t({name:"icon",comment:"图标"}),Q("design:type",String)],X.prototype,"icon",void 0),J([t({name:"title",comment:"套餐名称"}),Q("design:type",String)],X.prototype,"title",void 0),J([t({name:"type",comment:"套餐类型,套餐/加量包,suite/addon"}),Q("design:type",String)],X.prototype,"type",void 0),J([t({name:"content",comment:"套餐内容"}),Q("design:type",String)],X.prototype,"content",void 0),J([t({name:"duration_prices",comment:"时长及单价"}),Q("design:type",String)],X.prototype,"durationPrices",void 0),J([t({name:"duration",comment:"时长"}),Q("design:type",Number)],X.prototype,"duration",void 0),J([t({name:"price",comment:"单价"}),Q("design:type",Number)],X.prototype,"price",void 0),J([t({name:"intro",comment:"说明"}),Q("design:type",String)],X.prototype,"intro",void 0),J([t({name:"order",comment:"排序"}),Q("design:type",Number)],X.prototype,"order",void 0),J([t({name:"support_buy",comment:"是否支持购买",default:!0}),Q("design:type",Boolean)],X.prototype,"supportBuy",void 0),J([t({name:"disabled",comment:"禁用启用"}),Q("design:type",Boolean)],X.prototype,"disabled",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],X.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],X.prototype,"updateTime",void 0),X=H=J([i("cd_product")],X);let Z=class{id;userId;productId;tradeId;icon;title;productType;content;duration;deployCountUsed;activeTime;expiresTime;disabled;isPresent;isBootstrap;isEmpty;activationCodeId;createTime;updateTime;static getContent(e){return JSON.parse(e.content||"{}")}};J([e(),Q("design:type",Number)],Z.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],Z.prototype,"userId",void 0),J([t({name:"product_id",comment:"套餐ID"}),Q("design:type",Number)],Z.prototype,"productId",void 0),J([t({name:"trade_id",comment:"订单id"}),Q("design:type",Number)],Z.prototype,"tradeId",void 0),J([t({name:"icon",comment:"图标"}),Q("design:type",String)],Z.prototype,"icon",void 0),J([t({name:"title",comment:"套餐名称"}),Q("design:type",String)],Z.prototype,"title",void 0),J([t({name:"product_type",comment:"套餐类型,套餐/加量包,suite/addon"}),Q("design:type",String)],Z.prototype,"productType",void 0),J([t({name:"content",comment:"套餐内容"}),Q("design:type",String)],Z.prototype,"content",void 0),J([t({name:"duration",comment:"有效时长"}),Q("design:type",Number)],Z.prototype,"duration",void 0),J([t({name:"deploy_count_used",comment:"已使用部署次数"}),Q("design:type",Number)],Z.prototype,"deployCountUsed",void 0),J([t({name:"active_time",comment:"激活时间"}),Q("design:type",Number)],Z.prototype,"activeTime",void 0),J([t({name:"expires_time",comment:"有效期"}),Q("design:type",Number)],Z.prototype,"expiresTime",void 0),J([t({name:"disabled",comment:"启用/禁用",default:!1}),Q("design:type",Boolean)],Z.prototype,"disabled",void 0),J([t({name:"is_present",comment:"是否赠送",default:!1}),Q("design:type",Boolean)],Z.prototype,"isPresent",void 0),J([t({name:"is_bootstrap",comment:"是否初始套餐",default:!1}),Q("design:type",Boolean)],Z.prototype,"isBootstrap",void 0),J([t({name:"is_empty",comment:"是否用完",default:!1}),Q("design:type",Boolean)],Z.prototype,"isEmpty",void 0),J([t({name:"activation_code_id",comment:"激活码ID",nullable:!0}),Q("design:type",Number)],Z.prototype,"activationCodeId",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],Z.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],Z.prototype,"updateTime",void 0),Z=J([i("cd_user_suite")],Z);let ee=class{id;code;productId;duration;batchNo;status;usedUserId;usedTime;expireTime;disabledTime;exported;exportTime;remark;createTime;updateTime};J([e(),Q("design:type",Number)],ee.prototype,"id",void 0),J([n({unique:!0}),t({name:"code",comment:"激活码"}),Q("design:type",String)],ee.prototype,"code",void 0),J([t({name:"product_id",comment:"绑定套餐ID"}),Q("design:type",Number)],ee.prototype,"productId",void 0),J([t({name:"duration",comment:"有效时长(天)"}),Q("design:type",Number)],ee.prototype,"duration",void 0),J([t({name:"batch_no",comment:"批次号"}),Q("design:type",String)],ee.prototype,"batchNo",void 0),J([t({name:"status",comment:"状态:unused/used/disabled",default:"unused"}),Q("design:type",String)],ee.prototype,"status",void 0),J([t({name:"used_user_id",comment:"兑换用户ID",nullable:!0}),Q("design:type",Number)],ee.prototype,"usedUserId",void 0),J([t({name:"used_time",comment:"兑换时间",nullable:!0}),Q("design:type",Number)],ee.prototype,"usedTime",void 0),J([t({name:"expire_time",comment:"过期时间",nullable:!0}),Q("design:type",Number)],ee.prototype,"expireTime",void 0),J([t({name:"disabled_time",comment:"禁用时间",nullable:!0}),Q("design:type",Number)],ee.prototype,"disabledTime",void 0),J([t({name:"exported",comment:"是否已导出",default:!1}),Q("design:type",Boolean)],ee.prototype,"exported",void 0),J([t({name:"export_time",comment:"导出时间",nullable:!0}),Q("design:type",Number)],ee.prototype,"exportTime",void 0),J([t({name:"remark",comment:"备注",default:""}),Q("design:type",String)],ee.prototype,"remark",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ee.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ee.prototype,"updateTime",void 0),ee=J([i("cd_product_activation_code")],ee);let te=class extends T{repository;getRepository(){return this.repository}async add(e){return this.checkSuiteContent(e),await super.add(e)}async update(e){return this.checkSuiteContent(e),await super.update(e)}checkSuiteContent(e){const t=this.parseContent(e.content);if(t&&-1!==t.maxDomainCount&&-1===t.maxWildcardDomainCount)throw new P("域名总数量有限制时,其中泛域名数量不能设置为无限制")}parseContent(e){return null==e?null:"string"==typeof e?JSON.parse(e||"{}"):e}};J([b(X),Q("design:type",r)],te.prototype,"repository",void 0),te=J([p(),u(m.Request,{allowDowngrade:!0})],te);class ie{registry={};async createByPaymentType(e,t){return new(await this.getProviderCls(e))(t)}async getProviderCls(e){const t=this.registry[e];if(!t)throw new Error("不支持的支付方式:"+e);return await t()}async getDefine(e){return(await this.getProviderCls(e)).getDefine()}registerProvider(e,t){this.registry[e]=t}}const ne=new ie;let re=class extends T{repository;myCountService;sysSettingsService;productService;getRepository(){return this.repository}async presentGiftSuite(e){if(null==e)return!1;if(!j())return!1;const t=await this.getSuiteSetting();return!!t&&(!!t.enabled&&(!!t.registerGift?.productId&&await W.locker.execute(`presentGiftSuite:${e}`,async()=>{if(await this.getRepository().count({where:{userId:e,isPresent:!0}})>0)return!1;const i=await this.productService.info(t.registerGift.productId);return!!i&&(L.info(`注册赠送套餐:userId=${e},suite=${i.title}`),await this.productToUserSuite({},{userId:e,product:i,duration:t.registerGift.duration,isPresent:!0,isBootstrap:!0}),!0)})))}async productToUserSuite(e,t){const{duration:i,userId:n,product:r,tradeId:s,activationCodeId:a}=t,o=F(),d=o.valueOf();let p=0;p=-1===i?-1:o.add(i,"day").endOf("day").valueOf();const u=new Z;u.userId=n,u.productId=r.id,u.tradeId=s||0,u.icon="",u.title=r.title,u.productType=r.type,u.content=r.content,u.duration=i,u.deployCountUsed=0,u.disabled=!1,u.activeTime=d,u.expiresTime=p,u.isPresent=t.isPresent||!1,u.isBootstrap=t.isBootstrap||!1,u.isEmpty=!1,u.activationCodeId=a||null;const m=this.getRepo(e,Z);await m.save(u)}async getMySuiteDetail(e){const t=await this.sysSettingsService.getSetting(_);let i=await this.getMyValidSuiteList(e);if(!i||0===i.length){await this.presentGiftSuite(e)&&(i=await this.getMyValidSuiteList(e))}i&&0!==i.length||(i=[]);const n={max:0,used:0},r={max:0,used:0},s={max:0,used:0},a={max:0,used:0},o={max:0,used:0},d=[];if(i.length>0)for(const e of i){d.push({id:e.id,productId:e.productId,duration:e.duration,title:e.title,expiresTime:e.expiresTime,productType:e.productType});const t=Z.getContent(e);-1==n.max||-1==t.maxPipelineCount?n.max=-1:n.max+=t.maxPipelineCount??0,-1==r.max||-1==t.maxDomainCount?r.max=-1:r.max+=t.maxDomainCount??0,-1==s.max||-1==t.maxWildcardDomainCount?s.max=-1:s.max+=t.maxWildcardDomainCount??0,-1==a.max||-1==t.maxDeployCount?a.max=-1:a.max+=t.maxDeployCount??0,-1==o.max||-1==t.maxMonitorCount?o.max=-1:o.max+=t.maxMonitorCount??0,a.used+=e.deployCountUsed??0}const{pipelineCountUsed:p,domainCountUsed:u,wildcardDomainCountUsed:m,monitorCountUsed:y}=await this.myCountService.getUsedCount(e);return n.used=p??0,r.used=u??0,s.used=m??0,o.used=y??0,{enabled:t.enabled,suites:d,expiresTime:0,pipelineCount:n,domainCount:r,wildcardDomainCount:s,deployCount:a,monitorCount:o}}async getMyValidSuiteList(e){if(null==e)throw new Error("用户ID不能为空");const t=F();return[...(await this.getSuiteSetting()).allowSuiteStack?await this.getMyValidSuites(e,t):await this.getMyLatestValidSuiteList(e,t),...await this.getMyValidAddons(e,t)]}async getMyLatestValidSuiteList(e,t){const i=await this.getRepository().findOne({where:{userId:e,expiresTime:s(a(-1),o(t.valueOf())),activeTime:d(t.valueOf()),disabled:!1,productType:"suite"},order:{id:"DESC"}});return i?[i]:[]}async getMyValidSuites(e,t){return await this.getRepository().find({where:{userId:e,expiresTime:s(a(-1),o(t.valueOf())),activeTime:d(t.valueOf()),disabled:!1,productType:"suite"},order:{expiresTime:"ASC",id:"ASC"}})}async getMyValidAddons(e,t){return await this.getRepository().find({where:{userId:e,expiresTime:s(a(-1),o(t.valueOf())),activeTime:d(t.valueOf()),disabled:!1,productType:"addon",isEmpty:!1},order:{expiresTime:"ASC",id:"ASC"}})}async checkHasDeployCount(e,t=1){t<=0&&(t=1);if(!(await this.getSuiteSetting()).enabled)return null;const i=await this.getMyValidSuiteList(e);i.sort((e,t)=>e.expiresTime-t.expiresTime);for(const e of i){const i=Z.getContent(e);if(-1==i.maxDeployCount||i.maxDeployCount>=e.deployCountUsed+t)return e}throw new A("部署次数不足,请购买加量包或升级套餐")}async consumeDeployCount(e,t){if(null==e)return;e.deployCountUsed+=t;const i=Z.getContent(e);if(-1!=i.maxDeployCount&&e.deployCountUsed>=i.maxDeployCount){this.isOnlyDeployCount(i)&&(e.isEmpty=!0)}const n={deployCountUsed:()=>`deployCountUsed + ${t}`};e.isEmpty&&(n.isEmpty=!0),await this.repository.createQueryBuilder().update(Z).set(n).where("id = :suiteId",{suiteId:e.id}).execute()}checkHasInfinite(e){const t=Object.keys(e);for(const i of t)if(i.startsWith("max")&&-1==e[i])return!0;return!1}getSuiteSetting(){return this.sysSettingsService.getSetting(_)}isOnlyDeployCount(e){const t=Object.keys(e);for(const i of t)if(i.startsWith("max")&&"maxDeployCount"!=i&&0!=e[i])return!1;return-1!==e.maxDeployCount}async presentSuite(e){q();if(!(await this.getSuiteSetting()).enabled)throw new Error("套餐功能未开启");const t=await this.productService.info(e.productId);if(!t)throw new Error("产品不存在");const i=X.getDurationPrices(t).find(t=>t.duration===e.duration);if(!i)throw new Error("套餐时长不存在");await this.productToUserSuite({},{userId:e.userId,product:t,duration:i.duration,isPresent:!0})}};J([b(Z),Q("design:type",r)],re.prototype,"repository",void 0),J([y("myCountService"),Q("design:type",Object)],re.prototype,"myCountService",void 0),J([y(),Q("design:type",N)],re.prototype,"sysSettingsService",void 0),J([y(),Q("design:type",te)],re.prototype,"productService",void 0),re=J([p("userSuiteService"),u(m.Request,{allowDowngrade:!0})],re);let se=class{id;userId;code;disabled;createTime;updateTime};J([e(),Q("design:type",Number)],se.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],se.prototype,"userId",void 0),J([t({name:"code",comment:"邀请码"}),Q("design:type",String)],se.prototype,"code",void 0),J([t({name:"disabled",comment:"是否禁用",default:!1}),Q("design:type",Boolean)],se.prototype,"disabled",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],se.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],se.prototype,"updateTime",void 0),se=J([i("cd_invite_code")],se);let ae=class{id;inviterUserId;inviteeUserId;inviteCode;createTime;updateTime};J([e(),Q("design:type",Number)],ae.prototype,"id",void 0),J([t({name:"inviter_user_id",comment:"邀请人用户ID"}),Q("design:type",Number)],ae.prototype,"inviterUserId",void 0),J([t({name:"invitee_user_id",comment:"被邀请人用户ID"}),Q("design:type",Number)],ae.prototype,"inviteeUserId",void 0),J([t({name:"invite_code",comment:"邀请码"}),Q("design:type",String)],ae.prototype,"inviteCode",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ae.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ae.prototype,"updateTime",void 0),ae=J([i("cd_invite_relation")],ae);let oe=class{id;userId;amount;tradeId;inviteeUserId;consumeAmount;levelId;commissionRate;remark;createTime;updateTime};J([e(),Q("design:type",Number)],oe.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],oe.prototype,"userId",void 0),J([t({name:"amount",comment:"佣金金额"}),Q("design:type",Number)],oe.prototype,"amount",void 0),J([t({name:"trade_id",comment:"订单ID"}),Q("design:type",Number)],oe.prototype,"tradeId",void 0),J([t({name:"invitee_user_id",comment:"被邀请人用户ID"}),Q("design:type",Number)],oe.prototype,"inviteeUserId",void 0),J([t({name:"consume_amount",comment:"产生佣金的消费金额",default:0}),Q("design:type",Number)],oe.prototype,"consumeAmount",void 0),J([t({name:"level_id",comment:"推广等级ID",default:0}),Q("design:type",Number)],oe.prototype,"levelId",void 0),J([t({name:"commission_rate",comment:"结算佣金比例",default:0}),Q("design:type",Number)],oe.prototype,"commissionRate",void 0),J([t({name:"remark",comment:"备注"}),Q("design:type",String)],oe.prototype,"remark",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],oe.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],oe.prototype,"updateTime",void 0),oe=J([i("cd_invite_commission_log")],oe);let de=class{id;name;icon;sort;minAmount;commissionRate;levelType;disabled;createTime;updateTime};J([e(),Q("design:type",Number)],de.prototype,"id",void 0),J([t({name:"name",comment:"等级名称"}),Q("design:type",String)],de.prototype,"name",void 0),J([t({name:"icon",comment:"等级图标",default:"ion:ribbon-outline"}),Q("design:type",String)],de.prototype,"icon",void 0),J([t({name:"sort",comment:"排序",default:0}),Q("design:type",Number)],de.prototype,"sort",void 0),J([t({name:"min_amount",comment:"自动升级所需推广金额",default:0}),Q("design:type",Number)],de.prototype,"minAmount",void 0),J([t({name:"commission_rate",comment:"佣金比例",default:0}),Q("design:type",Number)],de.prototype,"commissionRate",void 0),J([t({name:"level_type",comment:"等级类型",default:"normal"}),Q("design:type",String)],de.prototype,"levelType",void 0),J([t({name:"disabled",comment:"是否禁用",default:!1}),Q("design:type",Boolean)],de.prototype,"disabled",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],de.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],de.prototype,"updateTime",void 0),de=J([i("cd_invite_level")],de);let pe=class{id;userId;enabled;levelId;levelLocked;promotionAmount;agreementTime;createTime;updateTime};J([e(),Q("design:type",Number)],pe.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],pe.prototype,"userId",void 0),J([t({name:"enabled",comment:"是否开通激励计划",default:!1}),Q("design:type",Boolean)],pe.prototype,"enabled",void 0),J([t({name:"level_id",comment:"当前推广等级ID",default:0}),Q("design:type",Number)],pe.prototype,"levelId",void 0),J([t({name:"level_locked",comment:"是否锁定为管理员指定等级",default:!1}),Q("design:type",Boolean)],pe.prototype,"levelLocked",void 0),J([t({name:"promotion_amount",comment:"累计推广金额",default:0}),Q("design:type",Number)],pe.prototype,"promotionAmount",void 0),J([t({name:"agreement_time",comment:"协议同意时间",default:0}),Q("design:type",Number)],pe.prototype,"agreementTime",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],pe.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],pe.prototype,"updateTime",void 0),pe=J([i("cd_invite_user_plan")],pe);class ue extends C{static __title__="激励计划设置";static __key__="sys.invite.commission";static __access__="private";enabled=!1;levelEnabled=!1;fixedCommissionRate=10;agreementContent="请遵守平台推广规则,不得通过虚假注册、刷单、恶意诱导等方式获取收益。平台有权对异常推广行为进行核查,并根据实际情况暂停结算或关闭激励计划资格。"}let me=class{id;userId;totalAmount;frozenAmount;totalIncomeAmount;totalConsumedAmount;totalWithdrawAmount;createTime;updateTime;getAvaliableAmount(){return Math.max(0,Math.floor(Number(this.totalAmount)||0)-Math.floor(Number(this.frozenAmount)||0))}};J([e(),Q("design:type",Number)],me.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],me.prototype,"userId",void 0),J([t({name:"total_amount",comment:"总余额",default:0}),Q("design:type",Number)],me.prototype,"totalAmount",void 0),J([t({name:"frozen_amount",comment:"冻结余额",default:0}),Q("design:type",Number)],me.prototype,"frozenAmount",void 0),J([t({name:"total_income_amount",comment:"累计收入",default:0}),Q("design:type",Number)],me.prototype,"totalIncomeAmount",void 0),J([t({name:"total_consumed_amount",comment:"累计消费抵扣",default:0}),Q("design:type",Number)],me.prototype,"totalConsumedAmount",void 0),J([t({name:"total_withdraw_amount",comment:"累计提现",default:0}),Q("design:type",Number)],me.prototype,"totalWithdrawAmount",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],me.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],me.prototype,"updateTime",void 0),me=J([i("cd_user_wallet")],me);let ye=class{id;userId;type;amount;balanceAfter;tradeId;withdrawId;remark;createTime;updateTime};J([e(),Q("design:type",Number)],ye.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],ye.prototype,"userId",void 0),J([t({name:"type",comment:"流水类型"}),Q("design:type",String)],ye.prototype,"type",void 0),J([t({name:"amount",comment:"变动金额"}),Q("design:type",Number)],ye.prototype,"amount",void 0),J([t({name:"balance_after",comment:"变动后可用余额"}),Q("design:type",Number)],ye.prototype,"balanceAfter",void 0),J([t({name:"trade_id",comment:"订单ID",default:0}),Q("design:type",Number)],ye.prototype,"tradeId",void 0),J([t({name:"withdraw_id",comment:"提现申请ID",default:0}),Q("design:type",Number)],ye.prototype,"withdrawId",void 0),J([t({name:"remark",comment:"备注"}),Q("design:type",String)],ye.prototype,"remark",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ye.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ye.prototype,"updateTime",void 0),ye=J([i("cd_user_wallet_log")],ye);let ce=class{id;userId;amount;status;channel;realName;account;bankName;qrCode;auditUserId;auditRemark;auditTime;createTime;updateTime};J([e(),Q("design:type",Number)],ce.prototype,"id",void 0),J([t({name:"user_id",comment:"用户ID"}),Q("design:type",Number)],ce.prototype,"userId",void 0),J([t({name:"amount",comment:"提现金额"}),Q("design:type",Number)],ce.prototype,"amount",void 0),J([t({name:"status",comment:"状态"}),Q("design:type",String)],ce.prototype,"status",void 0),J([t({name:"channel",comment:"提现渠道"}),Q("design:type",String)],ce.prototype,"channel",void 0),J([t({name:"real_name",comment:"真实姓名"}),Q("design:type",String)],ce.prototype,"realName",void 0),J([t({name:"account",comment:"收款账号"}),Q("design:type",String)],ce.prototype,"account",void 0),J([t({name:"bank_name",comment:"开户银行"}),Q("design:type",String)],ce.prototype,"bankName",void 0),J([t({name:"qr_code",comment:"收款二维码"}),Q("design:type",String)],ce.prototype,"qrCode",void 0),J([t({name:"audit_user_id",comment:"审核人用户ID"}),Q("design:type",Number)],ce.prototype,"auditUserId",void 0),J([t({name:"audit_remark",comment:"审核备注"}),Q("design:type",String)],ce.prototype,"auditRemark",void 0),J([t({name:"audit_time",comment:"审核时间"}),Q("design:type",Number)],ce.prototype,"auditTime",void 0),J([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ce.prototype,"createTime",void 0),J([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Q("design:type",Date)],ce.prototype,"updateTime",void 0),ce=J([i("cd_user_wallet_withdraw")],ce);class le extends C{static __title__="钱包设置";static __key__="sys.wallet";static __access__="private";minWithdrawAmount=0;withdrawChannels=["alipay","bank"];withdrawBanks=["中国工商银行","中国农业银行","中国银行","中国建设银行","交通银行","招商银行","中国邮政储蓄银行","中信银行","中国光大银行","华夏银行","中国民生银行","广发银行","平安银行","兴业银行","浦发银行"]}class ge extends C{static __title__="用户钱包提现设置";static __key__="user.wallet.withdraw";channel="alipay";realName="";account="";bankName="";qrCode=""}let we=class extends T{repository;logRepository;withdrawRepository;sysSettingsService;userSettingsService;fileService;getRepository(){return this.repository}async getSummary(e){const t=await this.ensureWallet(e);return this.toWalletSummary(t)}async ensureWallet(e,t){const i=t?.getRepository(me)||this.repository;let n=await i.findOne({where:{userId:e}});return n||(n=i.create({userId:e,totalAmount:0,frozenAmount:0,totalIncomeAmount:0,totalConsumedAmount:0,totalWithdrawAmount:0}),await i.save(n))}async addIncome(e){return await this.income(e)}async income(e){const t=this.toAmount(e.amount);return t<=0?null:(await this.doWalletTrade({tradeType:"income",userId:e.userId,amount:t,tradeId:e.tradeId||0,manager:e.manager}),await this.getWallet(e.manager,e.userId))}async frozenByTrade(e){const t=this.toAmount(e.amount);if(t<=0)return 0;for(let i=0;i<3;i++){const i=await this.ensureWallet(e.userId,e.manager),n=Math.min(i.getAvaliableAmount(),t);return n<=0?0:(await this.frozen({userId:e.userId,amount:n,manager:e.manager}),n)}return 0}async consumeByTrade(e){const t=this.toAmount(e.amount);return t<=0?0:(await this.doWalletTrade({tradeType:"consume",userId:e.userId,amount:-t,tradeId:e.tradeId,manager:e.manager}),t)}async cancelByTrade(e){const t=this.toAmount(e.amount);return t<=0?0:(await this.unfrozen({userId:e.userId,amount:-t,manager:e.manager}),t)}async saveWithdrawSetting(e,t){const i=t.channel||"alipay",n=t.realName?.trim(),r=t.account?.trim(),s=t.bankName?.trim()||"";let a="bank"===i?"":t.qrCode?.trim()||"";const o=await this.checkWithdrawChannelEnabled(i);if(!n)throw new P("真实姓名不能为空");if(!r)throw new P("收款账号不能为空");if("bank"===i&&!s)throw new P("开户银行不能为空");"bank"===i&&this.checkWithdrawBankEnabled(s,o),a&&(a=await this.fileService.saveFile(e,a,"private"));const d=new ge;return d.channel=i,d.realName=n,d.account=r,d.bankName=s,d.qrCode=a,await this.userSettingsService.saveSetting(e,null,d),d}async getWithdrawSetting(e){return await this.userSettingsService.getSetting(e,null,ge,!1)}async withdrawApply(e,t){if((t=this.toAmount(t))<=0)throw new P("提现金额必须大于0");const i=await this.sysSettingsService.getSetting(le);if(i?.minWithdrawAmount&&t<i.minWithdrawAmount)throw new P(`提现金额不能小于${i.minWithdrawAmount/100}元`);return await this.transaction(async i=>{const n=await this.getWithdrawSetting(e);if(!n?.realName||!n?.account)throw new P("请先设置提现信息");await this.checkWithdrawChannelEnabled(n.channel);const r=i.getRepository(ce).create({userId:e,amount:t,status:"pending",channel:n.channel,realName:n.realName,account:n.account,bankName:n.bankName||"",qrCode:n.qrCode||""}),s=await i.getRepository(ce).save(r);return await this.frozen({userId:e,amount:t,manager:i}),s})}async applyWithdraw(e,t){return await this.withdrawApply(e,t)}async approveWithdraw(e,t,i){return await this.auditWithdraw({id:e,auditUserId:t,auditRemark:i,status:"approved"})}async rejectWithdraw(e,t,i){return await this.auditWithdraw({id:e,auditUserId:t,auditRemark:i,status:"rejected"})}async auditWithdraw(e){return await this.transaction(async t=>{const i=t.getRepository(ce),n=await i.findOne({where:{id:e.id}});if(!n)throw new P("提现申请不存在");if("pending"!==n.status)throw new P("提现申请状态不正确");return"approved"===e.status?await this.withdrawApprove(t,n):await this.withdrawReject(t,n),n.status=e.status,n.auditUserId=e.auditUserId,n.auditRemark=e.auditRemark||"",n.auditTime=F().valueOf(),n.updateTime=new Date,await t.getRepository(ce).save(n),n})}async withdrawPage(e,t){return t.query=t.query||{},t.query.userId=e,await this.pageByRepository(this.withdrawRepository,t)}async logPage(e,t){return t.query=t.query||{},t.query.userId=e,await this.pageByRepository(this.logRepository,t)}async sysWithdrawPage(e){return await this.pageByRepository(this.withdrawRepository,e)}async checkWithdrawChannelEnabled(e){if(!["alipay","bank"].includes(e))throw new P("不支持的提现渠道");const t=await this.sysSettingsService.getSetting(le);if(!(t?.withdrawChannels?.length?t.withdrawChannels:["alipay","bank"]).includes(e))throw new P("该提现渠道未开启");return t}checkWithdrawBankEnabled(e,t){if(!this.getEnabledWithdrawBanks(t).includes(e))throw new P("该开户银行未开启")}getEnabledWithdrawBanks(e){return e?.withdrawBanks?.length?e.withdrawBanks.map(e=>e?.trim()).filter(Boolean):(new le).withdrawBanks}async pageByRepository(e,t){const i=t.page||{},n=i.offset||0,r=i.limit||20,[s,a]=await e.findAndCount({where:t.query||{},skip:n,take:r,order:{id:"DESC"}});return{records:s,total:a,offset:n,limit:r}}async addLog(e,t){const i=t.getRepository(ye),n=i.create({userId:e.userId,type:e.type,amount:e.amount||0,balanceAfter:e.balanceAfter||0,tradeId:e.tradeId||0,withdrawId:e.withdrawId||0,remark:e.remark||""});return await i.save(n)}async doWalletTrade(e){const t=this.toSignedAmount(e.amount);if(await this.ensureWallet(e.userId,e.manager),0===t)return;"withdraw"!==e.tradeType&&"consume"!==e.tradeType||await this.unfrozen({userId:e.userId,amount:-Math.abs(t),manager:e.manager}),await this.doBalanceChange(e),await this.increaseTotal(e.manager,e.userId,e.tradeType,Math.abs(t));const i=await this.getWallet(e.manager,e.userId);return await this.addLog({userId:e.userId,type:e.tradeType,amount:t,balanceAfter:i?.getAvaliableAmount()||0,tradeId:e.tradeId||0,withdrawId:e.withdrawId||0,remark:this.getTradeRemark(e.tradeType)},e.manager),i}async doBalanceChange(e){const t=this.toSignedAmount(e.amount);if(0===t)return;const i={totalAmount:()=>`total_amount ${t>0?"+":"-"} :amount`,updateTime:()=>"CURRENT_TIMESTAMP"},n=e.manager.getRepository(me).createQueryBuilder().update(me).set(i).where("user_id = :userId",{userId:e.userId}),r=Math.abs(t);t<0&&n.andWhere("total_amount >= :amount",{amount:r}),n.setParameters({amount:r});if(!(await n.execute()).affected)throw new P("余额不足")}async frozen(e){const t=this.toSignedAmount(e.amount);if(0===t)return;const i={frozenAmount:()=>`frozen_amount ${t>0?"+":"-"} :amount`,updateTime:()=>"CURRENT_TIMESTAMP"},n=e.manager.getRepository(me).createQueryBuilder().update(me).set(i).where("user_id = :userId",{userId:e.userId}),r=Math.abs(t);t>0?n.andWhere("total_amount - frozen_amount >= :amount",{amount:r}):n.andWhere("frozen_amount >= :amount",{amount:r}),n.setParameters({amount:r});if(!(await n.execute()).affected)throw new P(t>0?"余额不足":"冻结余额不足")}async unfrozen(e){await this.frozen(e)}async getWallet(e,t){return await e.getRepository(me).findOne({where:{userId:t}})}async increaseTotal(e,t,i,n){if((n=this.toAmount(n))<=0)return;let r="totalIncomeAmount",s="total_income_amount";"consume"===i&&(r="totalConsumedAmount",s="total_consumed_amount"),"withdraw"===i&&(r="totalWithdrawAmount",s="total_withdraw_amount");const a={[r]:()=>`${s} + :amount`,updateTime:()=>"CURRENT_TIMESTAMP"};await e.getRepository(me).createQueryBuilder().update(me).set(a).where("user_id = :userId",{userId:t}).setParameters({amount:n}).execute()}getTradeRemark(e){return"income"===e?"余额入账":"consume"===e?"订单余额抵扣":"提现审核通过,扣减余额"}async withdrawApprove(e,t){const i=this.toAmount(t.amount);if(i<=0)throw new P("提现金额不正确");await this.doWalletTrade({tradeType:"withdraw",userId:t.userId,amount:-i,withdrawId:t.id,manager:e})}async withdrawReject(e,t){await this.withdrawCancel(e,t)}async withdrawCancel(e,t){const i=this.toAmount(t.amount);if(i<=0)throw new P("提现金额不正确");await this.unfrozen({userId:t.userId,amount:-i,manager:e})}toAmount(e){return Math.max(0,Math.floor(Number(e)||0))}toSignedAmount(e){return Math.floor(Number(e)||0)}toWalletSummary(e){return{totalAmount:e.totalAmount||0,availableAmount:e.getAvaliableAmount(),frozenAmount:e.frozenAmount||0,totalIncomeAmount:e.totalIncomeAmount||0,totalConsumedAmount:e.totalConsumedAmount||0,totalWithdrawAmount:e.totalWithdrawAmount||0}}};J([b(me),Q("design:type",r)],we.prototype,"repository",void 0),J([b(ye),Q("design:type",r)],we.prototype,"logRepository",void 0),J([b(ce),Q("design:type",r)],we.prototype,"withdrawRepository",void 0),J([y(),Q("design:type",N)],we.prototype,"sysSettingsService",void 0),J([y(),Q("design:type",Object)],we.prototype,"userSettingsService",void 0),J([y(),Q("design:type",R)],we.prototype,"fileService",void 0),we=J([p(),u(m.Request,{allowDowngrade:!0})],we);let he=class extends T{repository;relationRepository;logRepository;levelRepository;userPlanRepository;sysSettingsService;walletService;getRepository(){return this.repository}async getMyInviteInfo(e){const t=await this.sysSettingsService.getSetting(ue),i=await this.userPlanRepository.findOne({where:{userId:e}}),n=!0===t?.enabled&&!0===i?.enabled,r=this.isLevelEnabled(t),s=r?await this.levelList(!0):[];if(!n)return{enabled:!1,levelEnabled:r,fixedCommissionRate:this.getFixedCommissionRate(t),agreementContent:t?.agreementContent||"",levelList:s,summary:this.emptySummary()};const a=r?await this.syncUserLevelByAmount({},{userId:e}):i,o=await this.ensureInviteCode({},{userId:e}),d=await this.getInviteSummary(e,a),p=await this.walletService.getSummary(e),u=r?await this.buildLevelInfo(a,d.promotionAmount):this.emptyLevelInfo(a),m=await this.buildInviteLink(o.code);return{enabled:!0,levelEnabled:r,fixedCommissionRate:this.getFixedCommissionRate(t),inviteCode:o.code,inviteLink:m,agreementContent:t?.agreementContent||"",summary:d,wallet:p,...u}}async openInvitePlan(e){const t=await this.sysSettingsService.getSetting(ue);if(!t?.enabled)throw new P("激励计划暂未开启");const i=this.isLevelEnabled(t),n=i?await this.getLowestAutoLevel({}):null;if(i&&!n)throw new P("管理员尚未配置推广等级");let r=await this.userPlanRepository.findOne({where:{userId:e}});return r?(r.enabled=!0,i&&!r.levelId?r.levelId=n.id:i||(r.levelId=0,r.levelLocked=!1),r.agreementTime=r.agreementTime||Date.now(),r.updateTime=new Date):r=this.userPlanRepository.create({userId:e,enabled:!0,levelId:n?.id||0,levelLocked:!1,agreementTime:Date.now()}),await this.userPlanRepository.save(r),await this.ensureInviteCode({},{userId:e}),await this.getMyInviteInfo(e)}async ensureInviteCode(e,t){const i=this.getRepo(e,se),{userId:n}=t;let r=await i.findOne({where:{userId:n}});if(r)return r;for(let e=0;e<8;e++){const e=this.generateInviteCode(n);if(!await i.findOne({where:{code:e}}))return r=i.create({userId:n,code:e,disabled:!1}),await i.save(r)}throw new Error("邀请码生成失败,请重试")}generateInviteCode(e){return`C${e.toString(36).toUpperCase()}${W.id.randomNumber(4)}`}async getBindInfo(e){const t=this.normalizeInviteCode(e);if(!t)throw new P("邀请码不能为空");const i=await this.repository.findOne({where:{code:t,disabled:!1}});if(!i)throw new P("邀请码不存在或已失效");return{inviteCode:i.code,inviterUserId:i.userId}}async bindInvitee(e,t){const i=this.normalizeInviteCode(t.inviteCode);if(!i)return null;const n=this.getRepo(e,se),r=this.getRepo(e,ae),s=await n.findOne({where:{code:i,disabled:!1}});if(!s)throw new P("邀请码不存在或已失效");if(s.userId===t.inviteeUserId)throw new P("不能填写自己的邀请码");if(await r.findOne({where:{inviteeUserId:t.inviteeUserId}}))throw new P("当前用户已绑定邀请关系");const a=r.create({inviterUserId:s.userId,inviteeUserId:t.inviteeUserId,inviteCode:s.code});return await r.save(a)}normalizeInviteCode(e){return e?.trim().toUpperCase()}async settleCommission(e,t){if(!e.manager)throw new Error("settleCommission 必须在事务中调用");const i=Math.max(0,Math.floor(t.paidAmount||0));if(i<=0)return null;const n=await this.sysSettingsService.getSetting(ue);if(!n?.enabled)return null;const r=e.manager,s=this.getRepo(e,ae),a=this.getRepo(e,oe),o=await s.findOne({where:{inviteeUserId:t.inviteeUserId}});if(!o)return null;const d=await a.findOne({where:{tradeId:t.tradeId}});if(d)return d;const p=this.isLevelEnabled(n),u=p?await this.syncUserLevelByAmount(e,{userId:o.inviterUserId}):await this.getRepo(e,pe).findOne({where:{userId:o.inviterUserId}});if(!u?.enabled)return null;let m=null,y=this.getFixedCommissionRate(n),c=`推广用户消费收益,比例${y}%`;if(p){if(!u.levelId)return null;if(m=await this.getRepo(e,de).findOne({where:{id:u.levelId}}),!m||m.disabled||m.commissionRate<=0)return null;y=m.commissionRate,c=`推广用户消费收益,等级${m.name},比例${m.commissionRate}%`}if(y<=0)return null;const l=Math.floor(i*y/100);if(l<=0)return null;await this.walletService.addIncome({userId:o.inviterUserId,amount:l,tradeId:t.tradeId,remark:"推广用户消费收益入账",manager:r});const g=await this.addLog(e,{data:{userId:o.inviterUserId,amount:l,tradeId:t.tradeId,inviteeUserId:t.inviteeUserId,consumeAmount:i,levelId:m?.id||0,commissionRate:y,remark:c}});return await this.increasePromotionAmount(e,{userId:o.inviterUserId,paidAmount:i}),p&&await this.syncUserLevelByAmount(e,{userId:o.inviterUserId}),g}async inviteePage(e,t){t.query=t.query||{},t.query.inviterUserId=e;const i=await this.relationRepository.manager.getRepository(ae).findAndCount({where:t.query,skip:t.page?.offset||0,take:t.page?.limit||20,order:{id:"DESC"}}).then(([e,i])=>({records:e,total:i,offset:t.page?.offset||0,limit:t.page?.limit||20}));return await this.fillSimpleUser(i.records,this.relationRepository.manager),i}async commissionPage(e,t){t.query=t.query||{},t.query.userId=e;const i=await this.pageByRepository(this.logRepository,t);return await this.fillSimpleUser(i.records,this.logRepository.manager),i}async pageByRepository(e,t){const i=t.page||{},n=i.offset||0,r=i.limit||20,[s,a]=await e.findAndCount({where:t.query||{},skip:n,take:r,order:{id:"DESC"}});return{records:s,total:a,offset:n,limit:r}}async addLog(e,t){if(!e.manager)throw new Error("addLog 必须在事务中调用");const i=this.getRepo(e,oe),n=t.data,r=i.create({userId:n.userId,amount:n.amount||0,tradeId:n.tradeId||0,inviteeUserId:n.inviteeUserId||0,consumeAmount:n.consumeAmount||0,levelId:n.levelId||0,commissionRate:n.commissionRate||0,remark:n.remark||""});return await i.save(r)}async levelList(e=!1){const t=e?{}:{disabled:!1};return await this.levelRepository.find({where:t,order:{sort:"ASC",minAmount:"ASC",id:"ASC"}})}async userLevelPage(e){const t=e.page||{},i=t.offset||0,n=t.limit||20,r=e.query||{},s=this.userPlanRepository.manager.createQueryBuilder().from("sys_user","u").leftJoin("cd_invite_user_plan","p","p.user_id = u.id").leftJoin("cd_invite_level","l","l.id = p.level_id");r.userId&&s.andWhere("u.id = :userId",{userId:r.userId}),r.username&&s.andWhere("(u.username LIKE :keyword OR u.nick_name LIKE :keyword OR u.mobile LIKE :keyword OR u.email LIKE :keyword)",{keyword:`%${r.username}%`}),r.levelId&&s.andWhere("p.level_id = :levelId",{levelId:r.levelId});const a=await s.clone().select("COUNT(1)","count").getRawOne(),o=await s.clone().select(["u.id as userId","u.username as username","u.nick_name as nickName","u.mobile as mobile","u.email as email","p.enabled as enabled","p.level_id as levelId","p.level_locked as levelLocked","l.name as levelName","l.commission_rate as commissionRate","l.level_type as levelType","p.promotion_amount as promotionAmount","p.create_time as createTime","p.update_time as updateTime"]).orderBy("u.id","DESC").offset(i).limit(n).getRawMany();return this.fillUserLevelSummary(o),{records:o,total:Number(a?.count||0),offset:i,limit:n}}async setUserLevel(e){if(!e.userId)throw new P("请选择用户");const t=await this.levelRepository.findOne({where:{id:e.levelId}});if(!t||t.disabled)throw new P("推广等级不存在或已禁用");let i=await this.userPlanRepository.findOne({where:{userId:e.userId}});return i||(i=this.userPlanRepository.create({userId:e.userId,enabled:!0,agreementTime:0})),i.enabled=!0,i.levelId=t.id,i.levelLocked="exclusive"===t.levelType,i.updateTime=new Date,await this.userPlanRepository.save(i)}async syncUserLevelByAmount(e,t){const i=this.getRepo(e,pe),n=this.getRepo(e,de),{userId:r}=t;let s=await i.findOne({where:{userId:r}});if(!s?.enabled)return s;const a=s.levelId?await n.findOne({where:{id:s.levelId}}):null;if(s.levelLocked||"exclusive"===a?.levelType)return s;const o=this.getPlanPromotionAmount(s),d=await this.findMatchedAutoLevel(e,{promotionAmount:o});return d?(a&&!0!==a.disabled&&a.minAmount>d.minAmount||s.levelId!==d.id&&(s.levelId=d.id,s.updateTime=new Date,s=await i.save(s)),s):s}async buildInviteLink(e){const t=await this.sysSettingsService.getSetting(k);return`${(t?.bindUrl||"").replace(/\/$/,"")}/#/register?inviteCode=${encodeURIComponent(e)}`}async getInviteSummary(e,t){const i=t||await this.userPlanRepository.findOne({where:{userId:e}}),n=this.getPlanPromotionAmount(i),[r,s,a]=await Promise.all([this.sumLogAmount(e,"amount"),this.sumLogAmount(e,"amount",{from:F().startOf("month").toDate(),to:F().endOf("month").toDate()}),this.relationRepository.count({where:{inviterUserId:e}})]);return{totalIncomeAmount:r,monthIncomeAmount:s,promotionAmount:n,inviteeCount:a}}async buildLevelInfo(e,t){const i=await this.levelList(!0),n=i.find(t=>t.id===e?.levelId)||null,r=i.filter(e=>"exclusive"!==e.levelType||e.id===n?.id),s="exclusive"===n?.levelType?null:i.find(e=>"exclusive"!==e.levelType&&!0!==e.disabled&&e.minAmount>t)||null;return{currentLevel:n,nextLevel:s?{...s,gapAmount:Math.max(0,s.minAmount-t)}:null,levelList:r,userPlan:e}}emptyLevelInfo(e){return{currentLevel:null,nextLevel:null,levelList:[],userPlan:e}}isLevelEnabled(e){return!0===e?.levelEnabled}getFixedCommissionRate(e){return Math.max(0,Math.min(100,Number(e?.fixedCommissionRate)||0))}async getLowestAutoLevel(e){const t=this.getRepo(e,de);return(await t.find({where:{disabled:!1,levelType:"normal"},order:{minAmount:"ASC",sort:"ASC",id:"ASC"}}))[0]||null}async findMatchedAutoLevel(e,t){const i=this.getRepo(e,de),n=await i.find({where:{disabled:!1,levelType:"normal"},order:{minAmount:"ASC",sort:"ASC",id:"ASC"}});let r=n[0]||null;for(const e of n)e.minAmount<=t.promotionAmount&&(r=e);return r}async sumLogAmount(e,t,i){const n=this.logRepository.createQueryBuilder("log").select(`COALESCE(SUM(log.${t}), 0)`,"sum").where("log.userId = :userId",{userId:e});i&&n.andWhere("log.createTime BETWEEN :from AND :to",i);const r=await n.getRawOne();return Number(r?.sum||0)}fillUserLevelSummary(e){if(e.length)for(const t of e)t.levelType=t.levelType||"normal",t.promotionAmount=Number(t.promotionAmount||0)}async increasePromotionAmount(e,t){if(!e.manager)throw new Error("increasePromotionAmount 必须在事务中调用");const i=this.getRepo(e,pe);if("function"==typeof i.increment)return await i.increment({userId:t.userId},"promotionAmount",t.paidAmount),"function"==typeof i.update&&await i.update({userId:t.userId},{updateTime:new Date}),await i.findOne({where:{userId:t.userId}});const n=await i.findOne({where:{userId:t.userId}});return n?(n.promotionAmount=this.getPlanPromotionAmount(n)+t.paidAmount,n.updateTime=new Date,await i.save(n)):null}getPlanPromotionAmount(e){return Math.max(0,Number(e?.promotionAmount||0))}emptySummary(){return{totalIncomeAmount:0,monthIncomeAmount:0,promotionAmount:0,inviteeCount:0}}async fillSimpleUser(e,t,i="inviteeUserId"){const n=Array.from(new Set(e.map(e=>Number(e[i])).filter(e=>e&&e>0)));if(0===n.length)return;if("function"!=typeof t?.createQueryBuilder)return;const r=await t.createQueryBuilder().select(["u.id as id","u.username as username","u.nick_name as nickName","u.mobile as mobile","u.email as email"]).from("sys_user","u").where("u.id IN (:...ids)",{ids:n}).getRawMany(),s=new Map;for(const e of r)s.set(Number(e.id),e);for(const t of e){const e=Number(t[i]),n=s.get(e),r=n&&(n.username||n.nickName||n.mobile||n.email)||`用户${e}`;t.simpleUser={id:e,username:r,displayName:`${r} (ID:${e})`}}}};J([b(se),Q("design:type",r)],he.prototype,"repository",void 0),J([b(ae),Q("design:type",r)],he.prototype,"relationRepository",void 0),J([b(oe),Q("design:type",r)],he.prototype,"logRepository",void 0),J([b(de),Q("design:type",r)],he.prototype,"levelRepository",void 0),J([b(pe),Q("design:type",r)],he.prototype,"userPlanRepository",void 0),J([y(),Q("design:type",N)],he.prototype,"sysSettingsService",void 0),J([y(),Q("design:type",we)],he.prototype,"walletService",void 0),he=J([p(),u(m.Request,{allowDowngrade:!0})],he);let ve=class extends T{repository;getRepository(){return this.repository}async beforeSave(e){if(e.name=e.name?.trim(),!e.name)throw new P("等级名称不能为空");if(e.icon=e.icon?.trim()||"ion:ribbon-outline",e.minAmount=Math.max(0,Math.floor(Number(e.minAmount)||0)),e.sort=Math.floor(Number(e.sort)||0),e.commissionRate=Number(e.commissionRate)||0,e.commissionRate<0||e.commissionRate>100)throw new P("佣金比例必须在0到100之间");e.levelType="exclusive"===e.levelType?"exclusive":"normal","exclusive"===e.levelType&&(e.minAmount=0),e.disabled=!0===e.disabled}async add(e){return await this.beforeSave(e),await super.add(e)}async update(e){return await this.beforeSave(e),await super.update(e)}};J([b(de),Q("design:type",r)],ve.prototype,"repository",void 0),ve=J([p(),u(m.Request,{allowDowngrade:!0})],ve);let Se=class extends T{repository;productService;sysSettingsService;accessService;userSuiteService;inviteService;walletService;getRepository(){return this.repository}async createFree(e){const t=await this.getBuyableProduct(e.productId),{price:i}=this.findDurationPrice(t,e.duration);if(0!==i)throw new Error("产品价格不为0");const n=await this.create({productId:e.productId,duration:e.duration,num:e.num,payType:e.payType,userId:e.userId,useRebateBalance:!1});await this.onPaid({tradeNo:n.tradeNo,status:"paid",amount:0,payNo:"free",remark:"免费赠送",payTime:F().valueOf()})}findDurationPrice(e,t){const i=JSON.parse(e.durationPrices||"[]").find(e=>e.duration===t);if(!i)throw new Error(`产品时长${t}不存在`);return i}async create(e){const t=await this.getBuyableProduct(e.productId),{price:i}=this.findDurationPrice(t,e.duration),n=F(),r="T"+n.format("YYYYMMDD")+n.unix()+W.id.randomNumber(6),s=`购买${t.title} ${e.duration}天`,a=`内含:${X.getContentStr(t)}`,o=new K;return o.title=s,o.desc=a,o.productId=e.productId,o.duration=e.duration,o.num=e.num,o.userId=e.userId,o.tradeNo=r,o.duration=e.duration,o.price=i,o.title=t.title,o.amount=o.price*o.num,o.rebateAmount=0,o.thirdPartyPayAmount=o.amount,o.status="wait_pay",o.payType=e.payType,await this.transaction(async t=>{const i=await t.save(o);if(e.useRebateBalance&&i.amount>0){const n=await this.walletService.frozenByTrade({userId:e.userId,tradeId:i.id,amount:i.amount,manager:t});n>0&&(i.rebateAmount=n,i.thirdPartyPayAmount=i.amount-n,i.thirdPartyPayAmount<=0&&(i.thirdPartyPayAmount=0,i.payType="rebate"),await t.save(i))}return i})}async getBuyableProduct(e){const t=await this.productService.info(e);if(!t)throw new Error("产品不存在");if(t.disabled)throw new Error("该产品已下架");if(!t.supportBuy)throw new Error("该产品不支持购买");return t}async buildPaymentReq(e,t){const i=await this.sysSettingsService.getSetting(k);let n=i?.bindUrl;if(!n)throw new Error("未绑定URL");n.endsWith("/")&&(n=n.slice(0,-1));const r=await this.getPaymentByType(e.payType);return await r.createOrder({...e,amount:this.getThirdPartyPayAmount(e)},{bindUrl:n,clientIp:t})}getThirdPartyPayAmount(e){return null!=e.thirdPartyPayAmount&&0!==e.thirdPartyPayAmount||null!=e.rebateAmount&&0!==e.rebateAmount||!(e.amount>0)?e.thirdPartyPayAmount??e.amount:e.amount}async getPaymentByType(e){const t=(await this.sysSettingsService.getSetting(x))[e];if(!t||!t.enabled)throw new Error(`支付方式${e}未启用`);const i=await this.accessService.getById(t.accessId,0);if(!i)throw new Error(`支付方式${e}未设置授权`);return await ne.createByPaymentType(e,i)}async getByTradeNo(e){if(!e)throw new Error("out_trade_no不能为空");return await this.repository.findOne({where:{tradeNo:e}})}async onPaid(e){const t=await this.getByTradeNo(e.tradeNo);if(!t)throw new Error(`订单${e.tradeNo}不存在`);if("paid"===t.status)return;if("wait_pay"!==t.status)throw new Error(`订单${e.tradeNo}状态不正确, 当前状态为${t.status}`);const i=this.getThirdPartyPayAmount(t);if(i!==e.amount)throw new Error(`订单${e.tradeNo}金额不正确, 当前应付金额为${i},实际支付金额为${e.amount}`);await this.transaction(async n=>{await n.update(K,{id:t.id},{status:"paid",remark:e.remark,payNo:e.payNo,payTime:e.payTime||F().valueOf()}),t.rebateAmount>0&&await this.walletService.consumeByTrade({userId:t.userId,tradeId:t.id,amount:t.rebateAmount,manager:n});const r=await this.productService.info(t.productId);if(!r)throw new Error("产品不存在");const s=t.id,a=t.userId,o=t.duration;await this.userSuiteService.productToUserSuite({manager:n},{duration:o,userId:a,product:r,tradeId:s}),await this.inviteService.settleCommission({manager:n},{tradeId:s,inviteeUserId:a,paidAmount:i})})}async syncStatus(e){const t=await this.info(e);if(!t)throw new Error("订单不存在");if("paid"===t.status)return;const i=await this.getPaymentByType(t.payType),n=await i.getDetail(t.tradeNo);if(!n)throw new Error("订单不存在");"paid"===n.status?await this.onPaid(n):"closed"===n.status&&await this.closeWaitPayTrade(t,n.remark||"订单已关闭")}async cancel(e,t="用户取消订单"){const i=await this.info(e);if(!i)throw new Error("订单不存在");if("paid"===i.status)throw new Error("已支付订单不能取消");return"wait_pay"!==i.status?i:await this.closeWaitPayTrade(i,t)}async closeWaitPayTrade(e,t){return await this.transaction(async i=>(e.rebateAmount>0&&await this.walletService.cancelByTrade({userId:e.userId,tradeId:e.id,amount:e.rebateAmount,manager:i}),await i.update(K,{id:e.id},{status:"closed",remark:t}),e.status="closed",e.remark=t,e))}async updatePaid(e,t){const i=await this.info(e);if(!i)throw new Error("订单不存在");"paid"!==i.status&&await this.onPaid({tradeNo:i.tradeNo,status:"paid",amount:this.getThirdPartyPayAmount(i),payNo:"",remark:`手动确认支付:${t}`,payTime:F().valueOf()})}};J([b(K),Q("design:type",r)],Se.prototype,"repository",void 0),J([y(),Q("design:type",te)],Se.prototype,"productService",void 0),J([y(),Q("design:type",N)],Se.prototype,"sysSettingsService",void 0),J([y(),Q("design:type",O)],Se.prototype,"accessService",void 0),J([y(),Q("design:type",re)],Se.prototype,"userSuiteService",void 0),J([y(),Q("design:type",he)],Se.prototype,"inviteService",void 0),J([y(),Q("design:type",we)],Se.prototype,"walletService",void 0),Se=J([p(),u(m.Request,{allowDowngrade:!0})],Se);let fe=class extends T{repository;userSuiteRepository;productService;userSuiteService;getRepository(){return this.repository}async generate(e){const{productId:t,duration:i,count:n,expireTime:r,exported:s,remark:a}=e;if(!t)throw new P("请选择套餐");if(!i||i<=0&&-1!==i)throw new P("时长必须大于0或为永久");if(!n||n<=0||n>1e3)throw new P("生成数量必须在1-1000之间");if(r&&r<=F().valueOf())throw new P("过期时间必须晚于当前时间");const o=await this.productService.info(t);if(!o)throw new P("套餐不存在");if(o.disabled)throw new P("该套餐已禁用,不能生成激活码");if(!X.getDurationPrices(o).find(e=>e.duration===i))throw new P("套餐时长不存在");const d="B"+F().format("YYYYMMDDHHmmss")+W.id.randomNumber(4),p=[];for(let e=0;e<n;e++){const e=this.generateCode(t),n=this.repository.create({code:e,productId:t,duration:i,batchNo:d,status:"unused",expireTime:r||null,exported:!!s,exportTime:s?F().valueOf():null,remark:a||""});p.push(n)}return await this.transaction(async e=>{await e.insert(ee,p)}),{batchNo:d,count:p.length,codes:p.map(e=>({code:e.code,productId:e.productId,duration:e.duration,batchNo:e.batchNo,status:"unused",expireTime:e.expireTime,remark:e.remark}))}}generateCode(e){const t=F().format("YYYYMMDD");return`CDK${String(e).padStart(4,"0").slice(0,4)}${t}${W.id.simpleNanoId(10).toUpperCase()}`}async use(e,t){if(!e)throw new P("用户未登录");if(!t)throw new P("请输入激活码");const i=t.trim().toUpperCase(),n=await this.repository.findOne({where:{code:i}});if(!n)throw new P("激活码不存在");if("used"===n.status)throw new P("激活码已被使用");if("disabled"===n.status)throw new P("激活码已失效");if(n.expireTime&&n.expireTime<=F().valueOf())throw new P("激活码已过期");const r=await this.productService.info(n.productId);if(!r)throw new P("套餐不存在或已下架");if(r.disabled)throw new P("套餐已禁用,不能兑换");return await this.transactionWithCtx({},async t=>{if(!(await t.update(ee,{id:n.id,status:"unused"},{status:"used",usedUserId:e,usedTime:F().valueOf(),updateTime:new Date})).affected)throw new P("激活码已被使用");return await this.userSuiteService.productToUserSuite({manager:t},{userId:e,product:r,duration:n.duration,activationCodeId:n.id}),{title:r.title,duration:n.duration}})}async disable(e){this.checkId(e);const t=await this.info(e);if(!t)throw new P("激活码不存在");if("used"===t.status)throw new P("已使用的激活码不能禁用");"disabled"!==t.status&&await this.repository.update({id:e},{status:"disabled",disabledTime:F().valueOf(),updateTime:new Date})}async enable(e){this.checkId(e);const t=await this.info(e);if(!t)throw new P("激活码不存在");if("used"===t.status)throw new P("已使用的激活码不能启用");"unused"!==t.status&&await this.repository.update({id:e},{status:"unused",disabledTime:null,updateTime:new Date})}async exportCodes(e){const t=e.ids||[];if(0===t.length)throw new P("请选择要导出的激活码");const i=(await this.repository.findByIds(t)).filter(e=>"unused"===e.status);if(0===i.length)throw new P("没有可导出的激活码");const n=i.map(e=>e.id),r=F().valueOf();return await this.repository.update(n,{exported:!0,exportTime:r,updateTime:new Date}),i.map(e=>({id:e.id,code:e.code,productId:e.productId,duration:e.duration,batchNo:e.batchNo,status:e.status,expireTime:e.expireTime,remark:e.remark}))}async deleteById(e){this.checkId(e);const t=await this.info(e);if(!t)throw new P("激活码不存在");if("used"===t.status)throw new P("已使用的激活码不能删除");await this.repository.delete({id:e})}checkId(e){if(!e||Number.isNaN(Number(e)))throw new P("id不能为空")}};J([b(ee),Q("design:type",r)],fe.prototype,"repository",void 0),J([b(Z),Q("design:type",r)],fe.prototype,"userSuiteRepository",void 0),J([y(),Q("design:type",te)],fe.prototype,"productService",void 0),J([y(),Q("design:type",re)],fe.prototype,"userSuiteService",void 0),fe=J([p(),u(m.Request,{allowDowngrade:!0})],fe);let Ie=class{logger;async onReady(e){this.logger.info("commercial start")}};J([c(),Q("design:type",Object)],Ie.prototype,"logger",void 0),Ie=J([l({namespace:"commercial"})],Ie);let be=class extends U{sysSettingsService;async paymentGet(){const e=await this.sysSettingsService.getSetting(x);return this.ok(e)}async paymentSave(e){q();const t=new x;return z(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}async suiteGet(){const e=await this.sysSettingsService.getSetting(_);return this.ok(e)}async suiteSave(e){q();const t=new _;return z(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}async headerMenusGet(){const e=await this.sysSettingsService.getSetting(E);return this.ok(e)}async headerMenusSave(e){q();const t=new E;return z(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}};J([y(),Q("design:type",N)],be.prototype,"sysSettingsService",void 0),J([g("/payment/get",{description:"sys:settings:view"}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],be.prototype,"paymentGet",null),J([g("/payment/save",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],be.prototype,"paymentSave",null),J([g("/suite/get",{description:"sys:settings:view"}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],be.prototype,"suiteGet",null),J([g("/suite/save",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],be.prototype,"suiteSave",null),J([g("/headerMenus/get",{description:"sys:settings:view"}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],be.prototype,"headerMenusGet",null),J([g("/headerMenus/save",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],be.prototype,"headerMenusSave",null),be=J([p(),v("/api/sys/settings")],be);let Te=class extends U{sysSettingsService;fileService;async saveSiteInfo(e){q();let t=await this.sysSettingsService.getSetting(D);return null==t&&(t=new D),$.merge(t,e),t.logo&&(t.logo=await this.fileService.saveFile(this.getUserId(),t.logo,"public")),t.loginLogo&&(t.loginLogo=await this.fileService.saveFile(this.getUserId(),t.loginLogo,"public")),await this.sysSettingsService.saveSetting(t),this.ok(t)}async getSiteInfo(){q();const e=await this.sysSettingsService.getSetting(D);return this.ok(e)}};J([y(),Q("design:type",N)],Te.prototype,"sysSettingsService",void 0),J([y(),Q("design:type",R)],Te.prototype,"fileService",void 0),J([g("/save",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Te.prototype,"saveSiteInfo",null),J([g("/get",{description:"sys:settings:view"}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Te.prototype,"getSiteInfo",null),Te=J([p(),v("/api/sys/site")],Te);let Pe=class extends M{service;getService(){return q(),this.service}async page(e){return await super.page(e)}async list(e){return await super.list(e)}async add(e){return await super.add(e)}async update(e){return await super.update(e)}async info(e){return await super.info(e)}async delete(e){return this.unsupportedDelete()}async syncStatus(e){return await this.service.syncStatus(e),this.ok()}async cancel(e){const t=await this.getLoginUser();return await this.service.cancel(e,`管理员取消订单:${t.id}_${t.username}`),this.ok()}async updatePaid(e){const t=await this.getLoginUser();return await this.service.updatePaid(e,t.id+"_"+t.username),this.ok()}async deleteByIds(e){return this.unsupportedDelete()}unsupportedDelete(){return{...B.res.error,data:null,message:"订单不支持删除,请取消订单"}}};J([y(),Q("design:type",Se)],Pe.prototype,"service",void 0),J([g("/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Pe.prototype,"page",null),J([g("/list",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Pe.prototype,"list",null),J([g("/add",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Pe.prototype,"add",null),J([g("/update",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Pe.prototype,"update",null),J([g("/info",{description:"sys:settings:view"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Pe.prototype,"info",null),J([g("/delete",{description:"sys:settings:edit"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Pe.prototype,"delete",null),J([g("/syncStatus",{description:"sys:settings:edit"}),V(0,w("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Pe.prototype,"syncStatus",null),J([g("/cancel",{description:"sys:settings:edit"}),V(0,w("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Pe.prototype,"cancel",null),J([g("/updatePaid",{description:"sys:settings:edit"}),V(0,w("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Pe.prototype,"updatePaid",null),J([g("/deleteByIds",{description:"sys:settings:edit"}),V(0,w("ids")),Q("design:type",Function),Q("design:paramtypes",[Array]),Q("design:returntype",Promise)],Pe.prototype,"deleteByIds",null),Pe=J([p(),v("/api/sys/suite/trade"),Y(["sys-trade"])],Pe);let _e=class extends M{service;getService(){return q(),this.service}async page(e){return await super.page(e)}async list(e){return await super.list(e)}async add(e){return await super.add(e)}async update(e){return await super.update(e)}async info(e){return await super.info(e)}async delete(e){return await super.delete(e)}async deleteByIds(e){return await super.deleteByIds(e)}};J([y(),Q("design:type",te)],_e.prototype,"service",void 0),J([g("/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],_e.prototype,"page",null),J([g("/list",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],_e.prototype,"list",null),J([g("/add",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],_e.prototype,"add",null),J([g("/update",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],_e.prototype,"update",null),J([g("/info",{description:"sys:settings:view"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],_e.prototype,"info",null),J([g("/delete",{description:"sys:settings:edit"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],_e.prototype,"delete",null),J([g("/deleteByIds",{description:"sys:settings:edit"}),V(0,w("ids")),Q("design:type",Function),Q("design:paramtypes",[Array]),Q("design:returntype",Promise)],_e.prototype,"deleteByIds",null),_e=J([p(),v("/api/sys/suite/product"),Y(["sys-product"])],_e);let Ae=class extends M{getService(){return this.userSuiteService}productService;userSuiteService;sysSettingsService;async page(e){return q(),await super.page(e)}async list(e){return await super.list(e)}async add(e){return q(),await super.add(e)}async update(e){return await super.update(e)}async info(e){return await super.info(e)}async delete(e){return await super.delete(e)}async deleteByIds(e){return await super.deleteByIds(e)}async presentSuite(e){return await this.userSuiteService.presentSuite({userId:e.userId,productId:e.productId,duration:e.duration}),this.ok()}};J([y(),Q("design:type",te)],Ae.prototype,"productService",void 0),J([y(),Q("design:type",re)],Ae.prototype,"userSuiteService",void 0),J([y(),Q("design:type",N)],Ae.prototype,"sysSettingsService",void 0),J([g("/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ae.prototype,"page",null),J([g("/list",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ae.prototype,"list",null),J([g("/add",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ae.prototype,"add",null),J([g("/update",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ae.prototype,"update",null),J([g("/info",{description:"sys:settings:view"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Ae.prototype,"info",null),J([g("/delete",{description:"sys:settings:edit"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Ae.prototype,"delete",null),J([g("/deleteByIds",{description:"sys:settings:edit"}),V(0,w("ids")),Q("design:type",Function),Q("design:paramtypes",[Array]),Q("design:returntype",Promise)],Ae.prototype,"deleteByIds",null),J([g("/presentSuite",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ae.prototype,"presentSuite",null),Ae=J([p(),v("/api/sys/suite/user-suite"),Y(["sys-user-suite"])],Ae);let Ne=class extends U{service;async page(e){return q(),this.ok(await this.service.page(e))}async list(e){return q(),this.ok(await this.service.list(e))}async generate(e){return q(),this.ok(await this.service.generate(e))}async disable(e){return q(),await this.service.disable(e),this.ok(null)}async enable(e){return q(),await this.service.enable(e),this.ok(null)}async export(e){return q(),this.ok(await this.service.exportCodes(e))}async delete(e){return q(),await this.service.deleteById(e),this.ok(null)}};J([y(),Q("design:type",fe)],Ne.prototype,"service",void 0),J([g("/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ne.prototype,"page",null),J([g("/list",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ne.prototype,"list",null),J([g("/generate",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ne.prototype,"generate",null),J([g("/disable",{description:"sys:settings:edit"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Ne.prototype,"disable",null),J([g("/enable",{description:"sys:settings:edit"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Ne.prototype,"enable",null),J([g("/export",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ne.prototype,"export",null),J([g("/delete",{description:"sys:settings:edit"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Ne.prototype,"delete",null),Ne=J([p(),v("/api/sys/suite/activation-code"),Y(["sys-product-activation-code"])],Ne);let Ce=class extends U{walletService;inviteService;sysSettingsService;async settingsGet(){const e=await this.sysSettingsService.getSetting(ue),t=await this.sysSettingsService.getSetting(le);return this.ok({...t,...e})}async settingsSave(e){q();const t=new ue;if(z(t,e),t.enabled&&this.isBlankAgreement(t.agreementContent))throw new P("请填写推广协议内容");if(t.levelEnabled=!0===t.levelEnabled,t.fixedCommissionRate=Number(t.fixedCommissionRate)||0,t.fixedCommissionRate<0||t.fixedCommissionRate>100)throw new P("佣金比例必须在0到100之间");if(t.enabled&&!t.levelEnabled&&t.fixedCommissionRate<=0)throw new P("关闭推广等级时,请设置佣金比例");const i=new le;if(z(i,e),i.minWithdrawAmount<0)throw new Error("最低提现金额不能小于0");return this.normalizeWalletSetting(i),await this.sysSettingsService.saveSetting(i),await this.sysSettingsService.saveSetting(t),this.ok({})}normalizeWalletSetting(e){if(e.withdrawChannels?.includes("bank")){if(e.withdrawBanks=(e.withdrawBanks||[]).map(e=>e?.trim()).filter(Boolean),0===e.withdrawBanks.length)throw new P("请至少选择一个开户银行")}else e.withdrawBanks=[]}isBlankAgreement(e){return!`${e||""}`.replace(/<[^>]*>/g,"").replace(/ /g,"").trim()}async userLevelPage(e){return q(),this.ok(await this.inviteService.userLevelPage(e))}async userLevelSet(e){return q(),this.ok(await this.inviteService.setUserLevel({userId:e.userId,levelId:e.levelId}))}async withdrawPage(e){return q(),this.ok(await this.walletService.sysWithdrawPage(e))}async withdrawApprove(e,t){return q(),this.ok(await this.walletService.approveWithdraw(e,this.getUserId(),t))}async withdrawReject(e,t){q();const i=t?.trim();if(!i)throw new P("请填写拒绝理由");return this.ok(await this.walletService.rejectWithdraw(e,this.getUserId(),i))}};J([y(),Q("design:type",we)],Ce.prototype,"walletService",void 0),J([y(),Q("design:type",he)],Ce.prototype,"inviteService",void 0),J([y(),Q("design:type",N)],Ce.prototype,"sysSettingsService",void 0),J([g("/settings/get",{description:"sys:settings:view"}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Ce.prototype,"settingsGet",null),J([g("/settings/save",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ce.prototype,"settingsSave",null),J([g("/user/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ce.prototype,"userLevelPage",null),J([g("/user/setLevel",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ce.prototype,"userLevelSet",null),J([g("/withdraw/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Ce.prototype,"withdrawPage",null),J([g("/withdraw/approve",{description:"sys:settings:edit"}),V(0,w("id")),V(1,w("remark")),Q("design:type",Function),Q("design:paramtypes",[Number,String]),Q("design:returntype",Promise)],Ce.prototype,"withdrawApprove",null),J([g("/withdraw/reject",{description:"sys:settings:edit"}),V(0,w("id")),V(1,w("remark")),Q("design:type",Function),Q("design:paramtypes",[Number,String]),Q("design:returntype",Promise)],Ce.prototype,"withdrawReject",null),Ce=J([p(),v("/api/sys/invite"),Y(["sys-invite"])],Ce);let Re=class extends M{levelService;getService(){return this.levelService}async page(e){return q(),await super.page(e)}async list(e){return q(),(e=e||{}).query=e.query||{},e.query.disabled=!1,await super.list(e)}async add(e){return q(),await super.add(e)}async update(e){return q(),await super.update(e)}async info(e){return q(),await super.info(e)}};J([y(),Q("design:type",ve)],Re.prototype,"levelService",void 0),J([g("/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Re.prototype,"page",null),J([g("/list",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Re.prototype,"list",null),J([g("/add",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[de]),Q("design:returntype",Promise)],Re.prototype,"add",null),J([g("/update",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[de]),Q("design:returntype",Promise)],Re.prototype,"update",null),J([g("/info",{description:"sys:settings:view"}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Re.prototype,"info",null),Re=J([p(),v("/api/sys/invite/level"),Y(["sys-invite-level"])],Re);let ke=class extends U{walletService;sysSettingsService;async settingsGet(){return this.ok(await this.sysSettingsService.getSetting(le))}async settingsSave(e){q();const t=new le;if(z(t,e),t.minWithdrawAmount<0)throw new Error("最低提现金额不能小于0");return this.normalizeWalletSetting(t),await this.sysSettingsService.saveSetting(t),this.ok({})}normalizeWalletSetting(e){if(e.withdrawChannels?.includes("bank")){if(e.withdrawBanks=(e.withdrawBanks||[]).map(e=>e?.trim()).filter(Boolean),0===e.withdrawBanks.length)throw new P("请至少选择一个开户银行")}else e.withdrawBanks=[]}async withdrawPage(e){return q(),this.ok(await this.walletService.sysWithdrawPage(e))}async withdrawApprove(e,t){return q(),this.ok(await this.walletService.approveWithdraw(e,this.getUserId(),t))}async withdrawReject(e,t){q();const i=t?.trim();if(!i)throw new P("请填写拒绝理由");return this.ok(await this.walletService.rejectWithdraw(e,this.getUserId(),i))}};J([y(),Q("design:type",we)],ke.prototype,"walletService",void 0),J([y(),Q("design:type",N)],ke.prototype,"sysSettingsService",void 0),J([g("/settings/get",{description:"sys:settings:view"}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],ke.prototype,"settingsGet",null),J([g("/settings/save",{description:"sys:settings:edit"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],ke.prototype,"settingsSave",null),J([g("/withdraw/page",{description:"sys:settings:view"}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],ke.prototype,"withdrawPage",null),J([g("/withdraw/approve",{description:"sys:settings:edit"}),V(0,w("id")),V(1,w("remark")),Q("design:type",Function),Q("design:paramtypes",[Number,String]),Q("design:returntype",Promise)],ke.prototype,"withdrawApprove",null),J([g("/withdraw/reject",{description:"sys:settings:edit"}),V(0,w("id")),V(1,w("remark")),Q("design:type",Function),Q("design:paramtypes",[Number,String]),Q("design:returntype",Promise)],ke.prototype,"withdrawReject",null),ke=J([p(),v("/api/sys/wallet"),Y(["sys-wallet"])],ke);let xe=class extends U{productService;async list(){q();const e=await this.productService.list({query:{disabled:!1,supportBuy:!0},sort:{prop:"order",asc:!0}});for(const t of e)t.durationPrices=JSON.parse(t.durationPrices||"[]"),t.content=JSON.parse(t.content||"{}");return G(e,e=>!0===e.isBootstrap),this.ok(e)}};J([y(),Q("design:type",te)],xe.prototype,"productService",void 0),J([g("/list",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],xe.prototype,"list",null),xe=J([p(),v("/api/suite/product"),Y(["suite"])],xe);let Oe=class extends U{productService;tradeService;sysSettingsService;async create(e){q();const{productId:t,duration:i,num:n,payType:r,useRebateBalance:s}=e,a=await this.tradeService.create({productId:t,duration:i,num:n,payType:r,useRebateBalance:s,userId:this.getUserId()});if(0===a.thirdPartyPayAmount)return await this.tradeService.onPaid({tradeNo:a.tradeNo,status:"paid",amount:0,payNo:"rebate",remark:"余额全额抵扣",payTime:Date.now()}),this.ok({paid:!0,tradeId:a.id,tradeNo:a.tradeNo,amount:a.amount,rebateAmount:a.rebateAmount,thirdPartyPayAmount:a.thirdPartyPayAmount});const o=this.ctx.request.ip,d=await this.tradeService.buildPaymentReq(a,o);return this.ok({...d,tradeId:a.id,tradeNo:a.tradeNo,amount:a.amount,rebateAmount:a.rebateAmount,thirdPartyPayAmount:a.thirdPartyPayAmount})}async createFree(e){q();const{productId:t,duration:i,num:n}=e,r=await this.tradeService.createFree({productId:t,duration:i,num:n,payType:"free",userId:this.getUserId()});return this.ok(r)}async info(e){const t=await this.tradeService.info(e.tradeId);return this.ok(t)}async page(e){e.query=e.query||{};e.query.userId=this.getUserId();const t=await this.tradeService.page(e);return this.ok(t)}async payments(){const e=await this.sysSettingsService.getSetting(x),t=[];return e.yizhifu&&e.yizhifu.enabled&&t.push({value:"yizhifu",label:"易支付",icon:"material-symbols:shield-outline"}),e.alipay&&e.alipay.enabled&&t.push({value:"alipay",label:"支付宝",icon:"ant-design:alipay-circle-filled"}),e.wxpay&&e.wxpay.enabled&&t.push({value:"wxpay",label:"微信",icon:"ant-design:wechat-filled"}),this.ok(t)}async syncStatus(e){const t=await this.tradeService.info(e);return t?t.userId!=this.getUserId()?this.fail("无权操作该交易订单"):("paid"===t.status||await this.tradeService.syncStatus(e),this.ok()):this.fail("交易订单不存在")}async cancel(e){const t=this.getUserId(),i=await this.tradeService.info(e);return i?i.userId!=t?this.fail("无权操作该交易订单"):(await this.tradeService.cancel(e,"用户取消订单"),this.ok()):this.fail("交易订单不存在")}async delete(e){throw new Error("订单不支持删除,请取消订单")}async deleteByIds(e){throw new Error("订单不支持删除,请取消订单")}};J([y(),Q("design:type",te)],Oe.prototype,"productService",void 0),J([y(),Q("design:type",Se)],Oe.prototype,"tradeService",void 0),J([y(),Q("design:type",N)],Oe.prototype,"sysSettingsService",void 0),J([g("/create",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Oe.prototype,"create",null),J([g("/createFree",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Oe.prototype,"createFree",null),J([g("/info",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Oe.prototype,"info",null),J([g("/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Oe.prototype,"page",null),J([g("/payments",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Oe.prototype,"payments",null),J([g("/syncStatus",{description:B.per.authOnly}),V(0,w("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Oe.prototype,"syncStatus",null),J([g("/cancel",{description:B.per.authOnly}),V(0,w("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Oe.prototype,"cancel",null),J([g("/delete",{description:B.per.authOnly}),V(0,S("id")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Oe.prototype,"delete",null),J([g("/deleteByIds",{description:B.per.authOnly}),V(0,w("ids")),Q("design:type",Function),Q("design:paramtypes",[Array]),Q("design:returntype",Promise)],Oe.prototype,"deleteByIds",null),Oe=J([p(),v("/api/suite/trade"),Y(["suite"])],Oe);let Ue=class extends U{sysSettingsService;async get(){const e=await this.sysSettingsService.getSetting(_);return this.ok({intro:e.intro,allowSuiteStack:e.allowSuiteStack})}};J([y(),Q("design:type",N)],Ue.prototype,"sysSettingsService",void 0),J([g("/get",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Ue.prototype,"get",null),Ue=J([p(),v("/api/suite/settings"),Y(["suite"])],Ue);let Ee=class extends U{service;async use(e){q();const t=this.getUserId(),i=await this.service.use(t,e);return this.ok(i)}};J([y(),Q("design:type",fe)],Ee.prototype,"service",void 0),J([g("/use",{description:B.per.authOnly}),V(0,w("code")),Q("design:type",Function),Q("design:paramtypes",[String]),Q("design:returntype",Promise)],Ee.prototype,"use",null),Ee=J([p(),v("/api/suite/activation-code"),Y(["suite-activation-code"])],Ee);let De=class extends U{productService;userSuiteService;sysSettingsService;async detail(){const e=await this.userSuiteService.getMySuiteDetail(this.getUserId());return this.ok(e)}async page(e){q(),e.query=e.query||{};e.query.userId=this.getUserId();const t=await this.userSuiteService.page(e);return this.ok(t)}};J([y(),Q("design:type",te)],De.prototype,"productService",void 0),J([y(),Q("design:type",re)],De.prototype,"userSuiteService",void 0),J([y(),Q("design:type",N)],De.prototype,"sysSettingsService",void 0),J([g("/detail",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],De.prototype,"detail",null),J([g("/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],De.prototype,"page",null),De=J([p(),v("/api/mine/suite"),Y(["suite"])],De);let Me=class{tradeService;accessService;sysSettingsService;async onNotify(e,t,i){const n=await this.tradeService.getPaymentByType(e);return i&&Object.keys(i).length>1&&(t=i),await n.onNotify(t,async e=>{await this.tradeService.onPaid(e)})}};J([y(),Q("design:type",Se)],Me.prototype,"tradeService",void 0),J([y(),Q("design:type",O)],Me.prototype,"accessService",void 0),J([y(),Q("design:type",N)],Me.prototype,"sysSettingsService",void 0),J([f("/:paymentType",{description:B.per.guest}),g("/:paymentType",{description:B.per.guest}),V(0,I("paymentType")),V(1,S(h)),V(2,w(h)),Q("design:type",Function),Q("design:paramtypes",[String,Object,Object]),Q("design:returntype",Promise)],Me.prototype,"onNotify",null),Me=J([p(),v("/api/payment/notify"),Y(["suite"])],Me);let Be=class extends U{inviteService;walletService;async my(){return q(),this.ok(await this.inviteService.getMyInviteInfo(this.getUserId()))}async open(){return q(),this.ok(await this.inviteService.openInvitePlan(this.getUserId()))}async bindInfo(e){return q(),this.ok(await this.inviteService.getBindInfo(e))}async inviteesPage(e){return q(),this.ok(await this.inviteService.inviteePage(this.getUserId(),e))}async commissionPage(e){return q(),this.ok(await this.inviteService.commissionPage(this.getUserId(),e))}async withdrawSettingGet(){return q(),this.ok(await this.walletService.getWithdrawSetting(this.getUserId()))}async withdrawSettingSave(e){return q(),this.ok(await this.walletService.saveWithdrawSetting(this.getUserId(),e))}async withdrawApply(e){return q(),this.ok(await this.walletService.applyWithdraw(this.getUserId(),e))}async withdrawPage(e){return q(),this.ok(await this.walletService.withdrawPage(this.getUserId(),e))}};J([y(),Q("design:type",he)],Be.prototype,"inviteService",void 0),J([y(),Q("design:type",we)],Be.prototype,"walletService",void 0),J([g("/my",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Be.prototype,"my",null),J([g("/open",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Be.prototype,"open",null),J([g("/bindInfo",{description:B.per.guest}),V(0,w("inviteCode")),Q("design:type",Function),Q("design:paramtypes",[String]),Q("design:returntype",Promise)],Be.prototype,"bindInfo",null),J([g("/invitees/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Be.prototype,"inviteesPage",null),J([g("/commission/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Be.prototype,"commissionPage",null),J([g("/withdraw/setting/get",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Be.prototype,"withdrawSettingGet",null),J([g("/withdraw/setting/save",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Be.prototype,"withdrawSettingSave",null),J([g("/withdraw/apply",{description:B.per.authOnly}),V(0,w("amount")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Be.prototype,"withdrawApply",null),J([g("/withdraw/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Be.prototype,"withdrawPage",null),Be=J([p(),v("/api/invite"),Y(["invite"])],Be);let Fe=class extends U{walletService;sysSettingsService;async summary(){return q(),this.ok(await this.walletService.getSummary(this.getUserId()))}async withdrawSettingGet(){return q(),this.ok(await this.walletService.getWithdrawSetting(this.getUserId()))}async walletSettingGet(){return q(),this.ok(await this.sysSettingsService.getSetting(le))}async withdrawSettingSave(e){return q(),this.ok(await this.walletService.saveWithdrawSetting(this.getUserId(),e))}async withdrawApply(e){return q(),this.ok(await this.walletService.applyWithdraw(this.getUserId(),e))}async withdrawPage(e){return q(),this.ok(await this.walletService.withdrawPage(this.getUserId(),e))}async logPage(e){return q(),this.ok(await this.walletService.logPage(this.getUserId(),e))}};J([y(),Q("design:type",we)],Fe.prototype,"walletService",void 0),J([y(),Q("design:type",N)],Fe.prototype,"sysSettingsService",void 0),J([g("/summary",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Fe.prototype,"summary",null),J([g("/withdraw/setting/get",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Fe.prototype,"withdrawSettingGet",null),J([g("/settings/get",{description:B.per.authOnly}),Q("design:type",Function),Q("design:paramtypes",[]),Q("design:returntype",Promise)],Fe.prototype,"walletSettingGet",null),J([g("/withdraw/setting/save",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Fe.prototype,"withdrawSettingSave",null),J([g("/withdraw/apply",{description:B.per.authOnly}),V(0,w("amount")),Q("design:type",Function),Q("design:paramtypes",[Number]),Q("design:returntype",Promise)],Fe.prototype,"withdrawApply",null),J([g("/withdraw/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Fe.prototype,"withdrawPage",null),J([g("/log/page",{description:B.per.authOnly}),V(0,w(h)),Q("design:type",Function),Q("design:paramtypes",[Object]),Q("design:returntype",Promise)],Fe.prototype,"logPage",null),Fe=J([p(),v("/api/wallet"),Y(["wallet"])],Fe);const We=[Z,X,ee,K,se,ae,oe,de,pe,me,ye,ce];export{be as CommSysSettingsController,Ie as Configuration,se as InviteCodeEntity,oe as InviteCommissionLogEntity,Be as InviteController,de as InviteLevelEntity,ve as InviteLevelService,ae as InviteRelationEntity,he as InviteService,pe as InviteUserPlanEntity,De as MySuiteController,Me as PaymentNotifyController,ie as PaymentProviderFactory,Ee as ProductActivationCodeController,ee as ProductActivationCodeEntity,fe as ProductActivationCodeService,xe as ProductController,X as ProductEntity,te as ProductService,Ue as SuiteSettingsController,ue as SysInviteCommissionSetting,Ce as SysInviteController,Re as SysInviteLevelController,Ne as SysProductActivationCodeController,_e as SysProductController,Te as SysSiteController,Pe as SysTradeController,ke as SysWalletController,le as SysWalletSetting,Oe as TradeController,K as TradeEntity,Se as TradeService,Ae as UserSuiteController,Z as UserSuiteEntity,re as UserSuiteService,me as UserWalletEntity,ye as UserWalletLogEntity,ce as UserWalletWithdrawEntity,ge as UserWalletWithdrawSetting,Fe as WalletController,we as WalletService,We as commercialEntities,ne as paymentProviderFactory};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certd/commercial-core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.41.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/d/index.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"compile": "tsc --skipLibCheck --watch"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@certd/basic": "^1.
|
|
21
|
-
"@certd/lib-server": "^1.
|
|
22
|
-
"@certd/pipeline": "^1.
|
|
23
|
-
"@certd/plus-core": "^1.
|
|
20
|
+
"@certd/basic": "^1.41.0",
|
|
21
|
+
"@certd/lib-server": "^1.41.0",
|
|
22
|
+
"@certd/pipeline": "^1.41.0",
|
|
23
|
+
"@certd/plus-core": "^1.41.0",
|
|
24
24
|
"@midwayjs/core": "3.20.11",
|
|
25
25
|
"@midwayjs/koa": "3.20.13",
|
|
26
26
|
"@midwayjs/logger": "3.4.2",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"tslib": "^2.8.1",
|
|
53
53
|
"typescript": "^5.4.2"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "d368f9666abf71d7f56891b6cbedeb618b82701c"
|
|
56
56
|
}
|
package/logs/app.log
DELETED
|
File without changes
|