Commit a92c27e2 by 朱继来

调整竞调订单

parent 78fc44a7
package JingdiaoAddress
type JingdiaoAddress struct {
Id int `db:"id"`
Company string `db:"company"`
Lianxiren string `db:"lianxiren"`
Address string `db:"address"`
Telphone string `db:"telphone"`
}
\ No newline at end of file
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"go-queue-server/dal/db" "go-queue-server/dal/db"
"go-queue-server/dal/order/OrderItems" "go-queue-server/dal/order/OrderItems"
"go-queue-server/dal/order/OtherAddress" "go-queue-server/dal/order/JingdiaoAddress"
"math/rand" "math/rand"
"strconv" "strconv"
"time" "time"
...@@ -23,19 +23,27 @@ func RandInt(min, max int) int { ...@@ -23,19 +23,27 @@ func RandInt(min, max int) int {
// 随机获取竞调用户user_id // 随机获取竞调用户user_id
func GetJingDiaoUserId() int { func GetJingDiaoUserId() int {
var max_count int //var max_count int
var min_count int //var min_count int
db.DB.Get(&max_count, "select Max(user_id) from lie_user_main where is_type = 1") //db.DB.Get(&max_count, "select Max(user_id) from lie_user_main where is_type = 1")
db.DB.Get(&min_count, "select Min(user_id) from lie_user_main where is_type = 1") //db.DB.Get(&min_count, "select Min(user_id) from lie_user_main where is_type = 1")
//
//rand_num := RandInt(min_count - 1, max_count + 1) // 从总数中取个随机数
//
//var user_id int
//db.DB.Get(&user_id, "select user_id from lie_user_main where user_id = ? and is_type = ? limit 1", rand_num, 1)
//
//if user_id == 0 {
// return GetJingDiaoUserId()
//}
rand_num := RandInt(min_count - 1, max_count + 1) // 从总数中取个随机数 var count int
db.DB.QueryRow("select count(*) from lie_user_id").Scan(&count)
var user_id int rand_num := RandInt(1, count + 1)
db.DB.Get(&user_id, "select user_id from lie_user_main where user_id = ? and is_type = ? limit 1", rand_num, 1)
if user_id == 0 { var user_id int
return GetJingDiaoUserId() db.DB.Get(&user_id, "select user_id from lie_user_id where id = ?", rand_num)
}
return user_id return user_id
} }
...@@ -60,25 +68,41 @@ func GetOneOrderItem() OrderItems.OrderItems { ...@@ -60,25 +68,41 @@ func GetOneOrderItem() OrderItems.OrderItems {
} }
// 随机获取一条收货地址 // 随机获取一条收货地址
func GetOneOrderAddress() OtherAddress.OtherAddress { func GetOrderAddress() JingdiaoAddress.JingdiaoAddress {
var max_count int var count int
var min_count int db.DB.QueryRow("select count(*) from lie_jingdiao_address").Scan(&count)
db.DB.Get(&max_count, "select Max(order_address_id) from lie_order_address_tmp where address_type = 1")
db.DB.Get(&min_count, "select Min(order_address_id) from lie_order_address_tmp where address_type = 1")
rand_num := RandInt(min_count - 1, max_count + 1) // 从总数中取个随机数 rand_num := RandInt(1, count + 1) // 从总数中取个随机数
var order_address OtherAddress.OtherAddress var address JingdiaoAddress.JingdiaoAddress
var field string = "order_address_id,address_id,province,city,district,address,consignee,mobile,area_code,telphone" db.DB.Get(&address, "select id, company, lianxiren, address, telphone from lie_jingdiao_address where id = ?", rand_num)
db.DB.Get(&order_address, "select "+field+" from lie_order_address_tmp where order_address_id = ? and address_type = ?", rand_num, 1)
if order_address.OrderAddressId == 0 { if address.Id == 0 {
return GetOneOrderAddress() return GetOrderAddress()
} }
return order_address return address
} }
//func GetOneOrderAddress() OtherAddress.OtherAddress {
// var max_count int
// var min_count int
// db.DB.Get(&max_count, "select Max(order_address_id) from lie_order_address_tmp where address_type = 1")
// db.DB.Get(&min_count, "select Min(order_address_id) from lie_order_address_tmp where address_type = 1")
//
// rand_num := RandInt(min_count - 1, max_count + 1) // 从总数中取个随机数
//
// var order_address OtherAddress.OtherAddress
// var field string = "order_address_id,address_id,province,city,district,address,consignee,mobile,area_code,telphone"
// db.DB.Get(&order_address, "select "+field+" from lie_order_address_tmp where order_address_id = ? and address_type = ?", rand_num, 1)
//
// if order_address.OrderAddressId == 0 {
// return GetOneOrderAddress()
// }
//
// return order_address
//}
// 随机获取客服 // 随机获取客服
func GetSaleId() int { func GetSaleId() int {
var max_count int var max_count int
......
...@@ -5,9 +5,10 @@ import ( ...@@ -5,9 +5,10 @@ import (
"fmt" "fmt"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"go-queue-server/dal/db" "go-queue-server/dal/db"
"go-queue-server/dal/order/JingdiaoAddress"
"go-queue-server/dal/order/Order" "go-queue-server/dal/order/Order"
"go-queue-server/dal/order/OrderItems" "go-queue-server/dal/order/OrderItems"
"go-queue-server/dal/order/OtherAddress" _"go-queue-server/dal/order/OtherAddress"
"go-queue-server/order/jingdiao/handle" "go-queue-server/order/jingdiao/handle"
"go-queue-server/util" "go-queue-server/util"
"strconv" "strconv"
...@@ -104,7 +105,7 @@ func main() { ...@@ -104,7 +105,7 @@ func main() {
Order.UpdateJingDiaoOrder() Order.UpdateJingDiaoOrder()
// 创建订单 // 创建订单
for i := 0; i < order_count; i++ { for i := 0; i < 1; i++ {
var user_id int = handle.GetJingDiaoUserId() var user_id int = handle.GetJingDiaoUserId()
CreateOrder(user_id, time.Now().Unix()) CreateOrder(user_id, time.Now().Unix())
} }
...@@ -116,14 +117,14 @@ func main() { ...@@ -116,14 +117,14 @@ func main() {
func CreateOrder(user_id int, create_time int64) { func CreateOrder(user_id int, create_time int64) {
var min_amount int // 订单总额不低于随机生成数 var min_amount int // 订单总额不低于随机生成数
var order_item OrderItems.OrderItems // 随机获取一条明细 var order_item OrderItems.OrderItems // 随机获取一条明细
var order_address OtherAddress.OtherAddress // 随机获取一条地址 var order_address JingdiaoAddress.JingdiaoAddress // 随机获取一条地址
var goods_number int // 商品数量 var goods_number int // 商品数量
var order_sn string // 订单号 var order_sn string // 订单号
var order_amount float64 // 订单总额 var order_amount float64 // 订单总额
min_amount = handle.RandInt(8000, 15000) / 100 * 100 min_amount = handle.RandInt(8000, 15000) / 100 * 100
order_item = handle.GetOneOrderItem() order_item = handle.GetOneOrderItem()
order_address = handle.GetOneOrderAddress() order_address = handle.GetOrderAddress()
goods_number = int(float64(min_amount) / order_item.GoodsPrice) goods_number = int(float64(min_amount) / order_item.GoodsPrice)
order_amount = handle.Decimal(order_item.GoodsPrice * float64(goods_number)) order_amount = handle.Decimal(order_item.GoodsPrice * float64(goods_number))
...@@ -132,7 +133,6 @@ func CreateOrder(user_id int, create_time int64) { ...@@ -132,7 +133,6 @@ func CreateOrder(user_id int, create_time int64) {
// 订单数据 // 订单数据
order := make(map[string]interface{}, 0) order := make(map[string]interface{}, 0)
goods_data := make(map[string]interface{}, 0) goods_data := make(map[string]interface{}, 0)
address_data := make(map[string]interface{}, 0)
order["order_sn"] = order_sn order["order_sn"] = order_sn
order["user_id"] = user_id order["user_id"] = user_id
...@@ -164,26 +164,14 @@ func CreateOrder(user_id int, create_time int64) { ...@@ -164,26 +164,14 @@ func CreateOrder(user_id int, create_time int64) {
goods_data["buyer_id"] = order_item.BuyerId goods_data["buyer_id"] = order_item.BuyerId
goods_data["batch"] = order_item.Batch goods_data["batch"] = order_item.Batch
address_data["address_id"] = order_address.AddressId
address_data["order_sn"] = order_sn
address_data["address_type"] = order_address.AddressType
address_data["province"] = order_address.Province
address_data["city"] = order_address.City
address_data["district"] = order_address.District
address_data["address"] = order_address.Address
address_data["consignee"] = order_address.Consignee
address_data["mobile"] = order_address.Mobile
address_data["area_code"] = order_address.AreaCode
address_data["telphone"] = order_address.Telphone
conn, err := db.DB.Begin() // 开启事务 conn, err := db.DB.Begin() // 开启事务
if err != nil { if err != nil {
return return
} }
// 添加lie_order // 添加lie_order
res, _ := conn.Exec("insert into lie_order (order_sn, user_id, order_amount, status, create_time, sale_id, is_type, erp_syn) values (?, ?, ?, ?, ?, ?, ?, ?)", order["order_sn"], res, _ := conn.Exec("insert into lie_order (order_sn, user_id, order_amount, status, create_time, sale_id, is_type, erp_syn, order_remark) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", order["order_sn"],
order["user_id"], order["order_amount"], order["status"], create_time, order["sale_id"], order["is_type"], 1) order["user_id"], order["order_amount"], order["status"], create_time, order["sale_id"], order["is_type"], 1, order_address.Address)
LastInsertId, err := res.LastInsertId() LastInsertId, err := res.LastInsertId()
if err != nil { if err != nil {
...@@ -194,22 +182,28 @@ func CreateOrder(user_id int, create_time int64) { ...@@ -194,22 +182,28 @@ func CreateOrder(user_id int, create_time int64) {
strInt64 := strconv.FormatInt(LastInsertId, 10) strInt64 := strconv.FormatInt(LastInsertId, 10)
order_id, _ := strconv.Atoi(strInt64) order_id, _ := strconv.Atoi(strInt64)
// 添加lie_order_extend
_, err = conn.Exec("insert into lie_order_extend (order_id, is_manager_audit) values (?, ?)", order_id, 3)
if err != nil {
conn.Rollback() //回滚
return
}
// 添加lie_order_items // 添加lie_order_items
_, err = conn.Exec("insert into lie_order_items (order_id, user_id, goods_id, supplier_id, brand_id, standard_brand_id, goods_sn, goods_name, sku_name, supplier_name, brand_name, " + _, err = conn.Exec("insert into lie_order_items (order_id, user_id, goods_id, supplier_id, brand_id, standard_brand_id, goods_sn, goods_name, sku_name, supplier_name, brand_name, " +
"standard_brand_name, goods_type, self_supplier_type, goods_number, goods_price, delivery_time, sale_type, ac_type, order_goods_type, buyer_id, batch) values (?, ?, ?, ?, " + "standard_brand_name, goods_type, self_supplier_type, goods_number, goods_price, delivery_time, sale_type, ac_type, order_goods_type, buyer_id, batch, single_pre_price) values (?, ?, ?, ?, " +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, goods_data["user_id"], goods_data["goods_id"], goods_data["supplier_id"], "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, goods_data["user_id"], goods_data["goods_id"], goods_data["supplier_id"],
goods_data["brand_id"], goods_data["standard_brand_id"], goods_data["goods_sn"], goods_data["goods_name"], goods_data["sku_name"], goods_data["supplier_name"], goods_data["brand_id"], goods_data["standard_brand_id"], goods_data["goods_sn"], goods_data["goods_name"], goods_data["sku_name"], goods_data["supplier_name"],
goods_data["brand_name"], goods_data["standard_brand_name"], goods_data["goods_type"], goods_data["self_supplier_type"], goods_data["goods_number"], goods_data["goods_price"], goods_data["brand_name"], goods_data["standard_brand_name"], goods_data["goods_type"], goods_data["self_supplier_type"], goods_data["goods_number"], goods_data["goods_price"],
goods_data["delivery_time"], goods_data["sale_type"], goods_data["ac_type"], goods_data["order_goods_type"], goods_data["buyer_id"], goods_data["batch"]) goods_data["delivery_time"], goods_data["sale_type"], goods_data["ac_type"], goods_data["order_goods_type"], goods_data["buyer_id"], goods_data["batch"], goods_data["goods_price"])
if err != nil { if err != nil {
conn.Rollback() //回滚 conn.Rollback() //回滚
return return
} }
// 添加lie_other_address // 添加lie_other_address
_, err = conn.Exec("insert into lie_other_address (order_id, address_id, order_sn, province, city, district, address, consignee, mobile, area_code, telphone) " + _, err = conn.Exec("insert into lie_other_address (order_id, address_id, order_sn, province, city, district, address, consignee, mobile) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, address_data["address_id"], address_data["order_sn"], address_data["province"], address_data["city"], "values (?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, 0, order_sn, 0, 0, 0, order_address.Address, order_address.Lianxiren, order_address.Telphone)
address_data["district"], address_data["address"], address_data["consignee"], address_data["mobile"], address_data["area_code"], address_data["telphone"])
if err != nil { if err != nil {
conn.Rollback() //回滚 conn.Rollback() //回滚
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment