Salepeople.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Clue\Lib;
  3. use Dever;
  4. Class Salepeople
  5. {
  6. private $default = array
  7. (
  8. 'value' => -1,
  9. 'name' => '不选择',
  10. );
  11. private $search_default = array
  12. (
  13. 'value' => -1,
  14. 'name' => '部门',
  15. );
  16. public function get_api()
  17. {
  18. $type = Dever::input('type', 2);
  19. # 联动总数,默认到部门
  20. $level_total = Dever::input('level_total', 1);
  21. # 当前联动级别
  22. $level_num = Dever::input('level_num');
  23. # 一般为id
  24. $level_id = Dever::input('level_id');
  25. # 是否是搜索列表页
  26. $level_search = Dever::input('level_search');
  27. if ($level_search) {
  28. $default = $this->search_default;
  29. if ($level_num == 1) {
  30. $default['name'] = '部门选择';
  31. } elseif ($level_num == 2) {
  32. $default['name'] = '组员选择';
  33. }
  34. } else {
  35. $default = $this->default;
  36. }
  37. if ($level_num == 1) {
  38. $data = $this->group();
  39. } elseif ($level_num == 2) {
  40. $data = $this->group_admin($level_id);
  41. }
  42. if (!$data) {
  43. Dever::alert('error');
  44. }
  45. if ($level_search || $level_num >= 1) {
  46. array_unshift($data, $default);
  47. }
  48. if ($level_num == 2) {
  49. unset($data[0]);
  50. }
  51. $result['level_total'] = $level_total;
  52. $result['list'] = $data;
  53. return $result;
  54. }
  55. public function group(){
  56. $auth = Dever::load("manage/auth.info");
  57. $company = Dever::load('manage/company.get');
  58. $admin = Dever::db('manage/admin')->find($auth['id']);
  59. $admin['group'] = explode(',',$admin['group']);
  60. foreach ($admin['group'] as $k =>$v) {
  61. $group = Dever::db('manage/group')->find(array('company_id'=>$company,'id'=>$v));
  62. }
  63. if ($group) {
  64. $data[] = Dever::db('clue/salepeople')->find(array('group_id'=>$group['id']));
  65. }
  66. // print_R($data);die;
  67. // $data = Dever::db('clue/salepeople')->getState();
  68. if ($data) {
  69. // $group = Dever::db('manage/group')->find(array('id'=>$data['group_id']));
  70. // $data[]['name'] = $group['name'];
  71. // $data[]['value'] = $data['group_id'];
  72. // print_R($data);die;
  73. foreach ($data as $k => $v) {
  74. $data[$k]['value'] = $v['group_id'];
  75. $group = Dever::db('manage/group')->find(array('id'=>$v['group_id']));
  76. $data[$k]['name'] = $group['name'];
  77. }
  78. } else {
  79. $data = array();
  80. $data['value'] = -1;
  81. }
  82. // print_R($data);die;
  83. return $data;
  84. }
  85. public function group_admin($level_id){
  86. $data = Dever::db('clue/salepeople')->state(array('group_id'=>$level_id));
  87. foreach ($data as $k =>$v) {
  88. $group = explode(',',$v['group']);
  89. if (isset($group[1]) && $group[1]) {
  90. $admin = Dever::db('manage/admin')->find($group[1]);
  91. if ($admin) {
  92. $data[$k]['value'] = $admin['id'];
  93. $data[$k]['name'] = $admin['username'];
  94. }
  95. }
  96. }
  97. return $data;
  98. }
  99. }