123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package score
- import (
- "errors"
- "fmt"
- "time"
- "zhiyuan/pkg/db"
- "zhiyuan/services/dept"
- "github.com/gin-gonic/gin"
- )
- type ScoreOrder struct {
- ID int64 `json:"id" prop:"add:false"`
- ScoreId int64 `json:"scoreId" label:"类型" type:"int" prop:"add" search:"="`
- ItemId int64 `json:"itemId" label:"类型" type:"int" prop:"add" search:"="`
- AdminId int64 `json:"adminId" label:"类型" type:"int" prop:"add:false" search:"="`
- Score int64 `json:"score" label:"名称" type:"int" prop:"add edit"`
- DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
- CreatedAt int64 `json:"created_at" prop:"add:false"`
- UpdatedAt int64 `json:"updated_at" prop:"add:false"`
- db.BaseModel
- }
- func (ScoreOrder) TableName() string {
- return "zy_score_order"
- }
- func (model ScoreOrder) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- return true
- }
- func (ScoreOrder) OnePrivilege(c *gin.Context, id int64) bool {
- return true
- }
- func (ScoreOrder) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
- itemId, _ := db.ToInt64(data["itemId"])
- var item ScoreItem
- db.GetModel(map[string]interface{}{
- "id": itemId,
- "deleted_at": 0,
- }, &item)
- if item.ID == 0 {
- return errors.New("没有权限")
- }
- var score Score
- db.GetModel(map[string]interface{}{
- "id": item.ScoreId,
- "deleted_at": 0,
- }, &score)
- if score.ID == 0 {
- return errors.New("没有权限")
- }
- now := time.Now().Unix()
- if now < score.StartTime || now >= score.EndTime {
- return errors.New("没有权限")
- }
- var order ScoreOrder
- db.GetModel(map[string]interface{}{
- "itemId": itemId,
- "adminId": c.GetInt("adminID"),
- "deleted_at": 0,
- }, &order)
- if order.ID != 0 {
- return errors.New("没有权限")
- }
- data["adminId"] = c.GetInt("adminID")
- return nil
- }
- func (ScoreOrder) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
- var order ScoreOrder
- db.GetModel(map[string]interface{}{
- "id": id,
- "deleted_at": 0,
- }, &order)
- if order.ID == 0 {
- return errors.New("没有权限")
- }
- if int(order.AdminId) != c.GetInt("adminID") {
- return errors.New("没有权限")
- }
- var item ScoreItem
- db.GetModel(map[string]interface{}{
- "id": order.ItemId,
- "deleted_at": 0,
- }, &item)
- if item.ID == 0 {
- return errors.New("没有权限")
- }
- var score Score
- db.GetModel(map[string]interface{}{
- "id": item.ScoreId,
- "deleted_at": 0,
- }, &score)
- if score.ID == 0 {
- return errors.New("没有权限")
- }
- now := time.Now().Unix()
- if now < score.StartTime || now >= score.EndTime {
- return errors.New("没有权限")
- }
- return nil
- }
- func (ScoreOrder) DelPrivilege(c *gin.Context, id int64) error {
- return nil
- }
- func (ScoreOrder) Page() bool {
- return false
- }
- func (ScoreOrder) Count() bool {
- return true
- }
- func (model ScoreOrder) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- return []db.JoinModel{}
- }
- type JoinAdmin struct {
- db.BaseModel
- }
- func (JoinAdmin) TableName() string {
- return "zy_admin"
- }
- type ScoreOrderMobile struct {
- Username string `json:"username" type:"string" prop:"select:admin.username"`
- Phone string `json:"phone" type:"string" prop:"select:admin.phone"`
- DeptId int64 `json:"dept_id" type:"int" prop:"select:admin.dept_id"`
- Name string `json:"name" type:"string" prop:"select:item.name"`
- ScoreOrder
- }
- func (model ScoreOrderMobile) ListAfter(c *gin.Context, data map[string]interface{}, list []map[string]interface{}) []map[string]interface{} {
- for i, v := range list {
- dept_id, _ := db.ToInt64(v["dept_id"])
- list[i]["dept_name"] = dept.GetDeptFullName(int(dept_id), "-")
- }
- return list
- }
- func (model ScoreOrderMobile) GroupBy() string {
- return fmt.Sprintf("`%s`.`adminId`,`%s`.`itemId`", model.TableName(), model.TableName())
- }
- func (model ScoreOrderMobile) OrderBy() string {
- return fmt.Sprintf("`%s`.`updated_at` desc", model.TableName())
- }
- func (model ScoreOrderMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- return append(model.ScoreOrder.LeftJoin(data, s),
- db.JoinModel{
- Model: JoinAdmin{},
- As: "admin",
- On: []string{"`admin`.`id` = " + model.TableName() + ".`adminId`"},
- },
- db.JoinModel{
- Model: ScoreItem{},
- As: "item",
- On: []string{"`item`.`id` = " + model.TableName() + ".`itemId`"},
- })
- }
|