| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- <?php
- namespace bizGhs\custom\classes;
- use biz\ghs\classes\GhsClass;
- use biz\sj\classes\MerchantClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\shop\classes\TotalDebtChangeClass;
- use common\components\business;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\util;
- use bizHd\base\classes\BaseClass;
- 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 => 'skAddPrice',
- self::LEVEL_PT => 'addPrice',
- self::LEVEL_HJ => 'hjAddPrice',
- self::LEVEL_ZS => 'zsAddPrice',
- ];
- //建立客户和供货商关系
- 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;
- }
- 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 ($custom->debtAmount > $debtLimit) {
- util::fail("您已欠款{$custom->debtAmount},请先结账哦");
- }
- }
- $balance = bcadd($custom->debtAmount, $amount, 2);
- $custom->debtAmount = $balance;
- $custom->save();
- $relateId = $order->id ?? 0;
- $customId = $custom->id ?? 0;
- $orderSn = $order->orderSn ?? '';
- $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
- $event = '购买花材,单号:' . $orderSn;
- if ($bookOrder) {
- $event = '预订单多退少补,单号:' . $orderSn;
- }
- $change = [
- 'relateId' => $relateId,
- 'customId' => $customId,
- 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
- 'capitalType' => $capitalType,
- 'amount' => $amount,
- 'balance' => $balance,
- 'io' => 1,
- 'payWay' => $order->payWay,
- 'event' => $event,
- 'sjId' => $order->sjId,
- 'shopId' => $order->id,
- 'mainId' => $order->mainId,
- ];
- CustomDebtChangeClass::addChange($change);
- $mainId = $order->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- $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);
- }
- //客户结账欠款金额减少 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;
- $capitalType = dict::getDict('capitalType', 'ghsXsClear', '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' => $ghs->sjId,
- 'shopId' => $ghs->id,
- 'mainId' => $ghs->mainId,
- ];
- CustomDebtChangeClass::addChange($change);
- $mainId = $ghs->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- $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;
- $saleOrderSn = $order->orderSn ?? '';
- $capitalType = dict::getDict('capitalType', 'saleRefund', 'id');
- $change = [
- 'relateId' => $relateId,
- 'customId' => $customId,
- 'ptStyle' => dict::getDict('ptStyle', 'ghs'),
- 'capitalType' => $capitalType,
- 'amount' => $refundPrice,
- 'balance' => $balance,
- 'io' => 0,
- 'payWay' => 0,
- 'event' => "订单号:{$saleOrderSn} 退款",
- 'sjId' => $refund->sjId,
- 'shopId' => $refund->id,
- 'mainId' => $order->mainId,
- ];
- CustomDebtChangeClass::addChange($change);
- $mainId = $order->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- $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);
- }
- }
|