247 lines
8.6 KiB
PHP
247 lines
8.6 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\CoinLog;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Http\Response\ResponseJson;
|
||
|
|
|
||
|
|
class SendProfileCoin implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
use ResponseJson;
|
||
|
|
protected $user, $type;
|
||
|
|
protected $profile_coin, $profile_photo_coin, $intro_coin, $interest_coin, $ideal_coin, $approve_coin;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($user, $type)
|
||
|
|
{
|
||
|
|
$this->user = $user;
|
||
|
|
$this->type = $type;
|
||
|
|
$this->approve_coin = $this->profile_coin = $this->profile_photo_coin = 10;
|
||
|
|
$this->intro_coin = $this->interest_coin = $this->ideal_coin = 3;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
switch ($this->type) {
|
||
|
|
case 'profile':
|
||
|
|
//检测是否可以赠送基本资料福币
|
||
|
|
$result = $this->checkSendProfileCoin($this->user);
|
||
|
|
if (empty($result) && !is_numeric($result)) throw new \Exception("检查赠送福币失败", 1);
|
||
|
|
//赠送基本资料福币
|
||
|
|
if ($result == 0) $this->sendCoin($this->user,$this->profile_coin, CoinLog::PROFILEREMARK);
|
||
|
|
//检测是否可以赠送个人简介福币
|
||
|
|
$result = $this->checkSendIntroCoin($this->user);
|
||
|
|
if (empty($result) && !is_numeric($result)) throw new \Exception("检查赠送福币失败", 1);
|
||
|
|
//赠送个人简介福币
|
||
|
|
if ($result == 0) $this->sendCoin($this->user,$this->intro_coin, CoinLog::INTROREMARK);
|
||
|
|
//检测是否可以赠送兴趣爱好福币
|
||
|
|
$result = $this->checkSendInterestCoin($this->user);
|
||
|
|
if (empty($result) && !is_numeric($result)) throw new \Exception("检查赠送福币失败", 1);
|
||
|
|
//赠送兴趣爱好福币
|
||
|
|
if ($result == 0) $this->sendCoin($this->user,$this->interest_coin, CoinLog::INTERESTREMARK);
|
||
|
|
//检测是否可以赠送择偶标准福币
|
||
|
|
$result = $this->checkSendIdealCoin($this->user);
|
||
|
|
if (empty($result) && !is_numeric($result)) throw new \Exception("检查赠送福币失败", 1);
|
||
|
|
//赠送择偶标准福币
|
||
|
|
if ($result == 0) $this->sendCoin($this->user,$this->ideal_coin, CoinLog::IDEALREMARK);
|
||
|
|
break;
|
||
|
|
case 'profile_photo':
|
||
|
|
//检查是否可以赠送个人相册福币
|
||
|
|
$result = $this->checkSendProfilePhotoCoin($this->user);
|
||
|
|
if (empty($result) && !is_numeric($result)) throw new \Exception("检查赠送福币失败", 1);
|
||
|
|
if ($result == 0) $this->sendCoin($this->user,$this->profile_photo_coin, CoinLog::PROFILEPHOTOREMARK);
|
||
|
|
break;
|
||
|
|
case "approve":
|
||
|
|
//检查是否可以赠送认证福币
|
||
|
|
$result = $this->checkSendApproveCoin($this->user);
|
||
|
|
if (empty($result) && !is_numeric($result)) throw new \Exception("检查赠送福币失败", 1);
|
||
|
|
if ($result == 0) $this->sendCoin($this->user,$this->approve_coin, CoinLog::APPROVEREMARK);
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
# code...
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 赠送福币
|
||
|
|
* @param [type] $user [description]
|
||
|
|
* @param [type] $coin [description]
|
||
|
|
* @param [type] $remark [description]
|
||
|
|
* @return [type] [description]
|
||
|
|
*/
|
||
|
|
public function sendCoin($user, $coin, $remark)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//判断记录是否存在
|
||
|
|
$count = $user->coinLogs()->where(['type'=>CoinLog::RECSYSTEM, 'coin'=>$coin, 'remark'=>$remark])->count();
|
||
|
|
if ($count) return false;
|
||
|
|
\DB::beginTransaction();
|
||
|
|
//增加福币记录
|
||
|
|
$user->addCoinLog(CoinLog::RECSYSTEM, 0, $coin, $remark);
|
||
|
|
//修改福币钱包
|
||
|
|
$user->updateCoinInfo('add', $coin, 'other');
|
||
|
|
\DB::commit();
|
||
|
|
return true;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
\DB::rollback();
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function checkSendApproveCoin($user)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//个人简介是否完善
|
||
|
|
if (empty($user->is_approved) || empty($user->name) || empty($user->card_num)) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
//是否已赠送过福币
|
||
|
|
$count = $user->coinLogs()->approveLog()->count();
|
||
|
|
return $count?1:0;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 检查兴趣爱好是否可以赠送福币
|
||
|
|
* @param [type] $user [description]
|
||
|
|
* @return [type] [description]
|
||
|
|
*/
|
||
|
|
public function checkSendInterestCoin($user)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//个人简介是否完善
|
||
|
|
if (empty($user->profileCourtship) || empty($user->profileCourtship->interest_hobby)) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
//是否已赠送过福币
|
||
|
|
$count = $user->coinLogs()->profileLog(CoinLog::INTERESTREMARK)->count();
|
||
|
|
return $count?1:0;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 检查择偶标准是否可以赠送福币
|
||
|
|
* @param [type] $user [description]
|
||
|
|
* @return [type] [description]
|
||
|
|
*/
|
||
|
|
public function checkSendIdealCoin($user)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//个人简介是否完善
|
||
|
|
if (empty($user->profileCourtship) || empty($user->profileCourtship->ideal_mate)) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
//是否已赠送过福币
|
||
|
|
$count = $user->coinLogs()->profileLog(CoinLog::IDEALREMARK)->count();
|
||
|
|
return $count?1:0;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 检查个人简介是否完善
|
||
|
|
* @param [type] $user [description]
|
||
|
|
* @return [type] [description]
|
||
|
|
*/
|
||
|
|
public function checkSendIntroCoin($user)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//个人简介是否完善
|
||
|
|
if (empty($user->profileCourtship) || empty($user->profileCourtship->introduction)) {
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
//是否已赠送过福币
|
||
|
|
$count = $user->coinLogs()->profileLog(CoinLog::INTROREMARK)->count();
|
||
|
|
return $count?1:0;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function checkSendProfilePhotoCoin($user)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//可以赠送
|
||
|
|
$res = 0;
|
||
|
|
$count = $user->profilePhoto()->count();
|
||
|
|
if (empty($count)) {
|
||
|
|
return $res = 1;
|
||
|
|
}
|
||
|
|
//是否已赠送过福币
|
||
|
|
$count = $user->coinLogs()->profilePhotoLog()->count();
|
||
|
|
return $count?1:0;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public function checkSendProfileCoin($user)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//资料是否完善
|
||
|
|
$user_data = User::COINUSER;
|
||
|
|
$profile_data = User::COINPROFILE;
|
||
|
|
$res = 0;
|
||
|
|
foreach ($user_data as $attribute) {
|
||
|
|
if (empty($user->$attribute)) {
|
||
|
|
$res = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($res) return $res;
|
||
|
|
$profile = $user->profileCourtship;
|
||
|
|
if (empty($profile)) {
|
||
|
|
$res = 1;
|
||
|
|
}
|
||
|
|
if ($res) return $res;
|
||
|
|
foreach ($profile_data as $attribute) {
|
||
|
|
if (empty($profile->$attribute)) {
|
||
|
|
$res = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($res) return $res;
|
||
|
|
//是否已赠送过福币
|
||
|
|
$count = $user->coinLogs()->profileLog(CoinLog::PROFILEREMARK)->count();
|
||
|
|
return $count?1:0;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|