AddonsCombo.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace common\models\addons;
  3. use common\enums\StatusEnum;
  4. use common\models\common\Addons;
  5. use common\models\mall\MallAddons;
  6. use Yii;
  7. use yii\db\Exception;
  8. /**
  9. * This is the model class for table "{{%addons_combo}}".
  10. *
  11. * @property int $id id
  12. * @property string $title 套餐名称
  13. * @property string|null $description 套餐说明
  14. * @property string|null $addons 套餐应用[逗号隔开]
  15. * @property string|null $expire 有效期设置
  16. * @property int|null $mall_num 使用套餐的商城数量
  17. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  18. * @property int|null $created_at 创建时间
  19. * @property int|null $updated_at 更新时间
  20. */
  21. class AddonsCombo extends \common\models\base\BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_combo}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['addons'], 'string'],
  37. [['mall_num', 'status', 'created_at', 'updated_at'], 'integer'],
  38. [['title'], 'string', 'max' => 100],
  39. [['description', 'expire'], 'string', 'max' => 255],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'id',
  49. 'title' => '套餐名称',
  50. 'description' => '套餐说明',
  51. 'addons' => '套餐应用[逗号隔开]',
  52. 'expire' => '有效期设置',
  53. 'mall_num' => '使用套餐的商城数量',
  54. 'status' => '状态[-1:删除;0:禁用;1启用]',
  55. 'created_at' => '创建时间',
  56. 'updated_at' => '更新时间',
  57. ];
  58. }
  59. /**
  60. * 保存数据
  61. * @Author: lun
  62. * @DateTime: 2022/3/29 0029 14:34
  63. * @Copyright: copyright (c) 2021 广东七件事集团
  64. * @param $params
  65. * @return array|bool
  66. */
  67. public static function setData($params)
  68. {
  69. try {
  70. if (!empty($params['id'])) {
  71. $model = self::findOne(['id' => $params['id'], 'status' => StatusEnum::ENABLED]);
  72. if (empty($model)) throw new \Exception('查无此套餐');
  73. } else {
  74. $model = new self();
  75. $model->loadDefaultValues();
  76. }
  77. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  78. return $model->toArray();
  79. } catch (\Exception $e) {
  80. self::setStaticError($e->getMessage());
  81. return false;
  82. }
  83. }
  84. /**
  85. * 获取套餐列表
  86. * @Author: lun
  87. * @DateTime: 2022/3/28 0028 19:38
  88. * @Copyright: copyright (c) 2021 广东七件事集团
  89. * @param array $cond
  90. * @param array $with
  91. * @param bool $is_array
  92. * @param string $select
  93. * @return array|\yii\db\ActiveRecord[]
  94. */
  95. public static function getAddonsCombo(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
  96. $default_cond = [['=','status',StatusEnum::ENABLED]];
  97. $cond = array_merge($default_cond,$cond);
  98. $query = self::find()->select($select);
  99. self::paramPack(['where'=>$cond, 'with'=>$with],$query);
  100. $data = $query->asArray($is_array)->all();
  101. return $data;
  102. }
  103. /**
  104. * 获取该商城未购买安装的应用
  105. * @Author: lun
  106. * @DateTime: 2023/2/1 0001 10:51
  107. * @Copyright: copyright (c) 2021 广东七件事集团
  108. * @param $mallId
  109. * @param $cate
  110. * @return array
  111. */
  112. public static function getNoInstallAddons($mallId, $cate)
  113. {
  114. $field = 'title,name,group';
  115. $list = Addons::getAddons([['is_online' => 1]], [], true, $field);// 获取已上架的应用列表
  116. $install_addons = MallAddons::find()->select('addons_name')->where(['mall_id' => $mallId])->andWhere(['>', 'addons_status', 0])->column();
  117. $addons_list = [];
  118. foreach ($list as $value) {
  119. $k = $value['group'];
  120. $addons_list[$k]['title'] = $cate[$k]['title'];
  121. $addons_list[$k]['list'][] = [
  122. 'title' => $value['title'],
  123. 'name' => $value['name'],
  124. 'check' => in_array($value['name'], $install_addons) ? true : false,
  125. ];
  126. }
  127. return $addons_list;
  128. }
  129. }