81 lines
3.0 KiB
PHP
81 lines
3.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Http\Response\ResponseJson;
|
||
|
|
use App\Models\Server\MEarning;
|
||
|
|
use App\Models\Server\MerchantUser;
|
||
|
|
use App\Services\UserService;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
|
||
|
|
class SaasEarningMPNotice implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
use ResponseJson;
|
||
|
|
public $tries = 1;
|
||
|
|
protected $order;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($order)
|
||
|
|
{
|
||
|
|
$this->order = $order;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$order = $this->order;
|
||
|
|
if (empty($order)) throw new \Exception("收益经典不存在");
|
||
|
|
while (true) {
|
||
|
|
// $earnings = MEarning::with('user.mpUser')->where('m_order_id', $order->id)->where('m_user_id', '<>', 0)->get();
|
||
|
|
|
||
|
|
$m_user_ids = MEarning::where('m_order_id', $order->id)->where('m_user_id', '!=', 0)->where('value', '>', 0)->distinct('m_user_id')->pluck('m_user_id');
|
||
|
|
foreach ($m_user_ids as $m_user_id) {
|
||
|
|
$user = MerchantUser::where('id', $m_user_id)->first();
|
||
|
|
if (empty($user) || empty($user->mpUser)) continue;
|
||
|
|
$user_service = new UserService();
|
||
|
|
$mp_user = $user->mpUser;
|
||
|
|
// if ($mp_user->id != 58859) continue;
|
||
|
|
//系统通知
|
||
|
|
$user_service->sendNotice($mp_user->id, 1, 'system', '您有一笔分享收益', null, 0, 'https://love.ufutx.com/h5/#/guidePage', 2);
|
||
|
|
//公众号通知
|
||
|
|
if ($mp_user->wechat && $mp_user->wechat->official_openid) {
|
||
|
|
$data['touser'] = $mp_user->wechat->official_openid;
|
||
|
|
$data['template_id'] = 'ln7gMeLbeMhF_FCVAwQx_zLQWyBpuNZboMei9FswZ6c';
|
||
|
|
$data['url'] = env('APP_URL').'/auth/saas/earning/account';
|
||
|
|
$data['data'] = [
|
||
|
|
'first' => '您推荐的用户已成功下单。',
|
||
|
|
'keyword1' => $order->name?:$order->user->unionid,
|
||
|
|
'keyword2' => $order->created_at->toDateTimeString(),
|
||
|
|
'keyword3' => $order->desc,
|
||
|
|
'keyword4' => '¥'.$order->price,
|
||
|
|
'keyword5' => null,
|
||
|
|
'reamrk' => '点击查看',
|
||
|
|
];
|
||
|
|
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$count = MEarning::where('m_order_id', $order->id)->count();
|
||
|
|
if ($count) break;
|
||
|
|
}
|
||
|
|
return ;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return ;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|