From f84d9c46574a2cd663105859035bc17891270923 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期一, 14 八月 2023 10:41:54 +0800
Subject: [PATCH] Merge branch 'master' into fly
---
model/salesDetails.go | 71 ++++++++++++++++++++++++++++++++---
1 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/model/salesDetails.go b/model/salesDetails.go
index b318ab7..be63cf7 100644
--- a/model/salesDetails.go
+++ b/model/salesDetails.go
@@ -20,6 +20,7 @@
SaleType int `json:"saleType" gorm:"column:sale_type;type:int;comment:閿�鍞被鍨�"`
SignTime string `json:"signTime" gorm:"column:sign_time;type:varchar(255);comment:绛惧崟鏃堕棿"`
MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+ Member User `json:"Member" gorm:"foreignKey:MemberId"`
DeliveryDate string `json:"deliveryDate" gorm:"column:delivery_date;type:varchar(255);comment:浜よ揣鏃ユ湡"`
WechatOrderStatusId int `json:"wechatOrderStatusId" gorm:"column:wechat_order_status;type:int;comment:寰俊璁㈠崟鐘舵��"`
WechatOrderStatus WechatOrderStatus `json:"wechatOrderStatus" gorm:"foreignKey:WechatOrderStatusId"`
@@ -27,16 +28,18 @@
Phone string `json:"phone" gorm:"column:phone;type:varchar(255);comment:鐢佃瘽"`
Addressee string `json:"addressee" gorm:"column:addressee;type:varchar(255);comment:鏀朵欢浜�"`
Conditions string `json:"conditions" gorm:"column:conditions;type:text;comment:鏉′欢"`
+ CreatorId int `json:"creatorId" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"`
Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
- Products []Product `json:"products" gorm:"many2many:sales_details_product;"`
+ Products []*Product `json:"products" gorm:"many2many:sales_details_product;"`
LogisticCompany string `json:"logisticCompany" gorm:"column:logistic_company;type:varchar(255);comment:鐗╂祦鍏徃"`
LogisticNumber string `json:"logisticNumber" gorm:"column:logistic_number;type:varchar(255);comment:鐗╂祦鍗曞彿"`
LogisticCost float64 `json:"logisticCost" gorm:"column:logistic_cost;type:decimal(10,2);comment:鐗╂祦璐圭敤"`
- AmountReceivable decimal.Decimal `gorm:"amount_receivable" json:"amountReceivable"` // 搴旀敹閲戦
- AmountReceived decimal.Decimal `gorm:"amount_received" json:"amountReceived"` // 宸叉敹閲戦
- AmountInvoiced decimal.Decimal `gorm:"amount_invoiced" json:"amountInvoiced"` // 宸插紑绁ㄩ噾棰�
- AmountUnInvoiced decimal.Decimal `gorm:"-" json:"amountUnInvoiced"` // 鏈紑绁ㄩ噾棰�
- gorm.Model `json:"-"`
+ AmountReceivable decimal.Decimal `gorm:"column:amount_receivable;type:decimal(12,2);comment:搴旀敹閲戦" json:"amountReceivable"` // 搴旀敹閲戦
+ AmountReceived decimal.Decimal `gorm:"column:amount_received;type:decimal(12,2);comment:宸叉敹閲戦" json:"amountReceived"` // 宸叉敹閲戦
+ AmountInvoiced decimal.Decimal `gorm:"column:amount_invoiced;type:decimal(12,2);comment:宸插紑绁ㄩ噾棰�" json:"amountInvoiced"` // 宸插紑绁ㄩ噾棰�
+ AmountUnInvoiced decimal.Decimal `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountUnInvoiced"` // 鏈紑绁ㄩ噾棰�
+ AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:浠风◣鍚堣" json:"amountTotal"` // 浠风◣鍚堣
+ CrmModel
}
SalesDetailsSearch struct {
@@ -111,7 +114,7 @@
return slf
}
-func (slf *SalesDetailsSearch) Find() (*SalesDetails, error) {
+func (slf *SalesDetailsSearch) First() (*SalesDetails, error) {
var db = slf.build()
var record = new(SalesDetails)
err := db.First(record).Error
@@ -161,3 +164,57 @@
slf.OrderBy = order
return slf
}
+
+func (slf *SalesDetailsSearch) UpdateByMap(upMap map[string]interface{}) error {
+ var (
+ db = slf.build()
+ )
+
+ if err := db.Updates(upMap).Error; err != nil {
+ return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
+ }
+
+ return nil
+}
+
+func (slf *SalesDetailsSearch) SetOrm(tx *gorm.DB) *SalesDetailsSearch {
+ slf.Orm = tx
+ return slf
+}
+
+func (slf *SalesDetailsSearch) AmountReceivableAdd(tx *gorm.DB, id int, amount decimal.Decimal) error {
+ slf.Orm = tx
+ record, err := slf.SetId(id).First()
+ if err != nil {
+ return err
+ }
+ amount = record.AmountReceivable.Add(amount)
+ return slf.UpdateByMap(map[string]interface{}{"amount_receivable": amount})
+}
+func (slf *SalesDetailsSearch) AmountReceivedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error {
+ slf.Orm = tx
+ record, err := slf.SetId(id).First()
+ if err != nil {
+ return err
+ }
+ amount = record.AmountReceived.Add(amount)
+ return slf.UpdateByMap(map[string]interface{}{"amount_received": amount})
+}
+func (slf *SalesDetailsSearch) AmountInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error {
+ slf.Orm = tx
+ record, err := slf.SetId(id).First()
+ if err != nil {
+ return err
+ }
+ amount = record.AmountInvoiced.Add(amount)
+ return slf.UpdateByMap(map[string]interface{}{"amount_invoiced": amount})
+}
+func (slf *SalesDetailsSearch) AmountNotInvoicedAdd(tx *gorm.DB, id int, amount decimal.Decimal) error {
+ slf.Orm = tx
+ record, err := slf.SetId(id).First()
+ if err != nil {
+ return err
+ }
+ amount = record.AmountUnInvoiced.Add(amount)
+ return slf.UpdateByMap(map[string]interface{}{"amount_not_invoiced": amount})
+}
--
Gitblit v1.8.0