Bladeren bron

1.增加查询顶级用户接口
2.#95623 现货报表 期末均价等字段计算
3.#95622 现货合同可以看到自己创建的(按申请人筛选)
4.$95615 敞口/期货头寸/期货明细查询没有数据

zou.yingbin 4 jaren geleden
bovenliggende
commit
1c1d04aa14
8 gewijzigde bestanden met toevoegingen van 641 en 17 verwijderingen
  1. 19 0
      controllers/ermcp3/qryErmcp3.go
  2. 175 0
      docs/docs.go
  3. 175 0
      docs/swagger.json
  4. 125 0
      docs/swagger.yaml
  5. 92 5
      models/ermcp3.go
  6. 54 11
      models/ermcp3Report.go
  7. 0 1
      models/ermcpExposure.go
  8. 1 0
      routers/router.go

+ 19 - 0
controllers/ermcp3/qryErmcp3.go

@@ -479,3 +479,22 @@ func QueryGoodsGroup(c *gin.Context) {
 		ExcludeCfg: req.EXCLUDECFG}
 	a.DoGetDataI(&m)
 }
+
+// QueryRootUserAccount
+// @Summary 查询顶级用户信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int true "用户ID"
+// @Success 200 {array} models.Ermcp3RootUserAccount
+// @Failure 500 {object} app.Response
+// @Router /Ermcp3/QueryRootUserAccount [get]
+// @Tags 企业风险管理v3(app)
+func QueryRootUserAccount(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	req := struct {
+		USERID int64 `form:"userid" binding:"required"` // 用户id
+	}{}
+	a.DoBindReq(&req)
+	m := models.Ermcp3RootUserAccount{USERID: req.USERID}
+	a.DoGetDataI(&m)
+}

+ 175 - 0
docs/docs.go

@@ -4418,6 +4418,48 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp3/QueryRootUserAccount": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v3(app)"
+                ],
+                "summary": "查询顶级用户信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.Ermcp3RootUserAccount"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp3/QuerySpotContract": {
             "get": {
                 "security": [
@@ -15539,6 +15581,139 @@ var doc = `{
                 }
             }
         },
+        "models.Ermcp3RootUserAccount": {
+            "type": "object",
+            "properties": {
+                "accountname": {
+                    "description": "账户名称(机构名称)",
+                    "type": "string"
+                },
+                "accountstatus": {
+                    "description": "账户状态 -  1:待激活 2:待审核 3:待复审 4:正常 5:审核拒绝 6:停用(注销) 7:注销(删除)",
+                    "type": "integer"
+                },
+                "applysrc": {
+                    "description": "申请来源 - 1:管理端 2:终端",
+                    "type": "integer"
+                },
+                "auditremark": {
+                    "description": "审核备注",
+                    "type": "string"
+                },
+                "auditsrc": {
+                    "description": "审核来源 - 1:管理端 2:终端",
+                    "type": "integer"
+                },
+                "audittime": {
+                    "description": "审核时间",
+                    "type": "string"
+                },
+                "audituserid": {
+                    "description": "审核人",
+                    "type": "integer"
+                },
+                "broker": {
+                    "description": "所属经纪人ID",
+                    "type": "integer"
+                },
+                "canceltime": {
+                    "description": "销户时间",
+                    "type": "string"
+                },
+                "canceluserid": {
+                    "description": "销户人",
+                    "type": "integer"
+                },
+                "canrecommend": {
+                    "description": "是否可推荐 - 0:不可 1;可",
+                    "type": "integer"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "creatorid": {
+                    "description": "创建人",
+                    "type": "integer"
+                },
+                "hasauth": {
+                    "description": "是否已实名认证 - 0:未认证 1:已认证 2:已提交(待审核) 3:已拒绝",
+                    "type": "integer"
+                },
+                "isanonymous": {
+                    "description": "是否匿名下单 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "maxinvestornum": {
+                    "description": "最大用户数(经纪会员下投资者个数)",
+                    "type": "integer"
+                },
+                "memberuserid": {
+                    "description": "所属会员ID",
+                    "type": "integer"
+                },
+                "modifierid": {
+                    "description": "修改人",
+                    "type": "integer"
+                },
+                "modifyremark": {
+                    "description": "变更备注",
+                    "type": "string"
+                },
+                "modifystatus": {
+                    "description": "变更状态 1 未变更 2 变更中 3 变更待审核 4 变更待复核(投资者)",
+                    "type": "integer"
+                },
+                "modifytime": {
+                    "description": "修改时间",
+                    "type": "string"
+                },
+                "parenttopuser": {
+                    "description": "上级顶级机构 [092=0,1时,默认为1, 092=2时若自已为顶级,则填入自己,自己不为顶级,填入ParentUserID的\"ParentTopUser\"]",
+                    "type": "string"
+                },
+                "parentuserid": {
+                    "description": "所属机构ID",
+                    "type": "integer"
+                },
+                "reckonaccountid": {
+                    "description": "默认结算资金账号ID(机构分润使用) 作废",
+                    "type": "integer"
+                },
+                "refercount": {
+                    "description": "推荐总人数",
+                    "type": "integer"
+                },
+                "refereeuserid": {
+                    "description": "推荐人ID",
+                    "type": "integer"
+                },
+                "refernum": {
+                    "description": "推荐码",
+                    "type": "string"
+                },
+                "rootuserid": {
+                    "description": "根用户ID",
+                    "type": "integer"
+                },
+                "subaccountlevel": {
+                    "description": "子账户层数",
+                    "type": "integer"
+                },
+                "subarealevelpath": {
+                    "description": "子机构层级路径(逗号分隔,首尾加逗号)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "usertype": {
+                    "description": "账户类型 -  1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者 6:客户 7:企业成员(云平台)",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Ermcp3SellBuyContract": {
             "type": "object",
             "properties": {

+ 175 - 0
docs/swagger.json

@@ -4402,6 +4402,48 @@
                 }
             }
         },
+        "/Ermcp3/QueryRootUserAccount": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理v3(app)"
+                ],
+                "summary": "查询顶级用户信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户ID",
+                        "name": "userid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.Ermcp3RootUserAccount"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp3/QuerySpotContract": {
             "get": {
                 "security": [
@@ -15523,6 +15565,139 @@
                 }
             }
         },
+        "models.Ermcp3RootUserAccount": {
+            "type": "object",
+            "properties": {
+                "accountname": {
+                    "description": "账户名称(机构名称)",
+                    "type": "string"
+                },
+                "accountstatus": {
+                    "description": "账户状态 -  1:待激活 2:待审核 3:待复审 4:正常 5:审核拒绝 6:停用(注销) 7:注销(删除)",
+                    "type": "integer"
+                },
+                "applysrc": {
+                    "description": "申请来源 - 1:管理端 2:终端",
+                    "type": "integer"
+                },
+                "auditremark": {
+                    "description": "审核备注",
+                    "type": "string"
+                },
+                "auditsrc": {
+                    "description": "审核来源 - 1:管理端 2:终端",
+                    "type": "integer"
+                },
+                "audittime": {
+                    "description": "审核时间",
+                    "type": "string"
+                },
+                "audituserid": {
+                    "description": "审核人",
+                    "type": "integer"
+                },
+                "broker": {
+                    "description": "所属经纪人ID",
+                    "type": "integer"
+                },
+                "canceltime": {
+                    "description": "销户时间",
+                    "type": "string"
+                },
+                "canceluserid": {
+                    "description": "销户人",
+                    "type": "integer"
+                },
+                "canrecommend": {
+                    "description": "是否可推荐 - 0:不可 1;可",
+                    "type": "integer"
+                },
+                "createtime": {
+                    "description": "创建时间",
+                    "type": "string"
+                },
+                "creatorid": {
+                    "description": "创建人",
+                    "type": "integer"
+                },
+                "hasauth": {
+                    "description": "是否已实名认证 - 0:未认证 1:已认证 2:已提交(待审核) 3:已拒绝",
+                    "type": "integer"
+                },
+                "isanonymous": {
+                    "description": "是否匿名下单 - 0:否 1:是",
+                    "type": "integer"
+                },
+                "maxinvestornum": {
+                    "description": "最大用户数(经纪会员下投资者个数)",
+                    "type": "integer"
+                },
+                "memberuserid": {
+                    "description": "所属会员ID",
+                    "type": "integer"
+                },
+                "modifierid": {
+                    "description": "修改人",
+                    "type": "integer"
+                },
+                "modifyremark": {
+                    "description": "变更备注",
+                    "type": "string"
+                },
+                "modifystatus": {
+                    "description": "变更状态 1 未变更 2 变更中 3 变更待审核 4 变更待复核(投资者)",
+                    "type": "integer"
+                },
+                "modifytime": {
+                    "description": "修改时间",
+                    "type": "string"
+                },
+                "parenttopuser": {
+                    "description": "上级顶级机构 [092=0,1时,默认为1, 092=2时若自已为顶级,则填入自己,自己不为顶级,填入ParentUserID的\"ParentTopUser\"]",
+                    "type": "string"
+                },
+                "parentuserid": {
+                    "description": "所属机构ID",
+                    "type": "integer"
+                },
+                "reckonaccountid": {
+                    "description": "默认结算资金账号ID(机构分润使用) 作废",
+                    "type": "integer"
+                },
+                "refercount": {
+                    "description": "推荐总人数",
+                    "type": "integer"
+                },
+                "refereeuserid": {
+                    "description": "推荐人ID",
+                    "type": "integer"
+                },
+                "refernum": {
+                    "description": "推荐码",
+                    "type": "string"
+                },
+                "rootuserid": {
+                    "description": "根用户ID",
+                    "type": "integer"
+                },
+                "subaccountlevel": {
+                    "description": "子账户层数",
+                    "type": "integer"
+                },
+                "subarealevelpath": {
+                    "description": "子机构层级路径(逗号分隔,首尾加逗号)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "usertype": {
+                    "description": "账户类型 -  1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者 6:客户 7:企业成员(云平台)",
+                    "type": "integer"
+                }
+            }
+        },
         "models.Ermcp3SellBuyContract": {
             "type": "object",
             "properties": {

+ 125 - 0
docs/swagger.yaml

@@ -4768,6 +4768,105 @@ definitions:
         description: 套保商品信息
         type: object
     type: object
+  models.Ermcp3RootUserAccount:
+    properties:
+      accountname:
+        description: 账户名称(机构名称)
+        type: string
+      accountstatus:
+        description: 账户状态 -  1:待激活 2:待审核 3:待复审 4:正常 5:审核拒绝 6:停用(注销) 7:注销(删除)
+        type: integer
+      applysrc:
+        description: 申请来源 - 1:管理端 2:终端
+        type: integer
+      auditremark:
+        description: 审核备注
+        type: string
+      auditsrc:
+        description: 审核来源 - 1:管理端 2:终端
+        type: integer
+      audittime:
+        description: 审核时间
+        type: string
+      audituserid:
+        description: 审核人
+        type: integer
+      broker:
+        description: 所属经纪人ID
+        type: integer
+      canceltime:
+        description: 销户时间
+        type: string
+      canceluserid:
+        description: 销户人
+        type: integer
+      canrecommend:
+        description: 是否可推荐 - 0:不可 1;可
+        type: integer
+      createtime:
+        description: 创建时间
+        type: string
+      creatorid:
+        description: 创建人
+        type: integer
+      hasauth:
+        description: 是否已实名认证 - 0:未认证 1:已认证 2:已提交(待审核) 3:已拒绝
+        type: integer
+      isanonymous:
+        description: 是否匿名下单 - 0:否 1:是
+        type: integer
+      maxinvestornum:
+        description: 最大用户数(经纪会员下投资者个数)
+        type: integer
+      memberuserid:
+        description: 所属会员ID
+        type: integer
+      modifierid:
+        description: 修改人
+        type: integer
+      modifyremark:
+        description: 变更备注
+        type: string
+      modifystatus:
+        description: 变更状态 1 未变更 2 变更中 3 变更待审核 4 变更待复核(投资者)
+        type: integer
+      modifytime:
+        description: 修改时间
+        type: string
+      parenttopuser:
+        description: 上级顶级机构 [092=0,1时,默认为1, 092=2时若自已为顶级,则填入自己,自己不为顶级,填入ParentUserID的"ParentTopUser"]
+        type: string
+      parentuserid:
+        description: 所属机构ID
+        type: integer
+      reckonaccountid:
+        description: 默认结算资金账号ID(机构分润使用) 作废
+        type: integer
+      refercount:
+        description: 推荐总人数
+        type: integer
+      refereeuserid:
+        description: 推荐人ID
+        type: integer
+      refernum:
+        description: 推荐码
+        type: string
+      rootuserid:
+        description: 根用户ID
+        type: integer
+      subaccountlevel:
+        description: 子账户层数
+        type: integer
+      subarealevelpath:
+        description: 子机构层级路径(逗号分隔,首尾加逗号)
+        type: string
+      userid:
+        description: 用户ID
+        type: integer
+      usertype:
+        description: 账户类型 -  1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者 6:客户 7:企业成员(云平台)
+        type: integer
+    type: object
   models.Ermcp3SellBuyContract:
     properties:
       accountid:
@@ -16038,6 +16137,32 @@ paths:
       summary: 查询套保品种详情(套保品种/商品详情)
       tags:
       - 企业风险管理v3(app)
+  /Ermcp3/QueryRootUserAccount:
+    get:
+      parameters:
+      - description: 用户ID
+        in: query
+        name: userid
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/models.Ermcp3RootUserAccount'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询顶级用户信息
+      tags:
+      - 企业风险管理v3(app)
   /Ermcp3/QuerySpotContract:
     get:
       parameters:

+ 92 - 5
models/ermcp3.go

@@ -742,13 +742,11 @@ func (r *Ermcp3Contract) buildSql() string {
 		"    on t.spotgoodsbrandid = gb.dgfactoryitemid" +
 		"  left join wrstandard w" +
 		"    on t.wrstandardid = w.wrstandardid" +
+		"  left join loginaccount l on t.applyid=l.loginid" +
 		" where 1 = 1"
-	sqlId.AndEx("t.userid", r.USERID, r.USERID > 0)
 	sqlId.AndEx("t.SPOTCONTRACTID", r.SPOTCONTRACTID, len(r.SPOTCONTRACTID) > 0)
-	if r.UserType == 7 {
-		// 企业成员
-		sqlId.Join(fmt.Sprintf(" and %v in(t.saleuserid, t.tradeuserid, t.meruserid)", r.OwnUserId))
-	}
+	// 用户条件
+	sqlId.Join(fmt.Sprintf(" and %v in(t.userid, t.saleuserid, t.tradeuserid, t.meruserid, l.userid)", r.OwnUserId))
 	status := r.getQryTypeStatus()
 	if len(status) > 0 {
 		sqlId.Join(fmt.Sprintf(" and t.contractstatus in (%v)", status))
@@ -2071,3 +2069,92 @@ func (r *Ermcp3GoodsGroup) GetData() ([]Ermcp3GoodsGroup, error) {
 func (r *Ermcp3GoodsGroup) GetDataEx() (interface{}, error) {
 	return r.GetData()
 }
+
+// Ermcp3RootUserAccount 顶级用户
+type Ermcp3RootUserAccount struct {
+	ROOTUSERID       int64  `json:"rootuserid"  xorm:"ROOTUSERID"`             // 根用户ID
+	CANRECOMMEND     int32  `json:"canrecommend"  xorm:"CANRECOMMEND"`         // 是否可推荐 - 0:不可 1;可
+	USERID           int64  `json:"userid"  xorm:"USERID"`                     // 用户ID
+	USERTYPE         int32  `json:"usertype"  xorm:"USERTYPE"`                 // 账户类型 -  1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者 6:客户 7:企业成员(云平台)
+	MODIFYSTATUS     int32  `json:"modifystatus"  xorm:"MODIFYSTATUS"`         // 变更状态 1 未变更 2 变更中 3 变更待审核 4 变更待复核(投资者)
+	ACCOUNTNAME      string `json:"accountname"  xorm:"ACCOUNTNAME"`           // 账户名称(机构名称)
+	PARENTUSERID     int64  `json:"parentuserid"  xorm:"PARENTUSERID"`         // 所属机构ID
+	BROKER           int64  `json:"broker"  xorm:"BROKER"`                     // 所属经纪人ID
+	SUBAREALEVELPATH string `json:"subarealevelpath"  xorm:"SUBAREALEVELPATH"` // 子机构层级路径(逗号分隔,首尾加逗号)
+	REFEREEUSERID    int64  `json:"refereeuserid"  xorm:"REFEREEUSERID"`       // 推荐人ID
+	MEMBERUSERID     int64  `json:"memberuserid"  xorm:"MEMBERUSERID"`         // 所属会员ID
+	ACCOUNTSTATUS    int32  `json:"accountstatus"  xorm:"ACCOUNTSTATUS"`       // 账户状态 -  1:待激活 2:待审核 3:待复审 4:正常 5:审核拒绝 6:停用(注销) 7:注销(删除)
+	RECKONACCOUNTID  int64  `json:"reckonaccountid"  xorm:"RECKONACCOUNTID"`   // 默认结算资金账号ID(机构分润使用) 作废
+	CREATETIME       string `json:"createtime"  xorm:"CREATETIME"`             // 创建时间
+	CREATORID        int64  `json:"creatorid"  xorm:"CREATORID"`               // 创建人
+	AUDITTIME        string `json:"audittime"  xorm:"AUDITTIME"`               // 审核时间
+	AUDITUSERID      int64  `json:"audituserid"  xorm:"AUDITUSERID"`           // 审核人
+	AUDITREMARK      string `json:"auditremark"  xorm:"AUDITREMARK"`           // 审核备注
+	CANCELTIME       string `json:"canceltime"  xorm:"CANCELTIME"`             // 销户时间
+	CANCELUSERID     int64  `json:"canceluserid"  xorm:"CANCELUSERID"`         // 销户人
+	MODIFYTIME       string `json:"modifytime"  xorm:"MODIFYTIME"`             // 修改时间
+	MODIFIERID       int64  `json:"modifierid"  xorm:"MODIFIERID"`             // 修改人
+	MODIFYREMARK     string `json:"modifyremark"  xorm:"MODIFYREMARK"`         // 变更备注
+	MAXINVESTORNUM   int64  `json:"maxinvestornum"  xorm:"MAXINVESTORNUM"`     // 最大用户数(经纪会员下投资者个数)
+	HASAUTH          int32  `json:"hasauth"  xorm:"HASAUTH"`                   // 是否已实名认证 - 0:未认证 1:已认证 2:已提交(待审核) 3:已拒绝
+	REFERCOUNT       int32  `json:"refercount"  xorm:"REFERCOUNT"`             // 推荐总人数
+	REFERNUM         string `json:"refernum"  xorm:"REFERNUM"`                 // 推荐码
+	ISANONYMOUS      int32  `json:"isanonymous"  xorm:"ISANONYMOUS"`           // 是否匿名下单 - 0:否 1:是
+	PARENTTOPUSER    string `json:"parenttopuser"  xorm:"PARENTTOPUSER"`       // 上级顶级机构 [092=0,1时,默认为1, 092=2时若自已为顶级,则填入自己,自己不为顶级,填入ParentUserID的"ParentTopUser"]
+	SUBACCOUNTLEVEL  int32  `json:"subaccountlevel"  xorm:"SUBACCOUNTLEVEL"`   // 子账户层数
+	APPLYSRC         int32  `json:"applysrc"  xorm:"APPLYSRC"`                 // 申请来源 - 1:管理端 2:终端
+	AUDITSRC         int32  `json:"auditsrc"  xorm:"AUDITSRC"`                 // 审核来源 - 1:管理端 2:终端
+}
+
+func (r *Ermcp3RootUserAccount) calc() {
+
+}
+
+func (r *Ermcp3RootUserAccount) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT t.ROOTUSERID," +
+		"       t.CANRECOMMEND," +
+		"       t.USERID," +
+		"       t.USERTYPE," +
+		"       t.MODIFYSTATUS," +
+		"       t.ACCOUNTNAME," +
+		"       t.PARENTUSERID," +
+		"       t.BROKER," +
+		"       t.SUBAREALEVELPATH," +
+		"       t.REFEREEUSERID," +
+		"       t.MEMBERUSERID," +
+		"       t.ACCOUNTSTATUS," +
+		"       t.RECKONACCOUNTID," +
+		"       to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
+		"       t.CREATORID," +
+		"       to_char(t.AUDITTIME, 'yyyy-mm-dd hh24:mi:ss') AUDITTIME," +
+		"       t.AUDITUSERID," +
+		"       t.AUDITREMARK," +
+		"       to_char(t.CANCELTIME, 'yyyy-mm-dd hh24:mi:ss') CANCELTIME," +
+		"       t.CANCELUSERID," +
+		"       to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
+		"       t.MODIFIERID," +
+		"       t.MODIFYREMARK," +
+		"       t.MAXINVESTORNUM," +
+		"       t.HASAUTH," +
+		"       t.REFERCOUNT," +
+		"       t.REFERNUM," +
+		"       t.ISANONYMOUS," +
+		"       t.PARENTTOPUSER," +
+		"       t.SUBACCOUNTLEVEL," +
+		"       t.APPLYSRC," +
+		"       t.AUDITSRC" +
+		"  FROM USERACCOUNT t" +
+		" WHERE 1 = 1 and t.userid in(select rootuserid from useraccount where userid=%v)"
+	sqlId.FormatParam(r.USERID)
+	return sqlId.String()
+}
+
+// GetDataEx 获取顶级用户
+func (r *Ermcp3RootUserAccount) GetDataEx() (interface{}, error) {
+	sData := make([]Ermcp3RootUserAccount, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}

+ 54 - 11
models/ermcp3Report.go

@@ -924,17 +924,60 @@ func (r *Ermcp3AreaSpotPLReport) calc() {
 	r.UNITIDNAME = mtpcache.GetEnumDicitemName(r.UNITID)
 	r.ACCOUNTNAME = mtpcache.GetUserNameByUserId(r.AREAUSERID)
 	r.CURRENCYNAME = mtpcache.GetCurrencyName(r.CURRENCYID)
-	if r.CURQTY > 0 {
-		r.CURAVERAGEPRICE = r.CURAMOUNT / r.CURQTY
-	}
-	if r.ORIQTY > 0 {
-		r.ORIAVERAGEPRICE = r.ORIAMOUNT / r.ORIQTY
-	}
-	if r.TODAYBUYQTY > 0 {
-		r.TODAYBUYAVERAGEPRICE = r.TODAYBUYAMOUNT / r.TODAYBUYQTY
-	}
-	if r.TODAYSELLQTY > 0 {
-		r.TODAYSELLAVERAGEPRICE = r.TODAYSELLAMOUNT / r.TODAYSELLQTY
+
+	if r.ORIQTY > 0 && r.CURQTY > 0 {
+		// 1.当期初量大于等于0时:期末量也大于等于0时:
+		// 期末均价 CurAveragePrice=(今采购额+期初额)/(今采购量+期初量)
+		// 期末额 CurAmoun =(今采购额 + 期初额)- 今销售量 * 期末均价
+		// 现货损益 ActualPL = 今销售额 - 今销售量 * 期末均价
+		// 浮动损益 = 期末市值 - 期末额
+		r.CURAVERAGEPRICE = (r.TODAYBUYAMOUNT + r.ORIAMOUNT) / (r.TODAYBUYQTY + r.ORIQTY)
+		r.CURAMOUNT = (r.TODAYBUYAMOUNT + r.ORIAMOUNT) - r.TODAYSELLQTY*r.CURAVERAGEPRICE
+		r.ACTUALPL = r.TODAYSELLAMOUNT - r.TODAYSELLQTY*r.CURAVERAGEPRICE
+		r.FLOATPL = r.CURMARKETVALUE - r.CURAMOUNT
+
+	} else if r.ORIQTY >= 0 && r.CURQTY < 0 {
+		// 2.当期初量大于等于0时:期末量也小于0时:
+		//期末均价=今销售额/今销售量
+		//期末额=(今采购量+期初量)*期末均价-今销售额
+		//现货损益=(今采购量+期初量)*期末均价-(今采购额+期初额)
+		//浮动损益 =期末市值 - 期末额
+		if r.TODAYSELLQTY > 0 {
+			r.CURAVERAGEPRICE = r.TODAYSELLAMOUNT / r.TODAYSELLQTY
+		} else {
+			r.CURAVERAGEPRICE = 0
+		}
+		r.CURAMOUNT = (r.TODAYBUYQTY+r.ORIQTY)*r.CURAVERAGEPRICE - r.TODAYSELLAMOUNT
+		r.ACTUALPL = (r.TODAYBUYQTY+r.ORIQTY)*r.CURAVERAGEPRICE - (r.TODAYBUYAMOUNT + r.ORIAMOUNT)
+		r.FLOATPL = r.CURMARKETVALUE - r.CURAMOUNT
+	} else if r.ORIQTY < 0 && r.CURQTY >= 0 {
+		// 3.当期初量小于0时:期末量也大于等于0时:
+		//期末均价=今采购额/今采购量
+		//期末额=今采购额-(今销售量-期初量)*期末均价
+		//现货损益=(今销售额-期初额)-(今销售量-期初量)*期末均价
+		//浮动损益 =期末市值 - 期末额
+		if r.TODAYBUYQTY > 0 {
+			r.CURAVERAGEPRICE = r.TODAYBUYAMOUNT / r.TODAYBUYQTY
+		} else {
+			r.CURAVERAGEPRICE = 0
+		}
+		r.CURAMOUNT = r.TODAYBUYAMOUNT - (r.TODAYSELLQTY-r.ORIQTY)*r.CURAVERAGEPRICE
+		r.ACTUALPL = (r.TODAYSELLAMOUNT - r.ORIAMOUNT) - (r.TODAYSELLQTY-r.ORIQTY)*r.CURAVERAGEPRICE
+		r.FLOATPL = r.CURMARKETVALUE - r.CURAMOUNT
+	} else if r.ORIQTY < 0 && r.CURQTY < 0 {
+		// 4.当期初量小于0时:期末量也小于0时:
+		//期末均价=(今销售额-期初额)/(今销售量-期初量)
+		//期末额=今采购量*期末均价-(今销售额-期初额)
+		//现货损益=今采购量*期末均价-今采购额
+		//浮动损益 =期末市值 - 期末额
+		if r.TODAYSELLQTY-r.ORIQTY != 0 {
+			r.CURAVERAGEPRICE = (r.TODAYSELLAMOUNT - r.ORIAMOUNT) / (r.TODAYSELLQTY - r.ORIQTY)
+		} else {
+			r.CURAVERAGEPRICE = 0
+		}
+		r.CURAMOUNT = r.TODAYBUYQTY*r.CURAVERAGEPRICE - (r.TODAYSELLAMOUNT - r.ORIAMOUNT)
+		r.ACTUALPL = r.TODAYBUYQTY*r.CURAVERAGEPRICE - r.TODAYBUYAMOUNT
+		r.FLOATPL = r.CURMARKETVALUE - r.CURAVERAGEPRICE
 	}
 }
 

+ 0 - 1
models/ermcpExposure.go

@@ -884,7 +884,6 @@ func (r *ErmcpHedgePositionDetail) buildSql() string {
 			"  from hedge_innertradedetail t" +
 			" inner join taaccount ta" +
 			"    on t.accountid = ta.accountid" +
-			"   and ta.ismain = 1" +
 			"   and ta.relateduserid = %v" +
 			"  left join goods g" +
 			"    on t.goodsid = g.goodsid" +

+ 1 - 0
routers/router.go

@@ -428,6 +428,7 @@ func InitRouter() *gin.Engine {
 		ermcp3R.GET("/QueryHedgePlan", ermcp3.QueryHedgePlan)
 		ermcp3R.GET("/QueryGoodsGroup", ermcp3.QueryGoodsGroup)
 		ermcp3R.GET("/QueryMiddleGoodsDetail", ermcp3.QueryMiddleGoodsDetail)
+		ermcp3R.GET("/QueryRootUserAccount", ermcp3.QueryRootUserAccount)
 
 		// 报表
 		ermcp3R.GET("/QryReportDaySpotDetail", ermcp3.QryReportDaySpotDetail)