255], [['bgcolor'], 'string', 'max' => 100], ['adv_link', 'string', 'max' => 1000] ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'sort' => '序号', 'title' => '图片标题', 'pic_path' => '图片保存路径', 'bgcolor' => '背景色', 'pic_adv' => '详情广告图', 'adv_link' => '广告图片跳转链接', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData(int $mall_id, array $data) { if (!empty($data['id'])) { $model = self::findOne(['mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'id' => $data['id']]); if (empty($model)) { self::$static_error = '分类数据异常'; return false; } } else { $model = new self(); $model->loadDefaultValues(); $model->status = StatusEnum::ENABLED; $model->mall_id = $mall_id; unset($data['id']); } foreach ($data as $key => $val) { if ('adv_link' === $key && !empty($val) && is_array($val)) { $val = json_encode($val); } $model->$key = $val; } if (!$model->save()) { self::$static_error = '保存数据失败:' . $model->getErrorMessage(); return false; } return $model; } public static function getCateListByDiy($mall_id, $post) { $where[] = ['mall_id' => $mall_id]; $where[] = ['status' => StatusEnum::ENABLED]; if (!empty($post['keyword'])) $where[] = ['like', 'title', trim($post['keyword']) . '%', false]; $params['limit'] = 10; $params['where'] = $where; $params['select'] = 'id,title,created_at'; $list = self::listPage($params); $first = [ 'created_at' => 0, 'id' => 0, 'is_list' => 0, 'label' => "全部", 'name' => "全部", 'pid' => 0, 'title' => "全部", 'value' => 1, ]; if (!empty($list['list'])) { foreach ($list['list'] as &$item) { $item['is_list'] = 0; $item['label'] = $item['title']; $item['title'] = $item['title']; $item['value'] = $item['id']; $item['pid'] = 0; } } array_unshift($list['list'],$first); return $list; } }