| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\admin\model\ps;
- use think\Model;
- class Template extends Model
- {
-
-
- // 表名
- protected $name = 'ps_template';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'locked_time_text',
- 'status_text'
- ];
- protected static function init()
- {
- self::beforeInsert(function ($row) {
- if (!isset($row['factory_id']) || $row['factory_id'] === '' || $row['factory_id'] === null) {
- $row['factory_id'] = 0;
- }
- if ((int)$row['factory_id'] === 0) {
- $row['is_system'] = 1;
- if (empty($row['source']) || $row['source'] === 'manual') {
- $row['source'] = 'system';
- }
- }
- });
- }
- public function getStatusList()
- {
- return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
- }
- public function getSourceList()
- {
- return ['manual' => __('Manual'), 'ai' => __('Ai'), 'system' => __('System'), 'market' => __('Market')];
- }
- public function getLicenseTypeList()
- {
- return [
- 'self' => __('Self'),
- 'system_copy' => __('System_copy'),
- 'market_single' => __('Market_single'),
- 'market_buyout' => __('Market_buyout'),
- ];
- }
- public function factory()
- {
- return $this->belongsTo('Factory', 'factory_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function getLockedTimeTextAttr($value, $data)
- {
- $value = $value ?: ($data['locked_time'] ?? '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ?: ($data['status'] ?? '');
- $list = $this->getStatusList();
- return $list[$value] ?? '';
- }
- protected function setLockedTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- }
|