func getHostRegexp() *regexp.Regexp { if commHostRegexp == nil { commHostRegexp = regexp.MustCompile("([^.]+)." + infrastructure.GetApp().Config().GetString(variable.ServerDomain)) } return commHostRegexp }
func PrintErr(err error) { _, f, line, _ := runtime.Caller(1) if err != nil && infrastructure.DebugMode { infrastructure.GetApp().Log().Println( fmt.Sprintf("[ERROR]:%s , File:%s line:%d", err.Error(), f, line)) } }
// 获取商户的域名 func (this *Partner) GetMajorHost() string { if len(this._host) == 0 { host := this._rep.GetPartnerMajorHost(this.GetAggregateRootId()) if len(host) == 0 { host = fmt.Sprintf("%s.%s", this._value.Usr, infrastructure.GetApp(). Config().GetString(variable.ServerDomain)) } this._host = host } return this._host }
// 获取站点配置 func (this *partnerRep) GetSiteConf(partnerId int) *partner.SiteConf { var siteConf partner.SiteConf if err := this.Connector.GetOrm().Get(partnerId, &siteConf); err == nil { if len(siteConf.Host) == 0 { var usr string this.Connector.ExecScalar( `SELECT usr FROM pt_partner WHERE id=?`, &usr, partnerId) siteConf.Host = fmt.Sprintf("%s.%s", usr, infrastructure.GetApp().Config(). GetString(variable.ServerDomain)) } return &siteConf } return nil }
// 获取商品图片地址 func GetGoodsImageUrl(image string) string { if !picCfgLoaded { ctx := infrastructure.GetApp() if len(imageServe) == 0 { imageServe = ctx.Config().GetString(variable.ImageServer) } if len(noPicUrl) == 0 { noPicUrl = ctx.Config().GetString(variable.StaticServer) + "/" + ctx.Config().GetString(variable.NoPicPath) } picCfgLoaded = true } if len(image) == 0 { return noPicUrl } return imageServe + "/" + image }
// 自动设置订单 func (this *Shopping) OrderAutoSetup(f func(error)) { var orders []*shopping.ValueOrder var err error log.Println("[SETUP] start auto setup") saleConf := this._partner.GetSaleConf() if saleConf.AutoSetupOrder == 1 { ctx := infrastructure.GetApp() orders, err = this._rep.GetWaitingSetupOrders(this._partnerId) if err != nil { f(err) return } dt := time.Now() for _, v := range orders { this.setupOrder(ctx, v, &saleConf, dt, f) } } }
// 获取商品图片地址 func GetGoodsImageUrl(image string) string { if !picCfgLoaded { ctx := infrastructure.GetApp() if len(imageServe) == 0 { imageServe = ctx.Config().GetString(variable.ImageServer) } if len(noPicUrl) == 0 { noPicUrl = imageServe + "/" + ctx.Config().GetString(variable.NoPicPath) } picCfgLoaded = true } if len(image) == 0 { return noPicUrl } if strings.HasPrefix(image, "http://") || strings.HasPrefix(image, "https://") { return image } return imageServe + "/" + image }
// 完成订单 func (this *Order) Complete() error { now := time.Now().Unix() v := this._value m := this._memberRep.GetMember(v.MemberId) if m == nil { return member.ErrNoSuchMember } var err error var ptl partner.IPartner ptl, err = this._partnerRep.GetPartner(v.PartnerId) if err != nil { log.Println("供应商异常!", v.PartnerId) log.PrintErr(err) return err } pv := ptl.GetValue() if pv.ExpiresTime < time.Now().Unix() { return errors.New("您的账户已经过期!") } // 增加经验 if EXP_BIT == 0 { fv := infrastructure.GetApp().Config().GetFloat(variable.EXP_BIT) if fv <= 0 { panic("[WANNING]:Exp_bit not set!") } EXP_BIT = float32(fv) } if err = m.AddExp(int(v.Fee * EXP_BIT)); err != nil { return err } // 更新账户 updateAccountForOrder(m, this) //******* 返现到账户 ************ var back_fee float32 saleConf := ptl.GetSaleConf() if saleConf.CashBackPercent > 0 { back_fee = v.Fee * saleConf.CashBackPercent //将此次消费记入会员账户 this.updateShoppingMemberBackFee(ptl, m, back_fee*saleConf.CashBackMemberPercent, now) //todo: 增加阶梯的返积分,比如订单满30送100积分 backIntegral := int(v.Fee)*saleConf.IntegralBackNum + saleConf.IntegralBackExtra // 赠送积分 if backIntegral != 0 { err = m.AddIntegral(v.PartnerId, enum.INTEGRAL_TYPE_ORDER, backIntegral, fmt.Sprintf("订单返积分%d个", backIntegral)) if err != nil { return err } } } this._value.Status = enum.ORDER_COMPLETED this._value.IsSuspend = 0 this._value.UpdateTime = now _, err = this.Save() if err == nil { err = this.AppendLog(enum.ORDER_LOG_SETUP, false, "订单已完成") // 处理返现促销 this.handleCashBackPromotions(ptl, m) // 三级返现 if back_fee > 0 { this.backFor3R(ptl, m, back_fee, now) } } return err }
// 完成订单 func (this *Order) Complete() error { now := time.Now().Unix() v := this._value m, err := this._memberRep.GetMember(v.MemberId) if err == nil { var ptl partner.IPartner ptl, err = this._partnerRep.GetPartner(v.PartnerId) if err != nil { log.Println("供应商异常!", v.PartnerId) log.PrintErr(err) return err } pv := ptl.GetValue() if pv.ExpiresTime < time.Now().Unix() { return errors.New("您的账户已经过期!") } //返现比例 saleConf := ptl.GetSaleConf() back_fee := v.Fee * saleConf.CashBackPercent //将此次消费记入会员账户 this.updateShoppingMemberAccount(ptl, m, back_fee*saleConf.CashBackMemberPercent, now) //todo: 增加阶梯的返积分,比如订单满30送100积分 backIntegral := int(v.Fee)*saleConf.IntegralBackNum + saleConf.IntegralBackExtra //判断是否满足升级条件 if backIntegral != 0 { err = m.AddIntegral(v.PartnerId, enum.INTEGRAL_TYPE_ORDER, backIntegral, fmt.Sprintf("订单返积分%d个", backIntegral)) if err != nil { return err } } // 增加经验 if EXP_BIT == 0 { fv := infrastructure.GetApp(). Config().GetFloat(variable.EXP_BIT) EXP_BIT = float32(fv) } if EXP_BIT == 0 { log.Println("[WANNING]:Exp_bit not set!") } err = m.AddExp(int(v.Fee * EXP_BIT)) if err != nil { return err } // 三级返现 this.backFor3R(ptl, m, back_fee, now) this._value.Status = enum.ORDER_COMPLETED this._value.IsSuspend = 0 this._value.UpdateTime = now _, err := this.Save() if err == nil { err = this.AppendLog(enum.ORDER_LOG_SETUP, false, "订单已完成") } } return err }
func Printf(s string, v ...interface{}) { if infrastructure.DebugMode { infrastructure.GetApp().Log().Printf(s, v...) } }