1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\common\model;
- use think\Model;
- /**
- * 模型
- */
- class Comment extends Model
- {
- // 表名
- protected $name = 'shop_comment';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- // 追加属性
- protected $append = [];
- public function getImagesAttr($value, $data)
- {
- $imagesArr = explode(',', $data['images'] ?? '');
- foreach ($imagesArr as $index => &$item) {
- $item && $item = cdnurl($item, true);
- }
- return array_filter($imagesArr);
- }
- public function setImagesAttr($value, $data)
- {
- return is_array($value) ? implode(',', $value) : $value;
- }
- public function User()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT');
- }
- public function Manage()
- {
- return $this->belongsTo('\app\admin\model\Admin', 'user_id', 'id', [], 'LEFT');
- }
- public function Goods()
- {
- return $this->belongsTo('Goods', 'goods_id', 'id', [], 'LEFT');
- }
- public function reply()
- {
- return $this->hasMany('Comment', 'pid', 'id')->where('status', 'normal');
- }
- }
|