diff --git a/zhctproject/store/application/api/service/MarketingStrategy.php b/private/tmp/cdx-ms-candidate-20261010/application/api/service/MarketingStrategy.php index 40b4023..193777a 100644 --- a/application/api/service/MarketingStrategy.php +++ b/application/api/service/MarketingStrategy.php @@ -109,6 +109,7 @@ class MarketingStrategy extends BaseService if ($data === false) { return false; } + $data = self::applyDmClock($data, null, ltrim((string)config('database.type'), '\\') === \app\cores\database\Dm::class); Db::startTrans(); try { $strategyId = Db::name('marketing_strategy')->insertGetId($data); @@ -140,6 +141,7 @@ class MarketingStrategy extends BaseService return false; } + $data = self::applyDmClock($data, $strategy, ltrim((string)config('database.type'), '\\') === \app\cores\database\Dm::class); Db::startTrans(); try { Db::name('marketing_strategy') @@ -334,6 +336,36 @@ class MarketingStrategy extends BaseService return $query->value('id') ? true : false; } + /** Keep this table's verified MySQL seconds/default/ON UPDATE semantics only on DM. */ + private static function applyDmClock(array $data, ?array $original, bool $dm): array + { + if (!$dm) { + return $data; + } + if ($original === null) { + $clock = new \think\db\Expression('CAST(CURRENT_TIMESTAMP AS TIMESTAMP(0))'); + $data['create_time'] = $clock; + $data['update_time'] = $clock; + return $data; + } + $integerFields = ['priority', 'strategy_type', 'is_first_consume_only', 'status', 'effective_type', 'store_id', 'time_range_mode']; + foreach ($data as $field => $value) { + $old = $original[$field] ?? null; + $same = $old === $value; + if ($old !== null && $value !== null && in_array($field, $integerFields, true)) { + $same = (int)$old === (int)$value; + } elseif ($field === 'strategy_value' && is_numeric($old) && is_numeric($value)) { + // This verified DECIMAL(10,2) value may arrive as int, float or text. + $same = bccomp((string)$old, (string)$value, 2) === 0; + } + if (!$same) { + $data['update_time'] = new \think\db\Expression('CAST(CURRENT_TIMESTAMP AS TIMESTAMP(0))'); + break; + } + } + return $data; + } + /** * 同步关联 * @param int $strategyId