Explorar o código

FUNC:修改个人信息(H5)

zoie hai 11 meses
pai
achega
41deeef73e

+ 302 - 21
app/admin/controller/applet_customer.go

@@ -5,11 +5,15 @@ import (
 	"gas-cylinder-api/app/admin/service"
 	"gas-cylinder-api/app/admin/service/dto"
 	"gas-cylinder-api/common/actions"
+	"github.com/dgrijalva/jwt-go"
 	"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"
+	"golang.org/x/crypto/bcrypt"
+	"net/http"
+	"strings"
+	"time"
 )
 
 type AppletCustomerController struct {
@@ -19,9 +23,9 @@ type AppletCustomerController struct {
 // Login 小程序登录
 // @Summary 小程序登录
 // @Description 小程序登录
-// @Tags 客户小程序
+// @Tags 用户端
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.Customer}} "{"code": 200, "data": [...]}"
-// @Router /api/customer [get]
+// @Router /api/applet/login [get]
 // @Security Bearer
 func (e AppletCustomerController) Login(c *gin.Context) {
 	s := service.AppletCustomer{}
@@ -49,12 +53,100 @@ func (e AppletCustomerController) Login(c *gin.Context) {
 	e.OK(data, "查询成功")
 }
 
+// Refresh 刷新token
+// @Summary 刷新token
+// @Description 刷新token
+// @Tags 用户端
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.Customer}} "{"code": 200, "data": [...]}"
+// @Router /api/applet/refresh [get]
+// @Security Bearer
+func (e AppletCustomerController) Refresh(c *gin.Context) {
+	s := service.AppletCustomer{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+
+	tokenString := c.GetHeader("Authorization")
+	if tokenString == "" {
+		c.JSON(http.StatusUnauthorized, gin.H{
+			"code": 401,
+			"msg":  "Unauthorized",
+		})
+		return
+	}
+
+	parts := strings.SplitN(tokenString, " ", 2)
+	if !(len(parts) == 2 && parts[0] == "Bearer") {
+		c.JSON(http.StatusOK, gin.H{
+			"code": 401,
+			"msg":  "请求头中auth格式有误",
+		})
+		return
+	}
+
+	// 解析token
+	token, err := jwt.ParseWithClaims(parts[1], &model.CustomerClaims{}, func(token *jwt.Token) (i interface{}, err error) {
+		return model.AppletCustomerSecret, nil
+	})
+
+	if err != nil || !token.Valid {
+		if err.(*jwt.ValidationError).Errors != jwt.ValidationErrorExpired {
+			c.JSON(http.StatusUnauthorized, gin.H{
+				"code": 401,
+				"msg":  "Unauthorized",
+			})
+			return
+		}
+	}
+
+	claims, ok := token.Claims.(*model.CustomerClaims)
+	if !ok {
+		c.JSON(http.StatusUnauthorized, gin.H{
+			"code": 401,
+			"msg":  "Unauthorized",
+		})
+		return
+	}
+
+	if claims.ExpiresAt < time.Now().Unix() {
+		if claims.ExpiresAt > time.Now().Add(-2*time.Hour).Unix() {
+			newToken, expiresAt, _ := s.GeneratorToken(claims.CustomerId)
+			c.Set("customer_id", claims.CustomerId)
+			data := map[string]string{
+				"token":     newToken,
+				"expiresAt": expiresAt,
+			}
+			e.OK(data, "查询成功")
+			return
+		}
+
+		c.JSON(http.StatusUnauthorized, gin.H{
+			"code": 401,
+			"msg":  "Token is expired",
+		})
+		return
+	}
+	newToken, expiresAt, _ := s.GeneratorToken(claims.CustomerId)
+	c.Set("customer_id", claims.CustomerId)
+	data := map[string]string{
+		"token":     newToken,
+		"expiresAt": expiresAt,
+	}
+	e.OK(data, "查询成功")
+}
+
 // Register 注册
 // @Summary 小程序登录
 // @Description 小程序登录
-// @Tags 客户小程序
+// @Tags 用户端
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.Customer}} "{"code": 200, "data": [...]}"
-// @Router /api/customer [get]
+// @Router /api/applet/register [get]
 // @Security Bearer
 func (e AppletCustomerController) Register(c *gin.Context) {
 	s := service.AppletCustomer{}
@@ -81,9 +173,9 @@ func (e AppletCustomerController) Register(c *gin.Context) {
 // GetProfile 获取个人中心用户
 // @Summary 获取个人中心用户
 // @Description 获取个人中心用户
-// @Tags 个人中心
+// @Tags 用户端
 // @Success 200 {object} response.Response{user=model.SysUser,role=model.SysRole}  "{"code": 200, "data": {"user":[...],"role":[...]}}"
-// @Router /api/user/profile [get]
+// @Router /api/applet/profile [get]
 // @Security Bearer
 func (e AppletCustomerController) GetProfile(c *gin.Context) {
 	s := service.Customer{}
@@ -112,7 +204,7 @@ func (e AppletCustomerController) GetProfile(c *gin.Context) {
 // GetOrderPage 获取订单列表
 // @Summary 获取订单列表
 // @Description 获取订单列表
-// @Tags 订单
+// @Tags 用户端
 // @Param state          query int false "订单状态 1-已下单 2-已派送 3-已送达 4-已取消"
 // @Param source         query int false "订单状态 1-坐席下单 2-小程序"
 // @Param orderStartTime query string false "下单开始时间"
@@ -122,7 +214,7 @@ func (e AppletCustomerController) GetProfile(c *gin.Context) {
 // @Param pageSize query int false "页条数"
 // @Param page query int false "页码"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.Order}} "{"code": 200, "data": [...]}"
-// @Router /api/Order [get]
+// @Router /api/applet/order [get]
 // @Security Bearer
 func (e AppletCustomerController) GetOrderPage(c *gin.Context) {
 	s := service.Order{}
@@ -156,13 +248,13 @@ func (e AppletCustomerController) GetOrderPage(c *gin.Context) {
 // OrderInsert 订气
 // @Summary 订气
 // @Description 订气
-// @Tags 用户H5订单
+// @Tags 用户
 // @Accept  application/json
 // @Product application/json
-// @Param data body dto.OrderInsertReq true "data"
+// @Param data body dto.OrderAppletInsertReq true "data"
 // @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
 // @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
-// @Router /api/order [post]
+// @Router /api/applet/order [post]
 // @Security Bearer
 func (e AppletCustomerController) OrderInsert(c *gin.Context) {
 	s := service.Order{}
@@ -189,9 +281,20 @@ func (e AppletCustomerController) OrderInsert(c *gin.Context) {
 	e.OK(req.GetId(), "创建成功")
 }
 
+// OrderUpdate 修改订单
+// @Summary 修改订单
+// @Description 修改订单
+// @Tags 用户端
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.OrderAppletUpdateReq true "data"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/applet/order [put]
+// @Security Bearer
 func (e AppletCustomerController) OrderUpdate(c *gin.Context) {
 	s := service.Order{}
-	req := dto.OrderUpdateReq{}
+	req := dto.OrderAppletUpdateReq{}
 	err := e.MakeContext(c).
 		MakeOrm().
 		Bind(&req, binding.JSON).
@@ -203,11 +306,7 @@ func (e AppletCustomerController) OrderUpdate(c *gin.Context) {
 		return
 	}
 
-	//数据权限检查
-	p := actions.GetPermissionFromContext(c)
-	// 设置创建人
-	req.SetCreateBy(user.GetUserId(c))
-	err = s.Update(&req, p)
+	err = s.AppletUpdate(&req)
 	if err != nil {
 		e.Error(500, err, err.Error())
 		return
@@ -215,13 +314,48 @@ func (e AppletCustomerController) OrderUpdate(c *gin.Context) {
 	e.OK(req.GetId(), "修改成功")
 }
 
+// OrderCancel 取消订单
+// @Summary 取消订单
+// @Description 取消订单
+// @Tags 用户端
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.OrderCancelReq true "data"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/applet/order [put]
+// @Security Bearer
+func (e AppletCustomerController) OrderCancel(c *gin.Context) {
+	s := service.Order{}
+	req := dto.OrderCancelReq{}
+	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
+	}
+
+	err = s.Cancel(&req, nil)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "取消成功")
+}
+
 // StoreList 获取销售门店列表
 // @Summary 获取销售门店列表
-// @Description 获取销售门店列表(用户公司及子公司)
-// @Tags 销售门店
+// @Description 获取销售门店列表
+// @Tags 用户端
 // @Param name query string false "销售门店名称"
+// @Param district query string false "所在地市"
+// @Param city query string false "所在区县"
 // @Success 200 {object} response.Response{data=response.Page{list=[]model.SysDept}} "{"code": 200, "data": [...]}"
-// @Router /api/store [get]
+// @Router /api/applet/store [get]
 // @Security Bearer
 func (e AppletCustomerController) StoreList(c *gin.Context) {
 	s := service.Store{}
@@ -246,3 +380,150 @@ func (e AppletCustomerController) StoreList(c *gin.Context) {
 	}
 	e.OK(list, "查询成功")
 }
+
+// UpdatePwd 修改密码
+// @Summary 修改密码
+// @Description 修改密码
+// @Tags 用户端
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.PassWord true "body"
+// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
+// @Router /api/user/pwd/set [put]
+// @Security Bearer
+func (e AppletCustomerController) UpdatePwd(c *gin.Context) {
+	s := service.AppletCustomer{}
+	req := dto.PassWord{}
+	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
+	}
+
+	var hash []byte
+	if hash, err = bcrypt.GenerateFromPassword([]byte(req.NewPassword), bcrypt.DefaultCost); err != nil {
+		req.NewPassword = string(hash)
+	}
+
+	err = s.UpdatePwd(service.GetAppletCustomerId(c), req.OldPassword, req.NewPassword)
+	if err != nil {
+		e.Error(http.StatusForbidden, err, err.Error())
+		return
+	}
+
+	e.OK(nil, "密码修改成功")
+
+}
+
+// GetGoodsPage 获取商品列表
+// @Summary 获取商品列表
+// @Description 获取商品列表
+// @Tags 用户端
+// @Param storeId   query int true "销售门店id"
+// @Param name      query string false "商品名称"
+// @Param mediaType query string false "介质类型"
+// @Param isShow    query int false "是否展示 1-展示 2-不展示"
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.Goods}} "{"code": 200, "data": [...]}"
+// @Router /api/goods [get]
+// @Security Bearer
+func (e AppletCustomerController) GetGoodsPage(c *gin.Context) {
+	s := service.Goods{}
+	req := dto.AppletGoodsGetPageReq{}
+	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)
+	p.DeptId = req.StoreId
+
+	list := make([]model.Goods, 0)
+	var count int64
+
+	err = s.GetAppletPage(&req, &list, &count)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// GetGasCylinderSpecPage 获取钢瓶规格列表
+// @Summary 获取钢瓶规格列表
+// @Description 获取钢瓶规格列表
+// @Tags 钢瓶规格
+// @Param name query string false "钢瓶规格名称"
+// @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinderSpec}} "{"code": 200, "data": [...]}"
+// @Router /api/dispatch-cost [get]
+// @Security Bearer
+func (e AppletCustomerController) GetGasCylinderSpecPage(c *gin.Context) {
+	s := service.GasCylinderSpec{}
+	req := dto.AppletGasCylinderSpecGetPageReq{}
+	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
+	}
+
+	//数据权限检查
+	list := make([]model.GasCylinderSpec, 0)
+	var count int64
+
+	err = s.GetAppletPage(&req, &list, &count)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
+}
+
+// UpdateCustomerInfo 修改个人信息
+// @Summary 修改客户信息
+// @Description 修改客户信息
+// @Tags 客户信息
+// @Accept  application/json
+// @Product application/json
+// @Param id path string true "客户信息id"
+// @Param data body dto.CustomerUpdateReq true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/customer [put]
+// @Security Bearer
+func (e AppletCustomerController) UpdateCustomerInfo(c *gin.Context) {
+	s := service.Customer{}
+	req := dto.AppletCustomerUpdateReq{}
+	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
+	}
+	req.Id = service.GetAppletCustomerId(c)
+	err = s.AppletUpdate(&req)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "更新成功")
+}

+ 9 - 7
app/admin/model/address.go

@@ -4,13 +4,15 @@ import model2 "gas-cylinder-api/common/model"
 
 type Address struct {
 	model2.Model
-	CustomerId string `json:"customerId" gorm:"size:32;"` // 客户id
-	Name       string `json:"name" gorm:"size:32;"`       // 收货人名称
-	Phone      string `json:"phone" gorm:"size:32;"`      // 联系电话
-	City       string `json:"city" gorm:"size:6;"`        // 所在地市
-	Area       string `json:"area" gorm:"size:6;"`        // 所属区/县
-	Address    string `json:"address" gorm:"size:128"`    // 详细地址
-	IsDefault  bool   `json:"isDefault" gorm:"size:128"`  // 默认
+	CustomerId string  `json:"customerId" gorm:"size:32;"` // 客户id
+	Name       string  `json:"name" gorm:"size:32;"`       // 收货人名称
+	Phone      string  `json:"phone" gorm:"size:32;"`      // 联系电话
+	City       string  `json:"city" gorm:"size:6;"`        // 所在地市
+	Area       string  `json:"area" gorm:"size:6;"`        // 所属区/县
+	Address    string  `json:"address" gorm:"size:128"`    // 详细地址
+	Lng        float64 `json:"lng" gorm:"size:9;"`         // 经度
+	Lat        float64 `json:"lat" gorm:"size:9;"`         // 纬度
+	IsDefault  bool    `json:"isDefault" gorm:"size:128"`  // 默认
 	model2.ControlBy
 	model2.ModelTime
 }

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

@@ -174,6 +174,8 @@ type SysUserOmit struct {
 	Id         int    `json:"id,omitempty"`         // 主键编码
 	NickName   string `json:"nickName,omitempty"`   // 昵称
 	ProvUserId string `json:"provUserId,omitempty"` // 省平台用户id
+	Phone      string `json:"phone"`                // 手机号
+
 }
 
 func (SysUserOmit) TableName() string {

+ 36 - 8
app/admin/router/applet_customer.go

@@ -7,6 +7,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"net/http"
 	"strings"
+	"time"
 )
 
 var (
@@ -22,7 +23,7 @@ func AppletCunJWTMiddleware() gin.HandlerFunc {
 		tokenString := c.GetHeader("Authorization")
 		if tokenString == "" {
 			c.JSON(http.StatusUnauthorized, gin.H{
-				"code": 200,
+				"code": 401,
 				"msg":  "Unauthorized",
 			})
 			c.Abort()
@@ -32,7 +33,7 @@ func AppletCunJWTMiddleware() gin.HandlerFunc {
 		parts := strings.SplitN(tokenString, " ", 2)
 		if !(len(parts) == 2 && parts[0] == "Bearer") {
 			c.JSON(http.StatusOK, gin.H{
-				"code": 2004,
+				"code": 401,
 				"msg":  "请求头中auth格式有误",
 			})
 			c.Abort()
@@ -45,6 +46,19 @@ func AppletCunJWTMiddleware() gin.HandlerFunc {
 		})
 
 		if err != nil || !token.Valid {
+			if err.(*jwt.ValidationError).Errors != jwt.ValidationErrorExpired {
+				c.JSON(http.StatusUnauthorized, gin.H{
+					"code": 401,
+					"msg":  "Unauthorized",
+				})
+				c.Abort()
+				return
+			}
+
+		}
+
+		claims, ok := token.Claims.(*model.CustomerClaims)
+		if !ok {
 			c.JSON(http.StatusUnauthorized, gin.H{
 				"code": 401,
 				"msg":  "Unauthorized",
@@ -53,14 +67,23 @@ func AppletCunJWTMiddleware() gin.HandlerFunc {
 			return
 		}
 
-		claims, ok := token.Claims.(*model.CustomerClaims)
-		if !ok {
+		if claims.ExpiresAt < time.Now().Unix() {
+			if claims.ExpiresAt > time.Now().Add(-2*time.Hour).Unix() {
+				c.JSON(http.StatusUnauthorized, gin.H{
+					"code": 6401,
+					"msg":  "Token is expired",
+				})
+				c.Abort()
+				return
+			}
+
 			c.JSON(http.StatusUnauthorized, gin.H{
-				"code": 401,
-				"msg":  "Unauthorized",
+				"code": 6401,
+				"msg":  "Token is expired",
 			})
 			c.Abort()
 			return
+
 		}
 
 		c.Set("customer_id", claims.CustomerId)
@@ -75,6 +98,7 @@ func AppletCustomerRouterInit(v1 *gin.RouterGroup) {
 	{
 		r.POST("/login", cont.Login)
 		r.POST("/register", cont.Register)
+		r.GET("/refresh", cont.Refresh)
 
 	}
 
@@ -85,14 +109,18 @@ func AppletCustomerRouterInit(v1 *gin.RouterGroup) {
 
 func AppletCustomerRouter(v1 *gin.RouterGroup, authMiddleware gin.HandlerFunc) {
 	cont := controller.AppletCustomerController{}
-	order := controller.OrderController{}
 
 	r := v1.Group("").Use(authMiddleware)
 	{
 		r.GET("/profile", cont.GetProfile)
+		r.PUT("/customer-info", cont.UpdateCustomerInfo)
+		r.PUT("/pwd", cont.UpdatePwd)
 		r.GET("/order", cont.GetOrderPage)
 		r.POST("/order", cont.OrderInsert)
-		r.PUT("/order", order.Update)
+		r.PUT("/order", cont.OrderUpdate)
+		r.POST("/order/cancel", cont.OrderCancel)
 		r.GET("/store", cont.StoreList)
+		r.GET("/goods", cont.GetGoodsPage)
+		r.GET("/gas-cylinder-spec", cont.GetGasCylinderSpecPage)
 	}
 }

+ 86 - 0
app/admin/service/applet_customer.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"gas-cylinder-api/app/admin/model"
 	"gas-cylinder-api/app/admin/service/dto"
+	"gas-cylinder-api/common/global"
 	"gas-cylinder-api/common/middleware/handler"
 	model2 "gas-cylinder-api/common/model"
 	"gas-cylinder-api/conf"
@@ -131,6 +132,46 @@ func (e *AppletCustomer) Login(c *dto.AppletCustomerLoginReq) (token, expiresAt
 	return token, expiresAt, nil
 
 }
+
+//	func (e *AppletCustomer) Refresh(oldToken string) (token, expiresAt string, err error) {
+//		var data model.Customer
+//
+//		err = e.Orm.Where("principal_phone = ? and dept_id = -1", c.Phone).First(&data).Error
+//		id := data.Id
+//		if err != nil {
+//			if errors.Is(err, gorm.ErrRecordNotFound) {
+//				return token, expiresAt, errors.New("用户名或密码错误")
+//			} else {
+//				return token, expiresAt, err
+//			}
+//		}
+//
+//		if len(c.VerifyCode) > 0 {
+//			code, err := sdk.Runtime.GetCacheAdapter().Get(handler.GetVerifyCodeCacheKey(c.Phone))
+//			if err != nil {
+//				e.Log.Errorf("user login error, %s", err.Error())
+//				err = errors.New("验证码已过期")
+//				return token, expiresAt, err
+//			}
+//			if code != c.VerifyCode {
+//				e.Log.Errorf("user login error, %s", "验证码错误")
+//				err = errors.New("验证码错误")
+//				return token, expiresAt, err
+//			}
+//			token, expiresAt, _ = e.GeneratorToken(id)
+//			return token, expiresAt, nil
+//		}
+//
+//		_, err = pkg.CompareHashAndPassword(data.Password, c.Password)
+//		if err != nil {
+//			e.Log.Errorf("user login error, %s", err.Error())
+//			return token, expiresAt, errors.New("用户名或密码错误")
+//		}
+//
+//		token, expiresAt, _ = e.GeneratorToken(id)
+//		return token, expiresAt, nil
+//
+// }
 func (e *AppletCustomer) Register(c *dto.AppletCustomerRegisterReq) (err error) {
 	var data model.Customer
 	code, err := sdk.Runtime.GetCacheAdapter().Get(handler.GetVerifyCodeCacheKey(c.Phone))
@@ -204,3 +245,48 @@ func (e *AppletCustomer) GeneratorToken(customerId string) (string, string, erro
 	tokenStr, err := token.SignedString(model.AppletCustomerSecret)
 	return tokenStr, expiresAt.Format("2006-01-02 15:04:05"), err
 }
+
+// UpdatePwd 修改SysUser对象密码
+func (e *AppletCustomer) UpdatePwd(id string, oldPassword, newPassword string) error {
+	var err error
+
+	if newPassword == "" {
+		return nil
+	}
+	c := &model.Customer{}
+
+	err = e.Orm.Model(c).
+		Select("id", "password").
+		Where("id = ?", id).
+		First(c).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.UpdateNotFoundOrNoPermissionErr
+		}
+		return errors.New("密码修改失败")
+	}
+	var ok bool
+	ok, err = pkg.CompareHashAndPassword(c.Password, oldPassword)
+	if err != nil {
+		e.Log.Errorf("CompareHashAndPassword error, %s", err.Error())
+		return errors.New("密码修改失败")
+	}
+	if !ok {
+		err = errors.New("incorrect Password")
+		e.Log.Warnf("user[%d] %s", id, err.Error())
+		return err
+	}
+	c.Password = newPassword
+	db := e.Orm.Model(c).Where("id = ?", id).
+		Select("Password", "Salt").
+		Updates(c)
+	if err = db.Error; err != nil {
+		if errors.Is(err, model.ErrForbidUpdateSysRole) {
+			return model.ErrForbidUpdateSysRole
+		}
+		e.Log.Errorf("db error: %s", err)
+		return errors.New("密码修改失败")
+	}
+	return nil
+}

+ 62 - 0
app/admin/service/customer.go

@@ -370,3 +370,65 @@ func CustomerCheckDataConsistency(req dto.CustomerInsertReq, customer model.Cust
 	}
 	return flag
 }
+
+// Update 修改Customer对象
+func (e *Customer) AppletUpdate(c *dto.AppletCustomerUpdateReq) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	var CustomerModel = model.Customer{}
+	// 查询客户是否存在
+	err = e.Orm.Where("id = ?", c.GetId()).
+		First(&CustomerModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.UpdateNotFoundOrNoPermissionErr
+		}
+		return global.UpdateFailedErr
+	}
+	// 同步该手机用户在其他公司下的客户信息
+	customerList := make([]model.Customer, 0)
+	// 查询客户是否存在
+	err = tx.Where("id like ?", c.Id+"%").
+		Find(&customerList).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.UpdateFailedErr
+	}
+
+	for _, customer := range customerList {
+		customer.Name = c.Name
+		customer.PrincipalPhone = c.PrincipalPhone
+		customer.Type = c.Type
+		if c.Type == 0 {
+			customer.ShopName = c.Name
+		}
+		if c.Type == 1 {
+			customer.PrincipalName = c.Name
+		}
+		// 检查数据完整性
+		dataIntegrity := CustomerCheckDataIntegrity(customer)
+		if dataIntegrity {
+			// TODO 同步省平台 更新客户信息
+			CustomerModel.IsSyncProv = true
+		}
+		err = tx.Save(&customer).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return global.UpdateFailedErr
+		}
+	}
+
+	c.Id = CustomerModel.Id
+
+	return nil
+}

+ 23 - 15
app/admin/service/dto/address.go

@@ -21,14 +21,16 @@ func (m *AddressGetPageReq) GetNeedSearch() interface{} {
 }
 
 type AddressInsertReq struct {
-	Id         int    `json:"id" comment:"编码" swaggerignore:"true"` // 编码
-	CustomerId string `json:"customerId"  swaggerignore:"true"`     // 客户id
-	Name       string `json:"name"`                                 // 收货人名称
-	Phone      string `json:"phone"`                                // 联系电话
-	City       string `json:"city"`                                 // 所在地市
-	Area       string `json:"area"`                                 // 所属区/县
-	Address    string `json:"address"`                              // 详细地址
-	IsDefault  bool   `json:"isDefault"`                            // 默认地址
+	Id         int     `json:"id" comment:"编码" swaggerignore:"true"` // 编码
+	CustomerId string  `json:"customerId"  swaggerignore:"true"`     // 客户id
+	Name       string  `json:"name"`                                 // 收货人名称
+	Phone      string  `json:"phone"`                                // 联系电话
+	City       string  `json:"city"`                                 // 所在地市
+	Area       string  `json:"area"`                                 // 所属区/县
+	Address    string  `json:"address"`                              // 详细地址
+	IsDefault  bool    `json:"isDefault"`                            // 默认地址
+	Lng        float64 `json:"lng"`                                  // 经度
+	Lat        float64 `json:"lat"`                                  // 纬度
 }
 
 func (s *AddressInsertReq) Generate(m *model.Address) {
@@ -42,6 +44,8 @@ func (s *AddressInsertReq) Generate(m *model.Address) {
 	m.Area = s.Area
 	m.Address = s.Address
 	m.IsDefault = s.IsDefault
+	m.Lng = s.Lng
+	m.Lat = s.Lat
 }
 
 func (e *AddressInsertReq) SetCustomerId(CustomerId string) {
@@ -53,13 +57,15 @@ func (s *AddressInsertReq) GetId() interface{} {
 }
 
 type AddressUpdateReq struct {
-	Id        int    `json:"id" comment:"编码"` // 编码
-	Name      string `json:"name"`            // 收货人名称
-	Phone     string `json:"phone"`           // 联系电话
-	City      string `json:"city"`            // 所在地市
-	Area      string `json:"area"`            // 所属区/县
-	Address   string `json:"address"`         // 详细地址
-	IsDefault bool   `json:"isDefault"`       // 默认地址
+	Id        int     `json:"id" comment:"编码"` // 编码
+	Name      string  `json:"name"`            // 收货人名称
+	Phone     string  `json:"phone"`           // 联系电话
+	City      string  `json:"city"`            // 所在地市
+	Area      string  `json:"area"`            // 所属区/县
+	Address   string  `json:"address"`         // 详细地址
+	IsDefault bool    `json:"isDefault"`       // 默认地址
+	Lng       float64 `json:"lng"`             // 经度
+	Lat       float64 `json:"lat"`             // 纬度
 
 	common.ControlBy `swaggerignore:"true"`
 }
@@ -74,6 +80,8 @@ func (s *AddressUpdateReq) Generate(m *model.Address) {
 	m.Area = s.Area
 	m.Address = s.Address
 	m.IsDefault = s.IsDefault
+	m.Lng = s.Lng
+	m.Lat = s.Lat
 	if s.ControlBy.UpdateBy != 0 {
 		m.UpdateBy = s.UpdateBy
 	}

+ 11 - 0
app/admin/service/dto/customer.go

@@ -151,3 +151,14 @@ type CustomerDeleteReq struct {
 func (s *CustomerDeleteReq) GetId() interface{} {
 	return s.Id
 }
+
+type AppletCustomerUpdateReq struct {
+	Id             string `json:"id" swaggerignore:"true"`                    // 主键ID
+	Name           string `json:"name" vd:"len($)>0;msg:'姓名不能为空'"`            // 名字
+	PrincipalPhone string `json:"principalPhone"  vd:"len($)>0;msg:'电话不能为空'"` // 负责人电话
+	Type           int    `json:"type"`                                       // 类型 0-商户 1-私人
+}
+
+func (s *AppletCustomerUpdateReq) GetId() interface{} {
+	return s.Id
+}

+ 11 - 0
app/admin/service/dto/gas_cylinder_spec.go

@@ -89,3 +89,14 @@ type GasCylinderSpecDeleteReq struct {
 func (s *GasCylinderSpecDeleteReq) GetId() interface{} {
 	return s.Id
 }
+
+type AppletGasCylinderSpecGetPageReq struct {
+	dto.Pagination `search:"-"`
+	StoreId        int    `form:"storeId" search:"type:exact;column:dept_id;table:gas_cylinder_spec"`
+	Name           string `form:"name" search:"type:contains;column:name;table:gas_cylinder_spec"` // 商品名称
+	GasCylinderSpecOrder
+}
+
+func (m *AppletGasCylinderSpecGetPageReq) GetNeedSearch() interface{} {
+	return *m
+}

+ 13 - 0
app/admin/service/dto/goods.go

@@ -115,3 +115,16 @@ type GoodsDeleteReq struct {
 func (s *GoodsDeleteReq) GetId() interface{} {
 	return s.Id
 }
+
+type AppletGoodsGetPageReq struct {
+	dto.Pagination `search:"-"`
+	StoreId        int    `form:"storeId" search:"type:exact;column:dept_id;table:goods"`
+	Name           string `form:"name" search:"type:contains;column:name;table:goods"`            // 商品名称
+	MediaType      string `form:"mediaType" search:"type:contains;column:media_type;table:goods"` // 介质类型
+	IsShow         int    `form:"isShow" search:"-"`                                              // 是否展示 1-展示 2-不展示
+	GoodsOrder
+}
+
+func (m *AppletGoodsGetPageReq) GetNeedSearch() interface{} {
+	return *m
+}

+ 34 - 0
app/admin/service/dto/order.go

@@ -150,6 +150,20 @@ type OrderUpdateReq struct {
 	Remark           string `json:"remark"`
 	common.ControlBy `swaggerignore:"true"`
 }
+type OrderAppletUpdateReq struct {
+	Id               int     `json:"id" comment:"编码" swaggerignore:"true"` // 编码
+	Address          string  `json:"address"`                              // 顾客地址
+	Lng              float64 `json:"lng"`                                  // 经度
+	Lat              float64 `json:"lat"`                                  // 纬度
+	City             string  `json:"city"`                                 // 所在地市
+	Area             string  `json:"area"`                                 // 所属区/县
+	Phone            string  `json:"Phone"`                                // 顾客电话
+	GoodsId          int     `json:"goodsId"`                              // 商品id
+	SpecId           int     `json:"specId"`                               // 规格id
+	Quantity         int     `json:"quantity"`                             // 数量
+	Remark           string  `json:"remark"`
+	common.ControlBy `swaggerignore:"true"`
+}
 
 func (s *OrderUpdateReq) Generate(order *model.Order) {
 	if s.Id != 0 {
@@ -170,10 +184,30 @@ func (s *OrderUpdateReq) Generate(order *model.Order) {
 		order.CreateBy = s.CreateBy
 	}
 }
+func (s *OrderAppletUpdateReq) Generate(order *model.Order) {
+	if s.Id != 0 {
+		order.Id = s.Id
+	}
+	order.Address = s.Address
+	order.Phone = s.Phone
+	order.GoodsId = s.GoodsId
+	order.SpecId = s.SpecId
+	order.Quantity = s.Quantity
+	order.Remark = s.Remark
+	if s.ControlBy.UpdateBy != 0 {
+		order.UpdateBy = s.UpdateBy
+	}
+	if s.ControlBy.CreateBy != 0 {
+		order.CreateBy = s.CreateBy
+	}
+}
 
 func (s *OrderUpdateReq) GetId() interface{} {
 	return s.Id
 }
+func (s *OrderAppletUpdateReq) GetId() interface{} {
+	return s.Id
+}
 
 type OrderGetReq struct {
 	Id int `uri:"id"`

+ 19 - 0
app/admin/service/gas_cylinder_spec.go

@@ -153,3 +153,22 @@ func (e *GasCylinderSpec) Remove(c *dto.GasCylinderSpecDeleteReq, p *actions.Dat
 
 	return nil
 }
+
+// GetAppletPage 获取GasCylinderSpec列表
+func (e *GasCylinderSpec) GetAppletPage(c *dto.AppletGasCylinderSpecGetPageReq, list *[]model.GasCylinderSpec, count *int64) error {
+	var err error
+	var data model.GasCylinderSpec
+
+	err = e.Orm.Model(&data).
+		Scopes(
+			cDto.MakeCondition(c.GetNeedSearch()),
+			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
+		).
+		Find(list).Limit(-1).Offset(-1).
+		Count(count).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.GetFailedErr
+	}
+	return nil
+}

+ 19 - 0
app/admin/service/goods.go

@@ -167,3 +167,22 @@ func (e *Goods) Remove(c *dto.GoodsDeleteReq, p *actions.DataPermission) error {
 
 	return nil
 }
+
+func (e *Goods) GetAppletPage(c *dto.AppletGoodsGetPageReq, list *[]model.Goods, count *int64) error {
+	var err error
+	var data model.Goods
+
+	err = e.Orm.Model(&data).
+		Scopes(
+			cDto.MakeCondition(c.GetNeedSearch()),
+			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
+			GoodsStationIdScopes(c.IsShow),
+		).
+		Find(list).Limit(-1).Offset(-1).
+		Count(count).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.GetFailedErr
+	}
+	return nil
+}

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

@@ -160,18 +160,15 @@ func (e *Order) AppletInsert(c *dto.OrderAppletInsertReq) error {
 					DeptId: c.StoreId,
 				},
 			}
-			obj.IsSyncProv = true // TODO
+			dataIntegrity := CustomerCheckDataIntegrity(obj)
+			if dataIntegrity {
+				obj.IsSyncProv = true
+			}
 			err = tx.Create(&obj).Error
 			if err != nil {
 				e.Log.Errorf("db error: %s", err)
 				return global.CreateFailedErr
 			}
-			c.Id = data.Id
-
-			dataIntegrity := CustomerCheckDataIntegrity(obj)
-			if dataIntegrity {
-				obj.IsSyncProv = true
-			}
 		} else {
 			return global.CreateFailedErr
 		}
@@ -183,7 +180,7 @@ func (e *Order) AppletInsert(c *dto.OrderAppletInsertReq) error {
 		storeCustomer.City = c.City
 		storeCustomer.Area = c.Area
 		storeCustomer.Address = c.Address
-		err = tx.Save(&data).Error
+		err = tx.Save(&storeCustomer).Error
 		dataIntegrity := CustomerCheckDataIntegrity(storeCustomer)
 		if dataIntegrity {
 			storeCustomer.IsSyncProv = true
@@ -246,6 +243,58 @@ func (e *Order) Update(c *dto.OrderUpdateReq, p *actions.DataPermission) error {
 
 	return nil
 }
+func (e *Order) AppletUpdate(c *dto.OrderAppletUpdateReq) error {
+	var err error
+
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	var orderModel = model.Order{}
+	// 查询订单是否存在
+	err = e.Orm.First(&orderModel, 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 orderModel.Address != c.Address {
+		// TODO 同步省平台 修改用户信息
+		err = tx.Model(&model.Customer{}).Where("id = ?", orderModel.CustomerId).Updates(
+			map[string]interface{}{
+				"area":    c.Area,
+				"city":    c.City,
+				"address": c.Address,
+			}).Error
+		if err != nil {
+			return global.UpdateFailedErr
+		}
+	}
+
+	// 订单为未派送才可以修改
+	if orderModel.State != model.OrderStateOrder {
+		return errors.New(fmt.Sprintf("订单状态为%s状态,无法修改", model.OrderStateMap[orderModel.State]))
+	}
+	c.Generate(&orderModel)
+	err = tx.Save(&orderModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.UpdateFailedErr
+	}
+
+	c.Id = orderModel.Id
+
+	return nil
+}
 
 // Remove 删除Order
 func (e *Order) Remove(c *dto.OrderDeleteReq, p *actions.DataPermission) error {
@@ -317,7 +366,7 @@ func (e *Order) Cancel(c *dto.OrderCancelReq, p *actions.DataPermission) error {
 		return nil
 	}
 
-	if orderModel.State != model.OrderStateOrder {
+	if orderModel.State != model.OrderStateOrder && orderModel.State != model.OrderStateDelivery {
 		return errors.New(fmt.Sprintf("订单状态为%s,禁止取消", model.OrderStateMap[orderModel.State]))
 	}