wrTrade.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package models
  2. import (
  3. "fmt"
  4. "mtp2_if/db"
  5. "time"
  6. )
  7. // 100.10仓单贸易
  8. // Deliverygoods 现货品种表
  9. type Deliverygoods struct {
  10. Deliverygoodsid int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'" binding:"required"` // 现货品种ID(SEQ_DELIVERYGOODS)
  11. Deliverygoodscode string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'" binding:"required"` // 现货品种代码
  12. Deliverygoodsname string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  13. Goodsunitid int32 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 现货品种单位ID
  14. Deliverygoodstype int32 `json:"deliverygoodstype" xorm:"'DELIVERYGOODSTYPE'"` // 现货品种类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细
  15. Standardqty int64 `json:"standardqty" xorm:"'STANDARDQTY'"` // 标准数量(库位数量) [标准品特有]
  16. Standardqtyrange float64 `json:"standardqtyrange" xorm:"'STANDARDQTYRANGE'"` // 标准数量偏差范围 [标准品特有]
  17. Auditflag int32 `json:"auditflag" xorm:"'AUDITFLAG'"` // 交割是否需要审核 - 0:不需要 1:需要审核 默认为0
  18. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  19. Issplit int32 `json:"issplit" xorm:"'ISSPLIT'"` // 是否拆分 - 0:不拆分 1:拆分 [整装] 0:不记录明细 1:记录明细 [散货] - 作废整装时不拆分,则标准数量=合约单位;拆分时标准数量为合约单位的整数倍;整装时必须记录明细表数据
  20. Agreeunit int64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位[散货时默认为1, 整装时默认为标准数量]
  21. Qtydecimalplace int32 `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
  22. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(SEQ_WRCATEGORY)
  23. Dgstatus int32 `json:"dgstatus" xorm:"'DGSTATUS'"` // 品种状态 - 作废 - 0:未激活 1:正常
  24. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  25. Remark string `json:"remark" xorm:"'REMARK'"` // 备注
  26. }
  27. // TableName is DELIVERYGOODS
  28. func (Deliverygoods) TableName() string {
  29. return "DELIVERYGOODS"
  30. }
  31. // Dgfactoryitemtype 品种要素项表
  32. type Dgfactoryitemtype struct {
  33. Dgfactoryitemtypeid int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'" binding:"required"` // 要素项类型ID(SEQ_DGFACTORYITEMTYPE)1-999:预留为特殊类型 1:仓库 - 选择项 2.品牌 - 选择项>1000(序列自增) 选择项 录入项
  34. Deliverygoodsid int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'" binding:"required"` // 品种ID
  35. Itemtypename string `json:"itemtypename" xorm:"'ITEMTYPENAME'"` // 要素项类型名称
  36. Itemtypemode int32 `json:"itemtypemode" xorm:"'ITEMTYPEMODE'"` // 要素项类型模式 -1:选择项 2:录入项
  37. Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
  38. Unitid int32 `json:"unitid" xorm:"'UNITID'"` // 单位ID - [录入项]
  39. Minivalue int64 `json:"minivalue" xorm:"'MINIVALUE'"` // 最小变动值 - [录入项]
  40. Minivaluedp int64 `json:"minivaluedp" xorm:"'MINIVALUEDP'"` // 最小变动值小数位 - [录入项]
  41. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  42. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  43. Updatorid int64 `json:"updatorid" xorm:"'UPDATORID'"` // 更新人
  44. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  45. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  46. }
  47. // TableName is DGFACTORYITEMTYPE
  48. func (Dgfactoryitemtype) TableName() string {
  49. return "DGFACTORYITEMTYPE"
  50. }
  51. // Dgfactoryitem 品种选择项定义表
  52. type Dgfactoryitem struct {
  53. Dgfactoryitemid int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'" binding:"required"` // 选择项ID(SEQ_DGFACTORYITEM)
  54. Deliverygoodsid int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID
  55. Dgfactoryitemtypeid int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'"` // 要素项类型
  56. Dgfactoryitemvalue string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值(类型为仓库时填写仓库名称)
  57. Warehouseid int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库ID(类型为仓库时填写)
  58. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  59. Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
  60. }
  61. // TableName is DGFACTORYITEM
  62. func (Dgfactoryitem) TableName() string {
  63. return "DGFACTORYITEM"
  64. }
  65. // Wrstandard 现货品类表
  66. type Wrstandard struct {
  67. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'" binding:"required"` // 现货品类ID(SEQ_WRSTANDARD)
  68. Wrstandardcode string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货品类代码
  69. Wrstandardname string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货品类名称
  70. Deliverygoodsid int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID
  71. Unitid int32 `json:"unitid" xorm:"'UNITID'"` // 单位ID
  72. Minivalue int64 `json:"minivalue" xorm:"'MINIVALUE'"` // 最小变动值
  73. Minivaluedp int64 `json:"minivaluedp" xorm:"'MINIVALUEDP'"` // 最小变动值小数位
  74. Realminivalue int64 `json:"realminivalue" xorm:"'REALMINIVALUE'"` // 实际最小变动值
  75. Realminivaluedp int64 `json:"realminivaluedp" xorm:"'REALMINIVALUEDP'"` // 实际最小变动值小数位
  76. Wrsstatus int32 `json:"wrsstatus" xorm:"'WRSSTATUS'"` // 状态 - 作废 - 0:未激活 1:正常
  77. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  78. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  79. Updatorid int64 `json:"updatorid" xorm:"'UPDATORID'"` // 更新人
  80. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  81. Factoryitemjson string `json:"factoryitemjson" xorm:"'FACTORYITEMJSON'"` // 要素项定义Json[{"DGFactoryItemTypeID": ,"ItemTypeMode": ,"FactoryItemIDs": },{.....},]DGFactoryItemTypeID - 要素项类型ID --DGFactoryItem->DGFactoryItemTypeIDItemTypeMode - 要素项类型模式 --DGFactoryItem->ItemTypeModeFactoryItemIDs - 选择项IDs--DGFactoryItem->DGFactoryItemID, 逗号分隔
  82. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  83. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  84. Remark string `json:"remark" xorm:"'REMARK'"` // 备注
  85. Convertfactor float64 `json:"convertfactor" xorm:"'CONVERTFACTOR'"` // 标仓系数
  86. }
  87. // TableName is WRSTANDARD
  88. func (Wrstandard) TableName() string {
  89. return "WRSTANDARD"
  90. }
  91. // Wrstandardfactoryitem 现货品类要素项定义表
  92. type Wrstandardfactoryitem struct {
  93. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'" binding:"required"` // 现货品类ID
  94. Dgfactoryitemtypeid int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'" binding:"required"` // 要素项类型ID
  95. Dgfactoryitemid int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'" binding:"required"` // 要素项ID - 输入项默认为0,选择项为选择项ID
  96. }
  97. // TableName is WRSTANDARDFACTORYITEM
  98. func (Wrstandardfactoryitem) TableName() string {
  99. return "WRSTANDARDFACTORYITEM"
  100. }
  101. // Wrfactortype 仓单要素类型表
  102. type Wrfactortype struct {
  103. Wrfactortypeid int64 `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" binding:"required"` // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
  104. Wrfactortypename string `json:"wrfactortypename" xorm:"'WRFACTORTYPENAME'"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  105. Deliverygoodsid int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 交割商品ID
  106. Brandid int64 `json:"brandid" xorm:"'BRANDID'"` // 品牌ID(1交割品种升贴水参数表 AutoID) - 作废
  107. Qualityid int64 `json:"qualityid" xorm:"'QUALITYID'"` // 品质ID(1交割品种升贴水参数表 AutoID) - 作废
  108. Specid int64 `json:"specid" xorm:"'SPECID'"` // 规格ID(1交割品种升贴水参数表 AutoID) - 作废
  109. Warehouseid int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库ID
  110. Deliverymonthid int64 `json:"deliverymonthid" xorm:"'DELIVERYMONTHID'"` // 月份ID(1交割品种升贴水参数表 AutoID) - 作废
  111. Wrstandardid int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货品类ID
  112. Wrstandardcode string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货品类代码
  113. Optioncompare string `json:"optioncompare" xorm:"'OPTIONCOMPARE'"` // 选择项比较串【{选择项ID}+{冒号}+选择项值 } ,逗号分隔,头尾加逗号】-- 所有选择项拼接,用于比较
  114. }
  115. // TableName is WRFACTORTYPE
  116. func (Wrfactortype) TableName() string {
  117. return "WRFACTORTYPE"
  118. }
  119. // Wrfactortypeitem 仓单要素类型选择项表
  120. type Wrfactortypeitem struct {
  121. Wrfactortypeid int64 `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" binding:"required"` // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
  122. Dgfactoryitemtypeid int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'" binding:"required"` // 要素选择项类型ID
  123. Dgfactoryitemid int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'" binding:"required"` // 选择项ID
  124. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  125. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  126. Updatorid int64 `json:"updatorid" xorm:"'UPDATORID'"` // 更新人
  127. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  128. }
  129. // TableName is WRFACTORTYPEITEM
  130. func (Wrfactortypeitem) TableName() string {
  131. return "WRFACTORTYPEITEM"
  132. }
  133. // Warehouseinfo 仓库信息表
  134. type Warehouseinfo struct {
  135. Autoid int64 `json:"autoid" xorm:"'AUTOID'" binding:"required"` // 自增ID
  136. Warehousecode string `json:"warehousecode" xorm:"'WAREHOUSECODE'" binding:"required"` // 仓库代码
  137. Warehousename string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  138. Warehousetype int32 `json:"warehousetype" xorm:"'WAREHOUSETYPE'"` // 仓库类型 - 1 厂库 2 自有库 3 合作库
  139. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  140. Warehousestatus int32 `json:"warehousestatus" xorm:"'WAREHOUSESTATUS'"` // 仓库状态 - 1:正常 2:注销 3:待审核 4:审核拒绝
  141. Countryid int32 `json:"countryid" xorm:"'COUNTRYID'"` // 国家
  142. Provinceid int32 `json:"provinceid" xorm:"'PROVINCEID'"` // 省
  143. Cityid int32 `json:"cityid" xorm:"'CITYID'"` // 市
  144. Districtid int32 `json:"districtid" xorm:"'DISTRICTID'"` // 区
  145. Address string `json:"address" xorm:"'ADDRESS'"` // 详细地址
  146. Remark string `json:"remark" xorm:"'REMARK'"` // 审核备注
  147. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  148. Hasvideo int32 `json:"hasvideo" xorm:"'HASVIDEO'"` // 是否有视频 - 0:无 1:有
  149. Videourl string `json:"videourl" xorm:"'VIDEOURL'"` // 视频地址
  150. Contactname string `json:"contactname" xorm:"'CONTACTNAME'"` // 联系人
  151. Contactnum string `json:"contactnum" xorm:"'CONTACTNUM'"` // 联系电话
  152. }
  153. // TableName is WAREHOUSEINFO
  154. func (Warehouseinfo) TableName() string {
  155. return "WAREHOUSEINFO"
  156. }
  157. // Wrcategory 现货分类表
  158. type Wrcategory struct {
  159. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
  160. Categoryname string `json:"categoryname" xorm:"'CATEGORYNAME'"` // 类别名称
  161. Parentcategoryid int32 `json:"parentcategoryid" xorm:"'PARENTCATEGORYID'"` // 父类别ID
  162. Categorydesc string `json:"categorydesc" xorm:"'CATEGORYDESC'"` // 类别描述
  163. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  164. Iconurl string `json:"iconurl" xorm:"'ICONURL'"` // 图标地址
  165. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  166. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  167. Updatorid int64 `json:"updatorid" xorm:"'UPDATORID'"` // 更新人
  168. Updatetime time.Time `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
  169. Orderindex int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 顺序
  170. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  171. }
  172. // TableName is WRCATEGORY
  173. func (Wrcategory) TableName() string {
  174. return "WRCATEGORY"
  175. }
  176. // WRStandardInfo 仓库信息
  177. type WRStandardInfo struct {
  178. Wrstandard `xorm:"extends"`
  179. Unitname string `json:"unitname" xorm:"UNITNAME"` // 单位
  180. Deliverygoodsname string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 交割商品名称
  181. }
  182. // GetWrstandards 获取有效的仓单标准
  183. func GetWrstandards() ([]WRStandardInfo, error) {
  184. engine := db.GetEngine()
  185. wrStandards := make([]WRStandardInfo, 0)
  186. if err := engine.Table("WRSTANDARD").Select("WRSTANDARD.*, E1.ENUMDICNAME UNITNAME, DG.DELIVERYGOODSNAME").
  187. Join("LEFT", "ENUMDICITEM E1", "E1.ENUMITEMNAME = WRSTANDARD.UNITID and E1.ENUMDICCODE = 'GOODSUNIT'").
  188. Join("LEFT", "DELIVERYGOODS DG", "DG.DELIVERYGOODSID = WRSTANDARD.DELIVERYGOODSID").
  189. Where("WRSTANDARD.ISVALID = 1").Find(&wrStandards); err != nil {
  190. return nil, err
  191. }
  192. return wrStandards, nil
  193. }
  194. // GetWareHouseinfos 获取有效的仓库信息
  195. func GetWareHouseinfos() ([]Warehouseinfo, error) {
  196. engine := db.GetEngine()
  197. wareHouseinfos := make([]Warehouseinfo, 0)
  198. if err := engine.Where("WAREHOUSESTATUS = 1").Find(&wareHouseinfos); err != nil {
  199. return nil, err
  200. }
  201. return wareHouseinfos, nil
  202. }
  203. // GetDeliverGoods 获取交割商品
  204. func GetDeliverGoods() ([]Deliverygoods, error) {
  205. engine := db.GetEngine()
  206. d := make([]Deliverygoods, 0)
  207. if err := engine.Where("IsValid=1").And("categoryid<>0").Find(&d); err != nil {
  208. return nil, fmt.Errorf("query deleiverygoods fail")
  209. }
  210. return d, nil
  211. }