@@ -0,0 +1,29 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"xorm.io/xorm" | |||
) | |||
func DetailInsert(Db *xorm.Engine, data *model.CommunityTeamStorePrinterDetail) (int64, error) { | |||
affected, err := Db.InsertOne(data) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func DetailUpdate(Db *xorm.Engine, id interface{}, data *model.CommunityTeamStorePrinterDetail, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(data) | |||
} else { | |||
affected, err = Db.Where("id=?", id).Update(data) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} |
@@ -0,0 +1,188 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func GetPrinterIndexAll(Db *xorm.Engine, storeId string) ([]model.CommunityTeamStorePrinter, error) { | |||
var list []model.CommunityTeamStorePrinter | |||
session := Db.Where("store_id= ? ", storeId) | |||
//排序 | |||
err := session.Desc("create_time").Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return list, err | |||
} | |||
func GetPrinterIndexById(Db *xorm.Engine, id, storeId string) (*model.CommunityTeamStorePrinter, error) { | |||
var list model.CommunityTeamStorePrinter | |||
session := Db.Where("id=? and store_id=?", id, storeId) | |||
//排序 | |||
has, err := session.Desc("create_time").Get(&list) | |||
if has == false || err != nil { | |||
return nil, err | |||
} | |||
return &list, err | |||
} | |||
func GetPrinterIndexByBluetooth(Db *xorm.Engine, storeId string) (*model.CommunityTeamStorePrinter, error) { | |||
var list model.CommunityTeamStorePrinter | |||
session := Db.Where("type=? and store_id=?", "bluetooth", storeId) | |||
//排序 | |||
has, err := session.Desc("create_time").Get(&list) | |||
if has == false || err != nil { | |||
return nil, err | |||
} | |||
return &list, err | |||
} | |||
// 分页查询方案 | |||
func GetPrinterIndexList(Db *xorm.Engine, parameter *md.IndexRequest) ([]md.IndexResList, error) { | |||
var list []model.CommunityTeamStorePrinter | |||
var webList []md.IndexResList | |||
session := Db.Where("store_id= ? ", parameter.StoreId) | |||
//分页 | |||
if utils.StrToInt(parameter.P) > 0 && utils.StrToInt(parameter.PageSize) > 0 { | |||
session = session.Limit(utils.StrToInt(parameter.PageSize), (utils.StrToInt(parameter.P)-1)*utils.StrToInt(parameter.PageSize)) | |||
} | |||
//排序 | |||
err := session.Desc("create_time").Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
var typeList = map[string]string{ | |||
"ordinary": "普通打印机", | |||
"cloud": "云打印机", | |||
"bluetooth": "蓝牙打印机", | |||
} | |||
var locationTypeList = map[string]string{ | |||
"reception": "前台", | |||
"kitchen": "后厨", | |||
} | |||
for _, v := range list { | |||
var tmp = md.IndexResList{ | |||
Id: utils.IntToStr(v.Id), | |||
Name: v.Name, | |||
IsUse: utils.IntToStr(v.IsUse), | |||
StoreId: utils.IntToStr(v.StoreId), | |||
SnNum: v.SnNum, | |||
IdentificationCode: v.IdentificationCode, | |||
ModuleId: utils.IntToStr(v.ModuleId), | |||
Type: v.Type, | |||
TypeStr: typeList[v.Type], | |||
LocationType: v.LocationType, | |||
LocationTypeStr: locationTypeList[v.LocationType], | |||
} | |||
webList = append(webList, tmp) | |||
} | |||
return webList, nil | |||
} | |||
func indexGetCount(Db *xorm.Engine, parameter *md.IndexRequest) int { | |||
var ord model.CommunityTeamStorePrinter | |||
session := Db.Where("store_id= ? ", parameter.StoreId) | |||
count, err := session.Count(&ord) | |||
if err != nil { | |||
return 0 | |||
} | |||
return int(count) | |||
} | |||
func IndexExists(Db *xorm.Engine, parameter *md.IndexSaveRequest) int { | |||
var ord model.CommunityTeamStorePrinter | |||
session := Db.Where("sn_num= ? ", parameter.SnNum) | |||
count, err := session.Count(&ord) | |||
if err != nil { | |||
return 0 | |||
} | |||
return int(count) | |||
} | |||
func IndexById(Db *xorm.Engine, parameter *md.IndexSaveRequest) (*model.CommunityTeamStorePrinter, error) { | |||
var ord model.CommunityTeamStorePrinter | |||
session := Db.Where("id= ? ", parameter.Id) | |||
_, err := session.Get(&ord) | |||
return &ord, err | |||
} | |||
// 写入数据 | |||
func IndexInsert(eg *xorm.Engine, m *model.CommunityTeamStorePrinter) (int64, error) { | |||
if m.Id > 0 { //编辑 | |||
id, err := IndexUpdate(eg, m, "type,is_use,sn_num,identification_code,name,update_time,location_type") | |||
if id == 0 || err != nil { | |||
return 0, logx.Warn("cannot insert data :", err) | |||
} | |||
return id, nil | |||
} | |||
m.CreateTime = time.Now() | |||
//写入 | |||
id, err := eg.InsertOne(m) | |||
if id == 0 || err != nil { | |||
return 0, logx.Warn("cannot insert data :", err) | |||
} | |||
return id, nil | |||
} | |||
// 修改数据 | |||
func IndexUpdate(eg *xorm.Engine, m *model.CommunityTeamStorePrinter, cols ...string) (int64, error) { | |||
update, err := eg.ID(m.Id).Cols(cols...).Update(m) | |||
if err != nil || update == 0 { | |||
return int64(m.Id), err | |||
} | |||
return int64(m.Id), nil | |||
} | |||
// 分页查询打印明细 | |||
func GetPrinterRecordList(Db *xorm.Engine, parameter *md.RecordRequest) ([]md.RecordResList, error) { | |||
var list []model.CommunityTeamStorePrinterDetail | |||
var webList []md.RecordResList | |||
session := Db.Where("store_id >0 and store_id=?", parameter.StoreId) | |||
if utils.StrToInt(parameter.PrinterId) > 0 { | |||
session.And("printer_id=? ", parameter.PrinterId) | |||
} | |||
if parameter.StartTime != "" { | |||
session.And("create_time>=? ", parameter.StartTime) | |||
} | |||
if parameter.EndTime != "" { | |||
session.And("create_time<=? ", parameter.EndTime) | |||
} | |||
//分页 | |||
if utils.StrToInt(parameter.P) > 0 && utils.StrToInt(parameter.PageSize) > 0 { | |||
session = session.Limit(utils.StrToInt(parameter.PageSize), (utils.StrToInt(parameter.P)-1)*utils.StrToInt(parameter.PageSize)) | |||
} | |||
//排序 | |||
if parameter.Sort == "printer_time_desc" { | |||
session.Desc("create_time") | |||
} else if parameter.Sort == "printer_time_asc" { | |||
session.Asc("create_time") | |||
} else { | |||
session.Desc("id") | |||
} | |||
//排序 | |||
err := session.Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
for _, v := range list { | |||
var tmp = md.RecordResList{ | |||
Id: utils.IntToStr(v.Id), | |||
OrdId: v.OrdId, | |||
OrdType: utils.IntToStr(v.OrdType), | |||
PrintContent: v.PrintContent, | |||
State: utils.IntToStr(v.State), | |||
PrintTime: v.PrintTime.Format("2006-01-02 15:04:05"), | |||
CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"), | |||
} | |||
if tmp.PrintTime == "0001-01-01 00:00:00" { | |||
tmp.PrintTime = "" | |||
} | |||
webList = append(webList, tmp) | |||
} | |||
return webList, nil | |||
} |
@@ -0,0 +1,60 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"xorm.io/xorm" | |||
) | |||
// 查询所有的模板 | |||
func GetAllPrinterModuleList(Db *xorm.Engine) ([]model.CommunityTeamStorePrinterModule, error) { | |||
var list []model.CommunityTeamStorePrinterModule | |||
err := Db.Desc("create_time").Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return list, nil | |||
} | |||
func GetAllPrinterModuleListByModuleId(Db *xorm.Engine, moduleIds []int) ([]model.CommunityTeamStorePrinterModule, error) { | |||
var list []model.CommunityTeamStorePrinterModule | |||
err := Db.In("id", moduleIds).Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return list, nil | |||
} | |||
func GetAllPrinterModuleListByModuleIdOne(Db *xorm.Engine, moduleId int) (*model.CommunityTeamStorePrinterModule, error) { | |||
var list model.CommunityTeamStorePrinterModule | |||
has, err := Db.Where("id=?", moduleId).Get(&list) | |||
if has == false || err != nil { | |||
return nil, err | |||
} | |||
return &list, nil | |||
} | |||
// 分页查询方案 | |||
func GetPrinterModuleList(Db *xorm.Engine, parameter *md.IndexRequest) ([]md.ModuleResList, error) { | |||
var list []model.CommunityTeamStorePrinterModule | |||
var webList []md.ModuleResList | |||
session := Db.Where("is_use= 1 ") | |||
//分页 | |||
if utils.StrToInt(parameter.P) > 0 && utils.StrToInt(parameter.PageSize) > 0 { | |||
session = session.Limit(utils.StrToInt(parameter.PageSize), (utils.StrToInt(parameter.P)-1)*utils.StrToInt(parameter.PageSize)) | |||
} | |||
//排序 | |||
err := session.Desc("create_time").Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
for _, v := range list { | |||
var tmp = md.ModuleResList{ | |||
Id: utils.IntToStr(v.Id), | |||
Name: v.Name, | |||
Content: v.Content, | |||
} | |||
webList = append(webList, tmp) | |||
} | |||
return webList, nil | |||
} |
@@ -0,0 +1,19 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type CommunityTeamStorePrinter struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
StoreId int `json:"store_id" xorm:"not null comment('店铺id') INT(11)"` | |||
SnNum string `json:"sn_num" xorm:"not null comment('打印机SN编号') VARCHAR(255)"` | |||
IdentificationCode string `json:"identification_code" xorm:"not null comment('打印机识别码') VARCHAR(255)"` | |||
Name string `json:"name" xorm:"not null comment('打印机名字') VARCHAR(255)"` | |||
ModuleId int `json:"module_id" xorm:"comment('打印模版id') INT(11)"` | |||
IsUse int `json:"is_use" xorm:"not null comment('是否使用') TINYINT(1)"` | |||
CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||
UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` | |||
Type string `json:"type" xorm:"not null default 'ordinary' comment('打印机类型 ordinary普通打印机 cloud云打印机') VARCHAR(255)"` | |||
LocationType string `json:"location_type" xorm:"not null default '' comment('打印机位置') VARCHAR(255)"` | |||
} |
@@ -0,0 +1,21 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type CommunityTeamStorePrinterDetail struct { | |||
Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"` | |||
OrdId string `json:"ord_id" xorm:"not null comment('订单id') VARCHAR(255)"` | |||
OrdType int `json:"ord_type" xorm:"not null comment('订单类型') INT(11)"` | |||
PrinterId int `json:"printer_id" xorm:"not null comment('打印机id') INT(11)"` | |||
PrinterModuleId int `json:"printer_module_id" xorm:"not null comment('模版id') INT(11)"` | |||
PrintContent string `json:"print_content" xorm:"not null comment('打印内容') TEXT"` | |||
FailMsg string `json:"fail_msg" xorm:"not null comment('打印失败原因') TEXT"` | |||
PrinterOid string `json:"printer_oid" xorm:"not null comment('打印订单号') VARCHAR(255)"` | |||
State int `json:"state" xorm:"not null comment('状态') INT(11)"` | |||
StoreId int `json:"store_id" xorm:"not null comment('店铺id') INT(11)"` | |||
PrintTime time.Time `json:"print_time" xorm:"comment('打印时间') DATETIME"` | |||
CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||
UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` | |||
} |
@@ -0,0 +1,14 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type CommunityTeamStorePrinterModule struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Name string `json:"name" xorm:"not null comment('模版名称') VARCHAR(255)"` | |||
IsUse int `json:"is_use" xorm:"not null comment('是否使用') TINYINT(1)"` | |||
Content string `json:"content" xorm:"not null comment('模版内容') TEXT"` | |||
CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||
UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` | |||
} |
@@ -0,0 +1,65 @@ | |||
package hdl | |||
import ( | |||
"applet/app/e" | |||
"applet/app/svc" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func PrinterCateList(c *gin.Context) { | |||
svc.PrinterCateList(c) | |||
} | |||
func PrinterLocationList(c *gin.Context) { | |||
svc.PrinterLocationList(c) | |||
} | |||
// 打印机 | |||
func PrinterIndex(c *gin.Context) { | |||
svc.PrinterIndexList(c) | |||
} | |||
// 模板列表 | |||
func PrinterModule(c *gin.Context) { | |||
svc.PrinterModuleList(c) | |||
} | |||
// 保存 | |||
func PrinterIndexSave(c *gin.Context) { | |||
svc.PrinterIndexSave(c) | |||
} | |||
// 保存模板id | |||
func PrinterIndexModuleSave(c *gin.Context) { | |||
svc.PrinterIndexModuleSave(c) | |||
} | |||
// 使用状态保存 | |||
func PrinterIndexStateSave(c *gin.Context) { | |||
svc.PrinterIndexStateSave(c) | |||
} | |||
// 删除接口 | |||
func PrinterIndexDel(c *gin.Context) { | |||
var idsMap map[string]string | |||
if err := c.ShouldBindJSON(&idsMap); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
svc.PrinterDelIndex(c, idsMap["id"], idsMap["store_id"]) | |||
} | |||
// 明细 | |||
func PrinterIndexRecord(c *gin.Context) { | |||
svc.PrinterIndexRecordList(c) | |||
} | |||
// 明细筛选 | |||
func PrinterIndexRecordScreen(c *gin.Context) { | |||
svc.PrinterIndexRecordScreen(c) | |||
} | |||
func PrinterIndexToSend(c *gin.Context) { | |||
svc.PrinterIndexToSend(c) | |||
} | |||
func PrinterIndexCheck(c *gin.Context) { | |||
svc.PrinterIndexCheck(c) | |||
} |
@@ -0,0 +1,58 @@ | |||
package hdl | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func StoreIndexTotal(c *gin.Context) { | |||
var arg map[string]string | |||
if err := c.ShouldBindJSON(&arg); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
user := svc.GetUser(c) | |||
stime, etime := svc.GetDate(c, arg) | |||
sql := `select SUM(amount-agent_commission-platform_commission) AS money,SUM(amount) AS amount,SUM(commission) AS commission,SUM(IF(state=3,1,0)) as count,SUM(IF(state in(1,2),1,0)) as success_count, | |||
SUM(IF(state=1,1,0)) as wait_count | |||
from community_team_order | |||
where %s | |||
` | |||
where := "store_uid=" + utils.IntToStr(user.Info.Uid) + " and state>0" | |||
wherePay := where + " and create_at>='" + stime.Format("2006-01-02 15:04:05") + "' and create_at<'" + etime.Format("2006-01-02 15:04:05") + "'" | |||
sqlPay := fmt.Sprintf(sql, wherePay) | |||
nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sqlPay) | |||
amount := "0" | |||
money := "0" | |||
commission := "0" | |||
count := "0" | |||
successCount := "0" | |||
waitCount := "0" | |||
for _, v := range nativeString { | |||
amount = v["amount"] | |||
money = v["money"] | |||
commission = v["commission"] | |||
count = v["count"] | |||
successCount = v["success_count"] | |||
waitCount = v["wait_count"] | |||
} | |||
store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid)) | |||
tmp := []map[string]string{ | |||
{"name": "营业总额", "value": svc.GetCommissionPrec(c, amount, "2", "1")}, | |||
} | |||
if store.StoreType == 0 { | |||
tmp = append(tmp, map[string]string{"name": "佣金收益", "value": svc.GetCommissionPrec(c, commission, "2", "1")}) | |||
} | |||
if store.StoreType > 0 { | |||
tmp = append(tmp, map[string]string{"name": "订单收益", "value": svc.GetCommissionPrec(c, money, "2", "1")}) | |||
} | |||
tmp = append(tmp, map[string]string{"name": "已付款订单量", "value": successCount}) | |||
tmp = append(tmp, map[string]string{"name": "已取消订单量", "value": count}) | |||
tmp = append(tmp, map[string]string{"name": "待提货订单量", "value": waitCount}) | |||
e.OutSuc(c, tmp, nil) | |||
return | |||
} |
@@ -0,0 +1,113 @@ | |||
package md | |||
// 模板列表请求参数 | |||
type ModuleRequest struct { | |||
Name string `json:"name"` //名称 | |||
IsUse string `json:"is_use"` //是否使用(否:0;是:1) | |||
P string `json:"p"` | |||
PageSize string `json:"page_size"` //页大小 | |||
} | |||
// 模板列表请求参数 | |||
type ModuleSaveRequest struct { | |||
Name string `json:"name"` //名称 | |||
IsUse string `json:"is_use"` //是否使用(否:0;是:1) | |||
Id string `json:"id"` // | |||
Content string `json:"content"` // | |||
} | |||
// 打印机列表请求参数 | |||
type IndexSaveRequest struct { | |||
Id string `json:"id"` // | |||
StoreId string `json:"store_id" ` | |||
SnNum string `json:"sn_num" ` | |||
IdentificationCode string `json:"identification_code" ` | |||
Name string `json:"name"` | |||
ModuleId string `json:"module_id" ` | |||
IsUse string `json:"is_use" ` | |||
Type string `json:"type"` | |||
LocationType string `json:"location_type"` | |||
} | |||
// 打印机列表请求参数 | |||
type IndexRequest struct { | |||
StoreId string `json:"store_id"` //店铺id | |||
P string `json:"p"` | |||
PageSize string `json:"size"` //页大小 | |||
} | |||
// 打印机测试打印请求参数 | |||
type IndexTestRequest struct { | |||
StoreId string `json:"store_id"` //店铺id | |||
PrinterId string `json:"printer_id"` //打印机id | |||
} | |||
// 打印机明细请求参数 | |||
type RecordRequest struct { | |||
StoreId string `json:"store_id"` //店铺id | |||
PrinterId string `json:"printer_id"` //打印机id | |||
StartTime string `json:"start_time"` //打印开始时间 | |||
EndTime string `json:"end_time"` //打印结束时间 | |||
P string `json:"p"` | |||
PageSize string `json:"size"` //页大小 | |||
Sort string `json:"sort"` | |||
} | |||
// 打印机列表返回数据 | |||
type IndexResList struct { | |||
Id string `json:"id"` | |||
Name string `json:"name"` | |||
IsUse string `json:"is_use"` | |||
StoreId string `json:"store_id" ` | |||
ModuleId string `json:"module_id" ` | |||
ModuleStr string `json:"module_str" ` | |||
UseStr string `json:"use_str" ` | |||
SnNum string `json:"sn_num" ` | |||
IdentificationCode string `json:"identification_code" ` | |||
Content string `json:"content" ` | |||
Img string `json:"img" ` | |||
TypeStr string `json:"type_str"` | |||
Type string `json:"type"` | |||
LocationTypeStr string `json:"location_type_str"` | |||
LocationType string `json:"location_type"` | |||
} | |||
// 打印机模板返回数据 | |||
type ModuleResList struct { | |||
Id string `json:"id"` | |||
Name string `json:"name"` | |||
Content string `json:"content"` | |||
} | |||
// 打印机列表返回数据 | |||
type RecordResList struct { | |||
Id string `json:"id"` | |||
OrdId string `json:"ord_id"` | |||
OrdType string `json:"ord_type"` | |||
Title string `json:"title" ` | |||
PrintContent string `json:"print_content" ` | |||
State string `json:"state" ` | |||
PrintTime string `json:"print_time" ` | |||
CreateTime string `json:"create_time"` | |||
OrdTypeStr string `json:"ord_type_str"` | |||
StateStr string `json:"state_str"` | |||
} | |||
type RecordPrinterScreen struct { | |||
TimeSort []NewSelectList `json:"time_sort"` | |||
PrinterList []NewSelectList `json:"printer_list"` | |||
} | |||
type PrinterRequest struct { | |||
StoreId string `json:"store_id"` | |||
PrinterId string `json:"printer_id"` | |||
MasterId string `json:"master_id"` | |||
Ord map[string]string `json:"ord"` | |||
GoodsInfo []map[string]string `json:"goods_info"` | |||
} | |||
type NewSelectList struct { | |||
Key string `json:"key"` | |||
Name string `json:"name"` | |||
} |
@@ -0,0 +1,29 @@ | |||
package md | |||
type PrinterReq struct { | |||
Sn string `json:"sn"` | |||
Key string `json:"key"` | |||
Remark string `json:"remark"` | |||
PhoneNum string `json:"phone_num"` | |||
Content string `json:"content"` | |||
Name string `json:"name"` | |||
Oid string `json:"oid"` | |||
PrinterType string `json:"printer_type"` | |||
} | |||
type AddPrinterResult struct { | |||
Data struct { | |||
No []string `json:"no"` | |||
Ok []string `json:"ok"` | |||
} `json:"data"` | |||
Msg string `json:"msg"` | |||
Ret int64 `json:"ret"` | |||
ServerExecutedTime int64 `json:"serverExecutedTime"` | |||
} | |||
type PrinterStateResult struct { | |||
Data interface{} `json:"data"` | |||
Msg string `json:"msg"` | |||
Ret int64 `json:"ret"` | |||
ServerExecutedTime int64 `json:"serverExecutedTime"` | |||
} |
@@ -187,4 +187,20 @@ func routeCommunityTeam(r *gin.RouterGroup) { | |||
r.POST("/store/order/detail", hdl.StoreOrderDetail) | |||
r.POST("/store/order/confirm", hdl.StoreOrderConfirm) | |||
r.GET("/store/order/cate", hdl.StoreOrderCate) | |||
r.POST("/store/index/total", hdl.StoreIndexTotal) | |||
r.GET("/printer/cate/list", hdl.PrinterCateList) //打印机类型列表 | |||
r.GET("/printer/location/list", hdl.PrinterLocationList) //打印机位置列表 | |||
r.POST("/printer/list", hdl.PrinterIndex) //打印机列表 | |||
r.POST("/printer/save", hdl.PrinterIndexSave) //打印机添加编辑 | |||
r.POST("/printer/del", hdl.PrinterIndexDel) //打印机删除 | |||
r.POST("/printer/module/list", hdl.PrinterModule) //打印机模板 | |||
r.POST("/printer/module/save", hdl.PrinterIndexModuleSave) //打印机模板选择 | |||
r.POST("/printer/use/save", hdl.PrinterIndexStateSave) //打印机使用状态调整 | |||
r.POST("/printer/record/list", hdl.PrinterIndexRecord) //打印机明细 | |||
r.POST("/printer/record/screen", hdl.PrinterIndexRecordScreen) //打印机筛选 | |||
r.POST("/printer/send", hdl.PrinterIndexToSend) //打印机测试 | |||
r.POST("/printer/check", hdl.PrinterIndexCheck) //订 | |||
} |
@@ -0,0 +1,62 @@ | |||
package svc | |||
import ( | |||
"applet/app/lib/zhimeng" | |||
"encoding/json" | |||
"github.com/gin-gonic/gin" | |||
"github.com/tidwall/gjson" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
) | |||
var DWZ_TOKEN = "eecdf4b18f416b0cf26fef98f7e1f4ff" | |||
// KuaiZhanShortURL is 快站短链 | |||
func KuaiZhanShortURL(c *gin.Context, url string) string { | |||
args := map[string]interface{}{ | |||
"appkey": SysCfgGet(c, "third_zm_app_key"), | |||
"secret_key": SysCfgGet(c, "third_zm_app_key"), | |||
"url": utils.Base64StdEncode(url), | |||
} | |||
resp, err := zhimeng.Send("kuaizhan", "short_url", args) | |||
if err != nil { | |||
return "" | |||
} | |||
kurl := gjson.GetBytes(resp, "data.shortUrl").String() | |||
if kurl == "" { | |||
kurl = url | |||
} | |||
return kurl | |||
} | |||
func ShortenUrl(url string) (string, error) { | |||
host := "https://dwz.cn/admin/v2/create" | |||
args := map[string]string{ | |||
"Url": url, | |||
"TermOfValidity": "1-year", | |||
} | |||
resp, err := utils.CurlPost(host, utils.Serialize(args), map[string]string{ | |||
"Content-Type": "application/json", | |||
"Token": DWZ_TOKEN, | |||
}) | |||
// {"Code":0,"IsNew":true,"ShortUrl":"https://dwz.cn/4kSgiKVl","LongUrl":"https://open.taobao.com/search.htm?q=taobao.tbk.sc.material","ErrMsg":""} | |||
if err != nil { | |||
return "", logx.Warn(err) | |||
} | |||
var tmp struct { | |||
Code int `json:"Code"` | |||
IsNew bool `json:"IsNew"` | |||
ShortURL string `json:"ShortUrl"` | |||
LongURL string `json:"LongUrl"` | |||
ErrMsg string `json:"ErrMsg"` | |||
} | |||
if err = json.Unmarshal(resp, &tmp); err != nil { | |||
return url, logx.Warn("resp: " + string(resp) + ", err:" + err.Error()) | |||
} | |||
if tmp.ShortURL == "" { | |||
tmp.ShortURL = url | |||
} | |||
return tmp.ShortURL, nil | |||
} |
@@ -0,0 +1,283 @@ | |||
package svc | |||
import ( | |||
"applet/app/e" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"crypto/sha1" | |||
"encoding/hex" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"github.com/syyongx/php2go" | |||
"io/ioutil" | |||
"net/http" | |||
"net/url" | |||
"strconv" | |||
"strings" | |||
"time" | |||
) | |||
var ( | |||
USER = "1157453392@qq.com" //必填,飞鹅云后台注册的账号名 | |||
UKEY = "apXI36MYv6rkY8ft" //必填,飞鹅云后台注册账号后生成的UKEY | |||
//SN = "xxxxxxxxx" //必填,打印机编号,必须要在管理后台里手动添加打印机或者通过API添加之后,才能调用API | |||
URL = "http://api.feieyun.cn/Api/Open/" //不需要修改 | |||
) | |||
// 添加打印机 | |||
func AddPrinter(c *gin.Context, args md.PrinterReq) error { | |||
//提示:打印机编号(必填) # 打印机识别码(必填) # 备注名称(选填) # 流量卡号码(选填),多台打印机请换行(\n)添加新打印机信息,每次最多100行(台)。 | |||
if args.PrinterType == "cloud" { //云打印 | |||
//AddCloudPrinter(c, args) | |||
} else { | |||
//拼接参数 | |||
snList := fmt.Sprintf("%s#%s#%s", args.Sn, args.Key, args.Remark) | |||
//请求接口 | |||
postValues := url.Values{} | |||
postValues.Add("apiname", "Open_printerAddlist") //固定 | |||
postValues.Add("printerContent", snList) //打印机 | |||
data := post(postValues) | |||
fmt.Println(data) | |||
var res md.AddPrinterResult | |||
err := json.Unmarshal([]byte(data), &res) | |||
if err != nil { | |||
return e.NewErr(400, "添加失败") | |||
} | |||
//处理错误信息 | |||
if len(res.Data.No) > 0 { | |||
msg := res.Data.No[0] | |||
msgArr := strings.Split(msg, " ") | |||
msg = "" | |||
if len(msgArr) > 0 { | |||
msg = msgArr[1] | |||
} | |||
//被添加过的 默认成功 | |||
if strings.Contains(msg, "已被添加过") { | |||
e.OutSuc(c, "success", nil) | |||
return nil | |||
} | |||
return e.NewErr(400, "添加失败,"+msg) | |||
} | |||
return nil | |||
} | |||
return nil | |||
} | |||
// 打印机状态 | |||
func PrinterState(c *gin.Context) { | |||
var args md.PrinterReq | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS) | |||
return | |||
} | |||
if args.PrinterType == "cloud" { //云打印 | |||
//GetPrinterStatus(c, args) | |||
} else { | |||
//调用接口 | |||
postValues := url.Values{} | |||
postValues.Add("apiname", "Open_queryPrinterStatus") //固定 | |||
postValues.Add("sn", args.Sn) //打印机编号 | |||
data := post(postValues) | |||
fmt.Println(data) | |||
var res md.PrinterStateResult | |||
err := json.Unmarshal([]byte(data), &res) | |||
//处理返回信息 | |||
r := make(map[string]string, 0) | |||
if err != nil { | |||
r["state"] = "0" | |||
r["msg"] = err.Error() | |||
} | |||
if res.Ret != 0 { | |||
r["state"] = "0" | |||
r["msg"] = res.Msg | |||
} | |||
data1 := utils.AnyToString(res.Data) | |||
r["msg"] = data1 | |||
if strings.Contains(data, "离线") { | |||
r["state"] = "1" | |||
} | |||
if strings.Contains(data, "在线,工作状态正常") { | |||
r["state"] = "2" | |||
} | |||
if strings.Contains(data, "在线,工作状态不正常") { | |||
r["state"] = "3" | |||
} | |||
e.OutSuc(c, r, nil) | |||
return | |||
} | |||
} | |||
// 删除打印机 | |||
func DelPrinter(c *gin.Context, args md.PrinterReq) error { | |||
if args.PrinterType == "cloud" { //云打印 | |||
//DelCloudPrinter(c, args) | |||
} else { | |||
//拼接参数 | |||
snList := args.Sn | |||
//请求接口 | |||
postValues := url.Values{} | |||
postValues.Add("apiname", "Open_printerDelList") //固定 | |||
postValues.Add("snlist", snList) //打印机 | |||
data := post(postValues) | |||
fmt.Println(data) | |||
var res md.AddPrinterResult | |||
err := json.Unmarshal([]byte(data), &res) | |||
if err != nil { | |||
return e.NewErr(400, "删除失败") | |||
} | |||
//处理错误信息 | |||
if len(res.Data.No) > 0 { | |||
msg := res.Data.No[0] | |||
return e.NewErr(400, "删除失败,"+msg) | |||
} | |||
return nil | |||
} | |||
return nil | |||
} | |||
// 修改打印机 | |||
func EditPrinter(c *gin.Context, args md.PrinterReq) error { | |||
if args.PrinterType == "cloud" { //云打印 | |||
//AddCloudPrinter(c, args) | |||
} else { | |||
//请求接口 | |||
postValues := url.Values{} | |||
postValues.Add("apiname", "Open_printerEdit") //固定 | |||
postValues.Add("sn", args.Sn) //打印机编号 | |||
postValues.Add("name", args.Remark) //打印机备注名称 | |||
if args.PhoneNum != "" { | |||
postValues.Add("phonenum", args.PhoneNum) | |||
} //打印机流量卡号码 | |||
data := post(postValues) | |||
fmt.Println(data) | |||
var res md.PrinterStateResult | |||
err := json.Unmarshal([]byte(data), &res) | |||
if err != nil { | |||
return e.NewErr(400, "修改失败") | |||
} | |||
//处理错误信息 | |||
if res.Ret != 0 { | |||
return e.NewErr(400, "修改失败,"+res.Msg) | |||
} | |||
return nil | |||
} | |||
return nil | |||
} | |||
// 打印机操作 | |||
func PrinterDoing(c *gin.Context) { | |||
var args md.PrinterReq | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS) | |||
return | |||
} | |||
data, msg := CommDoing(c, args.Content, args.Sn, args.PrinterType, args.Oid) | |||
if msg != "" { | |||
e.OutErr(c, 400, e.NewErr(400, msg)) | |||
return | |||
} | |||
e.OutSuc(c, map[string]string{"oid": utils.AnyToString(data)}, nil) | |||
return | |||
} | |||
func CommDoing(c *gin.Context, content, sn, printerType, oid string) (string, string) { | |||
if printerType == "cloud" { //云打印 | |||
//args := md.PrinterReq{ | |||
// Sn: sn, | |||
// Content: content, | |||
// Oid: oid, | |||
// PrinterType: printerType, | |||
//} | |||
//oids, err := CloudPrintDoing(c, args) | |||
//if err != nil || oids == "" { | |||
// return "", "打印失败" | |||
//} | |||
return "", "" | |||
} else { | |||
content1, _ := php2go.Base64Decode(content) | |||
if content1 != "" { | |||
content = content1 | |||
} | |||
//请求接口 | |||
postValues := url.Values{} | |||
postValues.Add("apiname", "Open_printMsg") //固定 | |||
postValues.Add("sn", sn) //打印机编号 | |||
postValues.Add("content", content) //打印内容 | |||
postValues.Add("times", "1") //打印次数,默认为1。 | |||
data := post(postValues) | |||
fmt.Println(data) | |||
var res md.PrinterStateResult | |||
err := json.Unmarshal([]byte(data), &res) | |||
if err != nil { | |||
return "", "打印失败" | |||
} | |||
//处理错误信息 | |||
if res.Ret != 0 { | |||
return "", "打印失败," + res.Msg | |||
} | |||
return res.Data.(string), "" | |||
} | |||
} | |||
// 订单打印状态 | |||
func PrinterOrderState(c *gin.Context) { | |||
var args md.PrinterReq | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS) | |||
return | |||
} | |||
if args.PrinterType == "cloud" { //云打印 | |||
//GetOrdStatus(c, args) | |||
} else { | |||
//请求接口 | |||
postValues := url.Values{} | |||
postValues.Add("apiname", "Open_queryOrderState") //固定 | |||
postValues.Add("orderid", args.Oid) //订单ID | |||
data := post(postValues) | |||
fmt.Println(data) | |||
var res md.PrinterStateResult | |||
err := json.Unmarshal([]byte(data), &res) | |||
if err != nil { | |||
e.OutErr(c, 400, e.NewErr(400, "查询失败")) | |||
return | |||
} | |||
//处理错误信息 | |||
if res.Ret != 0 { | |||
e.OutErr(c, 400, e.NewErr(400, "查询失败,"+res.Msg)) | |||
return | |||
} | |||
reqState := utils.AnyToBool(res.Data) | |||
state := "0" | |||
if reqState { | |||
state = "1" | |||
} | |||
e.OutSuc(c, map[string]string{"state": state}, nil) | |||
return | |||
} | |||
} | |||
func post(postValues url.Values) string { | |||
itime := time.Now().Unix() | |||
stime := strconv.FormatInt(itime, 10) | |||
sig := SHA1(USER + UKEY + stime) //生成签名 | |||
client := http.Client{} | |||
postValues.Add("user", USER) //账号名 | |||
postValues.Add("stime", stime) //当前时间的秒数,请求时间 | |||
postValues.Add("sig", sig) //签名 | |||
res, _ := client.PostForm(URL, postValues) | |||
data, _ := ioutil.ReadAll(res.Body) | |||
fmt.Println(string(data)) //服务器返回的JSON字符串,建议要当做日志记录起来 | |||
res.Body.Close() | |||
return string(data) | |||
} | |||
func SHA1(str string) string { | |||
s := sha1.Sum([]byte(str)) | |||
strsha1 := hex.EncodeToString(s[:]) | |||
return strsha1 | |||
} |
@@ -0,0 +1,560 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/e" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func PrinterCateList(c *gin.Context) { | |||
var list = []map[string]string{ | |||
{ | |||
"name": "普通打印机", | |||
"key": "ordinary", | |||
}, | |||
} | |||
e.OutSuc(c, list, nil) | |||
return | |||
} | |||
func PrinterLocationList(c *gin.Context) { | |||
var list = []map[string]string{ | |||
{ | |||
"name": "前台", | |||
"key": "reception", | |||
}, | |||
{ | |||
"name": "后厨", | |||
"key": "kitchen", | |||
}, | |||
} | |||
e.OutSuc(c, list, nil) | |||
return | |||
} | |||
// 打印机列表 | |||
func PrinterIndexList(c *gin.Context) { | |||
var search md.IndexRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
engine := MasterDb(c) | |||
if engine == nil { | |||
e.OutErr(c, e.ERR_MASTER_ID, nil) | |||
return | |||
} | |||
list, err := db.GetPrinterIndexList(engine, &search) | |||
fmt.Println(err) | |||
fmt.Println(list) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_BAD_REQUEST, err) | |||
return | |||
} | |||
if list == nil { | |||
list = make([]md.IndexResList, 0) | |||
} | |||
printerModule, _ := db.GetAllPrinterModuleList(engine) | |||
//处理模板数据 | |||
var moduleArr = make(map[int]string, 0) | |||
var moduleContentArr = make(map[int]string, 0) | |||
if printerModule != nil { | |||
for _, v := range printerModule { | |||
moduleArr[v.Id] = v.Name | |||
moduleContentArr[v.Id] = v.Content | |||
} | |||
} | |||
var useArr = []string{"离线", "在线"} | |||
for k, v := range list { | |||
isUse := utils.StrToInt(v.IsUse) | |||
list[k].UseStr = useArr[isUse] | |||
ModuleId := utils.StrToInt(v.ModuleId) | |||
list[k].ModuleStr = moduleArr[ModuleId] | |||
list[k].Content = moduleContentArr[ModuleId] | |||
list[k].Img = "http://ossn.izhim.net/o2o_printer.png" | |||
} | |||
e.OutSuc(c, &list, nil) | |||
return | |||
} | |||
// 模板列表 | |||
func PrinterModuleList(c *gin.Context) { | |||
var search md.IndexRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
engine := MasterDb(c) | |||
if engine == nil { | |||
e.OutErr(c, e.ERR_MASTER_ID, nil) | |||
return | |||
} | |||
list, err := db.GetPrinterModuleList(engine, &search) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_BAD_REQUEST, err) | |||
return | |||
} | |||
if list == nil { | |||
list = make([]md.ModuleResList, 0) | |||
} | |||
e.OutSuc(c, &list, nil) | |||
return | |||
} | |||
func PrinterIndexSave(c *gin.Context) { | |||
var search md.IndexSaveRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
if search.Type == "" { | |||
search.Type = "ordinary" | |||
} | |||
eg := MasterDb(c) | |||
//判断是不是有人绑过了 | |||
if search.Type != "bluetooth" { | |||
count := db.IndexExists(eg, &search) | |||
check := 1 | |||
if utils.StrToInt(search.Id) > 0 { | |||
//判断下是不是同一条记录保存 | |||
data, _ := db.IndexById(eg, &search) | |||
if data != nil && data.SnNum == search.SnNum { | |||
check = 0 | |||
} | |||
} | |||
if count > 0 && check == 1 { | |||
e.OutErr(c, 400, e.NewErr(400, "该打印机已被绑定过")) | |||
return | |||
} | |||
} | |||
var module = model.CommunityTeamStorePrinter{ | |||
Id: utils.StrToInt(search.Id), | |||
StoreId: utils.StrToInt(search.StoreId), | |||
SnNum: search.SnNum, | |||
IdentificationCode: search.IdentificationCode, | |||
Name: search.Name, | |||
IsUse: utils.StrToInt(search.IsUse), | |||
UpdateTime: time.Now(), | |||
Type: search.Type, | |||
LocationType: search.LocationType, | |||
} | |||
if search.Type != "bluetooth" { | |||
args := md.PrinterReq{ | |||
Sn: search.SnNum, | |||
Key: search.IdentificationCode, | |||
Remark: search.Name, | |||
PrinterType: search.Type, | |||
} | |||
//调用公共代码 调用打印机添加与编辑 | |||
if utils.StrToInt(search.Id) > 0 { //编辑 | |||
err := EditPrinter(c, args) | |||
if err != nil { | |||
e.OutErr(c, 400, err) | |||
return | |||
} | |||
} else { | |||
err := AddPrinter(c, args) | |||
if err != nil { | |||
e.OutErr(c, 400, err) | |||
return | |||
} | |||
} | |||
} | |||
id, err := db.IndexInsert(eg, &module) | |||
if id == 0 || err != nil { | |||
e.OutErr(c, 400, e.NewErr(400, "保存失败")) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// 模板id修改 | |||
func PrinterIndexModuleSave(c *gin.Context) { | |||
var search md.IndexSaveRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
var module = model.CommunityTeamStorePrinter{ | |||
Id: utils.StrToInt(search.Id), | |||
ModuleId: utils.StrToInt(search.ModuleId), | |||
UpdateTime: time.Now(), | |||
} | |||
id, err := db.IndexUpdate(MasterDb(c), &module, "module_id,update_time") | |||
if id == 0 || err != nil { | |||
e.OutErr(c, 400, e.NewErr(400, "保存失败")) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// 使用状态修改 | |||
func PrinterIndexStateSave(c *gin.Context) { | |||
var search md.IndexSaveRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
var module = model.CommunityTeamStorePrinter{ | |||
Id: utils.StrToInt(search.Id), | |||
IsUse: utils.StrToInt(search.IsUse), | |||
UpdateTime: time.Now(), | |||
} | |||
id, err := db.IndexUpdate(MasterDb(c), &module, "is_use,update_time") | |||
if id == 0 || err != nil { | |||
e.OutErr(c, 400, e.NewErr(400, "保存失败")) | |||
return | |||
} | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// 删除打印机 | |||
func PrinterDelIndex(c *gin.Context, ids, storeId string) { | |||
engine := MasterDb(c) | |||
//查出这条记录拿sn码 | |||
printerOne, _ := db.GetPrinterIndexById(engine, ids, storeId) | |||
if printerOne.Id == 0 { | |||
e.OutErr(c, 400, e.NewErr(400, "删除失败")) | |||
return | |||
} | |||
if printerOne.Type != "bluetooth" { | |||
//调用打印机删除 | |||
args := md.PrinterReq{ | |||
Sn: printerOne.SnNum, | |||
PrinterType: printerOne.Type, | |||
} | |||
err := DelPrinter(c, args) | |||
if err != nil { | |||
e.OutErr(c, 400, err) | |||
return | |||
} | |||
} | |||
has, err := engine.Where("id=? and store_id=?", ids, storeId).Delete(new(model.CommunityTeamStorePrinter)) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err) | |||
return | |||
} | |||
if has == 0 { | |||
e.OutErr(c, 400, e.NewErr(400, "删除失败")) | |||
return | |||
} | |||
e.OutSuc(c, []int{}, nil) | |||
return | |||
} | |||
// 明细筛选条件 | |||
func PrinterIndexRecordScreen(c *gin.Context) { | |||
var search md.RecordRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
engine := MasterDb(c) | |||
if engine == nil { | |||
e.OutErr(c, e.ERR_MASTER_ID, nil) | |||
return | |||
} | |||
printer, _ := db.GetPrinterIndexAll(engine, search.StoreId) | |||
var r md.RecordPrinterScreen | |||
r.TimeSort = []md.NewSelectList{ | |||
{ | |||
Key: "", | |||
Name: "默认排序", | |||
}, | |||
{ | |||
Key: "printer_time_desc", | |||
Name: "时间由近到远", | |||
}, | |||
{ | |||
Key: "printer_time_asc", | |||
Name: "时间由远到近", | |||
}, | |||
} | |||
r.PrinterList = make([]md.NewSelectList, 0) | |||
for _, v := range printer { | |||
var tmp = md.NewSelectList{ | |||
Key: utils.IntToStr(v.Id), | |||
Name: v.Name, | |||
} | |||
r.PrinterList = append(r.PrinterList, tmp) | |||
} | |||
e.OutSuc(c, r, nil) | |||
return | |||
} | |||
// 明细 | |||
func PrinterIndexRecordList(c *gin.Context) { | |||
var search md.RecordRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
engine := MasterDb(c) | |||
if engine == nil { | |||
e.OutErr(c, e.ERR_MASTER_ID, nil) | |||
return | |||
} | |||
list, err := db.GetPrinterRecordList(engine, &search) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_BAD_REQUEST, err) | |||
return | |||
} | |||
if list == nil { | |||
list = make([]md.RecordResList, 0) | |||
} | |||
var stateArr = []string{"正在打印", "打印成功", "打印失败"} | |||
var ordTypeArr = []string{"聚合收款订单", "外卖订单", "到店订单", "聚合收款订单"} | |||
for k, v := range list { | |||
State := utils.StrToInt(v.State) | |||
list[k].StateStr = stateArr[State] | |||
OrdType := utils.StrToInt(v.OrdType) | |||
list[k].OrdTypeStr = ordTypeArr[OrdType] | |||
list[k].Title = "#" + v.Id + " " + ordTypeArr[OrdType] | |||
if v.OrdId == "XXX" { | |||
list[k].Title = "#" + v.Id + " 测试" | |||
} | |||
list[k].PrintContent = strings.ReplaceAll(v.PrintContent, "<BR>", "\n") | |||
list[k].PrintContent = strings.ReplaceAll(list[k].PrintContent, "<QR>", "<二维码标签左>") | |||
list[k].PrintContent = strings.ReplaceAll(list[k].PrintContent, "</QR>", "<二维码标签右>") | |||
} | |||
e.OutSuc(c, &list, nil) | |||
return | |||
} | |||
func PrinterIndexToSend(c *gin.Context) { | |||
var search md.IndexTestRequest | |||
if err := c.ShouldBindJSON(&search); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
// 加锁 防止并发 | |||
mutexKey := fmt.Sprintf("%s:printer_send:p%ss%s", c.GetString("mid"), search.PrinterId, search.StoreId) | |||
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX") | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err) | |||
return | |||
} | |||
if withdrawAvailable != "OK" { | |||
e.OutErr(c, e.ERR, e.NewErr(400000, "操作过于频繁,请稍后再试")) | |||
return | |||
} | |||
eg := MasterDb(c) | |||
printerOne, _ := db.GetPrinterIndexById(eg, search.PrinterId, search.StoreId) | |||
if printerOne.Id == 0 { | |||
e.OutErr(c, 400, e.NewErr(400, "打印机不存在")) | |||
return | |||
} | |||
if printerOne.ModuleId == 0 { | |||
e.OutErr(c, 400, e.NewErr(400, "请选择打印模板")) | |||
return | |||
} | |||
ord := make(map[string]string, 0) | |||
ord["name"] = "XXX" | |||
ord["payment"] = "XXX" | |||
ord["phone"] = "XXX" | |||
ord["address"] = "XXX" | |||
ord["main_ord_id"] = "XXX" | |||
ord["num"] = "XXX" | |||
ord["table_num"] = "XXX" | |||
ord["store_name"] = "XXX" | |||
ord["store_qrcode_url"] = getStoreUrl(c, search.StoreId, "") | |||
ord["qrcode_url"] = getDownUrl(c, "") | |||
goodsInfo := make([]map[string]string, 0) | |||
one := map[string]string{ | |||
"name": "测试", | |||
"price": "10", | |||
"num": "1", | |||
"prices": "10", | |||
} | |||
goodsInfo = append(goodsInfo, one) | |||
var args = &md.PrinterRequest{ | |||
StoreId: search.StoreId, | |||
PrinterId: search.PrinterId, | |||
MasterId: c.GetString("mid"), | |||
Ord: ord, | |||
GoodsInfo: goodsInfo, | |||
} | |||
ReplaceOne(c, args) | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
// 处理订单打印内容 | |||
func ReplacePrinterContent(c *gin.Context) { | |||
var maps map[string]string | |||
if err := c.ShouldBindJSON(&maps); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
mainOrdId := maps["main_ord_id"] | |||
// 加锁 防止并发 | |||
mutexKey := fmt.Sprintf("%s:printer_content:%s", c.GetString("mid"), mainOrdId) | |||
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX") | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err) | |||
return | |||
} | |||
if withdrawAvailable != "OK" { | |||
e.OutErr(c, e.ERR, e.NewErr(400000, "操作过于频繁,请稍后再试")) | |||
return | |||
} | |||
engine := MasterDb(c) | |||
storeId, ord, goodsInfo, err := CommGetPrinterContent(c, mainOrdId) | |||
if err != nil { | |||
e.OutErr(c, 400, err) | |||
return | |||
} | |||
//打印操作 | |||
go ReplaceDoing(c, engine, storeId, ord, goodsInfo) | |||
e.OutSuc(c, "success", nil) | |||
return | |||
} | |||
func CommGetPrinterContent(c *gin.Context, mainOrdId string) (int, map[string]string, []map[string]string, error) { | |||
var storeId int | |||
ord := make(map[string]string, 0) | |||
var goodsInfo = make([]map[string]string, 0) | |||
engine := MasterDb(c) | |||
mainOrd := db.GetOrderByOid(engine, mainOrdId) | |||
if mainOrd == nil { | |||
return storeId, ord, goodsInfo, e.NewErr(400, "未查询到订单!") | |||
} | |||
ordItem := db.GetOrderInfoAllEg(engine, mainOrdId) | |||
if ordItem == nil { | |||
return storeId, ord, goodsInfo, e.NewErr(400, "未查询到订单!") | |||
} | |||
//查出订单id | |||
storeId = mainOrd.StoreUid | |||
ord["name"] = mainOrd.BuyName | |||
ord["phone"] = mainOrd.BuyPhone | |||
ord["address"] = mainOrd.Address | |||
ord["main_ord_id"] = utils.Int64ToStr(mainOrd.Oid) | |||
ord["order_type"] = "2" | |||
if mainOrd.Code != "" { | |||
ord["num"] = mainOrd.Code | |||
} | |||
if mainOrd.TableNum != "" { | |||
ord["table_num"] = mainOrd.TableNum | |||
} | |||
var storeInfo model.CommunityTeamStore | |||
engine.Where("uid = ?", storeId).Get(&storeInfo) | |||
ord["store_name"] = storeInfo.Name | |||
userProfile, _ := db.UserProfileFindByID(engine, storeId) | |||
inviteCode := "" | |||
if userProfile != nil && userProfile.Uid > 0 { | |||
inviteCode = userProfile.InviteCode | |||
} | |||
ord["qrcode_url"] = getDownUrl(c, inviteCode) | |||
ord["store_qrcode_url"] = getStoreUrl(c, utils.IntToStr(storeId), inviteCode) | |||
//查出对应商品的信息 | |||
var payment float64 = 0 | |||
for _, v := range *ordItem { | |||
one := map[string]string{ | |||
"name": v.Title, | |||
"price": utils.Float64ToStr(utils.FloatFormat(utils.StrToFloat64(v.Price)/float64(v.Num), 2)), | |||
"num": utils.IntToStr(v.Num), | |||
"prices": v.Price, | |||
} | |||
payment += utils.StrToFloat64(v.Price) | |||
one["sku_text"] = "" | |||
skuText := make([]map[string]string, 0) | |||
json.Unmarshal([]byte(v.SkuInfo), &skuText) | |||
if len(skuText) > 0 { | |||
skuText1 := "" | |||
for _, v1 := range skuText { | |||
skuText1 += v1["name"] + ":" + v1["value"] + " " | |||
} | |||
one["sku_text"] = skuText1 | |||
} | |||
goodsInfo = append(goodsInfo, one) | |||
} | |||
payment = utils.FloatFormat(payment, 2) | |||
ord["payment"] = utils.Float64ToStr(payment) | |||
return storeId, ord, goodsInfo, nil | |||
} | |||
// 替换打印 | |||
func ReplaceDoing(c *gin.Context, eg *xorm.Engine, storeId int, ord map[string]string, goodsInfo []map[string]string) { | |||
var args = &md.PrinterRequest{ | |||
StoreId: utils.IntToStr(storeId), | |||
PrinterId: "", | |||
MasterId: c.GetString("mid"), | |||
Ord: ord, | |||
GoodsInfo: goodsInfo, | |||
} | |||
ReplaceMore(c, args) | |||
} | |||
func getDownUrl(c *gin.Context, inviteCode string) string { | |||
downLoadRoute := "/#/zy-landing-page/pages/lading-page-download/lading-page-download?invited_code=" + inviteCode | |||
h5Domain := GetWebSiteDomainInfo(c, "wap") | |||
shareUrl := h5Domain + downLoadRoute | |||
//判断生成短链 | |||
shareUrl = CommShareShorUrl(c, shareUrl) | |||
return shareUrl | |||
} | |||
func getStoreUrl(c *gin.Context, storeId, invitedCode string) string { | |||
downLoadRoute := "%s/#/zy-o2o-base/pages/store-page/store-page?id=%s&invited_code=%s" | |||
h5Domain := GetWebSiteDomainInfo(c, "wap") | |||
shareUrl := fmt.Sprintf(downLoadRoute, h5Domain, storeId, invitedCode) | |||
//判断生成短链 | |||
shareUrl = CommShareShorUrl(c, shareUrl) | |||
return shareUrl | |||
} | |||
func CommShareShorUrl(c *gin.Context, shareUrl string) string { | |||
val := SysCfgFind(c, "share_link_type") | |||
if val["share_link_type"] == "1" { //百度短链 | |||
shareUrl, _ = ShortenUrl(shareUrl) | |||
} else if val["share_link_type"] == "2" { //快站短链 | |||
shareUrl = KuaiZhanShortURL(c, shareUrl) | |||
} | |||
return shareUrl | |||
} | |||
func PrinterIndexCheck(c *gin.Context) { | |||
var maps map[string]string | |||
if err := c.ShouldBindJSON(&maps); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
mainOrdId := maps["main_ord_id"] | |||
engine := MasterDb(c) | |||
storeId, ord, goodsInfo, err := CommGetPrinterContent(c, mainOrdId) | |||
if err != nil { | |||
e.OutErr(c, 400, err) | |||
return | |||
} | |||
printerOne, _ := db.GetPrinterIndexByBluetooth(engine, utils.IntToStr(storeId)) | |||
var res = map[string]interface{}{ | |||
"is_has_bluetooth": "0", | |||
"content": "", | |||
} | |||
if printerOne != nil { | |||
res["is_has_bluetooth"] = "1" | |||
} | |||
var args = &md.PrinterRequest{ | |||
StoreId: utils.IntToStr(storeId), | |||
PrinterId: "", | |||
MasterId: c.GetString("mid"), | |||
Ord: ord, | |||
GoodsInfo: goodsInfo, | |||
} | |||
res["content"] = GetReplaceContent(c, args) | |||
e.OutSuc(c, res, nil) | |||
return | |||
} |
@@ -0,0 +1,240 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
// 替换 | |||
func ReplaceOne(c *gin.Context, args *md.PrinterRequest) { | |||
eg := MasterDb(c) | |||
printerOne, _ := db.GetPrinterIndexById(eg, args.PrinterId, args.StoreId) | |||
if printerOne.Type == "bluetooth" { | |||
return | |||
} | |||
module, _ := db.GetAllPrinterModuleListByModuleIdOne(eg, printerOne.ModuleId) | |||
ReplaceStr(c, eg, args, printerOne, module.Content) | |||
} | |||
func GetReplaceContent(c *gin.Context, args *md.PrinterRequest) string { | |||
eg := MasterDb(c) | |||
printerOne, _ := db.GetPrinterIndexByBluetooth(eg, args.StoreId) | |||
if printerOne == nil { | |||
return "" | |||
} | |||
module, _ := db.GetAllPrinterModuleListByModuleIdOne(eg, printerOne.ModuleId) | |||
content := GetCommContent(args, printerOne, module.Content) | |||
return content | |||
} | |||
// 替换 | |||
func ReplaceMore(c *gin.Context, args *md.PrinterRequest) { | |||
eg := MasterDb(c) | |||
fmt.Println(args) | |||
//查出这个店铺下的所有打印机 | |||
list, err := db.GetPrinterIndexAll(eg, args.StoreId) | |||
if err != nil { | |||
logx.Info(err) | |||
return | |||
} | |||
//循环拿出模板id | |||
var moduleIds = make([]int, 0) | |||
for _, v := range list { | |||
if v.IsUse == 0 || v.Type == "bluetooth" || (args.Ord["order_type"] == "face_to_pay" && v.LocationType != "reception") { | |||
continue | |||
} | |||
if v.ModuleId > 0 { | |||
moduleIds = append(moduleIds, v.ModuleId) | |||
} | |||
} | |||
if moduleIds == nil || len(moduleIds) == 0 { | |||
return | |||
} | |||
//查出对应模板数据 | |||
moduleList, err := db.GetAllPrinterModuleListByModuleId(eg, moduleIds) | |||
if err != nil { | |||
logx.Info(err) | |||
return | |||
} | |||
moduleArr := make(map[int]model.CommunityTeamStorePrinterModule, 0) | |||
for _, v := range moduleList { | |||
moduleArr[v.Id] = v | |||
} | |||
//处理数据内容 | |||
for _, v := range list { | |||
if v.IsUse == 0 { | |||
continue | |||
} | |||
moduleId := v.ModuleId | |||
moduleData := moduleArr[moduleId] | |||
if moduleData.Content == "" { | |||
continue | |||
} | |||
content := moduleData.Content | |||
ReplaceStr(c, eg, args, &v, content) | |||
} | |||
} | |||
func GetCommContent(arg *md.PrinterRequest, list *model.CommunityTeamStorePrinter, content string) string { | |||
goodsInfoStr := ReplaceGoodsInfo(arg.GoodsInfo, list.Type, 15, 22, 26, 32) | |||
content = strings.ReplaceAll(content, "{商品信息}", goodsInfoStr) | |||
content = strings.ReplaceAll(content, "{付款金额}", arg.Ord["payment"]) | |||
content = strings.ReplaceAll(content, "{取餐号}", arg.Ord["num"]) | |||
content = strings.ReplaceAll(content, "{桌号}", arg.Ord["table_num"]) | |||
content = strings.ReplaceAll(content, "{订单号}", arg.Ord["main_ord_id"]) | |||
content = strings.ReplaceAll(content, "{姓名}", arg.Ord["name"]) | |||
content = strings.ReplaceAll(content, "{电话}", arg.Ord["phone"]) | |||
content = strings.ReplaceAll(content, "{打印时间}", time.Now().Format("2006-01-02 15:04:05")) | |||
content = strings.ReplaceAll(content, "{收货地址}", arg.Ord["address"]) | |||
content = strings.ReplaceAll(content, "{二维码链接}", arg.Ord["qrcode_url"]) | |||
content = strings.ReplaceAll(content, "{二维码标签左}", "<QR>") | |||
content = strings.ReplaceAll(content, "{二维码标签右}", "</QR>") | |||
content = strings.ReplaceAll(content, "{商家名称}", arg.Ord["store_name"]) | |||
content = strings.ReplaceAll(content, "{商家店铺首页二维码链接}", arg.Ord["store_qrcode_url"]) | |||
if list.Type == "cloud" { | |||
content = strings.ReplaceAll(content, "{居中放大左}", "<FS><center>") | |||
content = strings.ReplaceAll(content, "{居中放大右}", "</center></FS>") | |||
} else { | |||
content = strings.ReplaceAll(content, "{居中放大左}", "<CB>") | |||
content = strings.ReplaceAll(content, "{居中放大右}", "</CB>") | |||
content = strings.ReplaceAll(content, "\n", "<BR>") | |||
content = strings.ReplaceAll(content, "\\n", "<BR>") | |||
} | |||
return content | |||
} | |||
// 字符替换 | |||
func ReplaceStr(c *gin.Context, eg *xorm.Engine, arg *md.PrinterRequest, list *model.CommunityTeamStorePrinter, content string) { | |||
content = GetCommContent(arg, list, content) | |||
fmt.Println(content) | |||
if arg.Ord["order_type"] == "face_to_pay" { | |||
arg.Ord["order_type"] = "3" | |||
} | |||
//加入打印明细 | |||
var detailData = model.CommunityTeamStorePrinterDetail{ | |||
OrdId: arg.Ord["main_ord_id"], | |||
OrdType: utils.StrToInt(arg.Ord["order_type"]), | |||
PrinterId: list.Id, | |||
PrinterModuleId: list.ModuleId, | |||
PrintContent: content, | |||
StoreId: utils.StrToInt(arg.StoreId), | |||
CreateTime: time.Now(), | |||
UpdateTime: time.Now(), | |||
} | |||
has, err := db.DetailInsert(eg, &detailData) | |||
if has == 0 || err != nil { | |||
return | |||
} | |||
fmt.Println(detailData.Id) | |||
//调用打印机打印 | |||
oids := fmt.Sprintf("%s%d%d", detailData.OrdId, detailData.PrinterId, detailData.CreateTime.Unix()) | |||
oid, msg := CommDoing(c, content, list.SnNum, list.Type, oids) | |||
if msg != "" { | |||
return | |||
} | |||
detailData.State = 1 | |||
if msg != "" { | |||
logx.Info(msg) | |||
detailData.State = 2 | |||
detailData.FailMsg = msg | |||
} else { | |||
detailData.PrinterOid = oid | |||
} | |||
detailData.PrintTime = time.Now() | |||
detailData.UpdateTime = time.Now() | |||
_, err = db.DetailUpdate(eg, detailData.Id, &detailData, "printer_oid,print_time,update_time,state,fail_msg") | |||
logx.Info(err) | |||
} | |||
// 处理商品信息 | |||
func ReplaceGoodsInfo(goodsInfo []map[string]string, printerType string, nameLen, priceLen, numLen, pricesLen int) string { | |||
goodsInfoStr := "" | |||
var sub = []int{0, nameLen, priceLen, numLen, pricesLen} | |||
for _, v := range goodsInfo { | |||
name := v["name"] | |||
skuText := v["sku_text"] | |||
price := v["price"] | |||
num := v["num"] | |||
prices := v["prices"] | |||
goodsInfoStr += CheckStr(name, 0, sub) | |||
goodsInfoStr += CheckStr(price, 1, sub) | |||
goodsInfoStr += CheckStr(num, 2, sub) | |||
goodsInfoStr += CheckStr(prices, 3, sub) | |||
if printerType == "cloud" { | |||
goodsInfoStr += "\n" | |||
} else { | |||
goodsInfoStr += "<BR>" | |||
} | |||
if skuText != "" { | |||
goodsInfoStr += CheckStr(skuText, 0, sub) | |||
if printerType == "cloud" { | |||
goodsInfoStr += "\n" | |||
} else { | |||
goodsInfoStr += "<BR>" | |||
} | |||
} | |||
} | |||
return goodsInfoStr | |||
} | |||
func CheckStr(str string, index int, sub []int) string { | |||
kw := "" | |||
lens := len(str) | |||
if lens > 15 && index == 0 { | |||
if lens > 15 && lens <= 32 { | |||
kw += str | |||
for i := 0; i < 32-lens; i++ { | |||
kw += " " | |||
} | |||
kw += "<BR>" | |||
for i := 0; i < 15; i++ { | |||
kw += " " | |||
} | |||
} | |||
if lens > 32 { | |||
if lens > 16*4 { | |||
lens = 16 * 4 | |||
} | |||
kw += str[0:lens] | |||
kw += "<BR>" | |||
str2 := str[lens:] | |||
str2Len := len(str2) | |||
kw += str2 | |||
key := sub[index+1] - str2Len - sub[index] | |||
for i := 0; i < key; i++ { | |||
kw += " " | |||
} | |||
} | |||
} else { | |||
kw += str | |||
key := sub[index+1] - lens - sub[index] | |||
if index == 0 { | |||
key = 20 - lens | |||
if lens < 15 { | |||
key = 19 - lens | |||
} | |||
if lens < 10 { | |||
key = 18 - lens | |||
} | |||
if lens < 7 { | |||
key = 17 - lens | |||
} | |||
fmt.Println(lens) | |||
fmt.Println(key) | |||
} | |||
for i := 0; i < key; i++ { | |||
kw += " " | |||
} | |||
} | |||
return kw | |||
} |
@@ -305,6 +305,7 @@ func BankCard(c *gin.Context) { | |||
list := make([]map[string]string, 0) | |||
data := db.GetCard(MasterDb(c), arg) | |||
if data != nil { | |||
scheme, host := ImageBucket(c) | |||
for _, v := range *data { | |||
tmp := map[string]string{ | |||
"id": utils.IntToStr(v.Id), | |||
@@ -312,6 +313,7 @@ func BankCard(c *gin.Context) { | |||
"first_tip": v.FirstTip, | |||
"second_tip": v.SecondTip, | |||
"time_str": "", | |||
"img": ImageFormatWithBucket(scheme, host, v.Img), | |||
"type": "0", | |||
} | |||
if tmp["time_str"] != "" { | |||
@@ -10,6 +10,7 @@ import ( | |||
"encoding/json" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
@@ -25,6 +26,31 @@ func StoreOrderCate(c *gin.Context) { | |||
e.OutSuc(c, cate, nil) | |||
return | |||
} | |||
func GetDate(c *gin.Context, arg map[string]string) (time.Time, time.Time) { | |||
var stime, etime time.Time | |||
t := time.Now() | |||
if arg["type"] == "day" { | |||
stime = utils.TimeParseStd(arg["date"] + " 00:00:00") | |||
etime = time.Unix(stime.Unix()+86400, 0) | |||
} | |||
if arg["type"] == "month" { | |||
ex := strings.Split(arg["date"], "-") | |||
year := utils.StrToInt(ex[0]) | |||
stime = time.Date(year, time.Month(utils.StrToInt(ex[1])-1), 1, 0, 0, 0, 0, t.Location()) | |||
if utils.StrToInt(ex[1]) == 12 { | |||
year++ | |||
ex[1] = "1" | |||
} | |||
etime = time.Date(year, time.Month(utils.StrToInt(ex[1])), 1, 0, 0, 0, 0, t.Location()) | |||
} | |||
if arg["type"] == "year" { | |||
year := utils.StrToInt(arg["date"]) | |||
stime = time.Date(year, time.Month(0), 1, 0, 0, 0, 0, t.Location()) | |||
etime = time.Date(year+1, time.Month(0), 1, 0, 0, 0, 0, t.Location()) | |||
} | |||
return stime, etime | |||
} | |||
func StoreOrderList(c *gin.Context) { | |||
var arg map[string]string | |||
if err := c.ShouldBindJSON(&arg); err != nil { | |||