| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 | <?phpnamespace Scm_product\Lib;use Dever;class Set{    # 获取商品列表    public function goods_api()    {        $id = Dever::input('id', 1);        $project = Dever::input('project');        $table = Dever::input('table');        $price_id = Dever::input('price_id', -1);        $type = Dever::input('type', 1);        $source = '';        $table = 'scm_'.$project . '/' . $table;        if ($type == 2) {            $source = $table;            $table = '';        }        $goods_category = Dever::input('goods_category');        $where[$project . '_id'] = $id;        return Dever::outDiy(Dever::load('scm_product/lib/info')->getSetList($table, $where, $goods_category, 'goods_id', array(), $price_id, $source));    }    # 配置商品    public function home_api()    {        $data = array();        $data['id'] = Dever::input('id', 1);        $data['project'] = Dever::input('project');        $data['info'] = Dever::input('info');        $data['table'] = Dever::input('table');        $info = Dever::db('scm_' . $data['project'] . '/' . $data['info'])->find($data['id']);        $data['info'] = $info;        $data['host'] = Dever::url('lib/set.home', 'scm_product');        $uri = 'lib/set.goods?id=' . $data['id'] . '&project=' . $data['project'] . '&table=' . $data['table'];        if (isset($info['category'])) {        	$uri .= '&goods_category=' . $info['category'];        }        if (isset($info['price_id'])) {        	$uri .= '&price_id=' . $info['price_id'];        }        $data['url'] = Dever::url($uri, 'scm_product');        $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'scm_product');        return Dever::render('set_' . $data['project'] . '_goods', $data);    }    # 配置商品    public function action_commit_api()    {        $goods = Dever::input('goods');        if (!$goods) {            Dever::alert('请传入商品');        }        $project = Dever::input('project');        $table = Dever::input('table');        $goods = Dever::json_decode($goods);        $id = Dever::input('id');        $col = $project . '_id';        $table_goods = 'scm_' . $project . '/' . $table;        $info = Dever::db('scm_' . $project . '/info')->one($id);        $where['option_' . $col] = $id;        $where['set_state'] = 2;        Dever::db($table_goods)->updates($where);        foreach ($goods as $k => $v) {            $temp = explode('-', $k);            $goods_id = $temp[0];            if (isset($temp[1])) {                $sku_id = $temp[1];            } else {                $sku_id = -1;            }            if ($v['num'] < 0) {            	continue;            }            $w = array();            $w['goods_id'] = $goods_id;            $w[$col] = $id;            $w['sku_id'] = $sku_id;            if ($v['del'] == 2) {                $info = Dever::db($table_goods)->one($w);                if ($info) {                    Dever::db($table_goods)->update(array('where_id' => $info['id'], 'state' => 2));                }            } else {                $goods_info = Dever::db('scm_product/info')->one($goods_id);                $info = Dever::db($table_goods)->one($w);                if (isset($v['sell_min'])) {                	$w['sell_min'] = $v['sell_min'];                }                if (isset($v['buy_min'])) {                    $w['buy_min'] = $v['buy_min'];                }                if (isset($v['cost_price'])) {                	$w['cost_price'] = $v['cost_price'];                }                                if (!$info) {                    Dever::db($table_goods)->insert($w);                } else {                    $w['where_id'] = $info['id'];                    $w['state'] = 1;                    Dever::db($table_goods)->update($w);                }            }        }        return 'refer';    }}
 |