ThumbActionModel.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Models\Partner;
  3. use App\Exceptions\AlertException;
  4. use App\Models\Model;
  5. /**
  6. * App\Models\Partner\ThumbActionModel
  7. *
  8. * @property int $id
  9. * @property \Illuminate\Support\Carbon $created_at 创建时间
  10. * @property \Illuminate\Support\Carbon $updated_at 更新时间
  11. * @property int $uid 用户
  12. * @property int $partner_id 卡片id
  13. * @property int $thumb 点赞
  14. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel newModelQuery()
  15. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel newQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel query()
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel whereCreatedAt($value)
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel whereId($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel wherePartnerId($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel whereThumb($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel whereUid($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Partner\ThumbActionModel whereUpdatedAt($value)
  23. * @mixin \Eloquent
  24. */
  25. class ThumbActionModel extends Model
  26. {
  27. protected $table = "kdgx_fpdx_thumb_action";
  28. protected $dateFormat = "U";
  29. protected $fillable = ['uid', 'partner_id', 'thumb'];
  30. /**
  31. * 点赞或取消
  32. * @param int $uid
  33. * @param int $partner_id
  34. * @param int $thumb
  35. * @return bool
  36. * @throws AlertException
  37. */
  38. public static function createdOrDeleted(int $uid, int $partner_id, int $thumb)
  39. {
  40. if ($thumb == 0) {
  41. ThumbActionModel::where([['uid', $uid], ['partner_id', $partner_id]])->delete();
  42. return true;
  43. }
  44. if (100 < ThumbActionModel::where('uid', $uid)->count()) {
  45. throw new AlertException("存储上限", 201);
  46. }
  47. ThumbActionModel::firstOrCreate([
  48. 'uid' => $uid,
  49. 'partner_id' => $partner_id
  50. ], [
  51. 'uid' => $uid,
  52. 'partner_id' => $partner_id
  53. ]);
  54. return true;
  55. }
  56. }