Supplier.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Scm_role\Lib;
  3. use Dever;
  4. class Supplier
  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/' . $role);
  15. }
  16. # 分配供应商
  17. public function get_api()
  18. {
  19. $role = Dever::input('role');
  20. $id = Dever::input('id', 1);
  21. $data = Dever::db('scm_role/'.$role.'_supplier')->getAll(array($role . '_id' => $id));
  22. $type = Dever::db('scm_role/supplier_type')->select();
  23. $result = array();
  24. if ($type) {
  25. $i = 0;
  26. foreach ($type as $k => $v) {
  27. $supplier = Dever::db('scm_role/supplier')->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['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 set_api()
  55. {
  56. $data = array();
  57. $data['id'] = Dever::input('id', 1);
  58. $data['role'] = Dever::input('role');
  59. if ($data['role'] == 'seller') {
  60. $data['name'] = '销售商';
  61. } else {
  62. $data['name'] = '配送商';
  63. }
  64. $data['host'] = Dever::url('lib/supplier.set?role=' . $data['role'], 'scm_role');
  65. $data['url'] = Dever::url('lib/supplier.get?id=' . $data['id'] . '&role=' . $data['role'], 'scm_role');
  66. $data['search'] = Dever::url('lib/supplier.search?yes='.$data['id'].'&role=' . $data['role'] . '&json=1', 'scm_role');
  67. $data['submit'] = Dever::url('lib/supplier.set_commit?json=1', 'scm_role');
  68. return Dever::render('set_supplier', $data);
  69. }
  70. public function set_commit_api()
  71. {
  72. $value = Dever::input('value');
  73. if (!$value) {
  74. Dever::alert('未选择');
  75. }
  76. $value = Dever::json_decode($value);
  77. $id = Dever::input('id');
  78. $role = Dever::input('role');
  79. $col = $role . '_id';
  80. $table = 'scm_role/' . $role . '_supplier';
  81. $where['option_' . $col] = $id;
  82. $where['set_state'] = 2;
  83. Dever::db($table)->updates($where);
  84. foreach ($value as $k => $v) {
  85. $w = array();
  86. $w['supplier_id'] = $v['id'];
  87. $w[$col] = $id;
  88. $info = Dever::db($table)->one($w);
  89. if (!$info) {
  90. Dever::db($table)->insert($w);
  91. } else {
  92. $w['where_id'] = $info['id'];
  93. $w['state'] = 1;
  94. Dever::db($table)->update($w);
  95. }
  96. }
  97. return 'refer';
  98. }
  99. }