Browse Source

商户发送订阅消息,退款,下单,当面付

master
weigang 5 years ago
parent
commit
6b3db38b76
  1. 13
      app/JsonRpc/OrdersService.php
  2. 6
      app/Model/v3/Order.php
  3. 73
      app/Service/v3/Implementations/MiniprogramService.php
  4. 9
      app/Service/v3/Interfaces/MiniprogramServiceInterface.php

13
app/JsonRpc/OrdersService.php

@ -10,7 +10,9 @@ use App\Exception\ErrorCodeException;
use App\Model\v3\Order;
use App\Model\v3\OrderGoods;
use App\Model\v3\OrderMain;
use App\Model\v3\User;
use App\Service\v3\Interfaces\FinancialRecordServiceInterface;
use App\Service\v3\Interfaces\MiniprogramServiceInterface;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use EasyWeChat\Factory;
@ -56,6 +58,12 @@ class OrdersService implements OrdersServiceInterface
*/
protected $badgeService;
/**
* @Inject
* @var MiniprogramServiceInterface
*/
protected $miniprogramService;
/**
* 订单完成
* @param $global_order_id
@ -309,11 +317,16 @@ class OrdersService implements OrdersServiceInterface
// 计算本次退款实际退款金额
$refundStoreAmount = bcsub($order->money, $couponMoney, 2);
$this->financialRecordService->storeRefundDirect($order->store->user_id, $order->id, $refundStoreAmount);
$this->miniprogramService->subscribeMsgForSingleRefund($order->id, $refundStoreAmount);
}
} elseif ($refundType == 'sub'||$refundType == 'goods') { # 退子订单或者退单品的话,商户只有一个
$orderChildren = Order::query()->with('store:user_id')->where(['id' => $order_child_id])->get();
$this->financialRecordService->storeRefundDirect($orderChild->store->user_id, $orderChild->id, $refundAmount);
$orderGoodsId = $order_goods_id ?? '';
$this->miniprogramService->subscribeMsgForSingleRefund($order_child_id, $refundAmount, $orderGoodsId);
}
$this->financialRecordService->userRefundDirect($orderMain->user_id, $orderMain->global_order_id, $refundAmount);

6
app/Model/v3/Order.php

@ -10,6 +10,7 @@ class Order extends Model
protected $appends = [
'created_at_text',
'updated_at_text',
];
protected $fillable = [
@ -34,6 +35,11 @@ class Order extends Model
return date('Y-m-d H:i:s', $this->attributes['created_at']);
}
public function getUpdatedAtTextAttribute()
{
return date('Y-m-d H:i:s', $this->attributes['updated_at']);
}
public function orderGoods()
{
return $this->hasMany(OrderGoods::class, 'order_id', 'id');

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

@ -2,6 +2,7 @@
namespace App\Service\v3\Implementations;
use App\Constants\v3\Payment;
use App\Model\v3\Order;
use App\Model\v3\OrderGoods;
use App\Model\v3\OrderMain;
@ -71,6 +72,23 @@ class MiniprogramService implements MiniprogramServiceInterface
];
$ret_store = $this->sendTempMsg($store['openid'], '-M7DG_ACwJxqdAvyvJuAnPpx4xaLf3VkkN0fckno71c',$data_store);
// 小程序订阅消息发给商户
// 支付金额:{{amount1.DATA}}\n订单编号:{{character_string2.DATA}}\n支付时间:{{date3.DATA}}\n商品详情:{{thing4.DATA}}\n备注:{{thing7.DATA}}\n
$tmplId = 'UfCON4Dj_7aH_Q5k_HvDgzUb3gu67TokPITsJuvCMxc';
$page = 'pages/shopOrders/shopOrders?status=paid&store_id='.$store['id'];
$this->sendSubscribeMessage(
$store['openid'],
$tmplId,
[
'amount1' => $item->money,
'character_string2' => $item->order_num,
'date3' => $item->created_at_text??'',
'thing4' => implode(";", $goods_temp_all),
'thing7' => $item->note,
],
$page
);
}
// 模板数据发送消息给用户
@ -98,6 +116,9 @@ class MiniprogramService implements MiniprogramServiceInterface
public function sendTemMsgForOfflineOrder($globalOrderId)
{
// 主订单信息
$orderMain = OrderMain::query()->where(['global_order_id' => $globalOrderId])->first();
// 查询子订单,用于发消息给商户
$order_children = Order::query()
->where(['order_main_id' => $globalOrderId])
@ -126,6 +147,23 @@ class MiniprogramService implements MiniprogramServiceInterface
];
$ret_store = $this->sendTempMsg($store['openid'], 'lxVbC6PVpKbiO44bYqLmacl-BaME70D47Q0jn2Link0',$data_store);
// 小程序订阅消息发给商户
// 付款金额:{{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(
$store['openid'],
$tmplId,
[
'amount1' => $item['money'],
'thing2' => $store['name'],
'thing3' => Payment::getMessage($orderMain->pay_type),
'character_string4' => $item['order_num'],
'time5' => $item['created_at_text']??'',
],
$page
);
}
}
@ -150,6 +188,41 @@ class MiniprogramService implements MiniprogramServiceInterface
$ret_user = $this->sendTempMsg($openid,'ypZ7xdHUjWrRG8P-MD42dhpp6kUlh4Unoh7eTSrLZEg', $data_user);
}
/**
* @inheritDoc
*/
public function subscribeMsgForSingleRefund($orderId, $refundStoreAmount, $orderGoodsId = '')
{
$order = Order::query()->where(['id' => $orderId])->first();
$store = Store::query()->where(['id' => $order->store_id])->first();
$storeOpenid = User::query()->where(['id' => $store->user_id])->value('openid');
$goodsInfo = [];
if ($orderGoodsId) {
$goodsInfo = OrderGoods::query()->where(['id' => $orderGoodsId])->pluck('name')->toArray();
} else {
$goodsInfo = OrderGoods::query()->where(['order_id' => $orderId])->pluck('name')->toArray();
}
// 小程序订阅消息发给商户
// 订单编号:{{character_string7.DATA}}\n商品名称:{{thing10.DATA}}\n退款金额:{{amount3.DATA}}\n处理时间:{{date4.DATA}}\n退款说明:{{thing5.DATA}}\n
$tmplId = 'OaWeg0q40NVW2WeO5BY1TFdWi4GsgIY1rFBwo2wDa0g';
$page = 'pages/shopOrders/shopOrders?status=refund&store_id='.$store->id;
$this->sendSubscribeMessage(
$storeOpenid,
$tmplId,
[
'character_string7' => $order->order_num,
'thing10' => implode(';', $goodsInfo),
'amount3' => $refundStoreAmount,
'date4' => $order->updated_at_text ?? '',
'thing5' => $order->refund_note,
],
$page
);
}
/**
* @inheritDoc
*/

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

@ -28,6 +28,15 @@ interface MiniprogramServiceInterface
*/
public function sendTemMsgForAward($money, $note, $openid, $time);
/**
* 直接退款时订阅消息通知商户
* @param $orderId
* @param $refundStoreAmount
* @param $orderGoodsId
* @return mixed
*/
public function subscribeMsgForSingleRefund($orderId, $refundStoreAmount, $orderGoodsId = '');
/**
* 发送模板消息
* @param $openid

Loading…
Cancel
Save