find(Dever::input('yes')); $where['servicer_id'] = $servicer['servicer_id']; } return Dever::search('scm_role/' . $role, $where); } # 获取商品列表 public function goods_api() { $id = Dever::input('id', 1); $role = Dever::input('role'); $price_id = Dever::input('price_id', -1); $type = Dever::input('type', 'in'); $source = ''; $table = ''; $goods_category = Dever::input('goods_category'); $where[$role . '_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['role'] = Dever::input('role'); $data['type'] = Dever::input('type'); $info_table = $data['role']; if (strstr($data['role'], '_')) { $temp = explode('_', $data['role']); $info_table = $temp[0]; } $info = Dever::db('scm_role/' . $info_table)->find($data['id']); $data['info'] = $info; $data['host'] = Dever::url('lib/order.home', 'scm_role'); $uri = 'lib/order.goods?id=' . $data['id'] . '&role=' . $data['role']; # 选择上游 if ($data['role'] == 'seller') { $data['name'] = '销售商'; $data['source'] = Dever::db('scm_role/supplier')->select(); } elseif ($data['role'] == 'servicer_store') { $data['name'] = '仓库'; $servicer = Dever::db('scm_role/servicer_store')->find($data['id']); $data['source'] = Dever::db('scm_role/servicer_supplier')->getData(array('servicer_id' => $servicer['servicer_id'])); } $data['source'] = Dever::json_encode($data['source']); if ($data['type'] == 'in') { $data['type_name'] = '入库'; $data['type_config'] = array(1,2); } else { $data['type_name'] = '出库'; } $data['search'] = Dever::url('lib/order.search?yes='.$data['id'].'&role=' . $data['role'] . '&json=1', 'scm_role'); if (isset($info['category'])) { $uri .= '&goods_category=' . $info['category']; } $data['url'] = Dever::url($uri, 'scm_role'); $data['submit'] = Dever::url('lib/order.action_commit?json=1', 'scm_role'); return Dever::render('order_' . $data['role'], $data); } # 入库下单 public function action_commit_api() { $goods = Dever::input('goods'); if (!$goods) { Dever::alert('请传入商品'); } $role = Dever::input('role'); $goods = Dever::json_decode($goods); $id = Dever::input('id'); $col = $role . '_id'; $table_goods = 'scm_role/'.$role.'_goods'; $table_goods_sku = 'scm_role/'.$role.'_goods_sku'; $info = Dever::db('scm_role/' . $role)->one($id); $where['option_' . $col] = $id; $where['set_state'] = 2; Dever::db($table_goods)->updates($where); Dever::db($table_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; } $w = array(); $w['goods_id'] = $goods_id; $w[$col] = $id; $w['sku_id'] = $sku_id; if ($v['del'] == 2) { $sku_info = Dever::db($table_goods_sku)->one($w); if ($sku_info) { Dever::db($table_goods_sku)->update(array('where_id' => $sku_info['id'], 'state' => 2)); } unset($w['sku_id']); $t = $w; $t['state'] = 1; $total = Dever::db($table_goods_sku)->total($t); if ($total <= 0) { $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); $u = $w; $u['in_num'] = $v['num']; if (!$info) { Dever::db($table_goods)->insert($u); } else { $u['where_id'] = $info['id']; $u['state'] = 1; Dever::db($table_goods)->update($u); } $u['sku_id'] = $w['sku_id'] = $sku_id; $info = Dever::db($table_goods_sku)->one($w); if (!$info) { Dever::db($table_goods_sku)->insert($u); } else { $u['where_id'] = $info['id']; $u['state'] = 1; Dever::db($table_goods_sku)->update($u); } } } return 'refer'; } }