/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@certd/commercial-core@1.39.10/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
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 p}from"typeorm";import{Provide as d,Scope as u,ScopeEnum as y,Inject as c,Logger as g,Configuration as m,Post as l,Body as v,ALL as S,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,SysSuiteSetting as T,NeedSuiteException as x,SysSettingsService as N,SysInstallInfo as C,SysPaymentSetting as O,AccessService as F,BaseController as E,SysHeaderMenus as D,SysSiteInfo as B,FileService as _,CrudController as k,Constants as U}from"@certd/lib-server";import j from"dayjs";import{utils as M,logger as R}from"@certd/basic";import{isComm as $,checkComm as A}from"@certd/plus-core";import*as q from"lodash-es";import{merge as G,remove as L}from"lodash-es";import{ApiTags as J}from"@midwayjs/swagger";function V(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 W(e,t){return function(i,s){t(i,s,e)}}function Y(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;let z=class{id;userId;productId;tradeNo;duration;title;desc;num;price;amount;remark;status;payType;payTime;payNo;endTime;createTime;updateTime};var H;V([e(),Y("design:type",Number)],z.prototype,"id",void 0),V([t({name:"user_id",comment:"用户id"}),Y("design:type",Number)],z.prototype,"userId",void 0),V([t({name:"product_id",comment:"商品Id"}),Y("design:type",Number)],z.prototype,"productId",void 0),V([t({name:"trade_no",comment:"交易号"}),Y("design:type",String)],z.prototype,"tradeNo",void 0),V([t({name:"duration",comment:"时长"}),Y("design:type",Number)],z.prototype,"duration",void 0),V([t({name:"title",comment:"商品名称"}),Y("design:type",String)],z.prototype,"title",void 0),V([t({name:"desc",comment:"商品描述"}),Y("design:type",String)],z.prototype,"desc",void 0),V([t({name:"num",comment:"商品数量"}),Y("design:type",Number)],z.prototype,"num",void 0),V([t({name:"price",comment:"单价"}),Y("design:type",Number)],z.prototype,"price",void 0),V([t({name:"amount",comment:"总价"}),Y("design:type",Number)],z.prototype,"amount",void 0),V([t({name:"remark",comment:"备注"}),Y("design:type",String)],z.prototype,"remark",void 0),V([t({name:"status",comment:"状态"}),Y("design:type",String)],z.prototype,"status",void 0),V([t({name:"pay_type",comment:"支付类型"}),Y("design:type",String)],z.prototype,"payType",void 0),V([t({name:"pay_time",comment:"支付时间"}),Y("design:type",Number)],z.prototype,"payTime",void 0),V([t({name:"pay_no",comment:"支付单号"}),Y("design:type",String)],z.prototype,"payNo",void 0),V([t({name:"end_time",comment:"结束时间"}),Y("design:type",Number)],z.prototype,"endTime",void 0),V([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Y("design:type",Date)],z.prototype,"createTime",void 0),V([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Y("design:type",Date)],z.prototype,"updateTime",void 0),z=V([i("cd_trade")],z);let Q=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.maxPipelineCount?t+="流水线无限制；":t+=`流水线${i.maxPipelineCount}个；`,-1===i.maxDeployCount?t+="部署次数无限制；":t+=`部署${i.maxDeployCount}次；`,t}};V([e(),Y("design:type",Number)],Q.prototype,"id",void 0),V([t({name:"icon",comment:"图标"}),Y("design:type",String)],Q.prototype,"icon",void 0),V([t({name:"title",comment:"套餐名称"}),Y("design:type",String)],Q.prototype,"title",void 0),V([t({name:"type",comment:"套餐类型，套餐/加量包,suite/addon"}),Y("design:type",String)],Q.prototype,"type",void 0),V([t({name:"content",comment:"套餐内容"}),Y("design:type",String)],Q.prototype,"content",void 0),V([t({name:"duration_prices",comment:"时长及单价"}),Y("design:type",String)],Q.prototype,"durationPrices",void 0),V([t({name:"duration",comment:"时长"}),Y("design:type",Number)],Q.prototype,"duration",void 0),V([t({name:"price",comment:"单价"}),Y("design:type",Number)],Q.prototype,"price",void 0),V([t({name:"intro",comment:"说明"}),Y("design:type",String)],Q.prototype,"intro",void 0),V([t({name:"order",comment:"排序"}),Y("design:type",Number)],Q.prototype,"order",void 0),V([t({name:"support_buy",comment:"是否支持购买",default:!0}),Y("design:type",Boolean)],Q.prototype,"supportBuy",void 0),V([t({name:"disabled",comment:"禁用启用"}),Y("design:type",Boolean)],Q.prototype,"disabled",void 0),V([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Y("design:type",Date)],Q.prototype,"createTime",void 0),V([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Y("design:type",Date)],Q.prototype,"updateTime",void 0),Q=H=V([i("cd_product")],Q);let K=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||"{}")}};V([e(),Y("design:type",Number)],K.prototype,"id",void 0),V([t({name:"user_id",comment:"用户ID"}),Y("design:type",Number)],K.prototype,"userId",void 0),V([t({name:"product_id",comment:"套餐ID"}),Y("design:type",Number)],K.prototype,"productId",void 0),V([t({name:"trade_id",comment:"订单id"}),Y("design:type",Number)],K.prototype,"tradeId",void 0),V([t({name:"icon",comment:"图标"}),Y("design:type",String)],K.prototype,"icon",void 0),V([t({name:"title",comment:"套餐名称"}),Y("design:type",String)],K.prototype,"title",void 0),V([t({name:"product_type",comment:"套餐类型，套餐/加量包,suite/addon"}),Y("design:type",String)],K.prototype,"productType",void 0),V([t({name:"content",comment:"套餐内容"}),Y("design:type",String)],K.prototype,"content",void 0),V([t({name:"duration",comment:"有效时长"}),Y("design:type",Number)],K.prototype,"duration",void 0),V([t({name:"deploy_count_used",comment:"已使用部署次数"}),Y("design:type",Number)],K.prototype,"deployCountUsed",void 0),V([t({name:"active_time",comment:"激活时间"}),Y("design:type",Number)],K.prototype,"activeTime",void 0),V([t({name:"expires_time",comment:"有效期"}),Y("design:type",Number)],K.prototype,"expiresTime",void 0),V([t({name:"disabled",comment:"启用/禁用",default:!1}),Y("design:type",Boolean)],K.prototype,"disabled",void 0),V([t({name:"is_present",comment:"是否赠送",default:!1}),Y("design:type",Boolean)],K.prototype,"isPresent",void 0),V([t({name:"is_bootstrap",comment:"是否初始套餐",default:!1}),Y("design:type",Boolean)],K.prototype,"isBootstrap",void 0),V([t({name:"is_empty",comment:"是否用完",default:!1}),Y("design:type",Boolean)],K.prototype,"isEmpty",void 0),V([t({name:"create_time",comment:"创建时间",default:()=>"CURRENT_TIMESTAMP"}),Y("design:type",Date)],K.prototype,"createTime",void 0),V([t({name:"update_time",comment:"修改时间",default:()=>"CURRENT_TIMESTAMP"}),Y("design:type",Date)],K.prototype,"updateTime",void 0),K=V([i("cd_user_suite")],K);let X=class extends P{repository;getRepository(){return this.repository}};V([I(Q),Y("design:type",s)],X.prototype,"repository",void 0),X=V([d(),u(y.Request,{allowDowngrade:!0})],X);class Z{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 ee=new Z;let te=class extends P{repository;myCountService;sysSettingsService;productService;getRepository(){return this.repository}async presentGiftSuite(e){if(null==e)return!1;if(!$())return!1;const t=await this.getSuiteSetting();return!!t&&(!!t.enabled&&(!!t.registerGift?.productId&&await M.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&&(R.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=j(),a=o.valueOf();let p=0;p=-1===t?-1:o.add(t,"day").endOf("day").valueOf();const d=new K;d.userId=i,d.productId=s.id,d.tradeId=r||0,d.icon="",d.title=s.title,d.productType=s.type,d.content=s.content,d.duration=t,d.deployCountUsed=0,d.disabled=!1,d.activeTime=a,d.expiresTime=p,d.isPresent=e.isPresent||!1,d.isBootstrap=e.isBootstrap||!1,d.isEmpty=!1,n?await n.save(d):await this.getRepository().save(d)}async getMySuiteDetail(e){const t=await this.sysSettingsService.getSetting(T);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=[];if(i.length>0)for(const e of i){a.push({id:e.id,productId:e.productId,duration:e.duration,title:e.title,expiresTime:e.expiresTime,productType:e.productType});const t=K.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.maxDeployCount?n.max=-1:n.max+=t.maxDeployCount??0,-1==o.max||-1==t.maxMonitorCount?o.max=-1:o.max+=t.maxMonitorCount??0,n.used+=e.deployCountUsed??0}const{pipelineCountUsed:p,domainCountUsed:d,monitorCountUsed:u}=await this.myCountService.getUsedCount(e);return s.used=p??0,r.used=d??0,o.used=u??0,{enabled:t.enabled,suites:a,expiresTime:0,pipelineCount:s,domainCount:r,deployCount:n,monitorCount:o}}async getMyValidSuiteList(e){if(null==e)throw new Error("用户ID不能为空");const t=j(),i=await this.getMyValidSuite(e,t),s=await this.getMyValidAddons(e,t);return i?[i,...s]:s}async getMyValidSuite(e,t){return 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"}})}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=K.getContent(e);if(-1==i.maxDeployCount||i.maxDeployCount>=e.deployCountUsed+t)return e}throw new x("部署次数不足，请购买加量包或升级套餐")}async consumeDeployCount(e,t){if(null==e)return;e.deployCountUsed+=t;const i=K.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(K).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(T)}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){A();if(!(await this.getSuiteSetting()).enabled)throw new Error("套餐功能未开启");const t=await this.productService.info(e.productId);if(!t)throw new Error("产品不存在");const i=Q.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})}};V([I(K),Y("design:type",s)],te.prototype,"repository",void 0),V([c("myCountService"),Y("design:type",Object)],te.prototype,"myCountService",void 0),V([c(),Y("design:type",N)],te.prototype,"sysSettingsService",void 0),V([c(),Y("design:type",X)],te.prototype,"productService",void 0),te=V([d("userSuiteService"),u(y.Request,{allowDowngrade:!0})],te);let ie=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:j().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=j(),r="T"+s.format("YYYYMMDD")+s.unix()+M.id.randomNumber(6),n=`购买${t.title} ${e.duration}天`,o=`内含：${Q.getContentStr(t)}`,a=new z;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(C);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(O))[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 ee.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(z,{id:t.id},{status:"paid",amount:e.amount,remark:e.remark,payNo:e.payNo,payTime:e.payTime||j().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(z,{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:j().valueOf()})}};V([I(z),Y("design:type",s)],ie.prototype,"repository",void 0),V([c(),Y("design:type",X)],ie.prototype,"productService",void 0),V([c(),Y("design:type",N)],ie.prototype,"sysSettingsService",void 0),V([c(),Y("design:type",F)],ie.prototype,"accessService",void 0),V([c(),Y("design:type",te)],ie.prototype,"userSuiteService",void 0),ie=V([d(),u(y.Request,{allowDowngrade:!0})],ie);let se=class{logger;async onReady(e){this.logger.info("commercial start")}};V([g(),Y("design:type",Object)],se.prototype,"logger",void 0),se=V([m({namespace:"commercial"})],se);let re=class extends E{sysSettingsService;async paymentGet(){const e=await this.sysSettingsService.getSetting(O);return this.ok(e)}async paymentSave(e){A();const t=new O;return G(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}async suiteGet(){const e=await this.sysSettingsService.getSetting(T);return this.ok(e)}async suiteSave(e){A();const t=new T;return G(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}async headerMenusGet(){const e=await this.sysSettingsService.getSetting(D);return this.ok(e)}async headerMenusSave(e){A();const t=new D;return G(t,e),await this.sysSettingsService.saveSetting(t),this.ok({})}};V([c(),Y("design:type",N)],re.prototype,"sysSettingsService",void 0),V([l("/payment/get",{description:"sys:settings:view"}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],re.prototype,"paymentGet",null),V([l("/payment/save",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],re.prototype,"paymentSave",null),V([l("/suite/get",{description:"sys:settings:view"}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],re.prototype,"suiteGet",null),V([l("/suite/save",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],re.prototype,"suiteSave",null),V([l("/headerMenus/get",{description:"sys:settings:view"}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],re.prototype,"headerMenusGet",null),V([l("/headerMenus/save",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],re.prototype,"headerMenusSave",null),re=V([d(),h("/api/sys/settings")],re);let ne=class extends E{sysSettingsService;fileService;async saveSiteInfo(e){A();let t=await this.sysSettingsService.getSetting(B);return null==t&&(t=new B),q.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(){A();const e=await this.sysSettingsService.getSetting(B);return this.ok(e)}};V([c(),Y("design:type",N)],ne.prototype,"sysSettingsService",void 0),V([c(),Y("design:type",_)],ne.prototype,"fileService",void 0),V([l("/save",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ne.prototype,"saveSiteInfo",null),V([l("/get",{description:"sys:settings:view"}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],ne.prototype,"getSiteInfo",null),ne=V([d(),h("/api/sys/site")],ne);let oe=class extends k{service;getService(){return A(),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()}};V([c(),Y("design:type",ie)],oe.prototype,"service",void 0),V([l("/page",{description:"sys:settings:view"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],oe.prototype,"page",null),V([l("/list",{description:"sys:settings:view"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],oe.prototype,"list",null),V([l("/add",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],oe.prototype,"add",null),V([l("/update",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],oe.prototype,"update",null),V([l("/info",{description:"sys:settings:view"}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],oe.prototype,"info",null),V([l("/delete",{description:"sys:settings:edit"}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],oe.prototype,"delete",null),V([l("/syncStatus",{description:"sys:settings:edit"}),W(0,v("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],oe.prototype,"syncStatus",null),V([l("/updatePaid",{description:"sys:settings:edit"}),W(0,v("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],oe.prototype,"updatePaid",null),V([l("/deleteByIds",{description:"sys:settings:edit"}),W(0,v("ids")),Y("design:type",Function),Y("design:paramtypes",[Array]),Y("design:returntype",Promise)],oe.prototype,"deleteByIds",null),oe=V([d(),h("/api/sys/suite/trade"),J(["sys-trade"])],oe);let ae=class extends k{service;getService(){return A(),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)}};V([c(),Y("design:type",X)],ae.prototype,"service",void 0),V([l("/page",{description:"sys:settings:view"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ae.prototype,"page",null),V([l("/list",{description:"sys:settings:view"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ae.prototype,"list",null),V([l("/add",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ae.prototype,"add",null),V([l("/update",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ae.prototype,"update",null),V([l("/info",{description:"sys:settings:view"}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],ae.prototype,"info",null),V([l("/delete",{description:"sys:settings:edit"}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],ae.prototype,"delete",null),V([l("/deleteByIds",{description:"sys:settings:edit"}),W(0,v("ids")),Y("design:type",Function),Y("design:paramtypes",[Array]),Y("design:returntype",Promise)],ae.prototype,"deleteByIds",null),ae=V([d(),h("/api/sys/suite/product"),J(["sys-product"])],ae);let pe=class extends k{getService(){return this.userSuiteService}productService;userSuiteService;sysSettingsService;async page(e){return A(),await super.page(e)}async list(e){return await super.list(e)}async add(e){return A(),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()}};V([c(),Y("design:type",X)],pe.prototype,"productService",void 0),V([c(),Y("design:type",te)],pe.prototype,"userSuiteService",void 0),V([c(),Y("design:type",N)],pe.prototype,"sysSettingsService",void 0),V([l("/page",{description:"sys:settings:view"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],pe.prototype,"page",null),V([l("/list",{description:"sys:settings:view"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],pe.prototype,"list",null),V([l("/add",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],pe.prototype,"add",null),V([l("/update",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],pe.prototype,"update",null),V([l("/info",{description:"sys:settings:view"}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],pe.prototype,"info",null),V([l("/delete",{description:"sys:settings:edit"}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],pe.prototype,"delete",null),V([l("/deleteByIds",{description:"sys:settings:edit"}),W(0,v("ids")),Y("design:type",Function),Y("design:paramtypes",[Array]),Y("design:returntype",Promise)],pe.prototype,"deleteByIds",null),V([l("/presentSuite",{description:"sys:settings:edit"}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],pe.prototype,"presentSuite",null),pe=V([d(),h("/api/sys/suite/user-suite"),J(["sys-user-suite"])],pe);let de=class extends E{productService;async list(){A();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 L(e,(e=>!0===e.isBootstrap)),this.ok(e)}};V([c(),Y("design:type",X)],de.prototype,"productService",void 0),V([l("/list",{description:U.per.authOnly}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],de.prototype,"list",null),de=V([d(),h("/api/suite/product"),J(["suite"])],de);let ue=class extends E{productService;tradeService;sysSettingsService;async create(e){A();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){A();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(O),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:p(e),userId:t}),this.ok()}};V([c(),Y("design:type",X)],ue.prototype,"productService",void 0),V([c(),Y("design:type",ie)],ue.prototype,"tradeService",void 0),V([c(),Y("design:type",N)],ue.prototype,"sysSettingsService",void 0),V([l("/create",{description:U.per.authOnly}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ue.prototype,"create",null),V([l("/createFree",{description:U.per.authOnly}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ue.prototype,"createFree",null),V([l("/info",{description:U.per.authOnly}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ue.prototype,"info",null),V([l("/page",{description:U.per.authOnly}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ue.prototype,"page",null),V([l("/payments",{description:U.per.authOnly}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],ue.prototype,"payments",null),V([l("/syncStatus",{description:U.per.authOnly}),W(0,v("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],ue.prototype,"syncStatus",null),V([l("/delete",{description:U.per.authOnly}),W(0,w("id")),Y("design:type",Function),Y("design:paramtypes",[Number]),Y("design:returntype",Promise)],ue.prototype,"delete",null),V([l("/deleteByIds",{description:U.per.authOnly}),W(0,v("ids")),Y("design:type",Function),Y("design:paramtypes",[Array]),Y("design:returntype",Promise)],ue.prototype,"deleteByIds",null),ue=V([d(),h("/api/suite/trade"),J(["suite"])],ue);let ye=class extends E{sysSettingsService;async get(){const e=await this.sysSettingsService.getSetting(T);return this.ok({intro:e.intro})}};V([c(),Y("design:type",N)],ye.prototype,"sysSettingsService",void 0),V([l("/get",{description:U.per.authOnly}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],ye.prototype,"get",null),ye=V([d(),h("/api/suite/settings"),J(["suite"])],ye);let ce=class extends E{productService;userSuiteService;sysSettingsService;async detail(){const e=await this.userSuiteService.getMySuiteDetail(this.getUserId());return this.ok(e)}async page(e){A(),e.query=e.query||{};e.query.userId=this.getUserId();const t=await this.userSuiteService.page(e);return this.ok(t)}};V([c(),Y("design:type",X)],ce.prototype,"productService",void 0),V([c(),Y("design:type",te)],ce.prototype,"userSuiteService",void 0),V([c(),Y("design:type",N)],ce.prototype,"sysSettingsService",void 0),V([l("/detail",{description:U.per.authOnly}),Y("design:type",Function),Y("design:paramtypes",[]),Y("design:returntype",Promise)],ce.prototype,"detail",null),V([l("/page",{description:U.per.authOnly}),W(0,v(S)),Y("design:type",Function),Y("design:paramtypes",[Object]),Y("design:returntype",Promise)],ce.prototype,"page",null),ce=V([d(),h("/api/mine/suite"),J(["suite"])],ce);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)}))}};V([c(),Y("design:type",ie)],ge.prototype,"tradeService",void 0),V([c(),Y("design:type",F)],ge.prototype,"accessService",void 0),V([c(),Y("design:type",N)],ge.prototype,"sysSettingsService",void 0),V([f("/:paymentType",{description:U.per.guest}),l("/:paymentType",{description:U.per.guest}),W(0,b("paymentType")),W(1,w(S)),W(2,v(S)),Y("design:type",Function),Y("design:paramtypes",[String,Object,Object]),Y("design:returntype",Promise)],ge.prototype,"onNotify",null),ge=V([d(),h("/api/payment/notify"),J(["suite"])],ge);const me=[K,Q,z];export{re as CommSysSettingsController,se as Configuration,ce as MySuiteController,ge as PaymentNotifyController,Z as PaymentProviderFactory,de as ProductController,Q as ProductEntity,X as ProductService,ye as SuiteSettingsController,ae as SysProductController,ne as SysSiteController,oe as SysTradeController,ue as TradeController,z as TradeEntity,ie as TradeService,pe as UserSuiteController,K as UserSuiteEntity,te as UserSuiteService,me as commercialEntities,ee as paymentProviderFactory};
