| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | <?php/** * 协助处理库存相关的数据处理小工具类 */class Model_logic_whlabel extends Lin_Model {    function __construct(){        parent::__construct();        $this->load->_model('Model_typeclass','typeclass');        $this->load->_model('Model_classid','classid');        $this->load->_model('Model_logic_weight','logic_weight');        $this->load->_model("Model_logic_u9tools","logic_u9tools");    }    protected $pmList = [];//品名匹配的数据    protected $pm = [];    protected $weightList = [];//重量匹配的数据    //转化数组中需要变动的参数    /**     * $list 要转化的数组     * $condition  要处理的条件  $column  要转化的字段  $zhinfo  要转化字段的处理方法     */    public function dataTran($list,$condition){        foreach($condition as $v){            if($v == 'pm' ){                $this->pmData();            }        }        if(in_array('pm',$condition)){            $classid = $this->pm;            $typeclass = $this->pmList;        }        foreach($list as $k=>$v){            if(in_array('pm',$condition)){                $r = $this->logic_u9tools->getOneU9bmHasGift($v['features'],$classid,$typeclass);                $list[$k]['pm'] = $r['zh'];                $list[$k]['jm'] =  $r['jm'];                $list[$k]['bm'] =  $r['bm'];            }            if(in_array('weight',$condition)){                $list[$k]['weight'] = $this->getWeight($v['features']);            }        }        return $list;    }    protected function pmData(){        $typeclass = $this->typeclass->find_all();        $t = [];        foreach ($typeclass as $v)         {            $t[$v['id']] = $v;        }        $this->pmList = $t;        $this->pm = $this->classid->sku();    }    protected function getPm($features){        $t = $this->pmList;        $pm = $this->pm;        $features = explode('-',trim($features,'-'));        foreach($features as $v)        {            $zh = explode('|',trim($t[$v]['zh'],'|'));            $pm[$t[$v]['classid']] = $zh[0];        }        $zh = implode(" ",$pm);        $zh = str_replace('自然色 ','',rtrim($zh,' '));        $zh = str_replace(array('        ','       ','      ','     ','    ','   ','  '),' ',$zh);        return $zh;    }       protected function getWeight($features){        $features = explode("-",trim($features,"-"));        $type = 0;        if(in_array(126,$features)){            $type = 126;        }        if(in_array(127,$features)){            $type = 127;        }        if(in_array(128,$features)){            $type = 128;        }        if(in_array(130,$features)){            $type = 130;        }        $tmp_features = [];        $t = $this->pmList;        foreach($features as $v){            if(isset($t[$v])){                $tmp_features[] = $t[$v];            }        }        return $this->logic_weight->getWeightByFeature($type,$tmp_features);    }}
 |