AgentUserReward.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class AgentUserReward extends Model
  5. {
  6. /**
  7. * 数据库连接名
  8. */
  9. protected $connection = 'mysql';
  10. /**
  11. * 与模型关联的表名
  12. */
  13. protected $table = 'webgame.agent_user_rewards';
  14. /**
  15. * 可批量赋值的属性
  16. */
  17. protected $fillable = [
  18. 'UserID',
  19. 'reward_type',
  20. 'source_id',
  21. 'taskid',
  22. 'amount',
  23. 'remark',
  24. 'status'
  25. ];
  26. /**
  27. * 获取用户
  28. */
  29. public function user()
  30. {
  31. // return $this->belongsTo(User::class, 'UserID', 'id');
  32. }
  33. /**
  34. * 获取任务(如果是任务奖励)
  35. */
  36. public function task()
  37. {
  38. if ($this->reward_type == 1 && $this->taskid) {
  39. return $this->belongsTo(AgentTask::class, 'taskid', 'taskid');
  40. }
  41. return null;
  42. }
  43. /**
  44. * 获取佣金记录(如果是佣金奖励)
  45. */
  46. public function commission()
  47. {
  48. if ($this->reward_type == 2 && $this->source_id) {
  49. return $this->belongsTo(AgentDepositCommission::class, 'source_id', 'id');
  50. }
  51. return null;
  52. }
  53. }