getAll(array($role . '_id' => $id)); $type = Dever::db('scm_role/supplier_type')->select(); $result = array(); if ($type) { $i = 0; foreach ($type as $k => $v) { $supplier = Dever::db('scm_role/supplier')->select(array('status' => 1, 'type_id' => $v['id'])); if ($supplier) { $result[$i] = array(); $result[$i]['id'] = $v['id']; $result[$i]['name'] = $v['name']; $result[$i]['select'] = 2; $result[$i]['end'] = false; $result[$i]['children'] = array(); foreach ($supplier as $k1 => $v1) { $child = array(); $child['id'] = $v1['id']; $child['name'] = $v1['name']; $child['code'] = $v1['code']; $child['type_name'] = $v['name']; $child['select'] = 2; $child['end'] = true; if (isset($data[$v1['id']]) && $data[$v1['id']]) { $child['select'] = 1; } $result[$i]['children'][] = $child; } $i++; } } } return Dever::outDiy($result); } public function set_api() { $data = array(); $data['id'] = Dever::input('id', 1); $data['role'] = Dever::input('role'); if ($data['role'] == 'seller') { $data['name'] = '销售商'; } else { $data['name'] = '配送商'; } $data['host'] = Dever::url('lib/supplier.set?role=' . $data['role'], 'scm_role'); $data['url'] = Dever::url('lib/supplier.get?id=' . $data['id'] . '&role=' . $data['role'], 'scm_role'); $data['search'] = Dever::url('lib/supplier.search?yes='.$data['id'].'&role=' . $data['role'] . '&json=1', 'scm_role'); $data['submit'] = Dever::url('lib/supplier.set_commit?json=1', 'scm_role'); return Dever::render('set_supplier', $data); } public function set_commit_api() { $value = Dever::input('value'); if (!$value) { Dever::alert('未选择'); } $value = Dever::json_decode($value); $id = Dever::input('id'); $role = Dever::input('role'); $col = $role . '_id'; $table = 'scm_role/' . $role . '_supplier'; $where['option_' . $col] = $id; $where['set_state'] = 2; Dever::db($table)->updates($where); foreach ($value as $k => $v) { $w = array(); $w['supplier_id'] = $v['id']; $w[$col] = $id; $info = Dever::db($table)->one($w); if (!$info) { Dever::db($table)->insert($w); } else { $w['where_id'] = $info['id']; $w['state'] = 1; Dever::db($table)->update($w); } } return 'refer'; } }