胡轶钦 6 年前
父节点
当前提交
6895a1ff5b
共有 3 个文件被更改,包括 12 次插入14 次删除
  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 查看文件

@@ -531,7 +531,7 @@ func (m *BookDAO) GetCustomerBorrowInfo(customerInfo string) (*CustomerInfo, err
531 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 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 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 535
 	where a.phone = '` + customerInfo + `' OR a.barcode = '` + customerInfo + `'
536 536
 GROUP BY a.phone`
537 537
 	err := m.db.SQL(sql).Find(&customer)

+ 3
- 3
models/customer/customer.go 查看文件

@@ -65,7 +65,7 @@ func (m *CustomerDAO) CustWithWXList(phone, username, recommendname, begindate,
65 65
 	if enddate != "" {
66 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 70
 	query = query + ` ORDER BY
71 71
 			t.create_date DESC limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
@@ -93,7 +93,7 @@ func (m *CustomerDAO) CustWithWXListCount(phone, username, recommendname, begind
93 93
 	}
94 94
 
95 95
 	if username != "" {
96
-		query += " and t.customer_name like '%" + username + "%'"
96
+		query += " and t.name like '%" + username + "%'"
97 97
 	}
98 98
 
99 99
 	if recommendname != "" {
@@ -107,7 +107,7 @@ func (m *CustomerDAO) CustWithWXListCount(phone, username, recommendname, begind
107 107
 	if enddate != "" {
108 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 111
 	var custs []model.TaCustomer
112 112
 	err := m.db.Sql(query, models.STATUS_DEL).Find(&custs)
113 113
 

+ 8
- 10
models/task.go 查看文件

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