58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use App\Models\FruitHistory;
|
||
|
|
use App\Models\Participant;
|
||
|
|
use Illuminate\Support\Facades\Cache;
|
||
|
|
use App\Repositories\Eloquent\SmsRepository as Sms;
|
||
|
|
use Illuminate\Container\Container;
|
||
|
|
class ParticipantAddShare implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
|
||
|
|
public $tries = 1;
|
||
|
|
protected $participant;
|
||
|
|
protected $partner;
|
||
|
|
protected $sms;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($array)
|
||
|
|
{
|
||
|
|
$this->participant = $array['participant'];
|
||
|
|
$this->partner = $array['partner'];
|
||
|
|
$container = new Container();
|
||
|
|
$this->sms = new Sms($container);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//添加一次分享
|
||
|
|
FruitHistory::create(['participant_id'=>$this->participant->id, 'participant_helper_id'=>$this->partner->id]);
|
||
|
|
//更新分享缓存;
|
||
|
|
$key = Participant::PART_SHARE_KEY;
|
||
|
|
$key = $key.$this->participant->official_openid;
|
||
|
|
$share_list = FruitHistory::where('participant_id', $this->participant->id)->with('participant_helper')->orderBy('id','desc')->get();
|
||
|
|
Cache::forever($key, $share_list);
|
||
|
|
} catch (Exception $e) {
|
||
|
|
//TODO通知管理员
|
||
|
|
$message = $e->getMessage();
|
||
|
|
$this->sms->sentMessage($mobile, $message);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|