UserPointLogModel.php 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Points\Model;
  4. use app\model\User;
  5. use SixShop\Points\Enum\UserPointTypeEnum;
  6. use think\db\Query;
  7. use think\Model;
  8. use think\model\relation\BelongsTo;
  9. class UserPointLogModel extends Model
  10. {
  11. protected function getOptions(): array
  12. {
  13. return [
  14. 'name' => 'extension_user_point_log',
  15. 'type' => [
  16. 'type' => UserPointTypeEnum::class,
  17. ]
  18. ];
  19. }
  20. public function user(): BelongsTo
  21. {
  22. return $this->belongsTo(User::class, 'user_id', 'id');
  23. }
  24. public function searchUserIdAttr(Query $query, $value, $data)
  25. {
  26. $value > 0 && $query->where('user_id', $value);
  27. }
  28. public function searchTypeAttr(Query $query, $value, $data)
  29. {
  30. $value > 0 && $query->where('type', $value);
  31. }
  32. public function searchCreateTimeAttr(Query $query, $value, $data)
  33. {
  34. $value && $query->whereBetweenTime('create_time', $value[0], $value[1]);
  35. }
  36. }