| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Module\Task\Models;
- use UCore\ModelCore;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 任务消耗日志模型
- *
- * field start
- * @property int $id 主键
- * @property int $user_id 用户ID
- * @property int $task_id 任务ID,外键关联task_tasks表
- * @property string $cost_type 消耗类型(currency, item, energy, ticket等)
- * @property string $cost_param1 消耗参数1(如货币类型、物品类型等)
- * @property string $cost_param2 消耗参数2(如货币ID、物品ID等)
- * @property int $quantity 消耗数量
- * @property string $cost_at 消耗时间
- * @property string $ip_address IP地址
- * @property string $device_info 设备信息
- * @property \Carbon\Carbon $created_at 创建时间
- * field end
- */
- class TaskCostLog extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'task_cost_logs';
- /**
- * 主键
- *
- * @var string
- */
- protected $primaryKey = 'id';
- /**
- * 应该被转换为日期的属性
- *
- * @var array
- */
- protected $dates = [
- 'cost_at',
- 'created_at',
- ];
- /**
- * 指示模型是否应该被打上时间戳
- *
- * @var bool
- */
- public $timestamps = false;
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'task_id',
- 'cost_type',
- 'cost_param1',
- 'cost_param2',
- 'quantity',
- 'cost_at',
- 'ip_address',
- 'device_info',
- ];
- // attrlist end
- /**
- * 获取关联的任务
- *
- * @return BelongsTo
- */
- public function task(): BelongsTo
- {
- return $this->belongsTo(Task::class, 'task_id', 'id');
- }
- /**
- * 获取关联的用户任务
- *
- * @return BelongsTo
- */
- public function userTask(): BelongsTo
- {
- return $this->belongsTo(TaskUserTask::class, 'task_id', 'task_id')
- ->where('user_id', $this->user_id);
- }
- }
|