Esempio n. 1
0
File: item.go Progetto: zoe527/go2o
func (this *Item) SetValue(v *sale.ValueItem) error {
	if v.Id == this._value.Id {
		v.CreateTime = this._value.CreateTime
		v.GoodsNo = this._value.GoodsNo
		this._value = v
	}
	this._value.UpdateTime = time.Now().Unix()
	return nil
}
Esempio n. 2
0
File: sale.go Progetto: zoe527/go2o
func (this *Sale) CreateItem(v *sale.ValueItem) sale.IItem {
	if v.CreateTime == 0 {
		v.CreateTime = time.Now().Unix()
	}

	if v.UpdateTime == 0 {
		v.UpdateTime = v.CreateTime
	}

	//todo: 判断category

	return newItem(this, v, this._saleRep, this._saleTagRep, this._goodsRep, this._promRep)
}
Esempio n. 3
0
func (this *goodsC) SaveItem_post(ctx *web.Context) {
	partnerId := this.GetPartnerId(ctx)
	r, w := ctx.Request, ctx.Response
	var result gof.Message
	r.ParseForm()

	e := sale.ValueItem{}
	web.ParseFormToEntity(r.Form, &e)

	e.State = 1 //todo: 暂时使用

	id, err := dps.SaleService.SaveItem(partnerId, &e)

	if err != nil {
		result = gof.Message{Result: true, Message: err.Error()}
	} else {
		result = gof.Message{Result: true, Message: "", Data: id}
	}
	w.Write(result.Marshal())
}
Esempio n. 4
0
func (this *goodsC) SaveItem_post(ctx *web.Context) {
	partnerId := this.GetPartnerId(ctx)
	r := ctx.Request
	var result gof.Message
	r.ParseForm()

	e := sale.ValueItem{}
	web.ParseFormToEntity(r.Form, &e)

	e.State = 1 //todo: 暂时使用

	id, err := dps.SaleService.SaveItem(partnerId, &e)

	if err != nil {
		result.Message = err.Error()
	} else {
		result.Result = true
		result.Data = id
	}
	ctx.Response.JsonOutput(result)
}
Esempio n. 5
0
func (this *goodsC) Edit(ctx *web.Context) {
	partnerId := this.GetPartnerId(ctx)
	r, w := ctx.Request, ctx.Response
	var e *sale.ValueItem
	id, _ := strconv.Atoi(r.URL.Query().Get("item_id"))
	e = dps.SaleService.GetValueItem(partnerId, id)
	if e == nil {
		w.Write([]byte("商品不存在"))
		return
	}
	e.Description = ""
	js, _ := json.Marshal(e)

	shopChks := cache.GetShopCheckboxs(partnerId, e.ApplySubs)
	cateOpts := cache.GetDropOptionsOfCategory(partnerId)

	ctx.App.Template().Execute(w,
		gof.TemplateDataMap{
			"entity":    template.JS(js),
			"shop_chk":  template.HTML(shopChks),
			"cate_opts": template.HTML(cateOpts),
		},
		"views/partner/goods/update_goods.html")
}
Esempio n. 6
0
// 保存产品
func (this *saleService) SaveItem(partnerId int, v *sale.ValueItem) (int, error) {
	sl := this._rep.GetSale(partnerId)
	var pro sale.IItem
	if v.Id > 0 {
		pro = sl.GetItem(v.Id)
		if pro == nil {
			return 0, errors.New("产品不存在")
		}

		// 修改货品时,不会修改详情
		v.Description = pro.GetValue().Description

		if err := pro.SetValue(v); err != nil {
			return 0, err
		}
	} else {
		pro = sl.CreateItem(v)
	}
	return pro.Save()
}