<?php

/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 16/1/11
 * Time: 上午11:31
 */
class sku_mapper
{
    private $mod_sku_map;
    private $mod_goods;
    private $mod_goods_common;

    public function __construct()
    {
        $this->mod_sku_map = Model('sku_map');
        $this->mod_goods = Model('goods');
        $this->mod_goods_common = Model('goods_common');
    }

    public function proc()
    {
        $skumap = $this->mod_sku_map->field('psku,tmsku')->limit(false)->select();

        foreach($skumap as $row)
        {
            $tmsku = $row['tmsku'];
            $psku = $row['psku'];

            $ret = $this->mod_goods_common->where(array('goods_serial_tm' => $tmsku))->update(array('goods_serial' => $psku,'goods_state' => 1));
            if($ret == false) {
                Log::record("sku_mapper update common err: tmsku = {$tmsku},psku = {$psku}.",Log::ERR);
                //continue;
            }
            $this->mod_goods->where(array('goods_serial_tm' => $tmsku))->update(array('goods_serial' => $psku,'goods_state' => 1));
            if($ret == false) {
                Log::record("sku_mapper update common err: tmsku = {$tmsku},psku = {$psku}.",Log::ERR);
            }

            Log::record("sku_mapper update success: tmsku = {$tmsku},psku = {$psku}.",Log::DEBUG);
        }
    }
}

