Install.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace addons\Material;
  3. use common\enums\StatusEnum;
  4. use common\models\user\UserLevel;
  5. use Yii;
  6. use yii\db\Exception;
  7. use yii\db\Migration;
  8. use common\helpers\MigrateHelper;
  9. use common\interfaces\AddonWidget;
  10. /**
  11. * 安装
  12. *
  13. * Class Install
  14. * @package addons\Material
  15. */
  16. class Install extends Migration implements AddonWidget
  17. {
  18. /**
  19. * @param $addon
  20. * @return mixed|void
  21. * @throws \yii\base\InvalidConfigException
  22. * @throws \yii\web\NotFoundHttpException
  23. * @throws \yii\web\UnprocessableEntityHttpException
  24. */
  25. public function run($addon)
  26. {
  27. // MigrateHelper::upByPath([
  28. // '@addons/Material/console/migrations/'
  29. // ]);
  30. }
  31. public function runApp($mall_id, $addons_name){
  32. // 基础配置-初始化
  33. $user_level_list = UserLevel::getUserLevel([['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED]], [], 1,'level,name,id');
  34. $user_level_ids = implode(',',array_column($user_level_list,'level'));
  35. $config['basic'] = [
  36. 'is_audit' => "1",// 是否开启审核
  37. 'is_filter' => "1",//是否开启敏感词过滤
  38. 'user_level_limit' => $user_level_ids,//会员发布权限
  39. 'download_slogans' => '',
  40. 'is_show_download' => 0,
  41. 'download_type' => 0,
  42. 'share_style' => 0,
  43. ];
  44. // 保存设置
  45. $res = Yii::$app->services->setting->addons->set($mall_id, $addons_name, $config);
  46. if ($res == false) throw new Exception('基础设置保存失败');
  47. }
  48. }