供应商\经销商入入驻极光推送

This commit is contained in:
weiz 2024-05-21 15:08:30 +08:00
parent 553a07eeb1
commit f53b028278
5 changed files with 116 additions and 55 deletions

View File

@ -41,7 +41,7 @@ class MerchantController extends BaseAdminController
$page_no = $this->request->get('page_no', 1); $page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 15); $page_size = $this->request->get('page_size', 15);
$data = Db::name('user_auth_shop')->where('type', 1)->page($page_no, $page_size)->select()->each(function ($item) { $data = Db::name('user_auth_shop')->where('type', 1)->order('id desc')->page($page_no, $page_size)->select()->each(function ($item) {
$data = Merchant::where('mer_id', $item['pid'])->find(); $data = Merchant::where('mer_id', $item['pid'])->find();
$item['merchant'] = $data; $item['merchant'] = $data;
$item['apply_id'] = $item['id']; $item['apply_id'] = $item['id'];

View File

@ -38,7 +38,7 @@ class SupplierController extends BaseAdminController
$page_no = $this->request->get('page_no', 1); $page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 15); $page_size = $this->request->get('page_size', 15);
$data = Db::name('user_auth_shop')->where('type', 2)->page($page_no, $page_size)->select()->each(function ($item) { $data = Db::name('user_auth_shop')->where('type', 2)->order('id desc')->page($page_no, $page_size)->select()->each(function ($item) {
$data = Supplier::where('id', $item['pid'])->find(); $data = Supplier::where('id', $item['pid'])->find();
$item['supplier'] = $data; $item['supplier'] = $data;
$item['apply_id'] = $item['id']; $item['apply_id'] = $item['id'];

View File

@ -3,6 +3,7 @@
namespace app\admin\logic\merchant; namespace app\admin\logic\merchant;
use app\admin\logic\user\UserLogic; use app\admin\logic\user\UserLogic;
use app\admin\service\JgPushService;
use app\common\model\merchant\Merchant; use app\common\model\merchant\Merchant;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\user\User; use app\common\model\user\User;
@ -59,13 +60,13 @@ class MerchantLogic extends BaseLogic
'financial_type' => $params['financial_type'] ?? '', 'financial_type' => $params['financial_type'] ?? '',
'data_json' => json_encode([ 'data_json' => json_encode([
'company_address' => $params['address'] ?? '', 'company_address' => $params['address'] ?? '',
'company_nickname' => $params['nickname'] ?? '', 'company_nickname' => $params['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '', 'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '', 'company_name' => $params['company_name'] ?? '',
'images' => $params['images'][0] ?? '', 'images'=>$params['images'][0] ?? '',
]) ])
]); ]);
Db::name('user_auth_shop')->insert(['pid'=>$res->id,'user_id'=>0,'shop_uid'=>$params['shop_user_id'],'status'=>0,'type'=>1,'create_time'=>time()]); Db::name('user_auth_shop')->insert(['pid'=>$res->id,'user_id'=>0,'shop_uid'=>$params['shop_user_id'],'status'=>0,'type'=>1,'create_time'=>time(),'jg_register_id'=>$params['jg_register_id']]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -116,10 +117,10 @@ class MerchantLogic extends BaseLogic
'financial_type' => $params['financial_type'] ?? '', 'financial_type' => $params['financial_type'] ?? '',
'data_json' => json_encode([ 'data_json' => json_encode([
'company_address' => $params['address'] ?? '', 'company_address' => $params['address'] ?? '',
'company_nickname' => $params['nickname'] ?? '', 'company_nickname' => $params['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '', 'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '', 'company_name' => $params['company_name'] ?? '',
'images' => $params['images'][0] ?? '', 'images'=>$params['images'][0] ?? '',
]) ])
]); ]);
@ -140,8 +141,10 @@ class MerchantLogic extends BaseLogic
*/ */
public static function status(array $params): bool public static function status(array $params): bool
{ {
$apply_info = Db::name('user_auth_shop')->where('id',$params['apply_id'])->findOrEmpty();
Db::startTrans(); Db::startTrans();
try { try {
if($params['status']==1){
$user=[ $user=[
'real_name'=>$params['service_phone'], 'real_name'=>$params['service_phone'],
'nickname' => '用户'.$params['service_phone'], 'nickname' => '用户'.$params['service_phone'],
@ -158,7 +161,6 @@ class MerchantLogic extends BaseLogic
Db::rollback(); Db::rollback();
throw new BusinessException(UserLogic::getError(), 0); throw new BusinessException(UserLogic::getError(), 0);
} }
if($params['status']==1){
$data=[ $data=[
'user_id'=>$res1['id'], 'user_id'=>$res1['id'],
'status'=>1, 'status'=>1,
@ -179,12 +181,13 @@ class MerchantLogic extends BaseLogic
Merchant::where('mer_id', $params['mer_id'])->update([ Merchant::where('mer_id', $params['mer_id'])->update([
'status' => $params['status'], 'status' => $params['status'],
]); ]);
if(!empty($apply_info['jg_register_id'])){
(new JgPushService()) -> sendMsg($apply_info['jg_register_id'],'您的经销入驻请求审核'.($params['status']==1?'通过':'被拒绝'),'/pages/bindDistribution/index');
}
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
d($e);
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }

View File

@ -3,6 +3,7 @@
namespace app\admin\logic\supplier; namespace app\admin\logic\supplier;
use app\admin\logic\user\UserLogic; use app\admin\logic\user\UserLogic;
use app\admin\service\JgPushService;
use app\common\model\goods\GoodsLabel; use app\common\model\goods\GoodsLabel;
use app\common\model\supplier\Supplier; use app\common\model\supplier\Supplier;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
@ -62,13 +63,13 @@ class SupplierLogic extends BaseLogic
'financial_type' => $params['financial_type'] ?? '', 'financial_type' => $params['financial_type'] ?? '',
'data_json'=>json_encode([ 'data_json'=>json_encode([
'company_address' => $params['address'] ?? '', 'company_address' => $params['address'] ?? '',
'company_nickname' => $params['nickname'] ?? '', 'company_nickname' => $params['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '', 'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '', 'company_name' => $params['company_name'] ?? '',
'images'=>$params['images'][0] ?? '', 'images'=>$params['images'][0] ?? '',
]) ])
]); ]);
Db::name('user_auth_shop')->insert(['pid'=>$res->id,'user_id'=>0,'shop_uid'=>$params['shop_user_id'],'status'=>0,'type'=>2,'create_time'=>time()]); Db::name('user_auth_shop')->insert(['pid'=>$res->id,'user_id'=>0,'shop_uid'=>$params['shop_user_id'],'status'=>0,'type'=>2,'create_time'=>time(),'jg_register_id'=>$params['jg_register_id']]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -86,8 +87,10 @@ class SupplierLogic extends BaseLogic
*/ */
public static function status(array $params): bool public static function status(array $params): bool
{ {
$apply_info = Db::name('user_auth_shop')->where('id',$params['apply_id'])->findOrEmpty();
Db::startTrans(); Db::startTrans();
try { try {
if($params['status']==1){
$user=[ $user=[
'real_name'=>$params['service_phone'], 'real_name'=>$params['service_phone'],
'nickname' => '用户'.$params['service_phone'], 'nickname' => '用户'.$params['service_phone'],
@ -99,13 +102,11 @@ class SupplierLogic extends BaseLogic
'user_money' => 0 'user_money' => 0
]; ];
$res1=UserLogic::add($user); $res1=UserLogic::add($user);
if($res1==false){ if($res1==false){
Db::rollback(); Db::rollback();
throw new BusinessException(UserLogic::getError(), 0); throw new BusinessException(UserLogic::getError(), 0);
} }
if($params['status']==1){
$data=[ $data=[
'user_id'=>$res1['id'], 'user_id'=>$res1['id'],
'status'=>1, 'status'=>1,
@ -126,6 +127,9 @@ class SupplierLogic extends BaseLogic
Supplier::where('id', $params['id'])->update([ Supplier::where('id', $params['id'])->update([
'status' => $params['status'], 'status' => $params['status'],
]); ]);
if(!empty($apply_info['jg_register_id'])){
(new JgPushService()) -> sendMsg($apply_info['jg_register_id'],'您的供应入驻请求审核'.($params['status']==1?'通过':'被拒绝'),'/pages/bindSupplier/index');
}
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -178,7 +182,7 @@ class SupplierLogic extends BaseLogic
'financial_type' => $params['financial_type'] ?? '', 'financial_type' => $params['financial_type'] ?? '',
'data_json'=>json_encode([ 'data_json'=>json_encode([
'company_address' => $params['address'] ?? '', 'company_address' => $params['address'] ?? '',
'company_nickname' => $params['nickname'] ?? '', 'company_nickname' => $params['company_nickname'] ?? '',
'social_credit_code' => $params['social_credit_code'] ?? '', 'social_credit_code' => $params['social_credit_code'] ?? '',
'company_name' => $params['company_name'] ?? '', 'company_name' => $params['company_name'] ?? '',
'images'=>$params['images'][0] ?? '', 'images'=>$params['images'][0] ?? '',

View File

@ -0,0 +1,54 @@
<?php
namespace app\admin\service;
use JPush\Client;
use support\Log;
class JgPushService
{
public $client;
public $push;
public $iosKey;
public $iosSecret;
public $azKey;
public $azSecret;
public function __construct()
{
// ios
$this->iosKey = '8a5efd65cda14fafa6e64ad3';
$this->iosSecret = 'daebe19b547c43128796a078';
// 安卓
$this->azKey = 'b5f679f4357018605ea6fd2e';
$this->azSecret = 'c4fb573758f8d7058d697c54';
}
public function sendMsg($register_id,$message,$route = '',$type = 1){
try {
$this->client = new Client($this->iosKey, $this->iosSecret);
$this->push = $this->client->push();
$this->push->setPlatform(['android', 'ios']);
$this->push->addRegistrationId($register_id);
$this->push->iosNotification($message, ['extras' => ['route' => $route, 'type' => $type]]);
$this->push->send();
unset($this->client, $this->push);
} catch (\Exception $e) {
dump($e->getMessage());
Log::error($e->getMessage());
}
try {
$this->client = new Client($this->azKey, $this->azSecret);
$this->push = $this->client->push();
$this->push->setPlatform(['android', 'ios']);
$this->push->addRegistrationId($register_id);
$this->push->androidNotification($message, ['extras' => ['route' => $route, 'type' => $type]]);
$this->push->send();
unset($this->client, $this->push);
} catch (\Exception $e) {
dump($e->getMessage());
Log::error($e->getMessage());
}
}
}