save(['weigh' => $row['id']]); }); self::beforeWrite(function ($row) { //在更新之前对数组进行处理 foreach ($row->getData() as $k => $value) { if (is_array($value) && is_array(reset($value))) { $value = json_encode(self::getArrayData($value), JSON_UNESCAPED_UNICODE); } else { $value = is_array($value) ? implode(',', $value) : $value; } $row->setAttr($k, $value); } if (isset($row['begintime']) && isset($row['endtime']) && $row['begintime'] > $row['endtime']) { exception("结束时间必须大于开始时间"); } }); } public function getBegintimeTextAttr($value, $data) { $value = $value ? $value : $data['begintime']; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setBegintimeAttr($value) { return $value && !is_numeric($value) ? strtotime($value) : ($value ? $value : null); } public function getEndtimeTextAttr($value, $data) { $value = $value ? $value : $data['endtime']; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setEndtimeAttr($value) { return $value && !is_numeric($value) ? strtotime($value) : ($value ? $value : null); } public function getNameList() { // return ['indexfocus' => 'PC首页焦点图', 'downloadfocus' => 'PC下载频道页焦点图', 'newsfocus' => 'PC资讯频道页焦点图', 'productfocus' => 'PC产品频道页焦点图', 'uniappfocus' => 'UniAPP焦点图', 'wxappfocus' => '原生微信小程序焦点图']; return ['indexfocus' => 'PC首页焦点图', 'downloadfocus' => 'PC下载频道页焦点图', 'newsfocus' => '全部期刊页焦点图', 'journalfocus' => '期刊主页焦点图', 'articlefocus' => '文章页焦点图', 'specialfocus' => '特刊页焦点图', 'newfocus' => '新闻页焦点图']; } public function getStatusList() { return ['normal' => __('Normal'), 'hidden' => __('Hidden')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } }