Ejemplo n.º 1
0
func (this *listC) GetList(ctx *web.Context) {
	r, w := ctx.Request, ctx.ResponseWriter
	p := this.GetPartner(ctx)

	const getNum int = -1 //-1表示全部
	categoryId, _ := strconv.Atoi(r.URL.Query().Get("cid"))
	items := dps.SaleService.GetOnShelvesGoodsByCategoryId(p.Id, categoryId, getNum)
	if len(items) == 0 {
		w.Write([]byte(`无商品`))
		return
	}
	buf := bytes.NewBufferString("<ul>")

	for _, v := range items {

		buf.WriteString(fmt.Sprintf(`
			<li>
				<div class="gs_goodss">
                        <img src="%s" alt="%s"/>
                        <h3 class="name">%s%s</h3>
                        <span class="srice">原价:¥%s</span>
                        <span class="sprice">优惠价:¥%s</span>
                        <a href="javascript:cart.add(%d,1);" class="add">&nbsp;</a>
                </div>
             </li>
		`, format.GetGoodsImageUrl(v.Image), v.Name, v.Name, v.SmallTitle, format.FormatFloat(v.Price),
			format.FormatFloat(v.SalePrice),
			v.Id))
	}
	buf.WriteString("</ul>")
	w.Write(buf.Bytes())
}
Ejemplo n.º 2
0
// 商品列表
func (this *ListC) List_Index(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		p := this.BaseC.GetPartner(ctx)

		const size int = 20 //-1表示全部

		idArr := this.getIdArray(r.URL.Path)
		page, _ := strconv.Atoi(r.FormValue("page"))
		if page < 1 {
			page = 1
		}
		categoryId := idArr[len(idArr)-1]
		cat := dps.SaleService.GetCategory(p.Id, categoryId)

		total, items := dps.SaleService.GetPagedOnShelvesGoods(p.Id, categoryId, (page-1)*size, page*size)
		var pagerHtml string
		if total > size {
			pager := pager.NewUrlPager(pager.TotalPage(total, size), page, pager.GetterDefaultPager)
			pager.RecordCount = total
			pagerHtml = pager.PagerString()
		}

		buf := bytes.NewBufferString("")

		if len(items) == 0 {
			buf.WriteString("<div class=\"no_goods\">没有找到商品!</div>")
		} else {
			for i, v := range items {
				buf.WriteString(fmt.Sprintf(`
				<div class="item item-i%d">
					<div class="block">
						<a href="/item-%d.htm" class="goods-link">
							<img class="goods-img" src="%s" alt="%s"/>
							<h3 class="name">%s</h3>
							<span class="sale-price">¥%s</span>
							<span class="market-price"><del>¥%s</del></span>
						</a>
					</div>
                    <div class="clear-fix"></div>
                </div>
		`, i%2, v.GoodsId, format.GetGoodsImageUrl(v.Image),
					v.Name, v.Name, format.FormatFloat(v.SalePrice),
					format.FormatFloat(v.Price)))
			}
		}

		this.BaseC.ExecuteTemplate(ctx, gof.TemplateDataMap{
			"cat":   cat,
			"items": template.HTML(buf.Bytes()),
			"pager": template.HTML(pagerHtml),
		},
			"views/shop/ols/{device}/list.html",
			"views/shop/ols/{device}/inc/header.html",
			"views/shop/ols/{device}/inc/footer.html")
	}
}
Ejemplo n.º 3
0
// 商品详情
func (this *ListC) GoodsView(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		p := this.BaseC.GetPartner(ctx)
		path := r.URL.Path
		goodsId, _ := strconv.Atoi(path[strings.LastIndex(path, "-")+1 : strings.Index(path, ".")])

		m := this.BaseC.GetMember(ctx)
		var level int = 0
		if m != nil {
			level = m.Level
		}
		goods, proMap := dps.SaleService.GetGoodsDetails(p.Id, goodsId, level)
		goods.Image = format.GetGoodsImageUrl(goods.Image)

		// 促销价 & 销售价
		var promPrice string
		var salePrice string

		if goods.PromPrice < goods.SalePrice {
			promPrice = fmt.Sprintf(`<span class="prom-price">¥<b>%s</b></span>`, format.FormatFloat(goods.PromPrice))
			salePrice = fmt.Sprintf("<del>¥%s</del>", format.FormatFloat(goods.SalePrice))
		} else {
			salePrice = "¥" + format.FormatFloat(goods.SalePrice)
		}

		// 促销信息
		var promDescribe string
		var promCls string = "hidden"
		if len(proMap) != 0 {
			promCls = ""
			buf := bytes.NewBufferString("")
			var i int = 0
			for k, v := range proMap {
				i++
				buf.WriteString(fmt.Sprintf(`<div class="prom-box prom%d">
					<span class="bg_txt red">%s</span>:<span class="describe">%s</span></div>`, i, k, v))
			}
			promDescribe = buf.String()
		}

		this.BaseC.ExecuteTemplate(ctx, gof.TemplateDataMap{
			"goods":         goods,
			"promap":        proMap,
			"prom_price":    template.HTML(promPrice),
			"sale_price":    template.HTML(salePrice),
			"prom_describe": template.HTML(promDescribe),
			"prom_cls":      promCls,
		},
			"views/shop/ols/{device}/goods.html",
			"views/shop/ols/{device}/inc/header.html",
			"views/shop/ols/{device}/inc/footer.html")
	}
}
Ejemplo n.º 4
0
// 转换活动金到提现账户
func (this *accountC) Transfer_f2m(ctx *web.Context) {
	p := this.GetPartner(ctx)
	conf := this.GetSiteConf(p.Id)
	saleConf := dps.PartnerService.GetSaleConf(p.Id)
	m := this.GetMember(ctx)
	acc := dps.MemberService.GetAccount(m.Id)

	var commissionStr string
	if saleConf.FlowConvertCsn == 0 {
		commissionStr = "不收取手续费"
	} else {
		commissionStr = fmt.Sprintf("收取<i>%s%s</i>手续费",
			format.FormatFloat(saleConf.FlowConvertCsn*100), "%")
	}

	this.ExecuteTemplate(ctx, gof.TemplateDataMap{
		"conf":           conf,
		"partner":        p,
		"member":         m,
		"account":        acc,
		"commissionStr":  template.HTML(commissionStr),
		"flowAlias":      variable.AliasFlowAccount,
		"cns":            saleConf.TransCsn,
		"notSetTradePwd": len(m.TradePwd) == 0,
	}, "views/ucenter/{device}/account/transfer_f2m.html",
		"views/ucenter/{device}/inc/header.html",
		"views/ucenter/{device}/inc/menu.html",
		"views/ucenter/{device}/inc/footer.html")
}
Ejemplo n.º 5
0
func backCashForMember(m member.IMember, order *shopping.ValueOrder, fee int, refName string) error {
	//更新账户
	acc := m.GetAccount()
	acv := acc.GetValue()
	bFee := float32(fee)
	acv.PresentBalance += bFee // 更新赠送余额
	acv.TotalPresentFee += bFee
	acv.UpdateTime = time.Now().Unix()
	_, err := acc.Save()

	if err == nil {
		//给自己返现
		icLog := &member.IncomeLog{
			MemberId:   m.GetAggregateRootId(),
			OrderId:    order.Id,
			Type:       "backcash",
			Fee:        float32(fee),
			Log:        fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s", format.FormatFloat(bFee), order.OrderNo, refName),
			State:      1,
			RecordTime: acv.UpdateTime,
		}
		err = m.SaveIncomeLog(icLog)
	}
	return err
}
Ejemplo n.º 6
0
// 提现申请
func (this *accountC) Apply_cash(ctx *web.Context) {
	p := this.GetPartner(ctx)
	conf := this.GetSiteConf(p.Id)
	m := this.GetMember(ctx)
	acc := dps.MemberService.GetAccount(m.Id)
	saleConf := dps.PartnerService.GetSaleConf(p.Id)

	var latestInfo string = dps.MemberService.GetLatestApplyCashText(m.Id)
	if len(latestInfo) != 0 {
		latestInfo = "<div class=\"info\">" + latestInfo + "</div>"
	}

	var maxApplyAmount int
	if acc.PresentBalance < float32(minAmount) {
		maxApplyAmount = 0
	} else {
		maxApplyAmount = int(acc.PresentBalance)
	}

	var commissionStr string
	if saleConf.ApplyCsn == 0 {
		commissionStr = "不收取手续费"
	} else {
		commissionStr = fmt.Sprintf("收取<i>%s%s</i>手续费",
			format.FormatFloat(saleConf.ApplyCsn*100), "%")
	}

	this.ExecuteTemplate(ctx, gof.TemplateDataMap{
		"conf":           conf,
		"partner":        p,
		"member":         m,
		"minAmount":      format.FormatFloat(float32(minAmount)),
		"maxApplyAmount": maxApplyAmount,
		"account":        acc,
		"latestInfo":     template.HTML(latestInfo),
		"commissionStr":  template.HTML(commissionStr),
		"presentAlias":   variable.AliasFlowAccount,
		"cns":            saleConf.ApplyCsn,
		"notSetTradePwd": len(m.TradePwd) == 0,
	}, "views/ucenter/{device}/account/apply_cash.html",
		"views/ucenter/{device}/inc/header.html",
		"views/ucenter/{device}/inc/menu.html",
		"views/ucenter/{device}/inc/footer.html")
}
Ejemplo n.º 7
0
// 获取商品详情
func (this *saleService) GetGoodsDetails(partnerId, goodsId, mLevel int) (*valueobject.Goods, map[string]string) {
	sl := this._rep.GetSale(partnerId)
	var goods sale.IGoods = sl.GetGoods(goodsId)
	gv := goods.GetPackedValue()
	proMap := goods.GetPromotionDescribe()
	if b, price := goods.GetLevelPrice(mLevel); b {
		gv.PromPrice = price
		proMap["会员专享"] = fmt.Sprintf("会员优惠,仅需<b>¥%s</b>",
			format.FormatFloat(price))
	}
	return gv, proMap
}
Ejemplo n.º 8
0
func (this *listC) GetList(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	p := this.GetPartner(ctx)
	pa := this.GetPartnerApi(ctx)

	const getNum int = -1 //-1表示全部
	categoryId, err := strconv.Atoi(r.URL.Query().Get("cid"))
	if err != nil {
		w.Write([]byte(`{"error":"yes"}`))
		return
	}
	items, err := goclient.Partner.GetItems(p.Id, pa.ApiSecret, categoryId, getNum)
	if err != nil {
		w.Write([]byte(`{"error":"` + err.Error() + `"}`))
		return
	}
	buf := bytes.NewBufferString("<ul>")

	for _, v := range items {

		buf.WriteString(fmt.Sprintf(`
			<li>
				<div class="gs_goodss">
                        <img src="%s" alt="%s"/>
                        <h3 class="name">%s%s</h3>
                        <span class="srice">原价:¥%s</span>
                        <span class="sprice">优惠价:¥%s</span>
                        <a href="javascript:cart.add(%d,1);" class="add">&nbsp;</a>
                </div>
             </li>
		`, format.GetGoodsImageUrl(v.Image), v.Name, v.Name, v.SmallTitle, format.FormatFloat(v.Price),
			format.FormatFloat(v.SalePrice),
			v.Id))
	}
	buf.WriteString("</ul>")
	w.Write(buf.Bytes())
}
Ejemplo n.º 9
0
func backCashForMember(m member.IMember, order *shopping.ValueOrder,
	fee int, refName string) error {
	//更新账户
	acc := m.GetAccount()
	acv := acc.GetValue()
	bFee := float32(fee)
	acv.PresentBalance += bFee // 更新赠送余额
	acv.TotalPresentFee += bFee
	acv.UpdateTime = time.Now().Unix()
	_, err := acc.Save()

	if err == nil {
		tit := fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s",
			format.FormatFloat(bFee), order.OrderNo, refName)
		err = acc.PresentBalance(tit, order.OrderNo, float32(fee))
	}
	return err
}
Ejemplo n.º 10
0
func (this *goodsC) LvPrice(ctx *web.Context) {
	partnerId := this.GetPartnerId(ctx)
	//todo: should be goodsId
	itemId, _ := strconv.Atoi(ctx.Request.URL.Query().Get("item_id"))
	goods := dps.SaleService.GetGoodsBySku(partnerId, itemId, 0)
	lvs := dps.PartnerService.GetMemberLevels(partnerId)
	var prices []*sale.MemberPrice = dps.SaleService.GetGoodsLevelPrices(partnerId, goods.GoodsId)

	var buf *bytes.Buffer = bytes.NewBufferString("")

	var fmtFunc = func(level int, levelName string, id int, price float32, enabled int) {
		buf.WriteString(fmt.Sprintf(`
		<tr>
                <td><input type="hidden" field="Id_%d" value="%d"/>
                    %s</td>
                <td align="center"><input type="number" field="Price_%d" value="%s"/></td>
                <td align="center"><input type="checkbox" field="Enabled_%d" %s/></td>
            </tr>
		`, level, id, levelName, level, format.FormatFloat(price), level,
			gfmt.BoolString(enabled == 1, "checked=\"checked\"", "")))
	}

	var b bool
	for _, v := range lvs {
		b = false
		for _, v1 := range prices {
			if v.Value == v1.Level {
				fmtFunc(v.Value, v.Name, v1.Id, v1.Price, v1.Enabled)
				b = true
				break
			}
		}
		if !b {
			fmtFunc(v.Value, v.Name, 0, goods.SalePrice, 0)
		}
	}

	ctx.App.Template().Execute(ctx.Response, gof.TemplateDataMap{
		"goods":   goods,
		"setHtml": template.HTML(buf.String()),
	}, "views/partner/goods/level_price.html")
}
Ejemplo n.º 11
0
func (this *promC) Edit_cb(ctx *web.Context) {
	form := ctx.Request.URL.Query()
	id, _ := strconv.Atoi(form.Get("id"))
	e, e2 := dps.PromService.GetPromotion(id)

	js, _ := json.Marshal(e)
	js2, _ := json.Marshal(e2)

	var goodsInfo string
	goods := dps.SaleService.GetValueGoods(this.GetPartnerId(ctx), e.GoodsId)
	goodsInfo = fmt.Sprintf("%s<span>(销售价:%s)</span>", goods.Name, format.FormatFloat(goods.SalePrice))

	ctx.App.Template().Execute(ctx.Response,
		gof.TemplateDataMap{
			"entity":     template.JS(js),
			"entity2":    template.JS(js2),
			"goods_info": template.HTML(goodsInfo),
			"goods_cls":  "",
		},
		"views/partner/promotion/cash_back.html")
}
Ejemplo n.º 12
0
// 获取最近的提现描述
func (this *memberService) GetLatestApplyCashText(memberId int) string {
	var latestInfo string
	latestApplyInfo := this.GetLatestApplyCash(memberId)
	if latestApplyInfo != nil {
		var sText string
		switch latestApplyInfo.State {
		case 0:
			sText = "已申请"
		case 1:
			sText = "已审核,等待打款"
		case 2:
			sText = "被退回"
		case 3:
			sText = "已完成"
		}
		latestInfo = fmt.Sprintf(`<b>最近提现:</b>%s&nbsp;申请提现%s ,状态:<span class="status">%s</span>。`,
			time.Unix(latestApplyInfo.CreateTime, 0).Format("2006-01-02 15:04"),
			format.FormatFloat(latestApplyInfo.Amount),
			sText)
	}
	return latestInfo
}
Ejemplo n.º 13
0
// 获取最近的提现描述
func (this *memberService) GetLatestApplyCashText(memberId int) string {
	var latestInfo string
	latestApplyInfo := this.GetLatestApplyCash(memberId)
	if latestApplyInfo != nil {
		var sText string
		switch latestApplyInfo.State {
		case 0:
			sText = "已提交"
		case 1:
			sText = "已审核"
		case 2:
			sText = "被退回"
		case 3:
			sText = "已完成"
		}
		latestInfo = fmt.Sprintf("您于%s申请提现%s,%s。",
			time.Unix(latestApplyInfo.CreateTime, 0).Format("2006-01-02 15:04:05"),
			format.FormatFloat(latestApplyInfo.Amount),
			sText)
	}
	return latestInfo
}
Ejemplo n.º 14
0
func (this *accountC) Apply_cash_post(ctx *web.Context) {
	var msg gof.Message
	var err error
	ctx.Request.ParseForm()
	partnerId := this.GetPartner(ctx).Id
	amount, _ := strconv.ParseFloat(ctx.Request.FormValue("Amount"), 32)
	tradePwd := ctx.Request.FormValue("TradePwd")
	if amount < minAmount {
		err = errors.New(fmt.Sprintf("必须达到最低提现金额:%s元",
			format.FormatFloat(float32(minAmount))))
	} else {
		m := this.GetMember(ctx)
		err = dps.MemberService.SubmitApplyCash(partnerId, m.Id, tradePwd, member.TypeApplyCashToBank, float32(amount))
	}

	if err != nil {
		msg.Message = err.Error()
	} else {
		msg.Result = true
	}
	ctx.Response.JsonOutput(msg)
}
Ejemplo n.º 15
0
func (this *accountC) Apply_cash_post(ctx *web.Context) {
	var msg gof.Message
	var err error
	ctx.Request.ParseForm()
	partnerId := this.GetPartner(ctx).Id
	amount, _ := strconv.ParseFloat(ctx.Request.FormValue("Amount"), 32)
	tradePwd := ctx.Request.FormValue("TradePwd")
	memberId := this.GetMember(ctx).Id
	saleConf := dps.PartnerService.GetSaleConf(partnerId)
	bank := dps.MemberService.GetBank(memberId)

	if bank == nil || len(bank.Account) == 0 || len(bank.AccountName) == 0 ||
		len(bank.Network) == 0 {
		err = errors.New("请先设置收款银行信息")
		goto toErr
	}

	if _, err = dps.MemberService.VerifyTradePwd(memberId, tradePwd); err != nil {
		goto toErr
	}

	if amount < minAmount {
		err = errors.New(fmt.Sprintf("必须达到最低提现金额:%s元",
			format.FormatFloat(float32(minAmount))))
	} else {
		m := this.GetMember(ctx)
		err = dps.MemberService.SubmitApplyPresentBalance(partnerId, m.Id,
			member.TypeApplyCashToBank, float32(amount), saleConf.ApplyCsn)
	}

toErr:
	if err != nil {
		msg.Message = err.Error()
	} else {
		msg.Result = true
	}
	ctx.Response.JsonOutput(msg)
}
Ejemplo n.º 16
0
func (this *accountC) Apply_cash(ctx *web.Context) {
	p := this.GetPartner(ctx)
	conf := this.GetSiteConf(p.Id)
	m := this.GetMember(ctx)
	acc := dps.MemberService.GetAccount(m.Id)

	var latestInfo string = dps.MemberService.GetLatestApplyCashText(m.Id)
	if len(latestInfo) != 0 {
		latestInfo = "<div class=\"info\">" + latestInfo + "</div>"
	}
	this.ExecuteTemplate(ctx, gof.TemplateDataMap{
		"conf":           conf,
		"partner":        p,
		"member":         m,
		"minAmount":      format.FormatFloat(float32(minAmount)),
		"account":        acc,
		"latestInfo":     template.HTML(latestInfo),
		"notSetTradePwd": len(m.TradePwd) == 0,
	}, "views/ucenter/{device}/account/apply_cash.html",
		"views/ucenter/{device}/inc/header.html",
		"views/ucenter/{device}/inc/menu.html",
		"views/ucenter/{device}/inc/footer.html")
}
Ejemplo n.º 17
0
// 销售标签列表
func (this *ListC) SaleTagGoodsList(ctx *web.Context) {
	if this.BaseC.Requesting(ctx) {
		r := ctx.Request
		p := this.BaseC.GetPartner(ctx)

		const size int = 20
		page, _ := strconv.Atoi(r.FormValue("page"))
		if page < 1 {
			page = 1
		}
		i := strings.LastIndex(r.URL.Path, "/")
		tagCode := r.URL.Path[i+1:]

		saleTag := dps.SaleService.GetSaleTagByCode(p.Id, tagCode)
		if saleTag == nil {
			http.Error(ctx.Response.ResponseWriter, "404 file not found!", http.StatusNotFound)
			ctx.Response.WriteHeader(404)
			return
		}

		total, items := dps.SaleService.GetPagedValueGoodsBySaleTag(p.Id, saleTag.Id, (page-1)*size, page*size)
		var pagerHtml string
		if total > size {
			pager := pager.NewUrlPager(pager.TotalPage(total, size), page, pager.GetterDefaultPager)
			pager.RecordCount = total
			pagerHtml = pager.PagerString()
		}

		buf := bytes.NewBufferString("")

		if len(items) == 0 {
			buf.WriteString("<div class=\"no_goods\">没有找到商品!</div>")
		} else {
			for i, v := range items {
				buf.WriteString(fmt.Sprintf(`
				<div class="item item-i%d">
					<div class="block">
						<a href="/goods-%d.htm" class="goods-link">
							<img class="goods-img" src="%s" alt="%s"/>
							<h3 class="name">%s</h3>
							<span class="sale-price">¥%s</span>
							<span class="market-price"><del>¥%s</del></span>
						</a>
					</div>
                    <div class="clear-fix"></div>
                </div>
		`, i%2, v.GoodsId, format.GetGoodsImageUrl(v.Image),
					v.Name, v.Name, format.FormatFloat(v.SalePrice),
					format.FormatFloat(v.Price)))
			}
		}

		this.BaseC.ExecuteTemplate(ctx, gof.TemplateDataMap{
			"sale_tag": saleTag,
			"items":    template.HTML(buf.Bytes()),
			"pager":    template.HTML(pagerHtml),
		},
			"views/shop/ols/{device}/sale_tag.html",
			"views/shop/ols/{device}/inc/header.html",
			"views/shop/ols/{device}/inc/footer.html")
	}
}