YzMemberAddress.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/2
  6. * Time: 下午8:34
  7. */
  8. namespace app\frontend\modules\member\models;
  9. class YzMemberAddress extends \app\common\models\YzMemberAddress
  10. {
  11. protected $guarded = [''];
  12. public static function getStaticModel()
  13. {
  14. return new static();
  15. }
  16. /*
  17. * Get a list of members receiving addresses
  18. *
  19. * @param int $memberId
  20. *
  21. * @return array
  22. * */
  23. public static function getAddressList($memberId)
  24. {
  25. return static::select('id', 'username', 'mobile', 'zipcode', 'province', 'city', 'district','street', 'address', 'isdefault', 'latitude', 'longitude', 'country_code')
  26. ->uniacid()->where('uid', $memberId)->get()->toArray();
  27. }
  28. /*
  29. * Get the receiving address information through the receiving address ID
  30. *
  31. * @param int $addressId
  32. *
  33. * @return array
  34. * */
  35. public static function getAddressById($addressId)
  36. {
  37. return static::uniacid()->where('id', $addressId)->first();
  38. }
  39. /*
  40. * Delete the receiving address by receiving address ID
  41. *
  42. * @param int $addressId
  43. *
  44. * @return int 0 or 1
  45. * */
  46. public static function destroyAddress($addressId)
  47. {
  48. return static::where('id', $addressId)->delete();
  49. }
  50. /*
  51. * Cancel the default address
  52. *
  53. * @param int $memberId
  54. *
  55. * @return int 0or 1
  56. * */
  57. public static function cancelDefaultAddress($memberId)
  58. {
  59. return static::uniacid()->where('uid', $memberId)->where('isdefault', '1')->update(['isdefault' => '0']);
  60. }
  61. /**
  62. * 定义字段名
  63. *
  64. * @return array */
  65. public function atributeNames() {
  66. return [
  67. 'mobile' => 'mobile_phone',
  68. 'username' => '收货人',
  69. 'province' => '省份',
  70. 'city' => '城市',
  71. 'district' => '区域',
  72. 'street' => '街道',
  73. ];
  74. }
  75. /**
  76. * 字段规则
  77. *
  78. * @return array */
  79. public function rules()
  80. {
  81. return [
  82. 'mobile' => 'regex:/^[0-9]*$/',
  83. 'username' => 'required|max:45|min:2',
  84. //'province' => 'required',
  85. //'city' => 'required',
  86. //'district' => 'required',
  87. //'street' => 'required',
  88. ];
  89. }
  90. /**
  91. * 获取会员收货地址
  92. *
  93. * @param $addressId
  94. * @param $userId
  95. * @return MemberAddress
  96. */
  97. public static function getAddressAndUserById($addressId, $userId)
  98. {
  99. return static::uniacid()->where('id', $addressId)->where('uid', $userId)->first();
  100. }
  101. }