| 
									
										
										
										
											2020-11-25 09:07:06 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | namespace app\model; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HistoryInfo extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public static function onAfterInsert($item) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $item->sort  = $item->id; | 
					
						
							|  |  |  |         $item->save(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function getByHistoryIds($historyIds = [], $onlyVisible = false) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if(!is_array($historyIds) || count($historyIds) == 0) { | 
					
						
							|  |  |  |             return []; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $list = self::whereIn('history_id', $historyIds) | 
					
						
							|  |  |  |             ->when($onlyVisible, function ($query) { | 
					
						
							|  |  |  |                 $query->where('visible', 1); | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2020-12-03 13:47:57 +08:00
										 |  |  |             ->order(['history_id'=>'desc','sort'=>'desc']) | 
					
						
							| 
									
										
										
										
											2020-11-25 09:07:06 +08:00
										 |  |  |             ->select() | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							|  |  |  |         $data = []; | 
					
						
							|  |  |  |         foreach ($list as $item) { | 
					
						
							|  |  |  |             $item['img_list']  = []; | 
					
						
							|  |  |  |             if(!empty($item['imgs'])) { | 
					
						
							|  |  |  |                 $item['img_list']  = array_filter(explode(',', $item['imgs'])); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $data[$item['history_id']][] = $item; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $data; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function countByHistoryId($historyId) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::where('history_id', $historyId)->count(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function delByHistoryId($historyId) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::where('history_id', $historyId)->delete(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function getByHistoryId($historyId) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if($historyId <= 0) { | 
					
						
							|  |  |  |             return []; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-12-03 13:47:57 +08:00
										 |  |  |         return self::where('history_id', $historyId)->order(['sort'=>'desc'])->select()->toArray(); | 
					
						
							| 
									
										
										
										
											2020-11-25 09:07:06 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } |