60], [['pic_url'], 'string'], [['sort'], 'default', 'value' => 0], [['is_show'], 'default', 'value' => 1], [['is_delete'], 'default', 'value' => 0], [['shop_count'], 'integer'] ]; } /** * 保存分类 * @return array */ public function save() { $this->model->parent_id = $this->parent_id; $this->model->is_show = $this->is_show; if ($this->is_show == 0) { // 产品分类隐藏同时下架该分类下所有商品 $goods_ids = GoodsCat::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'cat_id' => post_params('id')])->select('goods_id')->asArray()->all(); Goods::updateAll(['status' => Goods::STATUS_DISABLE],['in', 'id', array_column($goods_ids, 'goods_id')]); } $this->model->name = $this->name; $this->model->pic_url = $this->pic_url; $this->model->sort = $this->sort; $this->model->store_id = $this->store_id; $this->model->shop_count = $this->shop_count; if ($this->model->save()) { return [ 'code' => 0, 'msg' => '提交成功' ]; } else { return [ 'code' => 0, 'msg' => '保存失败' ]; } } /** * Undocumented function * * @Author LGL 24963@qq.com * @DateTime 2021-01-18 * @desc: 根据id获取分类列表 * @param array $id * @return void */ public static function getCatListById ($id = []) { if (empty($id) && !is_array($id)) { return []; } return Cat::find()->where(['in', 'id', $id])->select('id, name, pic_url')->asArray()->all(); } }