| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace addons\LuckyGroup\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_lucky_group_category".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $sort 序号
- * @property string $title 图片标题
- * @property string $pic_path 图片保存路径
- * @property string $bgcolor 背景色
- * @property string $pic_adv 详情广告图
- * @property string $adv_link 广告图片跳转链接
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class LuckyGroupCategory extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_lucky_group_category}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
- [['title', 'pic_path', 'pic_adv'], 'string', 'max' => 255],
- [['bgcolor'], 'string', 'max' => 100],
- ['adv_link', 'string', 'max' => 1000]
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'sort' => '序号',
- 'title' => '图片标题',
- 'pic_path' => '图片保存路径',
- 'bgcolor' => '背景色',
- 'pic_adv' => '详情广告图',
- 'adv_link' => '广告图片跳转链接',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(int $mall_id, array $data)
- {
- if (!empty($data['id'])) {
- $model = self::findOne(['mall_id' => $mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'id' => $data['id']]);
- if (empty($model)) {
- self::$static_error = '分类数据异常';
- return false;
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->status = StatusEnum::ENABLED;
- $model->mall_id = $mall_id;
- unset($data['id']);
- }
- foreach ($data as $key => $val) {
- if ('adv_link' === $key && !empty($val) && is_array($val)) {
- $val = json_encode($val);
- }
- $model->$key = $val;
- }
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- public static function getCateListByDiy($mall_id, $post)
- {
- $where[] = ['mall_id' => $mall_id];
- $where[] = ['status' => StatusEnum::ENABLED];
- if (!empty($post['keyword'])) $where[] = ['like', 'title', trim($post['keyword']) . '%', false];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['select'] = 'id,title,created_at';
- $list = self::listPage($params);
- $first = [
- 'created_at' => 0,
- 'id' => 0,
- 'is_list' => 0,
- 'label' => "全部",
- 'name' => "全部",
- 'pid' => 0,
- 'title' => "全部",
- 'value' => 1,
- ];
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$item) {
- $item['is_list'] = 0;
- $item['label'] = $item['title'];
- $item['title'] = $item['title'];
- $item['value'] = $item['id'];
- $item['pid'] = 0;
- }
- }
- array_unshift($list['list'],$first);
- return $list;
- }
- }
|