数据修改可通过 Better Search Replace 插件或者使用 SQL 语句，插件更为简便，SQL 语句修改更为高效。

Slearn Pro主题已经取消授权，可将现在的网站域名修改成其它的，龙霄主题站搭建好可对照进行修改。

**注：修改前请备份和数据库，主题选项和其它类型文章选项。**

1、使用插件替换，输入要替换和替换的内容，选择对应的数据库表，「作为模拟运行」不要勾选，勾选了不会替换数据。

![](https://pic.salongweb.com/2021/08/better-search.jpg)2、使用 SQL 替换，将 SQL 语句添加到输入框，一行一条语句，可多行，确定后点击「执行」即可完成。也可点击「模拟查询」，可查看是否有数据有被替换。

![](https://pic.salongweb.com/2021/08/sql.jpg)## 一、修改字段

**1、常用字段，请一行一行的输入到SQL输入框中**

```
update wp_postmeta set meta_key = replace( meta_key, 'views', 'view_count' )
update wp_postmeta set meta_key = replace( meta_key, 'collects', 'collect_count' )
update wp_postmeta set meta_key = replace( meta_key, 'rates', 'rate_count' )
update wp_postmeta set meta_key = replace( meta_key, 'likes', 'like_count' )
update wp_postmeta set meta_key = replace( meta_key, 'unlikes', 'unlike_count' )
```

**2、问题字段**

```
update wp_postmeta set meta_key = replace( meta_key, 'positives', 'positive_count' )
update wp_postmeta set meta_key = replace( meta_key, 'negatives', 'negative_count' )
update wp_postmeta set meta_key = replace( meta_key, 'answers', 'answer_count' )
```

3、视频字段

```
update wp_postmeta set meta_key = replace( meta_key, 'preview_video', 'preview' )
update wp_postmeta set meta_key = replace( meta_key, 'video_duration', 'duration' )
update wp_postmeta set meta_key = replace( meta_key, 'watch_laters', 'watch_later_count' )
```

4、课程字段

```
update wp_postmeta set meta_key = replace( meta_key, 'lesson_completion', 'course_evaluation' )
```

5、课时字段

```
update wp_postmeta set meta_key = replace( meta_key, 'lesson_duration', 'duration' )
```

6、产品变量字段：`skuList` 修改成：`sku_list`，这个需要使用 Better Search Replace 插件进行修改

## 二、需要执行程序修改的

**将下面代码添加到主题根目录下的 functions.php 最后，保存刷新一下页面后，删除代码即可。**

1、作品画廊字段

```
$post_type = 'portfolio';
$query = get_posts(array(
    'posts_per_page' => -1,
    'post_type'      => $post_type
));

foreach ($query as $post) {
    $post_id = $post->ID;
    $portfolios = get_post_meta($post_id, 'portfolios', true);
    if ($portfolios) {
        $new = [];
        foreach ($portfolios as $p => $portfolio) {
            $new[$p] = [
                'title'       => $portfolio['title'],
                'description' => $portfolio['desc'],
                'src'         => $portfolio['value'],
            ];
        }
        update_post_meta($post_id, 'portfolios', $new);
    }
}
```

2、课时类型

```
$post_type = 'lesson';
$query = get_posts(array(
    'posts_per_page' => -1,
    'post_type'      => $post_type,
));

foreach ($query as $key => $post) {
    $post_id = $post->ID;
    $lesson_type = get_post_meta($post_id, 'lesson_type', true);
    if (in_array($lesson_type, ['hls', 'html5', 'tx_vod'])) {
        update_post_meta($post_id, 'lesson_type', 'video');
    }
}
```

3、更新订单数据表

```
global $wpdb;

$table_name = $wpdb->prefix . 'salong_order';

$wpdb->query("ALTER TABLE $table_name 
    MODIFY COLUMN `order_id` VARCHAR(50) NOT NULL,
    MODIFY COLUMN `user_id` BIGINT(20) UNSIGNED NOT NULL,
    MODIFY COLUMN `current_id` BIGINT(20) UNSIGNED DEFAULT NULL,
    MODIFY COLUMN `post_id` TEXT,
    MODIFY COLUMN `post_type` VARCHAR(20) DEFAULT NULL,
    MODIFY COLUMN `order_price` DECIMAL(10,2) DEFAULT 0.00,
    MODIFY COLUMN `order_total` DECIMAL(10,2) DEFAULT 0.00,
    MODIFY COLUMN `order_count` INT UNSIGNED DEFAULT 1,
    MODIFY COLUMN `order_goods` MEDIUMTEXT,
    MODIFY COLUMN `order_coupon` TEXT,
    MODIFY COLUMN `order_address` TEXT,
    MODIFY COLUMN `order_shipping` TEXT,
    MODIFY COLUMN `order_express` VARCHAR(100) DEFAULT NULL,
    MODIFY COLUMN `order_type` VARCHAR(20) DEFAULT NULL,
    MODIFY COLUMN `order_message` TEXT,
    MODIFY COLUMN `order_state` VARCHAR(20) DEFAULT 'pending',
    MODIFY COLUMN `pay_type` VARCHAR(20) DEFAULT NULL,
    MODIFY COLUMN `user_ip` VARCHAR(45) DEFAULT NULL,
    MODIFY COLUMN `order_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
");
```

4、更新订单数据

```
use SalongProduct\Module\Controller\Express;
use SalongProduct\Module\Controller\Product;

global $wpdb;
$table_name = $wpdb->prefix . 'salong_order';
$orders = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A);

if ($orders) {
    foreach ($orders as $key => $order) {
        $order_id           = $order['order_id'];
        $order_coupon       = $order['order_coupon'];
        $order_price        = $order['order_price'];
        $order_goods        = $order['order_goods'];
        $user_id            = $order['user_id'];
        $new_order_coupon   = [];
        $new_order_goods    = [];
        $coupon_order_total = 0;

        if ($order_coupon) {
            $order_coupon = json_decode($order_coupon, true);
            if (isset($order_coupon['order_total'])) {
                continue;
            }
            $coupon_items                    = $order_coupon['items'];
            $new_order_coupon['order_total'] = $order_coupon['total_price'];
            foreach ($coupon_items as $coupon_id => $coupon_item) {
                $new_order_coupon['items'][] = [
                    'coupon_code' => $coupon_item['code'],
                    'coupon_id'   => $coupon_id,
                    'minus_price' => $coupon_item['minus_price']
                ];
            }
        }

        if ($order_goods) {
            $order_goods = json_decode($order_goods, true);
            foreach ($order_goods as $key => $goods_item) {
                if (isset($goods_item['index'])) {
                    continue;
                }
                $post_id      = $goods_item['post_id'];
                $post_type    = get_post_type($post_id);
                $shipping     = $goods_item['shipping'];
                $count        = $goods_item['count'];
                $virtual      = $goods_item['virtual'];
                $coupon       = $goods_item['coupon'];
                $new_coupon   = [];
                $new_shipping = [];
                $index        = -1;
                if (strpos($key, '-')) {
                    $index = intval(explode('-', $key)[1]);
                }
                $new_order_goods[$key] = [
                    'post_id'      => $post_id,
                    'index'        => $index,
                    'count'        => $count,
                    'price'        => (string)$goods_item['price'],
                    'reward_point' => (int)$goods_item['reward_point'],
                    'virtual'      => $virtual,
                    'sku_attr'     => $goods_item['sku_attr'],
                ];

                if ($coupon) {
                    foreach ($coupon as $coupon_key => $coupon_value) {
                        $new_coupon[] = [
                            'label' => $coupon_key,
                            'value' => $coupon_value
                        ];
                        $coupon_order_total += $coupon_value;
                    }
                }
                $new_order_goods[$key]['coupon'] = $new_coupon;

                if ($post_type === 'product') {
                    if (!$virtual) {
                        $express_company_code = [];
                        $express_company_code = Express::companyCode();
                        $product_variable     = get_post_meta($post_id, 'product_variable', true);
                        $product_variable     = json_decode($product_variable, true);
                        $shipping_type        = isset($product_variable['attrs'][$index]['shipping_type']) ? $product_variable['attrs'][$index]['shipping_type'] : '';
                        $buy_mode             = get_post_meta($post_id, 'buy_mode', true);
                        $address              = Product::getAddress(['user_id' => $user_id]);
                        $shipping_value       = $address ? Product::singleFreight(['count' => $count, 'virtual' => $virtual, 'buy_mode' => $buy_mode, 'shipping_type' => $shipping_type, 'address' => json_encode($address)]) : 0;
                        $new_shipping             = ['type' => $shipping_type, 'value' => $shipping_value, 'label' => ($shipping_type && isset($express_company_code[$shipping_type]) ? $express_company_code[$shipping_type] : '')];
                    }
                }
                $new_order_goods[$key]['shipping'] = $new_coupon;
            }
        }
        $new_order_coupon['order_total'] = $coupon_order_total;
        $new_order_coupon                = json_encode($new_order_coupon);
        $new_order_goods                 = json_encode($new_order_goods);
        $order_total                     = $order_price - $coupon_order_total;

        // 更新订单
        $update = $wpdb->update($table_name, ['order_coupon' => $new_order_coupon, 'order_goods' => $new_order_goods, 'order_total' => $order_total], ['order_id' => $order_id], ['%s', '%s', '%f'], ['%s']);
    }
}
```

5、更新课程进度表

```
global $wpdb;
$table_name = $wpdb->prefix . 'salong_course_progress';

$row = $wpdb->get_results("SELECT end_time FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = {$table_name} AND column_name = 'completed_time'");

if (empty($row)) {
    $wpdb->query("ALTER TABLE {$table_name} ADD completed_time INT(1) NOT NULL DEFAULT 0 after end_time");
}
```

## 三、修改下载记录表字段

如何使用了商城插件，修改 `index` 为 `file_index` 后再修改 `sku` 为 `index`，下是修改好的

![](https://pic.salongweb.com/2025/10/download-field-1.webp)进入 phpMyAdmin 面板，点开数据库，再点击 `_salong_download` 这个数据表，切换到**结构**中，点击6、5行后面的修改

![](https://pic.salongweb.com/2025/10/download-field-2.webp)分别将名字 index 修改为 file\_index，sku 修改为 index，最后点击保存