Browse Source

订阅消息

master
weigang 5 years ago
parent
commit
5d96a9bd97
  1. 42
      app/Service/v3/Implementations/MiniprogramService.php
  2. 19
      app/Service/v3/Implementations/OrderOnlineService.php
  3. 9
      app/Service/v3/Interfaces/MiniprogramServiceInterface.php

42
app/Service/v3/Implementations/MiniprogramService.php

@ -95,7 +95,7 @@ class MiniprogramService implements MiniprogramServiceInterface
'character_string2' => $item->order_num,
'date3' => $item->created_at_text??'',
'thing4' => implode(";", $goods_temp_all),
'thing7' => $item->note,
'thing7' => $item->note??'无备注',
],
$page
);
@ -227,7 +227,7 @@ class MiniprogramService implements MiniprogramServiceInterface
'thing10' => implode(';', $goodsInfo),
'amount3' => $refundStoreAmount,
'date4' => $order->updated_at_text ?? '',
'thing5' => $order->refund_note,
'thing5' => $order->refund_note ?? '退款',
],
$page
);
@ -249,7 +249,7 @@ class MiniprogramService implements MiniprogramServiceInterface
$goodsInfo = OrderGoods::query()->whereIn('order_id', $orderIds)->pluck('name');
// 骑手信息
$horseman = Employees::query()->where(['id' => $orderMain->horseman_id])->whereJsonContains('positions', [(string)Employee::TYPE_HORSEMAN])->first();
$horseman = Employees::query()->where(['id' => $orderMain->horseman_id])->whereJsonContains('position', [(string)Employee::TYPE_HORSEMAN])->first();
// 发送给用户的
// 订单编号:{{character_string6.DATA}}\n商品名称:{{thing8.DATA}}\n骑手信息:{{thing7.DATA}}\n送出时间:{{date3.DATA}}\n温馨提示:{{thing4.DATA}}\n
@ -289,6 +289,42 @@ class MiniprogramService implements MiniprogramServiceInterface
}
/**
* @inheritDoc
*/
public function subscribeMsgForOrderComplete($orderMain)
{
// 主订单信息
if (!($orderMain instanceof OrderMain)) {
$orderMain = OrderMain::query()->where(['global_order_id' => $orderMain])->first();
}
if (!$orderMain) {
return false;
}
// 骑手信息
$horseman = Employees::query()->where(['id' => $orderMain->horseman_id])->whereJsonContains('position', [(string)Employee::TYPE_HORSEMAN])->first();
// 发送小程序订阅消息给用户提示用户订单完成
// 订单编号:{{character_string2.DATA}}\n订单金额:{{amount5.DATA}}\n配送地址:{{thing3.DATA}}\n配送人员:{{thing4.DATA}}\n送达时间:{{time6.DATA}}\n
$userTmplId = 'slYHfLTzKDGWRxnNLyJBr7sb__PEhh9OCrSBpMW_pdE';
$userPage = 'pages/orderDetail/orderDetail?global_order_id=' . $orderMain->global_order_id;
$userOpenid = User::query()->where(['id' => $orderMain->user_id])->value('openid');
$this->sendSubscribeMessage(
$userOpenid,
$userTmplId,
[
'character_string2' => $orderMain->global_order_id,
'amount5' => $orderMain->money,
'thing3' => $orderMain->name . ' - ' . $orderMain->address . '(电话:'.$orderMain->tel.')',
'thing4' => $horseman->name.'(电话:'.$horseman->tel.')',
'time6' => date('Y-m-d H:i:s', $orderMain->complete_time_text),
],
$userPage
);
}
/**
* @inheritDoc
*/

19
app/Service/v3/Implementations/OrderOnlineService.php

@ -3,6 +3,7 @@
namespace App\Service\v3\Implementations;
use App\Commons\Log;
use App\Constants\v3\Employee;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel;
use App\Constants\v3\OrderState;
@ -31,6 +32,7 @@ use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
use App\Service\v3\Interfaces\GoodsInventoryServiceInterface;
use App\Service\v3\Interfaces\GoodsServiceInterface;
use App\Service\v3\Interfaces\InitialDeliveryServiceInterface;
use App\Service\v3\Interfaces\MiniprogramServiceInterface;
use App\Service\v3\Interfaces\PaymentServiceInterface;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
use App\Service\v3\Interfaces\UserAddressServiceInterface;
@ -113,6 +115,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface
*/
protected $goodsInventoryService;
/**
* @Inject
* @var MiniprogramServiceInterface
*/
protected $miniprogramService;
/**
* 下单
* @param $marketId
@ -749,11 +757,14 @@ class OrderOnlineService implements OrderOnlineServiceInterface
throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
}
// 记录badge
$orderChildIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('store_id');
$this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::COMPLETED);
co(function () use ($orderMain) {
// 记录badge
$orderChildIds = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->pluck('store_id');
$this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::COMPLETED);
// 发送小程序订阅消息给用户提示用户订单完成
// 发送订阅消息
$this->miniprogramService->subscribeMsgForOrderComplete($orderMain);
});
return true;
}

9
app/Service/v3/Interfaces/MiniprogramServiceInterface.php

@ -2,6 +2,8 @@
namespace App\Service\v3\Interfaces;
use App\Model\v3\OrderMain;
interface MiniprogramServiceInterface
{
/**
@ -44,6 +46,13 @@ interface MiniprogramServiceInterface
*/
public function subscribeMsgForDeliveryStart($globalOrderId);
/**
* 订单完成发送订阅消息给用户
* @param OrderMain|int|string $orderMain 模型实例或者globalOrderId
* @return mixed
*/
public function subscribeMsgForOrderComplete($orderMain);
/**
* 发送模板消息
* @param $openid

Loading…
Cancel
Save