소스 검색

wip:文档购买记录

wangshan 1 년 전
부모
커밋
cd7193b130

+ 2 - 2
rpc/partnerlib/crontab/service/docinInfo.go

@@ -29,7 +29,7 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 			)
 			for _, v := range docinInfos.Data {
 				var (
-					id                = fmt.Sprintf("docin-%d", v.ProductId)
+					id                = fmt.Sprintf("%s-%d", entity.PartnerName, v.ProductId)
 					md5Id             = GetMD5(id, v.ProductName, v.Desc, v.FilePostfix) //判断数据是否已存在 md5
 					price             = int(v.Price * entity.Multiple)                   //价格转换
 					docTags, docClass = partner.SwitchDocClass(v.PcatName, v.CatName, 1) //标签和分类
@@ -50,7 +50,7 @@ func InsertDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 				//tidb 文档
 				docs = append(docs, sm.Docin{
 					Id:              id,
-					UserId:          "docin",
+					UserId:          entity.PartnerName,
 					AppId:           entity.AppId,
 					DocName:         v.ProductName,
 					DocFileType:     fileType,

+ 1 - 1
rpc/partnerlib/crontab/service/docinUpdate.go

@@ -19,7 +19,7 @@ func UpdateDocinInfos(b []byte) (err error, lastId int64, expectTotal, actualTot
 			//更新doc
 			for _, v := range docinInfos.Data {
 				var (
-					id  = fmt.Sprintf("docin-%d", v.ProductId)
+					id  = fmt.Sprintf("%s-%d", entity.PartnerName, v.ProductId)
 					doc = sm.Doc{}
 				)
 				lastId = v.ProductId

+ 3 - 0
rpc/partnerlib/entity/entity.go

@@ -11,6 +11,9 @@ const (
 	Multiple           = 10
 	DocTable           = "doc"
 	DocStatisticsTable = "doc_statistics"
+	DateFullLayout     = "20060102150405"
+	PartnerName        = "docin"
+	DocUserOrderTab    = "doc_user_order"
 )
 
 var (

+ 2 - 0
rpc/partnerlib/etc/partner.yaml → rpc/partnerlib/etc/partnerlib.yaml

@@ -36,3 +36,5 @@ FileSystemConf:
   Hosts:
     - 127.0.0.1:2379
   Key: moapp.filesystem.rpc
+OssInfo:
+  BucketName: jydocs-std

+ 2 - 1
rpc/partnerlib/init/init.go

@@ -4,12 +4,13 @@ import (
 	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/internal/config"
 	"app.yhyue.com/moapp/jy_docs/services/partner"
 	jyDocsRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
+	_ "app.yhyue.com/moapp/jypkg/public"
 	"flag"
 	"github.com/zeromicro/go-zero/core/conf"
 )
 
 var (
-	configFile    = flag.String("c", "etc/partner.yaml", "the partner file")
+	configFile    = flag.String("c", "etc/partnerlib.yaml", "the partnerlib file")
 	interfaceFile = flag.String("i", "etc/interface.yaml", "the interface file")
 	crontabFile   = flag.String("cron", "etc/crontab.yaml", "the crontab file")
 	warnFile      = flag.String("warn", "etc/warn.yaml", "the warn file")

+ 3 - 0
rpc/partnerlib/internal/config/config.go

@@ -14,4 +14,7 @@ type Config struct {
 	RedisAddr      []string
 	Mongo          jyDocRpcUtil.MongoConfig
 	FileSystemConf discov.EtcdConf
+	OssInfo        struct {
+		BucketName string
+	}
 }

+ 3 - 8
rpc/partnerlib/partnerlib.proto

@@ -18,14 +18,9 @@ message UserBuyVipRequest{
   string phone=2; //手机号
   int64 positionId=3;//职位id
   string appId=4;//剑鱼标识
-  string orderCode=5;//订单号
-  int64 productId=6;//文档id
-  int64 price=7;//价格金额,不可与券同时为空
-  int64 priceVip=8;//券,不可与金额同时为空
-  int64 type=9;//购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
-  string orderTime = 10;//合作方订单时间,格式为yyyyMMddHHmmss
-  int64 state = 11;//1:豆丁
-  int64 mold = 12;//0:保存文库会员购买记录订单信息;1:更新合作商购买订单信息
+  string docId=5;//文档id
+  int64 type=6;//购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
+  int64 state = 7;//1:豆丁
 }
 // 用户下载
 message UDRes{

+ 30 - 1
rpc/partnerlib/service/docDownload.go

@@ -3,7 +3,13 @@ package service
 import (
 	IC "app.yhyue.com/moapp/jy_docs/rpc/partnerlib/init"
 	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/type/partnerlib"
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/util"
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/warn"
+	"app.yhyue.com/moapp/jy_docs/services/model"
+	"app.yhyue.com/moapp/jy_docs/services/partner"
+	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
 	"encoding/json"
+	"fmt"
 )
 
 type DRes struct {
@@ -29,7 +35,30 @@ func DocDownload(in *partnerlib.UserDownloadRequest) (res *partnerlib.UDRes, err
 		if isJson {
 			err = json.Unmarshal(b, &res)
 		} else {
-			res = FileUpload(b)
+			//获取文件信息
+			docInfo := partner.DocsFindOne(in.DocId)
+			//查看oss服务器是否已存在此文档
+			if res.OssDocId = docInfo.OssDocId; res.OssDocId == "" {
+				//获取附件后上传oss
+				if uploadRes := FileUpload(&filesystem.SaveFileReq{
+					Domain: IC.C.OssInfo.BucketName,
+					FileId: fmt.Sprintf("%s.%s", util.GetHashKey(b), docInfo.DocFileSuffix),
+					Meta: map[string]string{
+						"docName":   docInfo.DocName,
+						"docSuffix": docInfo.DocFileSuffix,
+						"docSize":   fmt.Sprintf("%d", docInfo.DocFileSize),
+					},
+					RawFileContent: b,
+				}); uploadRes.OssDocId != "" {
+					//更新doc
+					if err := partner.DocsUpdate(model.Doc{OssDocId: res.OssDocId}); err != nil {
+						warn.SendMsgByWXURL(fmt.Sprintf("文档id:%s,文档名称:%s 上传tidb doc 异常:%s", docInfo.Id, docInfo.DocName, err.Error()))
+					}
+				} else {
+					warn.SendMsgByWXURL(fmt.Sprintf("文档id:%s,文档名称:%s,上传到oss异常:%s", docInfo.Id, docInfo.DocName, res.Msg))
+				}
+
+			}
 		}
 	} else {
 		res.Msg = err.Error()

+ 9 - 10
rpc/partnerlib/service/ossFileUpload.go

@@ -4,20 +4,19 @@ import (
 	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/type/partnerlib"
 	jyDocRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
 	"app.yhyue.com/moapp/jyfs/rpc/filesystem"
+	"fmt"
 	"github.com/gogf/gf/v2/os/gctx"
 )
 
 // 上传文档信息
-func FileUpload(b []byte) (res *partnerlib.UDRes) {
-	if len(b) > 0 {
-		fRes, err := jyDocRpcUtil.FileSystem.SaveFile(gctx.New(), &filesystem.SaveFileReq{
-			Domain:         "",
-			FileId:         "",
-			Meta:           nil,
-			RawFileContent: nil,
-		})
-		if err == nil {
-
+func FileUpload(fr *filesystem.SaveFileReq) (res *partnerlib.UDRes) {
+	if fr != nil && len(fr.RawFileContent) > 0 {
+		fRes, err := jyDocRpcUtil.FileSystem.SaveFile(gctx.New(), fr)
+		if err == nil && fRes.State {
+			res.OssDocId = fRes.FileId
+		} else {
+			res.Code = -1
+			res.Msg = fmt.Sprintf("%s上传异常", fr.Meta["docName"])
 		}
 	}
 	return

+ 47 - 21
rpc/partnerlib/service/userBuy.go

@@ -1,9 +1,16 @@
 package service
 
 import (
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/entity"
 	IC "app.yhyue.com/moapp/jy_docs/rpc/partnerlib/init"
 	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/type/partnerlib"
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/util"
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/warn"
+	"app.yhyue.com/moapp/jy_docs/services/model"
+	"app.yhyue.com/moapp/jy_docs/services/partner"
+	"app.yhyue.com/moapp/jybase/date"
 	"encoding/json"
+	"fmt"
 )
 
 type BRes struct {
@@ -15,28 +22,47 @@ type BRes struct {
 func UBHandle(in *partnerlib.UserBuyVipRequest) (res *partnerlib.UBVRes, err error) {
 	res = new(partnerlib.UBVRes)
 	var (
-		b []byte
+		b       []byte
+		docInfo = partner.DocsFindOne(in.DocId)
 	)
-	h := NewHH(IC.I.Docin.Name, IC.I.Docin.Host, IC.I.Docin.BuyRecord.Name, IC.I.Docin.BuyRecord.Pathname, IC.I.Docin.BuyRecord.Method, map[string]interface{}{
-		"orderNo":   in.OrderCode,
-		"productId": in.ProductId,
-		"userId":    in.PositionId,
-		"price":     in.Price,
-		"priceVip":  in.PriceVip,
-		"type":      in.Type,
-		"orderTime": in.OrderTime,
-	})
-	b, err, _ = h.HttpFunc()
-	go h.SaveDocinLogger(b, err, "req")
-	if err == nil {
-		//豆丁同步数据到mongo
-		go h.SaveDocinLogger(b, err, "res")
-		bRes := &BRes{}
-		if err = json.Unmarshal(b, &bRes); err == nil {
-			res.OrderNo = bRes.OrderNo
-			res.Msg = bRes.Msg
-			res.Code = bRes.Code
-			return
+	if docInfo.Id != "" {
+		orderCode := util.GetOrderCode(entity.PartnerName)
+		h := NewHH(IC.I.Docin.Name, IC.I.Docin.Host, IC.I.Docin.BuyRecord.Name, IC.I.Docin.BuyRecord.Pathname, IC.I.Docin.BuyRecord.Method, map[string]interface{}{
+			"orderNo":   orderCode,
+			"productId": in.DocId,
+			"userId":    in.PositionId,
+			"price":     docInfo.Price,
+			"priceVip":  docInfo.PriceVip,
+			"type":      in.Type,
+			"orderTime": date.NowFormat(entity.DateFullLayout),
+		})
+		b, err, _ = h.HttpFunc()
+		go h.SaveDocinLogger(b, err, "req")
+		if err == nil {
+			//豆丁同步数据到mongo
+			go h.SaveDocinLogger(b, err, "res")
+			bRes := &BRes{}
+			if err = json.Unmarshal(b, &bRes); err == nil {
+				//更新文档购买记录
+				if err = partner.InsertBuyDocOrder(&model.DocinUserOrder{
+					PositionId:   in.PositionId,
+					MgoUserId:    in.MgoUserId,
+					Phone:        in.Phone,
+					DocId:        docInfo.Id,
+					OrderCode:    orderCode,
+					Price:        docInfo.Price,
+					PriceVip:     docInfo.PriceVip,
+					PurchaseType: int(in.Type), //购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
+					State:        1,            //合作商:1:豆丁
+					CreateTime:   date.NowFormat(date.Date_Full_Layout),
+				}); err == nil {
+					warn.SendMsgByWXURL(fmt.Sprintf("%s文档名称: %s,文档id:%s,购买订单编号:%s,请求信息:%v", entity.PartnerName, docInfo.DocName, docInfo.Id, orderCode, in))
+				}
+				res.OrderNo = bRes.OrderNo
+				res.Msg = bRes.Msg
+				res.Code = bRes.Code
+				return
+			}
 		}
 	}
 	res.Msg = err.Error()

+ 30 - 79
rpc/partnerlib/type/partnerlib/partnerlib.pb.go

@@ -126,14 +126,9 @@ type UserBuyVipRequest struct {
 	Phone      string `protobuf:"bytes,2,opt,name=phone,proto3" json:"phone,omitempty"`            //手机号
 	PositionId int64  `protobuf:"varint,3,opt,name=positionId,proto3" json:"positionId,omitempty"` //职位id
 	AppId      string `protobuf:"bytes,4,opt,name=appId,proto3" json:"appId,omitempty"`            //剑鱼标识
-	OrderCode  string `protobuf:"bytes,5,opt,name=orderCode,proto3" json:"orderCode,omitempty"`    //订单号
-	ProductId  int64  `protobuf:"varint,6,opt,name=productId,proto3" json:"productId,omitempty"`   //文档id
-	Price      int64  `protobuf:"varint,7,opt,name=price,proto3" json:"price,omitempty"`           //价格金额,不可与券同时为空
-	PriceVip   int64  `protobuf:"varint,8,opt,name=priceVip,proto3" json:"priceVip,omitempty"`     //券,不可与金额同时为空
-	Type       int64  `protobuf:"varint,9,opt,name=type,proto3" json:"type,omitempty"`             //购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
-	OrderTime  string `protobuf:"bytes,10,opt,name=orderTime,proto3" json:"orderTime,omitempty"`   //合作方订单时间,格式为yyyyMMddHHmmss
-	State      int64  `protobuf:"varint,11,opt,name=state,proto3" json:"state,omitempty"`          //1:豆丁
-	Mold       int64  `protobuf:"varint,12,opt,name=mold,proto3" json:"mold,omitempty"`            //0:保存文库会员购买记录订单信息;1:更新合作商购买订单信息
+	DocId      string `protobuf:"bytes,5,opt,name=docId,proto3" json:"docId,omitempty"`            //文档id
+	Type       int64  `protobuf:"varint,6,opt,name=type,proto3" json:"type,omitempty"`             //购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
+	State      int64  `protobuf:"varint,7,opt,name=state,proto3" json:"state,omitempty"`           //1:豆丁
 }
 
 func (x *UserBuyVipRequest) Reset() {
@@ -196,34 +191,13 @@ func (x *UserBuyVipRequest) GetAppId() string {
 	return ""
 }
 
-func (x *UserBuyVipRequest) GetOrderCode() string {
+func (x *UserBuyVipRequest) GetDocId() string {
 	if x != nil {
-		return x.OrderCode
+		return x.DocId
 	}
 	return ""
 }
 
-func (x *UserBuyVipRequest) GetProductId() int64 {
-	if x != nil {
-		return x.ProductId
-	}
-	return 0
-}
-
-func (x *UserBuyVipRequest) GetPrice() int64 {
-	if x != nil {
-		return x.Price
-	}
-	return 0
-}
-
-func (x *UserBuyVipRequest) GetPriceVip() int64 {
-	if x != nil {
-		return x.PriceVip
-	}
-	return 0
-}
-
 func (x *UserBuyVipRequest) GetType() int64 {
 	if x != nil {
 		return x.Type
@@ -231,13 +205,6 @@ func (x *UserBuyVipRequest) GetType() int64 {
 	return 0
 }
 
-func (x *UserBuyVipRequest) GetOrderTime() string {
-	if x != nil {
-		return x.OrderTime
-	}
-	return ""
-}
-
 func (x *UserBuyVipRequest) GetState() int64 {
 	if x != nil {
 		return x.State
@@ -245,13 +212,6 @@ func (x *UserBuyVipRequest) GetState() int64 {
 	return 0
 }
 
-func (x *UserBuyVipRequest) GetMold() int64 {
-	if x != nil {
-		return x.Mold
-	}
-	return 0
-}
-
 // 用户下载
 type UDRes struct {
 	state         protoimpl.MessageState
@@ -397,7 +357,7 @@ var file_partnerlib_proto_rawDesc = []byte{
 	0x63, 0x6f, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64, 0x18, 0x06, 0x20,
 	0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74,
 	0x61, 0x74, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65,
-	0x22, 0xc7, 0x02, 0x0a, 0x11, 0x55, 0x73, 0x65, 0x72, 0x42, 0x75, 0x79, 0x56, 0x69, 0x70, 0x52,
+	0x22, 0xbd, 0x01, 0x0a, 0x11, 0x55, 0x73, 0x65, 0x72, 0x42, 0x75, 0x79, 0x56, 0x69, 0x70, 0x52,
 	0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6d, 0x67, 0x6f, 0x55, 0x73, 0x65,
 	0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x67, 0x6f, 0x55, 0x73,
 	0x65, 0x72, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x18, 0x02, 0x20,
@@ -405,39 +365,30 @@ var file_partnerlib_proto_rawDesc = []byte{
 	0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a,
 	0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x70,
 	0x70, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64,
-	0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x05, 0x20,
-	0x01, 0x28, 0x09, 0x52, 0x09, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1c,
-	0x0a, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28,
-	0x03, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05,
-	0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x70, 0x72, 0x69,
-	0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x69, 0x63, 0x65, 0x56, 0x69, 0x70, 0x18, 0x08,
-	0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x72, 0x69, 0x63, 0x65, 0x56, 0x69, 0x70, 0x12, 0x12,
-	0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79,
-	0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x18,
-	0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x54, 0x69, 0x6d, 0x65,
-	0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52,
-	0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x6f, 0x6c, 0x64, 0x18, 0x0c,
-	0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x6d, 0x6f, 0x6c, 0x64, 0x22, 0x49, 0x0a, 0x05, 0x55, 0x44,
-	0x52, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
-	0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02,
-	0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x73, 0x73,
-	0x44, 0x6f, 0x63, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, 0x73, 0x73,
-	0x44, 0x6f, 0x63, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x06, 0x55, 0x42, 0x56, 0x52, 0x65, 0x73, 0x12,
-	0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63,
-	0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
-	0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x6f,
-	0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x4e, 0x6f, 0x32,
-	0x8a, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x0b, 0x44,
-	0x6f, 0x63, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x1f, 0x2e, 0x70, 0x61, 0x72,
-	0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x44, 0x6f, 0x77, 0x6e,
-	0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x70, 0x61,
-	0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x44, 0x52, 0x65, 0x73, 0x12, 0x3c,
-	0x0a, 0x07, 0x55, 0x73, 0x65, 0x72, 0x42, 0x75, 0x79, 0x12, 0x1d, 0x2e, 0x70, 0x61, 0x72, 0x74,
-	0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x42, 0x75, 0x79, 0x56, 0x69,
-	0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x70, 0x61, 0x72, 0x74, 0x6e,
-	0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x42, 0x56, 0x52, 0x65, 0x73, 0x42, 0x0e, 0x5a, 0x0c,
-	0x2e, 0x2f, 0x70, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x62, 0x06, 0x70, 0x72,
-	0x6f, 0x74, 0x6f, 0x33,
+	0x12, 0x14, 0x0a, 0x05, 0x64, 0x6f, 0x63, 0x49, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x05, 0x64, 0x6f, 0x63, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x06,
+	0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74,
+	0x61, 0x74, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65,
+	0x22, 0x49, 0x0a, 0x05, 0x55, 0x44, 0x52, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64,
+	0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a,
+	0x03, 0x6d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12,
+	0x1a, 0x0a, 0x08, 0x6f, 0x73, 0x73, 0x44, 0x6f, 0x63, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
+	0x09, 0x52, 0x08, 0x6f, 0x73, 0x73, 0x44, 0x6f, 0x63, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x06, 0x55,
+	0x42, 0x56, 0x52, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20,
+	0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67,
+	0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x6f,
+	0x72, 0x64, 0x65, 0x72, 0x4e, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72,
+	0x64, 0x65, 0x72, 0x4e, 0x6f, 0x32, 0x8a, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x72, 0x74, 0x6e, 0x65,
+	0x72, 0x12, 0x41, 0x0a, 0x0b, 0x44, 0x6f, 0x63, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64,
+	0x12, 0x1f, 0x2e, 0x70, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x73,
+	0x65, 0x72, 0x44, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
+	0x74, 0x1a, 0x11, 0x2e, 0x70, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55,
+	0x44, 0x52, 0x65, 0x73, 0x12, 0x3c, 0x0a, 0x07, 0x55, 0x73, 0x65, 0x72, 0x42, 0x75, 0x79, 0x12,
+	0x1d, 0x2e, 0x70, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x73, 0x65,
+	0x72, 0x42, 0x75, 0x79, 0x56, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12,
+	0x2e, 0x70, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c, 0x69, 0x62, 0x2e, 0x55, 0x42, 0x56, 0x52,
+	0x65, 0x73, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x61, 0x72, 0x74, 0x6e, 0x65, 0x72, 0x6c,
+	0x69, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 21 - 0
rpc/partnerlib/util/util.go

@@ -1 +1,22 @@
 package util
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jypkg/public"
+	"crypto/sha256"
+	"fmt"
+)
+
+func GetHashKey(bs []byte) string {
+	defer common.Catch()
+	ha := sha256.New()
+	ha.Write(bs)
+	hbs := ha.Sum(nil)
+	key := fmt.Sprintf("%x", hbs)
+	return key
+}
+
+// 创建订单号
+func GetOrderCode(name string) string {
+	return fmt.Sprintf("%s-%s", name, <-public.VarOrderCode.Pool)
+}

+ 10 - 7
services/model/partner.go

@@ -34,13 +34,16 @@ func (ud *Docin) TableName() string {
 
 // 精品文库订单信息表
 type DocinUserOrder struct {
-	PositionId string `json:"position_id" gorm:"column:position_id"`
-	MgoUserId  string `json:"mgo_user_id" gorm:"column:mgo_user_id"`
-	Phone      string `json:"phone" gorm:"column:phone"`
-	OrderCode  string `json:"order_code" gorm:"column:order_code"`
-	State      string `json:"state" gorm:"column:state"`
-	CreateTime string `json:"create_time" gorm:"column:create_time"`
-	UpdateTime string `json:"update_time" gorm:"column:update_time"`
+	PositionId   int64  `json:"position_id" gorm:"column:position_id"`
+	MgoUserId    string `json:"mgo_user_id" gorm:"column:mgo_user_id"`
+	Phone        string `json:"phone" gorm:"column:phone"`
+	DocId        string `json:"doc_id" gorm:"column:doc_id"`
+	OrderCode    string `json:"order_code" gorm:"column:order_code"`
+	Price        int    `json:"price" gorm:"column:price"`                 //价格
+	PriceVip     int    `json:"price_vip" gorm:"column:price_vip"`         //券
+	PurchaseType int    `json:"purchase_type" gorm:"column:purchase_type"` //购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
+	State        int    `json:"state" gorm:"column:state"`
+	CreateTime   string `json:"create_time" gorm:"column:create_time"`
 }
 
 func (ud *DocinUserOrder) TableName() string {

+ 12 - 0
services/partner/docBuyOrder.go

@@ -0,0 +1,12 @@
+package partner
+
+import (
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/entity"
+	"app.yhyue.com/moapp/jy_docs/services/model"
+	jyDocRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
+)
+
+func InsertBuyDocOrder(orderInfo *model.DocinUserOrder) (err error) {
+	err = jyDocRpcUtil.GetJyDocsDB().Table(entity.DocUserOrderTab).Create(orderInfo).Error
+	return
+}

+ 18 - 0
services/partner/docsFind.go

@@ -0,0 +1,18 @@
+package partner
+
+import (
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/entity"
+	"app.yhyue.com/moapp/jy_docs/services/model"
+	jyDocRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
+	"fmt"
+	"log"
+)
+
+func DocsFindOne(docId string) (doc *model.Docin) {
+	doc = &model.Docin{}
+	err := jyDocRpcUtil.GetJyDocsDB().Table(entity.DocTable).Where("id = ?", docId).Find(doc)
+	if err != nil {
+		log.Println(fmt.Sprintf("获取 doc 文档 - %s 异常:%s", docId, err.Error))
+	}
+	return
+}

+ 1 - 1
services/partner/docsInsert.go

@@ -7,7 +7,7 @@ import (
 	"log"
 )
 
-func DocsInsert(docinInfos []model.DocNew, count int) {
+func DocsInsert(docinInfos []model.Docin, count int) {
 	res := docRpcUtil.GetJyDocsDB().Table(entity.DocTable).CreateInBatches(&docinInfos, count)
 	if res.Error != nil {
 		log.Println("error:", res.Error)

+ 14 - 6
services/partner/docsUpdate.go

@@ -9,12 +9,20 @@ import (
 )
 
 func DocsUpdate(doc model.Doc) (err error) {
-	err = docRpcUtil.GetJyDocsDB().Table(entity.DocTable).Where("id=?", doc.Id).Updates(map[string]interface{}{
-		"updateDate":  doc.UpdateDate.Format(date.Date_Full_Layout),
-		"price":       doc.Price,
-		"productType": doc.ProductType,
-		"downOrUp":    doc.DownOrUp,
-	}).Error
+	updateMap := map[string]interface{}{"updateDate": doc.UpdateDate.Format(date.Date_Full_Layout)}
+	if doc.Price > 0 {
+		updateMap["price"] = doc.Price
+	}
+	if doc.ProductType > 0 {
+		updateMap["productType"] = doc.ProductType
+	}
+	if doc.ProductType > 0 {
+		updateMap["downOrUp"] = doc.DownOrUp
+	}
+	if doc.OssDocId != "" {
+		updateMap["ossDocId"] = doc.OssDocId
+	}
+	err = docRpcUtil.GetJyDocsDB().Table(entity.DocTable).Where("id=?", doc.Id).Updates(updateMap).Error
 	if err.Error != nil {
 		log.Println("error:", err.Error)
 		return