1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\admin\model;
- use app\common\model\Category;
- use think\Model;
- use think\model\relation\HasMany;
- class Goods extends \app\common\model\Goods
- {
- // 追加属性
- protected $append = [
- 'create_time_text',
- 'update_time_text',
- ];
- public function getCreateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getUpdateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setCreateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setUpdateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- /**
- * @return HasMany|GoodsViewFavCart
- */
- public function viewFavCart(){
- return $this->hasMany(GoodsViewFavCart::class);
- }
- public function category(){
- return $this->belongsTo(Category::class)->setEagerlyType(0);
- }
- }
|