1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class Episode extends Model
- {
- protected $table = 'episode';
- public $timestamps = false;
- protected static $unguarded = true;
- public static function saveData($appId, $albumId, $episodeInfoList, $episodeIdMap) {
- \DB::begintransaction();
- foreach($episodeInfoList as $episodeInfo) {
- # 匹配剧集id
- $episodeId = $episodeIdMap[$episodeInfo['seq']];
- $con = [
- 'app_id' => $appId,
- 'album_id' => $albumId,
- 'seq' => $episodeInfo['seq']
- ];
- $attr = [
- 'title' => $episodeInfo['title'],
- 'cover_list' => implode(',', $episodeInfo['cover_list']),
- 'open_video_id' => $episodeInfo['open_video_id'],
- 'episode_id' => $episodeId
- ];
- $res = self::query()->updateOrCreate($con, $attr);
- if(!$res) {
- \DB::rollBack();
- return false;
- }
- }
- \DB::commit();
- return true;
- }
- public static function getList($appId, $albumId, $page, $pageSize) {
- $model = self::query()->where('app_id', $appId)->where('enable', 1)
- ->where('album_id', $albumId);
- $count = $model->count();
- $data = $model->select(['title', 'seq', 'cover_list', 'open_video_id', 'episode_id', 'album_id'])
- ->orderBy('seq', 'ASC')->offset(($page - 1) * $pageSize)->limit($pageSize)->get();
- return [$data, $count];
- }
- public static function getInfo($appId, $albumId, $seq) {
- return self::query()->where('app_id', $appId)->where('album_id', $albumId)->where('seq', $seq)
- ->where('enable', 1)->first();
- }
- public static function getInfoList($appId, $albumId, $episodeIdList) {
- return self::query()->where('app_id', $appId)->where('album_id', $albumId)->where('enable', 1)
- ->whereIn('episode_id', $episodeIdList)->get();
- }
- }
|