我必須在數據庫中添加一些條目才能向用戶發送通知,但條件看起來像這樣,這是我的結束日期06-05-2019,現在的當前日期是03-05-2019或01-05-2019,我想在結束日期的3天之前發送通知到實際的結束日期。就像,我的結束日期是06-05-2019某些事件的話,我想在日期發送的通知04-05-2019,05-05-2019,06-05-2019。我的cakePHP查詢代碼在這里:$offer_notify_second = $this->NotificationStore->find('all', array( 'contain' => array(), 'fields' => array('NotificationStore.id','NotificationStore.role_id','NotificationStore.user_id','NotificationStore.notification_type','NotificationStore.notification_app_display_type','NotificationStore.link','NotificationStore.offer_id','NotificationStore.offer_type'), 'conditions' => array('DATE_SUB(NotificationStore.end_date, INTERVAL 3 DAY)' => date('Y-m-d'), 'NotificationStore.user_id' => $this->request->data['user_id'], 'NotificationStore.notification_type' => OFFER_NOTIFICATION), ));```
1 回答

阿波羅的戰車
TA貢獻1862條經驗 獲得超6個贊
我將共享原始查詢片段,您可以將其映射到CAKEPHP
WHERE NotificationStore.end_date >= DATE(NOW() + INTERVAL 3 DAY) + INTERVAL 0 SECOND AND NotificationStore.end_date >= CURDATE();
第1部分
NotificationStore.end_date >= DATE(NOW() + INTERVAL 3 DAY) + INTERVAL 0
這意味著,現在+ 3天應該大于結束日期,
例如
當前時間為2019-05-02,接下來的3天為2019-05-05,然后條件失敗
當前條件為2019-05-03,接下來的3天為2019-05-06,然后條件成功
第2部分
NotificationStore.end_date >= CURDATE()
這意味著,end_date必須大于cur_date才能滿足即將到來的3天范圍,否則在有第一個條件的情況下它將始終大于。
- 1 回答
- 0 關注
- 190 瀏覽
添加回答
舉報
0/150
提交
取消