Tool.php 2.6 KB

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