Mlselection.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * 多级选择:地区选择,分类选择
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. /**
  8. * ============================================================================
  9. *
  10. * ============================================================================
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Mlselection extends BaseHome {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/mlselection.lang.php');
  21. }
  22. function index() {
  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. }