抖音小程序

Episode.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Episode extends Model
  5. {
  6. protected $table = 'episode';
  7. public $timestamps = false;
  8. protected static $unguarded = true;
  9. public static function saveData($appId, $albumId, $episodeInfoList, $episodeIdMap) {
  10. \DB::begintransaction();
  11. foreach($episodeInfoList as $episodeInfo) {
  12. # 匹配剧集id
  13. $episodeId = $episodeIdMap[$episodeInfo['seq']];
  14. $con = [
  15. 'app_id' => $appId,
  16. 'album_id' => $albumId,
  17. 'seq' => $episodeInfo['seq']
  18. ];
  19. $attr = [
  20. 'title' => $episodeInfo['title'],
  21. 'cover_list' => implode(',', $episodeInfo['cover_list']),
  22. 'open_video_id' => $episodeInfo['open_video_id'],
  23. 'episode_id' => $episodeId
  24. ];
  25. $res = self::query()->updateOrCreate($con, $attr);
  26. if(!$res) {
  27. \DB::rollBack();
  28. return false;
  29. }
  30. }
  31. \DB::commit();
  32. return true;
  33. }
  34. public static function getList($appId, $albumId, $page, $pageSize) {
  35. $model = self::query()->where('app_id', $appId)->where('enable', 1)
  36. ->where('album_id', $albumId);
  37. $count = $model->count();
  38. $data = $model->select(['title', 'seq', 'cover_list', 'open_video_id', 'episode_id', 'album_id'])
  39. ->orderBy('seq', 'ASC')->offset(($page - 1) * $pageSize)->limit($pageSize)->get();
  40. return [$data, $count];
  41. }
  42. public static function getInfo($appId, $albumId, $seq) {
  43. return self::query()->where('app_id', $appId)->where('album_id', $albumId)->where('seq', $seq)
  44. ->where('enable', 1)->first();
  45. }
  46. public static function getInfoList($appId, $albumId, $episodeIdList) {
  47. return self::query()->where('app_id', $appId)->where('album_id', $albumId)->where('enable', 1)
  48. ->whereIn('episode_id', $episodeIdList)->get();
  49. }
  50. }