抖音小程序

UserCollect.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class UserCollect extends Model
  5. {
  6. protected $table = 'user_collect';
  7. public $timestamps = false;
  8. protected static $unguarded = true;
  9. public static function getUserCollectList($appId, $openId, $albumIdList, $type = null, $startDate = null, $endDate = null
  10. , $page = null, $pageSize = null) {
  11. $model = self::query()->select(['app_id', 'open_id', 'album_id', 'episode_id', 'type', 'seq'])
  12. ->where('app_id', $appId)->where('open_id', $openId)->where('enable', 1);
  13. if(!empty($albumIdList)) {
  14. $model->whereIn('album_id', $albumIdList);
  15. }
  16. if(!empty($type)) {
  17. $model->where('type', $type);
  18. }
  19. if(!empty($startDate)) {
  20. $model->where('update_time', '>=', $startDate.' 00:00:00');
  21. }
  22. if(!empty($endDate)) {
  23. $model->where('update_time', '<=', $endDate.' 23:59:59');
  24. }
  25. if(!empty($page)) {
  26. $model->orderBy('update_time', 'desc')->offset(($page-1)*$pageSize)->limit($pageSize);
  27. }
  28. return [$model->get(), $model->count()];
  29. }
  30. public static function addRecord($appId, $openId, $type, $albumId, $episodeId, $seq) {
  31. $con = [
  32. 'app_id' => $appId,
  33. 'open_id' => $openId,
  34. 'type' => $type,
  35. 'album_id' => $albumId
  36. ];
  37. $attr = [
  38. 'enable' => 1,
  39. 'episode_id' => $episodeId,
  40. 'seq' => $seq
  41. ];
  42. return self::query()->updateOrCreate($con, $attr);
  43. }
  44. public static function delRecord($appId, $openId, $type, $albumId) {
  45. return self::query()->where('app_id', $appId)->where('open_id', $openId)->where('type', $type)
  46. ->where('album_id', $albumId)->update(['enable' => 0, 'update_time' => date('Y-m-d H:i:s')]);
  47. }
  48. }