|
|
@@ -11,6 +11,11 @@ use Illuminate\Queue\SerializesModels;
|
|
|
use App\Models\Manager\Personnel\Employee as EmployeeModel;
|
|
|
use App\Facades\Servers\Wechat\Official;
|
|
|
use App\Facades\Servers\Logs\Log;
|
|
|
+use Illuminate\Support\Carbon;
|
|
|
+use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
|
|
|
+use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -41,40 +46,148 @@ class Subscription implements ShouldQueue
|
|
|
public function handle()
|
|
|
{
|
|
|
try {
|
|
|
- $this->send($this->message_data['user_id_list'], $this->message_data['msg_title']);
|
|
|
+ $notice_type = $this->message_data['notice_type'];
|
|
|
+ $map = [];
|
|
|
+ $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
|
|
|
+ $todayEnd = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
|
|
|
+ switch ($notice_type) {
|
|
|
+ case 'low_price_goods':
|
|
|
+ $LowPriceGoodsMemberModel = new LowPriceGoodsMemberModel();
|
|
|
+
|
|
|
+ //查询今日待处理低价商品责任人
|
|
|
+ $map[] = ['process_lowprice_product.insert_time', '>=', $todayStart];
|
|
|
+ $map[] = ['process_lowprice_product.insert_time', '<=', $todayEnd];
|
|
|
+
|
|
|
+ $process_data = $LowPriceGoodsMemberModel
|
|
|
+ ->join('process_lowprice_product', 'process_lowprice_product_member.lowprice_product_logid', '=', 'process_lowprice_product.id')
|
|
|
+ ->where($map)
|
|
|
+ ->where([
|
|
|
+ 'process_lowprice_product.processing_status' => '1',
|
|
|
+ 'process_lowprice_product_member.duty_type' => '1'
|
|
|
+ ])
|
|
|
+ ->groupBy('process_lowprice_product_member.employee_id') // 按员工ID分组
|
|
|
+ ->select(
|
|
|
+ 'process_lowprice_product_member.employee_id',
|
|
|
+ DB::raw('count(*) as total_number') // 统计每个员工的数量
|
|
|
+ )
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if (empty($process_data)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为原来的数组格式
|
|
|
+ $user_id_list = [];
|
|
|
+ foreach ($process_data as $value) {
|
|
|
+ $user_id_list[$value->employee_id] = [
|
|
|
+ 'totle_number' => $value->total_number
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->send_low_price_goods_notice($user_id_list);
|
|
|
+ break;
|
|
|
+ case 'violation_product':
|
|
|
+ $ViolationProductMemberModel = new ViolationProductMemberModel();
|
|
|
+
|
|
|
+ //查询今日待处理禁止商品责任人
|
|
|
+ $map[] = ['process_violation_product.insert_time', '>=', $todayStart];
|
|
|
+ $map[] = ['process_violation_product.insert_time', '<=', $todayEnd];
|
|
|
+
|
|
|
+ $process_data = $ViolationProductMemberModel
|
|
|
+ ->join('process_violation_product', 'process_violation_product_member.lowprice_product_logid', '=', 'process_violation_product.id')
|
|
|
+ ->where($map)
|
|
|
+ ->where(['process_violation_product.processing_status' => '1', 'process_violation_product_member.duty_type' => '1'])
|
|
|
+ ->groupBy('process_violation_product_member.employee_id') // 按员工ID分组
|
|
|
+ ->select(
|
|
|
+ 'process_violation_product_member.employee_id',
|
|
|
+ DB::raw('count(*) as total_number') // 统计每个员工的数量
|
|
|
+ )
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if (empty($process_data)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为数组格式(如果需要原来的格式)
|
|
|
+ $user_id_list = [];
|
|
|
+ foreach ($process_data as $value) {
|
|
|
+ $user_id_list[$value['employee_id']] = [
|
|
|
+ 'totle_number' => $value['total_number']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->send_violation_product($user_id_list);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
} catch (\Exception $e) {
|
|
|
Log::info('job_error', '订阅消息通知推送队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 公众号消息订阅推送
|
|
|
- *
|
|
|
- * */
|
|
|
- private function send($user_id_list, $msg_title = '')
|
|
|
+ * 公众号消息订阅推送(低价挂网)
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-04
|
|
|
+ */
|
|
|
+ private function send_low_price_goods_notice($user_id_list)
|
|
|
{
|
|
|
$EmployeeModel = new EmployeeModel();
|
|
|
- $user_list = $EmployeeModel->whereIn('id',$user_id_list)->where([['open_subscribe', '=', 0], ['status', '=', 1]])->select(['openid'])->select();
|
|
|
- if(empty($user_list)) return true;
|
|
|
- $data = [
|
|
|
- 'thing1' => $msg_title,
|
|
|
- 'thing2' => '您有一条新的违规待处理通知要处理,请及时查看',
|
|
|
- 'time7' => strtotime(time(), 'Y:m:d H:i:s'),
|
|
|
- 'phrase9' => '待处理',
|
|
|
- ];
|
|
|
- foreach ($user_list as $value) {
|
|
|
+ foreach ($user_id_list as $key => $totle_number) {
|
|
|
+ $user_info = $EmployeeModel->where('id', $key)->where([['open_subscribe', '=', 0], ['status', '=', 1]])->first(['openid']);
|
|
|
+ if (empty($user_info)) return true;
|
|
|
+ if ($user_info['openid'] == '') return true;
|
|
|
+ $data = [
|
|
|
+ 'thing1' => '数据违规预警',
|
|
|
+ 'thing2' => '低价挂网商品:共【' . $totle_number . '】条',
|
|
|
+ 'time7' => strtotime(time(), 'Y:m:d H:i:s'),
|
|
|
+ 'phrase9' => '待处理',
|
|
|
+ ];
|
|
|
$params = [
|
|
|
- 'touser' => $value['openid'],
|
|
|
+ 'touser' => $user_info['openid'],
|
|
|
'template_id' => 't559Iagds7Av-YcqwIpeAaS5gt7LuOKuIBDvVKlyfm8',
|
|
|
'url' => '',
|
|
|
'data' => $data,
|
|
|
];
|
|
|
//发送模板消息
|
|
|
$result = Official::sendSubscription($params);
|
|
|
+ if (!empty($result) && isset($result['error'])) {
|
|
|
+ Log::info('job_notice', '公众号消息订阅推送失败', ['data' => $params, 'error' => $result]);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 告知结果
|
|
|
- return json_send(['code' => 'success', 'msg' => '成功', 'path' => '']);
|
|
|
+ /**
|
|
|
+ * 公众号消息订阅推送(禁止挂网)
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-03-04
|
|
|
+ */
|
|
|
+ private function send_violation_product($user_id_list)
|
|
|
+ {
|
|
|
+ $EmployeeModel = new EmployeeModel();
|
|
|
+ foreach ($user_id_list as $key => $totle_number) {
|
|
|
+ $user_info = $EmployeeModel->where('id', $key)->where([['open_subscribe', '=', 0], ['status', '=', 1]])->first(['openid']);
|
|
|
+ if (empty($user_info)) return true;
|
|
|
+ if ($user_info['openid'] == '') return true;
|
|
|
+ $data = [
|
|
|
+ 'thing1' => '数据违规预警',
|
|
|
+ 'thing2' => '禁止挂网商品:共【' . $totle_number . '】条',
|
|
|
+ 'time7' => strtotime(time(), 'Y:m:d H:i:s'),
|
|
|
+ 'phrase9' => '待处理',
|
|
|
+ ];
|
|
|
+ $params = [
|
|
|
+ 'touser' => $user_info['openid'],
|
|
|
+ 'template_id' => 't559Iagds7Av-YcqwIpeAaS5gt7LuOKuIBDvVKlyfm8',
|
|
|
+ 'url' => '',
|
|
|
+ 'data' => $data,
|
|
|
+ ];
|
|
|
+ //发送模板消息
|
|
|
+ $result = Official::sendSubscription($params);
|
|
|
+ if (!empty($result) && isset($result['error'])) {
|
|
|
+ Log::info('job_notice', '公众号消息订阅推送失败', ['data' => $params, 'error' => $result]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|