You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 20:42:07