Beispiel #1
0
 /**
  *格式化接收的photo参数
  * @param      $photo ['photoType:photoId:originalName:$file:rotation']
  * @param null $type
  * @return array $data  [ ['original_name'=>'','file'=>'','ratation'=>'','img_id'=>'','src_id'=>'','type'=>''] ]
  */
 public function validatePhotoParams($photo, $type = NULL)
 {
     if (!is_array($photo)) {
         return [];
     }
     $data = [];
     foreach ($photo as $item) {
         if (empty($item)) {
             continue;
         }
         $image = [];
         list($_type, $photoId, $originalName, $file, $rotation) = explode(":", $item);
         $image['file'] = $file ? config('setting.img_upload.base_temp_path') . '/' . $file : '';
         $image['original_name'] = $originalName;
         $image['rotation'] = $rotation ?: 0;
         $image['img_id'] = NULL;
         $image['src_id'] = NULL;
         if (!empty($photoId)) {
             $userPhoto = UserPhoto::find($photoId);
             if ($userPhoto) {
                 $image['img_id'] = $userPhoto->img_id;
                 $image['src_id'] = $userPhoto->src_id;
             }
         }
         $image['type'] = $type ?: $_type;
         $data[] = $image;
     }
     return $data;
 }