modified jobs for sending mails
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
|
||||
use App\Jobs\SendEveMail;
|
||||
use Commands\Library\CommandHelper;
|
||||
use App\Library\Finances\Helper\FinanceHelper;
|
||||
use App\Library\Structures\StructureTaxHelper;
|
||||
@@ -82,8 +83,6 @@ class CalculateMarketTax extends Command
|
||||
$finalTaxes = 0.00;
|
||||
}
|
||||
|
||||
//$finalTaxes = number_format($finalTaxes, 2, '.', ',');
|
||||
|
||||
//Get the info about the structures from the database
|
||||
$info = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first();
|
||||
|
||||
@@ -100,6 +99,22 @@ class CalculateMarketTax extends Command
|
||||
$bill->year = $start->year;
|
||||
$bill->save();
|
||||
|
||||
$mail = new EveMail;
|
||||
$mail->sender = 93738489;
|
||||
$mail->subject = 'Market Taxes Owed';
|
||||
$mail->body = 'Year ' . $start->year . ' ' .
|
||||
'Month: ' .
|
||||
$start->month .
|
||||
'<br>Market Taxes Owed: ' .
|
||||
number_format($finalTaxes, 2, '.', ',') .
|
||||
'<br>Please remit to Spatial Forces';
|
||||
$mail->recipient = (int)$info->character_id;
|
||||
$mail->recipient_type = 'character';
|
||||
|
||||
SendEveMail::dispatch($mail);
|
||||
|
||||
/*
|
||||
|
||||
//Retrieve the token for main character to send mails from
|
||||
$token = EsiToken::where(['character_id' => 93738489])->first();
|
||||
|
||||
@@ -138,7 +153,10 @@ class CalculateMarketTax extends Command
|
||||
} catch(RequestFailedException $e) {
|
||||
$this->line('Error is ' . $e);
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//Mark the job as finished
|
||||
$task->SetStopStatus();
|
||||
|
||||
@@ -8,7 +8,10 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
use App\Library\Esi\Mail;
|
||||
use Seat\Eseye\Configuration;
|
||||
use Seat\Eseye\Containers\EsiAuthentication;
|
||||
use Seat\Eseye\Eseye;
|
||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
|
||||
use App\Models\EveMail as EveMailModel;
|
||||
|
||||
@@ -21,6 +24,20 @@ class SendEveMail implements ShouldQueue
|
||||
*/
|
||||
protected $eveMail;
|
||||
|
||||
/**
|
||||
* Timeout in seconds
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 120;
|
||||
|
||||
/**
|
||||
* Retries
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $retries = 3;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@@ -43,21 +60,36 @@ class SendEveMail implements ShouldQueue
|
||||
//Access the model in the queue for processing
|
||||
$mail = $this->eveMail;
|
||||
|
||||
//Create a new Mail class variable
|
||||
$esi = new Mail();
|
||||
//Retrieve the token for main character to send mails from
|
||||
$token = EsiToken::where(['character_id'=> 93738489])->get();
|
||||
|
||||
//Process the mail from the model to send a new mail
|
||||
$esi->SendGeneralMail($mail->recepient, $mail->subject, $mail->body);
|
||||
//Create the ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token->refresh_token,
|
||||
]);
|
||||
|
||||
}
|
||||
//Setup the Eseye class
|
||||
$esi = new Eseye($authentication);
|
||||
|
||||
/**
|
||||
* Determine the time the job should timeout
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function retryUntil() {
|
||||
return now()->addSeconds(5);
|
||||
//Attemp to send the mail
|
||||
try {
|
||||
$esi->setBody([
|
||||
'approved_cost' => 0,
|
||||
'body' => $mail->body,
|
||||
'recipients' => [[
|
||||
'recipient_id' => (int)$mail->recipient,
|
||||
'recipient_type' => $mail->recipient_type,
|
||||
]],
|
||||
'subject' => $mail->subject,
|
||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||
'character_id'=> 93738489,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
|
||||
class Mail {
|
||||
|
||||
public function SendGeneralMail($recipient, $subject, $body) {
|
||||
public function SendMail($recipient, $rType, $subject, $body) {
|
||||
//Retrieve the token for main character to send mails from
|
||||
$token = EsiToken::where(['character_id' => 93738489])->get();
|
||||
//Create the ESI authentication container
|
||||
@@ -28,48 +28,21 @@ class Mail {
|
||||
$esi = new Eseye($authentication);
|
||||
try {
|
||||
$esi->setBody([
|
||||
'approved_cost' => 0,
|
||||
'body' => $body,
|
||||
'receipients' => [
|
||||
'recipient_id'=> $recipient,
|
||||
'recipient_type' => 'character',
|
||||
],
|
||||
'recipients' => [[
|
||||
'recipient_id' => (int)$recipient,
|
||||
'recipient_type' => $rType,
|
||||
]],
|
||||
'subject' => $subject,
|
||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||
'character_id' => 93738489,
|
||||
'character_id'=> 93738489,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return null;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function SendMail($charId, $taxAmount, $subject, $body) {
|
||||
//Retrieve the token for Amund Risalo
|
||||
$token = DB::table('EsiTokens')->where('character_id', 93738489)->get();
|
||||
$configuration = Configuration::getInstance();
|
||||
$configuration->cache = NullCache::class;
|
||||
//Create the ESI authentication container
|
||||
$config = config('esi');
|
||||
$authentication = new EsiAuthentication([
|
||||
'client_id' => $config['client_id'],
|
||||
'secret' => $config['secret'],
|
||||
'refresh_token' => $token[0]->refresh_token,
|
||||
]);
|
||||
//Create the esi class variable
|
||||
$esi = new Eseye($authentication);
|
||||
try {
|
||||
$esi->setBody([
|
||||
'body' => $body,
|
||||
'receipients' => [
|
||||
'recipient_id'=> $charId,
|
||||
'recipient_type' => 'character',
|
||||
],
|
||||
'subject' => $subject,
|
||||
])->invoke('post', '/characters/{character_id}/mail/', [
|
||||
'character_id' => 93738489,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,14 @@ class EveMail extends Model
|
||||
|
||||
//Timestamps
|
||||
public $timestamps = 'true';
|
||||
|
||||
protected $fillable = [
|
||||
'sender',
|
||||
'recipient',
|
||||
'recipient_type',
|
||||
'subject',
|
||||
'body',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ class CreateEveMailsTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->string('sender');
|
||||
$table->string('recipient');
|
||||
$table->string('subject');
|
||||
$table->string('body');
|
||||
$table->string('recipient_type');
|
||||
$table->text('subject');
|
||||
$table->text('body');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user