love_php/app/Imports/SingleProfilesImport.php

373 lines
12 KiB
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Imports;
use App\Models\SingleProfile;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\ToCollection;
use Illuminate\Support\Collection;
use App\Models\ProfileCourtship;
use App\Models\ProfileMarriage;
use App\Models\GoodMatch;
use App\Utils\Http;
use Exception;
class SingleProfilesImport implements ToArray
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return ;
}
public function collection(Collection $rows)
{
return;
}
public function Array(Array $tables)
{
//检查第一行的字段是否正确
if (is_array($tables) && count($tables)) {
$result = $this->checkField($tables[0]);
if (!empty($result)) {
// return $result;
throw new Exception("参数错误: ". $result, 1);
}
}
$profiles = [];
$tables = array_splice($tables,1);
foreach ($tables as $table) {
if (empty($table[1]) && empty($table[0])) {
break;
}
$profile = [];
$profile['name'] = $table[0];
$profile['sex'] = $table[1];
$profile['mobile'] = $table[2];
$profile['mobile'] = $table[2];
if (empty($profile['mobile'])) {
return;
}
#是否是内地号码
if (strlen($profile['mobile']) == 14 && strstr($profile['mobile'], '+86')) {
$profile['mobile'] = substr($profile['mobile'], 3);
}
$profile['birthday'] = $table[3].'-01-01';
$lover_birthday_arr = explode('', $table[4]);
$profile['lover_min_birthday'] = explode('', $lover_birthday_arr[0])[1].'-01-01';
$profile['lover_max_birthday'] = explode('', $lover_birthday_arr[1])[1].'-01-01';
$profile['stature'] = $table[5];
$profile['lover_stature'] = $table[6];
$profile['state'] = $table[7];
$profile['lover_state'] = json_encode($table[8], JSON_UNESCAPED_UNICODE);
$profile['has_child'] = $table[9];
$profile['lover_has_child'] = $table[10];
$profile['resident_province'] = $table[11];
$profile['resident_city'] = $table[12];
$profile['resident_dist'] = $table[13];
$profile['resident_address'] = $table[14];
$profile['province'] = $table[15];
$profile['city'] = $table[16];
$profile['dist'] = $table[17];
$profile['address'] = $table[18];
$profile['marriage_province'] = $table[19];
$profile['marriage_city'] = $table[20];
$profile['marriage_dist'] = $table[21];
$profile['marriage_place'] = $table[22];
$profile['character'] = $table[23];
$profile['lover_character'] = $table[24];
$profile['is_initiative'] = $table[25];
$profile['pay_type'] = $table[26];
$profile['single_reason'] = $table[27];
$profile['post'] = $table[28];
$profile['post_out'] = $table[29];
$profile['lover_post_out'] = $table[30];
$profile['lover_condition'] = $table[31];
$profile['degree'] = $table[32];
$profile['lover_degree'] = $table[33];
$profile['join_activity'] = $table[34];
$profile['study_love'] = $table[35];
$profile['income'] = $table[36];
$profile['lover_income'] = $table[37];
$profile['without_income'] = $table[38];
$profile['belief'] = $table[39];
$profile['lover_standrad'] = $table[40];
$profile['hold_wedding'] = $table[41];
$profile['live_idea'] = $table[42];
$profile['premarital_counseling'] = $table[43];
$from_user_id = $table[44];
$from_user_id_arr = explode('_', $from_user_id);
$from_user_id = count($from_user_id_arr)&&is_numeric($from_user_id_arr[0])?$from_user_id_arr[0]:null;
$profile['from_user_id'] = $from_user_id;
$profile['wechat_nickname'] = $table[45];
$profile['wechat_sex'] = $table[46];
$profile['wechat_country'] = $table[47];
$profile['wechat_address'] = $table[48];
$profile['openid'] = $table[49];
$profile['avatar'] = $table[50];
$profile['submitter'] = $table[51];
$profile['submit_time'] = $table[52];
$profile['update_time'] = $table[53];
$profile['devices'] = $table[54];
$profile['os'] = $table[55];
$profile['browser'] = $table[56];
$profile['ip'] = $table[57];
$profile['is_import'] = 1;
$profile['created_at'] = date("Y-m-d H:i:s");
$profile['updated_at'] = date('Y-m-d H:i:s');
$profiles[] = $profile;
//存在手机号删除记录
SingleProfile::where('mobile', $profile['mobile'])->delete();
}
SingleProfile::insert($profiles);
return '';
}
public function checkField($table)
{
#姓名
if ($table[0] != 'name') {
return 'name';
}
#手机号
if ($table[1] != 'sex') {
return 'sex';
}
#性别
if ($table[2] != 'mobile') {
return 'mobile';
}
#年纪
if ($table[3] != 'birthday') {
return 'birthday';
}
#出生地址
if ($table[4] != 'lover_birthday') {
return 'lover_birthday';
}
#工作地址
if ($table[5] != 'stature') {
return 'stature';
}
#婚姻状况
if ($table[6] != 'lover_stature') {
return 'lover_stature';
}
#是否恋爱过
if ($table[7] != 'state') {
return 'state';
}
#結婚計劃
if ($table[8] != 'lover_state') {
return 'lover_state';
}
#伴侣是否本地
if ($table[9] != 'has_chirld') {
return 'has_chirld';
}
#计划结婚地点
if ($table[10] != 'lover_has_child') {
return 'lover_has_child';
}
#您认为找对象最好的方式是
if ($table[11] != 'resident_province') {
return 'resident_province';
}
#您择偶时主要考虑哪些条件
if ($table[12] != 'resident_city') {
return 'resident_city';
}
#您在选择配偶时,愿意选择对方综合条件
if ($table[13] != 'resident_dist') {
return 'resident_dist';
}
#您在选择配偶时如何考虑父母的意见
if ($table[14] != 'resident_address') {
return 'resident_address';
}
#您认为男女双方结婚时的年龄为下列哪种情况最好
if ($table[15] != 'province') {
return 'province';
}
#您对恋爱的理解是
if ($table[16] != 'city') {
return 'city';
}
#您对恋爱与婚姻的关系有何理解
if ($table[17] != 'dist') {
return 'dist';
}
#你觉得恋爱会或者已经对你的学习和生活造成了怎样的影响呢
if ($table[18] != 'address') {
return 'address';
}
#您认为什么是婚姻的基础
if ($table[19] != 'marriage_province') {
return 'marriage_province';
}
#爱情和金钱您会如何选择
if ($table[20] != 'marriage_city') {
return 'marriage_city';
}
#微信昵称
if ($table[21] != 'marriage_dist') {
return 'marriage_dist';
}
#微信性别
if ($table[22] != 'marriage_place') {
return 'marriage_place';
}
#微信国家
if ($table[23] != 'character') {
return 'character';
}
#微信地址
if ($table[24] != 'lover_character') {
return 'lover_character';
}
#微信openid
if ($table[25] != 'is_initiative') {
return 'is_initiative';
}
#头像
if ($table[26] != 'pay_type') {
return 'pay_type';
}
#提交人
if ($table[27] != 'single_reason') {
return 'single_reason';
}
#提交时间
if ($table[28] != 'post') {
return 'post';
}
#修改时间
if ($table[29] != 'post_out') {
return 'post_out';
}
#设备
if ($table[30] != 'lover_post_out') {
return 'lover_post_out';
}
#操作糸统
if ($table[31] != 'lover_condition') {
return 'lover_condition';
}
#浏览器
if ($table[32] != 'degree') {
return 'degree';
}
#ip
if ($table[33] != 'lover_degree') {
return 'lover_degree';
}
#设备
if ($table[34] != 'join_activity') {
return 'join_activity';
}
#操作糸统
if ($table[35] != 'study_love') {
return 'study_love';
}
#浏览器
if ($table[36] != 'income') {
return 'income';
}
#ip
if ($table[37] != 'lover_income') {
return 'lover_income';
}
#操作糸统
if ($table[38] != 'without_income') {
return 'without_income';
}
#浏览器
if ($table[39] != 'belief') {
return 'belief';
}
#ip
if ($table[40] != 'lover_standrad') {
return 'lover_standrad';
}
#设备
if ($table[41] != 'hold_wedding') {
return 'hold_wedding';
}
#操作糸统
if ($table[42] != 'live_idea') {
return 'live_idea';
}
#浏览器
if ($table[43] != 'premarital_counseling') {
return 'premarital_counseling';
}
#邀請人
if ($table[44] != 'from_user_id') {
return 'from_user_id';
}
#ip
if ($table[45] != 'wechat_nickname') {
return 'wechat_nickname';
}
if ($table[46] != 'wechat_sex') {
return 'wechat_sex';
}
#浏览器
if ($table[47] != 'wechat_country') {
return 'wechat_country';
}
#ip
if ($table[48] != 'wechat_address') {
return 'wechat_address';
}
#设备
if ($table[49] != 'openid') {
return 'openid';
}
#操作糸统
if ($table[50] != 'avatar') {
return 'avatar';
}
#浏览器
if ($table[51] != 'submitter') {
return 'submitter';
}
#ip
if ($table[52] != 'submit_time') {
return 'submit_time';
}
if ($table[53] != 'update_time') {
return 'update_time';
}
#ip
if ($table[54] != 'devices') {
return 'devices';
}
#设备
if ($table[55] != 'os') {
return 'os';
}
#操作糸统
if ($table[56] != 'browser') {
return 'browser';
}
#浏览器
if ($table[57] != 'ip') {
return 'ip';
}
return '';
}
}