Skip to content

Commit

Permalink
merge 20210412_notification_staff_salary_authority_update
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrong committed Apr 27, 2021
1 parent 2e8044d commit 331de23
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion handler/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func Login(c *gin.Context) {
var loginDb model.Authority
var staff model.Staff
hrmsDB.Where("staff_id = ? and user_password = ?",
loginR.UserNo, loginR.UserPassword).First(&loginDb)
loginR.UserNo, service.MD5(loginR.UserPassword)).First(&loginDb)
if loginDb.StaffId != loginR.UserNo {
log.Printf("[handler.Login] user login fail, user = %v", loginR)
c.JSON(200, gin.H{
Expand Down
2 changes: 1 addition & 1 deletion handler/attend.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func GetAttendRecordApproveByLeaderStaffId(c *gin.Context) {
// 审批通过考勤信息
func ApproveAccept(c *gin.Context) {
attendId := c.Param("attendId")
if err := service.ApproveAccept(c, attendId); err != nil {
if err := service.Compute(c, attendId); err != nil {
c.JSON(200, gin.H{
"status": 5000,
"err": err,
Expand Down
2 changes: 1 addition & 1 deletion handler/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func PasswordEdit(c *gin.Context) {
return
}
staffId := passwordEditDTO.StaffId
password := passwordEditDTO.Password
password := service.MD5(passwordEditDTO.Password)
if err := resource.HrmsDB(c).Where("staff_id = ?", staffId).Updates(&model.Authority{
UserPassword: password,
}).Error; err != nil {
Expand Down
6 changes: 3 additions & 3 deletions handler/staff.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func StaffCreate(c *gin.Context) {
login := model.Authority{
AuthorityId: service.RandomID("auth"),
StaffId: staffId,
UserPassword: staff.IdentityNum[identLen-6 : identLen],
Aval: 1,
UserType: "normal", // 暂时只能创建普通员工
UserPassword: service.MD5(staff.IdentityNum[identLen-6 : identLen]),
//Aval: 1,
UserType: "normal", // 暂时只能创建普通员工
}
err := resource.HrmsDB(c).Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&staff).Error; err != nil {
Expand Down
4 changes: 2 additions & 2 deletions model/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Authority struct {
AuthorityId string `gorm:"column:authority_id" json:"authority_id"`
StaffId string `gorm:"column:staff_id" json:"staff_id"`
UserPassword string `gorm:"column:user_password" json:"user_password"`
Aval int64 `gorm:"column:aval" json:"aval"`
UserType string `gorm:"column:user_type" json:"user_type"`
//Aval int64 `gorm:"column:aval" json:"aval"`
UserType string `gorm:"column:user_type" json:"user_type"`
}

type PasswordQueryVO struct {
Expand Down
13 changes: 7 additions & 6 deletions model/model_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package model

import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
httpReq "github.com/kirinlabs/HttpRequest"
Expand Down Expand Up @@ -86,10 +88,9 @@ func TestSMS(t *testing.T) {
}

func TestComputeSalary(t *testing.T) {
leaveDays := 2
var bonus int64 = 500
x := float64(5-leaveDays) / 5.0
bonus = int64(float64(bonus) * x)
fmt.Println(x)
fmt.Println(bonus)
data := []byte("215517test")
md5Ctx := md5.New()
md5Ctx.Write(data)
cipherStr := md5Ctx.Sum(nil)
fmt.Println(hex.EncodeToString(cipherStr))
}
8 changes: 7 additions & 1 deletion service/attend_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func GetAttendRecordApproveByLeaderStaffId(c *gin.Context, leaderStaffId string)
}

// 通过考勤审批信息,修改考勤信息为通过,并且按该员工工资套账进行相应的薪资详情计算,得到五险一金税后薪资
func ApproveAccept(c *gin.Context, attendId string) error {
func Compute(c *gin.Context, attendId string) error {
err := resource.HrmsDB(c).Transaction(func(tx *gorm.DB) error {
// 更新考勤信息为审批通过状态
if err := tx.Model(&model.AttendanceRecord{}).Where("attendance_id = ?", attendId).Update("approve", 1).Error; err != nil {
Expand Down Expand Up @@ -259,11 +259,17 @@ func ApproveAccept(c *gin.Context, attendId string) error {
if err = tx.Create(&salaryRecord).Error; err != nil {
return err
}
// 通过税务系统上报税款并将工资发放至员工银行卡中
payStaffSalaryAndTax(salaryRecord)
return nil
})
return err
}

func payStaffSalaryAndTax(record model.SalaryRecord) {
// 需要对接银行系统及税务系统
}

func getCurMonthWorkdays() float64 {
return 22.25
}
Expand Down
11 changes: 11 additions & 0 deletions service/biz.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package service

import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -120,6 +122,7 @@ func Transfer(from, to interface{}) error {

const SMS_URL = "https://api.apishop.net/communication/sms/send"

// 向指定手机号发放短信通知
func sendNoticeMsg(msgType string, phone int64, content []string) {
if phone == 0 || phone != 15521306934 {
// 给自己手机号发短信验证效果
Expand Down Expand Up @@ -149,3 +152,11 @@ func sendNoticeMsg(msgType string, phone int64, content []string) {
body, _ := resp.Body()
log.Printf("[sendNoticeMsg] resp = %v", string(body))
}

func MD5(input string) string {
data := []byte(input)
md5Ctx := md5.New()
md5Ctx.Write(data)
cipherStr := md5Ctx.Sum(nil)
return hex.EncodeToString(cipherStr)
}
4 changes: 3 additions & 1 deletion views/normal_notification_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
{width: 60, title: '序号', sort: true, type:'numbers'},
{field: 'notice_title', width: 250, title: '通知标题'},
{field: 'type', width: 150, title: '通知类别'},
{field: 'date', width: 170, title: '生效日期'},
{field: 'date', width: 170, title: '生效日期', templet: function(data) {
return data.date.slice(0, 10)
}},
{field: 'notice_content', width: 150, title: '通知内容'},
{title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center", fixed: 'right'}
]],
Expand Down
2 changes: 1 addition & 1 deletion views/staff_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
form.on('submit(saveBtn)', function (req) {
req.field.base_salary = parseInt(req.field.base_salary)
req.field.phone = parseInt(req.field.phone)
alert(JSON.stringify(req.field))
// alert(JSON.stringify(req.field))
$.ajax({
type: "POST",
url: "/staff/create",
Expand Down

0 comments on commit 331de23

Please sign in to comment.