|
@@ -2,11 +2,12 @@
|
|
|
|
|
|
namespace app\common\model;
|
|
|
|
|
|
-use think\Db;
|
|
|
+use think\db\Query;
|
|
|
use think\Model;
|
|
|
|
|
|
/**
|
|
|
* 会员模型
|
|
|
+ * @method Query|self exists($data)
|
|
|
*/
|
|
|
class UserAddress extends Model
|
|
|
{
|
|
@@ -28,5 +29,30 @@ class UserAddress extends Model
|
|
|
self::where('user_id',$address['user_id'])->where('id','<>',$address['id'])->update(['is_default'=>0]);
|
|
|
}
|
|
|
});
|
|
|
+ self::beforeInsert(function (self $address){
|
|
|
+ if(empty($address['location'])){
|
|
|
+ $address['location']=tm()->getLocation($address['longitude'],$address['latitude'])['address'];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ public function scopeExists(Query $query,$data){
|
|
|
+ if(!empty($data['name'])){
|
|
|
+ $query->where('name',$data['name']);
|
|
|
+ }
|
|
|
+ if(!empty($data['mobile'])){
|
|
|
+ $query->where('mobile',$data['mobile']);
|
|
|
+ }
|
|
|
+ if(!empty($data['address'])){
|
|
|
+ $query->where('address',$data['address']);
|
|
|
+ }
|
|
|
+ if(!empty($data['city'])){
|
|
|
+ $query->where('city',$data['city']);
|
|
|
+ }
|
|
|
+ if(!empty($data['longitude'])){
|
|
|
+ $query->where('longitude',$data['longitude']);
|
|
|
+ }
|
|
|
+ if(!empty($data['latitude'])){
|
|
|
+ $query->where('latitude',$data['latitude']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|