| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\utils;
- use app\models\Option;
- use app\constants\OptionSetting;
- class UpdateAfter
- {
- // 此方法用于更新后执行一些回调操作
- public static function handle()
- {
- static::UpdateQQMapKey();
- if (!\has_column('cyy_goods', 'mch_audit_time')) {
- $sql = 'ALTER TABLE `cyy_goods` ADD COLUMN `mch_audit_time` int(11) NOT NULL DEFAULT 0;';
- \Yii::$app->db->createCommand($sql)->execute();
- }
- if (!\has_column('cyy_goods', 'is_front_centralize')) {
- $sql = 'ALTER TABLE `cyy_goods` ADD COLUMN `is_front_centralize` tinyint(1) NULL DEFAULT 0 ;';
- \Yii::$app->db->createCommand($sql)->execute();
- }
- if (!\has_column('cyy_share_holder_profit_goods_log', 'is_switch')) {
- $sql = 'ALTER TABLE `cyy_share_holder_profit_goods_log` ADD COLUMN `is_switch` tinyint(1) NULL DEFAULT 0;';
- \Yii::$app->db->createCommand($sql)->execute();
- }
- if (!\has_column('cyy_goods', 'agent_goods_status')) {
- $sql = "ALTER TABLE `cyy_goods` ADD COLUMN `agent_goods_status` tinyint(1) NULL DEFAULT 0 COMMENT '是否是云仓代理配送产品(配送方式只能为到店自提或快递 如果是可上门安装则为快递 如果不上门安装则为到店自提 大于0表示是代理配送商品 2表示需要上门安装)'";
- \Yii::$app->db->createCommand($sql)->execute();
- }
- }
-
- // 用于更新腾讯地图key
- public static function UpdateQQMapKey($oldKey = '')
- {
- try {
- $file = 'index.20ae380b.js'; // 每次更新需要修改这个文件名
- $defaultKey = 'CHIDIAN-QQ-MAP-KEY'; // 默认key
- if (\Yii::$app->isSaas()) {
- $key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
- } else {
- $key = Option::get(OptionSetting::TENCENT_MAP_KEY, DEFAULT_STORE_ID, 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, DEFAULT_STORE_ID, 'store', '')['value'])['value'];
- }
- if (empty($key)) {
- return;
- }
- $dirPath = \Yii::$app->basePath . '/h5/static/js';
- // if ($handle = opendir($dirPath)) {
- // while (false !== ($entry = readdir($handle))) {
- // // 检查文件名是否符合模式 index.xxx.js
- // if (preg_match('/^index\.[a-zA-Z0-9]+\.js$/', $entry)) {
- // $file = $entry;
- // break;
- // }
- // }
- // closedir($handle);
- // }
- if (!\file_exists($dirPath . '/' . $file)) {
- return;
- }
- $fileContext = file_get_contents($dirPath . '/' . $file);
- if (empty($oldKey)) {
- $oldKey = $key;
- }
- $fileContext = \str_replace([$defaultKey, $oldKey], [$key, $key], $fileContext);
- file_put_contents($dirPath . '/' . $file, $fileContext);
- } catch (\Throwable $e) {
- // Todo
- }
- }
- }
|