Set.php 3.6 KB

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