| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/3/2
- * Time: 下午8:34
- */
- namespace app\frontend\modules\member\models;
- class MemberAddress extends \app\common\models\MemberAddress
- {
- protected $guarded = [''];
- public static function getStaticModel()
- {
- return new static();
- }
- /*
- * Get a list of members receiving addresses
- *
- * @param int $memberId
- *
- * @return array
- * */
- public static function getAddressList($memberId)
- {
- return static::select('id', 'username', 'mobile', 'zipcode', 'province', 'city', 'district', 'address', 'isdefault', 'latitude', 'longitude', 'country_code')
- ->uniacid()->where('uid', $memberId)->get()->toArray();
- }
- /*
- * Get the receiving address information through the receiving address ID
- *
- * @param int $addressId
- *
- * @return array
- * */
- public static function getAddressById($addressId)
- {
- return static::uniacid()->where('id', $addressId)->first();
- }
- /*
- * Delete the receiving address by receiving address ID
- *
- * @param int $addressId
- *
- * @return int 0 or 1
- * */
- public static function destroyAddress($addressId)
- {
- return static::where('id', $addressId)->delete();
- }
- /*
- * Cancel the default address
- *
- * @param int $memberId
- *
- * @return int 0or 1
- * */
- public static function cancelDefaultAddress($memberId)
- {
- return static::uniacid()->where('uid', $memberId)->where('isdefault', '1')->update(['isdefault' => '0']);
- }
- /**
- * 定义字段名
- *
- * @return array
- */
- public function atributeNames()
- {
- return [
- 'mobile' => 'mobile_phone',
- 'username' => '收货人',
- 'province' => '省份',
- 'city' => '城市',
- 'district' => '区域',
- ];
- }
- /**
- * 字段规则
- *
- * @return array
- */
- public function rules()
- {
- return [
- 'mobile' => 'regex:/^[0-9]*$/',
- 'username' => 'required|max:45|min:2',
- //'province' => 'required',
- //'city' => 'required',
- //'district' => 'required',
- ];
- }
- /**
- * 获取会员收货地址
- *
- * @param $addressId
- * @param $userId
- * @return MemberAddress
- */
- public static function getAddressAndUserById($addressId, $userId)
- {
- return static::uniacid()->where('id', $addressId)->where('uid', $userId)->first();
- }
- }
|