buildUrl($value, $data); // } // private function buildUrl($value, $data, $domain = false) // { // $diyname = isset($data['diyname']) && $data['diyname'] ? $data['diyname'] : $data['id']; // $catename = isset($this->category) && $this->category ? $this->category->diyname : 'all'; // $cateid = isset($this->category) && $this->category ? $this->category->id : 0; // $time = $data['publishtime'] ?? time(); // $vars = [ // ':id' => $data['id'], // ':diyname' => $diyname, // ':category' => $cateid, // ':catename' => $catename, // ':cateid' => $cateid, // ':year' => date("Y", $time), // ':month' => date("m", $time), // ':day' => date("d", $time), // ]; // $config = get_addon_config('shop'); // $suffix = $config['moduleurlsuffix']['goods'] ?? $config['urlsuffix']; // return addon_url('shop/goods/index', $vars, $suffix, $domain); // } protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); self::beforeWrite(function ($row) { }); } // 计划上架时间的设置器:将前端datetime转为时间戳 public function setScheduledOnlineTimeAttr($value) { if (empty($value)) { return 0; } // 如果已经是时间戳,直接返回 if (is_numeric($value) && (int)$value == $value) { return $value; } // 如果是日期时间字符串,转换为时间戳 return strtotime($value); } // 计划上架时间的获取器:将时间戳转为datetime格式 public function getScheduledOnlineTimeAttr($value) { if (empty($value) || $value == 0) { return ''; } return date('Y-m-d H:i:s', $value); } // 计划上架时间的文本属性 public function getScheduledOnlineTimeTextAttr($value, $data) { $time = $data['scheduled_online_time'] ?? 0; if (empty($time) || $time == 0) { return ''; } return date('Y-m-d H:i:s', $time); } // 计划下架时间的设置器:将前端datetime转为时间戳 public function setScheduledOfflineTimeAttr($value) { if (empty($value)) { return 0; } // 如果已经是时间戳,直接返回 if (is_numeric($value) && (int)$value == $value) { return $value; } // 如果是日期时间字符串,转换为时间戳 return strtotime($value); } // 计划下架时间的获取器:将时间戳转为datetime格式 public function getScheduledOfflineTimeAttr($value) { if (empty($value) || $value == 0) { return ''; } return date('Y-m-d H:i:s', $value); } // 计划下架时间的文本属性 public function getScheduledOfflineTimeTextAttr($value, $data) { $time = $data['scheduled_offline_time'] ?? 0; if (empty($time) || $time == 0) { return ''; } return date('Y-m-d H:i:s', $time); } protected function setAttributeIdsAttr($value) { $ids = []; foreach ($value as $item) { foreach ($item as $id) { if ($id) { $ids[] = $id; } } } return implode(',', $ids); } public function Freight() { return $this->belongsTo('Freight', 'freight_id', 'id', [], 'LEFT'); } public function Brand() { return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT'); } public function GoodsSku() { return $this->belongsTo('GoodsSku', 'id', 'goods_id', [], 'LEFT'); } public function Category() { return $this->belongsTo('Category', 'category_id', 'id', [], 'LEFT'); } }