123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class UserCollect extends Model
- {
- protected $table = 'user_collect';
- public $timestamps = false;
- protected static $unguarded = true;
- public static function getUserCollectList($appId, $openId, $albumIdList, $type = null, $startDate = null, $endDate = null
- , $page = null, $pageSize = null) {
- $model = self::query()->select(['app_id', 'open_id', 'album_id', 'episode_id', 'type', 'seq'])
- ->where('app_id', $appId)->where('open_id', $openId)->where('enable', 1);
- if(!empty($albumIdList)) {
- $model->whereIn('album_id', $albumIdList);
- }
- if(!empty($type)) {
- $model->where('type', $type);
- }
- if(!empty($startDate)) {
- $model->where('update_time', '>=', $startDate.' 00:00:00');
- }
- if(!empty($endDate)) {
- $model->where('update_time', '<=', $endDate.' 23:59:59');
- }
- if(!empty($page)) {
- $model->orderBy('update_time', 'desc')->offset(($page-1)*$pageSize)->limit($pageSize);
- }
- return [$model->get(), $model->count()];
- }
- public static function addRecord($appId, $openId, $type, $albumId, $episodeId, $seq) {
- $con = [
- 'app_id' => $appId,
- 'open_id' => $openId,
- 'type' => $type,
- 'album_id' => $albumId
- ];
- $attr = [
- 'enable' => 1,
- 'episode_id' => $episodeId,
- 'seq' => $seq
- ];
- return self::query()->updateOrCreate($con, $attr);
- }
- public static function delRecord($appId, $openId, $type, $albumId) {
- return self::query()->where('app_id', $appId)->where('open_id', $openId)->where('type', $type)
- ->where('album_id', $albumId)->update(['enable' => 0, 'update_time' => date('Y-m-d H:i:s')]);
- }
- }
|