EnterprisesService.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\service;
  3. use app\model\Enterprises;
  4. use think\console\command\Lists;
  5. use think\db\exception\DataNotFoundException;
  6. use think\db\exception\DbException;
  7. use think\db\exception\ModelNotFoundException;
  8. use think\facade\Db;
  9. use think\Model;
  10. class EnterprisesService
  11. {
  12. public static function selectLoginInfo($loginInfo){
  13. $map[] = ["username","=",$loginInfo["username"]];
  14. $map[] = ["password","=",$loginInfo["password"]];
  15. return (new Enterprises())->where($map)->field("qydm, fzr_name")->find();
  16. }
  17. /**
  18. * @throws ModelNotFoundException
  19. * @throws DataNotFoundException
  20. * @throws DbException
  21. */
  22. public static function getEnterPrisesList($page, $xzqdm){
  23. switch (strlen($xzqdm) ){
  24. case 4:
  25. $map[]=["city","=",$xzqdm];
  26. break;
  27. case 6:
  28. $map[] = ["country","=",$xzqdm];
  29. break;
  30. case 9:
  31. $map[] = ["towns","=",$xzqdm];
  32. break;
  33. default:
  34. $map[]=["city","<>",""];
  35. }
  36. $res["row"] = (new Enterprises)->where($map)->page($page["page"],$page["size"])->select();
  37. $res["count"] = (new Enterprises)->where($map)->count();
  38. return $res;
  39. }
  40. public static function getEnterprisesInfoByQydm($qydm){
  41. return Db::name("enterprises")->field("t_enterprises.*,x.xzqmc as cityname,e.xzqmc as countyname,f.xzqmc as townsname")->where("qydm",$qydm)->leftJoin("t_zd_xzq x","t_enterprises.city=x.xzqdm")->leftJoin("t_zd_xzq e","t_enterprises.county=e.xzqdm")->leftJoin("t_zd_xzq f","t_enterprises.towns=f.xzqdm")->find();
  42. }
  43. /**
  44. * @throws ModelNotFoundException
  45. * @throws DataNotFoundException
  46. * @throws DbException
  47. */
  48. public static function getEnterprisesInfoById($id){
  49. return (new Enterprises)->find($id);
  50. }
  51. public static function editEnterprisesInfo($info,$id): Enterprises
  52. {
  53. return Enterprises::update($info,["id"=>$id]);
  54. }
  55. public static function addEnterprises($info): bool
  56. {
  57. return (new Enterprises)->save($info);
  58. }
  59. public static function delEnterprises($id): bool
  60. {
  61. return Enterprises::destroy($id);
  62. }
  63. }