Jianceproject.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Jianceproject extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $table = 'jiance_project';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'integer';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = false;
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'type_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterInsert(function ($row) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. });
  26. }
  27. public function getTypeList()
  28. {
  29. return ['0' => __('Type 0'),'1' => __('Type 1'), '2' => __('Type 2')];
  30. }
  31. public function getTypeTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  34. $list = $this->getTypeList();
  35. return isset($list[$value]) ? $list[$value] : '';
  36. }
  37. public function company()
  38. {
  39. return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
  40. }
  41. public function pj()
  42. {
  43. return $this->belongsTo('jianceproject', 'pid', 'id', [], 'LEFT')->setEagerlyType(0);
  44. }
  45. }