Set.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace Scm_supplier\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.'/supplier')->getAll(array($role . '_id' => $id));
  22. $type = Dever::db('scm_supplier/type')->select();
  23. $result = array();
  24. if ($type) {
  25. $i = 0;
  26. foreach ($type as $k => $v) {
  27. $supplier = Dever::db('scm_supplier/info')->select(array('status' => 1, 'type_id' => $v['id']));
  28. if ($supplier) {
  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 ($supplier 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['reorder'] = $v1['reorder'];
  42. $child['select'] = 2;
  43. $child['end'] = true;
  44. if (isset($data[$v1['id']]) && $data[$v1['id']]) {
  45. $child['select'] = 1;
  46. $child['reorder'] = $data[$v1['id']]['reorder'];
  47. }
  48. $result[$i]['children'][] = $child;
  49. }
  50. $i++;
  51. }
  52. }
  53. }
  54. return Dever::outDiy($result);
  55. }
  56. public function home_api()
  57. {
  58. $data = array();
  59. $data['id'] = Dever::input('id', 1);
  60. $data['role'] = Dever::input('role');
  61. $data['name'] = '经销商';
  62. if ($data['role'] == 'servicer') {
  63. $data['name'] = '配送商';
  64. }
  65. $data['host'] = Dever::url('lib/set.home?role=' . $data['role'], 'scm_supplier');
  66. $data['url'] = Dever::url('lib/set.getList?id=' . $data['id'] . '&role=' . $data['role'], 'scm_supplier');
  67. $data['search'] = Dever::url('lib/set.search?yes='.$data['id'].'&role=' . $data['role'] . '&json=1', 'scm_supplier');
  68. $data['submit'] = Dever::url('lib/set.set_commit?json=1', 'scm_supplier');
  69. return Dever::render('set_supplier', $data);
  70. }
  71. public function set_commit_api()
  72. {
  73. $value = Dever::input('value');
  74. if (!$value) {
  75. Dever::alert('未选择');
  76. }
  77. $value = Dever::json_decode($value);
  78. $id = Dever::input('id');
  79. $role = Dever::input('role');
  80. $col = $role . '_id';
  81. $table = 'scm_' . $role . '/supplier';
  82. $where['option_' . $col] = $id;
  83. $where['set_state'] = 2;
  84. Dever::db($table)->updates($where);
  85. foreach ($value as $k => $v) {
  86. $w = array();
  87. $w['supplier_id'] = $v['id'];
  88. $w[$col] = $id;
  89. $info = Dever::db($table)->one($w);
  90. $w['reorder'] = $v['reorder'];
  91. if (!$info) {
  92. Dever::db($table)->insert($w);
  93. } else {
  94. $w['where_id'] = $info['id'];
  95. $w['state'] = 1;
  96. Dever::db($table)->update($w);
  97. }
  98. }
  99. return 'refer';
  100. }
  101. }