|
|
@@ -4,7 +4,61 @@ namespace bizMall\custom\classes;
|
|
|
|
|
|
use bizMall\base\classes\BaseClass;
|
|
|
|
|
|
+/**
|
|
|
+ * 商城侧客户(xhCustom)业务类
|
|
|
+ * 用途:按 userId 维护多门店客户档案;默认收货地址回写等共用能力放这里。
|
|
|
+ */
|
|
|
class CustomClass extends BaseClass
|
|
|
{
|
|
|
public static $baseFile = '\bizMall\custom\models\Custom';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将商城默认收货地址同步到同一 userId 下全部 xhCustom
|
|
|
+ * 解决:用户在地址簿设默认后,各门店客户档案仍是旧地址,开单取不到最新收货信息。
|
|
|
+ *
|
|
|
+ * @param int $userId 用户 id(xhUser.id / xhCustom.userId)
|
|
|
+ * @param array|object $address 地址数据;phone 映射为 custom.mobile
|
|
|
+ * @return int 受影响行数(updateByCondition 返回值)
|
|
|
+ */
|
|
|
+ public static function syncFromUserDefaultAddress($userId, $address)
|
|
|
+ {
|
|
|
+ $userId = (int)$userId;
|
|
|
+ if ($userId <= 0 || empty($address)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ // 兼容 AR 模型与数组入参
|
|
|
+ $get = function ($key, $default = '') use ($address) {
|
|
|
+ if (is_array($address)) {
|
|
|
+ return $address[$key] ?? $default;
|
|
|
+ }
|
|
|
+ return isset($address->$key) ? $address->$key : $default;
|
|
|
+ };
|
|
|
+
|
|
|
+ $province = (string)$get('province', '');
|
|
|
+ $city = (string)$get('city', '');
|
|
|
+ $dist = (string)$get('dist', '');
|
|
|
+ $addr = (string)$get('address', '');
|
|
|
+ $floor = (string)$get('floor', '');
|
|
|
+ $fullAddress = (string)$get('fullAddress', '');
|
|
|
+ // 缺完整地址时按省市区+街道+门牌拼接,保证 xhCustom.fullAddress 可用
|
|
|
+ if ($fullAddress === '') {
|
|
|
+ $fullAddress = $province . $city . $dist . $addr . $floor;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'name' => (string)$get('name', ''),
|
|
|
+ 'mobile' => (string)$get('phone', $get('mobile', '')),
|
|
|
+ 'province' => $province,
|
|
|
+ 'city' => $city,
|
|
|
+ 'dist' => $dist,
|
|
|
+ 'address' => $addr,
|
|
|
+ 'floor' => $floor,
|
|
|
+ 'fullAddress' => $fullAddress,
|
|
|
+ 'showAddress' => (string)$get('showAddress', ''),
|
|
|
+ 'lat' => (string)$get('lat', ''),
|
|
|
+ 'long' => (string)$get('long', ''),
|
|
|
+ ];
|
|
|
+
|
|
|
+ return self::updateByCondition(['userId' => $userId], $data);
|
|
|
+ }
|
|
|
}
|