Parcourir la source

Merge remote-tracking branch 'origin/master'

master
DengBiao il y a 9 mois
Parent
révision
c81d6c465a
32 fichiers modifiés avec 865 ajouts et 93 suppressions
  1. +13
    -0
      app/admin/hdl/order/hdl_make_record.go
  2. +3
    -10
      app/admin/svc/order/svc_order_list.go
  3. +68
    -0
      app/admin/svc/svc_make_record.go
  4. +21
    -0
      app/db/db_admin.go
  5. +20
    -0
      app/db/db_enterprise.go
  6. +54
    -0
      app/db/db_order_goods_doing.go
  7. +45
    -0
      app/db/db_order_goods_list.go
  8. +36
    -19
      app/db/db_order_list.go
  9. +1
    -1
      app/db/model/order.go
  10. +5
    -5
      app/db/model/order_goods.go
  11. +23
    -0
      app/db/model/order_goods_doing.go
  12. +16
    -0
      app/db/model/order_goods_doing_flow.go
  13. +12
    -0
      app/ipad/hdl/hdl_demo.go
  14. +59
    -0
      app/ipad/hdl/hdl_login.go
  15. +23
    -0
      app/ipad/hdl/hdl_order.go
  16. +70
    -0
      app/ipad/hdl/hdl_order_goods.go
  17. +19
    -0
      app/ipad/hdl/hdl_order_make.go
  18. +10
    -0
      app/ipad/hdl/hdl_responsible.go
  19. +3
    -3
      app/ipad/lib/auth/auth.go
  20. +3
    -3
      app/ipad/lib/auth/base.go
  21. +1
    -1
      app/ipad/md/md_app_redis_key.go
  22. +7
    -15
      app/ipad/md/md_login.go
  23. +7
    -0
      app/ipad/md/md_order.go
  24. +30
    -0
      app/ipad/mw/mw_auth.go
  25. +10
    -20
      app/ipad/svc/svc_auth.go
  26. +2
    -3
      app/ipad/svc/svc_login.go
  27. +46
    -0
      app/ipad/svc/svc_order.go
  28. +7
    -0
      app/ipad/svc/svc_order_goods.go
  29. +206
    -0
      app/ipad/svc/svc_order_make.go
  30. +24
    -0
      app/ipad/svc/svc_responsible.go
  31. +9
    -8
      app/router/admin_router.go
  32. +12
    -5
      app/router/ipad_router.go

+ 13
- 0
app/admin/hdl/order/hdl_make_record.go Voir le fichier

@@ -0,0 +1,13 @@
package order

import (
"applet/app/admin/svc"
"github.com/gin-gonic/gin"
)

func MarkRecord(c *gin.Context) {
svc.MarkRecord(c)
}
func MarkRecordFlow(c *gin.Context) {
svc.MarkRecordFlow(c)
}

+ 3
- 10
app/admin/svc/order/svc_order_list.go Voir le fichier

@@ -23,19 +23,12 @@ func OrderList(c *gin.Context) {
list, total := db.GetOrderList(eg, args)
data := make([]map[string]string, 0)
if list != nil {
stateArr := []string{"待制作", "制作中", "烘焙中", "分拣中", "已完成", "已取消"}
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
enterpriseIds := make([]int, 0)
for _, v := range *list {
enterpriseIds = append(enterpriseIds, v.EnterpriseId)
}
enterpriseMap := make(map[int]model.Enterprise)
if len(enterpriseIds) > 0 {
enterpriseData := make([]model.Enterprise, 0)
eg.In("id", enterpriseIds).Find(&enterpriseData)
for _, v := range enterpriseData {
enterpriseMap[v.Id] = v
}
}
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)
for _, v := range *list {
v1 := JudgePackageOrdOrdState(&v)
isCanCancel := "1"
@@ -264,7 +257,7 @@ func OrderDetail(c *gin.Context) {
if skuStr != "" {
skuStr += ";"
}
skuStr += v1.Name + ":" + v1.Value
skuStr += v1.Value
}
tmp["sku_str"] = skuStr



+ 68
- 0
app/admin/svc/svc_make_record.go Voir le fichier

@@ -0,0 +1,68 @@
package svc

import (
"applet/app/db"
"applet/app/e"
"applet/app/utils"
"github.com/gin-gonic/gin"
)

func MarkRecord(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
eg := db.Db
list, total := db.GetOrderGoodsDoingList(eg, args)
data := make([]map[string]string, 0)
if list != nil {
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
enterpriseIds := make([]int, 0)
adminIds := make([]int, 0)
for _, v := range *list {
enterpriseIds = append(enterpriseIds, v.EnterpriseId)
adminIds = append(adminIds, v.AdminId)
}
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)
adminMap := db.GetAdminMore(eg, adminIds)

for _, v := range *list {
enterpriseName := ""
adminName := ""
_, ok := enterpriseMap[v.EnterpriseId]
if ok {
enterpriseName = enterpriseMap[v.EnterpriseId].Name
}
_, ok1 := adminMap[v.AdminId]
if ok1 {
adminName = adminMap[v.AdminId].Memo
}
var tmp = map[string]string{
"oid": utils.Int64ToStr(v.Oid),
"id": utils.IntToStr(v.Id),
"state_str": stateArr[v.State],
"state": utils.IntToStr(v.State),
"time": v.Time.Format("2006-01-02 15:04:05"),
"enterprise_name": enterpriseName,
"sku_str": v.Sku,
"goods_title": v.GoodsTitle,
"memo": v.Memo,
"admin_name": adminName,
"num": utils.IntToStr(v.Num),
"success_num": utils.IntToStr(v.SuccessNum),
}
data = append(data, tmp)
}
}

res := map[string]interface{}{
"total": total,
"list": data,
}
e.OutSuc(c, res, nil)
return
}
func MarkRecordFlow(c *gin.Context) {

}

+ 21
- 0
app/db/db_admin.go Voir le fichier

@@ -120,3 +120,24 @@ func (adminDb *AdminDb) AdminInsert(m *model.Admin) (int64, error) {
}
return insertAffected, nil
}

func GetAllAdmin(eg *xorm.Engine) *[]model.Admin {
var data []model.Admin
err := eg.Where("is_super_administrator=?", 0).Find(&data)
if err != nil {
return nil
}
return &data
}
func GetAdminMore(eg *xorm.Engine, ids []int) map[int]model.Admin {

data := make(map[int]model.Admin)
if len(ids) > 0 {
list := make([]model.Admin, 0)
eg.In("id", ids).Find(&list)
for _, v := range list {
data[v.AdmId] = v
}
}
return data
}

+ 20
- 0
app/db/db_enterprise.go Voir le fichier

@@ -76,3 +76,23 @@ func (enterpriseDb *EnterpriseDb) EnterpriseUpdate(m *model.Enterprise, columns
}
return affected, nil
}
func GetEnterpriseMore(eg *xorm.Engine, enterpriseIds []int) map[int]model.Enterprise {

enterpriseMap := make(map[int]model.Enterprise)
if len(enterpriseIds) > 0 {
enterpriseData := make([]model.Enterprise, 0)
eg.In("id", enterpriseIds).Find(&enterpriseData)
for _, v := range enterpriseData {
enterpriseMap[v.Id] = v
}
}
return enterpriseMap
}
func GetEnterpriseList(eg *xorm.Engine) *[]model.Enterprise {
var data []model.Enterprise
err := eg.Where("1=1").Find(&data)
if err != nil {
return nil
}
return &data
}

+ 54
- 0
app/db/db_order_goods_doing.go Voir le fichier

@@ -0,0 +1,54 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"xorm.io/xorm"
)

func GetOrderGoodsByRecordId(eg *xorm.Engine, id string) *model.OrderGoodsDoing {
var order model.OrderGoodsDoing
get, err := eg.Where("record_id=?", id).Get(&order)
if get == false || err != nil {
return nil
}
return &order
}
func GetOrderGoodsDoingList(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsDoing, int64) {
var order []model.OrderGoodsDoing
sess := eg.Where("1=1")
if param["admin_name"] != "" {
var data []model.Admin
eg.Where("memo like ?", "%"+param["admin_name"]+"%")
ids := []int{-1}
for _, v := range data {
ids = append(ids, v.AdmId)
}
sess.In("admin_id", ids)
}
if param["oid"] != "" {
sess.And("oid like ?", "%"+param["oid"]+"%")
}
if param["state"] != "" {
sess.And("state =?", param["state"])
}
if param["enterprise_id"] != "" {
sess.And("enterprise_id =?", param["enterprise_id"])
}
if param["goods_title"] != "" {
sess.And("goods_title like ?", "%"+param["goods_title"]+"%")
}
if param["start_time"] != "" {
sess.And("time>=?", param["start_time"])
}
if param["end_time"] != "" {
sess.And("time<=?", param["end_time"])
}
size := utils.StrToInt(param["limit"])
start := (utils.StrToInt(param["page"]) - 1) * size
count, err := sess.Limit(size, start).OrderBy("time desc,id desc").FindAndCount(&order)
if err != nil {
return nil, count
}
return &order, count
}

+ 45
- 0
app/db/db_order_goods_list.go Voir le fichier

@@ -0,0 +1,45 @@
package db

import (
"applet/app/db/model"
"applet/app/utils"
"xorm.io/xorm"
)

func GetOrderGoodsListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoods, int64) {
var order []model.OrderGoods
sess := eg.Where("state!=5")

if param["oid"] != "" {
sess.And("oid = ?", param["oid"])
}
if param["state"] != "" {
sess.And("state =?", param["state"])
}
if param["keyword"] != "" {
sess.And("goods_title like ?", "%"+param["keyword"]+"%")
}
size := utils.StrToInt(param["limit"])
start := (utils.StrToInt(param["page"]) - 1) * size
count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
if err != nil {
return nil, count
}
return &order, count
}
func GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods {
var order model.OrderGoods
get, err := eg.Where("id=?", id).Get(&order)
if get == false || err != nil {
return nil
}
return &order
}
func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods {
var order model.OrderGoods
get, err := sess.Where("id=?", id).Get(&order)
if get == false || err != nil {
return nil
}
return &order
}

+ 36
- 19
app/db/db_order_list.go Voir le fichier

@@ -3,6 +3,7 @@ package db
import (
"applet/app/db/model"
"applet/app/utils"
"github.com/syyongx/php2go"
"xorm.io/xorm"
)

@@ -14,9 +15,9 @@ func GetOrderById(eg *xorm.Engine, id string) *model.Order {
}
return &order
}
func GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods {
var order model.OrderGoods
get, err := eg.Where("id=?", id).Get(&order)
func GetOrderByIdSess(sess *xorm.Session, id string) *model.Order {
var order model.Order
get, err := sess.Where("oid=?", id).Get(&order)
if get == false || err != nil {
return nil
}
@@ -31,14 +32,6 @@ func GetOrderGoodsBySkuId(eg *xorm.Engine, oid, skuId string) *model.OrderGoods
return &order
}

func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods {
var order model.OrderGoods
get, err := sess.Where("id=?", id).Get(&order)
if get == false || err != nil {
return nil
}
return &order
}
func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.OrderGoods {
var order model.OrderGoods
get, err := sess.Where("oid=? and sku_id=?", oid, skuId).Get(&order)
@@ -57,16 +50,16 @@ func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int
sess.And("oid like ?", "%"+param["oid"]+"%")
}
if param["state"] != "" {
sess.And("state =", param["state"])
sess.And("state =?", param["state"])
}
if param["goods_title"] != "" {
var orderGoods []model.OrderGoods
eg.Where("goods_title like ?", "%"+param["goods_title"]+"%").Find(&orderGoods)
oids := []int64{-1}
for _, v := range orderGoods {
oids = append(oids, v.Oid)
if param["enterprise_name"] != "" {
var enterprise []model.Enterprise
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
oids := []int{-1}
for _, v := range enterprise {
oids = append(oids, v.Id)
}
sess.In("oid", oids)
sess.In("enterprise_id", oids)
}
size := utils.StrToInt(param["limit"])
start := (utils.StrToInt(param["page"]) - 1) * size
@@ -76,3 +69,27 @@ func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int
}
return &order, count
}
func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) {
var order []model.Order
sess := eg.Where("state!=5")

if param["keyword"] != "" {
var data []model.Enterprise
eg.Where("name like ?", "%"+param["keyword"]+"%").Find(&data)
ids := []string{"-1"}
for _, v := range data {
ids = append(ids, utils.IntToStr(v.Id))
}
sess.And("enterprise_id in (?) or oid like ?", php2go.Implode(",", ids), "%"+param["keyword"]+"%")
}
if param["state"] != "" {
sess.And("state =?", param["state"])
}
size := utils.StrToInt(param["limit"])
start := (utils.StrToInt(param["page"]) - 1) * size
count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order)
if err != nil {
return nil, count
}
return &order, count
}

+ 1
- 1
app/db/model/order.go Voir le fichier

@@ -13,5 +13,5 @@ type Order struct {
EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企id') INT(11)"`
BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"`
Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"`
BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机 ') VARCHAR(20)"`
BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"`
}

+ 5
- 5
app/db/model/order_goods.go Voir le fichier

@@ -3,12 +3,12 @@ package model
type OrderGoods struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Oid int64 `json:"oid" xorm:"default 0 comment('订单号') BIGINT(20)"`
GoodsId int64 `json:"goods_id" xorm:"default 0 comment('商品id') INT(11)"`
SkuId int64 `json:"sku_id" xorm:"default 0 comment('sku') INT(255)"`
GoodsId int64 `json:"goods_id" xorm:"default 0 comment('商品id') BIGINT(20)"`
SkuId int64 `json:"sku_id" xorm:"default 0 comment('sku') BIGINT(20)"`
Num int `json:"num" xorm:"default 0 comment('购买数量') INT(11)"`
Price string `json:"price" xorm:"default 0.00 comment('单价') DECIMAL(20,2)"`
SkuCode string `json:"sku_code" xorm:"default 0.00 comment('') VARCHAR(255)"`
Sku string `json:"sku_code" xorm:"default 0.00 comment('') VARCHAR(255)"`
GoodsTitle string `json:"goods_title" xorm:"default 0.00 comment('') VARCHAR(255)"`
State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 ') INT(11)"`
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"`
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"`
Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"`
}

+ 23
- 0
app/db/model/order_goods_doing.go Voir le fichier

@@ -0,0 +1,23 @@
package model

import (
"time"
)

type OrderGoodsDoing struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Oid int64 `json:"oid" xorm:"default 0 comment('订单号') BIGINT(20)"`
GoodsId int64 `json:"goods_id" xorm:"default 0 comment('商品id') BIGINT(20)"`
SkuId int64 `json:"sku_id" xorm:"default 0 comment('sku') BIGINT(20)"`
Num int `json:"num" xorm:"default 0 comment('购买数量') INT(11)"`
State int `json:"state" xorm:"default 0 comment('状态 1开始制作 2制作完成烘焙开始 3烘焙完成分拣开始 4已完成 ') INT(11)"`
SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"`
GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"`
Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"`
SuccessNum int `json:"success_num" xorm:"comment('完成数量') INT(11)"`
Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"`
Time time.Time `json:"time" xorm:"DATETIME"`
RecordId int `json:"record_id" xorm:"default 0 comment('order_goods 的id') INT(11)"`
AdminId int `json:"admin_id" xorm:"default 0 comment('admin 的id') INT(11)"`
EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企 的id') INT(11)"`
}

+ 16
- 0
app/db/model/order_goods_doing_flow.go Voir le fichier

@@ -0,0 +1,16 @@
package model

import (
"time"
)

type OrderGoodsDoingFlow struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Num int `json:"num" xorm:"default 0 comment('购买数量') INT(11)"`
State int `json:"state" xorm:"default 0 comment('状态 1开始制作 2制作完成烘焙开始 3烘焙完成分拣开始 4已完成 ') INT(11)"`
SuccessNum int `json:"success_num" xorm:"comment('完成数量') INT(11)"`
Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"`
Time time.Time `json:"time" xorm:"DATETIME"`
RecordId int `json:"record_id" xorm:"default 0 comment('order_goods_doing 的id') INT(11)"`
AdminId int `json:"admin_id" xorm:"default 0 comment('admin 的id') INT(11)"`
}

+ 12
- 0
app/ipad/hdl/hdl_demo.go Voir le fichier

@@ -0,0 +1,12 @@
package hdl

import (
"applet/app/e"
"github.com/gin-gonic/gin"
)

// Demo 测试
func Demo(c *gin.Context) {
e.OutSuc(c, "success", nil)
return
}

+ 59
- 0
app/ipad/hdl/hdl_login.go Voir le fichier

@@ -0,0 +1,59 @@
package hdl

import (
"applet/app/e"
"applet/app/enum"
"applet/app/ipad/lib/validate"
"applet/app/ipad/md"
"applet/app/ipad/svc"
svc2 "applet/app/svc"
"applet/app/utils"
"fmt"
"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
var req md.LoginReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
sysCfg := svc2.SysCfgFind(enum.ProductionWorkshopAccount, enum.ProductionWorkshopPassword)
if sysCfg[enum.ProductionWorkshopAccount] == "" || sysCfg[enum.ProductionWorkshopPassword] == "" {
e.OutErr(c, e.ERR_NO_DATA, "用户信息不存在")
return
}

if sysCfg[enum.ProductionWorkshopAccount] != req.Account || sysCfg[enum.ProductionWorkshopPassword] != req.Password {
e.OutErr(c, e.ERR_NO_DATA, "账号或密码错误")
return
}

ip := utils.GetIP(c.Request)
key := fmt.Sprintf(md.UserJwtTokenKey, ip)
token, err := svc.HandleLoginToken(key, &md.User{
Account: req.Account,
Password: req.Password,
})
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, md.LoginResponse{
Token: token,
}, nil)
return
}

func UserInfo(c *gin.Context) {
//1、获取用户信息
userInfo := svc.GetUser(c)

e.OutSuc(c, map[string]interface{}{
"user_info": userInfo,
}, nil)
return
}

+ 23
- 0
app/ipad/hdl/hdl_order.go Voir le fichier

@@ -0,0 +1,23 @@
package hdl

import (
"applet/app/e"
"applet/app/ipad/svc"
"github.com/gin-gonic/gin"
)

func OrderCate(c *gin.Context) {
var res = []map[string]string{
{"name": "全部", "id": ""},
{"name": "待制作", "id": "0"},
{"name": "制作中", "id": "1"},
{"name": "待烘焙", "id": "2"},
{"name": "待分拣", "id": "3"},
{"name": "已完成", "id": "4"},
}
e.OutSuc(c, res, nil)
return
}
func Order(c *gin.Context) {
svc.Order(c)
}

+ 70
- 0
app/ipad/hdl/hdl_order_goods.go Voir le fichier

@@ -0,0 +1,70 @@
package hdl

import (
"applet/app/admin/md"
"applet/app/db"
"applet/app/e"
"applet/app/svc"
"applet/app/utils"
"encoding/json"
"github.com/gin-gonic/gin"
)

func OrderGoods(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
eg := db.Db
data, _ := db.GetOrderGoodsListByIpad(eg, args)
list := make([]map[string]string, 0)
if data != nil {
gids := make([]int64, 0)
for _, v := range *data {
gids = append(gids, v.GoodsId)
}
goodsMap := db.GetGoodsMore(eg, gids)
scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c)
var tmpMap interface{}
stateArr := []string{"待制作", "制作中", "烘焙中", "分拣中", "已完成", "已取消"}
btnArr := []string{"开始制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
for _, v := range *data {
var tmp = map[string]string{
"oid": utils.Int64ToStr(v.Oid),
"id": utils.IntToStr(v.Id),
"num": utils.IntToStr(v.Num),
"state_str": stateArr[v.State],
"btn_str": btnArr[v.State],
"goods_title": v.GoodsTitle,
"goods_img": "",
"state": utils.IntToStr(v.State),
}
// 商品主图
if goodsMap[v.GoodsId].ImageList != "" {
utils.Unserialize([]byte(goodsMap[v.GoodsId].ImageList), &tmpMap)
var imageListUrlTmp []string
for _, v := range tmpMap.([]interface{}) {
imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
}
if imageListUrlTmp != nil {
tmp["goods_img"] = imageListUrlTmp[0]
}
}
skuData := make([]md.Sku, 0)
json.Unmarshal([]byte(v.Sku), &skuData)
skuStr := ""
for _, v1 := range skuData {
if skuStr != "" {
skuStr += ";"
}
skuStr += v1.Value
}
tmp["sku_str"] = skuStr
list = append(list, tmp)
}
}

e.OutSuc(c, list, nil)
return
}

+ 19
- 0
app/ipad/hdl/hdl_order_make.go Voir le fichier

@@ -0,0 +1,19 @@
package hdl

import (
"applet/app/ipad/svc"
"github.com/gin-gonic/gin"
)

func OrderMakeBegin(c *gin.Context) {
svc.OrderMakeBegin(c)
}
func OrderMakeEnd(c *gin.Context) {
svc.OrderMakeEnd(c)
}
func OrderBakingEnd(c *gin.Context) {
svc.OrderBakingEnd(c)
}
func OrderSortingEnd(c *gin.Context) {
svc.OrderSortingEnd(c)
}

+ 10
- 0
app/ipad/hdl/hdl_responsible.go Voir le fichier

@@ -0,0 +1,10 @@
package hdl

import (
"applet/app/ipad/svc"
"github.com/gin-gonic/gin"
)

func Responsible(c *gin.Context) {
svc.Responsible(c)
}

+ 3
- 3
app/ipad/lib/auth/auth.go Voir le fichier

@@ -7,11 +7,11 @@ import (
)

// GenToken 生成JWT
func GenToken(userId int, username string) (string, error) {
func GenToken(account, password string) (string, error) {
// 创建一个我们自己的声明
c := JWTUser{
UserId: userId,
Username: username,
Account: account,
Password: password,
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(TokenExpireDuration).Unix(), // 过期时间
Issuer: "bakery", // 签发人


+ 3
- 3
app/ipad/lib/auth/base.go Voir le fichier

@@ -9,11 +9,11 @@ import (
// TokenExpireDuration is jwt 过期时间
const TokenExpireDuration = time.Hour * 4380

var Secret = []byte("bakery_customer")
var Secret = []byte("bakery_big_data")

// JWTUser 如果想要保存更多信息,都可以添加到这个结构体中
type JWTUser struct {
UserId int `json:"user_id"`
Username string `json:"username"`
Account string `json:"account"`
Password string `json:"password"`
jwt.StandardClaims
}

+ 1
- 1
app/ipad/md/md_app_redis_key.go Voir le fichier

@@ -2,6 +2,6 @@ package md

// 缓存key统一管理
const (
UserJwtTokenKey = "%s:bakery_user_jwt_token:%s" // jwt, 占位符:ip, user:id
UserJwtTokenKey = "%s:bakery_production_workshop_user_jwt_token" // jwt, 占位符:ip, user:id
JwtTokenCacheTime = 3600 * 24 * 1
)

+ 7
- 15
app/ipad/md/md_login.go Voir le fichier

@@ -1,23 +1,15 @@
package md

type LoginReq struct {
Phone string `json:"phone" binding:"required" label:"登录手机号"`
Account string `json:"account" binding:"required" label:"账号"`
Password string `json:"password" binding:"required" label:"密码"`
}

type LoginResponse struct {
Token string `json:"token"`
}

type WxAppletLoginResponse struct {
OpenId string `json:"open_id"`
UnionId string `json:"union_id"`
type User struct {
Account string `json:"account" label:"账号"`
Password string `json:"password" label:"密码"`
}

type RegisterReq struct {
UserId string `json:"user_id" label:"支付宝用户的唯一userId"`
OpenId string `json:"open_id" label:"微信小程序openid"`
UnionId string `json:"union_id" label:"微信unionId"`
Nickname string `json:"nickname" label:"支付宝昵称"`
Avatar string `json:"avatar" label:"支付宝头像"`
Phone string `json:"phone" binding:"required" label:"手机号"`
type LoginResponse struct {
Token string `json:"token"`
}

+ 7
- 0
app/ipad/md/md_order.go Voir le fichier

@@ -0,0 +1,7 @@
package md

type OrderSorting struct {
Oid string `json:"oid"`
AdminId string `json:"admin_id"`
GoodsInfo []map[string]string `json:"goods_info"`
}

+ 30
- 0
app/ipad/mw/mw_auth.go Voir le fichier

@@ -0,0 +1,30 @@
package mw

import (
"applet/app/bigData/svc"
"applet/app/e"
"github.com/gin-gonic/gin"
)

// 检查权限, 签名等等
func ProductionWorkshopAuth(c *gin.Context) {
user, err := svc.CheckUser(c)
if err != nil {
switch err.(type) {
case e.E:
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
default:
e.OutErr(c, e.ERR_UNAUTHORIZED, err.Error())
return
}
}
if user == nil {
e.OutErr(c, e.ERR_NOT_AUTH, "当前用户信息失效")
return
}
// 将当前请求的username信息保存到请求的上下文c上
c.Set("user", user)
c.Next()
}

+ 10
- 20
app/ipad/svc/svc_auth.go Voir le fichier

@@ -1,33 +1,25 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/bigData/md"
"applet/app/ipad/lib/auth"
"errors"
"github.com/gin-gonic/gin"
"strings"
"time"
)

func GetUser(c *gin.Context) *model.User {
func GetUser(c *gin.Context) *md.User {
user, _ := c.Get("user")
if user == nil {
return &model.User{
Id: 0,
UserId: "",
Nickname: "",
Avatar: "",
Phone: "",
Memo: "",
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
return &md.User{
Account: "",
Password: "",
}
}
return user.(*model.User)
return user.(*md.User)
}

func CheckUser(c *gin.Context) (*model.User, error) {
func CheckUser(c *gin.Context) (*md.User, error) {
token := c.GetHeader("Authorization")
if token == "" {
return nil, errors.New("token not exist")
@@ -44,11 +36,9 @@ func CheckUser(c *gin.Context) (*model.User, error) {
}

// 获取user
userDb := db.UserDb{}
userDb.Set()
user, err := userDb.GetUser(mc.UserId)
if err != nil {
return nil, err
user := &md.User{
Account: mc.Account,
Password: mc.Password,
}
return user, nil
}

+ 2
- 3
app/ipad/svc/svc_login.go Voir le fichier

@@ -1,14 +1,13 @@
package svc

import (
"applet/app/db/model"
"applet/app/ipad/lib/auth"
"applet/app/ipad/md"
"applet/app/utils/cache"
"applet/app/utils/logx"
)

func HandleLoginToken(cacheKey string, user *model.User) (string, error) {
func HandleLoginToken(cacheKey string, user *md.User) (string, error) {
// 获取之前生成的token
token, err := cache.GetString(cacheKey)
if err != nil {
@@ -17,7 +16,7 @@ func HandleLoginToken(cacheKey string, user *model.User) (string, error) {
// 没有获取到
if err != nil || token == "" {
// 生成token
token, err = auth.GenToken(user.Id, user.Phone)
token, err = auth.GenToken(user.Account, user.Password)
if err != nil {
return "", err
}


+ 46
- 0
app/ipad/svc/svc_order.go Voir le fichier

@@ -0,0 +1,46 @@
package svc

import (
"applet/app/db"
"applet/app/e"
"applet/app/utils"
"github.com/gin-gonic/gin"
)

func Order(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
eg := db.Db
data, _ := db.GetOrderListByIpad(eg, args)
list := make([]map[string]string, 0)
if data != nil {
enterpriseIds := make([]int, 0)
for _, v := range *data {
enterpriseIds = append(enterpriseIds, v.EnterpriseId)
}
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)
stateArr := []string{"待制作", "制作中", "烘焙中", "分拣中", "已完成", "已取消"}
btnArr := []string{"进入制作", "进入制作", "进入制作", "开始分拣", "分拣完成", "已取消"}
for _, v := range *data {
enterpriseName := ""
_, ok := enterpriseMap[v.EnterpriseId]
if ok {
enterpriseName = enterpriseMap[v.EnterpriseId].Name
}
var tmp = map[string]string{
"oid": utils.Int64ToStr(v.Oid),
"id": utils.IntToStr(v.Id),
"state_str": stateArr[v.State],
"btn_str": btnArr[v.State],
"state": utils.IntToStr(v.State),
"enterprise_name": enterpriseName,
}
list = append(list, tmp)
}
}
e.OutSuc(c, list, nil)
return
}

+ 7
- 0
app/ipad/svc/svc_order_goods.go Voir le fichier

@@ -0,0 +1,7 @@
package svc

import "github.com/gin-gonic/gin"

func OrderGoods(c *gin.Context) {

}

+ 206
- 0
app/ipad/svc/svc_order_make.go Voir le fichier

@@ -0,0 +1,206 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/e"
"applet/app/ipad/md"
"applet/app/utils"
"github.com/gin-gonic/gin"
"time"
)

func OrderMakeBegin(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
args["state"] = "1"
args["str"] = "制作"
commMake(c, args)
}
func OrderMakeEnd(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
args["state"] = "2"
args["str"] = "烘焙"
commMake(c, args)
}

func OrderBakingEnd(c *gin.Context) {
var args map[string]string
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
args["state"] = "3"
args["str"] = "烘焙"
commMake(c, args)
}
func OrderSortingEnd(c *gin.Context) {
var args md.OrderSorting
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
eg := db.Db
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
order := db.GetOrderGoodsByIdSess(sess, args.Oid)
if order == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
return
}
if order.State == 4 {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单已分拣完成"))
return
}
//修改制作记录
for _, v := range args.GoodsInfo {
record := db.GetOrderGoodsByRecordId(eg, v["id"])
record.SuccessNum = utils.StrToInt(v["num"])
record.State = 4
record.AdminId = utils.StrToInt(args.AdminId)
record.Time = time.Now()
_, err := sess.Where("id=?", record.Id).Cols("success_num,state,time").Update(record)
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
//写入流程记录
var recordFlow = &model.OrderGoodsDoingFlow{
Num: record.Num,
State: 4,
Memo: "",
SuccessNum: utils.StrToInt(v["num"]),
Time: time.Now(),
RecordId: record.RecordId,
AdminId: utils.StrToInt(args.AdminId),
}
one, err := sess.InsertOne(recordFlow)
if one == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "开始制作失败,请重试"))
return
}
}
//判断大订单 要不要改状态
count, _ := sess.Where("oid=?", order.Oid).Count(&model.OrderGoods{})
countEnd, _ := sess.Where("oid=? and state=?", order.Oid, 4).Count(&model.OrderGoods{})
if countEnd == count {
_, err := sess.Where("oid=?", order.Oid).Cols("state").Update(&model.Order{State: 4})
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}

func commMake(c *gin.Context, args map[string]string) {
eg := db.Db
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
state := utils.StrToInt(args["state"])

orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"])
if orderGoods == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
return
}
order := db.GetOrderByIdSess(sess, utils.Int64ToStr(orderGoods.Oid))
if order == nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
return
}
record := db.GetOrderGoodsByRecordId(eg, args["id"])
if orderGoods.State >= state {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "该商品已在"+args["str"]+"中"))
return
}
if record == nil {
record = &model.OrderGoodsDoing{
Oid: orderGoods.Oid,
GoodsId: orderGoods.GoodsId,
SkuId: orderGoods.SkuId,
Num: orderGoods.Num,
State: state,
SkuCode: orderGoods.SkuCode,
GoodsTitle: orderGoods.GoodsTitle,
Sku: orderGoods.Sku,
Time: time.Now(),
RecordId: orderGoods.Id,
EnterpriseId: order.EnterpriseId,
AdminId: utils.StrToInt(args["admin_id"]),
}
one, err := sess.InsertOne(record)
if one == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
}
record.SuccessNum = utils.StrToInt(args["num"])
record.Memo = args["memo"]
record.State = state
record.AdminId = utils.StrToInt(args["admin_id"])
record.Time = time.Now()
_, err := sess.Where("id=?", record.Id).Cols("success_num,memo,state,time").Update(record)
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
//写入流程记录
var recordFlow = &model.OrderGoodsDoingFlow{
Num: orderGoods.Num,
State: state,
Memo: args["memo"],
SuccessNum: utils.StrToInt(args["num"]),
Time: time.Now(),
RecordId: record.RecordId,
AdminId: utils.StrToInt(args["admin_id"]),
}
one, err := sess.InsertOne(recordFlow)
if one == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "开始制作失败,请重试"))
return
}
orderGoods.State = state
update, err := sess.Where("id=?", orderGoods.Id).Cols("state").Update(&orderGoods)
if update == 0 || err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
//判断大订单 要不要改状态
count, _ := sess.Where("oid=?", orderGoods.Oid).Count(&model.OrderGoods{})
countEnd, _ := sess.Where("oid=? and state=?", orderGoods.Oid, state).Count(&model.OrderGoods{})
if countEnd == count {
_, err = sess.Where("oid=?", orderGoods.Oid).Cols("state").Update(&model.Order{State: state})
if err != nil {
sess.Rollback()
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
return
}
}
sess.Commit()
e.OutSuc(c, "success", nil)
return
}

+ 24
- 0
app/ipad/svc/svc_responsible.go Voir le fichier

@@ -0,0 +1,24 @@
package svc

import (
"applet/app/db"
"applet/app/e"
"applet/app/utils"
"github.com/gin-gonic/gin"
)

func Responsible(c *gin.Context) {
list := make([]map[string]string, 0)
admin := db.GetAllAdmin(db.Db)
if admin != nil {
for _, v := range *admin {
var tmp = map[string]string{
"id": utils.IntToStr(v.AdmId),
"name": v.Memo,
}
list = append(list, tmp)
}
}
e.OutSuc(c, list, nil)
return
}

+ 9
- 8
app/router/admin_router.go Voir le fichier

@@ -130,14 +130,15 @@ func rGoodsPay(r *gin.RouterGroup) {
r.POST("/create", orderHdl.GoodsPayCreate) //商品下单
}
func rOrder(r *gin.RouterGroup) {
r.POST("/list", orderHdl.OrderList) //用户订单
r.POST("/total", orderHdl.OrderTotal) //用户订单统计
r.POST("/cancel", orderHdl.OrderCancel) //用户订单取消
r.POST("/detail", orderHdl.OrderDetail) //用户订单详情
r.POST("/output", orderHdl.OrderOutput) //用户订单导出
r.POST("/del", orderHdl.OrderDel) //用户订单商品删除
r.POST("/edit", orderHdl.OrderEdit) //用户订单修改购买人信息
r.POST("/editNum", orderHdl.OrderEditNum) //用户订单修改订单数
r.POST("/list", orderHdl.OrderList) //用户订单
r.POST("/total", orderHdl.OrderTotal) //用户订单统计
r.POST("/cancel", orderHdl.OrderCancel) //用户订单取消
r.POST("/detail", orderHdl.OrderDetail) //用户订单详情
r.POST("/output", orderHdl.OrderOutput) //用户订单导出
r.POST("/del", orderHdl.OrderDel) //用户订单商品删除
r.POST("/edit", orderHdl.OrderEdit) //用户订单修改购买人信息
r.POST("/editNum", orderHdl.OrderEditNum) //用户订单修改订单数
r.POST("/makeRecord", orderHdl.MarkRecord) //制作记录
}

func rFinanceManage(r *gin.RouterGroup) {


+ 12
- 5
app/router/ipad_router.go Voir le fichier

@@ -1,15 +1,22 @@
package router

import (
"applet/app/ipad/hdl"
"applet/app/ipad/mw"
"github.com/gin-gonic/gin"
)

func IpadInit(r *gin.RouterGroup) {
rTest(r.Group("/test"))
r.Use(mw.Auth) //检测登录状态
r.POST("/login", hdl.Login)
r.Use(mw.Auth) //检测登录状态
r.GET("order/cate", hdl.OrderCate) //订单类目
r.POST("order/list", hdl.Order) //订单
r.GET("order/goods/cate", hdl.OrderCate) //订单商品类目
r.POST("order/goods/list", hdl.OrderGoods) //订单商品
r.GET("responsible", hdl.Responsible) //负责人
r.POST("order/make/begin", hdl.OrderMakeBegin) //订单开始制作
r.POST("order/make/end", hdl.OrderMakeEnd) //订单制作完成
r.POST("order/baking/end", hdl.OrderBakingEnd) //订单烘焙完成
r.POST("order/sorting/end", hdl.OrderSortingEnd) //订单分拣完成

}

func rTest(r *gin.RouterGroup) {
}

Chargement…
Annuler
Enregistrer