aa
This commit is contained in:
@@ -283,3 +283,104 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
type GetManageStateResult struct {
|
||||
OpenStoreCount int `json:"openStoreCount"` //营业店铺数
|
||||
HaveRestStoreCount int `json:"haveRestStoreCount"` //临时休息店铺数
|
||||
RestStoreCount int `json:"restStoreCount"` //休息店铺数
|
||||
FinishOrderState *GetManageStateOrderInfo //完成订单情况
|
||||
IngOrderState *GetManageStateOrderInfo //进行中订单情况
|
||||
CancelOrderState *GetManageStateOrderInfo //取消订单情况
|
||||
}
|
||||
|
||||
type GetManageStateOrderInfo struct {
|
||||
ActualPayPrice int `json:"actualPayPrice"` //支付总额
|
||||
TotalShopMoney int `json:"totalShopMoney"` //平台结算
|
||||
DesiredFee int `json:"desiredFee"` //配送费
|
||||
Yhld string `json:"yhld"` //优惠力度(支付总额-平台结算-配送支出)/支付总额*100%
|
||||
}
|
||||
|
||||
func getStoreStatusCount(db *dao.DaoDB, cityCodes []int, vendorID, status int) (count int, err error) {
|
||||
countType := &struct{ Count int }{}
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT COUNT(a.id) count
|
||||
FROM store a
|
||||
LEFT JOIN store_map b ON a.id = b.store_id AND b.deleted_at = ?
|
||||
`
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND a.city_code IN (" + dao.GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND b.vendor_id = ? AND b.status = ?"
|
||||
sqlParams = append(sqlParams, vendorID, status)
|
||||
} else {
|
||||
sql += " AND a.status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
sql += `
|
||||
WHERE a.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, utils.DefaultTimeValue)
|
||||
err = dao.GetRow(db, &countType, sql, sqlParams)
|
||||
return countType.Count, err
|
||||
}
|
||||
|
||||
func getOrderStateCount(db *dao.DaoDB, cityCodes []int, vendorID, status int) (getManageStateOrderInfo *GetManageStateOrderInfo, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
endTime := time.Now().AddDate(0, -3, 0)
|
||||
sql := `
|
||||
SELECT SUM(b.actual_pay_price) actual_pay_price, SUM(b.total_shop_money) total_shop_money, SUM(IFNULL(c.desired_fee, 0)) desired_fee
|
||||
FROM store a
|
||||
LEFT JOIN goods_order b ON a.id = IF(b.jx_store_id = 0, b.store_id, b.jx_store_id)
|
||||
LEFT JOIN waybill c ON IF(a.waybill_vendor_id = -1,a.vendor_order_id,a.vendor_waybill_id) = b.vendor_waybill_id
|
||||
WHERE a.deleted_at = ? AND a.status <> ?
|
||||
AND b.order_created_at < ? AND b.order_created_at > ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.StoreStatusDisabled, time.Now(), endTime)
|
||||
if len(cityCodes) > 0 {
|
||||
sql += " AND a.city_code IN (" + dao.GenQuestionMarks(len(cityCodes)) + ")"
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
if vendorID != -1 {
|
||||
sql += " AND b.vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID, status)
|
||||
}
|
||||
if status != model.OrderStatusDelivering {
|
||||
sql += " AND b.status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
} else {
|
||||
sql += " AND b.status < ? AND b.status >= ?"
|
||||
sqlParams = append(sqlParams, model.OrderStatusEndBegin, model.OrderStatusWait4Pay)
|
||||
}
|
||||
err = dao.GetRow(db, &getManageStateOrderInfo, sql, sqlParams)
|
||||
getManageStateOrderInfo.Yhld = utils.Float64ToStr((float64(getManageStateOrderInfo.ActualPayPrice-getManageStateOrderInfo.TotalShopMoney-getManageStateOrderInfo.DesiredFee) / float64(getManageStateOrderInfo.ActualPayPrice) * 100)) + "%"
|
||||
return getManageStateOrderInfo, err
|
||||
}
|
||||
|
||||
func GetManageState(ctx *jxcontext.Context, cityCodes []int, vendorID int) (getManageStateResult *GetManageStateResult, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
getManageStateResult = &GetManageStateResult{}
|
||||
if openCount, err := getStoreStatusCount(db, cityCodes, vendorID, model.StoreStatusOpened); err == nil {
|
||||
getManageStateResult.OpenStoreCount = openCount
|
||||
}
|
||||
if haveRestCount, err := getStoreStatusCount(db, cityCodes, vendorID, model.StoreStatusHaveRest); err == nil {
|
||||
getManageStateResult.HaveRestStoreCount = haveRestCount
|
||||
}
|
||||
if restCount, err := getStoreStatusCount(db, cityCodes, vendorID, model.StoreStatusClosed); err == nil {
|
||||
getManageStateResult.RestStoreCount = restCount
|
||||
}
|
||||
if finishCount, err := getOrderStateCount(db, cityCodes, vendorID, model.OrderStatusFinished); err == nil {
|
||||
getManageStateResult.FinishOrderState = finishCount
|
||||
}
|
||||
if ingCount, err := getOrderStateCount(db, cityCodes, vendorID, model.OrderStatusDelivering); err == nil {
|
||||
getManageStateResult.IngOrderState = ingCount
|
||||
}
|
||||
if cancelCount, err := getOrderStateCount(db, cityCodes, vendorID, model.OrderStatusCanceled); err == nil {
|
||||
getManageStateResult.CancelOrderState = cancelCount
|
||||
}
|
||||
return getManageStateResult, err
|
||||
}
|
||||
|
||||
@@ -96,3 +96,21 @@ func (c *ReportController) AutoFocusStoreSkus() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查询经营概况
|
||||
// @Description 查询经营概况
|
||||
// @Param token header string true "认证token"
|
||||
// @Param cityCodes query string false "城市ID列表[1,2,3]"
|
||||
// @Param vendorID query int false "vendorID 全部传-1"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetManageState [get]
|
||||
func (c *ReportController) GetManageState() {
|
||||
c.callGetManageState(func(params *tReportGetManageStateParams) (retVal interface{}, errCode string, err error) {
|
||||
var cityCodes []int
|
||||
if err = jxutils.Strings2Objs(params.CityCodes, &cityCodes); err == nil {
|
||||
retVal, err = report.GetManageState(params.Ctx, cityCodes, params.VendorID)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1539,6 +1539,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetManageState",
|
||||
Router: `/GetManageState`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"],
|
||||
beego.ControllerComments{
|
||||
Method: "PriceRefer",
|
||||
|
||||
Reference in New Issue
Block a user