hasOne(HappinessStore::class, ['id' => 'store_id', 'mall_id' => 'mall_id'])->where(['status' => StatusEnum::ENABLED]); } /** * @desc:保存数据 * @Author: hua * @Date: 2021/10/23 * @Time: 18:07 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $params * @return StoreClerk|false|null */ public static function setData(array $params) { try { if (!empty($params['mall_id']) && !empty($params['user_id']) && !empty($params['store_id'])) { $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'store_id' => $params['store_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) { $model = new self(); $model->loadDefaultValues(); } else { return $model; } } 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; } } }