Tool.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\middleware\Auth;
  5. use app\admin\model\Notice as NoticeModel;
  6. use think\facade\Db;
  7. /**
  8. * Description of Tool
  9. *
  10. * @author sgq
  11. */
  12. class Tool extends BaseController {
  13. //protected $middleware = [Auth::class];
  14. public function findChildDictBatch() {
  15. $result = [];
  16. for ($i = 0; $i < count($this->request->param()); $i++) {
  17. if ($obj = $this->request->param($i)) {
  18. $code = $obj["code"];
  19. $dict = \app\common\model\Dict::where("code", $code)->findOrEmpty();
  20. $childs = \app\common\model\Dict::where("pid", $dict["id"])->order("num")->select();
  21. $result[$obj["name"]] = $childs;
  22. }
  23. }
  24. return json(["code" => "200", "msg" => "", "obj" => $result]);
  25. }
  26. public function getProvinceSelect() {
  27. $where = [];
  28. $where[] = ["code", "like", "%0000"];
  29. return json(Db::table("un_common_location")->where($where)->select()->toArray());
  30. }
  31. public function findCityByProvinceSelect() {
  32. $code = $this->request->param("code");
  33. $province_prefix = substr($code, 0, 2);
  34. return json(Db::table("un_common_location")->where("code", "like", $province_prefix . "%00")->select()->toArray());
  35. }
  36. public function findCountyByCitySelect() {
  37. $code = $this->request->param("code");
  38. $city_prefix = substr($code, 0, 4);
  39. return json(Db::table("un_common_location")->where("code", "like", $city_prefix . "%")->select()->toArray());
  40. }
  41. /**
  42. * 通过地区编码找下级地区,比如传入35就找35**00,传入3505就找3505**
  43. * @return type
  44. */
  45. public function findChildAreaByCode() {
  46. $param = $this->request->param();
  47. $code = $param["code"];
  48. $where[] = ["code", "like", str_pad($code . "%%", 6, 0)];
  49. $where[] = ["code", "<>", str_pad($code . "00", 6, 0)];
  50. if (isset($param["no"])) {
  51. $where[] = ["code", "<>", $param["no"]];
  52. }
  53. return json(Db::table("un_common_location")->where($where)->select()->toArray());
  54. }
  55. }