'ID', 'cate_id' => '分类id', 'goods_id' => '产品id', 'created_at' => '创建时间', 'updated_at' => '修改时间', ]; } /** * 商品分类关联保存数据 * * @param integer $goods_id * @param array $cats 分类ID * @param string $type * @return boolean */ public static function setData(int $goods_id, array $cats, string $type = 'single') { try { if ($goods_id && $cats) { $insert = []; $now = time(); // 删除旧的分类 self::deleteAll([ 'and', ['goods_id' => $goods_id], ]); // 生成新分类数据 $insert = array_map(function ($item) use ($now, $goods_id) { return [$goods_id, $item, $now, $now]; }, $cats); $field = ['goods_id', 'cate_id', 'created_at', 'updated_at']; // 批量插入数据 Yii::$app->db->createCommand()->batchInsert(self::tableName(), $field, $insert)->execute(); } return true; } catch (\Exception $e) { self::$static_error = $e->getMessage(); return false; } } }