From d2eb0f422ade1c18e16f6c11eb2c1f01ac315e6c Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 5 Jan 2022 13:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=AE=B6=E7=AB=AF?= =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E6=92=AD=E6=8A=A5=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/QuotaV1SendCommand.php | 28 ++++---- app/Services/Push/MerchantUnipushService.php | 2 +- app/Services/Push/UniPushService.php | 74 ++++++++++++++++++++ 3 files changed, 90 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/QuotaV1SendCommand.php b/app/Console/Commands/QuotaV1SendCommand.php index 06a9f78e..850a00cd 100644 --- a/app/Console/Commands/QuotaV1SendCommand.php +++ b/app/Console/Commands/QuotaV1SendCommand.php @@ -41,19 +41,21 @@ class QuotaV1SendCommand extends Command $walletService = new WalletService(); //依次分红 foreach ($userInfos as $userInfo) { - $log = new QuotaV1SendLog(); - $log->user_id = $userInfo->user_id; - $log->job_id = $job->id; - $log->amount = round(bcmul(bcdiv($job->amount, $totalQuotaV1, 5), $userInfo->quota_v1, 3)); - $log->save(); - try { - DB::beginTransaction(); - $log->update(['status'=>1]); - $walletService->changeBalance($userInfo->user, $log->amount, WalletLog::ACTION_QUOTA_V1, '老配额分红', $log); - DB::commit(); - } catch (Throwable $th) { - DB::rollBack(); - report($th); + if ($userInfo->bonusable) {//只针对享受分红的人发放 + $log = new QuotaV1SendLog(); + $log->user_id = $userInfo->user_id; + $log->job_id = $job->id; + $log->amount = round(bcmul(bcdiv($job->amount, $totalQuotaV1, 5), $userInfo->quota_v1, 3)); + $log->save(); + try { + DB::beginTransaction(); + $log->update(['status'=>1]); + $walletService->changeBalance($userInfo->user, $log->amount, WalletLog::ACTION_QUOTA_V1, '老配额分红', $log); + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + } } } }); diff --git a/app/Services/Push/MerchantUnipushService.php b/app/Services/Push/MerchantUnipushService.php index be0dd885..1290bae7 100644 --- a/app/Services/Push/MerchantUnipushService.php +++ b/app/Services/Push/MerchantUnipushService.php @@ -65,7 +65,7 @@ class MerchantUnipushService extends UniPushService return false; } - return $this->pushCid($sn, $message->user->cid->m_cid, $message->title, $message->content, [ + return $this->pushPayload($sn, $message->user->cid->m_cid, $message->title, $message->content, [ 'jump_type' => $message->jump_type == 0 ? 1 : $message->jump_type, 'jump_link' => $message->type == 1 || empty($message->jump_link) ? '/pages/news/index' : $message->jump_link, ]); diff --git a/app/Services/Push/UniPushService.php b/app/Services/Push/UniPushService.php index 90e162b0..96d75bdc 100644 --- a/app/Services/Push/UniPushService.php +++ b/app/Services/Push/UniPushService.php @@ -190,6 +190,61 @@ class UniPushService ]; } + protected function createPushPayloadData($title, $body, $params = []) + { + $payload = json_encode($params); + return [ + 'settings'=>[ + 'ttl'=> 3600000, + 'strategy'=> [ + 'default'=>1, + 'ios'=>4, + ], + ], + 'push_message'=>[ + 'transmission'=> json_encode([ + // 'title' => $title, + // 'content'=> $body, + 'payload'=> $title, + ]), + // 'notification'=>[ + // 'title' => $title, + // 'body' => $body, + // 'click_type'=> 'payload', //默认打开首页 + // 'payload'=> $payload, + // ], + ], + 'push_channel'=>[ + 'android'=>[ + 'ups'=> [ + 'transmission'=> json_encode([ + // 'title' => $title, + // 'content'=> $body, + 'payload'=> $title, + ]), + // 'notification'=>[ + // 'title' => $title, + // 'body' => $body, + // 'click_type'=> 'payload', //默认打开首页 + // 'payload'=> $payload, + // ], + ], + ], + 'ios'=>[ + 'type'=>'notify', + 'payload' => $payload, + 'aps'=>[ + 'alert'=>[ + 'title'=>$title, + 'body'=>$body, + ], + 'content-available'=> 0, + ], + ], + ], + ]; + } + /** * 绑定cid和user_id * @@ -252,6 +307,25 @@ class UniPushService ); } + /** + * Undocumented function + * + * @return void + */ + public function pushPayload(string $sn, string $cid, string $title, string $body, array $params = []) + { + return $this->formatResStatus( + $this->post('push/single/cid', array_merge([ + 'request_id' => $sn, + 'audience'=>[ + 'cid'=>[ + $cid, + ], + ], + ], $this->createPushPayloadData($title, $body, $params))) + ); + } + protected function formatResStatus($res): bool { if (Arr::get($res, 'code', 1) === 0) {