1
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"io"
|
||||
@@ -258,6 +259,25 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
||||
if dataStr != "" {
|
||||
a, b := getCallbackMsgInfo(dataStr)
|
||||
t.changePrintMsg(dataStr, a, b)
|
||||
// 查询打印机是否扣费,未扣费就扣费,已经扣费不做处理
|
||||
have, err := dao.QueryOrderDeductionRecord(db, b, utils.Int64ToStr(a))
|
||||
if err != nil && !have {
|
||||
// 扣除打印机账号金额
|
||||
err = dao.DeductionPrintBalance(db, b)
|
||||
// 添加打印记录(支出记录)
|
||||
err = dao.AddPrintRecord(db, &model.PrintBillRecord{
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
PrintNo: b,
|
||||
PayType: 2,
|
||||
PayMoney: 1, // 固定支出一分钱
|
||||
OrderId: utils.Int64ToStr(a),
|
||||
UserId: "",
|
||||
})
|
||||
globals.SugarLogger.Debugf("扣除用户打印机金额/添加打印机打印记录错误 %s", err)
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("查询打印机扣费记录错误 %s", err)
|
||||
}
|
||||
//判断音频暂停?
|
||||
//收到打印成功回调后,如果消息中有音频,需要等待一下,等上一个音频播完
|
||||
//暂停时间就暂时取的sound标签内内容长度/2
|
||||
|
||||
@@ -327,8 +327,6 @@ func getCallbackMsgInfo(data string) (orderNo int64, printNo string) {
|
||||
orderNo = h8l82int(data[len(data)-6:len(data)-4], data[len(data)-4:len(data)-2])
|
||||
printNoData, _ := hex.DecodeString(data[len(printSuccessText) : len(data)-6])
|
||||
printNo = string(printNoData)
|
||||
globals.SugarLogger.Debug("=======================orderNo", orderNo)
|
||||
globals.SugarLogger.Debug("=======================printNo", printNo)
|
||||
return orderNo, printNo
|
||||
}
|
||||
|
||||
|
||||
7
business/model/dao/print_bill.go
Normal file
7
business/model/dao/print_bill.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package dao
|
||||
|
||||
// DeductionPrintBalance 扣除打印机账号余额
|
||||
func DeductionPrintBalance(db *DaoDB, printNo string) error {
|
||||
_, err := ExecuteSQL(db, `UPDATE print_bill SET print_balance = print_balance -1 WHERE print_no = ?`, []interface{}{printNo}...)
|
||||
return err
|
||||
}
|
||||
32
business/model/dao/print_bill_record.go
Normal file
32
business/model/dao/print_bill_record.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// QueryOrderDeductionRecord 查询订单扣除记录
|
||||
func QueryOrderDeductionRecord(db *DaoDB, printNo string, orderNo string) (bool, error) {
|
||||
sql := `SELECT * FROM print_bill_record WHERE print_no = ? AND order_no = ? AND created_at > ? AND created_at < ?`
|
||||
|
||||
timeNow := time.Now()
|
||||
startTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, timeNow.Location())
|
||||
endTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 23, 59, 59, 0, timeNow.Location())
|
||||
param := []interface{}{printNo, orderNo, startTime, endTime}
|
||||
|
||||
var result []*model.PrintBillRecord
|
||||
if err := GetRows(db, &result, sql, param...); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddPrintRecord 添加打印记录
|
||||
func AddPrintRecord(db *DaoDB, param *model.PrintBillRecord) error {
|
||||
return CreateEntity(db, param)
|
||||
}
|
||||
13
business/model/print_bill.go
Normal file
13
business/model/print_bill.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// PrintBill 打印机账户
|
||||
type PrintBill struct {
|
||||
ID int `orm:"column(id)" json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
||||
PrintNo string `orm:"type(varchar);size(32);index" json:"print_no" db:"print_no"` // 打印机编号
|
||||
PrintBalance int64 `orm:"type(int);size(16)" json:"print_balance" db:"print_balance"` // 账户余额
|
||||
UserId string `orm:"type(varchar);size(125)" json:"user_id" db:"user_id"` // 打印机所属用户
|
||||
}
|
||||
15
business/model/print_bill_record.go
Normal file
15
business/model/print_bill_record.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// PrintBillRecord 打印机充值/小费记录
|
||||
type PrintBillRecord struct {
|
||||
ID int `orm:"column(id)" json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
||||
PrintNo string `orm:"type(varchar);size(32);index" json:"print_no" db:"print_no"` // 打印机编号
|
||||
PayType int `orm:"type(int);size(2)" json:"pay_type" db:"pay_type"` // 支付类型[1-充值/2-支出]
|
||||
PayMoney int `orm:"type(int);size(10)" json:"pay_money" db:"pay_money"` // 金额
|
||||
OrderId string `orm:"type(varchar);size(64);index" json:"order_id" db:"order_id"` // 订单号
|
||||
UserId string `orm:"type(varchar);size(125)" json:"user_id" db:"user_id"` // 打印机所属用户
|
||||
}
|
||||
Reference in New Issue
Block a user