Skip to content

Commit

Permalink
Merge pull request #387 from LightCountry/master
Browse files Browse the repository at this point in the history
增加Bark推送、企业微信Bot推送、Telegram推送增加订单ID和支付通道字段
  • Loading branch information
assimon authored Aug 16, 2022
2 parents 62aaad3 + f029a03 commit 9ae3348
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 8 deletions.
9 changes: 9 additions & 0 deletions app/Admin/Forms/SystemSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public function form()
->default(BaseModel::STATUS_CLOSE);
$this->text('telegram_bot_token', admin_trans('system-setting.fields.telegram_bot_token'));
$this->text('telegram_userid', admin_trans('system-setting.fields.telegram_userid'));
$this->switch('is_open_bark_push', admin_trans('system-setting.fields.is_open_bark_push'))
->default(BaseModel::STATUS_CLOSE);
$this->switch('is_open_bark_push_url', admin_trans('system-setting.fields.is_open_bark_push_url'))
->default(BaseModel::STATUS_CLOSE);
$this->text('bark_server', admin_trans('system-setting.fields.bark_server'));
$this->text('bark_token', admin_trans('system-setting.fields.bark_token'));
$this->switch('is_open_qywxbot_push', admin_trans('system-setting.fields.is_open_qywxbot_push'))
->default(BaseModel::STATUS_CLOSE);
$this->text('qywxbot_key', admin_trans('system-setting.fields.qywxbot_key'));
});
$this->tab(admin_trans('system-setting.labels.mail_setting'), function () {
$this->text('driver', admin_trans('system-setting.fields.driver'))->default('smtp')->required();
Expand Down
86 changes: 86 additions & 0 deletions app/Jobs/BarkPush.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Jobs;

use App\Models\Order;
use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\BaseModel;


class BarkPush implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* 任务最大尝试次数。
*
* @var int
*/
public $tries = 2;

/**
* 任务运行的超时时间。
*
* @var int
*/
public $timeout = 30;

/**
* @var Order
*/
private $order;

/**
* 商品服务层.
* @var \App\Service\PayService
*/
private $goodsService;


/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
$this->goodsService = app('Service\GoodsService');
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$goodInfo = $this->goodsService->detail($this->order->goods_id);
$client = new Client();
$apiUrl = dujiaoka_config_get('bark_server') .'/'. dujiaoka_config_get('bark_token');
$params = [
"title" => __('dujiaoka.prompt.new_order_push').'('.$this->order->actual_price.'元)',
"body" => __('order.fields.order_id') .': '.$this->order->id."\n"
. __('order.fields.order_sn') .': '.$this->order->order_sn."\n"
. __('order.fields.pay_id') .': '.$this->order->pay->pay_name."\n"
. __('order.fields.title') .': '.$this->order->title."\n"
. __('order.fields.actual_price') .': '.$this->order->actual_price."\n"
. __('order.fields.email') .': '.$this->order->email."\n"
. __('goods.fields.gd_name') .': '.$goodInfo->gd_name."\n"
. __('goods.fields.in_stock') .': '.$goodInfo->in_stock."\n"
. __('order.fields.order_created') .': '.$this->order->created_at,
"icon"=>url('assets/common/images/default.jpg'),
"level"=>"timeSensitive",
"group"=>dujiaoka_config_get('text_logo', '独角数卡')
];
if (dujiaoka_config_get('is_open_bark_push_url', 0) == BaseModel::STATUS_OPEN) {
$params["url"] = url('detail-order-sn/'.$this->order->order_sn);
}
$client->post($apiUrl,['form_params' => $params, 'verify' => false]);
}
}
18 changes: 10 additions & 8 deletions app/Jobs/TelegramPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ public function __construct(Order $order)
public function handle()
{
$goodInfo = $this->goodsService->detail($this->order->goods_id);
$formatText = '*'. __('dujiaoka.prompt.new_order_push') .':*'.'%0A'
. __('order.fields.order_sn') .': `'.$this->order->order_sn.'`%0A'
. __('order.fields.title') .': '.$this->order->title.'%0A'
. __('order.fields.actual_price') .': '.$this->order->actual_price.'%0A'
. __('order.fields.email') .': `'.$this->order->email.'`%0A'
. __('goods.fields.gd_name') .': `'.$goodInfo->gd_name.'`%0A'
. __('goods.fields.in_stock') .': `'.$goodInfo->in_stock.'`%0A'
. __('order.fields.order_created') .': '.$this->order->created_at;
$formatText = '*'. __('dujiaoka.prompt.new_order_push').'('.$this->order->actual_price.'元)*%0A'
. __('order.fields.order_id') .': `'.$this->order->id.'`%0A'
. __('order.fields.order_sn') .': `'.$this->order->order_sn.'`%0A'
. __('order.fields.pay_id') .': `'.$this->order->pay->pay_name.'`%0A'
. __('order.fields.title') .': '.$this->order->title.'%0A'
. __('order.fields.actual_price') .': '.$this->order->actual_price.'%0A'
. __('order.fields.email') .': `'.$this->order->email.'`%0A'
. __('goods.fields.gd_name') .': `'.$goodInfo->gd_name.'`%0A'
. __('goods.fields.in_stock') .': `'.$goodInfo->in_stock.'`%0A'
. __('order.fields.order_created') .': '.$this->order->created_at;
$client = new Client([
'timeout' => 30,
'proxy'=> ''
Expand Down
82 changes: 82 additions & 0 deletions app/Jobs/WorkWeiXinPush.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Jobs;

use App\Models\Order;
use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;


class WorkWeiXinPush implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* 任务最大尝试次数。
*
* @var int
*/
public $tries = 1;

/**
* 任务运行的超时时间。
*
* @var int
*/
public $timeout = 30;

/**
* @var Order
*/
private $order;

/**
* 商品服务层.
* @var \App\Service\PayService
*/
private $goodsService;


/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
$this->goodsService = app('Service\GoodsService');
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$goodInfo = $this->goodsService->detail($this->order->goods_id);
$client = new Client();
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='. dujiaoka_config_get('qywxbot_key');
$params = [
"msgtype"=>"markdown",
"markdown"=>[
"content"=>__('dujiaoka.prompt.new_order_push').'(<font color="warning">'.$this->order->actual_price."</font>元)\n"
.'>'.__('order.fields.order_id') .': <font color="comment">'.$this->order->id."</font>\n"
.'>'.__('order.fields.order_sn') .': <font color="comment">'.$this->order->order_sn."</font>\n"
.'>'.__('order.fields.pay_id') .': <font color="comment">'.$this->order->pay->pay_name."</font>\n"
.'>'.__('order.fields.title') .': <font color="comment">'.$this->order->title."</font>\n"
.'>'.__('order.fields.actual_price') .': <font color="comment">'.$this->order->actual_price."</font>\n"
.'>'.__('order.fields.email') .': <font color="comment">'.$this->order->email."</font>\n"
.'>'.__('goods.fields.gd_name') .': <font color="comment">'.$goodInfo->gd_name."</font>\n"
.'>'.__('goods.fields.in_stock') .': <font color="comment">'.$goodInfo->in_stock."</font>\n"
.'>'.__('order.fields.order_created') .': <font color="comment">'.$this->order->created_at."</font>"
]
];
$client->post($apiUrl,['json' => $params, 'verify' => false]);
}
}
10 changes: 10 additions & 0 deletions app/Service/OrderProcessService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use App\Jobs\OrderExpired;
use App\Jobs\ServerJiang;
use App\Jobs\TelegramPush;
use App\Jobs\BarkPush;
use App\Jobs\WorkWeiXinPush;
use App\Models\BaseModel;
use App\Models\Coupon;
use App\Models\Goods;
Expand Down Expand Up @@ -418,6 +420,14 @@ public function completedOrder(string $orderSN, float $actualPrice, string $trad
if (dujiaoka_config_get('is_open_telegram_push', 0) == BaseModel::STATUS_OPEN) {
TelegramPush::dispatch($order);
}
// 如果开启了Bark推送
if (dujiaoka_config_get('is_open_bark_push', 0) == BaseModel::STATUS_OPEN) {
BarkPush::dispatch($order);
}
// 如果开启了企业微信Bot推送
if (dujiaoka_config_get('is_open_qywxbot_push', 0) == BaseModel::STATUS_OPEN) {
WorkWeiXinPush::dispatch($order);
}
// 回调事件
ApiHook::dispatch($order);
return $completedOrder;
Expand Down
1 change: 1 addition & 0 deletions resources/lang/zh_CN/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'goods_id' => '所属商品',
'goods_price' => '商品单价',
'info' => '订单详情',
'order_id' => '订单ID',
'order_sn' => '订单号',
'pay_id' => '支付通道',
'status' => '订单状态',
Expand Down
8 changes: 8 additions & 0 deletions resources/lang/zh_CN/system-setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@
'is_open_img_code' => '是否开启图形验证码',
'is_open_search_pwd' => '是否开启查询密码',
'is_open_google_translate' => '是否开启google翻译',

'is_open_server_jiang' => '是否开启server酱',
'server_jiang_token' => 'server酱通讯token',
'is_open_telegram_push' => '是否开启Telegram推送',
'telegram_userid' => 'Telegram用户id',
'telegram_bot_token' => 'Telegram通讯token',
'is_open_bark_push' => '是否开启Bark推送',
'is_open_bark_push_url' => '是否推送订单URL',
'bark_server' => 'Bark服务器',
'bark_token' => 'Bark通讯Token',
'is_open_qywxbot_push' => '是否开启企业微信Bot推送',
'qywxbot_key' => '企业微信Bot通讯Key',

'template' => '站点模板',
'language' => '站点语言',
'order_expire_time' => '订单过期时间(分钟)',
Expand Down

0 comments on commit 9ae3348

Please sign in to comment.