Browse Source

Merge branch 'CRM_15.7'

zwxi 9 months ago
parent
commit
47e6827eba

+ 164 - 0
controllers/yb_research_signup_statistics.go

@@ -0,0 +1,164 @@
+package controllers
+
+import (
+	"hongze/hz_crm_api/models"
+)
+
+// @Title 调研报名统计列表
+// @Description 获取分类
+// @Success 200 {object} models.BannerListResp
+// @router /research_statistics/list [get]
+func (this *BannerController) StatisticsList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	list, err := models.GetYbResearchSignupStatisticsItems()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.YbResearchSignupStatisticsResp)
+
+	for _, v := range list {
+		if v.Enable == 1 {
+			resp.OngoingList = append(resp.OngoingList, v)
+		} else {
+			resp.OverList = append(resp.OverList, v)
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 调研报名统计列表
+// @Description 获取分类
+// @Param   BannerId   query   int  true       "图片id"
+// @Success 200 {object} models.BannerListResp
+// @router /research_statistics/item [get]
+func (this *BannerController) StatisticsItem() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	bannerId, _ := this.GetInt("BannerId")
+
+	if bannerId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	var resp models.YbResearchSignupStatisticsItemsResp
+
+
+	list, err := models.GetYbResearchSignupStatisticsItemsById(bannerId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "GetYbResearchSignupStatisticsItemsById,Err:" + err.Error()
+		return
+	}
+	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.HasPayed.Name = "已付款"
+	resp.NoPay.Name = "未付款"
+	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 = "获取成功"
+	br.Data = resp
+}
+
+// @Title 调研报名统计列表
+// @Description 获取分类
+// @Param   Mobile   query   int  true       "分享人手机号"
+// @Success 200 {object} models.BannerListResp
+// @router /research_statistics/detail [get]
+func (this *BannerController) StatisticsDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	mobile := this.GetString("Mobile")
+	bannerId, _ := this.GetInt("BannerId")
+
+	if mobile == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	list, err := models.GetYbResearchSignupStatisticsItemsByMobile(mobile, bannerId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}
+
+// @Title 调研报名统计列表
+// @Description 获取分类
+// @Param   Amount   query   float64  true       "付款金额"
+// @Param   YbResearchSignupStatisticsId   query   int  true       "报名id"
+// @Success 200 {object} models.BannerListResp
+// @router /research_statistics/amount [get]
+func (this *BannerController) Amount() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	ybResearchSignupStatisticsId, _ := this.GetInt("YbResearchSignupStatisticsId")
+	amount, _ := this.GetFloat("Amount")
+
+	if ybResearchSignupStatisticsId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+
+	err := models.UpdateYbResearchSignupStatisticsAmountById(amount, ybResearchSignupStatisticsId)
+	if err != nil {
+		br.Msg = "更新付款金额失败"
+		br.ErrMsg = "UpdateYbResearchSignupStatisticsAmountById,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "修改成功"
+}

+ 140 - 0
models/yb_research_signup_statistics.go

@@ -0,0 +1,140 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// YbResearchSignupStatistics 调研报名统计结构体
+type YbResearchSignupStatistics struct {
+	YbResearchSignupStatisticsId int       // 主键ID
+	UserId                       int       // 分享人ID
+	RealName                     string    // 分享人姓名
+	Mobile                       string    // 分享人手机号
+	CompanyName                  string    // 公司名称
+	BannerId                     int       // 活动ID
+	CreateTime                   time.Time // 创建时间
+	Amount                       float64   // 付款金额
+	CustomName                   string    // 报名人姓名
+	CustomMobile                 string    // 报名人手机号
+	CustomCompanyName            string    // 报名人公司名称
+}
+
+type YbResearchSignupStatisticsListItem struct {
+	YbResearchSignupStatisticsId int     // 主键ID
+	BannerId                     int     // 活动ID
+	Amount                       float64 // 付款金额
+	Count                        int     // 报名人数
+	Remark                       string  // 备注-活动名称
+	StartDate                    string  // 活动开始时间
+	EndDate                      string  // 活动结束时间
+	Enable                       int     // 1:有效,0:禁用
+}
+
+func GetYbResearchSignupStatisticsItems() (items []*YbResearchSignupStatisticsListItem, err error) {
+	sql := ` SELECT
+	a.*,
+	b.start_date,
+	b.end_date,
+	b.remark,
+	b.enable,
+	COUNT( 1 ) AS count 
+FROM
+	yb_research_signup_statistics AS a
+	INNER JOIN banner AS b ON a.banner_id = b.id 
+WHERE
+	1 = 1 
+GROUP BY
+	a.banner_id 
+ORDER BY
+	start_date DESC `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+type YbResearchSignupStatisticsResp struct {
+	OngoingList []*YbResearchSignupStatisticsListItem
+	OverList    []*YbResearchSignupStatisticsListItem
+}
+
+type YbResearchSignupStatisticsItem struct {
+	YbResearchSignupStatisticsId int     // 主键ID
+	UserId                       int     // 分享人ID
+	RealName                     string  // 分享人姓名
+	Mobile                       string  // 分享人手机号
+	CompanyName                  string  // 公司名称
+	BannerId                     int     // 活动ID
+	CreateTime                   string  // 创建时间
+	Amount                       float64 // 付款金额
+	CustomName                   string  // 报名人姓名
+	CustomMobile                 string  // 报名人手机号
+	CustomCompanyName            string  // 报名人公司名称
+	Count                        int     // 报名人数
+	Enable                       int     // 1:有效,0:禁用
+}
+
+type YbResearchSignupStatisticsItemsResp struct {
+	List     []*YbResearchSignupStatisticsItem
+	Total    int
+	HasPayed PayItem
+	NoPay    PayItem
+}
+type PayItem struct {
+	Name       string
+	Count      int
+	Amount     float64
+	Percentage int
+}
+
+func GetYbResearchSignupStatisticsItemsById(bannerId int) (items []*YbResearchSignupStatisticsItem, err error) {
+	sql := ` SELECT
+	*,count(1) as count
+FROM
+	yb_research_signup_statistics 
+WHERE
+	1 = 1 and banner_id = ?
+GROUP BY
+	mobile 
+ORDER BY
+	count DESC `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, bannerId).QueryRows(&items)
+	return
+}
+
+func GetYbResearchSignupStatisticsItemsByMobile(mobile string, bannerId int) (items []*YbResearchSignupStatisticsItem, err error) {
+	sql := `SELECT
+	a.*,b.enable
+FROM
+	yb_research_signup_statistics AS a
+	INNER JOIN banner AS b ON a.banner_id = b.id 
+WHERE
+	1 = 1 AND mobile = ? and banner_id = ? 
+ORDER BY
+	create_time DESC `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, mobile, bannerId).QueryRows(&items)
+	return
+}
+
+// UpdateYbResearchSignupStatistics 更新付款金额
+func UpdateYbResearchSignupStatisticsAmountById(amount float64, id int) (err error) {
+	o := orm.NewOrm()
+	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
+}

+ 36 - 0
routers/commentsRouter.go

@@ -8899,6 +8899,42 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"],
+        beego.ControllerComments{
+            Method: "Amount",
+            Router: `/research_statistics/amount`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"],
+        beego.ControllerComments{
+            Method: "StatisticsDetail",
+            Router: `/research_statistics/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"],
+        beego.ControllerComments{
+            Method: "StatisticsItem",
+            Router: `/research_statistics/item`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"],
+        beego.ControllerComments{
+            Method: "StatisticsList",
+            Router: `/research_statistics/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:BannerController"],
         beego.ControllerComments{
             Method: "BannerStatistic",