更新
This commit is contained in:
@@ -28,7 +28,17 @@ class QywxPromotionConfig
|
||||
public static function installed(): bool
|
||||
{
|
||||
try {
|
||||
return Db::name('qywx_promotion_config')->getFields() !== [];
|
||||
foreach ([
|
||||
'qywx_promotion_config',
|
||||
'qywx_promotion_media',
|
||||
'qywx_promotion_automation_task',
|
||||
'qywx_promotion_automation_action_log',
|
||||
] as $table) {
|
||||
if (Db::name($table)->getFields() === []) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (\Throwable $error) {
|
||||
// 仅旧部署未建表时回退。数据库故障不能退回全天路由、忽略排班配置。
|
||||
if (str_contains($error->getMessage(), '42S02')
|
||||
@@ -64,13 +74,21 @@ class QywxPromotionConfig
|
||||
public static function save(int $poolId, array $config): void
|
||||
{
|
||||
self::assertInstalled();
|
||||
if ($poolId <= 0) {
|
||||
throw new RuntimeException('分流方案不存在,无法保存自动化配置');
|
||||
}
|
||||
$row = Db::name('qywx_promotion_config')->where('pool_id', $poolId)->find();
|
||||
$data = ['config_json' => json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR), 'update_time' => time()];
|
||||
$json = json_encode($config, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
|
||||
$data = ['config_json' => $json, 'update_time' => time()];
|
||||
if ($row) {
|
||||
Db::name('qywx_promotion_config')->where('pool_id', $poolId)->update($data);
|
||||
} else {
|
||||
Db::name('qywx_promotion_config')->insert($data + ['pool_id' => $poolId, 'create_time' => time()]);
|
||||
}
|
||||
$saved = Db::name('qywx_promotion_config')->where('pool_id', $poolId)->value('config_json');
|
||||
if (!is_string($saved) || !hash_equals($json, $saved)) {
|
||||
throw new RuntimeException('获客标签与欢迎语配置未能完整落库,请重试');
|
||||
}
|
||||
}
|
||||
|
||||
/** 不接受浏览器提供的 userid;成员归属必须经过现有后台数据权限校验后再绑定。 */
|
||||
|
||||
Reference in New Issue
Block a user