/
home
/
henzagold
/
server
/
app
/
Models
/
File Upload :
llllll
Current File: /home/henzagold/server/app/Models/Notify.php
<?php namespace App\Models; use App\DB\Selector; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Log; use LaravelFCM\Message\OptionsBuilder; use LaravelFCM\Message\PayloadDataBuilder; use LaravelFCM\Message\PayloadNotificationBuilder; use LaravelFCM\Facades\FCM as FCM; class Notify extends Model { protected $table = 'notify'; use HasFactory; //use Selector; protected $fillable = [ 'title', 'customer_id', 'user_id', 'note', 'read', 'value', 'type', 'type_send', 'sender_id' ]; protected $casts = [ 'read' => 'boolean' ]; public static $TYPES = [ 1 => 'سفارش', 2 => 'درخواست تسویه', 3 => 'پردازش سفارش' ]; public static $TYPES_SEND = [ 1=>'کارشناسان فروش', 2=>'مشتریان عمده', 3=>'یک مشتری', 4=>'همه مشتریان', 5=>'یک مدیر', 6=>'همه مدیران' ]; public function scopeMe($query) { return $query->where(function ($qq) { return $qq->where('customer_id', auth()->id()); }); } public static function store($token = null,$title,$body){ //Log::info("send notification"); //Log::info("this is token ".$token); if($token==null) return; $optionBuilder = new OptionsBuilder(); $optionBuilder->setTimeToLive(60*20); $notificationBuilder = new PayloadNotificationBuilder($title); $notificationBuilder->setBody($body); $dataBuilder = new PayloadDataBuilder(); $option = $optionBuilder->build(); $notification = $notificationBuilder->build(); $data = $dataBuilder->build(); // if (is_null($token)){ // $token = auth('customer')->user()->token_mobile; // } $downstreamResponse = FCM::sendTo($token, $option, $notification, $data); $downstreamResponse->numberSuccess(); $downstreamResponse->numberFailure(); $downstreamResponse->numberModification(); $downstreamResponse->tokensToDelete(); $downstreamResponse->tokensToModify(); $downstreamResponse->tokensToRetry(); $downstreamResponse->tokensWithError(); /*$customer = Customer::where('token_mobile',$token)->first(); Notify::create([ 'payload'=>$title, 'owner_id'=>$customer->id, ]);*/ } public static function sendToGroup($tokens = [],$title,$body){ //$notificationKey = ['a_notification_key']; $notificationBuilder = new PayloadNotificationBuilder($title); $notificationBuilder->setBody($body)->setSound('default'); $notification = $notificationBuilder->build(); $groupResponse = FCM::sendToGroup($tokens, null, $notification, null); $groupResponse->numberSuccess(); $groupResponse->numberFailure(); $groupResponse->tokensFailed(); } }
Copyright ©2k19 -
Hexid
|
Tex7ure