123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- package service
- import (
- "database/sql"
- "encoding/json"
- "fmt"
- "time"
- "app.yhyue.com/moapp/jybase/common"
- . "bp.jydev.jianyu360.cn/BaseService/orderCenter/entity"
- "bp.jydev.jianyu360.cn/BaseService/orderCenter/rpc/ordercenter"
- )
- func GetOrderCode(*ordercenter.GetOrderCodeReq) *ordercenter.GetOrderCodeResp {
- id := Node.Generate()
- return &ordercenter.GetOrderCodeResp{
- ErrorCode: 1,
- ErrorMsg: "",
- Data: &ordercenter.OrderCode{
- OrderCode: fmt.Sprint(id),
- },
- }
- }
- func OrderAdd(this *ordercenter.OrderAddUpdateReq) *ordercenter.OrderAddUpdateResp {
- status := 0
- orderCode := fmt.Sprint(Node.Generate())
- flag := false
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- flag = Mysql.ExecTx("", func(tx *sql.Tx) bool {
- orderId := Mysql.InsertBySqlByTx(tx, `insert into `+Order+`(appid,order_code,order_money,original_price,create_time,order_status,user_id,ent_id,del_status) values (?,?,?,?,?,?,?,?,?)`,
- this.Appid, orderCode, this.Order.OrderMoney, this.Order.OriginalPrice, nowTime, this.Order.OrderStatus, this.Order.UserId, this.Order.EntId, 0)
- extendId := Mysql.InsertBySqlByTx(tx, `insert into `+OrderExtend+`(appid,order_code,pay_type,source,dis_word,iscan_invoice,iscan_evaluate,remind_status,create_time) values (?,?,?,?,?,?,?,?,?)`,
- this.Appid, orderCode, this.OrderExtend.PayType, this.OrderExtend.Source, this.OrderExtend.DisWord, this.OrderExtend.IscanInvoice, this.OrderExtend.IscanEvaluate, this.OrderExtend.RemindStatus, nowTime)
- isOk1, isOk2 := true, true
- for _, v := range this.OrderCommodity {
- commodityId := Mysql.InsertBySqlByTx(tx, `insert into `+OrderCommodity+`(appid,order_code,goods_code,goods_spec_id,num,price,total,isgift,create_time) values (?,?,?,?,?,?,?,?,?)`,
- this.Appid, orderCode, v.GoodsCode, v.GoodsSpecId, v.Num, v.Price, v.Total, v.Isgift, nowTime)
- if commodityId == 0 {
- isOk1 = false
- }
- }
- if this.OrderBusiness.GoodsSpecId != 0 {
- BusinessId := Mysql.InsertBySqlByTx(tx, `insert into `+OrderBusiness+`(appid,order_code,service_status,service_time,filter,filter_keys,filter_publishtime,data_count,filter_id,download_url,goods_code,goods_spec_id,user_phone,user_mail) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,
- this.Appid, orderCode, this.OrderBusiness.ServiceStatus, this.OrderBusiness.ServiceTime, this.OrderBusiness.Filter, this.OrderBusiness.FilterKeys,
- this.OrderBusiness.FilterPublishtime, this.OrderBusiness.DataCount, this.OrderBusiness.FilterId, this.OrderBusiness.DownloadUrl,
- this.OrderBusiness.GoodsCode, this.OrderBusiness.GoodsSpecId, this.OrderBusiness.UserPhone, this.OrderBusiness.UserMail)
- if BusinessId == 0 {
- isOk2 = false
- }
- }
- return orderId > 0 && extendId > 0 && isOk1 && isOk2
- })
- if flag {
- status = 1
- }
- return &ordercenter.OrderAddUpdateResp{
- ErrorCode: 1,
- Data: &ordercenter.DataStatus{Status: int64(status)},
- }
- }
- func OrderUpdate(this *ordercenter.OrderAddUpdateReq) *ordercenter.OrderAddUpdateResp {
- status := 0
- if this.OrderCode != "" {
- flag := false
- // nowTime := time.Now().Format("2006-01-02 15:04:05")
- flag = Mysql.ExecTx("", func(tx *sql.Tx) bool {
- isOk1, isOk2, isOk3 := true, true, true
- if this.Order.UserId > 0 {
- ok := Mysql.UpdateByTx(tx, Order, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, map[string]interface{}{
- "order_money": this.Order.OrderMoney,
- "original_price": this.Order.OriginalPrice,
- "order_status": this.Order.OrderStatus,
- "user_id": this.Order.UserId,
- "ent_id": this.Order.EntId,
- })
- if !ok {
- isOk1 = false
- }
- }
- if this.OrderExtend != nil {
- ok := Mysql.UpdateByTx(tx, OrderExtend, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, map[string]interface{}{
- "pay_type": this.OrderExtend.PayType,
- "source": this.OrderExtend.Source,
- "dis_word": this.OrderExtend.DisWord,
- "iscan_invoice": this.OrderExtend.IscanInvoice,
- "iscan_evaluate": this.OrderExtend.IscanEvaluate,
- })
- if !ok {
- isOk2 = false
- }
- }
- if this.OrderBusiness.GoodsSpecId != 0 {
- ok := Mysql.UpdateByTx(tx, OrderBusiness, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, map[string]interface{}{
- "service_status": this.OrderBusiness.ServiceStatus,
- "service_time": this.OrderBusiness.ServiceTime,
- "filter": this.OrderBusiness.Filter,
- "filter_keys": this.OrderBusiness.FilterKeys,
- "filter_publishtime": this.OrderBusiness.FilterPublishtime,
- "data_count": this.OrderBusiness.DataCount,
- "filter_id": this.OrderBusiness.FilterId,
- "download_url": this.OrderBusiness.DownloadUrl,
- "goods_code": this.OrderBusiness.GoodsCode,
- "goods_spec_id": this.OrderBusiness.GoodsSpecId,
- "user_phone": this.OrderBusiness.UserPhone,
- "user_mail": this.OrderBusiness.UserMail,
- })
- if !ok {
- isOk3 = false
- }
- }
- return isOk1 && isOk2 && isOk3
- })
- if flag {
- status = 1
- }
- }
- return &ordercenter.OrderAddUpdateResp{
- ErrorCode: 1,
- Data: &ordercenter.DataStatus{Status: int64(status)},
- }
- }
- func OrderStatusUpdate(this *ordercenter.OrderStatusUpdateReq) *ordercenter.OrderAddUpdateResp {
- status, ok := 0, false
- if this.OrderCode != "" && this.OrderStatus != 0 {
- if this.DataType == 1 {
- ok = Mysql.Update(Order, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, map[string]interface{}{"order_status": this.OrderStatus})
- } else {
- ok = JyMysql.Update(OrderOld, map[string]interface{}{"order_code": this.OrderCode}, map[string]interface{}{"order_status": this.OrderStatus})
- }
- }
- if ok {
- status = 1
- }
- return &ordercenter.OrderAddUpdateResp{
- ErrorCode: 1,
- Data: &ordercenter.DataStatus{Status: int64(status)},
- }
- }
- func OrderDel(this *ordercenter.OrderDelReq) *ordercenter.OrderAddUpdateResp {
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- ok := Mysql.Update(Order, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, map[string]interface{}{"del_time": nowTime, "del_status": 1})
- status := 0
- if ok {
- status = 1
- }
- return &ordercenter.OrderAddUpdateResp{
- ErrorCode: 1,
- Data: &ordercenter.DataStatus{Status: int64(status)},
- }
- }
- func OrderList(this *ordercenter.OrderListReq) *ordercenter.OrderListResp {
- OrderLists := []*ordercenter.OrderLists{}
- orderNew := Mysql.Find(Order, map[string]interface{}{"appid": this.Appid, "user_id": this.NewUserId}, "", "create_time desc", -1, -1)
- orderOld := JyMysql.Find(OrderOld, map[string]interface{}{"user_id": this.UserId}, "", "create_time desc", -1, -1)
- if orderNew != nil && len(*orderNew) > 0 {
- for _, v := range *orderNew {
- orderData1 := &ordercenter.OrderLists{}
- orderData2 := &ordercenter.Order{}
- orderByte, _ := json.Marshal(v)
- json.Unmarshal(orderByte, orderData2)
- orderData1.Order = orderData2
- orderData1.OrderCode = common.ObjToString(v["order_code"])
- OrderLists = append(OrderLists, orderData1)
- }
- }
- if orderOld != nil && len(*orderOld) > 0 {
- for _, v := range *orderOld {
- orderData1 := &ordercenter.OrderLists{
- OrderCode: common.ObjToString(v["order_code"]),
- Order: &ordercenter.Order{
- OrderMoney: common.Int64All(v["order_money"]),
- OriginalPrice: common.Int64All(v["original_price"]),
- OrderStatus: common.Int64All(v["order_ststus"]),
- },
- OrderBusiness: &ordercenter.OrderBusiness{
- ServiceStatus: common.Int64All(v["service_status"]),
- Filter: common.ObjToString(v["filter"]),
- FilterKeys: common.ObjToString(v["filter_keys"]),
- FilterPublishtime: common.ObjToString(v["filter_publishtime"]),
- ServiceTime: common.ObjToString(v["service_time"]),
- DataCount: common.Int64All(v["data_count"]),
- FilterId: common.ObjToString(v["filter_id"]),
- DownloadUrl: common.ObjToString(v["download_url"]),
- UserPhone: common.ObjToString(v["user_phone"]),
- UserMail: common.ObjToString(v["user_mail"]),
- // GoodsCode: 0,
- // GoodsSpecId: 0,
- },
- }
- OrderLists = append(OrderLists, orderData1)
- }
- }
- return &ordercenter.OrderListResp{
- ErrorCode: 1,
- Data: &ordercenter.OrderList{OrderList: OrderLists},
- }
- }
- func OrderInfo(this *ordercenter.OrderInfoReq) *ordercenter.OrderInfoResp {
- orderData := &ordercenter.Order{}
- orderData1 := &ordercenter.OrderAddUpdateReq{}
- order := Mysql.FindOne(Order, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, "", "")
- if order != nil && len(*order) > 0 {
- orderByte, _ := json.Marshal(*order)
- json.Unmarshal(orderByte, orderData)
- orderData1.Order = orderData
- }
- return &ordercenter.OrderInfoResp{
- ErrorCode: 1,
- Data: &ordercenter.OrderInfo{OrderInfo: orderData1},
- }
- }
|