1
This commit is contained in:
@@ -2,10 +2,16 @@ package ebai
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/im"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,6 +29,81 @@ func (p *PurchaseHandler) OnImMessage(msg *ebaiapi.CallbackMsg) (response *ebaia
|
||||
return nil
|
||||
}
|
||||
|
||||
// InvoiceApply 用户申请发票
|
||||
func (p *PurchaseHandler) InvoiceApply(msg *ebaiapi.CallbackMsg) (response *ebaiapi.CallbackResponse) {
|
||||
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
applyNo = ""
|
||||
storeId = ""
|
||||
vendorStoreId = ""
|
||||
)
|
||||
|
||||
switch msg.Cmd {
|
||||
case ebaiapi.CmdImInvoicApply:
|
||||
invoice := &ebaiapi.InvoiceApplyBody{}
|
||||
if err := utils.Map2StructByJson(msg.Body, invoice, false); err != nil {
|
||||
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, msg.Cmd)
|
||||
}
|
||||
invoiceData, _ := dao.GetInvoiceInfo(db, utils.Int64ToStr(invoice.OrderList[0].OrderId))
|
||||
applyNo = invoice.ApplicationNo
|
||||
storeId = invoice.ShopId
|
||||
vendorStoreId = invoice.BaiduShopId
|
||||
if invoiceData == nil {
|
||||
invoiceObj := model.InvoiceMsg{
|
||||
ModelIDCUL: model.ModelIDCUL{},
|
||||
OrderId: utils.Int64ToStr(invoice.OrderList[0].OrderId),
|
||||
StoreID: utils.Str2Int(invoice.ShopId),
|
||||
VendorID: model.VendorIDEBAI,
|
||||
InvoiceTaskId: invoice.ApplicationNo,
|
||||
Status: invoice.Status,
|
||||
PushType: 1,
|
||||
InvoiceTitle: invoice.BuyerTitle.TitleName,
|
||||
TaxpayerId: invoice.BuyerTitle.TaxPayerNum,
|
||||
NeedInvoiceByCategory: 1,
|
||||
CompanyAddress: invoice.BuyerTitle.RegisterAddress,
|
||||
CompanyPhone: invoice.BuyerTitle.RegisterPhone,
|
||||
AccountBank: invoice.BuyerTitle.BankName,
|
||||
AccountNumber: invoice.BuyerTitle.BankAccount,
|
||||
Email: invoice.BuyerContact.Email,
|
||||
InvoiceAmount: utils.Float64TwoInt64(invoice.TotalInvoiceAmount * 100),
|
||||
InvoiceUrl: "",
|
||||
InvoiceId: "",
|
||||
}
|
||||
if len(invoice.OrderList) > 1 {
|
||||
orderList := make(map[int64]float64, 0)
|
||||
for _, v := range invoice.OrderList {
|
||||
orderList[v.OrderId] = v.InvoiceAmount
|
||||
}
|
||||
invoiceObj.Remark = string(utils.MustMarshal(orderList))
|
||||
}
|
||||
dao.WrapAddIDCULEntity(invoiceObj, "system")
|
||||
if err := dao.CreateEntity(db, invoiceObj); err != nil {
|
||||
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, msg.Cmd)
|
||||
}
|
||||
}
|
||||
case ebaiapi.CmdImInvoicEmail:
|
||||
invoice := &ebaiapi.InvoiceEmailPush{}
|
||||
if err := utils.Map2StructByJson(msg.Body, invoice, false); err != nil {
|
||||
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, msg.Cmd)
|
||||
}
|
||||
applyNo = invoice.ApplicationNo
|
||||
storeId = invoice.ShopId
|
||||
vendorStoreId = invoice.BaiduShopId
|
||||
invoiceData, _ := dao.GetInvoiceInfoByTaskId(db, invoice.ApplicationNo)
|
||||
if invoiceData != nil {
|
||||
invoiceData.UpdatedAt = time.Now()
|
||||
invoiceData.Email = invoice.Email
|
||||
dao.UpdateEntity(db, invoiceData, "UpdatedAt", "Email")
|
||||
}
|
||||
}
|
||||
content2 := fmt.Sprintf("发票单号:%s,用户申请发票,请老板提供发票信息!", applyNo)
|
||||
if _, err := weixinmsg.SendStoreMessage(jxcontext.AdminCtx, "美团用户申请发票", content2, []int{utils.Str2Int(storeId)}, nil, "", model.MessageTypeStore, true, true); err != nil {
|
||||
im.PushMsgByCid(vendorStoreId, model.VendorIDEBAI, content2)
|
||||
}
|
||||
return api.EbaiAPI.Err2CallbackResponse(msg.Cmd, nil, msg.Cmd)
|
||||
}
|
||||
|
||||
// BusinessSendMsg 向门店发送消息
|
||||
//func BusinessSendMsg(param *ebaiapi.BusinessSendMsgReq) error {
|
||||
// err := api.EbaiAPI.BusinessSendMsg(param)
|
||||
|
||||
Reference in New Issue
Block a user