BaseService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\service;
  3. use app\model\Base;
  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. class BaseService
  9. {
  10. public static function getBaseInfoByQydm($page,$qydm){
  11. $map[] =["qydm","=",$qydm];
  12. $res["row"]=Base::where($map)->page($page["page"],$page["size"])->field("t_base.*,x.xzqmc as cityname,e.xzqmc as countyname,f.xzqmc as townsname")->leftJoin("t_zd_xzq x","t_base.city=x.xzqdm")->leftJoin("t_zd_xzq e","t_base.county=e.xzqdm")->leftJoin("t_zd_xzq f","t_base.towns=f.xzqdm")->select();
  13. $res["count"]=Base::where($map)->count();
  14. return $res;
  15. }
  16. /**
  17. * @throws ModelNotFoundException
  18. * @throws DataNotFoundException
  19. * @throws DbException
  20. */
  21. public static function getBaseInfoById($id){
  22. return (new Base)->field("t_base.*,x.xzqmc as cityname,e.xzqmc as countyname,f.xzqmc as townsname")->where("t_base.id",$id)->leftJoin("t_zd_xzq x","t_base.city=x.xzqdm")->leftJoin("t_zd_xzq e","t_base.county=e.xzqdm")->leftJoin("t_zd_xzq f","t_base.towns=f.xzqdm")->find();
  23. }
  24. public static function editBaseInfo($info,$id): Base
  25. {
  26. return Base::update($info,["id"=>$id]);
  27. }
  28. public static function addBase($info): bool
  29. {
  30. return (new Base)->save($info);
  31. }
  32. public static function delBase($id): bool
  33. {
  34. return Base::destroy($id);
  35. }
  36. }