Пример #1
0
 public static function handelAttachment($url, $siteId = 0)
 {
     if (!$url) {
         return null;
     } else {
         $attachment = DB::connection('dest')->table('attachment_old')->where('filepath', $url)->first();
         if ($attachment) {
             return $attachment->new_id ?: null;
         } else {
             $fullUrl = MigrateHelper::fullAttachmentUrl($url);
             $attachment = DB::connection('dest')->table('attachment')->where('file_url', $fullUrl)->first();
             if ($attachment && $attachment->id) {
                 return $attachment->id;
             }
             $imgBasePrefix = config('app.img_base_url');
             $qiniuPrefix = 'http://imgcdn.121dian.com/';
             if (strpos($fullUrl, $qiniuPrefix) === 0) {
                 // 七牛CDN
                 $attachmentId = DB::connection('dest')->table('attachment')->insertGetId(['site_id' => $siteId, 'admin_id' => 0, 'storage_type' => 3, 'file_key' => substr($fullUrl, strlen($qiniuPrefix)), 'file_url' => $fullUrl, 'filesize' => 0, 'ip_upload' => '0.0.0.0']);
                 return $attachmentId ?: null;
             } elseif (strpos($fullUrl, $imgBasePrefix) === 0) {
                 // 默认cdn
                 $retData = MigrateHelper::uploadAttachmentToAliOss($fullUrl, $siteId);
                 return $retData['id'] ?: null;
             } else {
                 $attachmentId = DB::connection('dest')->table('attachment')->insertGetId(['site_id' => $siteId, 'admin_id' => 0, 'storage_type' => 1, 'file_key' => $fullUrl, 'file_url' => $fullUrl, 'filesize' => 0, 'ip_upload' => '0.0.0.0']);
                 return $attachmentId ?: null;
             }
         }
     }
 }
Пример #2
0
 protected function fastArea()
 {
     MigrateHelper::trace(">>begin to set province");
     $areaGroup = DB::connection('mydb')->table('dm_mobile')->select('mobile_area')->groupBy('mobile_area')->get();
     MigrateHelper::trace(">>there are " . count($areaGroup) . " group of area");
     MigrateHelper::trace(">>setting area ....(" . date('Y-m-d H:i:s') . ")");
     $bar = $this->output->createProgressBar(count($areaGroup));
     foreach ($areaGroup as $item) {
         if (empty($item->mobile_area)) {
             $data = ['province' => '', 'province_id' => 0, 'city' => '', 'city_id' => 0];
         } else {
             $mobile_area = explode(' ', $item->mobile_area);
             list($province, $city) = count($mobile_area) == 2 ? $mobile_area : [$mobile_area[0], $mobile_area[0]];
             $province_id = DB::connection('test')->table('kr_region')->where('name', 'like', '%' . $province . '%')->pluck('id');
             $city_id = DB::connection('test')->table('kr_region')->where('name', 'like', '%' . $city . '%')->pluck('id');
             $data = ['province' => $province, 'province_id' => $province_id, 'city' => $city, 'city_id' => $city_id];
         }
         DB::connection('mydb')->table('dm_mobile')->where('mobile_area', $item->mobile_area)->update($data);
         $bar->advance();
     }
     $bar->finish();
     MigrateHelper::trace(">> complete! (" . date('Y-m-d H:i:s') . ")" . PHP_EOL);
 }