|
|
@@ -578,25 +578,37 @@ class OrderService extends Service
|
|
|
if(count($reminders) >= 10) return [false, '批量操作一次最多10条'];
|
|
|
|
|
|
$details = ReminderDetails::from('reminder_details as a')
|
|
|
- ->leftjoin('wx_employee_official as b','b.employee_id','a.customer_supply_id')
|
|
|
+ ->leftJoin('wx_employee_official as b', function($join) use ($appid) {
|
|
|
+ $join->on('b.employee_id', '=', 'a.customer_supply_id')
|
|
|
+ ->where('b.type', WxEmployeeOfficial::login_type_one)
|
|
|
+ ->where('b.appid', $appid);
|
|
|
+ })
|
|
|
->where('a.del_time',0)
|
|
|
- ->where('b.type',WxEmployeeOfficial::login_type_one)
|
|
|
- ->where('b.appid',$appid)
|
|
|
->whereIn('a.reminder_id', array_column($reminders,'id'))
|
|
|
->select('a.reminder_id','a.customer_supply_id','b.openid')
|
|
|
->get()->toArray();
|
|
|
if (empty($details)) return [false, '未找到任何可发送的微信消息的供应商'];
|
|
|
|
|
|
+ $map = CustomerSupply::whereIn('id', array_column($details,'customer_supply_id'))->pluck('title','id')->toArray();
|
|
|
+
|
|
|
// 按 reminder_id 分组
|
|
|
- $detailMap = [];
|
|
|
+ $detailMap = [];$fail_2 = "";
|
|
|
foreach ($details as $d) {
|
|
|
if (! empty($d['openid'])) {
|
|
|
$detailMap[$d['reminder_id']][] = [
|
|
|
'open_id' => $d['openid'],
|
|
|
'employee_id' => $d['customer_supply_id'],
|
|
|
];
|
|
|
+ }else{
|
|
|
+ $t = $map[$d['customer_supply_id']] ?? "";
|
|
|
+ if(empty($openid)){
|
|
|
+ $fail_2 .= $t . ",";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if(! empty($fail_2)){
|
|
|
+ $fail_2 = "(" . rtrim($fail_2,',') . ")未绑定公众号";
|
|
|
+ }
|
|
|
|
|
|
$wxService = new WxTemplateMessageService();
|
|
|
|
|
|
@@ -613,8 +625,8 @@ class OrderService extends Service
|
|
|
|
|
|
$product_detail = $reminder['product_title'] . ',数量:' . $reminder['tl_quantity'];
|
|
|
foreach ($d_array as $value) {
|
|
|
- $openid = $value['open_id'];
|
|
|
$employee_id = $value['employee_id'];
|
|
|
+ $openid = $value['open_id'];
|
|
|
$params = [
|
|
|
'order_number' => $reminder['order_number'] ?? '',
|
|
|
'product_detail' => $product_detail ?? '暂无',
|
|
|
@@ -656,8 +668,8 @@ class OrderService extends Service
|
|
|
|
|
|
// ④ 结果统计返回
|
|
|
$resultMsg = "共需发送 {$total} 条模板消息,成功 {$success} 条,失败 {$fail} 条。";
|
|
|
+ if(! empty($fail_2)) $resultMsg .= "其中 {$fail_2}";
|
|
|
if ($fail > 0) {
|
|
|
- $resultMsg .= ' 失败详情见日志。';
|
|
|
Log::error('微信模板消息发送失败详情', $failList);
|
|
|
}
|
|
|
|