package db import ( "applet/app/db/model" "applet/app/utils" "fmt" "github.com/syyongx/php2go" "strings" "xorm.io/xorm" ) func GetOrderGoodsListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoods, int64) { var order []model.OrderGoods sess := eg.Where("state!=5 and goods_type=0") if param["sorting"] == "1" { sess.And("state!=4") } if param["oid"] != "" { sess.And("oid = ?", param["oid"]) } if param["gid"] != "" { sess.And("goods_id = ?", param["gid"]) } if param["sku_id"] != "" { sess.And("sku_id = ?", param["sku_id"]) } if param["state"] != "" { sess.And("state =?", param["state"]) } if param["keyword"] != "" { sess.And("goods_title like ?", "%"+param["keyword"]+"%") } size := utils.StrToInt(param["limit"]) start := (utils.StrToInt(param["page"]) - 1) * size count, err := sess.Limit(size, start).OrderBy("make_date asc,id asc").FindAndCount(&order) if err != nil { return nil, count } return &order, count } func GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods { var order model.OrderGoods get, err := eg.Where("id=?", id).Get(&order) if get == false || err != nil { return nil } return &order } func GetOrderGoodsByIds(sess *xorm.Session, id string) *[]model.OrderGoods { var order []model.OrderGoods err := sess.Where("oid=?", id).Find(&order) if err != nil { return nil } return &order } func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods { var order model.OrderGoods get, err := sess.Where("id=?", id).Get(&order) if get == false || err != nil { return nil } return &order } func GetOrderGoods(sess *xorm.Session, oid, gid, skuId string) *model.OrderGoods { var data model.OrderGoods get, err := sess.Where("oid=? and goods_id=? and sku_id=?", oid, gid, skuId).Get(&data) if err != nil || get == false { return nil } return &data } func GetOrderGoodsAll(sess *xorm.Session, oid string) *[]model.OrderGoods { var order []model.OrderGoods err := sess.Where("oid=? and goods_type=0", oid).Find(&order) if err != nil { return nil } return &order } func GetOrderGoodsByOid(eg *xorm.Engine, oid []int64) *[]model.OrderGoods { var order []model.OrderGoods err := eg.In("oid", oid).And("goods_type=0").Find(&order) if err != nil { return nil } return &order } func GetOrderGoodsList(eg *xorm.Engine, param map[string]string) ([]map[string]string, int64) { where := "goods_type=0" if param["phone"] != "" { where += " and o.buy_phone like '%" + param["phone"] + "%'" } if param["oid"] != "" { where += " and o.oid like '%" + param["oid"] + "%'" } if param["ord_no"] != "" { where += " and o.ord_no like '%" + param["ord_no"] + "%'" } if param["goods_title"] != "" { where += " and og.goods_title like '%" + param["goods_title"] + "%'" } if param["state"] != "" { where += " and o.state =" + param["state"] } if param["start_at"] != "" { where += " and o.create_at >='" + param["start_at"] + "'" } if param["end_at"] != "" { where += " and o.create_at <='" + param["end_at"] + "'" } if param["date"] != "" { param["date"] = strings.ReplaceAll(param["date"], "-", "") where += " and o.date ='" + param["date"] + "'" } if param["make_date"] != "" { param["make_date"] = strings.ReplaceAll(param["make_date"], "-", "") where += " and o.make_date ='" + param["make_date"] + "'" } if param["enterprise_name"] != "" { var enterprise []model.Enterprise eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) oids := []string{"-1"} for _, v := range enterprise { oids = append(oids, utils.IntToStr(v.Id)) } where += " and o.enterprise_id in(" + php2go.Implode(",", oids) + ")" } if param["inside_name"] != "" { var enterprise []model.Enterprise eg.Where("inside_name like ?", "%"+param["inside_name"]+"%").Find(&enterprise) oids := []string{"-1"} for _, v := range enterprise { oids = append(oids, utils.IntToStr(v.Id)) } where += " and o.enterprise_id in(" + php2go.Implode(",", oids) + ")" } size := utils.StrToInt(param["limit"]) start := (utils.StrToInt(param["page"]) - 1) * size sql := "SELECT %s FROM order_goods og left join `order` o on o.oid=og.oid where %s order by og.id desc %s" sql1 := fmt.Sprintf(sql, "og.deduct_memo,og.oid,og.goods_id,og.sku_id,og.num,og.price,og.state,og.sku_code,og.goods_title,og.sku,og.success_num,og.memo,og.time,og.admin_id,og.enterprise_id,og.deduct_memo,og.ord_no,og.make_date,o.create_at,o.buy_info,o.buy_phone", where, "limit "+utils.IntToStr(start)+","+utils.IntToStr(size)) sql2 := fmt.Sprintf(sql, "COUNT(*) as count", where, "") nativeString, _ := QueryNativeString(eg, sql2) count := 0 for _, v := range nativeString { count = utils.StrToInt(v["count"]) } nativeString1, _ := QueryNativeString(eg, sql1) return nativeString1, int64(count) }