85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Models\Live\TaskViewer;
|
||
|
|
use App\Models\Live\Task;
|
||
|
|
use App\Models\Live\ViewerTaskScore;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
class DoTask implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
protected $data;
|
||
|
|
public $tries = 1;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($data)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
$task = Task::find($this->data['task_id']);
|
||
|
|
if(empty($task) || $task->num ==0){
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
DB::beginTransaction();
|
||
|
|
$cash = Task::where('id', $task->id)->value('new_score');
|
||
|
|
$adddata['cash'] = $cash / 100;
|
||
|
|
$adddata['viewer_id'] = $this->data['from_id'];
|
||
|
|
$adddata['type'] = 'share_cash';
|
||
|
|
$adddata['source_id'] = $this->data['source_id'];
|
||
|
|
|
||
|
|
|
||
|
|
$task->decrement('the_rest');
|
||
|
|
|
||
|
|
$task_viewer = New Taskviewer();
|
||
|
|
$task_viewer->viewer_id = $this->data['from_id'];
|
||
|
|
$task_viewer->task_id = $this->data['task_id'];
|
||
|
|
$task_viewer->other_viewer_id = $this->data['other_viewer_id'];
|
||
|
|
$task_viewer->save();
|
||
|
|
// if(!empty($this->data['type'])){
|
||
|
|
//任务奖励先存起来
|
||
|
|
$viewer_task_score = ViewerTaskScore::where('viewer_id', $this->data['from_id'])->where('task_id', $this->data['task_id'])->first();
|
||
|
|
if(!empty($viewer_task_score)){
|
||
|
|
$viewer_task_score->increment('all_score', $cash);
|
||
|
|
$viewer_task_score->increment('score', $cash);
|
||
|
|
}else{
|
||
|
|
$viewer_task_score = New ViewerTaskScore();
|
||
|
|
$viewer_task_score->viewer_id = $this->data['from_id'];
|
||
|
|
$viewer_task_score->task_id = $this->data['task_id'];
|
||
|
|
$viewer_task_score->all_score = $cash;
|
||
|
|
$viewer_task_score->score = $cash;
|
||
|
|
$viewer_task_score->save();
|
||
|
|
|
||
|
|
}
|
||
|
|
// }else{
|
||
|
|
// AddCashToViewer::dispatch($adddata)->onQueue('love');
|
||
|
|
// }
|
||
|
|
|
||
|
|
DB::commit();
|
||
|
|
return true;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
DB::rollBack();
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|