LifeFarmLand.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 地块模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class LifeFarmLand extends Model
  11. {
  12. const ROLE_STATUS = 1;
  13. const IS_DEL_YES = 1;
  14. const IS_DEL_NO = 0;
  15. const GOODS_IS_SHOW = [
  16. self::IS_DEL_YES => '已删除',
  17. self::IS_DEL_NO => '未删除'
  18. ];
  19. /**
  20. * The table associated with the model.
  21. *
  22. * @var string
  23. */
  24. protected $table = 'life_farm_land';
  25. public $timestamps = false;
  26. /**
  27. * Notes:获取地块列表
  28. * @param string $keywords
  29. * @param int $page
  30. * @param int $limit
  31. * @return array
  32. * User: YCP
  33. * Date: 2022/10/17
  34. */
  35. public static function getLandList(int $page, int $limit, string $keywords)
  36. {
  37. $list = static::select('*')
  38. ->where(['land_is_del'=>static::IS_DEL_NO])
  39. ->when($keywords != '', function ($query) use ($keywords){
  40. $query->where('land_name', 'like', '%' . $keywords . '%');
  41. })
  42. ->orderBy('land_create_time','DESC')
  43. ->forPage($page, $limit)
  44. ->get();
  45. $count = static::where(['land_is_del'=>static::IS_DEL_NO])
  46. ->when($keywords != '', function ($query) use ($keywords){
  47. $query->where('land_name', 'like', '%' . $keywords . '%');
  48. })
  49. ->count();
  50. return [$list, $count];
  51. }
  52. /**
  53. * Notes:获取地块列表
  54. * @return array
  55. * User: YCP
  56. * Date: 2022/10/17
  57. */
  58. public static function getLandAll()
  59. {
  60. $list = static::select(['land_id','land_name'])
  61. ->where(['land_is_del'=>static::IS_DEL_NO])
  62. ->orderBy('land_create_time','DESC')
  63. ->get();
  64. return $list;
  65. }
  66. /**
  67. * Notes:获取地块名称
  68. * @param string $account
  69. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  70. * User: YCP
  71. * Date: 2022/10/17
  72. */
  73. public static function landMation($admin_land)
  74. {
  75. $where = [];
  76. $where['land_is_del'] = static::IS_DEL_NO;
  77. $mation = static::where($where)
  78. ->when($admin_land != '', function ($query) use ($admin_land){
  79. $query->whereIn('land_id', $admin_land);
  80. })
  81. ->get('land_name');
  82. return $mation;
  83. }
  84. /**
  85. * Notes:检测地块名是否存在
  86. * @param $doctor_name
  87. * @param $doctor_mobile
  88. * @return bool
  89. * User: YCP
  90. * Date: 2022/10/17
  91. * 验证条件:地块名存在的情况下
  92. */
  93. public static function checkLandName($land_name)
  94. {
  95. return static::where(['land_name' => $land_name, 'land_is_del' => static::IS_DEL_NO])->exists();
  96. }
  97. /**
  98. * Notes:检测坐标是否存在
  99. * @param $doctor_name
  100. * @param $doctor_mobile
  101. * @return bool
  102. * User: YCP
  103. * Date: 2022/10/17
  104. * 验证条件:经度纬度同时存在的情况下
  105. */
  106. public static function checkLandPoint($land_longitude,$land_latitude)
  107. {
  108. return static::where(['land_longitude' => $land_longitude, 'land_latitude' => $land_latitude, 'land_is_del' => static::IS_DEL_NO])->exists();
  109. }
  110. }