You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.6 KiB
67 lines
2.6 KiB
package console
|
|
|
|
import (
|
|
"yunyan/comm"
|
|
"yunyan/lego/sys/postgres"
|
|
)
|
|
|
|
// AppGoods 应用内购商品配置。结构定义在 comm(见 comm/appgoods.go)——这张表由本后台维护、
|
|
// 业务侧 pay 模块发货时按应用名读取,两边共用同一份结构,故上移到 comm,这里保留别名不动调用方。
|
|
//
|
|
// 与旧方案的关系:商品原本落在**各应用业务库**的 goods 表(pb.DBGoods,由 api 模块的
|
|
// api_getgoodss/api_addgoods 等接口维护)。本版把配置口径统一收到后台公共库,
|
|
// 字段与 pb.DBGoods 一一对应(多出 AppName/Sort/Remark/时间戳)。
|
|
// 业务侧读取现状:PayPal 通知 v2(pay_paypalnotifyv2)已改读本表发货;
|
|
// 其余支付渠道与 api_getgoodss 仍读各自业务库的 goods 表,逐步迁移。
|
|
type AppGoods = comm.AppGoods
|
|
|
|
// ---- 商品表 CRUD(console 主库 postgres,与 app_product 同库同套 helper)----
|
|
|
|
// listGoods 列出某应用的全部商品(sort 升序,其次 id)。appName 为空返回空列表——
|
|
// 商品必须挂在具体应用下,没有「全局商品」这一档。
|
|
func (this *modelComp) listGoods(appName string) (models []*AppGoods, err error) {
|
|
models = make([]*AppGoods, 0)
|
|
if appName == "" {
|
|
return
|
|
}
|
|
err = postgres.Table(comm.TableAppGoods).Where("app_name=?", appName).Order("sort ASC, id ASC").Find(&models).Error
|
|
return
|
|
}
|
|
|
|
// getGoods 按主键取商品。
|
|
func (this *modelComp) getGoods(id uint32) (model *AppGoods, err error) {
|
|
model = &AppGoods{}
|
|
err = postgres.FindOne(comm.TableAppGoods, model, "id=?", id)
|
|
return
|
|
}
|
|
|
|
// getGoodsByGid 按 (应用, 商品标识) 取商品,用于查重。不存在返回 (nil,nil)。
|
|
func (this *modelComp) getGoodsByGid(appName, goodsId string) (*AppGoods, error) {
|
|
model := &AppGoods{}
|
|
err := postgres.FindOne(comm.TableAppGoods, model, "app_name=? AND goods_id=?", appName, goodsId)
|
|
if err != nil {
|
|
if err == postgres.ErrNoDocuments {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|
|
|
|
// addGoods 新增商品(Insert 后 model.Id 被回填)。
|
|
func (this *modelComp) addGoods(model *AppGoods) (err error) {
|
|
err = postgres.Insert(comm.TableAppGoods, model)
|
|
return
|
|
}
|
|
|
|
// saveGoods 更新商品。
|
|
func (this *modelComp) saveGoods(model *AppGoods) (err error) {
|
|
err = postgres.Save(comm.TableAppGoods, model)
|
|
return
|
|
}
|
|
|
|
// delGoods 按 id 批量删除某应用的商品(带 app_name 条件,防跨应用误删)。
|
|
func (this *modelComp) delGoods(appName string, ids []uint32) (err error) {
|
|
err = postgres.Delete(comm.TableAppGoods, "app_name=? AND id IN ?", appName, ids)
|
|
return
|
|
}
|
|
|