You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.4 KiB
93 lines
2.4 KiB
|
5 years ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Notifications\RechargePaid;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
use Illuminate\Support\Facades\Request;
|
||
|
|
|
||
|
|
class Notifications extends CommonModel
|
||
|
|
{
|
||
|
|
protected $table = "notifications";
|
||
|
|
protected $tryTimes = 3;
|
||
|
|
protected $scheduleNumber = 10;
|
||
|
|
|
||
|
|
public function notifiable()
|
||
|
|
{
|
||
|
|
return $this->morphTo();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function sendSchedule()
|
||
|
|
{
|
||
|
|
$smsSchedule = $this
|
||
|
|
->whereNull("read_at")
|
||
|
|
->where(\DB::raw('DATEDIFF(now(),created_at)'), 0)
|
||
|
|
->whereBetween("via_sms_times", [1, $this->tryTimes])
|
||
|
|
->whereNull('via_sms_at')
|
||
|
|
->limit($this->scheduleNumber)
|
||
|
|
->with("notifiable")
|
||
|
|
->get();
|
||
|
|
foreach ($smsSchedule as $vo) {
|
||
|
|
$this->sendSms($vo);
|
||
|
|
}
|
||
|
|
|
||
|
|
$wechatSchedule = $this
|
||
|
|
->whereNull("read_at")
|
||
|
|
->where(\DB::raw('DATEDIFF(now(),created_at)'), 0)
|
||
|
|
->whereBetween("via_wechat_times", [1, $this->tryTimes])
|
||
|
|
->whereNull('via_wechat_at')
|
||
|
|
->limit($this->scheduleNumber)
|
||
|
|
->get();
|
||
|
|
foreach ($wechatSchedule as $vo) {
|
||
|
|
$this->sendWechat($vo);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function sendSms($vo)
|
||
|
|
{
|
||
|
|
$data = json_decode($vo->data, true);
|
||
|
|
|
||
|
|
switch ($vo->type) {
|
||
|
|
case RechargePaid::class:
|
||
|
|
if (isset($data["recharge_id"])) {
|
||
|
|
$recharge = Recharge::find($data["recharge_id"]);
|
||
|
|
$project = "huBdi3";
|
||
|
|
|
||
|
|
$vars = [
|
||
|
|
"customer" => $recharge->customer->name,
|
||
|
|
"money" => $recharge->money,
|
||
|
|
"order_serial" => $recharge->order ? ",相关订单号:" . $recharge->order->serial : ""
|
||
|
|
];
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!isset($project)) {
|
||
|
|
$vo->via_sms_times++;
|
||
|
|
$vo->save();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
$to = $vo->notifiable->mobile;
|
||
|
|
$result = sms($to, $vars, $project, self::class, $vo->id);
|
||
|
|
|
||
|
|
if ($result) {
|
||
|
|
$vo->via_sms_at = date("Y-m-d H:i:s");
|
||
|
|
$vo->save();
|
||
|
|
} else {
|
||
|
|
$vo->via_sms_times++;
|
||
|
|
$vo->save();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function sendWechat($vo)
|
||
|
|
{
|
||
|
|
//todo
|
||
|
|
}
|
||
|
|
|
||
|
|
function sendTemplateMsg($to, $data, $template_id, $url = "", $type = null, $linked_id = null)
|
||
|
|
{
|
||
|
|
//todo
|
||
|
|
}
|
||
|
|
}
|