zhou.xiaoning пре 3 година
родитељ
комит
1c9c88121b
9 измењених фајлова са 352 додато и 23 уклоњено
  1. 7 7
      config/config.xml
  2. 0 2
      controllers/ferroalloy/quote.go
  3. 33 0
      controllers/ferroalloy/score.go
  4. 53 6
      docs/docs.go
  5. 53 6
      docs/swagger.json
  6. 33 2
      docs/swagger.yaml
  7. 112 0
      models/ferroalloy.go
  8. 60 0
      models/ori.go
  9. 1 0
      routers/router.go

+ 7 - 7
config/config.xml

@@ -13,11 +13,11 @@
     <DbAddress value="192.168.31.88"/>
     <DbName value="orcl"/>
     <DbPort value="1521"/>
-    <DbUser value="mtp2_test201"/>
+    <DbUser value="mtp2_test167"/>
     <DbPwd value="muchinfo"/>
   </DbSetting>
   <RedisSetting>
-    <Address value="192.168.31.201"/>
+    <Address value="192.168.31.167"/>
     <Port value="5007"/>
     <Timeout value="3"/>
     <ConnNum value="1"/>
@@ -25,11 +25,11 @@
     <Pwd value=""/>
   </RedisSetting>
   <MqSetting>
-    <Url value="amqp://guest:guest@192.168.31.201:5020/test"/>
+    <Url value="amqp://guest:guest@192.168.31.167:5020/test"/>
     <Exchange value="entry"/>
   </MqSetting>
   <MongoDBSetting>
-    <HostName value="192.168.31.201"/>
+    <HostName value="192.168.31.167"/>
     <Port value="5025"/>
     <DBName value="HistoryQuote"/>
     <Username value="quote_test01"/>
@@ -38,8 +38,8 @@
   <MySQLSetting>
     <Host value="192.168.30.72"/>
     <Port value="3306"/>
-    <DBName value="historyquote_test201"/>
-    <Username value="quote_test201"/>
+    <DBName value="historyquote_test167"/>
+    <Username value="quote_test167"/>
     <Password value="123456"/>
   </MySQLSetting>
-</Configuration>
+</Configuration>

+ 0 - 2
controllers/ferroalloy/quote.go

@@ -11,8 +11,6 @@ import (
 // @Summary  获取现货行情
 // @Produce  json
 // @Security ApiKeyAuth
-// @Security LoginID
-// @Security Group
 // @Param    page     query    int false "页码"
 // @Param    pagesize query    int false "每页条数"
 // @Success  200      {array}  models.GErmcpspotgoodsprice

+ 33 - 0
controllers/ferroalloy/score.go

@@ -0,0 +1,33 @@
+package ferroalloy
+
+import (
+	"mtp2_if/global/app"
+	"mtp2_if/global/e"
+	"mtp2_if/logger"
+	"mtp2_if/models"
+	"net/http"
+
+	"github.com/gin-gonic/gin"
+)
+
+// Signin
+// @Summary  用户签到
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param    jsonBody body     models.THJSigninReq true "用户签到请求"
+// @Success  200      {object} app.Response
+// @Failure  500      {object} app.Response
+// @Router   /Ferroalloy/Signin [post]
+// @Tags     铁合金
+func Signin(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	m := models.THJSigninReq{}
+	a.DoBindReq(&m)
+
+	if err := m.Signin(); err == nil {
+		a.Response(http.StatusOK, e.SUCCESS, "OK")
+	} else {
+		logger.GetLogger().Errorf("insert fail, %v", err)
+		a.Response(http.StatusBadRequest, e.ERROR_OPERATION_FAILED, nil)
+	}
+}

+ 53 - 6
docs/docs.go

@@ -7554,12 +7554,6 @@ const docTemplate = `{
                 "security": [
                     {
                         "ApiKeyAuth": []
-                    },
-                    {
-                        "LoginID": []
-                    },
-                    {
-                        "Group": []
                     }
                 ],
                 "produces": [
@@ -7602,6 +7596,47 @@ const docTemplate = `{
                 }
             }
         },
+        "/Ferroalloy/Signin": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "铁合金"
+                ],
+                "summary": "用户签到",
+                "parameters": [
+                    {
+                        "description": "用户签到请求",
+                        "name": "jsonBody",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.THJSigninReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Guangzuan/GZBSFWOrderOperate": {
             "get": {
                 "security": [
@@ -39349,6 +39384,18 @@ const docTemplate = `{
                 }
             }
         },
+        "models.THJSigninReq": {
+            "type": "object",
+            "required": [
+                "userid"
+            ],
+            "properties": {
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Taaccount": {
             "type": "object",
             "required": [

+ 53 - 6
docs/swagger.json

@@ -7545,12 +7545,6 @@
                 "security": [
                     {
                         "ApiKeyAuth": []
-                    },
-                    {
-                        "LoginID": []
-                    },
-                    {
-                        "Group": []
                     }
                 ],
                 "produces": [
@@ -7593,6 +7587,47 @@
                 }
             }
         },
+        "/Ferroalloy/Signin": {
+            "post": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "铁合金"
+                ],
+                "summary": "用户签到",
+                "parameters": [
+                    {
+                        "description": "用户签到请求",
+                        "name": "jsonBody",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/models.THJSigninReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Guangzuan/GZBSFWOrderOperate": {
             "get": {
                 "security": [
@@ -39340,6 +39375,18 @@
                 }
             }
         },
+        "models.THJSigninReq": {
+            "type": "object",
+            "required": [
+                "userid"
+            ],
+            "properties": {
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Taaccount": {
             "type": "object",
             "required": [

+ 33 - 2
docs/swagger.yaml

@@ -16694,6 +16694,14 @@ definitions:
         description: 现货商品名称
         type: string
     type: object
+  models.THJSigninReq:
+    properties:
+      userid:
+        description: 用户ID
+        type: integer
+    required:
+    - userid
+    type: object
   models.Taaccount:
     properties:
       accountflag:
@@ -28201,11 +28209,34 @@ paths:
             $ref: '#/definitions/app.Response'
       security:
       - ApiKeyAuth: []
-      - LoginID: []
-      - Group: []
       summary: 获取现货行情
       tags:
       - 铁合金
+  /Ferroalloy/Signin:
+    post:
+      parameters:
+      - description: 用户签到请求
+        in: body
+        name: jsonBody
+        required: true
+        schema:
+          $ref: '#/definitions/models.THJSigninReq'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/app.Response'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 用户签到
+      tags:
+      - 铁合金
   /Guangzuan/GZBSFWOrderOperate:
     get:
       parameters:

+ 112 - 0
models/ferroalloy.go

@@ -1,9 +1,13 @@
 package models
 
 import (
+	"errors"
 	"fmt"
 	"mtp2_if/db"
+	"mtp2_if/logger"
 	"mtp2_if/utils"
+	"strconv"
+	"sync"
 	"time"
 )
 
@@ -75,3 +79,111 @@ func (r *GErmcpspotgoodsprice) GetDataByPage() (interface{}, error, int, int, in
 	}
 	return sData, err, r.Page, r.PageSize, total
 }
+
+type THJSigninReq struct {
+	USERID int64 `form:"userid" binding:"required"` // 用户ID
+}
+
+// Signin 用户签到
+func (r *THJSigninReq) Signin() (err error) {
+	// 资源锁
+	var lock sync.Mutex
+	lock.Lock()
+	defer lock.Unlock()
+
+	engine := db.GetEngine()
+
+	// 判断目标用户当日是否已经签到
+	p := new(Thjsignin)
+	if has, err := engine.Where("userid = ?", r.USERID).And("tradedate = to_char(sysdate, 'yyyymmdd')").Get(&p); err != nil {
+		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+		err = errors.New("数据错误")
+		return err
+	} else {
+		if has {
+			err = errors.New("当日已签到")
+			return err
+		}
+	}
+
+	// 获取签到积配置
+	c := Thjscoreconfig{
+		SCORECONFIGTYPE: 2,
+	}
+	if has, err := engine.Get(&c); err != nil || !has {
+		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+		err = errors.New("数据错误")
+		return err
+	}
+
+	// 事务
+	session := engine.NewSession()
+	defer session.Close()
+	// add Begin() before any action
+	if err := session.Begin(); err != nil {
+		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+		return errors.New("数据错误")
+	}
+
+	// 判断用户积分表是否已经存在此用户
+	curscore := 0
+	t := Thjuserscore{USERID: r.USERID}
+	has, err := session.Exist(t)
+	if err != nil {
+		session.Rollback()
+		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+		return errors.New("数据错误")
+	}
+	if has {
+		// 更新积分
+		curscore = int(t.CURSCORE)
+		t.CURSCORE += int64(c.PARMA1)
+		t.UPDATETIME = time.Now()
+		_, err = session.Update(&t)
+		if err != nil {
+			session.Rollback()
+			logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+			return errors.New("数据错误")
+		}
+	} else {
+		// 新增用户积分记录
+		t.CURSCORE = int64(c.PARMA1)
+		t.UPDATETIME = time.Now()
+		_, err = session.Insert(&t)
+		if err != nil {
+			session.Rollback()
+			logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+			return errors.New("数据错误")
+		}
+	}
+
+	// 记录积分流水
+	q := Thjuserscorelog{}
+	seqMap, err := session.QueryString("SELECT SEQ_THJ_USERSCORELOG.nextval SEQID FROM dual")
+	if err != nil {
+		session.Rollback()
+		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+		return errors.New("数据错误")
+	}
+	if len(seqMap) <= 0 {
+		session.Rollback()
+		return errors.New("获取自增ID错误")
+	}
+	seqID, _ := strconv.Atoi(seqMap[0]["SEQID"])
+	q.AUTOID = int64(seqID)
+	q.USERID = r.USERID
+	q.SCORECONFIGTYPE = 2 // 2:签到送积分
+	q.SCORE = float64(c.PARMA1)
+	q.ORISCORE = float64(curscore)
+	q.CURSCORE = float64(t.CURSCORE)
+	q.CREATETIME = time.Now()
+	_, err = session.Insert(&q)
+	if err != nil {
+		session.Rollback()
+		logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
+		return errors.New("数据错误")
+	}
+
+	// add Commit() after all actions
+	return session.Commit()
+}

+ 60 - 0
models/ori.go

@@ -198,3 +198,63 @@ type Gzbsfworderoperate struct {
 func (r *Gzbsfworderoperate) TableName() string {
 	return "GZ_BSFWORDEROPERATE"
 }
+
+// Thjsignin 铁合金用户签到表
+type Thjsignin struct {
+	USERID     int64     `json:"userid" xorm:"USERID"`         // 经纪会员用户ID
+	TRADEDATE  string    `json:"tradedate" xorm:"TRADEDATE"`   // 交易日(yyyyMMdd)
+	SIGNINTIME time.Time `json:"signintime" xorm:"SIGNINTIME"` // 签到时间
+}
+
+// TableName is THJ_SIGNIN
+func (r *Thjsignin) TableName() string {
+	return "THJ_SIGNIN"
+}
+
+// Thjscoreconfig 铁合金积分配置表
+type Thjscoreconfig struct {
+	SCORECONFIGTYPE int32 `json:"scoreconfigtype" xorm:"SCORECONFIGTYPE"` // 积分配置类型 - 1:注册送红包 2:签到送积分 3:推广送积分 4:下级用户下单送积分 5:自己采购下单送积分 6:自己供求下单送积分 7:抽奖得红包
+	PARMA1          int32 `json:"parma1" xorm:"PARMA1"`                   // 参数1
+	PARMA2          int32 `json:"parma2" xorm:"PARMA2"`                   // 参数2
+	PARMA3          int32 `json:"parma3" xorm:"PARMA3"`                   // 参数3
+	PARMA4          int32 `json:"parma4" xorm:"PARMA4"`                   // 参数4
+	PARMA5          int32 `json:"parma5" xorm:"PARMA5"`                   // 参数5
+	PARMA6          int32 `json:"parma6" xorm:"PARMA6"`                   // 参数6
+	PARMA7          int32 `json:"parma7" xorm:"PARMA7"`                   // 参数6
+}
+
+// TableName is THJ_SCORECONFIG
+func (r *Thjscoreconfig) TableName() string {
+	return "THJ_SCORECONFIG"
+}
+
+// Thjuserscore 铁合金用户积分表
+type Thjuserscore struct {
+	USERID      int64     `json:"userid" xorm:"USERID"`           // 用户ID
+	CURSCORE    int64     `json:"curscore" xorm:"CURSCORE"`       // 期末积分
+	FREEZESCORE int64     `json:"freezescore" xorm:"FREEZESCORE"` // 冻结积分
+	UPDATETIME  time.Time `json:"updatetime" xorm:"UPDATETIME"`   // 更新时间
+}
+
+// TableName is THJ_USERSCORE
+func (r *Thjuserscore) TableName() string {
+	return "THJ_USERSCORE"
+}
+
+// Thjuserscorelog 铁合金用户积分流水表
+type Thjuserscorelog struct {
+	AUTOID          int64     `json:"autoid" xorm:"AUTOID"`                   // AutoID(SEQ_THJ_USERSCORELOG)
+	USERID          int64     `json:"userid" xorm:"USERID"`                   // 用户ID
+	SCORECONFIGTYPE int32     `json:"scoreconfigtype" xorm:"SCORECONFIGTYPE"` // 配置类型 - 1:注册红包 2:签到积分 3:推广积分 4:下级用户下单积分 5:自己采购下单积分 6:自己供求下单积分 7:抽奖配置
+	SCORE           float64   `json:"score" xorm:"SCORE"`                     // 变动积分
+	ORISCORE        float64   `json:"oriscore" xorm:"ORISCORE"`               // 期初积分(变动前积)
+	CURSCORE        float64   `json:"curscore" xorm:"CURSCORE"`               // 期末积分(变动后积)
+	CREATETIME      time.Time `json:"createtime" xorm:"CREATETIME"`           // 记账时间
+	REMARK          string    `json:"remark" xorm:"REMARK"`                   // 备注
+	RELATEDORDERID  int64     `json:"relatedorderid" xorm:"RELATEDORDERID"`   // 关联单号
+}
+
+// TableName is THJ_USERSCORELOG
+func (r *Thjuserscorelog) TableName() string {
+	return "THJ_USERSCORELOG"
+}

+ 1 - 0
routers/router.go

@@ -690,6 +690,7 @@ func InitRouter() *gin.Engine {
 	ferroalloyR.Use(token.Auth())
 	{
 		ferroalloyR.GET("GetSpotGoodsPrice", ferroalloy.GetSpotGoodsPrice)
+		ferroalloyR.POST("Signin", ferroalloy.Signin)
 	}
 
 	return r