作者 唐旭辉

实际订单列表 更新

... ... @@ -2,19 +2,17 @@ package query
//ListOrderQuery 获取用户列表
type ListOrderBaseQuery struct {
//合伙人id
PartnerId int64 `json:"partnerId" `
//订单编号
OrderCode string `json:"order_code"`
// 查询偏离量
Offset int `json:"offset" `
// 查询限制
Limit int `json:"limit"`
//发货单号
DeliveryCode string `json:"deliveryCode"`
CompanyId int64 `json:"companyId"`
PartnerOrCode string `json:"partnerOrCode"`
CompanyId int64 `json:"companyId"`
//订单类型
OrderType int `json:"orderType"`
PartnerOrCode string `json:"partner_or_code"`
OrderType int `json:"orderType"`
//合伙人分类
PartnerCategory int `json:"partnerCategory"`
UpdateTimeBegin string `json:"updateTimeBegin"`
UpdateTimeEnd string `json:"updateTimeEnd"`
}
... ...
... ... @@ -6,8 +6,8 @@ type ListOrderBonusQuery struct {
// 查询限制
Limit int `json:"limit"`
CompanyId int64 `json:"companyId"`
PartnerCategory int `json:"partner_category"`
PartnerCategory int `json:"partnerCategory"`
//订单类型
OrderType int `json:"orderType"`
PartnerOrCode string `json:"partner_or_code"`
PartnerOrCode string `json:"partnerOrCode"`
}
... ...
... ... @@ -29,7 +29,8 @@ func NewOrderInfoService(option map[string]interface{}) *OrderInfoService {
}
// PageListOrderBase 获取订单列表
func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderBaseQuery) ([]domain.OrderBase, int, error) {
func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrderBaseQuery) ([]map[string]interface{}, int, error) {
var err error
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
... ... @@ -41,28 +42,24 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
transactionContext.RollbackTransaction()
}()
var (
orderRepository domain.OrderBaseRepository
orders []domain.OrderBase
cnt int
orderDao *dao.OrderBaseDao
orders []models.OrderBase
cnt int
)
if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{
if orderDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
query := domain.OrderBaseFindQuery{
PartnerId: listOrderQuery.PartnerId,
OrderCode: listOrderQuery.OrderCode,
Offset: listOrderQuery.Offset,
Limit: listOrderQuery.Limit,
OrderType: listOrderQuery.OrderType,
DeliveryCode: listOrderQuery.DeliveryCode,
CompanyId: listOrderQuery.CompanyId,
}
orders, cnt, err = orderRepository.Find(query)
}
orders, cnt, err = orderDao.OrderListByCondition(
listOrderQuery.CompanyId,
listOrderQuery.OrderType,
listOrderQuery.PartnerOrCode,
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
listOrderQuery.PartnerCategory,
listOrderQuery.Limit, listOrderQuery.Offset,
)
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -72,6 +69,8 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderDataReturn := make([]map[string]interface{}, 0)
for i := range orders {
partnerData := &domain.PartnerInfo{}
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
... ... @@ -79,12 +78,33 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
})
if err != nil {
logs.Error("获取合伙(id=%d)失败%s", orders[i].PartnerId, err)
} else {
orders[i].PartnerInfo = partnerData.Partner
}
m := map[string]interface{}{
"createTime": orders[i].CreateTime.Local().Format("2006-01-02 15:04:05"),
"updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"),
"buyer": orders[i].Buyer.BuyerName,
"id": orders[i].Id,
"orderId": orders[i].OrderCode,
"shipmentsId": orders[i].DeliveryCode,
"partner": partnerData.Partner.PartnerName,
"orderNum": orders[i].PlanOrderCount,
"orderPrice": orders[i].PlanOrderAmount,
"orderDist": orders[i].RegionInfo.RegionName,
"quantityControl": "",
"priceControl": "",
"status": orders[i].IsDisable,
"partnerCategory": orders[i].PartnerCategory.Name,
}
if orders[i].UseOrderCount >= 0 {
m["quantityControl"] = fmt.Sprint(orders[i].UseOrderCount)
}
if orders[i].UseOrderAmount >= 0 {
m["priceControl"] = fmt.Sprint(orders[i].UseOrderAmount)
}
orderDataReturn = append(orderDataReturn, m)
}
transactionContext.CommitTransaction()
return orders, cnt, nil
return orderDataReturn, cnt, nil
}
//GetOrderDetail 获取订单详情
... ... @@ -766,6 +786,7 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde
listOrderQuery.CompanyId,
listOrderQuery.OrderType,
listOrderQuery.PartnerOrCode,
listOrderQuery.PartnerCategory,
listOrderQuery.Limit,
listOrderQuery.Offset,
)
... ...
... ... @@ -17,9 +17,10 @@ type SyncCompanyService struct{}
var _ SyncAction = (*SyncCompanyService)(nil)
type CompanyBaseApplet struct {
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
ImageUrl string `json:"image_url"`
}
//企业平台的公司基础数据
... ... @@ -114,9 +115,10 @@ func (service SyncCompanyService) addCompany(data CompanytData) error {
applets := []domain.CompanyApplets{}
for _, v := range data.Company.Applets {
app := domain.CompanyApplets{
Name: v.Name,
URL: v.URL,
Id: v.Id,
Name: v.Name,
URL: v.URL,
Id: v.Id,
ImageUrl: v.ImageUrl,
}
applets = append(applets, app)
}
... ... @@ -207,9 +209,10 @@ func (service SyncCompanyService) updateCompany(data CompanytData) error {
applets := []domain.CompanyApplets{}
for _, v := range data.Company.Applets {
app := domain.CompanyApplets{
Name: v.Name,
URL: v.URL,
Id: v.Id,
Name: v.Name,
URL: v.URL,
Id: v.Id,
ImageUrl: v.ImageUrl,
}
applets = append(applets, app)
}
... ...
... ... @@ -18,9 +18,10 @@ const (
)
type CompanyApplets struct {
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
ImageUrl string `json:"imageUrl"`
}
// 公司信息
... ...
... ... @@ -50,7 +50,8 @@ func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ..
//OrderListByCondition 根据条件获取订单分红列表
//orderType 订单类型
//partnerOrCode 合伙人姓名或订单号或发货单号
func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int, partnerOrCode string, limit, offset int) ([]models.OrderBase, int, error) {
func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int, partnerOrCode string,
partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
... ... @@ -59,6 +60,9 @@ func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int
} else {
query = query.Where("order_base.order_type<>?", domain.OrderIntention)
}
if partnerCategory > 0 {
query = query.Where(`order_base.partner_category@>'{"id":?}'`, partnerCategory)
}
if len(partnerOrCode) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
... ... @@ -76,36 +80,7 @@ func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int
return orders, cnt, err
}
//导出分红列表所用的sql
// SELECT
// ROW_NUMBER() over(ORDER BY t1.update_time DESC) AS num,
// t1.ID AS order_id,
// t1.order_type,
// t1.order_code,
// t1.bonus_status,
// to_char(t1.update_time at time zone 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time,
// (CASE
// WHEN t1.use_partner_bonus>0
// THEN
// t1.use_partner_bonus
// ELSE
// t1.plan_partner_bonus
// END) AS partner_bonus,
// t1.partner_bonus_has,
// t1.partner_bonus_not,
// t1.partner_bonus_expense,
// tt1.has_bonus_percent,
// t2.partner_name
// FROM
// order_base AS t1
// LEFT JOIN partner_info AS t2 ON t1.partner_id = t2."id"
// LEFT JOIN (
// SELECT COUNT ( * ) AS has_bonus_percent, t3.order_id
// FROM "order_good" AS t3
// WHERE t3.partner_bonus_percent >= 0
// GROUP BY t3.order_id
// ) AS tt1 ON t1."id" = tt1.order_id
//CustomOrderBonusForExcel 导出分红列表所用的结构
type CustomOrderBonusForExcel struct {
Num int
OrderId int64
... ... @@ -127,11 +102,10 @@ type CustomOrderBonusForExcel struct {
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param partnerCategory 合伙人类型id
//@return result 处理后的数据,可直接用于导出数据到excel
//@return column 数据对应的键名,例 [0][英文键名,中文名称]
//@return result 查询结果数据
func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, partnerOrCode string,
partnerCategory int) (result []CustomOrderBonusForExcel, err error) {
//导出分红列表所用的sql
sqlStr := `SELECT
t1.ID AS order_id,
t1.order_type,
... ... @@ -188,3 +162,46 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
}
return result, nil
}
//OrderListByCondition 获取实际订单列表
//@param companyId 公司id
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param partnerCategory 合伙人类型id
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2016-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, partnerOrCode string,
updateTime [2]string, partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
if orderType > 0 {
query = query.Where("order_base.order_type=?", orderType)
} else {
query = query.Where("order_base.order_type<>?", domain.OrderIntention)
}
if partnerCategory > 0 {
query = query.Where(`order_base.partner_category@>'{"id":?}'`, partnerCategory)
}
if len(updateTime[0]) > 0 {
query = query.Where(`order_base.update_time>=?`, updateTime[0])
}
if len(updateTime[1]) > 0 {
query = query.Where(`order_base.update_time<=?`, updateTime[1])
}
if len(partnerOrCode) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q = q.WhereOr("order_base.order_code like ? ", "%"+partnerOrCode+"%").
WhereOr("order_base.delivery_code like ? ", "%"+partnerOrCode+"%").
WhereOr("p.partner_name like ? ", "%"+partnerOrCode+"%")
return q, nil
})
}
query = query.Order("order_base.update_time DESC").
Offset(offset).
Limit(limit)
cnt, err := query.SelectAndCount()
return orders, cnt, err
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"unicode/utf8"
"github.com/astaxie/beego/logs"
... ... @@ -410,10 +411,12 @@ func (postData *postOrderPurposeDelivery) Valid() error {
//PageListOrderReal 获取实发订单列表
func (c *OrderInfoController) PageListOrderReal() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
SearchText string `json:"searchText"`
PartnerCategory int `json:"PartnerCategory"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
UpdateTimeBegin string `json:"updateTimeBegin"`
UpdateTimeEnd string `json:"updateTimeEnd"`
}
var (
param Parameter
... ... @@ -430,47 +433,39 @@ func (c *OrderInfoController) PageListOrderReal() {
if param.PageSize == 0 {
param.PageSize = 20
}
if len(param.UpdateTimeBegin) > 0 {
t, err := time.Parse("2016-01-02 15:04:05+07", param.UpdateTimeBegin)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
param.UpdateTimeBegin = t.Format("2016-01-02 15:04:05+07")
}
if len(param.UpdateTimeEnd) > 0 {
t, err := time.Parse("2016-01-02 15:04:05+07", param.UpdateTimeEnd)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
param.UpdateTimeEnd = t.Format("2016-01-02 15:04:05+07")
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
PartnerId: param.Partner,
DeliveryCode: param.SearchText,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerOrCode: param.SearchText,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: param.UpdateTimeBegin,
UpdateTimeEnd: param.UpdateTimeEnd,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"createTime": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"shipmentsId": orderinfo.DeliveryCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"orderNum": orderinfo.OrderCompute.PlanOrderCount,
"orderPrice": orderinfo.OrderCompute.PlanOrderAmount,
"orderDist": orderinfo.RegionInfo.RegionName,
"quantityControl": "",
"priceControl": "",
"status": orderinfo.IsDisable,
}
if orderinfo.OrderCompute.UseOrderCount >= 0 {
m["quantityControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
}
if orderinfo.OrderCompute.UseOrderAmount >= 0 {
m["priceControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
c.ResponsePageList(orderinfos, cnt, param.PageNumber)
return
}
... ...