OrderAddress.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/14
  6. * Time: 上午11:01
  7. */
  8. namespace app\common\models;
  9. /**
  10. * Class OrderAddress
  11. * @package app\common\models
  12. * @property string address
  13. * @property string mobile
  14. * @property string realname
  15. * @property int order_id
  16. * @property int province_id
  17. * @property int city_id
  18. * @property int district_id
  19. * @property string note
  20. * @property int street_id
  21. */
  22. class OrderAddress extends BaseModel
  23. {
  24. public $table = 'yz_order_address';
  25. protected $guarded = ['id'];
  26. protected $hidden = ['id', 'order_id'];
  27. public $province;
  28. public $city;
  29. public $district;
  30. public $street;
  31. protected $attributes = [
  32. 'street_id' => 0,
  33. 'zipcode' => '',
  34. ];
  35. /**
  36. * 定义字段名
  37. * 可使
  38. * @return array */
  39. public function atributeNames() {
  40. return [
  41. 'address'=> '收货详细地址',
  42. 'mobile'=> '收货电话',
  43. 'realname'=> '收货人姓名',
  44. 'province_id'=> '收货省份',
  45. 'city_id'=> '收货城市',
  46. 'district_id'=> '收货地区',
  47. 'zipcode' => '收件地址邮编'
  48. ];
  49. }
  50. /**
  51. * 字段规则
  52. * @return array */
  53. public function rules() {
  54. $rule = [
  55. //具体unique可看文档 https://laravel.com/docs/5.4/validation#rule-unique
  56. 'address'=> 'required',
  57. //'mobile'=> 'required',
  58. //'realname'=> 'required',
  59. 'province_id'=> 'required',
  60. 'city_id'=> 'required',
  61. 'district_id'=> 'required',
  62. // 'zipcode'=> ''
  63. ];
  64. return $rule;
  65. }
  66. public function save(array $options = [])
  67. {
  68. if ($this->validator()->fails()) {
  69. return true;
  70. }
  71. return parent::save($options);
  72. }
  73. }