Commit e2714269 authored by hangjun83's avatar hangjun83

openapi 震坤行邮件

parent 9f49efcd
...@@ -55,7 +55,7 @@ class ZhenkhJob extends Job ...@@ -55,7 +55,7 @@ class ZhenkhJob extends Job
$service->hMUpdateOrdersList(); $service->hMUpdateOrdersList();
break; break;
case 'sendMail' : case 'sendMail' :
$service->sendMail(); $service->sendMail('订单确认邮件', '订单号:未确认成功');
default: default:
} }
} }
......
...@@ -22,12 +22,12 @@ class MailService{ ...@@ -22,12 +22,12 @@ class MailService{
$this->registerProvider($this->getMailAccountConfig($this->type)); $this->registerProvider($this->getMailAccountConfig($this->type));
} }
public function getMailAccountConfig($type) public function getMailAccountConfig()
{ {
$username = env("MAIL_{$type}_USERNAME"); $username = env("MAIL_USERNAME");
$password = env("MAIL_{$type}_PASSWORD"); $password = env("MAIL_PASSWORD");
$address = env("MAIL_{$type}_FROM_ADDRESS"); $address = env("MAIL_FROM_ADDRESS");
$fromName = env("MAIL_{$type}_FROM_NAME"); $fromName = env("MAIL_FROM_NAME");
$config = config('mail'); $config = config('mail');
...@@ -45,11 +45,13 @@ class MailService{ ...@@ -45,11 +45,13 @@ class MailService{
app()->register(\Illuminate\Mail\MailServiceProvider::class); app()->register(\Illuminate\Mail\MailServiceProvider::class);
} }
public function send($type, $toUser, $message) public function sendMail($title, $toUser, $message)
{ {
$this->setFromType($type)->initSendService(); $this->setFromType('zkh')->initSendService();
Mail::to($toUser)->send(new MailTempl([ Mail::raw($message,function($mail) use ($toUser, $title){
'message' => $message $mail->to($toUser);
])); $mail->subject($title);
});
} }
} }
\ No newline at end of file
...@@ -21,6 +21,7 @@ class ZhenKhService ...@@ -21,6 +21,7 @@ class ZhenKhService
$this->apiService = (new ZhenkhApiService(app(ThirdApiPlatformRepository::class))); $this->apiService = (new ZhenkhApiService(app(ThirdApiPlatformRepository::class)));
$this->rhawnService = app(RhawnChemicalsService::class); $this->rhawnService = app(RhawnChemicalsService::class);
$this->rhawnOrderService = app(RhawnOrdersService::class); $this->rhawnOrderService = app(RhawnOrdersService::class);
$this->mailService = app(MailService::class);
} }
public function orderNoRollBack() public function orderNoRollBack()
...@@ -331,6 +332,7 @@ class ZhenKhService ...@@ -331,6 +332,7 @@ class ZhenKhService
{ {
try{ try{
$orderDelivery = $this->rhawnOrderService->getSorderDeliveryDetail($deliveryCode); $orderDelivery = $this->rhawnOrderService->getSorderDeliveryDetail($deliveryCode);
$noMatchGoods = [];
if($orderDelivery){ if($orderDelivery){
$expressArray = $this->apiService->getPlatformDataEntries('zkh_order_express','data_values'); $expressArray = $this->apiService->getPlatformDataEntries('zkh_order_express','data_values');
if(empty($expressArray)){ if(empty($expressArray)){
...@@ -389,6 +391,7 @@ class ZhenKhService ...@@ -389,6 +391,7 @@ class ZhenKhService
foreach($orderDelivery as $delivery){ foreach($orderDelivery as $delivery){
$zkhGoods = $this->rhawnService->getZkhGoodsSku($delivery->p_id); $zkhGoods = $this->rhawnService->getZkhGoodsSku($delivery->p_id);
if(empty($zkhGoods)){ if(empty($zkhGoods)){
$noMatchGoods[] = $orderNo;
throw new \Exception('对应震坤行商品数据未找到'); throw new \Exception('对应震坤行商品数据未找到');
} }
foreach($zkhGoods as $goods){ foreach($zkhGoods as $goods){
...@@ -425,6 +428,10 @@ class ZhenKhService ...@@ -425,6 +428,10 @@ class ZhenKhService
$this->apiService->storePlatformDataEntries('zkh_delivery_code_'.$deliveryCode,['code' => $deliveryResult['data']]); $this->apiService->storePlatformDataEntries('zkh_delivery_code_'.$deliveryCode,['code' => $deliveryResult['data']]);
} }
} }
if(!empty($noMatchGoods)){
//发送邮件
$this->sendMail('订单同步邮件', '订单号:'.implode(',',$orderNo).'未同步成功');
}
}catch(\Throwable $exception){ }catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':sendDeliveryOrder', 'error'); SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':sendDeliveryOrder', 'error');
...@@ -479,7 +486,7 @@ class ZhenKhService ...@@ -479,7 +486,7 @@ class ZhenKhService
} }
if(!$result){ if(!$result){
//发送邮件 //发送邮件
$this->sendMail('订单确认邮件', '订单号:'.$orderNo.'未确认成功');
} }
} }
} }
...@@ -522,11 +529,11 @@ class ZhenKhService ...@@ -522,11 +529,11 @@ class ZhenKhService
} }
} }
public function sendMail() public function sendMail($title, $message)
{ {
$mailService = app(MailService::class);
try{ try{
$mailService->send('zkh','hangjun83@126.com','测试邮件'); $mailer = $this->apiService->getPlatformDataEntries('zkh_send_mailer','data_values');
$this->mailService->sendMail($title, $mailer,'震坤行【'.$message.'】,请人工操作!');
}catch(\Throwable $exception){ }catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':sendMail', 'error'); SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':sendMail', 'error');
return false; return false;
......
...@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\DB; ...@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\DB;
class PlatformDataEntriesSeeder extends Seeder class PlatformDataEntriesSeeder extends Seeder
{ {
protected $entries = [ protected $entries = [
[ /*[
'platform_id' => 27, 'platform_id' => 27,
'data_key' => 'zkh_order_invoice', 'data_key' => 'zkh_order_invoice',
'data_values' => [ 'data_values' => [
...@@ -27,8 +27,34 @@ class PlatformDataEntriesSeeder extends Seeder ...@@ -27,8 +27,34 @@ class PlatformDataEntriesSeeder extends Seeder
'address' => '上海浦东科苑路399号张江创新园5号楼', 'address' => '上海浦东科苑路399号张江创新园5号楼',
'company_phone' => '400-680-9696' 'company_phone' => '400-680-9696'
] ]
],
[
'platform_id' => 27,
'data_key' => 'sys_delivery_logistics',
'data_values' => [
'JD'=>'京东',
'SF'=>'顺丰',
'ZT'=>'中通',
'YD'=>'韵达',
'ZJS'=>'宅急送',
'DBL'=>'德邦',
'YTO'=>'圆通',
'YZPY'=>'邮政',
'AN'=>'安能',
'STO'=>'申通',
'HHTT'=>'天天',
'WL'=>'物流',
'ziti'=>'自提'
]
],*/
[
'platform_id' => 27,
'data_key' => 'zkh_send_mailer',
'data_values' => [
'it@rhawn.cn','yuxiaohui@rhawn.cn','hangjun@rhawn.cn'
] ]
]; ] ];
public function run() public function run()
{ {
......
@component('mail::message') @component('mail::message')
震坤行订单{{$message}}未同步成功,请人工下单! {{$message}}
@endcomponent @endcomponent
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment