get(); $sys_count = 0; $sys_last_id = 0; if ($sys->isNotEmpty()) { $sys_data = []; foreach ($sys as $k => $v) { $time = date('Y-m-d H:i:s', $v->dateline); $sys_data = array( 'id' => $v->spmid, 'user_type' => $v->spms_usertype, 'news_type' => 1, 'type' => $v->spms_type, 'content' => $v->message, 'started_at' => 0, 'ended_at' => 0, 'subsite_id' => $v->subsite_id, 'created_at' => $time, 'updated_at' => $time ); if (SysMessage::insert($sys_data)) { //添加分站对应关系 $subsite_data = array( 'sys_message_id' => $v->spmid, 'subsite_id' => $v->subsite_id, 'created_at' => null, 'updated_at' => null, ); SubsiteSysMessage::insert($subsite_data); $sys_count++; $sys_last_id = $v->spmid; } else { $this->info('导入系统站内信'.$v->spmid.'失败'); } } } $this->info("导入系统站内信:".$sys_count.'条,最后导入的系统站内信id是:'.$sys_last_id); //添加个人消息 $num = 3000; $all_count = intval(Pms::count()/$num) +1; for ($i=0; $i<$all_count; $i++) { $insert=[]; $list = Pms::with(['memberInfo'])->offset($i * $num)->limit($num)->get(); if ($list) { foreach ($list as $key => $val) { $utype = 0; if ($val->memberInfo) { $utype = $val->memberInfo->utype; $insert[$key] = array( 'id' => $val->pmid, 'utype' => $utype, 'msgtype' => $val->msgtype, 'msgfromuid' => $val->msgfromuid, 'msgfrom' => $val->msgfrom, 'msgtoname' => $val->msgtoname, 'msgtouid' => $val->msgtouid, 'message' => $val->message, 'started_at' => 0, 'ended_at' => 0, 'new' => $val->new, 'created_at' => date('Y-m-d H:i:s', $val->dateline), 'updated_at' => date('Y-m-d H:i:s', $val->dateline) ); } } if (newPms::insert($insert)) { $has_total = (int)(count($insert) + $i*$num); $this->info('已导入第'.($i+1).'页数据,共'.$has_total.'条pms数据'); } else { $this->info('已导入'.$num*$i.'条pms数据'); break; } } } $this->info("导入系统消息成功"); } }