Area.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/4
  6. * Time: 上午11:23
  7. */
  8. namespace app\common\models;
  9. use Illuminate\Database\Eloquent\Model;
  10. /**
  11. * Class Area
  12. * @package app\common\models
  13. * @property int id
  14. * @property int level
  15. * @property int parentid
  16. * @property string areaname
  17. */
  18. class Area extends Model
  19. {
  20. public $table = 'yz_address';
  21. protected $guarded = [''];
  22. public static function getAreaList()
  23. {
  24. return self::get();
  25. }
  26. public static function getProvincesList()
  27. {
  28. return self::where('parentid', 0)
  29. ->get();
  30. }
  31. public static function getProvinces($parentId)
  32. {
  33. return self::where('parentid', $parentId)
  34. ->get();
  35. }
  36. public static function getCitysByProvince($parentId)
  37. {
  38. return self::where('parentid', $parentId)
  39. ->get();
  40. }
  41. public static function getAreasByCity($parentId)
  42. {
  43. return self::where('parentid', $parentId)
  44. ->get();
  45. }
  46. /**
  47. * @return array message
  48. */
  49. public static function validationMessages()
  50. {
  51. return [
  52. 'required' => ' :attribute不能为空!',
  53. 'min' => ' :attribute不能少于:min!',
  54. 'max' => ' :attribute不能少于:max!',
  55. 'integer' => ':attribute请填写数字',
  56. ];
  57. }
  58. /**
  59. * 校验表单数据
  60. *
  61. * @param $data
  62. * @return \Illuminate\Validation\Validator
  63. */
  64. public static function validator($data)
  65. {
  66. $validator = Validator::make($data, [
  67. 'display_order' => 'accepted|integer',
  68. 'dispatch_name' => 'required|max:50',
  69. 'first_weight' => 'accepted|max:50',
  70. 'first_weight_price' => 'accepted',
  71. 'another_weight' => 'accepted',
  72. 'another_weight_price' => 'accepted',
  73. 'first_piece' => 'accepted',
  74. 'first_piece_price' => 'accepted',
  75. 'another_piece' => 'accepted',
  76. 'another_piece_price' => 'accepted',
  77. ], self::validationMessages());
  78. return $validator;
  79. }
  80. /**
  81. * 是叶节点
  82. * @return bool
  83. */
  84. public function isLeaf(){
  85. // 区县并且没开启街道
  86. return $this->level == 3 && !\Setting::get('shop.trade.is_street');
  87. }
  88. }