<?php
 namespace TechSoft\Laravel\MemberAddress; use TechOnline\Laravel\Dao\ModelUtil; class MemberAddressUtil { public static function loadWithUserId($userId, $id) { return ModelUtil::get('member_address', ['id' => $id, 'userId' => $userId]); } public static function delete($id) { ModelUtil::delete('member_address', ['id' => $id]); } public static function update($id, $data) { return ModelUtil::update('member_address', ['id' => $id], $data); } public static function add($data) { return ModelUtil::insert('member_address', $data); } public static function listAllByUserId($userId) { return ModelUtil::model('member_address')->where(['userId' => $userId])->orderBy('id', 'desc')->orderBy('isDefault', 'desc')->get()->toArray(); } public static function getDefault($userId) { $address = ModelUtil::get('member_address', ['userId' => $userId, 'isDefault' => 1]); if (empty($address)) { $address = ModelUtil::get('member_address', ['userId' => $userId]); } return $address; } public static function clearDefault($userId) { ModelUtil::update('member_address', ['userId' => $userId], ['isDefault' => 0]); } public static function truncate($memberUserId) { ModelUtil::delete('member_address', ['userId' => $memberUserId]); } }