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 (
"fmt"
"go-queue-server/dal/db"
"go-queue-server/dal/order/OrderItems"
"go-queue-server/dal/order/OtherAddress"
"go-queue-server/dal/order/JingdiaoAddress"
"math/rand"
"strconv"
"time"
......@@ -23,19 +23,27 @@ func RandInt(min, max int) int {
// 随机获取竞调用户user_id
func GetJingDiaoUserId() int {
var max_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(&min_count, "select Min(user_id) from lie_user_main where is_type = 1")
//var max_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(&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
db.DB.Get(&user_id, "select user_id from lie_user_main where user_id = ? and is_type = ? limit 1", rand_num, 1)
rand_num := RandInt(1, count + 1)
if user_id == 0 {
return GetJingDiaoUserId()
}
var user_id int
db.DB.Get(&user_id, "select user_id from lie_user_id where id = ?", rand_num)
return user_id
}
......@@ -60,25 +68,41 @@ func GetOneOrderItem() OrderItems.OrderItems {
}
// 随机获取一条收货地址
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")
func GetOrderAddress() JingdiaoAddress.JingdiaoAddress {
var count int
db.DB.QueryRow("select count(*) from lie_jingdiao_address").Scan(&count)
rand_num := RandInt(min_count - 1, max_count + 1) // 从总数中取个随机数
rand_num := RandInt(1, 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)
var address JingdiaoAddress.JingdiaoAddress
db.DB.Get(&address, "select id, company, lianxiren, address, telphone from lie_jingdiao_address where id = ?", rand_num)
if order_address.OrderAddressId == 0 {
return GetOneOrderAddress()
if address.Id == 0 {
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 {
var max_count int
......
......@@ -5,9 +5,10 @@ import (
"fmt"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/dal/order/JingdiaoAddress"
"go-queue-server/dal/order/Order"
"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/util"
"strconv"
......@@ -104,7 +105,7 @@ func main() {
Order.UpdateJingDiaoOrder()
// 创建订单
for i := 0; i < order_count; i++ {
for i := 0; i < 1; i++ {
var user_id int = handle.GetJingDiaoUserId()
CreateOrder(user_id, time.Now().Unix())
}
......@@ -116,14 +117,14 @@ func main() {
func CreateOrder(user_id int, create_time int64) {
var min_amount int // 订单总额不低于随机生成数
var order_item OrderItems.OrderItems // 随机获取一条明细
var order_address OtherAddress.OtherAddress // 随机获取一条地址
var order_address JingdiaoAddress.JingdiaoAddress // 随机获取一条地址
var goods_number int // 商品数量
var order_sn string // 订单号
var order_amount float64 // 订单总额
min_amount = handle.RandInt(8000, 15000) / 100 * 100
order_item = handle.GetOneOrderItem()
order_address = handle.GetOneOrderAddress()
order_address = handle.GetOrderAddress()
goods_number = int(float64(min_amount) / order_item.GoodsPrice)
order_amount = handle.Decimal(order_item.GoodsPrice * float64(goods_number))
......@@ -132,7 +133,6 @@ func CreateOrder(user_id int, create_time int64) {
// 订单数据
order := 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["user_id"] = user_id
......@@ -164,26 +164,14 @@ func CreateOrder(user_id int, create_time int64) {
goods_data["buyer_id"] = order_item.BuyerId
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() // 开启事务
if err != nil {
return
}
// 添加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"],
order["user_id"], order["order_amount"], order["status"], create_time, order["sale_id"], order["is_type"], 1)
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_address.Address)
LastInsertId, err := res.LastInsertId()
if err != nil {
......@@ -194,22 +182,28 @@ func CreateOrder(user_id int, create_time int64) {
strInt64 := strconv.FormatInt(LastInsertId, 10)
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
_, 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 (?, ?, ?, ?, " +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, goods_data["user_id"], goods_data["goods_id"], goods_data["supplier_id"],
"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"],
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["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 {
conn.Rollback() //回滚
return
}
// 添加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) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, address_data["address_id"], address_data["order_sn"], address_data["province"], address_data["city"],
address_data["district"], address_data["address"], address_data["consignee"], address_data["mobile"], address_data["area_code"], address_data["telphone"])
_, err = conn.Exec("insert into lie_other_address (order_id, address_id, order_sn, province, city, district, address, consignee, mobile) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?)", order_id, 0, order_sn, 0, 0, 0, order_address.Address, order_address.Lianxiren, order_address.Telphone)
if err != nil {
conn.Rollback() //回滚
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