Mlselection.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /*
  3. * 多级选择:地区选择,分类选择
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. /**
  8. *
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * 控制器
  13. */
  14. class Mlselection extends BaseHome
  15. {
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/mlselection.lang.php');
  20. }
  21. function index()
  22. {
  23. $type = input('param.type');
  24. $pid = intval(input('param.pid'));
  25. $result = array();
  26. in_array($type, array('region', 'goodsclass')) or json_encode('invalid type');
  27. switch ($type) {
  28. case 'region':
  29. $area_mod = model('area');
  30. $regions = $area_mod->getAreaList(array('area_parent_id' => $pid));
  31. foreach ($regions as $key => $region) {
  32. $result[$key]['area_name'] = htmlspecialchars($region['area_name']);
  33. $result[$key]['area_id'] = $region['area_id'];
  34. }
  35. ds_json_encode(10000, '', $result);
  36. break;
  37. case 'goodsclass':
  38. $goodsclass_model = model('goodsclass');
  39. $goods_class = $goodsclass_model->getGoodsclassListByParentId($pid);
  40. $array = array();
  41. if (is_array($goods_class) and count($goods_class) > 0) {
  42. foreach ($goods_class as $val) {
  43. $array[$val['gc_id']] = array('gc_id' => $val['gc_id'], 'gc_name' => htmlspecialchars($val['gc_name']), 'gc_parent_id' => $val['gc_parent_id'], 'commis_rate' => $val['commis_rate'], 'gc_sort' => $val['gc_sort']);
  44. }
  45. }
  46. ds_json_encode(10000, '', array_values($array));
  47. break;
  48. }
  49. }
  50. }