20], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'name' => '名称', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData(array $params) { try { if (!empty($params['id'])) { $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new \Exception('服务不存在或者已删除'); } else { $model = new self(); } $model->loadDefaultValues(); if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage()); if (!$model->save()) throw new \Exception($model->getErrorMessage()); return $model; } catch (\Exception $e) { self::$static_error = $e->getMessage(); return false; } } public static function getCateListByDiy($mall_id, $post) { $where[] = ['mall_id' => $mall_id]; $where[] = ['status' => StatusEnum::ENABLED]; if (!empty($post['keyword'])) $where[] = ['like', 'name', trim($post['keyword']) . '%', false]; $params['limit'] = 10; $params['where'] = $where; $params['select'] = 'id,name,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['name']; $item['title'] = $item['name']; $item['value'] = $item['id']; $item['pid'] = 0; } } array_unshift($list['list'],$first); return $list; } }