Tool.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /**
  32. * 通过省份编码查找所有市区
  33. * @return type
  34. */
  35. public function findCityByProvinceSelect() {
  36. $code = $this->request->param("code");
  37. $province_prefix = substr($code, 0, 2);
  38. $where[] = ["code", "like", $province_prefix . "%00"];
  39. $where[] = ["code", "<>", $code];
  40. return json(Db::table("un_common_location")->where($where)->select()->toArray());
  41. }
  42. /**
  43. * 通过市级编码查找所有区县
  44. * @return type
  45. */
  46. public function findCountyByCitySelect() {
  47. $code = $this->request->param("code");
  48. $city_prefix = substr($code, 0, 4);
  49. $where[] = ["code", "like", $city_prefix . "%"];
  50. $where[] = ["code", "<>", $code];
  51. return json(Db::table("un_common_location")->where($where)->select()->toArray());
  52. }
  53. /**
  54. * 通过地区编码找下级地区,比如传入35就找35**00,传入3505就找3505**
  55. * @return type
  56. */
  57. public function findChildAreaByCode() {
  58. $param = $this->request->param();
  59. $code = $param["code"];
  60. $where[] = ["code", "like", str_pad($code . "%%", 6, 0)];
  61. $where[] = ["code", "<>", str_pad($code . "00", 6, 0)];
  62. if (isset($param["no"])) {
  63. $where[] = ["code", "<>", $param["no"]];
  64. }
  65. return json(Db::table("un_common_location")->where($where)->select()->toArray());
  66. }
  67. }