浏览代码

Merge branch 'CRM_15.7' into debug

zwxi 1 年之前
父节点
当前提交
5a5a767618
共有 2 个文件被更改,包括 47 次插入9 次删除
  1. 22 4
      controllers/yb_research_signup_statistics.go
  2. 25 5
      models/yb_research_signup_statistics.go

+ 22 - 4
controllers/yb_research_signup_statistics.go

@@ -56,20 +56,38 @@ func (this *BannerController) StatisticsItem() {
 		br.ErrMsg = "参数错误"
 		return
 	}
+	var resp models.YbResearchSignupStatisticsItemsResp
+
+
 	list, err := models.GetYbResearchSignupStatisticsItemsById(bannerId)
 	if err != nil {
 		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + err.Error()
+		br.ErrMsg = "GetYbResearchSignupStatisticsItemsById,Err:" + err.Error()
 		return
 	}
-
-	var resp models.YbResearchSignupStatisticsItemsResp
 	resp.List = list
-
 	for _, v := range list {
 		resp.Total += v.Count
 	}
 
+	amountList, err := models.GetYbResearchSignupStatisticsAmount(bannerId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "GetYbResearchSignupStatisticsAmount,Err:" + err.Error()
+		return
+	}
+	for _, v := range amountList {
+		if v.Amount > 0 {
+			resp.HasPayed.Amount += v.Amount
+			resp.HasPayed.Count += 1
+		} else {
+			resp.NoPay.Count += 1
+		}
+	}
+	resp.NoPay.Percentage = resp.NoPay.Count * 100 / resp.Total
+	resp.HasPayed.Percentage = resp.HasPayed.Count * 100 / resp.Total
+
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 25 - 5
models/yb_research_signup_statistics.go

@@ -74,8 +74,15 @@ type YbResearchSignupStatisticsItem struct {
 }
 
 type YbResearchSignupStatisticsItemsResp struct {
-	List  []*YbResearchSignupStatisticsItem
-	Total int
+	List     []*YbResearchSignupStatisticsItem
+	Total    int
+	HasPayed PayItem
+	NoPay    PayItem
+}
+type PayItem struct {
+	Count      int
+	Amount     float64
+	Percentage int
 }
 
 func GetYbResearchSignupStatisticsItemsById(bannerId int) (items []*YbResearchSignupStatisticsItem, err error) {
@@ -90,7 +97,7 @@ GROUP BY
 ORDER BY
 	count DESC `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql,bannerId).QueryRows(&items)
+	_, err = o.Raw(sql, bannerId).QueryRows(&items)
 	return
 }
 
@@ -105,7 +112,7 @@ WHERE
 ORDER BY
 	create_time DESC `
 	o := orm.NewOrm()
-	_, err = o.Raw(sql,mobile).QueryRows(&items)
+	_, err = o.Raw(sql, mobile).QueryRows(&items)
 	return
 }
 
@@ -115,4 +122,17 @@ func UpdateYbResearchSignupStatisticsAmountById(amount float64, id int) (err err
 	sql := `UPDATE yb_research_signup_statistics SET amount=? WHERE yb_research_signup_statistics_id=?`
 	_, err = o.Raw(sql, amount, id).Exec()
 	return
-}
+}
+
+func GetYbResearchSignupStatisticsAmount(bannerId int) (items []*YbResearchSignupStatisticsListItem, err error) {
+	sql := ` SELECT
+	a.*
+FROM
+	yb_research_signup_statistics AS a
+	INNER JOIN banner AS b ON a.banner_id = b.id 
+WHERE
+	1 = 1 AND a.banner_id = ? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, bannerId).QueryRows(&items)
+	return
+}