123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- namespace Scm_product\Lib;
- use Dever;
- class Manage
- {
- public function check($id,$name,$data)
- {
- //Dever::alert('reload');
- }
- # 选择来源
- public function selectSource_api()
- {
- $value = Dever::input('value');
- $id = Dever::input('id');
- $data = array();
- if ($id) {
- $data = Dever::db('scm_product/info')->find($id);
- if ($value != $data['source_type']) {
- $data['source_id'] = -1;
- }
- }
-
- $config['source_id'] = Dever::db('scm_product/info')->config['struct']['source_id'];
- $config['source_id']['update'] = 'select';
- $config['source_id']['update_search'] = 'scm/lib/role.search?source_type=' . $value;
- $result = Dever::load('manage/database')->update_struct(array('struct' => $config), false, $data, -1, '', true);
- return $result;
- }
- /**
- * 更新信息
- *
- * @return mixed
- */
- public function updateInfo($id, $name, $data)
- {
- # 更新分类id
- $category = Dever::param('category', $data);
- if ($category) {
- if (is_array($category)) {
- $category_id = end($category);
- $top_category_id = $category[0];
- if (isset($category[1])) {
- $second_category_id = $category[1];
- } else {
- $second_category_id = $category[0];
- }
-
- } else {
- $category_id = $category;
- $top_category_id = $category;
- $second_category_id = $category;
- }
- $update['top_category_id'] = $top_category_id;
- $update['second_category_id'] = $second_category_id;
- $update['category_id'] = $category_id;
- }
- if (isset($update)) {
- $update['where_id'] = $id;
- Dever::db('scm_product/info')->update($update);
- }
- }
- public function updateCategory($id, $name, $data)
- {
- $info = Dever::param('category', $data);
- if ($info && $info != -1) {
- $update['top_category_id'] = $info[0];
- $num = count($info)+1;
- $update['level'] = $num;
- $parent = Dever::param('category_id', $data);
- $child = Dever::db('scm_product/category')->one(array('category_id' => $id));
- if (!$child) {
- $update['level'] = -1;
- }
- Dever::db('scm_product/category')->update(array('where_id' => $parent, 'level' => $num - 1));
- } else {
- $update['level'] = 1;
- $update['top_category_id'] = -1;
- }
- if (isset($update)) {
- $update['where_id'] = $id;
- Dever::db('scm_product/category')->update($update);
- }
- }
- /**
- * 更新属性信息
- *
- * @return mixed
- */
- public function updateAttr($id, $name, $data)
- {
- return;
- $is_sell = Dever::param('is_sell', $data);
- if ($is_sell > 1) {
- $update['type'] = 11;
- }
- if (isset($update)) {
- $update['where_id'] = $id;
- Dever::db('scm_product/category_attr')->update($update);
- }
- }
- public function searchProduct_api()
- {
- $id = Dever::input('id');
- $keyword = Dever::input('keyword');
- $where = array();
- if ($keyword) {
- $where['name'] = $keyword;
- }
- $data = array();
- $cate = '';
- $supplier_id = Dever::input('supplier_id');
- if ($supplier_id) {
- $where['supplier_id'] = $supplier_id;
- $data = Dever::search('scm_supplier/goods', $where);
- if (!$data) {
- $supplier = Dever::db('scm_supplier/info')->find($supplier_id);
- if ($supplier && $supplier['category']) {
- $cate = $supplier['category'];
- }
- }
- }
- $seller_id = Dever::input('seller_id');
- if ($seller_id) {
- $where['seller_id'] = $seller_id;
- $data = Dever::search('scm_seller/goods', $where);
- if (!$data) {
- $seller = Dever::db('scm_seller/info')->find($seller_id);
- if ($seller && $seller['category']) {
- $cate = $seller['category'];
- }
- }
- }
- $service_id = Dever::input('service_id');
- $servicer_store_id = Dever::input('servicer_store_id');
- if ($servicer_store_id) {
- $where['servicer_store_id'] = $servicer_store_id;
- $data = Dever::search('scm_servicer/store_goods', $where);
- }
- if (!$data) {
- $id = Dever::input('where_id');
- if ($id) {
- $where['id_no'] = $id;
- }
- if ($cate) {
- $where['cate'] = $cate;
- }
- $data = Dever::search('scm_product/info', $where);
- }
-
- if ($data) {
- $old = $data;
- $data = array();
- foreach ($old as $k => $v) {
- Dever::load('scm_product/lib/sku')->getList($v, $data);
- }
- }
- $width = '600';
- $table = '<style>.layui-table-view{margin:10px!important}</style><table class="layui-table" lay-filter="'.$id.'">';
- $table .= '<thead>
- <tr>
- <th lay-data="{field:\'value\', fixed:\'left\', width: 120}">ID</th>
- <th lay-data="{field:\'name\', fixed:\'left\', hide:true}">名称</th>
- <th lay-data="{field:\'sname\', fixed:\'left\', width: 120}">名称</th>
- <th lay-data="{field:\'spec\'}">规格</th>
- </tr>
- </thead>';
- $table .= '<tbody>';
- foreach ($data as $k => $v) {
- $table .= '<tr>
- <td>'.$v['id'].'</td>
- <td>'.$v['name'].'</td>
- <td>'.$v['sname'].'</td>
- <td>'.$v['spec'].'</td>
- </tr>';
- }
- $table .= '</tbody>';
- $table .= '</table>';
- $result['list'] = $data;
- //$result['table'] = $table;
- $result['table_config'] = array('width' => $width);
- return $result;
- }
- public function getGoods($id, $table = 'scm_servicer/in_order_goods', $cash = true)
- {
- $result = array();
- $result['head'] = array('名称', '批次', '单价', '数量', '状态');
- if (!$cash) {
- unset($result['head'][1]);
- }
- $result['body'] = array();
- $data = Dever::db($table)->select(array('order_id' => $id));
- if ($data) {
- $status = Dever::db($table)->config['status'];
- foreach ($data as $k => $v) {
- $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id']);
- $status_name = Dever::status($status, $v['status']);
- $unit = Dever::db('scm/unit')->one($v['unit_id']);
- $result['body'][$k][] = $goods_info['aname'];
- if (isset($v['batch'])) {
- $result['body'][$k][] = $v['batch'];
- } else {
- unset($result['head'][1]);
- }
-
- $result['body'][$k][] = $v['cash'];
- $result['body'][$k][] = $v['num'] . $unit['name'];
- $result['body'][$k][] = $status_name;
- if (!$cash) {
- unset($result['body'][$k][1]);
- }
- }
- }
- $body[''] = array
- (
- 'type' => 'table',
- 'content' => $result,
- );
- if ($result['body']) {
- return Dever::show('', $body);
- } else {
- return '暂无';
- }
- }
- public function searchRole_api()
- {
- $in_type = Dever::input('in_type');
- $service_id = Dever::input('service_id');
- $servicer_store_id = Dever::input('servicer_store_id');
- if ($in_type == 2) {
- # 生成仓库入库单
-
- }
- }
- # 根据商品获取信息,后台入库出库单使用
- public function showInfo_api()
- {
- $goods = Dever::input('value');
- $cash_col = Dever::input('cash_col', 'cost_price');
- list($goods_id, $sku_id) = explode('-', $goods);
- $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
- $option = array();
- $result = array();
- $result['goods_id'] = '暂无';
- $result['unit_id'] = 1;
- $result['cash'] = '0.00';
- if ($goods_info) {
- $result['cash'] = $goods_info[$cash_col];
- $string = '';
- $table = Dever::input('table');
- $unit_id = false;
- if ($table != 'out_order') {
- # 出库不需要
- $unit_id = -1;
- }
- $data = Dever::load('scm/lib/unit')->getData($goods_id, $sku_id, $unit_id, Dever::input('cash_col'));
- if ($data) {
- $result['cash'] = $data['cash'];
- $result['goods_id'] = $data['num'] . $goods_info['unit'] . $string;
- }
- $result['unit_id'] = $goods_info['unit_id'];
-
- if ($result['unit_id']) {
- $unit = Dever::db('scm_product/info_unit')->select(array('info_id' => $goods_info['id']));
- $option['unit_id'] = '';
- $unit_info = Dever::db('scm/unit')->find($result['unit_id']);
- $option['unit_id'] .= '<option value="'.$unit_info['id'].'" selected>'.$unit_info['name'].'</option>';
- if ($unit) {
- foreach ($unit as $k => $v) {
- $unit_info = Dever::db('scm/unit')->find($v['unit_id']);
- $option['unit_id'] .= '<option value="'.$unit_info['id'].'">'.$unit_info['name'].'</option>';
- }
- }
- }
- $result['cash'] = Dever::number($result['cash']);
- $result['num'] = '1.00';
- }
-
- return array('data' => $result, 'html' => '', 'option' => $option);
- }
- # 根据单位获取价格
- public function showPriceByUnit_api()
- {
- $unit = Dever::input('value');
- $goods = Dever::input('goods');
- $temp = explode('-', $goods);
- $goods_id = $temp[0];
- $sku_id = $temp[1];
- $data = Dever::load('scm/lib/unit')->getData($goods_id, $sku_id, $unit, Dever::input('cash_col'));
- if ($data && $data['num'] > 0) {
- $unit = Dever::db('scm/unit')->one($unit);
- $data['goods_id'] = $data['num'] . $unit['name'];
- }
- unset($data['num']);
-
- return array('data' => $data, 'html' => '');
- }
- }
|