如何使用Laravel在Excel指定日期前5天发送短信?
Excel导入后定时短信发送实现
完成Excel数据导入后,我希望向对应人员的手机号发送短信,发送时间为Excel中录入日期的前5天。我已使用Job命令实现相关逻辑,以下是Controller.php中的代码:
public function import(Request $request) { Excel::import(new OtherImport, $request->file('file')->store('temp')); $insuranceData = Other::query()->select('personal_insurance', 'mobile')->get(); $sentMobileNumbers = []; foreach ($insuranceData as $data) { $insuranceDate = $data->personal_insurance; $mobileNumber = $data->mobile; if (!empty($insuranceDate) && !in_array($mobileNumber, $sentMobileNumbers)) { try { $jalaliDate = Jalalian::fromFormat('Y/m/d', $insuranceDate); $carbonDate = Carbon::create($jalaliDate->getYear(), $jalaliDate->getMonth(), $jalaliDate->getDay()); $smsDate = $carbonDate->subDay(5); if ($smsDate->isPast()) { SendSmsJob::dispatch([$mobileNumber]); $sentMobileNumbers[] = $mobileNumber; } } catch (\Exception $e) { dd($e->getMessage()); } } } return back(); }
内容的提问来源于stack exchange,提问作者Mahmoud Khosravi
相关产品推荐
相关产品推荐

