插入价格日志,自动更新该商品价格,并设置该状态为 未上传

DROP TRIGGER IF EXISTS `goods_log_add_Update`;
CREATE DEFINER=`root`@`%` TRIGGER `goods_log_add_Update` 
AFTER INSERT ON `goods_log` FOR EACH ROW 
BEGIN
    set @count = (select count(*) from goods where md5 = new.md5);
    if @count = 0 then
        INSERT INTO goods(`robot_name`, `robot_id`, `url`, `md5`, `goods_id`, `name`, `model`, `price_market`, `price_shop`, `price_cost`) SELECT `robot_name`, `robot_id`, `url`, `md5`, `goods_id`, `name`, `model`, `price_market`, `price_shop`, `price_cost` FROM goods_log WHERE log_id=new.log_id;
     else 
       UPDATE goods SET price_market=new.price_market,price_shop=new.price_shop,price_cost=new.price_cost  where md5 = new.md5;
         set @count_update = (SELECT ROW_COUNT());
        if @count_update > 0 then
            UPDATE goods SET is_upload=0  where md5 = new.md5;
        end if;
     end if;

END

首发 http://www.foxwho.com/article/132
同步 foxwho(神秘狐)的领地 http://www.foxwho.com

 Tags :

Donate:| 文章有帮助,可以 请我喝杯咖啡

Powered by foxwho.com