123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace Role\Lib;
- use Dever;
- class Supplier
- {
- public function __construct()
- {
- Dever::load('manage/auth.init');
- }
- # 获取门店
- public function search_api()
- {
- return Dever::search('product/category', array(), 'getTop');
- }
- # 获取商品列表
- public function goods_api()
- {
- $supplier_id = Dever::input('supplier_id', 1);
- $goods_category = Dever::input('goods_category');
- $where['supplier_id'] = $supplier_id;
- return Dever::outDiy(Dever::load('product/lib/info')->getSetList('role/supplier_goods_sku', $where, $goods_category));
- }
- # 配置商品
- public function setGoods_api()
- {
- $data = array();
- $data['supplier_id'] = Dever::input('id', 1);
- $info = Dever::db('role/supplier')->find($data['supplier_id']);
- $data['info'] = $info;
- $goods_category = $info['category'];
- $data['host'] = Dever::url('lib/supplier.setGoods', 'role');
- $data['url'] = Dever::url('lib/supplier.goods?supplier_id=' . $data['supplier_id'] . '&goods_category=' . $goods_category, 'role');
- //$data['search'] = Dever::url('lib/supplier.search?yes='.$data['supplier_id'].'&json=1', 'role');
- $data['submit'] = Dever::url('lib/supplier.setGoods_action_commit?json=1', 'role');
- return Dever::render('set_supplier_goods', $data);
- }
- # 配置商品
- public function setGoods_action_commit_api()
- {
- $goods = Dever::input('goods');
- if (!$goods) {
- Dever::alert('请传入商品');
- }
- $goods = Dever::json_decode($goods);
- $supplier_id = Dever::input('supplier_id');
- $supplier = Dever::db('role/supplier')->one($supplier_id);
- $where['option_supplier_id'] = $supplier_id;
- $where['set_state'] = 2;
- Dever::db('role/supplier_goods')->updates($where);
- Dever::db('role/supplier_goods_sku')->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;
- }
- if ($v['del'] == 2) {
- $w = array();
- $w['goods_id'] = $goods_id;
- $w['supplier_id'] = $supplier_id;
- $w['sku_id'] = $sku_id;
- $sku_info = Dever::db('role/supplier_goods_sku')->one($w);
- if ($sku_info) {
- Dever::db('role/supplier_goods_sku')->update(array('where_id' => $sku_info['id'], 'state' => 2));
- }
- unset($w['sku_id']);
- $t = $w;
- $t['state'] = 1;
- $total = Dever::db('role/supplier_goods_sku')->total($t);
- if ($total <= 0) {
- $info = Dever::db('role/supplier_goods')->one($w);
- if ($info) {
- Dever::db('role/supplier_goods')->update(array('where_id' => $info['id'], 'state' => 2));
- }
- }
- } else {
- $goods_info = Dever::db('product/info')->one($goods_id);
- $w = array();
- $w['goods_id'] = $goods_id;
- $w['supplier_id'] = $supplier_id;
- $info = Dever::db('role/supplier_goods')->one($w);
- if (!$info) {
- Dever::db('role/supplier_goods')->insert($w);
- } else {
- $w['where_id'] = $info['id'];
- $w['state'] = 1;
- Dever::db('role/supplier_goods')->update($w);
- }
- $w = array();
- $w['goods_id'] = $goods_id;
- $w['supplier_id'] = $supplier_id;
- $w['sku_id'] = $sku_id;
- $info = Dever::db('role/supplier_goods_sku')->one($w);
- $w['in_num'] = $v['num'];
- if (!$info) {
- Dever::db('role/supplier_goods_sku')->insert($w);
- } else {
- $w['in_num'] += $info['in_num'];
- $w['where_id'] = $info['id'];
- $w['state'] = 1;
- Dever::db('role/supplier_goods_sku')->update($w);
- }
- }
- }
- return 'refer';
- }
- }
|