UpdateAfter.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils;
  8. use app\models\Option;
  9. use app\constants\OptionSetting;
  10. class UpdateAfter
  11. {
  12. // 此方法用于更新后执行一些回调操作
  13. public static function handle()
  14. {
  15. static::UpdateQQMapKey();
  16. if (!\has_column('cyy_goods', 'mch_audit_time')) {
  17. $sql = 'ALTER TABLE `cyy_goods` ADD COLUMN `mch_audit_time` int(11) NOT NULL DEFAULT 0;';
  18. \Yii::$app->db->createCommand($sql)->execute();
  19. }
  20. if (!\has_column('cyy_goods', 'is_front_centralize')) {
  21. $sql = 'ALTER TABLE `cyy_goods` ADD COLUMN `is_front_centralize` tinyint(1) NULL DEFAULT 0 ;';
  22. \Yii::$app->db->createCommand($sql)->execute();
  23. }
  24. if (!\has_column('cyy_share_holder_profit_goods_log', 'is_switch')) {
  25. $sql = 'ALTER TABLE `cyy_share_holder_profit_goods_log` ADD COLUMN `is_switch` tinyint(1) NULL DEFAULT 0;';
  26. \Yii::$app->db->createCommand($sql)->execute();
  27. }
  28. if (!\has_column('cyy_goods', 'agent_goods_status')) {
  29. $sql = "ALTER TABLE `cyy_goods` ADD COLUMN `agent_goods_status` tinyint(1) NULL DEFAULT 0 COMMENT '是否是云仓代理配送产品(配送方式只能为到店自提或快递 如果是可上门安装则为快递 如果不上门安装则为到店自提 大于0表示是代理配送商品 2表示需要上门安装)'";
  30. \Yii::$app->db->createCommand($sql)->execute();
  31. }
  32. }
  33. // 用于更新腾讯地图key
  34. public static function UpdateQQMapKey($oldKey = '')
  35. {
  36. try {
  37. $file = 'index.20ae380b.js'; // 每次更新需要修改这个文件名
  38. $defaultKey = 'CHIDIAN-QQ-MAP-KEY'; // 默认key
  39. if (\Yii::$app->isSaas()) {
  40. $key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
  41. } else {
  42. $key = Option::get(OptionSetting::TENCENT_MAP_KEY, DEFAULT_STORE_ID, 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, DEFAULT_STORE_ID, 'store', '')['value'])['value'];
  43. }
  44. if (empty($key)) {
  45. return;
  46. }
  47. $dirPath = \Yii::$app->basePath . '/h5/static/js';
  48. // if ($handle = opendir($dirPath)) {
  49. // while (false !== ($entry = readdir($handle))) {
  50. // // 检查文件名是否符合模式 index.xxx.js
  51. // if (preg_match('/^index\.[a-zA-Z0-9]+\.js$/', $entry)) {
  52. // $file = $entry;
  53. // break;
  54. // }
  55. // }
  56. // closedir($handle);
  57. // }
  58. if (!\file_exists($dirPath . '/' . $file)) {
  59. return;
  60. }
  61. $fileContext = file_get_contents($dirPath . '/' . $file);
  62. if (empty($oldKey)) {
  63. $oldKey = $key;
  64. }
  65. $fileContext = \str_replace([$defaultKey, $oldKey], [$key, $key], $fileContext);
  66. file_put_contents($dirPath . '/' . $file, $fileContext);
  67. } catch (\Throwable $e) {
  68. // Todo
  69. }
  70. }
  71. }