Set_store.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Scm_servicer\Lib;
  3. use Dever;
  4. class Set_store
  5. {
  6. public function __construct()
  7. {
  8. Dever::load('manage/auth.init');
  9. }
  10. # 获取下游
  11. public function search_api()
  12. {
  13. $role = Dever::input('role');
  14. $table = Dever::input('table');
  15. $yes = Dever::input('yes');
  16. $where = array();
  17. $info = Dever::db('scm_' . $role . '/' . $table)->find($yes);
  18. $where[$role . '_id'] = $info[$role . '_id'];
  19. return Dever::search('scm_' . $role . '/' . $table, $where);
  20. }
  21. # 分配配送商
  22. public function getList_api()
  23. {
  24. $role = Dever::input('role');
  25. $table = Dever::input('table');
  26. $id = Dever::input('id', 1);
  27. $data = Dever::db('scm_'.$role.'/'.$table.'_store')->getAll(array($role . '_' . $table . '_id' => $id));
  28. $type = Dever::db('scm_servicer/info')->select();
  29. $result = array();
  30. if ($type) {
  31. $i = 0;
  32. foreach ($type as $k => $v) {
  33. $store = Dever::db('scm_servicer/store')->select(array('status' => 1, 'servicer_id' => $v['id']));
  34. if ($store) {
  35. $result[$i] = array();
  36. $result[$i]['id'] = $v['id'];
  37. $result[$i]['name'] = $v['name'];
  38. $result[$i]['select'] = 2;
  39. $result[$i]['end'] = false;
  40. $result[$i]['children'] = array();
  41. foreach ($store as $k1 => $v1) {
  42. $child = array();
  43. $child['id'] = $v1['id'];
  44. $child['name'] = $v1['name'];
  45. $child['code'] = $v1['code'];
  46. $child['type_name'] = $v['name'];
  47. $child['select'] = 2;
  48. $child['end'] = true;
  49. if (isset($data[$v1['id']]) && $data[$v1['id']]) {
  50. $child['select'] = 1;
  51. }
  52. $result[$i]['children'][] = $child;
  53. }
  54. $i++;
  55. }
  56. }
  57. }
  58. return Dever::outDiy($result);
  59. }
  60. public function home_api()
  61. {
  62. $data = array();
  63. $data['id'] = Dever::input('id', 1);
  64. $data['role'] = Dever::input('role');
  65. $data['table'] = Dever::input('table');
  66. $data['name'] = '门店';
  67. $data['host'] = Dever::url('lib/set_store.home?role=' . $data['role'] . '&table=' . $data['table'], 'scm_servicer');
  68. $data['url'] = Dever::url('lib/set_store.getList?id=' . $data['id'] . '&role=' . $data['role'] . '&table=' . $data['table'], 'scm_servicer');
  69. $data['search'] = Dever::url('lib/set_store.search?yes='.$data['id'].'&role=' . $data['role'] . '&table=' . $data['table'] . '&json=1', 'scm_servicer');
  70. $data['submit'] = Dever::url('lib/set_store.set_commit?json=1', 'scm_servicer');
  71. return Dever::render('set_store', $data);
  72. }
  73. public function set_commit_api()
  74. {
  75. $value = Dever::input('value');
  76. if (!$value) {
  77. Dever::alert('未选择');
  78. }
  79. $value = Dever::json_decode($value);
  80. $id = Dever::input('id');
  81. $role = Dever::input('role');
  82. $table = Dever::input('table');
  83. $col = $role . '_' . $table . '_id';
  84. $table = 'scm_' . $role . '/' . $table . '_store';
  85. $where['option_' . $col] = $id;
  86. $where['set_state'] = 2;
  87. Dever::db($table)->updates($where);
  88. foreach ($value as $k => $v) {
  89. $w = array();
  90. $w[$role . '_' . $table . '_id'] = $v['id'];
  91. $w[$col] = $id;
  92. $info = Dever::db($table)->one($w);
  93. if (!$info) {
  94. Dever::db($table)->insert($w);
  95. } else {
  96. $w['where_id'] = $info['id'];
  97. $w['state'] = 1;
  98. Dever::db($table)->update($w);
  99. }
  100. }
  101. return 'refer';
  102. }
  103. }