Address.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace common\models\member;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. /**
  6. * This is the model class for table "{{%member_address}}".
  7. *
  8. * @property int $id 主键
  9. * @property int|null $merchant_id 商户id
  10. * @property int|null $member_id 用户id
  11. * @property string|null $realname 真实姓名
  12. * @property string|null $mobile 手机号码
  13. * @property int|null $province_id 省
  14. * @property int|null $city_id 市
  15. * @property int|null $area_id 区
  16. * @property string|null $name 省市区名称
  17. * @property string|null $details 详细地址
  18. * @property string|null $street_number 门牌号
  19. * @property string|null $longitude 经度
  20. * @property string|null $latitude 纬度
  21. * @property int|null $floor_level 楼层
  22. * @property string|null $zip_code 邮编
  23. * @property string|null $tel_no 家庭号码
  24. * @property int|null $is_default 默认地址
  25. * @property int $status 状态(-1:已删除,0:禁用,1:正常)
  26. * @property int|null $created_at 创建时间
  27. * @property int|null $updated_at 修改时间
  28. */
  29. class Address extends \common\models\base\BaseModel
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%member_address}}';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['area_id', 'details', 'realname', 'mobile'], 'required'],
  45. [['merchant_id', 'member_id', 'province_id', 'city_id', 'area_id', 'floor_level', 'is_default', 'status', 'created_at', 'updated_at'], 'integer'],
  46. [['realname', 'longitude', 'latitude'], 'string', 'max' => 100],
  47. [['mobile', 'tel_no'], 'string', 'max' => 20],
  48. [['name', 'details', 'street_number'], 'string', 'max' => 200],
  49. [['zip_code'], 'string', 'max' => 10],
  50. ];
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function attributeLabels()
  56. {
  57. return [
  58. 'id' => '主键',
  59. 'merchant_id' => '商户id',
  60. 'member_id' => '用户id',
  61. 'realname' => '真实姓名',
  62. 'mobile' => '手机号码',
  63. 'province_id' => '省',
  64. 'city_id' => '市',
  65. 'area_id' => '区',
  66. 'name' => '省市区名称',
  67. 'details' => '详细地址',
  68. 'street_number' => '门牌号',
  69. 'longitude' => '经度',
  70. 'latitude' => '纬度',
  71. 'floor_level' => '楼层',
  72. 'zip_code' => '邮编',
  73. 'tel_no' => '家庭号码',
  74. 'is_default' => '默认地址',
  75. 'status' => '状态',
  76. 'created_at' => '创建时间',
  77. 'updated_at' => '修改时间',
  78. ];
  79. }
  80. /**
  81. * @param bool $insert
  82. * @return bool
  83. */
  84. public function beforeSave($insert)
  85. {
  86. list($this->province_id, $this->city_id, $this->area_id) = Yii::$app->services->provinces->getParentIdsByAreaId($this->area_id);
  87. $this->name = Yii::$app->services->provinces->getCityListName([$this->province_id, $this->city_id, $this->area_id]);
  88. if (($this->isNewRecord || $this->oldAttributes['is_default'] == StatusEnum::DISABLED) && $this->is_default == StatusEnum::ENABLED) {
  89. self::updateAll(['is_default' => StatusEnum::DISABLED], ['member_id' => $this->member_id, 'is_default' => StatusEnum::ENABLED]);
  90. }
  91. return parent::beforeSave($insert);
  92. }
  93. }
粤ICP备19079148号