1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\Db;
- class Productchufadi extends Model
- {
-
-
- // 表名
- protected $table = 'product_chufadi';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'chufatype_text'
- ];
-
- protected static function init()
- {
- self::beforeUpdate(function ($row) {
- $road_info = Db::name('product_road')->where('id',$row->road_id)->find();
- $row->chufatype = $road_info['roadtype'];
- });
- self::beforeInsert(function ($row) {
- $road_info = Db::name('product_road')->where('id',$row->road_id)->find();
- $row->chufatype = $road_info['roadtype'];
- });
- }
-
- public function getChufatypeList()
- {
- return ['1' => __('Chufatype 1'), '2' => __('Chufatype 2')];
- }
- public function getChufatypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['chufatype']) ? $data['chufatype'] : '');
- $list = $this->getChufatypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function product()
- {
- return $this->belongsTo('Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function road()
- {
- return $this->belongsTo('app\admin\model\Productroad', 'road_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|