1
This commit is contained in:
@@ -132,26 +132,22 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
|
||||
}
|
||||
|
||||
func SendMsgToStore(storeID int, templateID, downloadURL, miniPageURL string, data interface{}) (err error) {
|
||||
if storeID == 0 { // 测试,只发给我
|
||||
// SmartMessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", templateID, downloadURL, miniPageURL, data)
|
||||
} else {
|
||||
openIDs := GetWeixinOpenIDsFromStoreID(storeID)
|
||||
successCount := 0
|
||||
for _, openID := range openIDs {
|
||||
realMiniPageURL := miniPageURL
|
||||
if err2 := SmartMessageTemplateSend(openID, templateID, downloadURL, realMiniPageURL, data); err2 == nil {
|
||||
successCount++
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
if successCount > 0 {
|
||||
err = nil // 只要成功一个都当成成功
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("SendMsgToStore all failed storeID:%d, templateID:%s, error:%v", storeID, templateID, err)
|
||||
openIDs := GetWeixinOpenIDsFromStoreID(storeID)
|
||||
successCount := 0
|
||||
for _, openID := range openIDs {
|
||||
realMiniPageURL := miniPageURL
|
||||
if err2 := SmartMessageTemplateSend(openID, templateID, downloadURL, realMiniPageURL, data); err2 == nil {
|
||||
successCount++
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
if successCount > 0 {
|
||||
err = nil // 只要成功一个都当成成功
|
||||
}
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("SendMsgToStore all failed storeID:%d, templateID:%s, error:%v", storeID, templateID, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -256,7 +252,6 @@ func NotifyNewOrder(order *model.GoodsOrder) (err error) {
|
||||
},
|
||||
}
|
||||
storeID := jxutils.GetSaleStoreIDFromOrder(order)
|
||||
globals.SugarLogger.Debugf("NotifyNewOrder storeID=%d", storeID)
|
||||
return SendMsgToStore(storeID, WX_NEWORDER_TEMPLATE_ID2, globals.WxBackstageHost+fmt.Sprintf("%s%d", WX_TO_ORDER_PAGE_URL, storeID), WX_MINI_TO_ORDER_PAGE_URL, data)
|
||||
}
|
||||
|
||||
|
||||
55
business/model/dao/invoice_dao.go
Normal file
55
business/model/dao/invoice_dao.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetInvoiceInfo(db *DaoDB, vendorOrderId string) (*model.InvoiceMsg, error) {
|
||||
data := &model.InvoiceMsg{}
|
||||
sql := ` SELECT * FROM invoice_msg WHERE order_id = ? `
|
||||
err := GetRow(db, data, sql, []interface{}{vendorOrderId}...)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func GetStoreInvoiceList(storeID int, startTime, endTime time.Time, status string, offset, pageSize int) (info *model.PagedInfo, err error) {
|
||||
parameter := []interface{}{}
|
||||
sql := ` SELECT * FROM invoice_msg WHERE 1=1 `
|
||||
if storeID != 0 {
|
||||
sql += ` AND store_id = ? `
|
||||
parameter = append(parameter, storeID)
|
||||
}
|
||||
if !utils.IsTimeZero(startTime) {
|
||||
sql += ` AND created_at >= ? `
|
||||
parameter = append(parameter, startTime)
|
||||
}
|
||||
if !utils.IsTimeZero(endTime) {
|
||||
sql += ` AND created_at <= ? `
|
||||
parameter = append(parameter, endTime)
|
||||
}
|
||||
if status != "" {
|
||||
switch status {
|
||||
case "1": // 未回复
|
||||
sql += ` AND invoice_url = ""`
|
||||
case "2": // 已回复
|
||||
sql += ` AND invoice_url <> ""`
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
parameter = append(parameter, jxutils.FormalizePageSize(pageSize), offset)
|
||||
db := GetDB()
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
data := make([]*model.InvoiceMsg, 0, 0)
|
||||
if err = GetRowsTx(txDB, &data, sql, parameter...); err == nil {
|
||||
pagedInfo := &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount2(db, txDB),
|
||||
Data: data,
|
||||
}
|
||||
return pagedInfo, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
31
business/model/invoice_msg.go
Normal file
31
business/model/invoice_msg.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
type InvoiceMsg struct {
|
||||
ModelIDCUL
|
||||
OrderId string `orm:"column(order_id);size(32)" json:"order_id"` // 订单ID
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
||||
VendorID int `orm:"column(vendor_id);size(2)" json:"vendorID"` // 平台ID
|
||||
InvoiceTaskId string `orm:"column(invoice_task_id);size(64)" json:"invoiceTaskId"` // 任务ID
|
||||
PushType int `orm:"column(push_type);size(2)" json:"pushType"` // 消息类型,1-开发票,3-催发票
|
||||
InvoiceTitle string `orm:"column(invoice_title);size(256)" json:"invoiceTitle"` // 发票抬头,为用户填写的开发票的抬头。
|
||||
TaxpayerId string `orm:"column(taxpayer_id);size(32)" json:"taxpayerId"` // 纳税人识别号
|
||||
NeedInvoiceByCategory int `orm:"column(need_category);size(2)" json:"needCategory"` // 是否需要按大类开票:1-需要按大类开票;2-需要商品明细开票;如果用户端没有选择,默认是按照明细开票
|
||||
CompanyAddress string `orm:"column(company_address);size(256)" json:"companyAddress"` // 公司地址
|
||||
CompanyPhone string `orm:"column(company_phone);size(16)" json:"companyPhone"` // 公司电话
|
||||
AccountBank string `orm:"column(account_bank);size(64)" json:"accountBank"` // 开户银行
|
||||
AccountNumber string `orm:"column(account_number);size(32)" json:"accountNumber"` // 开户账号
|
||||
Email string `orm:"column(email);size(64)" json:"email"` // 邮箱
|
||||
InvoiceAmount int64 `orm:"column(invoice_amount);size(16)" json:"invoiceAmount"` // 商家开票金额,单位分
|
||||
InvoiceUrl string `orm:"column(invoice_url);size(512)" json:"invoiceUrl"` // 发票文件链接
|
||||
InvoiceId string `orm:"column(invoice_id);size(32)" json:"invoiceId"` // 发票号码
|
||||
}
|
||||
|
||||
func (o *InvoiceMsg) TableUnique() [][]string {
|
||||
return [][]string{}
|
||||
}
|
||||
func (o *InvoiceMsg) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CreatedAt", "StoreID"},
|
||||
[]string{"OrderId"},
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
|
||||
}
|
||||
orderFmt += `
|
||||
<CB>%s#%d</CB><BR><BR>
|
||||
<C><BOLD>%s:%s</BOLD><BR></C><BR>
|
||||
--------------------------------<BR>
|
||||
下单时间: %s<BR>
|
||||
预计送达: %s<BR>
|
||||
@@ -92,6 +93,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
|
||||
orderParams = append(orderParams,
|
||||
jxutils.GetVendorName(order.VendorID),
|
||||
order.OrderSeq,
|
||||
order.StoreName, storeTel,
|
||||
utils.Time2Str(order.OrderCreatedAt),
|
||||
utils.Time2Str(expectedDeliveryTime),
|
||||
order.VendorOrderID,
|
||||
@@ -130,14 +132,13 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
|
||||
<BOLD>实付:%s</BOLD>
|
||||
--------------------------------<BR>
|
||||
<C><BOLD>商品质量问题请联系:</BOLD><BR></C>
|
||||
<C><BOLD>%s:%s</BOLD><BR></C><BR>
|
||||
更多信息请关注官方微信: %s<BR>
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
--------------------------------<BR>
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.StoreName, storeTel, globals.StoreName)
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), globals.StoreName)
|
||||
return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...)
|
||||
}
|
||||
|
||||
@@ -166,6 +167,7 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
|
||||
}
|
||||
orderFmt += `
|
||||
<CB>%s#%d</CB><BR><BR>
|
||||
<BOLD>%s:%s</BOLD><BR><BR>
|
||||
--------------------------------<BR>
|
||||
下单时间: %s<BR>
|
||||
预计送达: %s<BR>
|
||||
@@ -200,6 +202,7 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
|
||||
orderParams = append(orderParams,
|
||||
jxutils.GetVendorName(order.VendorID),
|
||||
order.OrderSeq,
|
||||
order.StoreName, storeTel,
|
||||
utils.Time2Str(order.OrderCreatedAt),
|
||||
utils.Time2Str(expectedDeliveryTime),
|
||||
order.VendorOrderID,
|
||||
@@ -236,14 +239,13 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
<C><BOLD>商品质量问题请联系:</BOLD><BR></C>
|
||||
<BOLD>%s:%s</BOLD><BR><BR>
|
||||
更多信息请关注官方微信: %s<BR>
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
--------------------------------<BR>
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.StoreName, storeTel, globals.StoreName)
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), globals.StoreName)
|
||||
return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ package mtwm
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/im"
|
||||
beego "github.com/astaxie/beego/server/web"
|
||||
"net/http"
|
||||
@@ -130,3 +133,42 @@ func pushIMToGyOrPet(msg *mtwmapi.ImCallbackMsg, serverType string) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func InvoiceCallback(invoice *mtwmapi.InvoiceCallback) (err error) {
|
||||
localOrder, _ := partner.CurOrderManager.LoadOrder(invoice.OrderId, model.VendorIDMTWM)
|
||||
if localOrder == nil {
|
||||
return fmt.Errorf("订单不存在:%s", invoice.OrderId)
|
||||
}
|
||||
invoiceData, _ := dao.GetInvoiceInfo(dao.GetDB(), invoice.OrderId)
|
||||
if invoiceData == nil {
|
||||
invoiceObj := model.InvoiceMsg{
|
||||
ModelIDCUL: model.ModelIDCUL{},
|
||||
OrderId: invoice.OrderId,
|
||||
StoreID: localOrder.JxStoreID,
|
||||
VendorID: model.VendorIDMTWM,
|
||||
InvoiceTaskId: invoice.InvoiceTaskId,
|
||||
PushType: invoice.PushType,
|
||||
InvoiceTitle: invoice.InvoiceTitle,
|
||||
TaxpayerId: invoice.TaxpayerId,
|
||||
NeedInvoiceByCategory: invoice.NeedInvoiceByCategory,
|
||||
CompanyAddress: invoice.CompanyAddress,
|
||||
CompanyPhone: invoice.CompanyPhone,
|
||||
AccountBank: invoice.AccountBank,
|
||||
AccountNumber: invoice.AccountNumber,
|
||||
Email: invoice.Email,
|
||||
InvoiceAmount: invoice.ItemTotalInvoiceAmount,
|
||||
InvoiceUrl: "",
|
||||
InvoiceId: "",
|
||||
}
|
||||
dao.WrapAddIDCULEntity(invoiceObj, "system")
|
||||
if err = dao.CreateEntity(dao.GetDB(), invoiceObj); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
content2 := fmt.Sprintf("订单:%s,用户申请发票,请老板提供发票信息!", localOrder.VendorOrderID)
|
||||
if _, err = weixinmsg.SendStoreMessage(jxcontext.AdminCtx, "美团用户申请发票", content2, []int{localOrder.JxStoreID}, nil, "", model.MessageTypeStore, true, true); err != nil {
|
||||
im.PushMsgByCid(localOrder.VendorStoreID, localOrder.VendorID, content2)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1058,3 +1058,12 @@ func (c *PurchaseHandler) ApplyCompensationOrder(order *model.GoodsOrder) (strin
|
||||
Amount: num,
|
||||
})
|
||||
}
|
||||
|
||||
func UploadInvoice(param *model.InvoiceMsg) error {
|
||||
goodsOrder, err := partner.CurOrderManager.LoadOrder(param.OrderId, param.VendorID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return getAPI(goodsOrder.VendorOrgCode, jxutils.GetSaleStoreIDFromOrder(goodsOrder), goodsOrder.VendorStoreID).UploadInvoice(param.OrderId, param.InvoiceUrl, param.InvoiceId, param.InvoiceTaskId)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/permission"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -1496,3 +1497,49 @@ func (c *OrderController) UpdateTiktokSettlement() {
|
||||
return retVal, errCode, err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 获取门店的发票申请
|
||||
// @Description 获取门店的发票申请
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeId formData int false "门店id"
|
||||
// @Param startTime formData string true "开始时间"
|
||||
// @Param endTime formData string true "结束时间"
|
||||
// @Param status formData string false "发票回复状态[1未回复/2回复]"
|
||||
// @Param offset query int false "结果起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "结果页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetInvoiceRecord [post]
|
||||
func (c *OrderController) GetInvoiceRecord() {
|
||||
c.callGetInvoiceRecord(func(params *tOrderGetInvoiceRecordParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = dao.GetStoreInvoiceList(params.StoreId, utils.Str2Time(params.StartTime), utils.Str2Time(params.EndTime), params.Status, params.Offset, params.PageSize)
|
||||
return retVal, errCode, err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 上传订单发票
|
||||
// @Description 上传订单发票
|
||||
// @Param token header string true "认证token"
|
||||
// @Param orderId formData string true "订单ID"
|
||||
// @Param invoiceUrl formData string true "发票地址[10M内pdf/png/jpeg/jpg]"
|
||||
// @Param invoiceId formData string true "发票号码"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UploadOrderInvoice [post]
|
||||
func (c *OrderController) UploadOrderInvoice() {
|
||||
c.callUploadOrderInvoice(func(params *tOrderUploadOrderInvoiceParams) (retVal interface{}, errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
invoice, err := dao.GetInvoiceInfo(db, params.OrderId)
|
||||
if err != nil {
|
||||
return retVal, errCode, err
|
||||
}
|
||||
invoice.InvoiceUrl = params.InvoiceUrl
|
||||
invoice.InvoiceId = params.InvoiceId
|
||||
dao.UpdateEntity(db, invoice, "InvoiceUrl", "InvoiceId")
|
||||
|
||||
err = mtwm.UploadInvoice(invoice)
|
||||
return retVal, errCode, err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -144,13 +144,24 @@ func (c *MtwmController) DeliveryFeeChange() {
|
||||
func (c *MtwmController) Invoice() {
|
||||
body, err := ioutil.ReadAll(c.Ctx.Request.Body)
|
||||
if err != nil {
|
||||
c.Data["json"] = mtwmapi.Err2CallbackResponse(err, "")
|
||||
c.Data["json"] = map[string]interface{}{"result_code": -1}
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
globals.SugarLogger.Debugf("------body:= %s", string(body))
|
||||
callbackResponse := mtwmapi.Err2CallbackResponse(nil, "")
|
||||
c.Data["json"] = callbackResponse
|
||||
|
||||
data := &mtwmapi.InvoiceCallback{}
|
||||
if err = json.Unmarshal(body, data); err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"result_code": -1}
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
// 消息通知
|
||||
if err = mtwm.InvoiceCallback(data); err != nil {
|
||||
globals.SugarLogger.Errorf("mtwm Invoice err := %v", err)
|
||||
}
|
||||
c.Data["json"] = map[string]interface{}{"result_code": 1}
|
||||
c.ServeJSON()
|
||||
|
||||
}
|
||||
|
||||
@@ -1704,6 +1704,24 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
// 获取门店发票申请
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
web.ControllerComments{
|
||||
Method: "GetInvoiceRecord",
|
||||
Router: `/GetInvoiceRecord`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
// 上传门店发票
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
web.ControllerComments{
|
||||
Method: "UploadOrderInvoice",
|
||||
Router: `/UploadOrderInvoice`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
web.ControllerComments{
|
||||
|
||||
Reference in New Issue
Block a user