| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 | 
							- <?php
 
- /**
 
-  * Created by PhpStorm.
 
-  * User: Administrator
 
-  * Date: 2019/4/24
 
-  * Time: 19:49
 
-  */
 
- namespace App\Console\Commands\Transfer;
 
- use Illuminate\Console\Command;
 
- use App\Transfer\Pms;
 
- use App\Transfer\SysPms;
 
- use App\Models\SubsiteSysMessage;
 
- use App\Models\Pms as newPms;
 
- use App\Models\SysMessage;
 
- class PmsCommand extends Command
 
- {
 
-     protected $signature = 'aix:transfer-pms';
 
-     protected $description = 'add the transfer-pms data';
 
-     /**
 
-      * PmsCommand constructor.
 
-      */
 
-     public function __construct()
 
-     {
 
-         parent::__construct();
 
-     }
 
-     public function handle()
 
-     {
 
-         SysMessage::truncate();
 
-         SubsiteSysMessage::truncate();
 
-         newPms::truncate();
 
-         //获取系统消息表数据
 
-         $sys = SysPms::orderBy('spmid', 'asc')->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("导入系统消息成功");
 
-     }
 
- }
 
 
  |