| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789 |
- <?php
- namespace bizGhs\custom\classes;
- use biz\ghs\classes\GhsClass;
- use biz\sj\classes\MerchantClass;
- use bizGhs\book\classes\BookCustomClass;
- use bizGhs\book\classes\BookItemCustomClass;
- use bizGhs\custom\models\Custom;
- use bizGhs\ghs\classes\GhsBalanceChangeClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\shop\classes\TotalDebtChangeClass;
- use bizGhs\ghs\classes\GhsBalanceClass;
- use bizGhs\ghs\classes\GhsRechargeClass;
- use bizGhs\shop\classes\ShopClass;
- use common\components\business;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\util;
- use common\components\orderSn;
- use bizHd\base\classes\BaseClass;
- use Yii;
- class CustomClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\custom\models\Custom';
- const IS_DEBT_NO = 0;
- const IS_DEBT_YES = 1;
- const NOT_BLACK = 1;
- const IS_BLACK = 2;
- const LEVEL_SK = 0; //散客
- const LEVEL_PT = 1; //花店
- const LEVEL_HJ = 2; //同行
- const LEVEL_ZS = 3; //金店
- public static $levelMap = [
- self::LEVEL_SK => '散客',
- self::LEVEL_PT => '花店',
- self::LEVEL_HJ => '同行',
- self::LEVEL_ZS => '金店',
- ];
- public static $nickNameMap = [
- self::LEVEL_SK => '零售',
- self::LEVEL_PT => '批发',
- self::LEVEL_HJ => '同行',
- self::LEVEL_ZS => '金店',
- ];
- public static $levelPriceKeyMap = [
- self::LEVEL_SK => 'skPrice',
- self::LEVEL_PT => 'price',
- self::LEVEL_HJ => 'hjPrice',
- self::LEVEL_ZS => 'zsPrice',
- ];
- public static $levelAddPriceKeyMap = [
- self::LEVEL_SK => 'skMore',
- self::LEVEL_PT => 'addPrice',
- self::LEVEL_HJ => 'hjAddPrice',
- self::LEVEL_ZS => 'zsAddPrice',
- ];
- //预订相关表同步更新货位 ssh 20240729
- public static function syncBookSeat($shop, $custom, $seatSn)
- {
- $bookSn = $shop->bookSn ?? 0;
- if (empty($bookSn)) {
- return true;
- }
- $customId = $custom->id ?? 0;
- BookItemCustomClass::updateByCondition(['bookSn' => $bookSn, 'customId' => $customId], ['seatSn' => $seatSn]);
- BookCustomClass::updateByCondition(['bookSn' => $bookSn, 'customId' => $customId], ['seatSn' => $seatSn]);
- }
- //消费余额 ssh 20240311
- public static function clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clear)
- {
- $customId = $custom->id ?? 0;
- $customName = $custom->name ?? '';
- $ghsId = $ghs->id ?? 0;
- $relateId = $clear->id ?? 0;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $clearSn = $clear->orderSn;
- $mainId = $shop->mainId ?? 0;
- $shopId = $shop->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $newGhsBalance = bcsub($ghs->balance, $amount, 2);
- $ghs->balance = $newGhsBalance;
- $ghs->save();
- $newCustomBalance = bcsub($custom->balance, $amount, 2);
- $custom->balance = $newCustomBalance;
- $custom->save();
- if ($newGhsBalance < 0) {
- util::fail('余额有问题哦..');
- }
- if (floatval($newGhsBalance) != floatval($newCustomBalance)) {
- util::fail('余额有问题...');
- }
- $capitalType = dict::getDict('capitalType', 'ghsHelpCustomUseBalanceClear', 'id');
- $fromType = dict::getDict('fromType', 'shop');
- $cbData = [
- 'customId' => $customId,
- 'customName' => $customName,
- 'relateId' => $relateId,
- 'onlinePay' => 1,
- 'ptStyle' => 2,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $newCustomBalance,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'io' => 0,
- 'side' => 0,
- 'payWay' => 0,
- 'fromType' => $fromType,
- 'event' => '结账 ' . $clearSn,
- 'mainId' => $mainId,
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'remark' => '',
- ];
- $cbc = CustomBalanceChangeClass::add($cbData, true);
- $customShopId = $custom->shopId ?? 0;
- $customShop = ShopClass::getById($customShopId, true);
- if (empty($customShop)) {
- util::fail('没有找到客户门店呢..');
- }
- $customShopSjId = $customShop->sjId ?? 0;
- $customShopMainId = $customShop->mainId ?? 0;
- $capitalType = dict::getDict('capitalType', 'customAskGhsUseBalanceClear', 'id');
- $gbData = [
- 'ghsId' => $ghsId,
- 'relateId' => $relateId,
- 'ptStyle' => 2,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $newGhsBalance,
- 'io' => 0,
- 'side' => 0,
- 'onlinePay' => 1,
- 'payWay' => 0,
- 'fromType' => $fromType,
- 'event' => '结账 ' . $clearSn,
- 'sjId' => $customShopSjId,
- 'mainId' => $customShopMainId,
- 'shopId' => $customShopId,
- 'remark' => '',
- ];
- $gbc = GhsBalanceChangeClass::add($gbData, true);
- $clear->customBalanceChangeId = $cbc->id ?? 0;
- $clear->ghsBalanceChangeId = $gbc->id ?? 0;
- $clear->save();
- }
- //充值金额,有多个地方要同步修改,请搜索关键词custom_ghs_recharge ssh 20240310
- public static function rechargeBalance($custom, $amount, $shop, $staff, $payWay, $params = [])
- {
- $ghsId = $custom->ghsId ?? 0;
- $ghsInfo = GhsClass::getLockById($ghsId);
- if (empty($ghsInfo)) {
- util::fail('没有找到供货商');
- }
- $ghsShopId = $ghsInfo->shopId ?? 0;
- $ghsName = $ghsInfo->name ?? '';
- $customId = $custom->id ?? 0;
- $customShopId = $custom->shopId ?? 0;
- $customName = $custom->name ?? '';
- $customShop = ShopClass::getById($customShopId, true);
- if (empty($customShop)) {
- util::fail('没有找到客户门店');
- }
- $payTime = date("Y-m-d H:i:s");
- $customShopSjId = $customShop->sjId ?? 0;
- $customShopMainId = $customShop->mainId ?? 0;
- $custom->balance = bcadd($custom->balance, $amount, 2);
- $custom->save();
- $orderSn = orderSn::getGhsCustomRechargeSn();
- $shopId = $shop->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $mainId = $shop->mainId ?? 0;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $remark = $params['remark'] ?? '';
- $rechargeType = $params['rechargeType'] ?? 0;
- $payMap = dict::getDict('payWayName');
- $payName = $payMap[$payWay] ?? '';
- $rechargeEvent = $payName . '充值';
- if ($rechargeType == 1) {
- $rechargeEvent = '售后返充';
- }
- $cData = [
- 'orderSn' => $orderSn,
- 'onlinePay' => 1,
- 'payWay' => $payWay,
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'amount' => $amount,
- 'balance' => $custom->balance,
- 'side' => 0,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'payStatus' => 1,
- 'status' => 1,
- 'ghsId' => $ghsId,
- 'ghsShopId' => $ghsShopId,
- 'ghsName' => $ghsName,
- 'customId' => $customId,
- 'customShopId' => $customShopId,
- 'customName' => $customName,
- 'remark' => $remark,
- 'payTime' => $payTime,
- 'rechargeType' => $rechargeType,
- ];
- $cRecharge = CustomRechargeClass::add($cData, true);
- $cRechargeId = $cRecharge->id ?? 0;
- $capitalType = dict::getDict('capitalType', 'ghsHelpCustomRecharge', 'id');
- if ($rechargeType == 1) {
- //售后返充
- $capitalType = dict::getDict('capitalType', 'ghsHelpCustomRechargeReturn', 'id');
- }
- $fromType = dict::getDict('fromType', 'shop');
- $cbData = [
- 'customId' => $customId,
- 'customName' => $customName,
- 'relateId' => $cRechargeId,
- 'onlinePay' => 1,
- 'ptStyle' => 2,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $custom->balance,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'io' => 1,
- 'side' => 0,
- 'payWay' => $payWay,
- 'fromType' => $fromType,
- 'event' => $rechargeEvent,
- 'mainId' => $mainId,
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'remark' => $remark,
- ];
- CustomBalanceChangeClass::add($cbData, true);
- $ghsInfo->balance = bcadd($ghsInfo->balance, $amount, 2);
- $ghsInfo->save();
- $orderSn = orderSn::getGhsRechargeSn();
- $customMainId = $custom->mainId ?? 0;
- $gData = [
- 'orderSn' => $orderSn,
- 'onlinePay' => 1,
- 'payWay' => $payWay,
- 'shopId' => $customShopId,
- 'mainId' => $customMainId,
- 'amount' => $amount,
- 'balance' => $ghsInfo->balance,
- 'side' => 0,
- 'staffId' => 0,
- 'staffName' => '',
- 'payStatus' => 1,
- 'status' => 1,
- 'ghsId' => $ghsId,
- 'ghsShopId' => $ghsShopId,
- 'ghsName' => $ghsName,
- 'customId' => $customId,
- 'customShopId' => $customShopId,
- 'customName' => $customName,
- 'remark' => $remark,
- 'payTime' => $payTime,
- 'rechargeType' => $rechargeType,
- ];
- $gRecharge = GhsRechargeClass::add($gData, true);
- $gRechargeId = $gRecharge->id ?? 0;
- $capitalType = dict::getDict('capitalType', 'customAskGhsRecharge', 'id');
- if ($rechargeType == 1) {
- //售后返充
- $capitalType = dict::getDict('capitalType', 'customAskGhsRechargeReturn', 'id');
- }
- $gbData = [
- 'ghsId' => $ghsId,
- 'ghsName' => $ghsName,
- 'relateId' => $gRechargeId,
- 'ptStyle' => 2,
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $ghsInfo->balance,
- 'io' => 1,
- 'side' => 0,
- 'onlinePay' => 1,
- 'payWay' => $payWay,
- 'fromType' => $fromType,
- 'event' => $rechargeEvent,
- 'sjId' => $customShopSjId,
- 'mainId' => $customShopMainId,
- 'shopId' => $customShopId,
- 'remark' => $remark,
- ];
- GhsBalanceChangeClass::add($gbData, true);
- return ['custom' => $custom, 'ghs' => $ghsInfo, 'customRecharge' => $cRecharge, 'ghsRecharge' => $gRecharge];
- }
- public static function createSeatSn($mainId)
- {
- $max = Custom::find(['mainId' => $mainId])->max('seatSn');
- $new = bcadd($max, 1);
- return $new;
- }
- //建立客户和供货商关系
- public static function build($ghsShopId, $hdShopId, $changeName = '')
- {
- return GhsClass::build($ghsShopId, $hdShopId, 2, $changeName);
- }
- //添加客户 ssh 2021.2.24
- public static function addCustom($data)
- {
- return self::add($data);
- }
- //获取客户信息 ssh 2021.2.4
- public static function getCustom($id)
- {
- $info = self::getById($id);
- if (empty($info)) {
- return $info;
- }
- $respond = self::groupBaseInfo([$info]);
- return current($respond);
- }
- public static function getCustomByIds($ids)
- {
- $list = self::getByIds($ids, null, 'id');
- return self::groupBaseInfo($list);
- }
- //整合头像等信息 ssh 2021.1.8
- public static function groupBaseInfo($list)
- {
- if (empty($list)) {
- return $list;
- }
- //获取客户信息
- $customSjIdList = array_unique(array_filter(array_column($list, 'sjId')));
- $sjInfo = MerchantClass::getByIds($customSjIdList, null, 'id');
- $levelMap = self::$levelMap;
- foreach ($list as $key => $val) {
- $customSjId = $val['sjId'];
- $currentInfo = isset($sjInfo[$customSjId]) ? $sjInfo[$customSjId] : [];
- $currentInfo = business::formatMerchantLogo($currentInfo);
- $smallAvatar = !empty($currentInfo['smallLogoUrl']) ? $currentInfo['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
- $avatar = !empty($currentInfo['logoUrl']) ? $currentInfo['logoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
- $list[$key]['smallAvatar'] = $smallAvatar;
- $list[$key]['shortSmallAvatar'] = $currentInfo['shortSmallLogoUrl'];
- $list[$key]['avatar'] = $avatar;
- $list[$key]['shortAvatar'] = $currentInfo['shortLogoUrl'];
- $list[$key]['sn'] = $val['id'];
- $level = $val['level'] ?? 1;
- $levelName = $levelMap[$level] ?? '';
- $list[$key]['levelName'] = $levelName;
- $debtAmount = $val['debtAmount'] ?? 0;
- $balance = $val['balance'] ?? 0;
- $remainDebtAmount = bcsub($debtAmount, $balance, 2);
- $list[$key]['remainDebtAmount'] = $remainDebtAmount;
- //前端使用,走播,预订客户添加新客户
- $list[$key]['zbNum'] = '';
- $list[$key]['zbPrice'] = '';
- $recentExpend = $val['recentExpend'] ?? '';
- $recentExpendTime = strtotime($recentExpend);
- $seven = bcmul(86400, 7);
- $addTime = bcadd($recentExpendTime, $seven);
- $list[$key]['overSevenUnExpend'] = 0;
- if ($addTime < time()) {
- //超过7天未下单
- $list[$key]['overSevenUnExpend'] = 1;
- }
- //超时未下单
- $list[$key]['overTimeUnExpend'] = 0;
- if ($recentExpend == '0000-00-00 00:00:00') {
- $list[$key]['overTimeUnExpend'] = 10000;
- } else {
- $recentExpendTime = strtotime($recentExpend);
- $seven = bcmul(86400, 7);
- $sevenTime = bcadd($recentExpendTime, $seven);
- if ($sevenTime < time()) {
- $list[$key]['overTimeUnExpend'] = 7;
- }
- $month = bcmul(86400, 30);
- $monthTime = bcadd($recentExpendTime, $month);
- if ($monthTime < time()) {
- $list[$key]['overTimeUnExpend'] = 30;
- }
- $halfYear = bcmul(86400, 180);
- $halfYearTime = bcadd($recentExpendTime, $halfYear);
- if ($halfYearTime < time()) {
- $list[$key]['overTimeUnExpend'] = 180;
- }
- $year = bcmul(86400, 365);
- $yearTime = bcmul($recentExpendTime, $year);
- if ($yearTime < time()) {
- $list[$key]['overTimeUnExpend'] = 365;
- }
- }
- }
- return $list;
- }
- //欠款权限开关 ssh 2021.1.8
- public static function debt($custom, $debt)
- {
- $id = isset($custom['id']) ? $custom['id'] : 0;
- self::updateById($id, ['debt' => $debt]);
- return true;
- }
- //采购查看权限的黑白名单设置 shizhongqi 2021.08.08
- public static function black($custom, $black)
- {
- $id = isset($custom['id']) ? $custom['id'] : 0;
- self::updateById($id, ['black' => $black]);
- return true;
- }
- //权限判断 ssh 2021.1.8
- public static function valid($custom, $shopId)
- {
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom['ownShopId'] != $shopId) {
- util::fail('您无法操作此客户');
- }
- }
- //客户采购欠款金额增加 ssh 20220306
- public static function cgDebtAmountAdd($custom, $order, $bookOrder = false)
- {
- $amount = $order->remainDebtPrice ?? 0;
- $custom->isDebt = CustomClass::IS_DEBT_YES;
- $debtLimit = $custom->debtLimit ?? 0;
- if ($bookOrder == false) {
- if (isset($order->shopAdminId) && $order->shopAdminId == 0) {
- //客户自己下单要受额度限制
- if ($custom->debtAmount > $debtLimit) {
- util::fail("已欠款{$custom->debtAmount},请先结账哦");
- }
- }
- }
- $balance = bcadd($custom->debtAmount, $amount, 2);
- $mustNotice = false;
- if (getenv('YII_ENV') == 'production') {
- //王品牛排 黄先生
- if ($custom->id == 11726) {
- $mustNotice = true;
- }
- } else {
- if ($custom->id == 577) {
- $mustNotice = true;
- }
- }
- if (getenv('YII_ENV', 'local') == 'production') {
- if ($mustNotice) {
- noticeUtil::push("【开单动作 | 客户】变化前欠款:{$custom->debtAmount} 变化金额:{$amount} 变化后欠款:{$balance}", '15280215347');
- }
- }
- $custom->debtAmount = $balance;
- $custom->save();
- $relateId = $order->id ?? 0;
- $customId = $custom->id ?? 0;
- $customName = $custom->name ?? '';
- $orderSn = $order->orderSn ?? '';
- $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
- $event = '购买花材,单号:' . $orderSn;
- if ($bookOrder) {
- $event = '预订单多退少补,单号:' . $orderSn;
- }
- $change = [
- 'relateId' => $relateId,
- 'customId' => $customId,
- 'customName' => $customName,
- 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $balance,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->shopId,
- 'mainId' => $order->mainId,
- ];
- CustomDebtChangeClass::addChange($change);
- $mainId = $order->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息8');
- }
- $debt = $main->debt ?? 0;
- $remain = bcadd($debt, $amount, 2);
- if (getenv('YII_ENV', 'local') == 'production') {
- if ($mustNotice) {
- noticeUtil::push("【开单动作 | 总欠款】变化前欠款:{$debt} 变化金额:{$amount} 变化后欠款:{$remain}", '15280215347');
- }
- }
- $main->debt = $remain;
- $main->save();
- $event = $custom->name . ' 购买花材,单号:' . $orderSn;
- $change['balance'] = $remain;
- $change['event'] = $event;
- TotalDebtChangeClass::addChange($change);
- }
- //客户结账欠款金额减少 ssh 20220306
- public static function clearDebtAmountReduce($custom, $ghs, $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;
- $customName = $custom->name ?? '';
- $capitalType = dict::getDict('capitalType', 'ghsXsClear', 'id');
- $orderSn = $clear->orderSn ?? '';
- $change = [
- 'relateId' => $relateId,
- 'customId' => $customId,
- 'customName' => $customName,
- 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $remain,
- 'io' => 0,
- 'payWay' => 0,
- 'event' => "结账,单号:{$orderSn}",
- 'sjId' => $ghs->sjId,
- 'shopId' => $ghs->shopId,
- 'mainId' => $ghs->mainId,
- ];
- CustomDebtChangeClass::addChange($change);
- $mainId = $ghs->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息9');
- }
- $debt = $main->debt ?? 0;
- $remain = bcsub($debt, $amount, 2);
- $main->debt = $remain;
- $main->save();
- $event = $custom->name . " 结账,单号:{$orderSn}";
- $change['balance'] = $remain;
- $change['event'] = $event;
- TotalDebtChangeClass::addChange($change);
- }
- //客户退款欠款金额减少 ssh 20220306
- public static function refundDebtAmountReduce($custom, $refund, $order)
- {
- $refundPrice = $refund->refundPrice ?? 0;
- $balance = bcsub($custom->debtAmount, $refundPrice, 2);
- $custom->debtAmount = $balance;
- $custom->save();
- $relateId = $refund->id ?? 0;
- $customId = $custom->id ?? 0;
- $customName = $custom->name ?? '';
- $saleOrderSn = $order->orderSn ?? '';
- $capitalType = dict::getDict('capitalType', 'saleRefund', 'id');
- $payTime = $order->payTime;
- $change = [
- 'relateId' => $relateId,
- 'customId' => $customId,
- 'customName' => $customName,
- 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
- 'capitalType' => $capitalType,
- 'amount' => $refundPrice,
- 'balance' => $balance,
- 'io' => 0,
- 'payWay' => 0,
- 'event' => "订单号:{$saleOrderSn} 退款",
- 'sjId' => $refund->sjId,
- 'shopId' => $refund->shopId,
- 'mainId' => $order->mainId,
- 'payTime' => $payTime,
- ];
- CustomDebtChangeClass::addChange($change);
- $mainId = $order->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息10');
- }
- $debt = $main->debt ?? 0;
- $remain = bcsub($debt, $refundPrice, 2);
- $main->debt = $remain;
- $main->save();
- $event = $custom->name . " 订单号:{$saleOrderSn} 退款";
- $change['balance'] = $remain;
- $change['event'] = $event;
- TotalDebtChangeClass::addChange($change);
- }
- public static function exportCustom($where, $sort, $mainId)
- {
- $list = self::getAllByCondition($where, $sort, '*', null);
- if (empty($list)) {
- util::fail('没有找到客户');
- }
- $list = self::groupBaseInfo($list);
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '欠款');
- $objPHPExcel->getActiveSheet()->setCellValue('E1', '余额');
- $objPHPExcel->getActiveSheet()->setCellValue('F1', '待结金额');
- $objPHPExcel->getActiveSheet()->setCellValue('G1', '最近下单');
- $objPHPExcel->getActiveSheet()->setCellValue('H1', '累计消费');
- $objPHPExcel->getActiveSheet()->setCellValue('I1', '累计消费次数');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
- $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile'], \PHPExcel_Cell_DataType::TYPE_STRING);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['debtAmount']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['balance']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['remainDebtAmount']);
- if ($custom['recentExpend'] == '0000-00-00 00:00:00') {
- $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, '没有下过单');
- } else {
- $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $custom['recentExpend']);
- }
- $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $custom['buyAmount']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $custom['buyNum']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- }
- $fileName = '客户-' . date("m-d");
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- public static function showTotalBalance($pfShopId = 0, $lsShopId = 0)
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $pfAmount = 0;
- $lsAmount = 0;
- if (!empty($pfShopId)) {
- $custom = CustomClass::getAllByCondition(['ownShopId' => $pfShopId], null, '*', null, true);
- if (!empty($custom)) {
- foreach ($custom as $c) {
- $balance = $c->balance ?? 0;
- $debtAmount = $c->debtAmount ?? 0;
- $new = bcsub($balance, $debtAmount, 2);
- $pfAmount = bcadd($pfAmount, $new, 2);
- }
- }
- }
- if (!empty($lsShopId)) {
- $lsCustom = \bizHd\custom\classes\CustomClass::getAllByCondition(['shopId' => $lsShopId], null, '*', null, true);
- if (!empty($lsCustom)) {
- foreach ($lsCustom as $lc) {
- $balance = $lc->balance ?? 0;
- $lsAmount = bcadd($balance, $lsAmount, 2);
- }
- }
- }
- return ['pfAmount' => $pfAmount, 'lsAmount' => $lsAmount];
- }
- }
|