|
|
|
@ -2,7 +2,10 @@ |
|
|
|
|
|
|
|
namespace App\Service\v3\Implementations; |
|
|
|
|
|
|
|
use App\Commons\Log; |
|
|
|
use App\Constants\v3\Employee; |
|
|
|
use App\Constants\v3\Payment; |
|
|
|
use App\Model\v3\Employees; |
|
|
|
use App\Model\v3\Order; |
|
|
|
use App\Model\v3\OrderGoods; |
|
|
|
use App\Model\v3\OrderMain; |
|
|
|
@ -12,10 +15,17 @@ use App\Model\v3\User; |
|
|
|
use App\Service\v3\Interfaces\MiniprogramServiceInterface; |
|
|
|
use EasyWeChat\Factory; |
|
|
|
use Hyperf\Guzzle\CoroutineHandler; |
|
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
|
|
|
|
|
class MiniprogramService implements MiniprogramServiceInterface |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var Log |
|
|
|
*/ |
|
|
|
protected $log; |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritDoc |
|
|
|
*/ |
|
|
|
@ -152,7 +162,7 @@ class MiniprogramService implements MiniprogramServiceInterface |
|
|
|
// 付款金额:{{amount1.DATA}}\n商户名称:{{thing2.DATA}}\n支付方式:{{thing3.DATA}}\n交易单号:{{character_string4.DATA}}\n交易时间:{{time5.DATA}}\n
|
|
|
|
$tmplId = 'PCRNmKGb7t98xsz_GPux3rhXjsu68TPI3nXR7749dC0'; |
|
|
|
$page = 'pages/faceOrderList/faceOrderList?store_id='.$store['id']; |
|
|
|
$this->sendSubscribeMessage( |
|
|
|
$res = $this->sendSubscribeMessage( |
|
|
|
$store['openid'], |
|
|
|
$tmplId, |
|
|
|
[ |
|
|
|
@ -223,6 +233,62 @@ class MiniprogramService implements MiniprogramServiceInterface |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritDoc |
|
|
|
*/ |
|
|
|
public function subscribeMsgForDeliveryStart($globalOrderId) |
|
|
|
{ |
|
|
|
// 主订单信息
|
|
|
|
$orderMain = OrderMain::query()->where(['global_order_id' => $globalOrderId])->first(); |
|
|
|
if (!$orderMain) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// 订单商品
|
|
|
|
$orderIds = Order::query()->where(['order_main_id' => $globalOrderId])->pluck('id'); |
|
|
|
$goodsInfo = OrderGoods::query()->whereIn('order_id', $orderIds)->pluck('name'); |
|
|
|
|
|
|
|
// 骑手信息
|
|
|
|
$horseman = Employees::query()->where(['id' => $orderMain->horseman_id, 'type' => Employee::TYPE_HORSEMAN])->first(); |
|
|
|
|
|
|
|
// 发送给用户的
|
|
|
|
// 订单编号:{{character_string6.DATA}}\n商品名称:{{thing8.DATA}}\n骑手信息:{{thing7.DATA}}\n送出时间:{{date3.DATA}}\n温馨提示:{{thing4.DATA}}\n
|
|
|
|
$userTmplId = 'jZMTjlflXrAO7bPk5Lq_rFjol9Yuq5i4czwwrJbteqk'; |
|
|
|
$userPage = 'pages/orderDetail/orderDetail?global_order_id=' . $globalOrderId; |
|
|
|
$userOpenid = User::query()->where(['id' => $orderMain->user_id])->value('openid'); |
|
|
|
$this->sendSubscribeMessage( |
|
|
|
$userOpenid, |
|
|
|
$userTmplId, |
|
|
|
[ |
|
|
|
'character_string6' => $orderMain->global_order_id, |
|
|
|
'thing8' => implode(';', $goodsInfo), |
|
|
|
'thing7' => $horseman->name.'(电话:'.$horseman->tel.')', |
|
|
|
'date3' => $orderMain->updated_at_text ?? '', |
|
|
|
'thing4' => '懒族骑手已经拿到您订单货品,马上开始配送,请您耐心等待,您可以点击订单详情查看,感谢使用!', |
|
|
|
], |
|
|
|
$userPage |
|
|
|
); |
|
|
|
|
|
|
|
// 发送给骑手的
|
|
|
|
// 订单编号:{{character_string1.DATA}}\n商品信息:{{thing8.DATA}}\n收货地址:{{thing9.DATA}}\n预约时间:{{time17.DATA}}\n温馨提示:{{thing11.DATA}}\n
|
|
|
|
$horsemanTmplId = '6gxjnBZ4bLnaMC0g8wRaP46jGUZU7YqfYb1FPpJVr50'; |
|
|
|
$horsemanPage = 'pages/deliverymanOrdersDetail/deliverymanOrdersDetail?global_order_id=' . $globalOrderId . '&employees_id=' . $horseman->id; |
|
|
|
$horsemanOpenid = User::query()->where(['id' => $horseman->user_id])->value('openid'); |
|
|
|
$this->sendSubscribeMessage( |
|
|
|
$horsemanOpenid, |
|
|
|
$horsemanTmplId, |
|
|
|
[ |
|
|
|
'character_string1' => $orderMain->global_order_id, |
|
|
|
'thing8' => implode(';', $goodsInfo), |
|
|
|
'thing9' => $orderMain->name . ' - ' . $orderMain->address . '(电话:'.$orderMain->tel.')', |
|
|
|
'time17' => $orderMain->delivery_time_note ?? '尽快送达', |
|
|
|
'thing4' => '后台已经派发此订单给您,请注意及时取货配送,您可以点击订单详情查看,辛苦了!', |
|
|
|
], |
|
|
|
$horsemanPage |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritDoc |
|
|
|
*/ |
|
|
|
@ -280,7 +346,15 @@ class MiniprogramService implements MiniprogramServiceInterface |
|
|
|
|
|
|
|
$app = Factory::miniProgram(config('wechat.applet')); |
|
|
|
$app['guzzle_handler'] = CoroutineHandler::class; |
|
|
|
$app->uniform_message->send($template); |
|
|
|
$res = $app->uniform_message->send($template); |
|
|
|
|
|
|
|
if (!isset($res['errcode']) || $res['errcode'] != '0') { |
|
|
|
|
|
|
|
$backtrace = debug_backtrace(); |
|
|
|
array_shift($backtrace); |
|
|
|
|
|
|
|
$this->log->event('template_message_error', ['from' => json_encode($backtrace), 'res' => json_encode($res), 'msg' => json_encode($template)]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function sendSubscribeMessage($openid, $template_id, $data, $page = '') |
|
|
|
@ -300,7 +374,15 @@ class MiniprogramService implements MiniprogramServiceInterface |
|
|
|
'data' => $data |
|
|
|
]; |
|
|
|
|
|
|
|
return $app->subscribe_message->send($msgData); |
|
|
|
$res = $app->subscribe_message->send($msgData); |
|
|
|
if (!isset($res['errcode']) || $res['errcode'] != '0') { |
|
|
|
|
|
|
|
$backtrace = debug_backtrace(); |
|
|
|
array_shift($backtrace); |
|
|
|
|
|
|
|
$this->log->event('subscribe_message_error', ['from' => json_encode($backtrace), 'res' => json_encode($res), 'msg' => json_encode($msgData)]); |
|
|
|
} |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
public function getSubscribeMessageTempList($forUserType) |
|
|
|
|