| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace addons\Happiness\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_store_clerk".
- *
- */
- class HappinessHistoryStore extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_happiness_history_store}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- public function getStore()
- {
- return $this->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;
- }
- }
- }
|