Contribute.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\admin\model\books;
  3. use think\Model;
  4. class Contribute extends Model
  5. {
  6. // 表名
  7. protected $name = 'contribute';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'manuscript_status_text',
  17. 'last_publish_time_text',
  18. 'funds_status_text'
  19. ];
  20. public function getManuscriptStatusList()
  21. {
  22. return ['0' => __('待启动'), '1' => __('编写中'), '2' => __('已截稿')];
  23. }
  24. public function getFundsStatusList()
  25. {
  26. return ['0' => __('无经费'), '1' => __('三万以内'), '2' => __('五万以内'), '3' => __('五万以上')];
  27. }
  28. public function getManuscriptStatusTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : (isset($data['manuscript_status']) ? $data['manuscript_status'] : '');
  31. $list = $this->getManuscriptStatusList();
  32. return isset($list[$value]) ? $list[$value] : '';
  33. }
  34. public function getLastPublishTimeTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['last_publish_time']) ? $data['last_publish_time'] : '');
  37. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  38. }
  39. public function getFundsStatusTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['funds_status']) ? $data['funds_status'] : '');
  42. $list = $this->getFundsStatusList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. protected function setLastPublishTimeAttr($value)
  46. {
  47. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  48. }
  49. }