select('id','customer_id','fp','fz') ->get()->toArray(); if(! empty($data)){ // $fp_id = array_unique(array_column($data,'fp')); // $depart = Depart::where("del_time",0) // ->whereIn("id", $fp_id) // ->select('id','notify_id') // ->get()->toArray(); // $depart_map = array_column($depart,'notify_id','id'); // $fp_man_id = array_filter(array_unique(array_column($depart,'notify_id'))); $fz_id = array_unique(array_column($data,'fz')); // $employee_id = array_unique(array_merge($fp_man_id, $fz_id)); $employee_id = array_unique($fz_id); $wx_map = WxEmployeeOfficial::whereIn('employee_id', $employee_id) ->pluck('openid','employee_id') ->toArray(); $send_data = $insert = []; $customer_id = []; foreach ($data as $value){ if(! empty($value['fp'])) { $insert[] = [ 'data_id' => $value['customer_id'], //客户id 'data_type' => SeeRange::type_one, 'param_id' => $value['fp'], //门店id 'type' => SeeRange::data_three, 'crt_time' => $time, ]; $customer_id[] = $value['customer_id']; } $open_id_fz = $wx_map[$value['fz']] ?? ""; // $fp_man_t = $depart_map[$value['fp']] ?? 0; // $open_id_fp = $wx_map[$fp_man_t] ?? ""; //负责人 和 门店负责人都为空跳过 // if(empty($open_id_fz) && empty($open_id_fp)) continue; if(empty($open_id_fz)) continue; //组织发送 $this->makeData($send_data, $open_id_fz, $value); // $this->makeData($send_data, $open_id_fp, $value); } if(! empty($send_data)){ echo "发送中\n"; $send_data = array_values($send_data); (new OaService())->sendWxOaCheckMessage($send_data, 1); } $c_id = array_column($data,'customer_id'); //清空分配门店 SeeRange::where('del_time',0) ->whereIn('data_id', $c_id) ->where('data_type',SeeRange::type_one) ->where('type',SeeRange::data_three) ->update(['del_time' => $time]); //分配门店 if(! empty($insert)) SeeRange::insert($insert); //更新单据 CrModel::whereIn('id',array_column($data,'id')) ->update(['del_time' => $time]); if(! empty($customer_id)) Customer::whereIn('id', $customer_id)->update(['fp_time' => $time]); }else{ echo "暂无\n"; } echo '发送提醒--------end---------------'; } private function makeData(&$send_data, $open_id, $value){ if(! empty($open_id)) { if(! isset($send_data[$open_id])){ $send_data[$open_id] = [ 'employee_id' => 12343215, 'type' => 2, 'state' => 0, 'menu_id' => "16|list", 'openid' => $open_id, 'order_number' => $value['customer_id'], 'tmp_data' => [ time(), "客资分配提醒", "已分配", "T9品牌中心", date('Y-m-d H:i:s'), ], ]; }else{ $tmp = explode(',', $send_data[$open_id]['order_number']); if(! in_array($value['customer_id'], $tmp)) $send_data[$open_id]['order_number'] .= ',' . $value['customer_id']; } } } }