Pārlūkot izejas kodu

ADD:钢瓶调拨

zoie 11 mēneši atpakaļ
vecāks
revīzija
00d0edc328

+ 1 - 0
.gitignore

@@ -41,4 +41,5 @@ setting.yml
 /app/jobs
 /docs
 uploads
+.DS_Store
 

+ 299 - 0
app/admin/controller/gas_cylinder_allot.go

@@ -0,0 +1,299 @@
+package controller
+
+import (
+	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/app/admin/service"
+	"gas-cylinder-api/app/admin/service/dto"
+	"gas-cylinder-api/common/actions"
+	"github.com/gin-gonic/gin"
+	"github.com/gin-gonic/gin/binding"
+	"gogs.baozhida.cn/zoie/OAuth-core/api"
+	"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
+	_ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
+)
+
+type GasCylinderAllotController struct {
+	api.Api
+}
+
+// GetPage 获取调拨信息列表
+// @Summary 获取调拨信息列表
+// @Description 获取调拨信息列表
+// @Tags 调拨信息
+// @Param name query string false "调拨信息名称"
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderAllot}} "{"code": 200, "data": [...]}"
+// @Router /api/dispatch-cost [get]
+// @Security Bearer
+func (e GasCylinderAllotController) GetPage(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotGetPageReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, binding.Query).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	//数据权限检查
+	p := actions.GetPermissionFromContext(c)
+
+	list := make([]model.GasCylinderAllot, 0)
+	var count int64
+
+	err = s.GetPage(&req, &list, &count, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// Get 通过id获取调拨信息
+// @Summary 通过id获取调拨信息
+// @Description 通过id获取调拨信息
+// @Tags 调拨信息
+// @Param id path string true "调拨信息id"
+// @Success 200 {object} response.Response{data=model.GasCylinderAllot} "{"code": 200, "data": [...]}"
+// @Router /api/dispatch-cost/{id} [get]
+// @Security Bearer
+func (e GasCylinderAllotController) Get(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotGetReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, nil).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	var object model.GasCylinderAllot
+	p := actions.GetPermissionFromContext(c)
+
+	//数据权限检查
+	err = s.Get(&req, &object, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	e.OK(object, "查询成功")
+}
+
+// GetByOptType 通过id获取调拨信息
+// @Summary 通过id获取调拨信息
+// @Description 通过id获取调拨信息
+// @Tags 调拨信息
+// @Param optType path string true "操作流程id"
+// @Success 200 {object} response.Response{data=model.GasCylinderAllot} "{"code": 200, "data": [...]}"
+// @Router /api/dispatch-cost/{id} [get]
+// @Security Bearer
+func (e GasCylinderAllotController) GetByOptType(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotGetByOptTypeReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, nil).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	var object model.GasCylinderAllot
+	p := actions.GetPermissionFromContext(c)
+
+	//数据权限检查
+	err = s.GetByOptType(&req, &object, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	e.OK(object, "查询成功")
+}
+
+// Insert 添加调拨信息
+// @Summary 添加调拨信息
+// @Description 添加调拨信息
+// @Tags 调拨信息
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderAllotInsertReq true "data"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/dispatch-cost [post]
+// @Security Bearer
+func (e GasCylinderAllotController) Insert(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotInsertReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, binding.JSON).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	p := actions.GetPermissionFromContext(c)
+	// 设置创建人
+	req.SetCreateBy(user.GetUserId(c))
+	req.SetDeptId(p.DeptId)
+	err = s.Insert(&req)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "调拨成功")
+}
+
+// Update 修改调拨信息
+// @Summary 修改调拨信息
+// @Description 修改调拨信息
+// @Tags 调拨信息
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderAllotUpdateReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/dispatch-cost [put]
+// @Security Bearer
+func (e GasCylinderAllotController) Update(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotUpdateReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	p := actions.GetPermissionFromContext(c)
+
+	req.SetUpdateBy(user.GetUserId(c))
+	err = s.Update(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "更新成功")
+}
+
+// Delete 删除调拨信息
+// @Summary 删除调拨信息
+// @Description 删除调拨信息
+// @Tags 调拨信息
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderAllotDeleteReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "删除成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "删除失败"}"
+// @Router /api/dispatch-cost [delete]
+// @Security Bearer
+func (e GasCylinderAllotController) Delete(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotDeleteReq{}
+	userSvc := service.SysUser{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, binding.JSON, nil).
+		MakeService(&s.Service).
+		MakeService(&userSvc.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	//数据权限检查
+	p := actions.GetPermissionFromContext(c)
+	err = s.Remove(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "删除成功")
+}
+
+// Cancel 取消调拨
+// @Summary 取消调拨
+// @Description 取消调拨
+// @Tags 调拨信息
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderAllotUpdateReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/dispatch-cost [put]
+// @Security Bearer
+func (e GasCylinderAllotController) Cancel(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotCancelReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	p := actions.GetPermissionFromContext(c)
+
+	req.SetUpdateBy(user.GetUserId(c))
+	err = s.Cancel(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "取消成功")
+}
+
+// Submit 提交调拨信息
+// @Summary 提交调拨信息
+// @Description 提交调拨信息
+// @Tags 调拨信息
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderAllotUpdateReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/dispatch-cost [put]
+// @Security Bearer
+func (e GasCylinderAllotController) Submit(c *gin.Context) {
+	s := service.GasCylinderAllot{}
+	req := dto.GasCylinderAllotSubmitReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	p := actions.GetPermissionFromContext(c)
+
+	req.SetUpdateBy(user.GetUserId(c))
+	err = s.Submit(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "提交成功")
+}

+ 191 - 0
app/admin/controller/gas_cylinder_status.go

@@ -0,0 +1,191 @@
+package controller
+
+import (
+	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/app/admin/service"
+	"gas-cylinder-api/app/admin/service/dto"
+	"gas-cylinder-api/common/actions"
+	"github.com/gin-gonic/gin"
+	"github.com/gin-gonic/gin/binding"
+	"gogs.baozhida.cn/zoie/OAuth-core/api"
+	"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
+	_ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
+)
+
+type GasCylinderStatusController struct {
+	api.Api
+}
+
+// GetPage 获取钢瓶状态列表
+// @Summary 获取钢瓶状态列表
+// @Description 获取钢瓶状态列表
+// @Tags 钢瓶状态
+// @Param name query string false "钢瓶状态名称"
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderStatus}} "{"code": 200, "data": [...]}"
+// @Router /api/dispatch-cost [get]
+// @Security Bearer
+func (e GasCylinderStatusController) GetPage(c *gin.Context) {
+	s := service.GasCylinderStatus{}
+	userSvc := service.SysUser{}
+	req := dto.GasCylinderStatusGetPageReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, binding.Query).
+		MakeService(&s.Service).
+		MakeService(&userSvc.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	//数据权限检查
+	p := actions.GetPermissionFromContext(c)
+	var userObj model.SysUser
+	err = userSvc.Get(&dto.SysUserGetReq{Id: user.GetUserId(c)}, nil, &userObj)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	list := make([]model.GasCylinderStatus, 0)
+	var count int64
+	if (userObj.ProvUser.UserType == 3 && userObj.ProvUser.Isorders == 0) || userObj.ProvUser.UserType == 4 {
+		// 送气员 货车司机
+		err = s.GetUserPage(&req, &list, &count, p)
+	} else {
+		err = s.GetPage(&req, &list, &count, p)
+	}
+
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// Get 通过id获取钢瓶状态
+// @Summary 通过id获取钢瓶状态
+// @Description 通过id获取钢瓶状态
+// @Tags 钢瓶状态
+// @Param id path string true "钢瓶状态id"
+// @Success 200 {object} response.Response{data=model.GasCylinderStatus} "{"code": 200, "data": [...]}"
+// @Router /api/dispatch-cost/{id} [get]
+// @Security Bearer
+func (e GasCylinderStatusController) Get(c *gin.Context) {
+	s := service.GasCylinderStatus{}
+	req := dto.GasCylinderStatusGetReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, nil).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	var object model.GasCylinderStatus
+	p := actions.GetPermissionFromContext(c)
+
+	//数据权限检查
+	err = s.Get(&req, &object, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	e.OK(object, "查询成功")
+}
+
+// Update 修改钢瓶状态
+// @Summary 修改钢瓶状态
+// @Description 修改钢瓶状态
+// @Tags 钢瓶状态
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderStatusInsertReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/dispatch-cost [put]
+// @Security Bearer
+func (e GasCylinderStatusController) Insert(c *gin.Context) {
+	s := service.GasCylinderStatus{}
+	userSvc := service.SysUser{}
+	req := dto.GasCylinderStatusInsertReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req).
+		MakeService(&s.Service).
+		MakeService(&userSvc.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	p := actions.GetPermissionFromContext(c)
+
+	// 设置创建人
+	req.SetCreateBy(user.GetUserId(c))
+	req.SetDeptId(p.DeptId)
+	var userObj model.SysUser
+	err = userSvc.Get(&dto.SysUserGetReq{Id: user.GetUserId(c)}, nil, &userObj)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	if userObj.ProvUser.UserType == 3 && userObj.ProvUser.Isorders == 0 {
+		// 送气员
+		err = s.UserInsert(&req, p, true)
+	} else if userObj.ProvUser.UserType == 4 {
+		// 货车司机
+		err = s.UserInsert(&req, p, false)
+	} else {
+		err = s.Insert(&req, p)
+	}
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "添加成功")
+}
+
+// Delete 删除钢瓶状态
+// @Summary 删除钢瓶状态
+// @Description 删除钢瓶状态
+// @Tags 钢瓶状态
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.GasCylinderStatusDeleteReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "删除成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "删除失败"}"
+// @Router /api/dispatch-cost [delete]
+// @Security Bearer
+func (e GasCylinderStatusController) Delete(c *gin.Context) {
+	s := service.GasCylinderStatus{}
+	req := dto.GasCylinderStatusDeleteReq{}
+	userSvc := service.SysUser{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, binding.JSON, nil).
+		MakeService(&s.Service).
+		MakeService(&userSvc.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	//数据权限检查
+	p := actions.GetPermissionFromContext(c)
+	err = s.Remove(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "删除成功")
+}

+ 50 - 0
app/admin/controller/store.go

@@ -112,6 +112,56 @@ func (e StoreController) GetAllPage(c *gin.Context) {
 		return
 	}
 
+	//var dept model.SysDept
+	//数据权限检查
+	//err = s.Get(&dto.StoreGetReq{
+	//	Id: user.GetDeptId(c),
+	//}, &dept)
+	//if err != nil {
+	//	e.Error(500, err, err.Error())
+	//	return
+	//}
+	//deptId := user.GetDeptId(c)
+	//deptIdList := strings.Split(strings.Trim(dept.Path, "/"), "/")
+	//if len(deptIdList) > 1 {
+	//	deptId, _ = strconv.Atoi(deptIdList[1])
+	//}
+	//数据权限检查
+	p := actions.GetPermissionFromContext(c)
+	//req.DeptId = deptId
+	req.Type = model.TypeStore
+	list := make([]model.SysDept, 0)
+	//p.DeptId = deptId
+	list, err = s.SetStorePage(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(list, "查询成功")
+}
+
+// GetAllPage2 获取配送门店列表(根公司下所有公司)
+// @Summary 获取配送门店列表
+// @Description 获取配送门店列表(进入公司后的公司列表)
+// @Tags 销售门店
+// @Param name query string false "销售门店名称"
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.SysDept}} "{"code": 200, "data": [...]}"
+// @Router /api/store/all2 [get]
+// @Security Bearer
+func (e StoreController) GetAllPageByUser(c *gin.Context) {
+	s := service.Store{}
+	req := dto.StoreGetPageReq{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req, binding.Query).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+
 	var dept model.SysDept
 	//数据权限检查
 	err = s.Get(&dto.StoreGetReq{

+ 1 - 1
app/admin/model/customer.go

@@ -26,7 +26,7 @@ type Customer struct {
 	IsSyncProv bool   `json:"isSyncProv"`                     // 是否同步到省平台
 	Openid     string `json:"openid"`                         // 微信id
 	State      int    `json:"state" gorm:"size:6;default:-1"` // 0-待整改 1-整改中 2-已整改 合格
-	Name       string `json:"principalName" gorm:"size:128;"`
+	Name       string `json:"name" gorm:"size:128;"`
 	Password   string `json:"-" gorm:"size:128;comment:密码"`
 	model2.ControlBy
 	model2.ModelTime

+ 41 - 0
app/admin/model/gas_cylinder_allot.go

@@ -0,0 +1,41 @@
+package model
+
+import model2 "gas-cylinder-api/common/model"
+
+var (
+	GasCylinderAllotStateAllot         = 1 // 调拨中
+	GasCylinderAllotStateFinish        = 2 // 已完成
+	GasCylinderAllotStateCancel        = 3 // 已取消
+	GasCylinderAllotStateTimeoutCancel = 4 // 超时取消
+
+	GasCylinderAllotStateMap = map[int]string{
+		GasCylinderAllotStateAllot:         "已下单",
+		GasCylinderAllotStateFinish:        "已完成",
+		GasCylinderAllotStateCancel:        "已取消",
+		GasCylinderAllotStateTimeoutCancel: "已超时取消",
+	}
+)
+
+// 气瓶调拨
+type GasCylinderAllot struct {
+	model2.Model
+	OptType         string            `json:"optType" gorm:"size:48"`          // 气瓶流转步骤
+	AllotUserId     int               `json:"allotUserId" gorm:"size:48;"`     // 调拨者用户id
+	AcceptUserId    int               `json:"acceptUserId" gorm:"size:48;"`    // 接收者用户id
+	AllotCompanyId  int               `json:"allotCompanyId" gorm:"size:48;"`  // 调拨者所属公司id
+	AcceptCompanyId int               `json:"acceptCompanyId" gorm:"size:48;"` // 接收者所属公司id
+	InnerCodeList   model2.StringList `json:"innerCodeList" gorm:"type:json"`  // 单位内编码列表
+	Status          int               `json:"status" gorm:"size:4"`            // 1-调拨中 2-调拨完成 3-取消调拨
+	AllotUser       SysUserOmit       `json:"allotUser"  gorm:"foreignkey:AllotUserId;references:Id"`
+	AcceptUser      SysUserOmit       `json:"acceptUser"  gorm:"foreignkey:AcceptUserId;references:Id"`
+	AllotCompany    SysDeptOmit       `json:"allotCompany"  gorm:"foreignkey:AllotCompanyId;references:Id"`
+	AcceptCompany   SysDeptOmit       `json:"acceptCompany" gorm:"->;foreignkey:AcceptCompanyId;references:Id"`
+
+	model2.ControlBy
+	model2.ModelTime
+	model2.DeptBy
+}
+
+func (GasCylinderAllot) TableName() string {
+	return "gas_cylinder_allot"
+}

+ 33 - 0
app/admin/model/gas_cylinder_status.go

@@ -0,0 +1,33 @@
+package model
+
+import model2 "gas-cylinder-api/common/model"
+
+var (
+	GasCylinderStatusWeighty     = 1 // 重瓶区
+	GasCylinderStatusEmpty       = 2 // 空瓶区
+	GasCylinderStatusUnqualified = 3 // 不合格瓶区
+
+	GasCylinderStatusStateMap = map[int]string{
+		GasCylinderStatusWeighty:     "重瓶区",
+		GasCylinderStatusEmpty:       "空瓶区",
+		GasCylinderStatusUnqualified: "不合格瓶区",
+	}
+)
+
+// 气瓶状态
+type GasCylinderStatus struct {
+	model2.Model
+	InnerCode string      `json:"inner_code"`                // 1单位内编号
+	Status    int         `json:"status" gorm:"size:1;"`     // 1-重瓶区 2-空瓶区 3-不合格瓶区
+	UserId    int         `json:"userId" gorm:"size:48;"`    // 省平台用户id 司机 送气员
+	CompanyId int         `json:"companyId" gorm:"size:48;"` // 所属公司id
+	User      SysUserOmit `json:"user"  gorm:"foreignkey:UserId;references:Id"`
+	Company   SysDeptOmit `json:"company" gorm:"->;foreignkey:CompanyId;references:Id"`
+	model2.ControlBy
+	model2.ModelTime
+	model2.DeptBy
+}
+
+func (GasCylinderStatus) TableName() string {
+	return "gas_cylinder_status"
+}

+ 1 - 0
app/admin/model/order.go

@@ -37,6 +37,7 @@ type Order struct {
 	DeliveryTime model2.Time     `json:"deliveryTime" gorm:"size:128"` // 配送时间
 	ArriveTime   model2.Time     `json:"arriveTime" gorm:"size:128"`   // 送达时间
 	CancelTime   model2.Time     `json:"cancelTime" gorm:"size:128"`   // 取消时间
+
 	Customer     Customer        `json:"customer" gorm:"->"`
 	Store        SysDeptOmit     `json:"store" gorm:"->"`
 	User         SysUserOmit     `json:"user" gorm:"->"`

+ 30 - 0
app/admin/model/sys_dept.go

@@ -9,6 +9,7 @@ import (
 	"github.com/gin-gonic/gin"
 	log "gogs.baozhida.cn/zoie/OAuth-core/logger"
 	"gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
+	"strconv"
 	"strings"
 
 	"gogs.baozhida.cn/zoie/OAuth-core/sdk"
@@ -190,3 +191,32 @@ func GetDeptByCmpCode(CmpCode string) (SysDept, error) {
 
 	return deptModel, nil
 }
+
+func GetParentIds(id int) (arr []int, err error) {
+	var deptModel SysDept
+	//准备db
+	db := sdk.Runtime.GetDbByKey(config.ApplicationConfig.Host)
+	if db == nil {
+		err = errors.New("db not exist")
+		log.Errorf("host[%s]'s %s", err.Error())
+		return arr, err
+	}
+	err = db.First(&deptModel, id).Error
+	if err != nil {
+		log.Errorf("db error: %s", err)
+		err = errors.New("获取企业信息失败")
+		return arr, err
+	}
+
+	//  将字符串分割为整数
+	for _, s := range deptModel.Path {
+		if s != '/' && s != '0' {
+			num, err := strconv.Atoi(string(s))
+			if err != nil {
+				continue
+			}
+			arr = append(arr, num)
+		}
+	}
+	return arr, nil
+}

+ 2 - 2
app/admin/model/sys_user.go

@@ -160,7 +160,7 @@ func GetUserCode(id int) (SysUser, error) {
 		log.Errorf("host[%s]'s %s", err.Error())
 		return userModel, err
 	}
-	err = db.First(&userModel, id).Error
+	err = db.Preload("Dept").First(&userModel, id).Error
 	if err != nil {
 		log.Errorf("db error: %s", err)
 		err = errors.New("获取用户信息失败")
@@ -174,7 +174,7 @@ type SysUserOmit struct {
 	Id         int    `json:"id,omitempty"`         // 主键编码
 	NickName   string `json:"nickName,omitempty"`   // 昵称
 	ProvUserId string `json:"provUserId,omitempty"` // 省平台用户id
-	Phone      string `json:"phone"`                // 手机号
+	Phone      string `json:"phone,omitempty"`      // 手机号
 
 }
 

+ 29 - 0
app/admin/router/gas_cylinder_allot.go

@@ -0,0 +1,29 @@
+package router
+
+import (
+	"gas-cylinder-api/app/admin/controller"
+	"gas-cylinder-api/common/actions"
+	"github.com/gin-gonic/gin"
+	jwt "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth"
+)
+
+func init() {
+	routerCheckRole = append(routerCheckRole, registerGasCylinderAllotRouter)
+}
+
+// 派费管理
+// 需认证的路由代码
+func registerGasCylinderAllotRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
+	cont := controller.GasCylinderAllotController{}
+	r := v1.Group("/gas-cylinder-allot").Use(authMiddleware.MiddlewareFunc()).Use(actions.PermissionAction())
+	{
+		r.GET("", cont.GetPage)
+		r.GET("/:id", cont.Get)
+		r.GET("/opt-type/:optType", cont.GetByOptType)
+		r.POST("", cont.Insert)
+		r.POST("/cancel", cont.Cancel)
+		r.POST("/submit", cont.Submit)
+		r.PUT("", cont.Update)
+		r.DELETE("", cont.Delete)
+	}
+}

+ 25 - 0
app/admin/router/gas_cylinder_status.go

@@ -0,0 +1,25 @@
+package router
+
+import (
+	"gas-cylinder-api/app/admin/controller"
+	"gas-cylinder-api/common/actions"
+	"github.com/gin-gonic/gin"
+	jwt "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth"
+)
+
+func init() {
+	routerCheckRole = append(routerCheckRole, registerGasCylinderStatusRouter)
+}
+
+// 派费管理
+// 需认证的路由代码
+func registerGasCylinderStatusRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
+	cont := controller.GasCylinderStatusController{}
+	r := v1.Group("/gas-cylinder-status").Use(authMiddleware.MiddlewareFunc()).Use(actions.PermissionAction())
+	{
+		r.GET("", cont.GetPage)
+		r.GET("/:id", cont.Get)
+		r.POST("", cont.Insert)
+		r.DELETE("", cont.Delete)
+	}
+}

+ 1 - 0
app/admin/router/sys_dept.go

@@ -41,6 +41,7 @@ func registerStoreRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewa
 		r.DELETE("", cont.Delete)
 		r.POST("/enter", cont.Enter)
 		r.GET("/all", cont.GetAllPage)
+		r.GET("/all2", cont.GetAllPageByUser)
 	}
 
 }

+ 2 - 2
app/admin/service/customer.go

@@ -26,7 +26,7 @@ func (e *Customer) GetPage(c *dto.CustomerGetPageReq, list *[]model.Customer, co
 		Scopes(
 			cDto.MakeCondition(c.GetNeedSearch()),
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
-			actions.Permission(data.TableName(), p),
+			InDeptIdScopes(p.DeptId),
 		).
 		Find(list).Limit(-1).Offset(-1).
 		Count(count).Error
@@ -214,7 +214,7 @@ func (e *Customer) Update(c *dto.CustomerUpdateReq, p *actions.DataPermission) e
 
 	var CustomerModel = model.Customer{}
 	// 查询客户是否存在
-	err = tx.Scopes(actions.Permission(CustomerModel.TableName(), p)).
+	err = tx.Scopes(InDeptIdScopes(p.DeptId)).
 		Where("id = ?", c.GetId()).
 		First(&CustomerModel).Error
 	if err != nil {

+ 129 - 0
app/admin/service/dto/gas_cylinder_allot.go

@@ -0,0 +1,129 @@
+package dto
+
+import (
+	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/common/dto"
+	common "gas-cylinder-api/common/model"
+)
+
+type GasCylinderAllotGetPageReq struct {
+	dto.Pagination `search:"-"`
+	StoreId        int    `form:"storeId" search:"type:exact;column:dept_id;table:gas_cylinder_allot" vd:"$>0;msg:'门店id不能为空'"`
+	ProvUserId     string `form:"provUserId" search:"type:exact;column:prov_user_id;table:gas_cylinder_allot"` // 钢瓶规格名称
+	GasCylinderAllotOrder
+}
+type GasCylinderAllotOrder struct {
+	CreatedAtOrder string `search:"type:order;column:created_at;table:gas_cylinder_allot" form:"createdAtOrder" default:"desc"`
+}
+
+func (m *GasCylinderAllotGetPageReq) GetNeedSearch() interface{} {
+	return *m
+}
+
+type GasCylinderAllotInsertReq struct {
+	Id               int               `json:"id" comment:"编码" swaggerignore:"true"`        // 编码
+	OptType          string            `json:"optType" vd:"len($)>0;msg:'气瓶流转步骤不能为空'"`      // 气瓶流转步骤
+	AllotUserId      int               `json:"allotUserId" swaggerignore:"true"`            // 调拨者用户id
+	AcceptUserId     int               `json:"acceptUserId" vd:"$>0;msg:'接收者用户id不能为空'"`     // 接收者用户id
+	AllotCompanyId   int               `json:"allotCompanyId" swaggerignore:"true"`         // 调拨者所属公司id
+	AcceptCompanyId  int               `json:"acceptCompanyId" vd:"$>0;msg:'接收者公司id不能为空'"`  // 接收者所属公司id
+	InnerCodeList    common.StringList `json:"innerCodeList" vd:"len($)>0;msg:'单位内编码不能为空'"` // 单位内编码列表
+	Status           int               `json:"status" swaggerignore:"true"`                 // 单位内编码列表
+	common.ControlBy `swaggerignore:"true"`
+	common.DeptBy    `swaggerignore:"true"`
+}
+
+func (s *GasCylinderAllotInsertReq) Generate(m *model.GasCylinderAllot) {
+	if s.Id != 0 {
+		m.Id = s.Id
+	}
+	m.OptType = s.OptType
+	m.AllotUserId = s.CreateBy
+	m.AcceptUserId = s.AcceptUserId
+	m.AllotCompanyId = s.DeptId
+	m.AcceptCompanyId = s.AcceptCompanyId
+	m.InnerCodeList = s.InnerCodeList
+	m.Status = model.GasCylinderAllotStateAllot
+	if s.ControlBy.UpdateBy != 0 {
+		m.UpdateBy = s.UpdateBy
+	}
+	if s.ControlBy.CreateBy != 0 {
+		m.CreateBy = s.CreateBy
+	}
+	if s.DeptBy.DeptId != 0 {
+		m.DeptId = s.DeptId
+	}
+}
+func (s *GasCylinderAllotInsertReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderAllotUpdateReq struct {
+	Id               int    `json:"id" comment:"编码"`                     // 编码
+	Status           string `json:"status" vd:"len($)>0;msg:'钢瓶位置不能为空'"` // 钢瓶规格名称
+	Remark           string `json:"remark"`                              // 备注
+	common.ControlBy `swaggerignore:"true"`
+}
+
+func (s *GasCylinderAllotUpdateReq) Generate(model *model.GasCylinderAllot) {
+	if s.Id != 0 {
+		model.Id = s.Id
+	}
+	//model.Status = s.Status
+	if s.ControlBy.UpdateBy != 0 {
+		model.UpdateBy = s.UpdateBy
+	}
+	if s.ControlBy.CreateBy != 0 {
+		model.CreateBy = s.CreateBy
+	}
+}
+
+func (s *GasCylinderAllotUpdateReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderAllotGetReq struct {
+	Id int `uri:"id" vd:"$>0;msg:'id不能为空'"`
+}
+
+func (s *GasCylinderAllotGetReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderAllotGetByOptTypeReq struct {
+	OptType string `uri:"optType" vd:"len($)>0;msg:'气瓶流转步骤不能为空'"` // 气瓶流转步骤
+}
+
+type GasCylinderAllotDeleteReq struct {
+	Id               int `json:"id" vd:"$>0;msg:'id不能为空'"`
+	common.ControlBy `swaggerignore:"true"`
+}
+
+func (s *GasCylinderAllotDeleteReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderAllotCancelReq struct {
+	Id               int `json:"id" comment:"编码"` // 编码
+	common.ControlBy `swaggerignore:"true"`
+}
+
+func (s *GasCylinderAllotCancelReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderAllotSubmitReq struct {
+	Id               int      `json:"id" comment:"编码"`                             // 编码
+	OptType          string   `json:"optType" vd:"len($)>0;msg:'气瓶流转步骤不能为空'"`      // 气瓶流转步骤
+	AllotUserId      int      `json:"allotUserId" swaggerignore:"true"`            // 调拨者用户id
+	AcceptUserId     int      `json:"acceptUserId" vd:"$>0;msg:'接收者用户id不能为空'"`     // 接收者用户id
+	AllotCompanyId   int      `json:"allotCompanyId" swaggerignore:"true"`         // 调拨者所属公司id
+	AcceptCompanyId  int      `json:"acceptCompanyId" vd:"$>0;msg:'接收者公司id不能为空'"`  // 接收者所属公司id
+	InnerCodeList    []string `json:"innerCodeList" vd:"len($)>0;msg:'单位内编码不能为空'"` // 单位内编码列表
+	common.ControlBy `swaggerignore:"true"`
+	common.DeptBy    `swaggerignore:"true"`
+}
+
+func (s *GasCylinderAllotSubmitReq) GetId() interface{} {
+	return s.Id
+}

+ 71 - 0
app/admin/service/dto/gas_cylinder_status.go

@@ -0,0 +1,71 @@
+package dto
+
+import (
+	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/common/dto"
+	common "gas-cylinder-api/common/model"
+)
+
+type GasCylinderStatusGetPageReq struct {
+	dto.Pagination `search:"-"`
+	UserId         int    `form:"userId" search:"-"`
+	CompanyId      string `form:"companyId" search:"-"`
+	InnerCode      string `form:"inner_code" search:"type:contains;column:inner_code;table:gas_cylinder_status"` // 1单位内编号
+	Status         int    `form:"status" search:"type:exact;column:status;table:gas_cylinder_status"`            // 1-重瓶区 2-空瓶区 3-不合格瓶区
+	GasCylinderStatusOrder
+}
+type GasCylinderStatusOrder struct {
+	CreatedAtOrder string `search:"type:order;column:created_at;table:gas_cylinder_status" form:"createdAtOrder" default:"desc"`
+}
+
+func (m *GasCylinderStatusGetPageReq) GetNeedSearch() interface{} {
+	return *m
+}
+
+type GasCylinderStatusInsertReq struct {
+	Id               int      `json:"id" comment:"编码"` // 编码
+	InnerCodeList    []string `json:"innerCodeList" vd:"len($)>0;msg:'单位内编码不能为空'"`
+	Status           int      `json:"status" vd:"$>0;msg:'钢瓶状态不能为空'"` // 钢瓶状态
+	Remark           string   `json:"remark"`                         // 备注
+	common.ControlBy `swaggerignore:"true"`
+	common.DeptBy    `swaggerignore:"true"`
+}
+
+func (s *GasCylinderStatusInsertReq) Generate(innerCode string, model *model.GasCylinderStatus) {
+	if s.Id != 0 {
+		model.Id = s.Id
+	}
+	model.InnerCode = innerCode
+	model.Status = s.Status
+	model.CompanyId = s.DeptId
+	if s.ControlBy.UpdateBy != 0 {
+		model.UpdateBy = s.UpdateBy
+	}
+	if s.ControlBy.CreateBy != 0 {
+		model.CreateBy = s.CreateBy
+	}
+	if s.DeptBy.DeptId != 0 {
+		model.DeptId = s.DeptId
+	}
+}
+
+func (s *GasCylinderStatusInsertReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderStatusGetReq struct {
+	Id int `uri:"id" vd:"$>0;msg:'id不能为空'"`
+}
+
+func (s *GasCylinderStatusGetReq) GetId() interface{} {
+	return s.Id
+}
+
+type GasCylinderStatusDeleteReq struct {
+	Id               int `json:"id" vd:"$>0;msg:'id不能为空'"`
+	common.ControlBy `swaggerignore:"true"`
+}
+
+func (s *GasCylinderStatusDeleteReq) GetId() interface{} {
+	return s.Id
+}

+ 2 - 1
app/admin/service/dto/operation_log.go

@@ -23,7 +23,8 @@ type OperationLogInsertReq struct {
 	ChipUidList       []string `json:"chipUidList"`                          // 高频编码列表
 	OptType           string   `json:"optType"`                              // 气瓶流转步骤
 	CurrentEnterprise string   `json:"currentEnterprise"`                    // 当前企业ID OptType=25 OptType=27 时必填
-
+	UserId            int      `json:"userId"`                               // 调拨用户ID
+	Type              int      `json:"type"`                                 // 录入类型 1-扫码 2 调拨
 }
 
 func (s *OperationLogInsertReq) GetId() interface{} {

+ 5 - 3
app/admin/service/dto/order.go

@@ -60,6 +60,7 @@ type OrderAppletInsertReq struct {
 	Id               int         `json:"id" comment:"编码" swaggerignore:"true"` // 编码
 	CustomerId       string      `json:"customerId"`                           // 顾客id
 	Address          string      `json:"address"`                              // 顾客地址
+	Name             string      `json:"name"`                                 // 顾客名称
 	Lng              float64     `json:"lng"`                                  // 经度
 	Lat              float64     `json:"lat"`                                  // 纬度
 	City             string      `json:"city"`                                 // 所在地市
@@ -154,6 +155,7 @@ type OrderUpdateReq struct {
 type OrderAppletUpdateReq struct {
 	Id               int     `json:"id" comment:"编码" swaggerignore:"true"` // 编码
 	Address          string  `json:"address"`                              // 顾客地址
+	Name             string  `json:"name"`                                 // 顾客名称
 	Lng              float64 `json:"lng"`                                  // 经度
 	Lat              float64 `json:"lat"`                                  // 纬度
 	City             string  `json:"city"`                                 // 所在地市
@@ -265,9 +267,9 @@ func (s *OrderDeliveryReq) GetId() interface{} {
 }
 
 type OrderUpdateStateReq struct {
-	Id               int    `json:"id"`
-	State            int    `json:"state"`
-	ChipUid          string `json:"chipUid"` // 高频id
+	Id               int      `json:"id"`
+	State            int      `json:"state"`
+	ChipUid          []string `json:"chipUid"` // 高频id
 	common.ControlBy `swaggerignore:"true"`
 }
 

+ 1169 - 0
app/admin/service/gas_cylinder_allot.go

@@ -0,0 +1,1169 @@
+package service
+
+import (
+	"errors"
+	"fmt"
+	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/app/admin/service/dto"
+	"gas-cylinder-api/common/actions"
+	cDto "gas-cylinder-api/common/dto"
+	"gas-cylinder-api/common/global"
+	cModel "gas-cylinder-api/common/model"
+	"gogs.baozhida.cn/zoie/OAuth-core/service"
+	"gorm.io/gorm"
+	"gorm.io/gorm/utils"
+	"time"
+)
+
+type GasCylinderAllot struct {
+	service.Service
+}
+
+// GetPage 获取GasCylinderAllot列表
+func (e *GasCylinderAllot) GetPage(c *dto.GasCylinderAllotGetPageReq, list *[]model.GasCylinderAllot, count *int64, p *actions.DataPermission) error {
+	var err error
+	var data model.GasCylinderAllot
+
+	err = e.Orm.Model(&data).
+		Scopes(
+			cDto.MakeCondition(c.GetNeedSearch()),
+			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
+			actions.Permission(data.TableName(), p),
+		).
+		Find(list).Limit(-1).Offset(-1).
+		Count(count).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.GetFailedErr
+	}
+	return nil
+}
+
+// Get 获取GasCylinderAllot对象
+func (e *GasCylinderAllot) Get(d *dto.GasCylinderAllotGetReq, gasCylinderAllotModel *model.GasCylinderAllot, p *actions.DataPermission) error {
+	err := e.Orm.
+		Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		Preload("AllotUser").
+		Preload("AcceptUser").
+		Preload("AllotCompany").
+		Preload("AcceptCompany").
+		First(gasCylinderAllotModel, d.GetId()).Error
+
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.GetNotFoundOrNoPermissionErr
+		}
+		return global.GetFailedErr
+	}
+
+	return nil
+}
+
+// ByOptType 获取GasCylinderAllot对象
+func (e *GasCylinderAllot) GetByOptType(d *dto.GasCylinderAllotGetByOptTypeReq, gasCylinderAllotModel *model.GasCylinderAllot, p *actions.DataPermission) error {
+	err := e.Orm.
+		Where("opt_type = ? and accept_user_id = ? and status = ?", d.OptType, p.UserId, model.GasCylinderAllotStateAllot).
+		Preload("AllotUser").
+		Preload("AllotCompany").
+		First(gasCylinderAllotModel).Error
+
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.GetNotFoundOrNoPermissionErr
+		}
+		return global.GetFailedErr
+	}
+
+	return nil
+}
+
+// Insert 创建GasCylinderAllot对象
+func (e *GasCylinderAllot) Insert(c *dto.GasCylinderAllotInsertReq) error {
+	var err error
+	var data model.GasCylinderAllot
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	err = e.Orm.
+		Where("opt_type = ? and accept_user_id = ? and status = ?", c.OptType, c.AcceptUserId, model.GasCylinderAllotStateAllot).
+		First(&data).Error
+
+	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+		e.Log.Errorf("db error: %s", err)
+		return global.GetFailedErr
+	}
+	if data.Id > 0 {
+		err = errors.New("调拨中,请勿重复提交!")
+		return err
+	}
+
+	// 添加调拨信息
+	c.Generate(&data)
+	err = tx.Create(&data).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.CreateFailedErr
+	}
+	c.Id = data.Id
+	return nil
+
+}
+
+// Update 修改GasCylinderAllot对象
+func (e *GasCylinderAllot) Update(c *dto.GasCylinderAllotUpdateReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	var gasCylinderAllotModel = model.GasCylinderAllot{}
+	// 查询调拨信息是否存在
+	err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		First(&gasCylinderAllotModel, c.GetId()).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.UpdateNotFoundOrNoPermissionErr
+		}
+		return global.UpdateFailedErr
+	}
+
+	c.Generate(&gasCylinderAllotModel)
+	err = tx.Save(&gasCylinderAllotModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.UpdateFailedErr
+	}
+
+	c.Id = gasCylinderAllotModel.Id
+
+	return nil
+}
+
+// Remove 删除GasCylinderAllot
+func (e *GasCylinderAllot) Remove(c *dto.GasCylinderAllotDeleteReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	var gasCylinderAllotModel model.GasCylinderAllot
+
+	// 查询调拨信息是否存在
+	err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		First(&gasCylinderAllotModel, c.GetId()).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.DeleteNotFoundOrNoPermissionErr
+		}
+		return global.DeleteFailedErr
+	}
+
+	if gasCylinderAllotModel.Status != model.GasCylinderAllotStateFinish {
+		err = errors.New(fmt.Sprintf("状态为%s,无法删除", model.GasCylinderAllotStateMap[gasCylinderAllotModel.Status]))
+		return err
+	}
+
+	db := tx.Delete(&gasCylinderAllotModel)
+
+	if err = db.Error; err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.DeleteFailedErr
+	}
+	if db.RowsAffected == 0 {
+		return global.DeleteNotFoundOrNoPermissionErr
+	}
+
+	return nil
+}
+
+// Cancel 取消GasCylinderAllot
+func (e *GasCylinderAllot) Cancel(c *dto.GasCylinderAllotCancelReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	var gasCylinderAllotModel = model.GasCylinderAllot{}
+	// 查询调拨信息是否存在
+	err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		First(&gasCylinderAllotModel, c.GetId()).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.UpdateNotFoundOrNoPermissionErr
+		}
+		return global.UpdateFailedErr
+	}
+	if gasCylinderAllotModel.Status != model.GasCylinderAllotStateAllot {
+		err = errors.New(fmt.Sprintf("状态为%s,无法取消", model.GasCylinderAllotStateMap[gasCylinderAllotModel.Status]))
+		return err
+	}
+
+	gasCylinderAllotModel.Status = model.GasCylinderAllotStateCancel
+	err = tx.Save(&gasCylinderAllotModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.UpdateFailedErr
+	}
+
+	c.Id = gasCylinderAllotModel.Id
+
+	return nil
+}
+
+// Submit 提交GasCylinderAllot
+func (e *GasCylinderAllot) Submit(c *dto.GasCylinderAllotSubmitReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	// 调拨状态更新为 已完成
+	// 调拨者气瓶状态更新
+	// 接收更新气瓶状态 上报气瓶流转信息
+	// 油站更新气瓶状态 上报气瓶流转信息
+
+	var gasCylinderAllotModel = model.GasCylinderAllot{}
+	// 查询调拨信息是否存在
+	err = e.Orm.First(&gasCylinderAllotModel, c.GetId()).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.UpdateNotFoundOrNoPermissionErr
+		}
+		return global.UpdateFailedErr
+	}
+	if gasCylinderAllotModel.Status != model.GasCylinderAllotStateAllot {
+		err = errors.New(fmt.Sprintf("状态为%s,无法提交", model.GasCylinderAllotStateMap[gasCylinderAllotModel.Status]))
+		return err
+	}
+
+	gasCylinderAllotModel.Status = model.GasCylinderAllotStateFinish
+	err = tx.Save(&gasCylinderAllotModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.UpdateFailedErr
+	}
+
+	c.Id = gasCylinderAllotModel.Id
+
+	acceptUser, err := model.GetUserCode(c.AcceptUserId)
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.CreateFailedErr
+	}
+	allotUser, err := model.GetUserCode(c.AllotUserId)
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.CreateFailedErr
+	}
+	data := make([]model.OperationLog, 0)
+
+	switch c.OptType {
+	case "25":
+		// 25送气员领重瓶 37 门店重瓶出库
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 25送气员领重瓶
+			operationLog25 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					OptUser:           acceptUser.ProvUserId,
+					ObjectUser:        acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStore:      acceptUser.Dept.CmpCode,
+					Lng:               utils.ToString(acceptUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(acceptUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+			data = append(data, operationLog25)
+			// 37 门店重瓶出库
+			operationLog37 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "37",
+					OptUser:           allotUser.ProvUserId,
+					ObjectUser:        allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStore:      allotUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(allotUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(allotUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: allotUser.DeptId,
+				},
+			}
+			data = append(data, operationLog37)
+
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    acceptUser.Id,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 添加送气员重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除门店重瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ?", c.InnerCodeList, allotUser.Dept.Id).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "21":
+		// 21门店回收空瓶 27送气员回收空瓶
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 21门店回收空瓶
+			operationLog21 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					ObjectUser:        acceptUser.ProvUserId,
+					OptUser:           acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStore:      acceptUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(acceptUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(acceptUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+			data = append(data, operationLog21)
+
+			// 添加门店空瓶
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+			err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除送气员空瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?", c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "11":
+		// 10 门店空瓶出库 11 司机确认空瓶装车
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 11 司机确认空瓶装车
+			var truckUserCarInfo model.TruckUserCarInfo
+			err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+			operationLog11 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					ObjectUser:        acceptUser.ProvUserId,
+					OptUser:           acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStore:      allotUser.ProvUser.CmpCode,
+					CurrentTruck:      acceptUser.ProvUserId,
+					CurrentMotor:      truckUserCarInfo.CarNo,
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 10 门店空瓶出库
+			operationLog10 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "10",
+					ObjectUser:        acceptUser.ProvUserId,
+					OptUser:           allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStore:      allotUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(allotUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(allotUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: allotUser.DeptId,
+				},
+			}
+			data = append(data, operationLog10)
+
+			data = append(data, operationLog11)
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    acceptUser.Id,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 添加司机空瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除门店空瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?", c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "13":
+		// 12 司机运输空瓶到达气站 13 气站确认空瓶到达气站
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+			var truckUserCarInfo model.TruckUserCarInfo
+			err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+
+			// 13 气站确认空瓶到达气站
+			operationLog13 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					ObjectUser:        acceptUser.ProvUserId,
+					OptUser:           acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStation:    acceptUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(acceptUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(acceptUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+			data = append(data, operationLog13)
+
+			// 12 司机运输空瓶到达气站
+			operationLog12 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "12",
+					ObjectUser:        allotUser.ProvUserId,
+					OptUser:           allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStation:    acceptUser.ProvUser.CmpCode,
+					CurrentTruck:      allotUser.ProvUserId,
+					CurrentMotor:      truckUserCarInfo.CarNo,
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+			data = append(data, operationLog12)
+
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusEmpty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 添加气站空瓶
+			err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除司机空瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?", c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusEmpty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "17":
+		// 15 气站重瓶出库 17 司机确认重瓶从气站出库
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+			var truckUserCarInfo model.TruckUserCarInfo
+			err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+
+			// 17 司机确认重瓶从气站出库
+			err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+			operationLog17 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					OptUser:           acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStation:    allotUser.ProvUser.CmpCode,
+					CurrentTruck:      acceptUser.ProvUserId,
+					CurrentMotor:      truckUserCarInfo.CarNo,
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+			data = append(data, operationLog17)
+
+			// 15 气站重瓶出库
+			operationLog15 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "15",
+					OptUser:           allotUser.ProvUserId,
+					ObjectUser:        allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStation:    allotUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(allotUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(allotUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: allotUser.DeptId,
+				},
+			}
+			data = append(data, operationLog15)
+
+			// 司机添加重瓶
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    acceptUser.Id,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除气站重瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
+			c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "31":
+		// 19 司机交付门店 31 门店确认重瓶卸货入库
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+			var truckUserCarInfo model.TruckUserCarInfo
+			err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+
+			// 31 门店确认重瓶卸货入库
+			operationLog31 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					OptUser:           acceptUser.ProvUserId,
+					ObjectUser:        acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStore:      acceptUser.ProvUser.CmpCode,
+					CurrentTruck:      acceptUser.ProvUserId,
+					CurrentMotor:      truckUserCarInfo.CarNo,
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+			data = append(data, operationLog31)
+
+			// 19 司机交付门店
+			operationLog19 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "19",
+					OptUser:           allotUser.ProvUserId,
+					ObjectUser:        allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStore:      acceptUser.ProvUser.CmpCode,
+					CurrentTruck:      allotUser.ProvUserId,
+					CurrentMotor:      truckUserCarInfo.CarNo,
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: allotUser.DeptId,
+				},
+			}
+			data = append(data, operationLog19)
+
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 门店添加重瓶
+			err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除司机重瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+			c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "35":
+		// 35 门店确认未配送重瓶返库
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+			var truckUserCarInfo model.TruckUserCarInfo
+			err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+
+			// 2、上报气瓶流转信息
+			err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+			operationLog35 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					OptUser:           acceptUser.ProvUserId,
+					CompanyId:         acceptUser.ProvUser.CmpCode,
+					CurrentEnterprise: acceptUser.ProvUser.CmpCode,
+					CurrentStore:      acceptUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(acceptUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(acceptUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+			data = append(data, operationLog35)
+
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 门店添加重瓶
+			err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除送气员重瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+			c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "033":
+		// 33 门店将重瓶退回司机
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+			var truckUserCarInfo model.TruckUserCarInfo
+			// 2、上报气瓶流转信息
+			err = tx.Where("prov_user_id = ?", acceptUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+			operationLog33 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "33",
+					OptUser:           allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStore:      allotUser.ProvUser.CmpCode,
+					Lng:               utils.ToString(allotUser.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(allotUser.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: allotUser.DeptId,
+				},
+			}
+			data = append(data, operationLog33)
+
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    acceptUser.Id,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 司机添加重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除门店重瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
+			c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "016":
+		// 16 司机将订单退回气站
+		for _, chipUid := range c.InnerCodeList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 2、上报气瓶流转信息
+			var truckUserCarInfo model.TruckUserCarInfo
+			err = tx.Where("prov_user_id = ?", allotUser.ProvUserId).First(&truckUserCarInfo).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取车辆信息失败: %s", err)
+				return errors.New("获取车辆信息失败")
+			}
+			operationLog16 := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           "16",
+					ObjectUser:        allotUser.ProvUserId,
+					OptUser:           allotUser.ProvUserId,
+					CompanyId:         allotUser.ProvUser.CmpCode,
+					CurrentEnterprise: allotUser.ProvUser.CmpCode,
+					CurrentStation:    acceptUser.Dept.CmpCode,
+					CurrentTruck:      allotUser.ProvUserId,
+					CurrentMotor:      truckUserCarInfo.CarNo,
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			data = append(data, operationLog16)
+
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: acceptUser.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: acceptUser.DeptId,
+				},
+			}
+
+			// 气站添加重瓶
+			err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+		// 删除司机重瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+			c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "Unqualified":
+		// 不合格 送气员->门店->司机->气站
+		// 送气员->门店
+		if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 0 {
+			// 送气员到门店 送气员不合格- 门店+
+			if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 1 {
+				for _, chipUid := range c.InnerCodeList {
+
+					gasCylinderStatus := &model.GasCylinderStatus{
+						InnerCode: chipUid,
+						UserId:    0,
+						CompanyId: acceptUser.Dept.Id,
+						Status:    model.GasCylinderStatusUnqualified,
+						ControlBy: cModel.ControlBy{
+							CreateBy: p.UserId,
+						},
+						DeptBy: cModel.DeptBy{
+							DeptId: acceptUser.DeptId,
+						},
+					}
+
+					// 门店添加不合格瓶
+					err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+						Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusUnqualified}).FirstOrCreate(&gasCylinderStatus).Error
+					if err != nil {
+						e.Log.Errorf("db error: %s", err)
+						return global.CreateFailedErr
+					}
+				}
+				// 删除送气员不合格瓶
+				err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+					c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusUnqualified).
+					Delete(&model.GasCylinderStatus{}).Error
+				if err != nil {
+					e.Log.Errorf("db error: %s", err)
+					return global.CreateFailedErr
+				}
+			} else {
+				err = errors.New("请出示正确的门店回收不合格瓶调拨码")
+				return err
+			}
+		} else if allotUser.ProvUser.UserType == 3 && allotUser.ProvUser.Isorders == 1 {
+			// 门店到司机 门店- 司机+
+			if acceptUser.ProvUser.UserType == 4 {
+				for _, chipUid := range c.InnerCodeList {
+
+					gasCylinderStatus := &model.GasCylinderStatus{
+						InnerCode: chipUid,
+						UserId:    acceptUser.Id,
+						CompanyId: acceptUser.Dept.Id,
+						Status:    model.GasCylinderStatusUnqualified,
+						ControlBy: cModel.ControlBy{
+							CreateBy: p.UserId,
+						},
+						DeptBy: cModel.DeptBy{
+							DeptId: acceptUser.DeptId,
+						},
+					}
+
+					// 司机添加不合格瓶
+					err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: acceptUser.Id, CompanyId: acceptUser.Dept.Id}).
+						Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusUnqualified}).FirstOrCreate(&gasCylinderStatus).Error
+					if err != nil {
+						e.Log.Errorf("db error: %s", err)
+						return global.CreateFailedErr
+					}
+				}
+				// 删除门店不合格瓶
+				err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
+					c.InnerCodeList, allotUser.Dept.Id, model.GasCylinderStatusUnqualified).
+					Delete(&model.GasCylinderStatus{}).Error
+				if err != nil {
+					e.Log.Errorf("db error: %s", err)
+					return global.CreateFailedErr
+				}
+			} else {
+				err = errors.New("请司机出示正确的回收不合格瓶调拨码")
+				return err
+			}
+		} else if allotUser.ProvUser.UserType == 4 {
+			// 司机->气站 司机- 气站+
+			if acceptUser.ProvUser.UserType == 3 && acceptUser.ProvUser.Isorders == 0 {
+				for _, chipUid := range c.InnerCodeList {
+
+					gasCylinderStatus := &model.GasCylinderStatus{
+						InnerCode: chipUid,
+						UserId:    0,
+						CompanyId: acceptUser.Dept.Id,
+						Status:    model.GasCylinderStatusUnqualified,
+						ControlBy: cModel.ControlBy{
+							CreateBy: p.UserId,
+						},
+						DeptBy: cModel.DeptBy{
+							DeptId: acceptUser.DeptId,
+						},
+					}
+
+					// 气站添加不合格瓶
+					err = tx.Where("inner_code = ? and user_id = 0 and company_id = ? ", chipUid, acceptUser.Dept.Id).
+						Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusUnqualified}).FirstOrCreate(&gasCylinderStatus).Error
+					if err != nil {
+						e.Log.Errorf("db error: %s", err)
+						return global.CreateFailedErr
+					}
+				}
+				// 删除司机不合格瓶
+				err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+					c.InnerCodeList, allotUser.Id, allotUser.Dept.Id, model.GasCylinderStatusUnqualified).
+					Delete(&model.GasCylinderStatus{}).Error
+				if err != nil {
+					e.Log.Errorf("db error: %s", err)
+					return global.CreateFailedErr
+				}
+			} else {
+				err = errors.New("请气站出示正确的回收不合格瓶调拨码")
+				return err
+			}
+		}
+
+	}
+
+	provList := make([]model.ProvOperationLog, 0)
+	for _, v := range data {
+		provList = append(provList, v.GenProvOperationLog())
+	}
+
+	// TODO 同步省平台 1.1.1.22  批量新增操作记录
+	if len(data) > 0 {
+		err = tx.Create(&data).Error
+		if err != nil {
+			tx.Rollback()
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	}
+
+	return nil
+
+}

+ 13 - 13
app/admin/service/gas_cylinder_spec.go

@@ -36,10 +36,10 @@ func (e *GasCylinderSpec) GetPage(c *dto.GasCylinderSpecGetPageReq, list *[]mode
 }
 
 // Get 获取GasCylinderSpec对象
-func (e *GasCylinderSpec) Get(d *dto.GasCylinderSpecGetReq, carInfoModel *model.GasCylinderSpec, p *actions.DataPermission) error {
+func (e *GasCylinderSpec) Get(d *dto.GasCylinderSpecGetReq, gasCylinderAllotModel *model.GasCylinderSpec, p *actions.DataPermission) error {
 	err := e.Orm.
-		Scopes(actions.Permission(carInfoModel.TableName(), p)).
-		First(carInfoModel, d.GetId()).Error
+		Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		First(gasCylinderAllotModel, d.GetId()).Error
 
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -91,10 +91,10 @@ func (e *GasCylinderSpec) Update(c *dto.GasCylinderSpecUpdateReq, p *actions.Dat
 		}
 	}()
 
-	var carInfoModel = model.GasCylinderSpec{}
+	var gasCylinderAllotModel = model.GasCylinderSpec{}
 	// 查询角色是否存在
-	err = e.Orm.Scopes(actions.Permission(carInfoModel.TableName(), p)).
-		First(&carInfoModel, c.GetId()).Error
+	err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		First(&gasCylinderAllotModel, c.GetId()).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
 		if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -103,14 +103,14 @@ func (e *GasCylinderSpec) Update(c *dto.GasCylinderSpecUpdateReq, p *actions.Dat
 		return global.UpdateFailedErr
 	}
 
-	c.Generate(&carInfoModel)
-	err = tx.Save(&carInfoModel).Error
+	c.Generate(&gasCylinderAllotModel)
+	err = tx.Save(&gasCylinderAllotModel).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
 		return global.UpdateFailedErr
 	}
 
-	c.Id = carInfoModel.Id
+	c.Id = gasCylinderAllotModel.Id
 
 	return nil
 }
@@ -128,11 +128,11 @@ func (e *GasCylinderSpec) Remove(c *dto.GasCylinderSpecDeleteReq, p *actions.Dat
 		}
 	}()
 
-	var carInfoModel model.GasCylinderSpec
+	var gasCylinderAllotModel model.GasCylinderSpec
 
 	// 查询角色是否存在
-	err = e.Orm.Scopes(actions.Permission(carInfoModel.TableName(), p)).
-		First(&carInfoModel, c.GetId()).Error
+	err = e.Orm.Scopes(actions.Permission(gasCylinderAllotModel.TableName(), p)).
+		First(&gasCylinderAllotModel, c.GetId()).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
 		if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -141,7 +141,7 @@ func (e *GasCylinderSpec) Remove(c *dto.GasCylinderSpecDeleteReq, p *actions.Dat
 		return global.DeleteFailedErr
 	}
 
-	db := tx.Delete(&carInfoModel)
+	db := tx.Delete(&gasCylinderAllotModel)
 
 	if err = db.Error; err != nil {
 		e.Log.Errorf("db error: %s", err)

+ 276 - 0
app/admin/service/gas_cylinder_status.go

@@ -0,0 +1,276 @@
+package service
+
+import (
+	"errors"
+	"fmt"
+	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/app/admin/service/dto"
+	"gas-cylinder-api/common/actions"
+	cDto "gas-cylinder-api/common/dto"
+	"gas-cylinder-api/common/global"
+	cModel "gas-cylinder-api/common/model"
+	"gogs.baozhida.cn/zoie/OAuth-core/service"
+	"gorm.io/gorm"
+	"gorm.io/gorm/utils"
+	"time"
+)
+
+type GasCylinderStatus struct {
+	service.Service
+}
+
+// GetPage 获取GasCylinderStatus列表
+func (e *GasCylinderStatus) GetPage(c *dto.GasCylinderStatusGetPageReq, list *[]model.GasCylinderStatus, count *int64, p *actions.DataPermission) error {
+	var err error
+	var data model.GasCylinderStatus
+
+	err = e.Orm.Model(&data).
+		Scopes(
+			cDto.MakeCondition(c.GetNeedSearch()),
+			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
+			//actions.Permission(data.TableName(), p),
+		).
+		Where("company_id = ? AND user_id = 0", p.DeptId).
+		Find(list).Limit(-1).Offset(-1).
+		Count(count).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.GetFailedErr
+	}
+	return nil
+}
+
+// GetPage 获取GasCylinderStatus列表
+func (e *GasCylinderStatus) GetUserPage(c *dto.GasCylinderStatusGetPageReq, list *[]model.GasCylinderStatus, count *int64, p *actions.DataPermission) error {
+	var err error
+	var data model.GasCylinderStatus
+
+	err = e.Orm.Model(&data).
+		Scopes(
+			cDto.MakeCondition(c.GetNeedSearch()),
+			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
+			//actions.Permission(data.TableName(), p),
+		).
+		Where("user_id = ?", p.UserId).
+		Find(list).Limit(-1).Offset(-1).
+		Count(count).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.GetFailedErr
+	}
+	return nil
+}
+
+// Get 获取GasCylinderStatus对象
+func (e *GasCylinderStatus) Get(d *dto.GasCylinderStatusGetReq, carInfoModel *model.GasCylinderStatus, p *actions.DataPermission) error {
+	err := e.Orm.
+		Scopes(actions.Permission(carInfoModel.TableName(), p)).
+		First(carInfoModel, d.GetId()).Error
+
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.GetNotFoundOrNoPermissionErr
+		}
+		return global.GetFailedErr
+	}
+
+	return nil
+}
+
+// Insert 创建GasCylinderStatus对象
+func (e *GasCylinderStatus) Insert(c *dto.GasCylinderStatusInsertReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	for _, innerCode := range c.InnerCodeList {
+		var data model.GasCylinderStatus
+
+		err = e.Orm.
+			Where("inner_code = ? ", innerCode).
+			Preload("Company").
+			First(&data).Error
+
+		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+			e.Log.Errorf("db error: %s", err)
+			return global.GetFailedErr
+		}
+		if data.Id > 0 {
+			if data.CompanyId == p.DeptId {
+				continue
+			} else {
+				err = errors.New(fmt.Sprintf("钢瓶%s被【%s】关联,请检查!", innerCode, data.Company.Name))
+				return err
+			}
+
+		}
+
+		// 添加调拨信息
+		data.CompanyId = p.DeptId
+		c.Generate(innerCode, &data)
+		err = tx.Create(&data).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+
+	}
+	return nil
+}
+func (e *GasCylinderStatus) UserInsert(c *dto.GasCylinderStatusInsertReq, p *actions.DataPermission, isorders bool) error {
+	//Isorders 是否是送气员
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	for _, innerCode := range c.InnerCodeList {
+		var data model.GasCylinderStatus
+
+		err = e.Orm.
+			Where("inner_code = ? ", innerCode).
+			Preload("Company").
+			Preload("User").
+			First(&data).Error
+
+		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+			e.Log.Errorf("db error: %s", err)
+			return global.GetFailedErr
+		}
+		if data.Id > 0 {
+			if data.UserId == p.UserId {
+				continue
+			} else {
+				err = errors.New(fmt.Sprintf("钢瓶被【%s】%s关联,请检查!", data.Company.Name, data.User.NickName))
+				return err
+			}
+
+		}
+
+		// 添加调拨信息
+		data.UserId = p.UserId
+		data.CompanyId = p.DeptId
+		c.Generate(innerCode, &data)
+		err = tx.Create(&data).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+
+		if isorders {
+			// 27 送气员回收空瓶
+			log := make([]model.OperationLog, 0)
+			var user model.SysUser
+			user, err = model.GetUserCode(p.UserId)
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 修改用户关联的气瓶信息
+			var cgc model.CustomerGasCylinder
+			err = tx.Where("inner_code = ? and state = 1", innerCode).First(&cgc).Error
+			if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			operationLog := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         innerCode,
+					OptType:           "27",
+					ObjectCustomer:    cgc.CustomerId,
+					OptCustomer:       cgc.CustomerId,
+					OptUser:           user.ProvUserId,
+					ObjectUser:        user.ProvUserId,
+					CompanyId:         user.ProvUser.CmpCode,
+					CurrentEnterprise: user.ProvUser.CmpCode,
+					CurrentStore:      user.Dept.CmpCode,
+					Lng:               utils.ToString(user.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(user.Dept.ProvStore.Lat),
+					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+			log = append(log, operationLog)
+			// TODO 同步省平台 1.1.1.22  批量新增操作记录
+			err = tx.Create(&log).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			if cgc.Id > 0 {
+				cgc.ReturnTime = cModel.Time(time.Now())
+				cgc.State = 2
+				err = tx.Save(&cgc).Error
+				if err != nil {
+					e.Log.Errorf("db error: %s", err)
+					return global.CreateFailedErr
+				}
+			}
+
+		}
+
+	}
+	return nil
+
+}
+
+// Remove 删除GasCylinderStatus
+func (e *GasCylinderStatus) Remove(c *dto.GasCylinderStatusDeleteReq, p *actions.DataPermission) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	var carInfoModel model.GasCylinderStatus
+
+	// 查询钢瓶是否存在
+	err = e.Orm.Scopes(actions.Permission(carInfoModel.TableName(), p)).
+		First(&carInfoModel, c.GetId()).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.DeleteNotFoundOrNoPermissionErr
+		}
+		return global.DeleteFailedErr
+	}
+
+	db := tx.Delete(&carInfoModel)
+
+	if err = db.Error; err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.DeleteFailedErr
+	}
+	if db.RowsAffected == 0 {
+		return global.DeleteNotFoundOrNoPermissionErr
+	}
+
+	return nil
+}

+ 429 - 79
app/admin/service/operation_log.go

@@ -92,13 +92,6 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 	switch c.OptType {
 	case "25", "27":
 		// 送气员领重瓶
-		// 查询门店
-		store, err := model.GetDeptByCmpCode(c.CurrentEnterprise)
-		if err != nil {
-			tx.Rollback()
-			log.Errorf("db error: %s", err)
-			return errors.New("获取门店信息失败")
-		}
 		for _, chipUid := range c.ChipUidList {
 			// 1、通过高频ID查询气瓶内编码
 			var gasCylinder model.GasCylinder
@@ -113,11 +106,12 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 					InnerCode:         gasCylinder.InnerCode,
 					OptType:           c.OptType,
 					OptUser:           user.ProvUserId,
+					ObjectUser:        user.ProvUserId,
 					CompanyId:         user.ProvUser.CmpCode,
 					CurrentEnterprise: user.ProvUser.CmpCode,
-					CurrentStore:      store.CmpCode,
-					Lng:               utils.ToString(store.ProvStore.Lng),
-					Lat:               utils.ToString(store.ProvStore.Lat),
+					CurrentStore:      user.Dept.CmpCode,
+					Lng:               utils.ToString(user.Dept.ProvStore.Lng),
+					Lat:               utils.ToString(user.Dept.ProvStore.Lat),
 					OptTime:           time.Now().Format("2006-01-02 15:04:05"),
 				},
 				ControlBy: cModel.ControlBy{
@@ -127,14 +121,12 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 					DeptId: p.DeptId,
 				},
 			}
-			data = append(data, operationLog)
 
 			if c.OptType == "27" {
 				// 修改用户关联的气瓶信息
 				var cgc model.CustomerGasCylinder
 				err = tx.Where("inner_code = ? and state = 1", gasCylinder.InnerCode).First(&cgc).Error
 				if err != nil {
-					tx.Rollback()
 					log.Errorf("db error: %s", err)
 					return global.CreateFailedErr
 				}
@@ -142,13 +134,15 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 				cgc.State = 2
 				err = tx.Save(&cgc).Error
 				if err != nil {
-					tx.Rollback()
 					log.Errorf("db error: %s", err)
 					return global.CreateFailedErr
 				}
+				operationLog.ObjectCustomer = cgc.CustomerId
+				operationLog.OptCustomer = cgc.CustomerId
+				operationLog.CurrentAddress = cgc.CustomerId
 			}
+			data = append(data, operationLog)
 		}
-
 	case "6", "10", "21", "31", "33", "34", "35", "37":
 
 		// 门店端
@@ -178,6 +172,7 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 					InnerCode:         gasCylinder.InnerCode,
 					OptType:           c.OptType,
 					OptUser:           user.ProvUserId,
+					ObjectUser:        user.ProvUserId,
 					CompanyId:         user.ProvUser.CmpCode,
 					CurrentEnterprise: user.ProvUser.CmpCode,
 					CurrentStore:      user.ProvUser.CmpCode,
@@ -215,9 +210,10 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 			}
 			operationLog := model.OperationLog{
 				ProvOperationLog: model.ProvOperationLog{
-					InnerCode: gasCylinder.InnerCode,
-					OptType:   c.OptType,
-					OptUser:   user.ProvUserId,
+					InnerCode:  gasCylinder.InnerCode,
+					OptType:    c.OptType,
+					OptUser:    user.ProvUserId,
+					ObjectUser: user.ProvUserId,
 					//CompanyId:         user.ProvUser.CmpCode,
 					//CurrentEnterprise: user.ProvUser.CmpCode,
 					//CurrentStore:      user.ProvUser.CmpCode,
@@ -240,26 +236,65 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 			}
 
 			if c.OptType == "11" || c.OptType == "19" {
+				operationLog.CurrentStore = c.CurrentEnterprise
 				operationLog.CompanyId = c.CurrentEnterprise
 				operationLog.CurrentEnterprise = c.CurrentEnterprise
-				operationLog.CurrentStore = c.CurrentEnterprise
 			}
 
 			data = append(data, operationLog)
 		}
+	case "13", "14", "15":
+		// 气站端
+		for _, chipUid := range c.ChipUidList {
+			// 1、通过高频ID查询气瓶内编码
+			var gasCylinder model.GasCylinder
+			err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+			if err != nil {
+				tx.Rollback()
+				e.Log.Errorf("获取气瓶信息失败: %s", err)
+				return errors.New("获取气瓶信息失败")
+			}
+
+			operationLog := model.OperationLog{
+				ProvOperationLog: model.ProvOperationLog{
+					InnerCode:         gasCylinder.InnerCode,
+					OptType:           c.OptType,
+					ObjectUser:        user.ProvUserId,
+					OptUser:           user.ProvUserId,
+					CompanyId:         user.ProvUser.CmpCode,
+					CurrentEnterprise: user.ProvUser.CmpCode,
+					//CurrentStore:      user.ProvUser.CmpCode,
+					CurrentStation: user.ProvUser.CmpCode,
+					Lng:            utils.ToString(user.Dept.ProvStore.Lng),
+					Lat:            utils.ToString(user.Dept.ProvStore.Lat),
+					OptTime:        time.Now().Format("2006-01-02 15:04:05"),
+				},
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
 
+			data = append(data, operationLog)
+		}
 	}
 
 	provList := make([]model.ProvOperationLog, 0)
-	for _, datum := range data {
-		provList = append(provList, datum.GenProvOperationLog())
+	for _, v := range data {
+		provList = append(provList, v.GenProvOperationLog())
+	}
+	err = e.UpdateGasCylinderStatus(tx, c, user, p)
+	if err != nil {
+		e.Log.Errorf("更新钢瓶状态失败: %s", err)
+		return global.CreateFailedErr
 	}
 
 	// TODO 同步省平台 1.1.1.22  批量新增操作记录
 
 	err = tx.Create(&data).Error
 	if err != nil {
-		tx.Rollback()
 		e.Log.Errorf("db error: %s", err)
 		return global.CreateFailedErr
 	}
@@ -268,6 +303,284 @@ func (e *OperationLog) Insert(c *dto.OperationLogInsertReq, p *actions.DataPermi
 
 }
 
+func (e *OperationLog) UpdateGasCylinderStatus(tx *gorm.DB, c *dto.OperationLogInsertReq, user model.SysUser, p *actions.DataPermission) (err error) {
+
+	switch c.OptType {
+	case "15":
+		// 删除气站重瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
+			c.ChipUidList, user.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "17":
+		// 司机确认重瓶从气站出库 添加司机重瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    user.Id,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			// 司机添加重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+	case "19":
+		// 删除司机重瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+			c.ChipUidList, user.Id, user.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "31":
+		// 送气员领重瓶出库 添加送气员重瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			// 门店添加重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+	case "37":
+		// 门店重瓶出库 删除门店重瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ?", c.ChipUidList, user.Dept.Id).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "25":
+		// 送气员领重瓶出库 添加送气员重瓶
+		for _, chipUid := range c.ChipUidList {
+			// 送气员领重瓶出库
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    user.Id,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+			// 添加送气员重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+	case "27":
+		// 删除送气员空瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?", c.ChipUidList, user.Id, user.Dept.Id, model.GasCylinderStatusEmpty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "21":
+		//21门店回收空瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			// 添加门店空瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+	case "10":
+		// 删除门店空瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?", c.ChipUidList, user.Dept.Id, model.GasCylinderStatusEmpty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "11":
+		// 添加司机空瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    user.Id,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+	case "13":
+		// 删除司机空瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?", c.ChipUidList, user.Id, user.Dept.Id, model.GasCylinderStatusEmpty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "12":
+		// 添加气站空瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusEmpty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusEmpty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+	case "14":
+		// 气站空瓶转重瓶
+		err = tx.Model(&model.GasCylinderStatus{}).Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?", c.ChipUidList, user.Dept.Id, model.GasCylinderStatusEmpty).
+			Updates(map[string]interface{}{
+				"status": model.GasCylinderStatusWeighty,
+			}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+
+	case "16":
+		// 删除司机重瓶
+		err = tx.Where("inner_code in (?) and user_id = ? and company_id = ? and status = ?",
+			c.ChipUidList, user.Id, user.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "016":
+		// 添加气站空瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    0,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			// 气站添加重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+
+	case "33":
+		// 删除门店重瓶
+		err = tx.Where("inner_code in (?) and user_id = 0 and company_id = ? and status = ?",
+			c.ChipUidList, user.Dept.Id, model.GasCylinderStatusWeighty).
+			Delete(&model.GasCylinderStatus{}).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.CreateFailedErr
+		}
+	case "033":
+		// 添加气站空瓶
+		for _, chipUid := range c.ChipUidList {
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    user.Id,
+				CompanyId: user.Dept.Id,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: p.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: p.DeptId,
+				},
+			}
+
+			// 司机添加重瓶
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: user.Id, CompanyId: user.Dept.Id}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				e.Log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+		}
+
+	}
+	return nil
+}
+
 func (e *OperationLog) InsertForGasStation(c *dto.OperationLogInsertForGasStationReq) error {
 	var err error
 	tx := e.Orm.Begin()
@@ -317,70 +630,107 @@ func (e *OperationLog) InsertForGasStation(c *dto.OperationLogInsertForGasStatio
 }
 
 // 送气员送达重瓶,送气订单取消
-func InsertOperationLogByOptType26Or36(tx *gorm.DB, OptType string, chipUid string, order model.Order) error {
+func InsertOperationLogByOptType26Or36(tx *gorm.DB, OptType string, chipUids []string, order model.Order) error {
 	var err error
+	for _, chipUid := range chipUids {
+		// 1、通过高频ID查询气瓶内编码
+		var gasCylinder model.GasCylinder
+		err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
+		if err != nil {
+			return errors.New("获取气瓶信息失败")
+		}
 
-	// 1、通过高频ID查询气瓶内编码
-	var gasCylinder model.GasCylinder
-	err = tx.Where("uid = ?", chipUid).First(&gasCylinder).Error
-	if err != nil {
-		return errors.New("获取气瓶信息失败")
-	}
+		// 新增操作记录
+		operationLog := model.OperationLog{
+			ProvOperationLog: model.ProvOperationLog{
+				OptType:           OptType,
+				OptTime:           time.Now().Format("2006-01-02 15:04:05"),
+				OptUser:           order.User.ProvUserId,
+				ObjectUser:        order.User.ProvUserId,
+				InnerCode:         gasCylinder.InnerCode,
+				ObjectCustomer:    order.CustomerId,
+				OptCustomer:       order.CustomerId,
+				CompanyId:         order.Dept.CmpCode,
+				CurrentEnterprise: order.Store.CmpCode,
+				CurrentStore:      order.Store.CmpCode,
+				CurrentAddress:    order.CustomerId,
+			},
+			ControlBy: cModel.ControlBy{
+				CreateBy: order.UserId,
+			},
+			DeptBy: cModel.DeptBy{
+				DeptId: order.StoreId,
+			},
+		}
 
-	operationLog := model.OperationLog{
-		ProvOperationLog: model.ProvOperationLog{
-			OptType:           OptType,
-			OptTime:           time.Now().Format("2006-01-02 15:04:05"),
-			OptUser:           order.User.ProvUserId,
-			InnerCode:         gasCylinder.InnerCode,
-			ObjectCustomer:    order.CustomerId,
-			OptCustomer:       order.CustomerId,
-			CompanyId:         order.Dept.CmpCode,
-			CurrentEnterprise: order.Store.CmpCode,
-			CurrentAddress:    order.CustomerId,
-		},
-		ControlBy: cModel.ControlBy{
-			CreateBy: order.UserId,
-		},
-		DeptBy: cModel.DeptBy{
-			DeptId: order.DeptId,
-		},
-	}
-	// TODO 同步省平台 1.1.1.20 新增操作记录
-	//ipr := data.GenProvOperationLog()
-	err = tx.Create(&operationLog).Error
-	if err != nil {
-		tx.Rollback()
-		log.Errorf("db error: %s", err)
-		return global.CreateFailedErr
-	}
-	if OptType == "26" {
-		// 新增客户气瓶信息
-		err = tx.Create(&model.CustomerGasCylinder{
-			CustomerId: order.CustomerId,
-			InnerCode:  gasCylinder.InnerCode,
-			State:      1,
-			BorrowTime: cModel.Time(time.Now()),
-		}).Error
-		if err != nil {
-			tx.Rollback()
-			log.Errorf("db error: %s", err)
-			return global.CreateFailedErr
+		if OptType == "26" {
+			// 新增客户气瓶信息
+			err = tx.Create(&model.CustomerGasCylinder{
+				CustomerId: order.CustomerId,
+				InnerCode:  gasCylinder.InnerCode,
+				State:      1,
+				BorrowTime: cModel.Time(time.Now()),
+			}).Error
+			if err != nil {
+				tx.Rollback()
+				log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 删除送气员重瓶
+			err = tx.Where("inner_code = ? and user_id = ? and company_id = ? and status = ?",
+				gasCylinder.InnerCode, order.UserId, order.StoreId, model.GasCylinderStatusWeighty).
+				Delete(&model.GasCylinderStatus{}).Error
+			if err != nil {
+				log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
 		}
-	}
 
-	if OptType == "36" {
-		// 查询气瓶信息
-		var cgc model.CustomerGasCylinder
-		err = tx.Where("inner_code = ? and state = 1", gasCylinder.InnerCode, order.CustomerId).First(&cgc).Error
-		if err != nil {
-			tx.Rollback()
-			log.Errorf("db error: %s", err)
-			return global.CreateFailedErr
+		if OptType == "36" {
+			// 查询气瓶信息
+			var cgc model.CustomerGasCylinder
+			err = tx.Where("inner_code = ? and customer_id=? and state = 1", gasCylinder.InnerCode, order.CustomerId).First(&cgc).Error
+			if err != nil {
+				log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+			cgc.ReturnTime = cModel.Time(time.Now())
+			cgc.State = 2
+			err = tx.Save(&cgc).Error
+			if err != nil {
+				log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			// 添加送气员重瓶
+			gasCylinderStatus := &model.GasCylinderStatus{
+				InnerCode: chipUid,
+				UserId:    order.UserId,
+				CompanyId: order.StoreId,
+				Status:    model.GasCylinderStatusWeighty,
+				ControlBy: cModel.ControlBy{
+					CreateBy: order.UserId,
+				},
+				DeptBy: cModel.DeptBy{
+					DeptId: order.StoreId,
+				},
+			}
+			err = tx.Where(model.GasCylinderStatus{InnerCode: chipUid, UserId: order.UserId, CompanyId: order.StoreId}).
+				Assign(model.GasCylinderStatus{Status: model.GasCylinderStatusWeighty}).FirstOrCreate(&gasCylinderStatus).Error
+			if err != nil {
+				log.Errorf("db error: %s", err)
+				return global.CreateFailedErr
+			}
+
+			operationLog.ObjectCustomer = cgc.CustomerId
+			operationLog.OptCustomer = cgc.CustomerId
+			operationLog.CurrentAddress = cgc.CustomerId
 		}
-		cgc.ReturnTime = cModel.Time(time.Now())
-		cgc.State = 2
-		err = tx.Save(&cgc).Error
+
+		// TODO 同步省平台 1.1.1.20 新增操作记录
+		//ipr := data.GenProvOperationLog()
+		err = tx.Create(&operationLog).Error
 		if err != nil {
 			tx.Rollback()
 			log.Errorf("db error: %s", err)

+ 9 - 2
app/admin/service/order.go

@@ -176,12 +176,14 @@ func (e *Order) AppletInsert(c *dto.OrderAppletInsertReq) error {
 	}
 
 	if len(storeCustomer.ProvCustomer.Id) > 0 {
+		storeCustomer.Name = c.Name
 		storeCustomer.Lng = c.Lng
 		storeCustomer.Lat = c.Lat
 		storeCustomer.City = c.City
 		storeCustomer.Area = c.Area
 		storeCustomer.Address = c.Address
 		storeCustomer.AddressImg = c.AddressImg
+
 		dataIntegrity := CustomerCheckDataIntegrity(storeCustomer)
 		if dataIntegrity {
 			// TODO 同步省平台 更新客户信息
@@ -276,6 +278,7 @@ func (e *Order) AppletUpdate(c *dto.OrderAppletUpdateReq) error {
 				"area":    c.Area,
 				"city":    c.City,
 				"address": c.Address,
+				"name":    c.Name,
 			}).Error
 		if err != nil {
 			return global.UpdateFailedErr
@@ -421,7 +424,8 @@ func (e *Order) UpdateState(c *dto.OrderUpdateStateReq, p *actions.DataPermissio
 
 	var orderModel = model.Order{}
 	// 查询订单是否存在
-	err = e.Orm.Scopes(actions.Permission(orderModel.TableName(), p)).
+	err = e.Orm.
+		Scopes(InDeptIdScopes(p.DeptId)).
 		Preload("User").Preload("Store").Preload("Dept").
 		First(&orderModel, c.GetId()).Error
 	if err != nil {
@@ -441,23 +445,26 @@ func (e *Order) UpdateState(c *dto.OrderUpdateStateReq, p *actions.DataPermissio
 		}
 	}()
 
-	c.Generate(&orderModel)
 	// 配送中
 	if c.State == model.OrderStateInDelivery {
+		orderModel.State = c.State
 		orderModel.DeliveryTime = common.Time(time.Now())
 	}
 	// 已送达
 	if c.State == model.OrderStateArrive {
+		orderModel.State = c.State
 		orderModel.ArriveTime = common.Time(time.Now())
 		err = InsertOperationLogByOptType26Or36(tx, "26", c.ChipUid, orderModel)
 		if err != nil {
 			e.Log.Errorf("db error: %s", err)
 			return global.UpdateFailedErr
 		}
+		// 删除送气员重瓶
 
 	}
 	// 已取消
 	if c.State == model.OrderStateCancel && orderModel.State == model.OrderStateArrive {
+		orderModel.State = c.State
 		orderModel.CancelTime = common.Time(time.Now())
 		err = InsertOperationLogByOptType26Or36(tx, "36", c.ChipUid, orderModel)
 		if err != nil {

+ 14 - 0
app/admin/service/store.go

@@ -24,6 +24,20 @@ type Store struct {
 	service.Service
 }
 
+func InDeptIdScopes(deptId int) func(db *gorm.DB) *gorm.DB {
+
+	return func(db *gorm.DB) *gorm.DB {
+		if deptId == 0 {
+			return db
+		}
+		ids, err := model.GetParentIds(deptId)
+		if err != nil {
+			return db
+		}
+		return db.Where("dept_id in (?)", ids)
+	}
+}
+
 // Get 获取SysDept对象
 func (e *Store) Get(d *dto.StoreGetReq, deptModel *model.SysDept) error {
 	err := e.Orm.

+ 1 - 12
app/admin/service/sys_user.go

@@ -119,11 +119,9 @@ func (e *SysUser) GetCount(c *dto.SysUserGetCountReq, count *int64) error {
 // Get 获取SysUser对象
 func (e *SysUser) Get(d *dto.SysUserGetReq, p *actions.DataPermission, userModel *model.SysUser) error {
 	var data model.SysUser
-	var dept model.SysDept
-	var role model.SysRole
-	//var post model.SysPost
 	err := e.Orm.Model(&data).
 		Scopes(actions.UserPermission(data.TableName(), p)).
+		Preload("Dept").Preload("Role").
 		First(userModel, d.GetId()).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -132,15 +130,6 @@ func (e *SysUser) Get(d *dto.SysUserGetReq, p *actions.DataPermission, userModel
 		}
 		return global.GetFailedErr
 	}
-	err = e.Orm.First(&dept, userModel.DeptId).Error
-	userModel.Dept = dept
-
-	err = e.Orm.First(&role, userModel.RoleId).Error
-	userModel.Role = role
-
-	//err = e.Orm.First(&post, userModel.PostId).Error
-	//userModel.Post = post
-
 	return nil
 }
 func (e *SysUser) GetByProvUserId(provUserId string, userModel *model.SysUser) error {

+ 5 - 5
cmd/api/server.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"gas-cylinder-api/app/admin/model"
+	"gas-cylinder-api/app/jobs"
 	"gas-cylinder-api/common/file_store"
 	global2 "gas-cylinder-api/common/global"
 	"gas-cylinder-api/common/middleware"
@@ -96,14 +97,13 @@ func run() error {
 	//go func() {
 	//	otherSvc.InitJob()
 	//	otherSvc.Setup(sdk.Runtime.GetDb())
-	//
 	//}()
 
 	// fixme 定时任务,需要时再配置
-	//go func() {
-	//	jobs.InitJob()
-	//	jobs.Setup(sdk.Runtime.GetDb())
-	//}()
+	go func() {
+		jobs.InitJob()
+		jobs.Setup(sdk.Runtime.GetDb())
+	}()
 
 	go func() {
 		// 服务连接

+ 1 - 1
common/actions/permission.go

@@ -99,7 +99,7 @@ func Permission(tableName string, p *DataPermission) func(db *gorm.DB) *gorm.DB
 		case "3":
 			return db.Where(tableName+".dept_id = ?", p.DeptId)
 		case "4":
-			return db.Where(tableName+".create_by in (SELECT id from sys_user where sys_user.dept_id in (select id from sys_dept where dept_path like ? ))", "%/"+pkg.IntToString(p.DeptId)+"/%")
+			return db.Where(tableName+".create_by in (SELECT id from sys_user where sys_user.dept_id in (select id from sys_dept where path like ? ))", "%/"+pkg.IntToString(p.DeptId)+"/%")
 		case "5":
 			return db.Where(tableName+".create_by = ?", p.UserId)
 		default:

+ 13 - 1
common/model/byat.go

@@ -2,6 +2,7 @@ package model
 
 import (
 	"database/sql/driver"
+	"encoding/json"
 	"fmt"
 	"gorm.io/gorm"
 	"time"
@@ -74,7 +75,7 @@ func (t Time) String() string {
 	return time.Time(t).Format(timeFormat)
 }
 
-func (t Time) local() time.Time {
+func (t Time) Local() time.Time {
 	loc, _ := time.LoadLocation(timezone)
 	return time.Time(t).In(loc)
 }
@@ -96,3 +97,14 @@ func (t *Time) Scan(v interface{}) error {
 	}
 	return fmt.Errorf("can not convert %v to timestamp", v)
 }
+
+type StringList []string
+
+func (e StringList) Value() (driver.Value, error) {
+	d, err := json.Marshal(e)
+	return string(d), err
+}
+
+func (e *StringList) Scan(src interface{}) error {
+	return json.Unmarshal(src.([]byte), e)
+}

+ 3 - 1
conf/settings.yml

@@ -49,4 +49,6 @@ settings:
       endpoint: "https://bzdcdn.baozhida.cn/"
       accessKeyID: "-8ezB_d-8-eUFTMvhOGbGzgeQRPeKQnaQ3DBcUxo"
       accessKeySecret: "KFhkYxTAJ2ZPN3ZS3euTsfWk8-C92rKgkhAMkDRN"
-      bucketName: "bzdcdn"
+      bucketName: "bzdcdn"
+    applet:
+      tokenExpire: 30

+ 4 - 0
db/migration.go

@@ -4,6 +4,7 @@ import (
 	"go.uber.org/zap"
 
 	"gas-cylinder-api/app/admin/model"
+	jobModel "gas-cylinder-api/app/jobs/model"
 )
 
 // 执行数据迁移
@@ -11,6 +12,7 @@ func AutoMigrateDB() {
 	//自动迁移模式
 	err := DB.Set("gorm:table_options", "charset=utf8mb4").
 		AutoMigrate(
+			&jobModel.SysJob{},
 			&model.SysUser{},
 			&model.SysRole{},
 			&model.SysRoleMenu{},
@@ -36,6 +38,8 @@ func AutoMigrateDB() {
 			&model.FillData{},
 			&model.TruckUserCarInfo{},
 			&model.CustomerGasCylinder{},
+			&model.GasCylinderAllot{},
+			&model.GasCylinderStatus{},
 		)
 	if err != nil {
 		zap.L().Panic("migrate db fail", zap.Error(err))

+ 2 - 1
go.mod

@@ -74,6 +74,8 @@ require (
 	github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
 	github.com/klauspost/cpuid/v2 v2.0.9 // indirect
 	github.com/leodido/go-urn v1.2.1 // indirect
+	github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
+	github.com/lestrrat-go/strftime v1.0.6 // indirect
 	github.com/mailru/easyjson v0.7.7 // indirect
 	github.com/mattn/go-colorable v0.1.7 // indirect
 	github.com/mattn/go-isatty v0.0.17 // indirect
@@ -115,5 +117,4 @@ require (
 
 replace gogs.baozhida.cn/zoie/OAuth-core => /Users/zoie/work/bzd_project/OAuth-core
 
-
 replace google.golang.org/grpc => google.golang.org/grpc v1.26.0

+ 5 - 0
go.sum

@@ -383,6 +383,11 @@ github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL
 github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
 github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
 github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
+github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
+github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
+github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
+github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
+github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
 github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE=
 github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8=
 github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0=