胡轶钦 6 years ago
parent
commit
6895a1ff5b
3 changed files with 12 additions and 14 deletions
  1. 1
    1
      models/book/book.go
  2. 3
    3
      models/customer/customer.go
  3. 8
    10
      models/task.go

+ 1
- 1
models/book/book.go View File

531
 	(select count(1) from ta_book_borrow_record c WHERE borrow_status = '1' and c.customer_id = a.customer_id)as borrow_num,
531
 	(select count(1) from ta_book_borrow_record c WHERE borrow_status = '1' and c.customer_id = a.customer_id)as borrow_num,
532
 	(select count(1) from ta_book_borrow_record c WHERE borrow_status = '0' and c.customer_id = a.customer_id)as late_num
532
 	(select count(1) from ta_book_borrow_record c WHERE borrow_status = '0' and c.customer_id = a.customer_id)as late_num
533
 FROM
533
 FROM
534
-	ta_customer a INNER JOIN ta_book_borrow_record b on a.customer_id = b.customer_id 
534
+	ta_customer a LEFT JOIN ta_book_borrow_record b on a.customer_id = b.customer_id 
535
 	where a.phone = '` + customerInfo + `' OR a.barcode = '` + customerInfo + `'
535
 	where a.phone = '` + customerInfo + `' OR a.barcode = '` + customerInfo + `'
536
 GROUP BY a.phone`
536
 GROUP BY a.phone`
537
 	err := m.db.SQL(sql).Find(&customer)
537
 	err := m.db.SQL(sql).Find(&customer)

+ 3
- 3
models/customer/customer.go View File

65
 	if enddate != "" {
65
 	if enddate != "" {
66
 		query = query + ` AND t.create_date<'` + begindate + `'`
66
 		query = query + ` AND t.create_date<'` + begindate + `'`
67
 	}
67
 	}
68
-	query = query + ` AND t.customer_name <> ''`
68
+	query = query + ` AND (t.customer_name <> '' and t.headimgurl <> '' and t.phone <>'')`
69
 
69
 
70
 	query = query + ` ORDER BY
70
 	query = query + ` ORDER BY
71
 			t.create_date DESC limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
71
 			t.create_date DESC limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
93
 	}
93
 	}
94
 
94
 
95
 	if username != "" {
95
 	if username != "" {
96
-		query += " and t.customer_name like '%" + username + "%'"
96
+		query += " and t.name like '%" + username + "%'"
97
 	}
97
 	}
98
 
98
 
99
 	if recommendname != "" {
99
 	if recommendname != "" {
107
 	if enddate != "" {
107
 	if enddate != "" {
108
 		query = query + ` AND t.create_date<'` + begindate + `'`
108
 		query = query + ` AND t.create_date<'` + begindate + `'`
109
 	}
109
 	}
110
-
110
+	query = query + ` AND (t.customer_name <> '' and t.headimgurl <> '' and t.phone <>'')`
111
 	var custs []model.TaCustomer
111
 	var custs []model.TaCustomer
112
 	err := m.db.Sql(query, models.STATUS_DEL).Find(&custs)
112
 	err := m.db.Sql(query, models.STATUS_DEL).Find(&custs)
113
 
113
 

+ 8
- 10
models/task.go View File

13
 func InitTask() {
13
 func InitTask() {
14
 	kernel := utils.NewKernel()
14
 	kernel := utils.NewKernel()
15
 	kernel.SetTask("sendmessage", SendMessageToCustomer)
15
 	kernel.SetTask("sendmessage", SendMessageToCustomer)
16
-	timeStr := time.Now().Format("2006-01-02") + beego.AppConfig.String("job::sendmessagetime")
17
-	ten, _ := time.Parse(timeStr, "2006-01-02 15:04:05")
16
+	now := time.Now().Local()
17
+	timeStr := now.Format("2006-01-02") + " " + beego.AppConfig.String("job::sendmessagetime")
18
+	ten, _ := time.ParseInLocation("2006-01-02 15:04:05", timeStr, time.Local)
18
 	var tomorrow time.Time
19
 	var tomorrow time.Time
19
-	if time.Now().Before(ten) {
20
+	if now.Before(ten) {
20
 		tomorrow = ten
21
 		tomorrow = ten
21
 	} else {
22
 	} else {
22
 		tomorrow = ten.AddDate(0, 0, 1)
23
 		tomorrow = ten.AddDate(0, 0, 1)
23
 	}
24
 	}
24
-	dur := tomorrow.Sub(time.Now())
25
-
25
+	dur := tomorrow.Sub(now)
26
+	beego.Error(dur)
26
 	kernel.StartTask("sendmessage", dur)
27
 	kernel.StartTask("sendmessage", dur)
27
 }
28
 }
28
 
29
 
53
 	DATE_FORMAT( a.end_date, "%Y-%m-%d" ) = DATE_FORMAT( ( SELECT date_add( now( ), INTERVAL 1 WEEK ) ), "%Y-%m-%d" )
54
 	DATE_FORMAT( a.end_date, "%Y-%m-%d" ) = DATE_FORMAT( ( SELECT date_add( now( ), INTERVAL 1 WEEK ) ), "%Y-%m-%d" )
54
 	and a.borrow_status = '1'`
55
 	and a.borrow_status = '1'`
55
 	DBEngine.Sql(sql).Find(&weekList)
56
 	DBEngine.Sql(sql).Find(&weekList)
56
-	beego.Error("________________________sql", sql)
57
-	beego.Error("________________________weekList", weekList)
58
 	var lateList []TimeRecordList
57
 	var lateList []TimeRecordList
59
 	sqlLate := `SELECT
58
 	sqlLate := `SELECT
60
 	a.*,
59
 	a.*,
70
 	DATE_FORMAT( now(), "%Y-%m-%d" ) = DATE_FORMAT( ( SELECT date_add( a.end_date, INTERVAL 2 DAY ) ), "%Y-%m-%d" )
69
 	DATE_FORMAT( now(), "%Y-%m-%d" ) = DATE_FORMAT( ( SELECT date_add( a.end_date, INTERVAL 2 DAY ) ), "%Y-%m-%d" )
71
 	and a.borrow_status = '0'`
70
 	and a.borrow_status = '0'`
72
 	DBEngine.Sql(sqlLate).Find(&lateList)
71
 	DBEngine.Sql(sqlLate).Find(&lateList)
73
-	beego.Error("________________________sql", sqlLate)
74
-	beego.Error("________________________weekList", lateList)
75
 	// 发消息
72
 	// 发消息
76
 	if len(weekList) > 0 {
73
 	if len(weekList) > 0 {
77
 		for i := 0; i < len(weekList); i++ {
74
 		for i := 0; i < len(weekList); i++ {
96
 				continue
93
 				continue
97
 			}
94
 			}
98
 			utils.WxClientSingleton(weekList[i].OrgId, cert)
95
 			utils.WxClientSingleton(weekList[i].OrgId, cert)
96
+			time.Sleep(5 * time.Second)
99
 			go utils.SendWechat(message)
97
 			go utils.SendWechat(message)
100
 		}
98
 		}
101
 	}
99
 	}
122
 				continue
120
 				continue
123
 			}
121
 			}
124
 			utils.WxClientSingleton(weekList[i].OrgId, cert)
122
 			utils.WxClientSingleton(weekList[i].OrgId, cert)
123
+			time.Sleep(5 * time.Second)
125
 			go utils.SendWechat(message)
124
 			go utils.SendWechat(message)
126
 		}
125
 		}
127
 	}
126
 	}
128
 	timeNext, _ := time.ParseDuration("24h")
127
 	timeNext, _ := time.ParseDuration("24h")
129
-	beego.Error("___________________timeNext", timeNext)
130
 	return timeNext
128
 	return timeNext
131
 }
129
 }