50], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'addons_combo_id' => '套餐id,对应qimall_addons_combo.id', 'operator_id' => '操作人id', 'operator_username' => '操作人昵称', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '添加时间戳', 'updated_at' => '更新时间戳', ]; } /** * 保存数据 * @Author: lun * @DateTime: 2022/3/28 0028 19:35 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @param $params * @return array|bool */ public static function setData($mall_id, $params) { try { $model = self::findOne(['mall_id' => $mall_id, 'addons_combo_id' => $params['addons_combo_id'], 'status' => StatusEnum::ENABLED]); if (empty($model)) { $model = new self(); $model->mall_id = $mall_id; $model->loadDefaultValues(); } if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage()); // 获取套餐内容 $combo = AddonsCombo::findOne(['id' => $params['addons_combo_id'], 'status' => StatusEnum::ENABLED]); $addons_arr = Json::decode($combo['addons'], true); $expire = Json::decode($combo['expire'], true); $month = -1;// 过期时间,月份 if ($expire['is_forever'] == false) { $month = $expire['unit'] == 1 ? $expire['duration'] : $expire['duration'] * 12; } // 保存成功后自动安装插件 foreach ($addons_arr as $addon) { // 获取插件版本号 $version = Addons::find()->select('version')->where(['name' => $addon, 'status' => StatusEnum::ENABLED])->scalar(); $addons_params = [ 'mall_id' => $mall_id, 'addons_name' => $addon, 'month' => $month, 'version' => $version, 'addons_status' => MallAddonsEnum::INSTALL, ]; $res = MallAddons::setData($addons_params);// 保存数据 if ($res == false) throw new Exception("安装{$addon}应用失败:" . MallAddons::getStaticError()); // 初始化安装插件 $install_key = "addons\\" . $addon . "\Install"; if (class_exists($install_key)) { $install = new $install_key(); $install->runApp($mall_id, $addon); } } // 增加使用套餐的商城数量 $combo->mall_num = $combo->mall_num + 1; if (!$combo->save()) throw new Exception('增加使用套餐的商城数量失败:'.$combo->getErrorMessage()); return $model->toArray(); } catch (\Exception $e) { self::setStaticError('应用付费套餐绑定失败:'.$e->getMessage()); return false; } } }