Commit 7c8e65bf by keith

UPDATE

parent babaca33
Showing with 304 additions and 48 deletions
......@@ -59,7 +59,7 @@ func (c *BaseController) GetUserInfo() *models.User {
var userRepository = services.GetUserRepositoryInstance()
user := userRepository.GetUserWithToken(token)
if user == nil {
logs.Warn("GetAdminAuthInfo fun error------------登录已失效!")
logs.Warn("GetUserInfo get current user info error------------登录已失效!")
}
return user
}
......@@ -30,7 +30,7 @@ func (c *CompanyController) Finish() {}
// Get get conpany info
func (c *CompanyController) Get() {
company := c.CompanyRepository.GetCompany(1)
company := c.CompanyRepository.GetCompany()
if company == nil {
c.JSON(configs.ResponseFail, "fail", nil)
}
......@@ -62,7 +62,7 @@ func (c *CompanyController) Put() {
}
// orm
row, err := c.CompanyRepository.Update(1, orm.Params{
row, err := c.CompanyRepository.Update(orm.Params{
"Title": company.Title,
"Address": company.Address,
"Email": company.Email,
......
......@@ -121,6 +121,7 @@ func (c *PublicController) Register() {
// update userinfo
c.UserRepository.Update(user.ID, orm.Params{
"Online": 1,
"RemoteAddr": currentRemoteAddr,
"Address": sessionRequestDto.Address,
"Platform": sessionRequestDto.Platform,
"LastActivity": time.Now().Unix(),
......@@ -203,7 +204,7 @@ func (c *PublicController) Read() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseSucess, "查询成功!", 0)
c.JSON(configs.ResponseFail, "查询失败!", 0)
}
readCount, err := c.MessageRepository.GetReadCount(user.ID)
......@@ -220,7 +221,7 @@ func (c *PublicController) Window() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseSucess, "更新成功!", "")
c.JSON(configs.ResponseFail, "更新失败!", "")
}
type WindowType struct {
......@@ -248,7 +249,7 @@ func (c *PublicController) CleanRead() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseSucess, "清除成功!", "")
c.JSON(configs.ResponseFail, "清除失败!", "")
}
// clear
......@@ -263,6 +264,12 @@ func (c *PublicController) CleanRead() {
// Robot get robot
func (c *PublicController) Robot() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseFail, "fail!", "")
}
// request body
pid, _ := strconv.ParseInt(c.Ctx.Input.Param(":platform"), 10, 64)
......@@ -279,6 +286,16 @@ func (c *PublicController) Robot() {
// RobotInfo get robot info
func (c *PublicController) RobotInfo() {
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "fail,!", nil)
}
}
id, _ := strconv.ParseInt(c.Ctx.Input.Param(":id"), 10, 64)
// request
......@@ -301,6 +318,16 @@ type UploadSecretMode struct {
// UploadSecret update Secret
func (c *PublicController) UploadSecret() {
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "fail!", nil)
}
}
// system info
system := services.GetSystemRepositoryInstance().GetSystem()
......@@ -364,9 +391,19 @@ func (c *PublicController) LastActivity() {
// GetCompanyInfo get Company info
func (c *PublicController) GetCompanyInfo() {
// system info
system := services.GetSystemRepositoryInstance().GetSystem()
c.JSON(configs.ResponseSucess, "上报成功!", &system)
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "fail!", nil)
}
}
// company info
company := services.GetCompanyRepositoryInstance().GetCompany()
c.JSON(configs.ResponseSucess, "查询成功!", &company)
}
......@@ -411,6 +448,16 @@ func (c *PublicController) PushMessage() {
// Upload upload image
func (c *PublicController) Upload() {
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "上传失败,无权限上传!", nil)
}
}
f, h, er := c.GetFile("file")
fileName := c.GetString("file_name")
if er != nil {
......@@ -525,7 +572,7 @@ func (c *PublicController) CreateWorkOrder() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseFail, "工单创建失败!", "")
c.JSON(configs.ResponseFail, "工单创建失败,请刷新重试!", "")
}
workOrder := models.WorkOrder{}
......@@ -535,17 +582,24 @@ func (c *PublicController) CreateWorkOrder() {
// validation
valid := validation.Validation{}
valid.Required(workOrder.TID, "tid").Message("tid不能为空!")
valid.Required(workOrder.UID, "uid").Message("account不能为空!")
valid.Required(workOrder.Phone, "phone").Message("page_size不能为空!")
valid.Email(workOrder.Email, "email").Message("email格式不正确!")
valid.Required(workOrder.Content, "content").Message("content不能为空!")
valid.Required(workOrder.TID, "tid").Message("工单类型不能为空!")
valid.Required(workOrder.Title, "title").Message("工单名称不能为空!")
valid.MaxSize(workOrder.Title, 100, "title").Message("工单名称不能大于100个字符!")
valid.Required(workOrder.Phone, "phone").Message("手机号不能为空!")
valid.Phone(workOrder.Phone, "phone").Message("手机号格式不正确!")
if workOrder.Email != "" {
valid.Email(workOrder.Email, "email").Message("邮箱格式不正确!")
}
valid.Required(workOrder.Content, "content").Message("工单内容不能为空!")
valid.MinSize(workOrder.Content, 10, "content").Message("工单内容不能小于10个字符!")
valid.MaxSize(workOrder.Content, 2000, "content").Message("工单内容不能大于2000个字符!")
if valid.HasErrors() {
for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, nil)
}
}
workOrder.CreateAt = time.Now().Unix()
workOrder.UID = user.ID
workOrderRepository := services.GetWorkOrderRepositoryInstance()
wid, err := workOrderRepository.Add(workOrder)
if err != nil {
......@@ -558,4 +612,169 @@ func (c *PublicController) CreateWorkOrder() {
// ReplyWorkOrder send word order
func (c *PublicController) ReplyWorkOrder() {
// request ctx
workOrderComment := models.WorkOrderComment{}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &workOrderComment); err != nil {
c.JSON(configs.ResponseFail, "参数有误,请检查!", nil)
}
// is user ?
isUser := true
// get user
user := c.GetUserInfo()
if user == nil {
isUser = false
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "发送失败!", nil)
}
workOrderComment.AID = auth.UID
}
// validation
valid := validation.Validation{}
valid.Required(workOrderComment.WID, "wid").Message("工单ID不能为空!")
valid.Required(workOrderComment.Content, "content").Message("工单ID不能为空!")
valid.Required(workOrderComment.Content, "content").Message("内容不能为空!")
valid.MaxSize(workOrderComment.Content, 2000, "content").Message("工单内容不能大于2000个字符!")
if valid.HasErrors() {
for _, err := range valid.Errors {
c.JSON(configs.ResponseFail, err.Message, nil)
}
}
// workorder exist
workOrderRepository := services.GetWorkOrderRepositoryInstance()
if _, err := workOrderRepository.GetWorkOrder(workOrderComment.WID); err != nil {
c.JSON(configs.ResponseFail, "发送失败,工单不存在!", nil)
}
// add
workOrderCommentRepository := services.GetWorkOrderCommentRepositoryInstance()
if _, err := workOrderCommentRepository.Add(workOrderComment); err != nil {
c.JSON(configs.ResponseFail, "发送失败!", nil)
}
// update WorkOrder params
var params = orm.Params{}
// change status
status := 2
if !isUser {
status = 1
params["LastReply"] = workOrderComment.AID
}
params["Status"] = status
if _, err := workOrderRepository.Update(workOrderComment.WID, params); err != nil {
c.JSON(configs.ResponseFail, "发送失败!", nil)
}
c.JSON(configs.ResponseSucess, "发送成功!", nil)
}
// GetWorkOrders user get word order all
func (c *PublicController) GetWorkOrders() {
// get user
user := c.GetUserInfo()
if user == nil {
c.JSON(configs.ResponseFail, "查询失败!", nil)
}
workOrderRepository := services.GetWorkOrderRepositoryInstance()
workOrders, err := workOrderRepository.GetUserWorkOrders(user.ID)
if err != nil {
c.JSON(configs.ResponseFail, "查询失败!", nil)
}
c.JSON(configs.ResponseSucess, "查询成功!", &workOrders)
}
// GetWorkOrderComments get word order comments
func (c *PublicController) GetWorkOrderComments() {
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "fail!", nil)
}
}
// wid
wid, _ := strconv.ParseInt(c.Ctx.Input.Param(":wid"), 10, 64)
workOrderCommentRepository := services.GetWorkOrderCommentRepositoryInstance()
workOrderComments, err := workOrderCommentRepository.GetWorkOrderComments(wid)
if err != nil {
c.JSON(configs.ResponseFail, "查询失败!", nil)
}
c.JSON(configs.ResponseSucess, "查询成功!", &workOrderComments)
}
// GetWorkOrder user get word order content
func (c *PublicController) GetWorkOrder() {
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "fail!", nil)
}
}
// wid
wid, _ := strconv.ParseInt(c.Ctx.Input.Param(":wid"), 10, 64)
workOrderRepository := services.GetWorkOrderRepositoryInstance()
workOrder, err := workOrderRepository.GetWorkOrder(wid)
if err != nil {
c.JSON(configs.ResponseFail, "查询失败,工单不存在!", nil)
}
if user != nil && user.ID != workOrder.UID {
c.JSON(configs.ResponseFail, "查询失败,工单不存在!", nil)
}
c.JSON(configs.ResponseSucess, "查询成功!", &workOrder)
}
// DeleteWorkOrder user delete word order
func (c *PublicController) DeleteWorkOrder() {
// get user
user := c.GetUserInfo()
if user == nil {
// GetAdminAuthInfo
auth := c.GetAdminAuthInfo()
if auth == nil {
c.JSON(configs.ResponseFail, "fail!", nil)
}
}
// wid
wid, _ := strconv.ParseInt(c.Ctx.Input.Param(":wid"), 10, 64)
workOrderRepository := services.GetWorkOrderRepositoryInstance()
workOrder, err := workOrderRepository.GetWorkOrder(wid)
if err != nil {
c.JSON(configs.ResponseFail, "查询失败,工单不存在!", nil)
}
if user != nil && user.ID != workOrder.UID {
c.JSON(configs.ResponseFail, "删除失败,工单不存在!", nil)
}
if workOrder.Status != 3 {
c.JSON(configs.ResponseFail, "删除失败,工单未结单不能删除!", nil)
}
if _, err := workOrderRepository.Update(wid, orm.Params{"Delete": 1}); err != nil {
c.JSON(configs.ResponseFail, "删除失败,工单不存在!", nil)
}
c.JSON(configs.ResponseSucess, "删除成功!", nil)
}
......@@ -5,14 +5,12 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/toolbox"
_ "github.com/go-sql-driver/mysql"
"kefu_server/controllers"
"kefu_server/db"
"kefu_server/grpcs"
_ "kefu_server/routers"
"kefu_server/task"
)
// Initialization log
......@@ -39,9 +37,9 @@ func main() {
initLog()
// init task
task.Run()
toolbox.StartTask()
defer toolbox.StopTask()
// task.Run()
// toolbox.StartTask()
// defer toolbox.StopTask()
/// Static file configuration
beego.SetStaticPath("/", "public/client")
......
......@@ -5,13 +5,16 @@ type WorkOrder struct {
ID int64 `orm:"auto;pk;type(bigint);column(id)" json:"id"` // ID
UID int64 `orm:"type(bigint);column(uid)" json:"uid"` // 用户ID
TID int64 `orm:"type(bigint);column(tid))" json:"tid"` // 工单类型ID
Title string `orm:"column(title)" json:"title"` // 工单标题
Content string `orm:"type(text);column(content)" json:"content"` // 内容
Phone string `orm:"type(char);null;column(phone)" json:"phone"` // 用户联系电话
Email string `orm:"type(varchar);null;column(email)" json:"email"` // 邮箱(可用于客服回复后发提醒邮件给客户)
Status int `orm:"default(0);column(status)" json:"status"` // 当前状态 ( 0=待处理 | 1=客服已回复 | 2=客户已回复 | 3=已结单 )
LastReply int64 `orm:"type(bigint);column(last_reply))" json:"last_reply"` // 最后回复的客服ID
CID int64 `orm:"type(bigint);column(cid))" json:"cid"` // 结单客服ID
CloseAt int64 `orm:"type(bigint);column(close_at)" json:"close_at"` // 结单时间
Comment string `orm:"type(text);column(comment)" json:"comment"` // 结单原因
Content string // 内容(不实际存储)
Remark string `orm:"column(remark)" json:"remark"` // 结单原因
UpdateAt int64 `orm:"type(bigint);column(update_at)" json:"update_at"` // 更新时间
Delete int `orm:"default(0);column(delete)" json:"delete"` // 是否已删除 0 未删除, 1已删除 (未结单状态不能删除)
CreateAt int64 `orm:"type(bigint);column(create_at)" json:"create_at"` // 提交时间
}
File mode changed
No preview for this file type
No preview for this file type
No preview for this file type

4.35 KB | W: | H:

4.35 KB | W: | H:

public/admin/img/kefu_logo.9c308a55.png
public/admin/img/kefu_logo.9c308a55.png
public/admin/img/kefu_logo.9c308a55.png
public/admin/img/kefu_logo.9c308a55.png
  • 2-up
  • Swipe
  • Onion skin

237 KB | W: | H:

237 KB | W: | H:

public/admin/img/login_bg.8ba760be.jpg
public/admin/img/login_bg.8ba760be.jpg
public/admin/img/login_bg.8ba760be.jpg
public/admin/img/login_bg.8ba760be.jpg
  • 2-up
  • Swipe
  • Onion skin

23.4 KB | W: | H:

23.4 KB | W: | H:

public/admin/img/login_bg1.531e0c1c.jpg
public/admin/img/login_bg1.531e0c1c.jpg
public/admin/img/login_bg1.531e0c1c.jpg
public/admin/img/login_bg1.531e0c1c.jpg
  • 2-up
  • Swipe
  • Onion skin
File mode changed
File mode changed
File mode changed
File mode changed
No preview for this file type

8.64 KB | W: | H:

8.64 KB | W: | H:

public/client/img/expression.73c98a16.png
public/client/img/expression.73c98a16.png
public/client/img/expression.73c98a16.png
public/client/img/expression.73c98a16.png
  • 2-up
  • Swipe
  • Onion skin

5.59 KB | W: | H:

5.59 KB | W: | H:

public/client/img/photo_btn.c337b681.png
public/client/img/photo_btn.c337b681.png
public/client/img/photo_btn.c337b681.png
public/client/img/photo_btn.c337b681.png
  • 2-up
  • Swipe
  • Onion skin
File mode changed
File mode changed
......@@ -50,6 +50,10 @@ func init() {
beego.NSRouter("/message/cancel", &controllers.PublicController{}, "post:CancelMessage"),
beego.NSRouter("/workorder/create", &controllers.PublicController{}, "post:CreateWorkOrder"),
beego.NSRouter("/workorder/reply", &controllers.PublicController{}, "post:ReplyWorkOrder"),
beego.NSRouter("/workorders", &controllers.PublicController{}, "get:GetWorkOrders"),
beego.NSRouter("/workorder/comments/:wid", &controllers.PublicController{}, "get:GetWorkOrderComments"),
beego.NSRouter("/workorder/:wid", &controllers.PublicController{}, "get:GetWorkOrder"),
beego.NSRouter("/workorder/:wid", &controllers.PublicController{}, "delete:DeleteWorkOrder"),
),
// knowledge_base
......
......@@ -9,7 +9,7 @@ import (
// CompanyRepositoryInterface interface
type CompanyRepositoryInterface interface {
GetCompany(id int64) *models.Company
GetCompany() *models.Company
Update(id int64, params *orm.Params) (int64, error)
}
......@@ -26,9 +26,9 @@ func GetCompanyRepositoryInstance() *CompanyRepository {
}
// GetCompany get one company
func (r *CompanyRepository) GetCompany(id int64) *models.Company {
func (r *CompanyRepository) GetCompany() *models.Company {
var company models.Company
if err := r.q.Filter("id", id).One(&company); err != nil {
if err := r.q.Filter("id", 1).One(&company); err != nil {
logs.Warn("GetCompany get one company------------", err)
return nil
}
......@@ -36,8 +36,8 @@ func (r *CompanyRepository) GetCompany(id int64) *models.Company {
}
// Update company
func (r *CompanyRepository) Update(id int64, params orm.Params) (int64, error) {
index, err := r.q.Filter("id", id).Update(params)
func (r *CompanyRepository) Update(params orm.Params) (int64, error) {
index, err := r.q.Filter("id", 1).Update(params)
if err != nil {
logs.Warn("Update company------------", err)
}
......
......@@ -2,14 +2,14 @@ package services
import (
"kefu_server/models"
"time"
"github.com/astaxie/beego/logs"
)
// WorkOrderCommentRepositoryInterface interface
type WorkOrderCommentRepositoryInterface interface {
GetWorkOrder() *models.WorkOrderComment
DeleteAll(wid int64) (int64, error)
GetWorkOrderComments(wid int64) ([]models.WorkOrderComment, error)
Add(workOrderComment models.WorkOrderComment) (int64, error)
}
......@@ -25,20 +25,22 @@ func GetWorkOrderCommentRepositoryInstance() *WorkOrderCommentRepository {
return instance
}
// Add add WorkOrderComment
func (r *WorkOrderCommentRepository) Add(workOrderComment models.WorkOrderComment) (int64, error) {
index, err := r.o.Insert(workOrderComment)
// GetWorkOrderComments get WorkOrderComments
func (r *WorkOrderCommentRepository) GetWorkOrderComments(wid int64) ([]models.WorkOrderComment, error) {
var workOrderComments []models.WorkOrderComment
_, err := r.q.Filter("wid", wid).OrderBy("id").All(&workOrderComments)
if err != nil {
logs.Warn(" Add add WorkOrderComment------------", err)
logs.Warn("GetWorkOrderComments get WorkOrderComments-----------", err)
}
return index, err
return workOrderComments, err
}
// DeleteAll delete all WorkOrderComment
func (r *WorkOrderCommentRepository) DeleteAll(wid int64) (int64, error) {
index, err := r.q.Filter("wid", wid).Delete()
// Add add WorkOrderComment
func (r *WorkOrderCommentRepository) Add(workOrderComment models.WorkOrderComment) (int64, error) {
workOrderComment.CreateAt = time.Now().Unix()
index, err := r.o.Insert(&workOrderComment)
if err != nil {
logs.Warn(" DeleteAll delete all WorkOrderComment------------", err)
logs.Warn(" Add add WorkOrderComment------------", err)
}
return index, err
}
......@@ -10,10 +10,12 @@ import (
// WorkOrderRepositoryInterface interface
type WorkOrderRepositoryInterface interface {
GetWorkOrder() models.WorkOrder
GetWorkOrder(id int64) (models.WorkOrder, error)
GetUserWorkOrders(uid int64) ([]models.WorkOrder, error)
Update(id int64, params *orm.Params) (int64, error)
Add(workOrder models.WorkOrder) (int64, error)
Delete(id int64) (int64, error)
Close(id int64) (int64, error)
}
// WorkOrderRepository struct
......@@ -30,26 +32,53 @@ func GetWorkOrderRepositoryInstance() *WorkOrderRepository {
return instance
}
// Delete delete WorkOrder
func (r *WorkOrderRepository) Delete(id int64) (int64, error) {
index, err := r.q.Filter("id", id).Delete()
// Close close WorkOrder
func (r *WorkOrderRepository) Close(id int64) (int64, error) {
row, err := r.q.Filter("id", id).Update(orm.Params{
"Status": 3,
})
if err != nil {
logs.Warn("Close close WorkOrder-----------", err)
}
return row, err
}
// GetUserWorkOrders get user WorkOrders
func (r *WorkOrderRepository) GetUserWorkOrders(uid int64) ([]models.WorkOrder, error) {
var workOrders []models.WorkOrder
_, err := r.q.Filter("uid", uid).Filter("delete", 0).OrderBy("-id").All(&workOrders)
if err != nil {
logs.Warn("Delete delete WorkOrder------------", err)
logs.Warn("GetUserWorkOrders get user WorkOrders------------", err)
}
if index > 0 {
_, err := r.WorkOrderCommentRepository.DeleteAll(id)
return workOrders, err
}
// GetWorkOrder get WorkOrder
func (r *WorkOrderRepository) GetWorkOrder(id int64) (models.WorkOrder, error) {
var workOrder models.WorkOrder
err := r.q.Filter("id", id).One(&workOrder)
if err != nil {
logs.Warn("Delete delete WorkOrder child------------", err)
logs.Warn("GetWorkOrder get WorkOrder------------", err)
}
return workOrder, err
}
// Delete delete WorkOrder
func (r *WorkOrderRepository) Delete(id int64) (int64, error) {
row, err := r.q.Filter("id", id).Update(orm.Params{
"Delete": 1,
})
if err != nil {
logs.Warn("Delete delete WorkOrder-----------", err)
}
return index, err
return row, err
}
// Add add WorkOrder
func (r *WorkOrderRepository) Add(workOrder models.WorkOrder) (int64, error) {
createAt := time.Now().Unix()
workOrder.CreateAt = createAt
wid, err := r.o.Insert(workOrder)
wid, err := r.o.Insert(&workOrder)
if err != nil {
logs.Warn("Add add WorkOrder------------", err)
}
......@@ -65,6 +94,7 @@ func (r *WorkOrderRepository) Add(workOrder models.WorkOrder) (int64, error) {
// Update WorkOrder Info
func (r *WorkOrderRepository) Update(id int64, params orm.Params) (int64, error) {
params["UpdateAt"] = time.Now().Unix()
index, err := r.q.Filter("id", id).Update(params)
if err != nil {
logs.Warn("Update WorkOrder Info------------", err)
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment