'散客', 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'] ?? ''; $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) { if (isset($order->shopAdminId) && $order->shopAdminId == 0) { //客户自己下单要受额度限制 if ($custom->debtAmount > $debtLimit) { //虚拟供货商和客户关系不受影响 if($custom->live == 1){ 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]; } }