| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace addons\DepositPresale\common\models;
- use addons\DepositPresale\common\enums\DepositPresaleEnum;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\goods\Goods;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_deposit_presale_cate".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property string $name 名称
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class DepositPresaleCate extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_deposit_presale_cate}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name'], 'required'],
- [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['name'], 'string', 'max' => 20],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'name' => '名称',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或者已删除');
- } else {
- $model = new self();
- }
- $model->loadDefaultValues();
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function getCateListByDiy($mall_id, $post)
- {
- $where[] = ['mall_id' => $mall_id];
- $where[] = ['status' => StatusEnum::ENABLED];
- if (!empty($post['keyword'])) $where[] = ['like', 'name', trim($post['keyword']) . '%', false];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['select'] = 'id,name,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['name'];
- $item['title'] = $item['name'];
- $item['value'] = $item['id'];
- $item['pid'] = 0;
- }
- }
- array_unshift($list['list'],$first);
- return $list;
- }
- }
|