DengBiao 1 год назад
Родитель
Сommit
610e92531c
7 измененных файлов: 171 добавлений и 104 удалений
  1. +117
    -0
      app/db/db_mall_ord_item.go
  2. +29
    -0
      app/db/model/mall_ord_item.go
  3. +0
    -104
      app/svc/svc_file_img_upload.go
  4. +1
    -0
      consume/canal_guide_order_consume.go
  5. +22
    -0
      consume/canal_order_consume.go
  6. +1
    -0
      consume/md/md_canal_guide_order_consume.go
  7. +1
    -0
      es/md/es_struct.go

+ 117
- 0
app/db/db_mall_ord_item.go Просмотреть файл

@@ -0,0 +1,117 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"applet/app/utils/logx"
"errors"
"fmt"
"reflect"
"xorm.io/xorm"
)

// BatchSelectMallOrdItems 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `MallOrdItemFindByParams` 方法
func BatchSelectMallOrdItems(Db *xorm.Engine, params map[string]interface{}) (*[]model.MallOrdItem, error) {
var MallOrdItemData []model.MallOrdItem
if err := Db.In(utils.AnyToString(params["key"]), params["value"]).
Find(&MallOrdItemData); err != nil {
return nil, logx.Warn(err)
}
return &MallOrdItemData, nil
}

// MallOrdItemInsert 插入单条数据
func MallOrdItemInsert(Db *xorm.Engine, MallOrdItem *model.MallOrdItem) (int64, error) {
_, err := Db.InsertOne(MallOrdItem)
if err != nil {
return 0, err
}
return MallOrdItem.OrdId, nil
}

// BatchAddMallOrdItems 批量新增数据
func BatchAddMallOrdItems(Db *xorm.Engine, MallOrdItemData []*model.MallOrdItem) (int64, error) {
affected, err := Db.Insert(MallOrdItemData)
if err != nil {
return 0, err
}
return affected, nil
}

func GetMallOrdItemCount(Db *xorm.Engine) int {
var MallOrdItem model.MallOrdItem
session := Db.Where("")
count, err := session.Count(&MallOrdItem)
if err != nil {
return 0
}
return int(count)
}

// MallOrdItemDelete 删除记录
func MallOrdItemDelete(Db *xorm.Engine, id interface{}) (int64, error) {
if reflect.TypeOf(id).Kind() == reflect.Slice {
return Db.In("id", id).Delete(model.MallOrdItem{})
} else {
return Db.Where("id = ?", id).Delete(model.MallOrdItem{})
}
}

// MallOrdItemUpdate 更新记录
func MallOrdItemUpdate(Db *xorm.Engine, id interface{}, MallOrdItem *model.MallOrdItem, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(MallOrdItem)
} else {
affected, err = Db.Where("id=?", id).Update(MallOrdItem)
}
if err != nil {
return 0, err
}
return affected, nil
}

// MallOrdItemGetOneByParams 通过传入的参数查询数据(单条)
func MallOrdItemGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.MallOrdItem, error) {
var m model.MallOrdItem
var query = fmt.Sprintf("%s =?", params["key"])
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false {
return nil, logx.Error(err)
}
return &m, nil
}

// MallOrdItemFindByParams 通过传入的参数查询数据(多条)
func MallOrdItemFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.MallOrdItem, error) {
var m []model.MallOrdItem
if params["value"] == nil {
return nil, errors.New("参数有误")
}
if params["key"] == nil {
//查询全部数据
err := Db.Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
} else {
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice {
//指定In查询
if err := Db.In(utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil {
return nil, logx.Warn(err)
}
return &m, nil
} else {
var query = fmt.Sprintf("%s =?", params["key"])
err := Db.Where(query, params["value"]).Find(&m)
if err != nil {
return nil, logx.Error(err)
}
return &m, nil
}

}
}

+ 29
- 0
app/db/model/mall_ord_item.go Просмотреть файл

@@ -0,0 +1,29 @@
package model

import (
"time"
)

type MallOrdItem struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
OrdId int64 `json:"ord_id" xorm:"comment('订单id') BIGINT(20)"`
GoodsCopy string `json:"goods_copy" xorm:"comment('商品快照') TEXT"`
GoodsNum int `json:"goods_num" xorm:"comment('件数') INT(11)"`
OriginPrice string `json:"origin_price" xorm:"comment('商品金额(原价,乘以件数后的)') DECIMAL(12,2)"`
GoodsPrice string `json:"goods_price" xorm:"comment('商品金额(实付价,乘以件数后的)') DECIMAL(12,2)"`
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"`
GoodsImg string `json:"goods_img" xorm:"comment('商品图片') VARCHAR(255)"`
CouponDiscount string `json:"coupon_discount" xorm:"not null default 0.00 comment('优惠券折扣额') DECIMAL(12,2)"`
DiscountPrice string `json:"discount_price" xorm:"not null default 0.00 comment('立减') DECIMAL(12,2)"`
ReturnInsuranceFee string `json:"return_insurance_fee" xorm:"not null default 0.00 comment('退货无忧费用') DECIMAL(12,2)"`
ShippingFee string `json:"shipping_fee" xorm:"not null default 0.00 comment('运费') DECIMAL(12,2)"`
CreateTime time.Time `json:"create_time" xorm:"created not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateTime time.Time `json:"update_time" xorm:"updated not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
SkuId int64 `json:"sku_id" xorm:"comment('sku') BIGINT(20)"`
SkuText string `json:"sku_text" xorm:"not null comment('sku文字显示') VARCHAR(1024)"`
GoodsId int `json:"goods_id" xorm:"not null comment('商品id') INT(11)"`
SupplierPrice string `json:"supplier_price" xorm:"not null comment('') VARCHAR(100)"`
SupplierAddPrice string `json:"supplier_add_price" xorm:"not null comment('') VARCHAR(100)"`
SupplierMerchantName string `json:"supplier_merchant_name" xorm:"not null comment('') VARCHAR(100)"`
SupplierGoodsId string `json:"supplier_goods_id" xorm:"not null comment('') VARCHAR(100)"`
}

+ 0
- 104
app/svc/svc_file_img_upload.go Просмотреть файл

@@ -1,104 +0,0 @@
package svc

import (
"fmt"
"strings"

"applet/app/e"
"applet/app/lib/qiniu"
"applet/app/md"
"applet/app/utils"
"applet/app/utils/logx"

"github.com/gin-gonic/gin"
)

// 请求文件上传
func ImgReqUpload(c *gin.Context, uid, dirName, fname, callbackUrl string, fsize int64) (interface{}, error) {
ext := utils.FileExt(fname)
if err := initStg(c, fsize, ext); err != nil {
return nil, err
}
// logx.Warn(uid)
newName := dirName + "_" + fmt.Sprintf("%010s", uid)

// if dirName == md.FILE_DIR_FEEDBACK || dirName == md.FILE_DIR_STYLE {
// newName += "_" + utils.FormatNanoUnix() + utils.RandString(4, "0123456789")
// }
// 默认都加时间戳
newName += "_" + utils.FormatNanoUnix() + utils.RandString(4, "0123456789")
newName += ".png" // 因为可能存在多种图像格式,这里统一后缀为png

f := &md.FileCallback{
Uid: uid,
DirId: md.FileUserDir[dirName],
FileName: newName,
}
// logx.Warn(f.Uid)
return qiniu.ReqImgUpload(f, callbackUrl), nil
}

func initStg(c *gin.Context, fsize int64, ext string) error {
// 获取上传配置
stgInfo := SysCfgFind(
c,
md.KEY_CFG_FILE_BUCKET,
md.KEY_CFG_FILE_HOST,
md.KEY_CFG_FILE_AK,
md.KEY_CFG_FILE_SK,
md.KEY_CFG_FILE_PVD,
md.KEY_CFG_FILE_REGION,
md.KEY_CFG_FILE_MAX_SIZE,
md.KEY_CFG_FILE_EXT,
md.KEY_CFG_FILE_SCHEME,
md.KEY_CFG_FILE_AVATAR_THUMBNAIL,
)
//?imageView2/1/w/120/h/120/format/webp/interlace/1
if stgInfo == nil {
return e.NewErrCode(e.ERR_CFG)
}
// todo 目前仅支持七牛
if v, ok := stgInfo[md.KEY_CFG_FILE_PVD]; !ok || v != "qiniu" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_REGION]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_AK]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_SK]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_BUCKET]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_SCHEME]; !ok || v == "" {
stgInfo[md.KEY_CFG_FILE_SCHEME] = "http"
SysCfgSet(c, md.KEY_CFG_FILE_SCHEME, stgInfo[md.KEY_CFG_FILE_SCHEME], "文件域名HTTP协议")
}
qiniu.Init(stgInfo[md.KEY_CFG_FILE_AK], stgInfo[md.KEY_CFG_FILE_SK], stgInfo[md.KEY_CFG_FILE_BUCKET], stgInfo[md.KEY_CFG_FILE_REGION], stgInfo[md.KEY_CFG_FILE_SCHEME])
if v, ok := stgInfo[md.KEY_CFG_FILE_HOST]; !ok || v == "" {
var err error
stgInfo[md.KEY_CFG_FILE_HOST], err = qiniu.BucketGetDomain(stgInfo[md.KEY_CFG_FILE_BUCKET])
if err != nil {
logx.Error(err)
return e.NewErrCode(e.ERR_CFG)
}
SysCfgSet(c, md.KEY_CFG_FILE_HOST, stgInfo[md.KEY_CFG_FILE_HOST], "文件域名地址")
}
// 头像缩略图参数
if v, ok := stgInfo[md.KEY_CFG_FILE_AVATAR_THUMBNAIL]; !ok || v == "" {
SysCfgSet(c, md.KEY_CFG_FILE_AVATAR_THUMBNAIL, "?imageView2/1/w/200/h/200/format/png", "文件用户头像缩略图参数")
}

// 检查文件大小限制
if v, ok := stgInfo[md.KEY_CFG_FILE_MAX_SIZE]; ok && v != "" && utils.StrToInt64(v) < fsize {
return e.NewErrCode(e.ERR_FILE_MAX_SIZE)
}
// 检查文件后缀
if v, ok := stgInfo[md.KEY_CFG_FILE_EXT]; ok && v != "" && !strings.Contains(v, ext) {
return e.NewErrCode(e.ERR_FILE_EXT)
}
return nil
}

+ 1
- 0
consume/canal_guide_order_consume.go Просмотреть файл

@@ -85,6 +85,7 @@ func handleGuideOrdTable(msg []byte) error {
CostPrice: utils.StrToFloat64(data.CostPrice),
State: int32(utils.StrToInt(data.State)),
StateZh: md.CanalGuideOrderState(int32(utils.StrToInt(data.State))).String(),
GoodsNum: utils.StrToInt(data.ItemNum),
PayChannel: 0,
PayChannelZh: "",
ReceiverPhone: user.Phone,


+ 22
- 0
consume/canal_order_consume.go Просмотреть файл

@@ -64,6 +64,23 @@ func handleMallOrdTable(msg []byte) error {

//4、构造数据结构体 && 插入es文档
masterId := strings.Split(canalMsg.Database, "_")[1]

var ordList []string
for _, data := range canalMsg.Data {
ordList = append(ordList, data.OrdId)
}
ordItemList, err := db.MallOrdItemFindByParams(db.DBs[masterId], map[string]interface{}{
"key": "ord_id",
"value": ordList,
})
if err != nil {
return err
}
var ordItemListMap map[string]int
for _, item := range *ordItemList {
ordItemListMap[utils.AnyToString(item.OrdId)] = item.GoodsNum
}

for _, data := range canalMsg.Data {
var uniqueId = masterId + "_" + data.OrdId //es的唯一键,每个文档必须要有唯一键
province, err := db.ProvinceGetOne(data.ProvinceId)
@@ -79,6 +96,10 @@ func handleMallOrdTable(msg []byte) error {
return err
}
now := time.Now()
var goodsNum = 1
if ordItemListMap[data.OrdId] != 0 {
goodsNum = ordItemListMap[data.OrdId]
}
esData := esMd.ZhiosOrdersEs{
OrdKind: "mall",
MasterId: utils.StrToInt(masterId),
@@ -103,6 +124,7 @@ func handleMallOrdTable(msg []byte) error {
City: city.Name,
County: county.Name,
OrderType: int32(utils.StrToInt(data.OrderType)),
GoodsNum: goodsNum,
EstimateCommission: utils.StrToFloat64(data.EstimateCommission),
LogisticCompany: data.LogisticCompany,
PayTime: data.PayTime,


+ 1
- 0
consume/md/md_canal_guide_order_consume.go Просмотреть файл

@@ -11,6 +11,7 @@ type CanalGuideOrder struct {
CostPrice string `json:"cost_price"`
State string `json:"state"`
OrderType string `json:"order_type"`
ItemNum string `json:"item_num"`
SysCommission string `json:"sys_commission"`
CreateAt string `json:"create_at"`
}


+ 1
- 0
es/md/es_struct.go Просмотреть файл

@@ -14,6 +14,7 @@ type ZhiosOrdersEs struct {
StateZh string `json:"state_zh"`
PayTime interface{} `json:"pay_time"`
PayChannel int32 `json:"pay_channel"`
GoodsNum int `json:"goods_num"`
PayChannelZh string `json:"pay_channel_zh"`
ReceiverPhone string `json:"receiver_phone"`
ReceiverName string `json:"receiver_name"`


Загрузка…
Отмена
Сохранить