hdId ?? 0; $hd = HdClass::getLockById($hdId); $customId = $order->customId ?? 0; $custom = self::getLockById($customId); } //会员等级变化,包括手动修改、自动降会员和充值升会员等 ssh 20250324 public static function levelChange($oldLevel, $newLevel, $shop, $custom, $hd, $params) { $staffId = $params['staffId'] ?? 0; $staffName = $params['staffName'] ?? ''; $style = $params['style'] ?? 0; $target = $params['target'] ?? []; $onlinePay = $params['onlinePay'] ?? 1; $rechargeAmount = $params['rechargeAmount'] ?? 0; $targetId = $target->id ?? 0; $mainId = $shop->mainId; $shopId = $shop->id; $weal = MemberWealClass::getAllByCondition(['mainId' => $mainId], null, '*', 'level'); $current = $weal[$newLevel] ?? []; $before = $weal[$oldLevel] ?? []; $beforeName = $before['name'] ?? ''; $discount = $current['discount'] ?? 1; $memberName = $current['name'] ?? ''; $custom->member = $newLevel; $custom->discount = $discount; $custom->memberName = $memberName; $custom->save(); $hd->member = $newLevel; $hd->discount = $discount; $hd->memberName = $memberName; $hd->save(); $event = '手动修改'; if ($style == 0) { if ($onlinePay == 2) { $event = '线上充值' . $rechargeAmount . '元'; } else { $event = '线下充值' . $rechargeAmount . '元'; } } $change = [ 'customId' => $custom->id, 'customName' => $custom->name, 'hdId' => $hd->id, 'hdName' => $hd->name, 'mainId' => $mainId, 'shopId' => $shopId, 'targetId' => $targetId, 'rechargeAmount' => $rechargeAmount, 'days' => 0, 'daysBefore' => '0000-00-00 00:00:00', 'daysAfter' => '0000-00-00 00:00:00', 'beforeLevel' => $oldLevel, 'afterLevel' => $newLevel, 'beforeName' => $beforeName, 'afterName' => $memberName, 'style' => $style, 'event' => $event, 'staffId' => $staffId, 'staffName' => $staffName, ]; MemberChangeClass::add($change); } //客户采购欠款金额增加 ssh 20220908 public static function cgDebtAmountAdd($custom, $order) { $amount = $order->remainDebtPrice ?? 0; $custom->isDebt = 1; $lastDebt = bcadd($custom->debtAmount, $amount, 2); $custom->debtAmount = $lastDebt; $custom->save(); $relateId = $order->id ?? 0; $customId = $custom->id ?? 0; $orderSn = $order->orderSn ?? ''; $capitalType = dict::getDict('capitalType', 'xhOrder', 'id'); $event = '购买花材,订单号:' . $orderSn; $change = [ 'relateId' => $relateId, 'customId' => $customId, 'ptStyle' => dict::getDict('ptStyle', 'hd'), 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $lastDebt, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'sjId' => $order->sjId, 'shopId' => $order->id, 'mainId' => $order->mainId, ]; CustomDebtRecordClass::addChange($change); $mainId = $order->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息38'); } $debt = $main->debt ?? 0; $remain = bcadd($debt, $amount, 2); $main->debt = $remain; $main->save(); $event = $custom->name . ' 购买花材,订单号:' . $orderSn; $change['balance'] = $remain; $change['event'] = $event; TotalDebtChangeClass::addChange($change); } //散客申请退款,零售门店欠款金额减少 public static function refundDebtAmountReduce($custom, $amount, $refund) { $debtAmount = $custom->debtAmount ?? 0.00; $remain = bcsub($debtAmount, $amount, 2); if ($remain < 0) { noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次退款金额:{$amount} 客户ID:{$custom->id} 超出了", '15280215347'); util::fail('操作失败,欠款金额会出现负数'); } $custom->isDebt = $remain <= 0 ? 0 : 1; $custom->debtAmount = $remain; $custom->save(); $relateId = $refund->id ?? 0; $customId = $custom->id ?? 0; $capitalType = dict::getDict('capitalType', 'hdRefund', 'id'); $refundSn = $refund->refundSn ?? ''; $change = [ 'relateId' => $relateId, 'customId' => $customId, 'ptStyle' => dict::getDict('ptStyle', 'hd'), 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $remain, 'io' => 0, 'payWay' => 0, 'event' => "客户申请退款,退款单号:{$refundSn}", 'sjId' => $refund->sjId ?? 0, 'shopId' => $refund->shopId ?? 0, 'mainId' => $refund->mainId ?? 0, ]; CustomDebtRecordClass::addChange($change); $mainId = $refund->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息39'); } $debt = $main->debt ?? 0; $totalRemain = bcsub($debt, $amount, 2); $main->debt = $totalRemain; $main->save(); $event = $custom->name . "申请退款,退款单号:{$refundSn}"; $change['balance'] = $totalRemain; $change['event'] = $event; TotalDebtChangeClass::addChange($change); } //客户结账欠款金额减少 ssh 20220908 public static function clearDebtAmountReduce($custom, $amount, $clear) { $debtAmount = $custom->debtAmount ?? 0.00; $remain = bcsub($debtAmount, $amount, 2); if ($remain < 0) { noticeUtil::push("零售客户欠款总金额:{$custom->debtAmount} 本次结账金额:{$amount} 客户ID:{$custom->id} 超出了", '15280215347'); util::fail('操作失败,结账后欠款金额会出现负数'); } $custom->isDebt = $remain <= 0 ? 0 : 1; $custom->debtAmount = $remain; $custom->save(); $relateId = $clear->id ?? 0; $customId = $custom->id ?? 0; $capitalType = dict::getDict('capitalType', 'hdXsClear', 'id'); $orderSn = $clear->orderSn ?? ''; $change = [ 'relateId' => $relateId, 'customId' => $customId, 'ptStyle' => dict::getDict('ptStyle', 'ghs'), 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $remain, 'io' => 0, 'payWay' => 0, 'event' => "结账,单号:{$orderSn}", 'sjId' => $clear->sjId, 'shopId' => $clear->id, 'mainId' => $clear->mainId, ]; CustomDebtRecordClass::addChange($change); $mainId = $clear->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息40'); } $debt = $main->debt ?? 0; $totalRemain = bcsub($debt, $amount, 2); $main->debt = $totalRemain; $main->save(); $event = $custom->name . " 结账,单号:{$orderSn}"; $change['balance'] = $totalRemain; $change['event'] = $event; TotalDebtChangeClass::addChange($change); } public static function getCustomCacheKey($sjId, $shopId, $userId) { return 'hd_custom_key_' . $sjId . '_' . $shopId . '_' . $userId; } //添加客户 ssh 2021.2.28 public static function addCustom($data) { return self::add($data, true); } //创建或获取客户信息 ssh 2021.3.19 public static function buildRelation($shop, $user) { if (empty($user)) { return false; } if (empty($shop)) { return false; } $salt = stringUtil::charsShuffleLowerCase(8); $isNewCustom = 0; $userId = $user->id; $name = $user->name ?? ''; $mobile = $user->mobile ?? ''; $shopId = $shop->id ?? 0; $hdAvatar = $shop->avatar ?? ''; $sjId = $shop->sjId ?? 0; $sjName = $shop->merchantName ?? ''; $shopName = $shop->shopName ?? ''; $hdMobile = $shop->mobile ?? ''; $hdName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $hdPy = stringUtil::py($hdName); $custom = self::getByCondition(['shopId' => $shopId, 'userId' => $userId], true); if (empty($custom)) { $py = stringUtil::py($name); $visitTime = date("Y-m-d H:i:s"); $data = [ 'userId' => $userId, 'sjId' => $sjId, 'shopId' => $shopId, 'name' => $name, 'originName' => $name, 'py' => $py, 'mobile' => $mobile, 'visitTime' => $visitTime, 'salt' => $salt, ]; $custom = self::addCustom($data); $isNewCustom = 1; } $customId = $custom->id ?? 0; $hd = HdClass::getByCondition(['shopId' => $shopId, 'userId' => $userId], true); if (empty($hd)) { $hdData = [ 'shopId' => $shopId, 'userId' => $userId, 'name' => $hdName, 'sjId' => $sjId, 'customId' => $customId, 'avatar' => $hdAvatar, 'py' => $hdPy, 'mobile' => $hdMobile, 'province' => $shop->province ?? '', 'city' => $shop->city ?? '', 'dist' => $shop->dist ?? '', 'address' => $shop->address ?? '', 'floor' => $shop->floor ?? '', 'fullAddress' => $shop->fullAddress ?? '', 'showAddress' => $shop->showAddress ?? '', 'lat' => $shop->lat ?? '', 'long' => $shop->long ?? '', 'salt' => $salt, ]; $hd = HdClass::addData($hdData); $isNewCustom = 1; } $hdId = $hd->id ?? 0; $custom->hdId = $hdId; $custom->save(); if ($isNewCustom == 1) { WxMessageClass::newHdCustomInform($shop, $custom); } return ['custom' => $custom, 'hd' => $hd]; } //获取客户信息 public static function getCustom($data) { $custom = self::getByCondition($data); if (empty($custom)) { $custom = self::add($data); } return $custom; } //获取客户信息 ssh 2021.2.1 public static function getCustomInfo($id) { $custom = self::getById($id); if (empty($custom)) { return $custom; } $list = self::groupBaseInfo([$custom]); return current($list); } //获取客户信息 ssh 2021.3.19 public static function getCustomByIds($ids) { $list = self::getByIds($ids); $list = self::groupBaseInfo($list); return $list; } public static function valid($info, $shopId) { if (isset($info['shopId']) && $info['shopId'] == $shopId) { return true; } util::fail('客户信息无效'); } //整合基本信息 ssh 2021.1.31 public static function groupBaseInfo($list) { if (empty($list)) { return $list; } foreach ($list as $key => $val) { $list[$key]['avatar'] = imgUtil::groupImg($val['avatar']); } return $list; } //更新客户信息 ssh 2021.3.23 public static function updateCustomInfo($custom, $data) { $userId = $custom['userId']; $userData = []; if (isset($data['mobile']) && !empty($data['mobile'])) { $userData['mobile'] = $data['mobile']; } if (!empty($userData)) { UserClass::updateById($userId, $userData); } $id = $custom['id']; self::updateById($id, $data); } }