lat ?? ''; $long = $shop->long ?? ''; $address = $shop->address ?? ''; $hasMap = dict::getDict('hasMap'); $ext = ShopExtClass::getByCondition(['shopId' => $shop->id], true, null, 'id,shopId,thirdSend,thirdSendFee,hcFreeKm,hcMap,hsFreeKm,hsAddFee'); //默认客户自理、到付和客户自己叫跑腿 $openIntraCity = 0; if ($ext->thirdSend == 1) { //禁用跑腿 $openIntraCity = 2; } else { if ($ext->thirdSendFee == 0) { //商家强制要求客户自理、到付和客户自己叫跑腿 $openIntraCity = 0; } else { $mainId = $shop->mainId ?? 0; $hasAuth = DeliveryAuthTokenClass::getByCondition(['mainId' => $mainId], true); //有地图功能,并且有绑定跑腿,并且商家有设置门店的经纬度和地址,则支持通过跑腿接口自动计算跑腿费 if ($hasMap == 1 && !empty($hasAuth) && !empty($lat) && !empty($long) && !empty($address)) { $openIntraCity = 1; } } } return [ // openIntraCity = 0 客户自理、到付和客户自己叫跑腿,1支持自动计算跑腿费,2禁用跑腿 'openIntraCity' => $openIntraCity, 'hcFreeKm' => $ext->hcFreeKm, 'hcMap' => $ext->hcMap, 'hsFreeKm' => $ext->hsFreeKm, 'hsAddFee' => $ext->hsAddFee ]; } //营业状态 public static function isOpen($shop) { if (isset($shop['open']) == false || $shop['open'] == 0) { return 0; } $openStartTime = $shop['openStartTime'] ?? ''; if (empty($openStartTime)) { return 1; } $openEndTime = $shop['openEndTime'] ?? ''; $start = strtotime(date("Y-m-d") . ' ' . $openStartTime); $end = strtotime(date("Y-m-d") . ' ' . $openEndTime); $time = time(); if ($time > $start && $time < $end) { return 1; } return 0; } //修改门店营业时间 public static function updateOpenTime($shop, $data) { $id = $shop['id'] ?? 0; if ($id <= 0) { util::fail('门店不存在'); } $open = isset($data['open']) ? intval($data['open']) : 1; if (!in_array($open, [0, 1], true)) { util::fail('营业状态无效'); } $openType = isset($data['openType']) ? intval($data['openType']) : 0; $openStartTime = trim($data['openStartTime'] ?? ''); $openEndTime = trim($data['openEndTime'] ?? ''); if ($openType == 0) { $openStartTime = ''; $openEndTime = ''; } else { if ($openStartTime === '' || $openEndTime === '') { util::fail('请填写营业时间'); } if (!preg_match('/^\d{2}:\d{2}$/', $openStartTime) || !preg_match('/^\d{2}:\d{2}$/', $openEndTime)) { util::fail('营业时间格式错误'); } } return self::updateById($id, [ 'open' => $open, 'openStartTime' => $openStartTime, 'openEndTime' => $openEndTime, ]); } //获取图片信息 ssh 2021.3.14 public static function getShopInfo($id) { $info = self::getById($id); if (empty($info)) { return $info; } $list = self::groupShopInfo([$info]); return current($list); } public static function getShopList($where) { $list = self::getList('*', $where, 'addTime DESC'); return $list; } //查看店铺 ssh 2021.3.1 public static function getShopByIds($ids) { $list = self::getByIds($ids); return self::groupShopInfo($list); } //门店 ssh 2021.3.1 public static function groupShopInfo($list) { if (empty($list)) { return $list; } foreach ($list as $key => $val) { $shortAvatar = $val['avatar'] ?? ''; $avatar = imgUtil::groupImg($shortAvatar); $list[$key]['avatar'] = $avatar; $list[$key]['shortAvatar'] = $shortAvatar; $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $list[$key]['smallAvatar'] = $smallAvatar; //店长微信 $superWx = $val['superWx'] ?? ''; $list[$key]['superWx'] = imgUtil::groupImg($superWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; } return $list; } //获取商家默认的门店ID ssh 2020.1.19 public static function getDefaultShopId($merchant) { return isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0; } //更新门店 ssh 2020.2.29 public static function updateShop($shop, $data) { $id = $shop['id'] ?? 0; $shopName = isset($data['shopName']) ? $data['shopName'] : ''; if (stringUtil::getWordNum($shopName) > 8) { util::fail('门店名称不能超过8个汉字,2个字母顶一个汉字'); } $sjId = $data['sjId']; $findShop = self::getByCondition(['sjId' => $sjId, 'shopName' => $shopName]); if (!empty($findShop) && $findShop['id'] != $id) { util::fail('门店名称已经存在'); } $dist = $data['dist'] ?? ''; $floor = $data['floor'] ?? ''; $address = $data['address'] ?? ''; $data['fullAddress'] = $data['city'] . $dist . $address . $floor; // 营业时间设置逻辑 if ($data['openType'] == 0) { // openType: 0. 表示 24小时营业 1. 表示 xx ~ xx $data['openStartTime'] = ''; // openStartTime 营业开始时间,空表示24小时 $data['openEndTime'] = ''; } $cutStyle = $data['cutStyle'] ?? 0; $cutAmount = $data['cutAmount'] ?? 0; $meetAmount = $data['meetAmount'] ?? 0; if ($cutStyle == 1) { if ($cutAmount >= 1) { util::fail('折扣要小于1'); } } else { if ($meetAmount > 0 && $cutAmount > 0) { if ($cutAmount >= $meetAmount) { util::fail('优惠金额过大'); } } } //默认门店的开启和关闭 $preDefault = $shop['default'] ?? 0; $default = $data['default'] ?? 0; if ($preDefault != $default) { if ($default == 0) { util::fail('总店地位无法修改,至少要有一个总店'); } $sjId = $shop['sjId'] ?? 0; self::updateByCondition(['sjId' => $sjId], ['default' => 0]); } $data['packCost'] = isset($data['packCost']) && $data['packCost'] > 0 ? $data['packCost'] : 0; $data['cgUnitType'] = $data['cgUnitType'] ?? 0; $data['saleHour'] = $data['saleHour'] ?? 0; $respond = self::updateById($id, $data); $ptStyle = $shop['ptStyle'] ?? dict::getDict('ptStyle', 'hd'); $default = $shop['default'] ?? 0; $sjName = $shop['merchantName'] ?? ''; //默认门店只显示商家名称即可 $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $shopUpdate = [ 'name' => $name, //'mobile' => $data['mobile'] ?? '', // 由于前面已经 unset 掉 mobile,所以会为"",而把原有值置空 'province' => $data['province'] ?? '', 'city' => $data['city'] ?? '', 'dist' => $data['dist'] ?? '', 'address' => $data['address'] ?? '', 'floor' => $data['floor'] ?? '', 'fullAddress' => $data['fullAddress'] ?? '', 'showAddress' => $data['showAddress'] ?? '', 'lat' => $data['lat'] ?? '', 'long' => $data['long'] ?? '' ]; // 如果是批发端,则变更零售端的地址 if ($ptStyle == dict::getDict('ptStyle', 'ghs')) { //$lsShop = self::getById($id, false, 'lsShopId'); $lsShopId = intval($shop['lsShopId']); if ($lsShopId > 0) { $re = self::updateById($lsShopId, $shopUpdate); } } // 如果是零售端,则变更批发端的地址 if ($ptStyle == dict::getDict('ptStyle', 'hd')) { //$pfShop = self::getById($id, false, 'pfShopId'); $pfShopId = intval($shop['pfShopId']); if ($pfShopId > 0) { $re = self::updateById($pfShopId, $shopUpdate); } } $where = ['sjId' => $sjId, 'shopId' => $id]; if ($ptStyle == dict::getDict('ptStyle', 'ghs')) { //如果是批发店,更新供货商信息 GhsClass::updateByCondition($where, $shopUpdate); } if ($ptStyle == dict::getDict('ptStyle', 'hd')) { //如果是花店,更新客户端信息 $city = $data['city'] ?? ''; $dist = $data['dist'] ?? ''; $address = $data['address'] ?? ''; $floor = $data['floor'] ?? ''; $fullAddress = $city . $dist . $address . $floor; $showAddress = $data['showAddress'] ?? ''; $lat = $data['lat'] ?? ''; $long = $data['long'] ?? ''; $upData = [ 'city' => $city, 'dist' => $dist, 'address' => $address, 'floor' => $floor, 'fullAddress' => $fullAddress, 'showAddress' => $showAddress, 'lat' => $lat, 'long' => $long ]; CustomClass::updateByCondition(['shopId' => $id], $upData); //更新散客的xhHd信息 $upData['name'] = $name; HdClass::updateByCondition(['shopId' => $id], $upData); } return $respond; } //取商家所有门店 ssh 2020.2.30 public static function getAllShop($sjId) { return self::getAllByCondition(['sjId' => $sjId], null, "*"); } //验证所属权限 ssh 2020.2.29 public static function valid($shop, $sjId) { if (empty($shop)) { util::fail('门店无效'); } if (isset($shop['sjId']) == false || $shop['sjId'] != $sjId) { util::fail('您无法访问'); } } //删除门店 ssh 2020.3.1 public static function deleteShop($shop) { if (isset($shop['default']) && $shop['default'] == 1) { util::fail('默认门店不允许删除'); } $id = $shop['id']; self::updateById($id, ['delStatus' => 1]); } //生成收款码 ssh 2020.3.9 public static function generateGatheringCode($sjId, $shopId) { $url = Yii::$app->params['mallDomain'] . "/#/pages/pay/index?account=" . $shopId; //强制转成https $url = httpUtil::becomeHttps($url); Yii::info('收款码url:' . $url); $gatheringCode = qrCodeUtil::generateGatheringQrCode($url, $sjId, $shopId, '', 16); Yii::info('gatheringCode:' . $gatheringCode); //$imgUrl = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode) . ',g_nw,x_276,y_463/watermark,image_' . base64_encode('gathering/logo_big.png?x-oss-process=image/resize,P_12') . ',g_nw,x_555,y_728'; $imgUrl = Yii::$app->params['hdImgHost'] . 'gathering/1.jpg?x-oss-process=image/watermark,image_' . base64_encode($gatheringCode) . ',g_nw,x_276,y_463'; return $imgUrl; } //客户充值增加余额 ssh 20240508 public static function customRechargeAddBalance($main, $shop, $order) { $mainId = $shop->mainId ?? 0; $balance = bcadd($main->balance, $order->amount, 2); $txBalance = bcadd($main->txBalance, $order->amount, 2); $main->balance = $balance; $main->txBalance = $txBalance; $main->save(); $rechargeId = $order->id ?? 0; $tx = dict::getDict('yeTx', 'can'); $capitalType = dict::getDict('capitalType', 'customRechargeToGhs', 'id'); $custom = '客户'; if (isset($order->customName) && !empty($order->customName)) { $custom = $order->customName; } $change = [ 'relateId' => $rechargeId, 'capitalType' => $capitalType, 'amount' => $order->amount, 'balance' => $balance, 'txBalance' => $txBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $custom . "充值,单号:{$order->orderSn}", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, 'mainId' => $mainId, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::customRechargeAddBalance($shop, $order, $capitalType, $tx); } /** * 客户线上充值退款:扣减门店 xhMain 余额并记门店余额变动(不涉及平台资产 PtAsset)。 */ public static function customRechargeRefundReduceBalance($main, $shop, $order, $capitalType, $staffName = '') { $amount = bcadd((string)($order->amount ?? '0'), '0', 2); if (bccomp($amount, '0', 2) <= 0) { util::fail('退款金额有误'); } $mainId = $shop->mainId ?? 0; $currentBalance = bcsub((string)($main->balance ?? '0'), $amount, 2); if (bccomp($currentBalance, '0', 2) < 0) { util::fail('门店余额不足,无法退款'); } $main->balance = $currentBalance; $currentTx = bcsub((string)($main->txBalance ?? '0'), $amount, 2); if (bccomp($currentTx, '0', 2) < 0) { $currentTx = '0.00'; } $main->txBalance = $currentTx; $main->save(); $custom = '客户'; if (!empty($order->customName)) { $custom = $order->customName; } $orderSn = $order->orderSn ?? ''; $operator = $staffName !== '' ? "(操作人:{$staffName})" : ''; $event = $custom . "充值退款{$operator},单号:{$orderSn}"; $tx = dict::getDict('yeTx', 'can'); $change = [ 'relateId' => $order->id ?? 0, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 0, 'payWay' => $order->payWay ?? 0, 'event' => $event, 'sjId' => $shop->sjId ?? 0, 'shopId' => $shop->id ?? 0, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle ?? 0, ]; ShopYeChangeClass::addChange($change, true); } public static function skRechargeAddBalance($main, $shop, $order) { $mainId = $main->id; $balance = bcadd($main->balance, $order->amount, 2); $txBalance = bcadd($main->txBalance, $order->amount, 2); $main->balance = $balance; $main->txBalance = $txBalance; $main->save(); $rechargeId = $order->id ?? 0; $tx = dict::getDict('yeTx', 'can'); $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id'); $custom = !empty($order->customName) ? $order->customName : '客户'; $change = [ 'relateId' => $rechargeId, 'capitalType' => $capitalType, 'amount' => $order->amount, 'balance' => $balance, 'txBalance' => $txBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $custom . "充值,单号:{$order->orderSn}", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); } //客户结帐增加余额 ssh 20210729 public static function customClearAddBalance($main, $shop, $order) { $mainId = $shop->mainId ?? 0; $balance = bcadd($main->balance, $order->actPrice, 2); $txBalance = bcadd($main->txBalance, $order->actPrice, 2); $main->balance = $balance; $main->txBalance = $txBalance; $main->save(); $clearId = $order->id ?? 0; $tx = dict::getDict('yeTx', 'can'); $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id'); $custom = '客户'; if (isset($order->customName) && !empty($order->customName)) { $custom = $order->customName; } $change = [ 'relateId' => $clearId, 'capitalType' => $capitalType, 'amount' => $order->actPrice, 'balance' => $balance, 'txBalance' => $txBalance, 'io' => 1, 'payWay' => $order->payWay, 'event' => $custom . "结帐(单号:{$order->orderSn})", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, 'mainId' => $mainId, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::customClearAddBalance($shop, $order, $capitalType, $tx); } //客户使用优惠券增加余额 ssh 20210601 public static function customKdUseCouponAddBalance($shop, $order, $capitalType) { //门店余额增加 $amount = $order->discountAmount; $currentBalance = bcadd($shop->balance, $amount, 2); $shop->balance = $currentBalance; $shop->totalRecharge = bcadd($shop->totalRecharge, $amount, 2); //可提现余额同步增加 $currentTx = bcadd($shop->txBalance, $amount, 2); $shop->txBalance = $currentTx; $shop->save(); //增加余额变动记录 $id = $order->id; $event = "客户下单(使用平台优惠券{$amount}元)"; $tx = dict::getDict('yeTx', 'can'); $mainId = $shop->mainId ?? 0; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::customKdUseCouponAddBalance($shop, $order, $capitalType, $tx); } //客户下单引起的余额增加 ssh 20210520 public static function customKdAddBalance($main, $shop, $amount, $order, $capitalType) { //门店余额增加 $mainId = $shop->mainId ?? 0; $currentBalance = bcadd($main->balance, $amount, 2); $main->balance = $currentBalance; //可提现余额同步增加 $currentTx = bcadd($main->txBalance, $amount, 2); $main->txBalance = $currentTx; $main->save(); $ptStyle = $shop->ptStyle ?? dict::getDict('ptStyle', 'hd'); $customName = '客户'; if ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $customId = $order->customId ?? 0; $custom = CustomClass::getById($customId, true); if (isset($custom->name) && !empty($custom->name)) { $customName = $custom->name; } } //增加余额变动记录 $id = $order->id; $event = $customName . "下单" . floatval($amount) . "元"; $tx = dict::getDict('yeTx', 'can'); $fromType = $order->fromType ?? 1; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, 'fromType' => $fromType, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 //PtAssetClass::customKdAddBalance($shop, $amount, $order, $capitalType, $tx); } public static function customScanPayAddBalance($main, $shop, $amount, $order, $capitalType) { //门店余额增加 $mainId = $shop->mainId ?? 0; $currentBalance = bcadd($main->balance, $amount, 2); $main->balance = $currentBalance; //可提现余额同步增加 $currentTx = bcadd($main->txBalance, $amount, 2); $main->txBalance = $currentTx; $main->save(); $customName = '客户'; $customId = $order->customId ?? 0; $custom = \bizHd\custom\classes\CustomClass::getById($customId, true); if (!empty($custom->name)) { $customName = $custom->name; } //增加余额变动记录 $id = $order->id; $event = $customName . "扫码付款" . floatval($amount) . "元"; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'mainId' => $mainId, 'tx' => 2, 'ptStyle' => $shop->ptStyle, 'fromType' => 1, ]; ShopYeChangeClass::addChange($change, true); } public static function customScanPayRefundReduceBalance($main, $shop, $amount, $order, $refund, $capitalType) { $mainId = $shop->mainId ?? 0; $currentBalance = bcsub($main->balance, $amount, 2); if ($currentBalance < 0) { util::fail('余额不足,请稍后再操作'); } $main->balance = $currentBalance; $currentTx = bcsub($main->txBalance, $amount, 2); if ($currentTx < 0) { $currentTx = 0; } $main->txBalance = $currentTx; $main->save(); $customName = $order->customName ?? '客户'; if (empty($customName)) { $customName = '客户'; } $refundSn = $refund->orderSn ?? ''; $event = $customName . '扫码付款退款' . floatval($amount) . '元(' . $refundSn . ')'; $change = [ 'relateId' => $refund->id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 0, 'payWay' => $order->payWay ?? 0, 'event' => $event, 'mainId' => $mainId, 'tx' => 2, 'ptStyle' => $shop->ptStyle, 'fromType' => 1, ]; ShopYeChangeClass::addChange($change, true); } //门店充值增加余额 ssh 2021.2.21 //$fix = true 余额只能在指定门店使用 public static function rechargeAddBalance($shop, $amount, $order, $tx, $capitalType, $fix = false) { $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有找到资产信息'); } //门店余额增加 $currentBalance = bcadd($main->balance, $amount, 2); $main->balance = $currentBalance; $currentTotalRecharge = bcadd($shop->totalRecharge, $amount, 2); $main->totalRecharge = $currentTotalRecharge; //定向消费余额 if ($fix) { $currentFix = bcadd($main->fixBalance, $amount, 2); $main->fixBalance = $currentFix; } $currentTx = $main->txBalance; //提现余额 if ($tx == dict::getDict('yeTx', 'can')) { $currentTx = bcadd($main->txBalance, $amount, 2); $main->txBalance = $currentTx; } $main->save(); $order->totalRecharge = $currentTotalRecharge; $order->save(); //增加余额变动记录 $id = $order->id; $event = "充值{$amount}元"; if ($order->shopAdminId == 0) { $event = "系统充值{$amount}元"; } $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 1, 'payWay' => $order->payWay, 'event' => $event, 'sjId' => $order->sjId, 'shopId' => $order->shopId, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::rechargeAddBalance($shop, $amount, $order, $capitalType, $tx); } //采购余额付款,减少余额 ssh 20210519 public static function purchaseReduceBalance($main, $shop, $amount, $order) { if (bccomp($amount, $main->balance, 2) == 1) { util::fail('余额不足'); } $sjId = $order->sjId; $shopId = $order->shopId; $mainId = $order->mainId ?? 0; $currentBalance = bcsub($main->balance, $amount, 2); $main->balance = $currentBalance; $tx = dict::getDict('yeTx', 'canNot'); //还有可提现余额也要先用掉 $currentTxBalance = $main->txBalance; if ($currentTxBalance > 0) { $reduceTxBalance = $currentTxBalance > $amount ? $amount : $currentTxBalance; $main->txBalance = bcsub($currentTxBalance, $reduceTxBalance, 2); $tx = dict::getDict('yeTx', 'can'); } $main->save(); $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id'); //增加余额变动记录 $id = $order->id; $change = [ 'relateId' => $id, 'capitalType' => $capitalType, 'amount' => $amount, 'balance' => $currentBalance, 'txBalance' => $currentTxBalance, 'io' => 0, 'payWay' => $order->payWay, 'event' => "采购余额付款{$amount}元", 'sjId' => $sjId, 'shopId' => $shopId, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::reduceBalance($shop, $amount, $order, $capitalType, $tx); } //零售采购退款 public static function cgRefundAddBalance($main, $shop, $refundPrice, $cgRefund, $ghs) { //客户余额增加 $currentBalance = bcadd($main->balance, $refundPrice, 2); $main->balance = $currentBalance; $main->save(); $currentTxBalance = $main->txBalance; $currentType = dict::getDict('capitalType', 'cgRefund', 'id'); $id = $cgRefund->id; $ptStyle = $shop->ptStyle; $sjId = $shop->sjId; $shopId = $shop->id; $mainId = $shop->mainId; $tx = dict::getDict('yeTx', 'canNot'); $ghsName = $ghs->name ?? ''; $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentBalance, 'txBalance' => $currentTxBalance, 'io' => 1, 'payWay' => 0, 'event' => "采购退款({$ghsName})", 'sjId' => $sjId, 'shopId' => $shopId, 'mainId' => $mainId, 'tx' => $tx, 'ptStyle' => $ptStyle, ]; ShopYeChangeClass::addChange($change, true); PtAssetClass::cgRefundAddBalance($shop, $refundPrice, $cgRefund, $currentType, $tx); } //供货商预订被多付了退款减少余额 ssh 20220324 public static function ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice) { $currentBalance = bcsub($main->balance, $refundPrice, 2); if ($currentBalance < 0) { util::fail('余额不足,请先充值哦'); } $main->balance = $currentBalance; $currentTx = $main->txBalance; if ($currentTx > 0) { if ($refundPrice > $currentTx) { $currentTx = 0; } else { $currentTx = bcsub($currentTx, $refundPrice, 2); } } $main->txBalance = $currentTx; $main->save(); $currentType = dict::getDict('capitalType', 'ghsBookRefund'); $id = $refund->id; $event = "预订单被多付退给客户(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})"; $relateOrderSn = $refund->relateOrderSn ?? ''; if (!empty($relateOrderSn)) { $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true); $customName = $relateOrder->customName ?? ''; if (!empty($customName)) { $event = "预订单{$customName}多付退款(退款单 {$refund->orderSn} 订单{$refund->relateOrderSn})"; } } $tx = dict::getDict('yeTx', 'can'); $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 0, 'payWay' => 0, 'event' => $event, 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::ghsBookOrderRefundReduceBalance($shop, $refund, $refundPrice); } //花店销售单退款减少余额 public static function hdSaleRefundReduceBalance($main, $shop, $refund, $refundPrice) { //门店余额减少 $currentBalance = bcsub($main->balance, $refundPrice, 2); if ($currentBalance < 0) { util::fail('余额不足,请先充值吧'); } $main->balance = $currentBalance; $currentTx = $main->txBalance; if ($currentTx > 0) { if ($refundPrice > $currentTx) { $currentTx = 0; } else { $currentTx = bcsub($currentTx, $refundPrice, 2); } } $main->txBalance = $currentTx; $main->save(); $currentType = dict::getDict('capitalType', 'hdOrderRefund'); $id = $refund->id; $event = "退款给客户(退款单 {$refund->refundSn})"; $relateOrderSn = $refund->orderSn ?? ''; if (!empty($relateOrderSn)) { $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true); $customName = $relateOrder->customName ?? ''; if (!empty($customName)) { $event = "退款给{$customName}(退款单 {$refund->refundSn})"; } } $tx = dict::getDict('yeTx', 'can'); $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 0, 'payWay' => 0, 'event' => $event, 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::hdSaleRefundReduceBalance($shop, $refund, $refundPrice); } //销售单退款减少余额 ssh 2021.2.21 public static function saleRefundReduceBalance($main, $shop, $refund, $refundPrice) { //门店余额减少 $currentBalance = bcsub($main->balance, $refundPrice, 2); if ($currentBalance < 0) { util::fail('余额不足,请稍后再操作'); } $main->balance = $currentBalance; $currentTx = $main->txBalance; if ($currentTx > 0) { if ($refundPrice > $currentTx) { $currentTx = 0; } else { $currentTx = bcsub($currentTx, $refundPrice, 2); } } $main->txBalance = $currentTx; $main->save(); $currentType = dict::getDict('capitalType', 'saleRefund'); $id = $refund->id; $event = "退款给客户(退款单 {$refund->orderSn})"; $relateOrderSn = $refund->relateOrderSn ?? ''; if (!empty($relateOrderSn)) { $relateOrder = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true); $customName = $relateOrder->customName ?? ''; if (!empty($customName)) { $event = "退款给{$customName}(退款单 {$refund->orderSn})"; } } $tx = dict::getDict('yeTx', 'can'); $change = [ 'relateId' => $id, 'capitalType' => $currentType, 'amount' => $refundPrice, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 0, 'payWay' => 0, 'event' => $event, 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 PtAssetClass::saleRefundReduceBalance($shop, $refund, $refundPrice); } //获取商家所有的门店 ssh 2021.2.26 public static function getSjShopList($sjId) { return self::getAllByCondition(['sjId' => $sjId, 'delStatus' => 0], null, ['id']); } //取门店长信息 ssh 2021.1.17 public static function getSuper($id) { $shop = self::getById($id); if (empty($shop)) { return []; } $adminId = $shop['adminId'] ?? 0; return \bizHd\admin\classes\AdminClass::getDetail($adminId); } //佣金引起的余额增加 lqh 2021211 /** * @param $shop * @param $amount 提现金额 * @param $cashId 提现主键ID * @param $capitalType */ public static function brokerageAddBalance($shop, $cash, $capitalType) { $amount = $cash->amount ?? 0; $amount = floatval($amount); $cashId = $cash->id ?? 0; $customerSjName = $cash->sjName ?? ''; $customerName = $cash->shopName ?? ''; //获取的佣金 万分之三 暂时先写死,后续可走配置 $brokerage = bcmul($amount, 0.0003, 2); //门店余额增加 $currentBalance = bcadd($shop->balance, $brokerage, 2); $shop->balance = $currentBalance; $shop->totalRecharge = bcadd($shop->totalRecharge, $brokerage, 2); //可提现余额同步增加 $currentTx = bcadd($shop->txBalance, $brokerage, 2); $shop->txBalance = $currentTx; $shop->save(); //增加余额变动记录 $tx = dict::getDict('yeTx', 'can'); $change = [ 'relateId' => $cashId, 'capitalType' => $capitalType, 'amount' => $brokerage, 'balance' => $currentBalance, 'txBalance' => $currentTx, 'io' => 1, 'payWay' => 0, 'event' => $customerSjName . '-' . $customerName . "提现" . $amount . "元获得佣金", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'mainId' => $shop->mainId, 'tx' => $tx, 'ptStyle' => $shop->ptStyle, ]; ShopYeChangeClass::addChange($change, true); //平台余额增加 $ptStyle = $shop->ptStyle; if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $asset = PtAssetClass::getHdBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $asset = PtAssetClass::getGhsBalance(); } else { util::fail('没有找到平台'); } //增加平台可余额 $currentPtBalance = bcadd($asset->amount, $brokerage, 2); $asset->amount = $currentPtBalance; $asset->save(); if ($ptStyle == dict::getDict('ptStyle', 'hd')) { $txAsset = PtAssetClass::getHdTxBalance(); } elseif ($ptStyle == dict::getDict('ptStyle', 'ghs')) { $txAsset = PtAssetClass::getGhsTxBalance(); } else { util::fail('没有找到平台'); } //增加平台可提现余额 $currentPtTxBalance = $txAsset->amount; $currentPtTxBalance = bcadd($currentPtTxBalance, $brokerage, 2); $txAsset->amount = $currentPtTxBalance; $txAsset->save(); $change = [ 'relateId' => $cashId, 'capitalType' => $capitalType, 'amount' => $brokerage, 'balance' => $currentPtBalance, 'txBalance' => $currentPtTxBalance, 'io' => 1, 'payWay' => 0, 'event' => $customerSjName . '-' . $customerName . "提现" . $amount . "元,代理商【{$shop->merchantName}-{$shop->shopName}】获得佣金", 'sjId' => $shop->sjId, 'shopId' => $shop->id, 'tx' => $tx, 'ptStyle' => $ptStyle, 'shopName' => $shop->shopName, 'sjName' => $shop->merchantName, ]; PtYeChangeClass::addChange($change, true); } }