| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace common\models\addons;
- use common\enums\StatusEnum;
- use common\models\common\Addons;
- use common\models\mall\MallAddons;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_combo}}".
- *
- * @property int $id id
- * @property string $title 套餐名称
- * @property string|null $description 套餐说明
- * @property string|null $addons 套餐应用[逗号隔开]
- * @property string|null $expire 有效期设置
- * @property int|null $mall_num 使用套餐的商城数量
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class AddonsCombo extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_combo}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['addons'], 'string'],
- [['mall_num', 'status', 'created_at', 'updated_at'], 'integer'],
- [['title'], 'string', 'max' => 100],
- [['description', 'expire'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'id',
- 'title' => '套餐名称',
- 'description' => '套餐说明',
- 'addons' => '套餐应用[逗号隔开]',
- 'expire' => '有效期设置',
- 'mall_num' => '使用套餐的商城数量',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/3/29 0029 14:34
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return array|bool
- */
- public static function setData($params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'status' => StatusEnum::ENABLED]);
- if (empty($model)) throw new \Exception('查无此套餐');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model->toArray();
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- /**
- * 获取套餐列表
- * @Author: lun
- * @DateTime: 2022/3/28 0028 19:38
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $cond
- * @param array $with
- * @param bool $is_array
- * @param string $select
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getAddonsCombo(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
- $default_cond = [['=','status',StatusEnum::ENABLED]];
- $cond = array_merge($default_cond,$cond);
- $query = self::find()->select($select);
- self::paramPack(['where'=>$cond, 'with'=>$with],$query);
- $data = $query->asArray($is_array)->all();
- return $data;
- }
- /**
- * 获取该商城未购买安装的应用
- * @Author: lun
- * @DateTime: 2023/2/1 0001 10:51
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mallId
- * @param $cate
- * @return array
- */
- public static function getNoInstallAddons($mallId, $cate)
- {
- $field = 'title,name,group';
- $list = Addons::getAddons([['is_online' => 1]], [], true, $field);// 获取已上架的应用列表
- $install_addons = MallAddons::find()->select('addons_name')->where(['mall_id' => $mallId])->andWhere(['>', 'addons_status', 0])->column();
- $addons_list = [];
- foreach ($list as $value) {
- $k = $value['group'];
- $addons_list[$k]['title'] = $cate[$k]['title'];
- $addons_list[$k]['list'][] = [
- 'title' => $value['title'],
- 'name' => $value['name'],
- 'check' => in_array($value['name'], $install_addons) ? true : false,
- ];
- }
- return $addons_list;
- }
- }
|