123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace Scm_servicer\Lib;
- use Dever;
- class Set_store
- {
- public function __construct()
- {
- Dever::load('manage/auth.init');
- }
- # 获取下游
- public function search_api()
- {
- $role = Dever::input('role');
- $table = Dever::input('table');
- $yes = Dever::input('yes');
- $where = array();
- $info = Dever::db('scm_' . $role . '/' . $table)->find($yes);
- $where[$role . '_id'] = $info[$role . '_id'];
- return Dever::search('scm_' . $role . '/' . $table, $where);
- }
- # 分配配送商
- public function getList_api()
- {
- $role = Dever::input('role');
- $table = Dever::input('table');
- $id = Dever::input('id', 1);
- $data = Dever::db('scm_'.$role.'/'.$table.'_store')->getAll(array($role . '_' . $table . '_id' => $id));
- $type = Dever::db('scm_servicer/info')->select();
-
- $result = array();
- if ($type) {
- $i = 0;
- foreach ($type as $k => $v) {
- $store = Dever::db('scm_servicer/store')->select(array('status' => 1, 'servicer_id' => $v['id']));
- if ($store) {
- $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 ($store 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 home_api()
- {
- $data = array();
- $data['id'] = Dever::input('id', 1);
- $data['role'] = Dever::input('role');
- $data['table'] = Dever::input('table');
- $data['name'] = '门店';
- $data['host'] = Dever::url('lib/set_store.home?role=' . $data['role'] . '&table=' . $data['table'], 'scm_servicer');
- $data['url'] = Dever::url('lib/set_store.getList?id=' . $data['id'] . '&role=' . $data['role'] . '&table=' . $data['table'], 'scm_servicer');
- $data['search'] = Dever::url('lib/set_store.search?yes='.$data['id'].'&role=' . $data['role'] . '&table=' . $data['table'] . '&json=1', 'scm_servicer');
- $data['submit'] = Dever::url('lib/set_store.set_commit?json=1', 'scm_servicer');
- return Dever::render('set_store', $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');
- $table = Dever::input('table');
- $col = $role . '_' . $table . '_id';
- $table = 'scm_' . $role . '/' . $table . '_store';
- $where['option_' . $col] = $id;
- $where['set_state'] = 2;
- Dever::db($table)->updates($where);
- foreach ($value as $k => $v) {
- $w = array();
- $w[$role . '_' . $table . '_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';
- }
- }
|