亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Yii2 - Swiftmailer - 為每個用戶添加多個動態記錄

Yii2 - Swiftmailer - 為每個用戶添加多個動態記錄

PHP
米琪卡哇伊 2021-10-22 14:10:34
設置是這樣的:我有預訂課程的用戶/客戶。課程可以是每個日期、每個地點和每個講師的多個課程?,F在由于特定位置的不可避免的原因需要取消預訂。所以我添加了一個site_closure帶有location_name,start_date和的表end_date,并在控制器中更新 order_itemstatus與cancelled發布的日期的所有預訂site_closure下一步是我需要向用戶/客戶發送郵件,詳細說明取消的課程列表。所以在我的 site_closure 控制器創建操作中,我添加了以下代碼:public function actionCreate()    {        $model = new SiteClosure();        $st = Yii::$app->getTable;        if ($model->load(Yii::$app->request->post()) ) {            $order_items= OrderItem::find()->where(['location_id'=>$model->location_name])->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all();            $users_id_array = OrderItem::find()->select('distinct(user_id)')->where(['location_id'=>$model->location_name])->andwhere(['between', 'date', $model->from_date, $model->to_date ])->asArray()->all();            $users_id = array_values($users_id_array[0]);            $users=implode(',',$users_id);            $client_emails = User::find()->where(['in','user.id' ,$users])->asArray()->all();           // var_dump($client_emails);exit;            foreach($order_items as $order_item){                $order_item->cancellation_status="cancelled";                $order_item->save();               // $user_id.=$order_item->user_id;            }如果我迭代\Yii::$app->mailer->compose()in foreach,它將為每個類發送郵件,而我希望在單個郵件中取消該用戶的所有類。
查看完整描述

1 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

您可以將客戶的所有時間保存在一個字符串中,一個列表中,然后在電子郵件中使用它


foreach( $client_emails as  $client_email){

    $cancelled_items=OrderItem::find()->where(['location_id'=>$model->location_name] and ['user_id'=>$client_email['id']])->andwhere(['between', 'date', $model->from_date, $model->to_date ])->all();

    $body = "regarding cancellation 

    <ul>"; // create the ul element

    foreach($cancelled_items as $cancelled_item){

        $start_time = $cancelled_item->start_time;

        $body .= "<li>". $start_time."</li>"; // add the li with the start_time content inside

    }

    $body .= "</ul>"; // close the list

    \Yii::$app->mailer->compose()

    ->setFrom([$from_email => $from_name])

    ->setTo($client_email['email'])

    ->setSubject('Regarding Cancellation of Classes')

    ->setHtmlBody($body)

    ->send();

}


不要獲取取消狀態未設置為取消的用戶。$orders像這樣編輯你的變量


$order_items = OrderItem::find()->where(['location_id'=>$model->location_name])

->andwhere(['between', 'date', '', $model->from_date, $model->to_date ])

->andWhere("cancellation_status=:cancellation_status",array(':cancellation_status'=>'cancelled'))->all();



查看完整回答
反對 回復 2021-10-22
  • 1 回答
  • 0 關注
  • 119 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號