add($data); return $result; } /** * 编辑地址 * @param $id * @param $user_id * @param $address * @param $phone * @return bool * author: xmy 280564871@qq.com */ public function editAddress($id,$user_id,$name,$city,$address,$phone,$is_default){ $data['address'] = $address; $data['name'] = $name; $data['city'] = $city; $data['phone'] = $phone; if($is_default == 1){ $data['is_default'] = time(); } $sa=$this->where(['id'=>$id,'user_id'=>$user_id])->save($data); return $sa; } /** * 删除地址 * @param $id * @param $user_id * @return mixed * author: xmy 280564871@qq.com */ public function deleteAddress($id,$user_id){ return $this->where(['id'=>$id,'user_id'=>$user_id])->delete(); } /** * 设为默认地址 * @param $id * @param $user_id * @return bool * author: xmy 280564871@qq.com */ public function setDefault($id,$user_id){ $map['id'] = $id; $map['user_id'] = $user_id; return $this->where($map)->setField(['is_default'=>time()]); } /** * 获取默认地址 * @param $user_id * @return mixed * author: xmy 280564871@qq.com */ public function getDefault($user_id){ $map['user_id'] = $user_id; $data = $this->field("id,name,city,address,phone")->where($map)->order("is_default desc")->find(); return $data; } /** * 获取地址列表 * @param $map * @param $order * @return mixed * author: xmy 280564871@qq.com */ public function getLists($map,$order="is_default desc"){ return $this->field("id,name,city,address,phone")->where($map)->order($order)->select(); } }