| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?php
- namespace bizHd\product\classes;
- use biz\item\classes\PtItemClass;
- use bizHd\base\classes\BaseClass;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\sms;
- use common\components\util;
- use Yii;
- class ProductClass extends BaseClass
- {
- public static $baseFile = '\bizHd\product\models\Product';
- //花材列表用到的数据组合 ssh 20221225
- public static function itemListGroup($list, $level = 0)
- {
- //各个等级对应的price addPrice字段
- $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
- $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $cover = imgUtil::getPrefix() . 'hhb_small.png';
- if (!empty($shortCover)) {
- $parse = parse_url(self::groupImg($shortCover));
- if (empty($parse['query'])) {
- $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- } else {
- $cover = self::groupImg($shortCover);
- }
- }
- $list[$k]['cover'] = $cover;
- //今日特价、会员价
- $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
- if ($level == 0) {
- //零售做特价时显示的原价,不能删除
- if (isset($v['skPrice'])) {
- $list[$k]['prePrice'] = $v['skPrice'];
- }
- }
- if (isset($v['discountPrice']) && $v['discountPrice'] > 0) {
- //做特价花材时,花材列表和改价列表显示的会员价和零售价,不能删除
- $list[$k]['hjPrice'] = floatval($v['hjDiscountPrice']);
- $list[$k]['skPrice'] = floatval($v['skDiscountPrice']);
- }
- $list[$k]['price'] = $price;
- $cost = $v['cost'] ?? 0;
- if ($price > 0) {
- $profit = bcsub($price, $cost, 2);
- $mll = bcdiv($profit, $price, 3);
- $mll = bcmul($mll, 100);
- $mll = round($mll, 1);
- } else {
- $mll = 0;
- }
- $list[$k]['mll'] = $mll;
- }
- return $list;
- }
- public static function kdItemGroup($list, $level = 0)
- {
- //各个等级对应的price addPrice字段
- $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
- $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $cover = imgUtil::getPrefix() . 'hhb_small.png';
- if (!empty($shortCover)) {
- $parse = parse_url(self::groupImg($shortCover));
- if (empty($parse['query'])) {
- $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- } else {
- $cover = self::groupImg($shortCover);
- }
- }
- $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
- $list[$k]['cover'] = $cover;
- $stockInfo = self::formatStock($v['stock'], $ratio);
- $list[$k]['bigNum'] = $stockInfo['bigNum'];
- $list[$k]['smallNum'] = $stockInfo['smallNum'];
- $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
- $list[$k]['price'] = $price;
- $list[$k]['bigPrice'] = $price;
- $smallRatio = $v['smallRatio'] ?? 0;
- $smallPrice = bcdiv($price, $ratio, 2);
- $smallPrice = bcmul($smallPrice, $smallRatio, 2);
- $list[$k]['smallPrice'] = $smallPrice;
- }
- return $list;
- }
- //花店的花材转成批发店花材 ssh 20230308
- public static function hdToggleGhs($list, $ghsShop)
- {
- $ghsMainId = $ghsShop->mainId ?? 0;
- $ptItemIds = array_column($list, 'itemId');
- $ghsHasProduct = ProductClass::getAllByCondition(['mainId' => $ghsMainId, 'itemId' => ['in', $ptItemIds]], null, '*', 'itemId');
- $ghsSjId = $ghsShop->sjId ?? 0;
- $ghsShopId = $ghsShop->id ?? 0;
- $defaultClassId = \bizGhs\item\classes\ItemClassClass::getDefaultClassId($ghsMainId);
- if (empty($defaultClassId)) {
- util::fail('没有找到花材的默认分类');
- }
- foreach ($list as $k => $v) {
- $ptItemId = $v['itemId'] ?? 0;
- $hdProductId = $v['productId'] ?? 0;
- if (isset($ghsHasProduct[$ptItemId]) == false) {
- //不存在,则从平台新增
- $ptItem = PtItemClass::getById($ptItemId);
- unset($ptItem['addTime']);
- unset($ptItem['updateTime']);
- $productData = $ptItem;
- $productData['sjId'] = $ghsSjId;
- $productData['shopId'] = $ghsShopId;
- $productData['mainId'] = $ghsMainId;
- $productData['itemId'] = $ptItemId;
- $productData['classId'] = $defaultClassId;
- unset($productData['id']);
- $productData['rank'] = '';
- $cost = $v['cost'] ?? 0;
- $addPrice = $v['addPrice'] ?? 0;
- $productData['price'] = bcadd($cost, $addPrice, 2);
- $addProduct = ProductClass::addBaseData($productData);
- $ghsProductId = $addProduct->id ?? 0;
- } else {
- $ghsProductId = $ghsHasProduct[$ptItemId]['id'] ?? 0;
- }
- $list[$k]['productId'] = $ghsProductId;
- $list[$k]['hdProductId'] = $hdProductId;
- }
- return $list;
- }
- public static function addBaseData($data)
- {
- $respond = self::add($data, true);
- return $respond;
- }
- public static function adStockCheck($shop, $productList)
- {
- //阿东开5支老是会出现5扎情况跟踪
- $mainId = $shop->mainId ?? 0;
- Yii::info("mainId:" . $mainId);
- if (getenv('YII_ENV') == 'production') {
- if ($mainId != 742 && $mainId != 50) {
- return false;
- }
- } else {
- if ($mainId != 644) {
- return false;
- }
- }
- Yii::info('productList:' . json_encode($productList));
- if (!empty($productList)) {
- $adIds = [];
- foreach ($productList as $adItem) {
- if (isset($adItem['property']) && $adItem['property'] == 1 && $adItem['unitType'] == 0 && $adItem['num'] == 5) {
- $adIds[] = $adItem['productId'];
- Yii::info('productId:' . $adItem['productId']);
- }
- }
- if (!empty($adIds)) {
- $arr = self::getByIds($adIds);
- if (!empty($arr)) {
- foreach ($arr as $it) {
- Yii::info("num:" . $it['scanNum']);
- if (isset($it['scanNum']) && $it['scanNum'] > 0) {
- $name = $it['name'] ?? '';
- if (getenv('YII_ENV') == 'production') {
- if ($mainId == 742) {
- sms::freeSend('13531700113,' . $name, '刚刚,花材:{$var},5支被开成了5扎,请注意!!!');
- sms::freeSend('15220670540,' . $name, '刚刚,花材:{$var},5支被开成了5扎,请注意!!!');
- sms::freeSend('13531704009,' . $name, '刚刚,花材:{$var},5支被开成了5扎,请注意!!!');
- sms::freeSend('15766689130,' . $name, '刚刚,花材:{$var},5支被开成了5扎,请注意!!!');
- sms::freeSend('15280215347,' . $name, '刚刚,花材:{$var},5支被开成了5扎,请注意!!!');
- }
- if ($mainId == 50) {
- sms::freeSend('15280215347,' . $name, '刚刚,花材:{$var},5支被开成了5扎,请注意!!!');
- }
- } else {
- noticeUtil::push('刚刚,花材:' . $name . ',5支被开成了5扎,请注意!!!', '15280215347');
- }
- }
- }
- }
- }
- }
- }
- //花材的库存转换: 库存是小数,根据各个花材的unitNum, 计算出多少扎,多少支
- public static function formatStock($stock, $unitNum)
- {
- $pn = true; //正数
- if ($stock < 0) {
- $pn = false;
- $stock = abs($stock);
- }
- $bigNum = floor($stock); // 扎
- $stockArr = explode('.', $stock);
- $smallNum = 0; //支
- if (count($stockArr) === 2) {
- $smallNum = bcmul(($stock - $bigNum), $unitNum);
- }
- if (!$pn) {
- $bigNum *= -1;
- $smallNum *= -1;
- }
- return [
- 'bigNum' => $bigNum,
- 'smallNum' => $smallNum,
- ];
- }
- //通用花材列表数组组合
- public static function changePriceGroup($list, $level = 0)
- {
- //各个等级对应的price addPrice字段
- $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
- $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $cover = imgUtil::getPrefix() . 'hhb_small.png';
- if (!empty($shortCover)) {
- $parse = parse_url(self::groupImg($shortCover));
- if (empty($parse['query'])) {
- $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- } else {
- $cover = self::groupImg($shortCover);
- }
- }
- $list[$k]['cover'] = $cover;
- $list[$k]['prePrice'] = $v['price'] ?? 0;
- //今日特价、会员价
- $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
- if ($level == 0) {
- //零售做特价时显示的原价,不能删除
- if (isset($v['skPrice'])) {
- $list[$k]['prePrice'] = $v['skPrice'];
- }
- }
- if (isset($v['discountPrice']) && $v['discountPrice'] > 0) {
- //做特价花材时,花材列表和改价列表显示的会员价和零售价,不能删除
- $list[$k]['hjPrice'] = floatval($v['hjDiscountPrice']);
- $list[$k]['skPrice'] = floatval($v['skDiscountPrice']);
- }
- $list[$k]['price'] = $price;
- $cost = $v['cost'] ?? 0;
- $ml = 0;
- if ($price > 0) {
- $profit = bcsub($price, $cost, 2);
- $ml = $profit;
- $mll = bcdiv($profit, $price, 3);
- $mll = bcmul($mll, 100);
- $mll = round($mll, 1);
- } else {
- $mll = 0;
- }
- $list[$k]['mll'] = $mll;
- $list[$k]['ml'] = $ml;
- }
- return $list;
- }
- public static function breakItemGroup($list, $level = 0)
- {
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 20;
- $stockInfo = self::formatStock($v['stock'], $ratio);
- $list[$k]['bigNum'] = $stockInfo['bigNum'];
- $list[$k]['smallNum'] = $stockInfo['smallNum'];
- $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- }
- return $list;
- }
- public static function partItemGroup($list, $level = 0)
- {
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 20;
- $stockInfo = self::formatStock($v['stock'], $ratio);
- $list[$k]['bigNum'] = $stockInfo['bigNum'];
- $list[$k]['smallNum'] = $stockInfo['smallNum'];
- $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- }
- return $list;
- }
- public static function checkItemGroup($list, $level = 0)
- {
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
- $stockInfo = self::formatStock($v['stock'], $ratio);
- $list[$k]['bigNum'] = $stockInfo['bigNum'];
- $list[$k]['smallNum'] = $stockInfo['smallNum'];
- }
- return $list;
- }
- public static function cgItemGroup($list, $level = 0)
- {
- $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
- $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 1;
- $stockInfo = self::formatStock($v['stock'], $ratio);
- $list[$k]['bigNum'] = $stockInfo['bigNum'];
- $list[$k]['smallNum'] = $stockInfo['smallNum'];
- $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
- $list[$k]['price'] = $price;
- $list[$k]['bigPrice'] = $price;
- $smallRatio = $v['smallRatio'] ?? 0;
- $smallPrice = bcdiv($price, $ratio, 2);
- $smallPrice = bcmul($smallPrice, $smallRatio, 2);
- $list[$k]['smallPrice'] = $smallPrice;
- }
- return $list;
- }
- //通用花材列表数组组合
- public static function changeStockGroup($list, $level = 0)
- {
- //各个等级对应的price addPrice字段
- $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
- $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $cover = imgUtil::getPrefix() . 'hhb_small.png';
- if (!empty($shortCover)) {
- $parse = parse_url(self::groupImg($shortCover));
- if (empty($parse['query'])) {
- $cover = self::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- } else {
- $cover = self::groupImg($shortCover);
- }
- }
- $list[$k]['cover'] = $cover;
- $list[$k]['prePrice'] = $v['price'] ?? 0;
- //今日特价、会员价
- $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
- //零售做特价时的原价
- if ($level == 0) {
- $currentAddPrice = $v['skMore'] ?? 0;
- $list[$k]['prePrice'] = bcadd($v['price'], $currentAddPrice, 2);
- }
- if (isset($v['discountPrice']) && $v['discountPrice'] > 0) {
- $currentAddPrice = $v['skMore'] ?? 0;
- $list[$k]['skPrice'] = bcadd($v['discountPrice'], $currentAddPrice, 2);
- }
- $list[$k]['price'] = $price;
- $cost = $v['cost'] ?? 0;
- $ml = 0;
- if ($price > 0) {
- $profit = bcsub($price, $cost, 2);
- $ml = $profit;
- $mll = bcdiv($profit, $price, 3);
- $mll = bcmul($mll, 100);
- $mll = round($mll, 1);
- } else {
- $mll = 0;
- }
- $list[$k]['mll'] = $mll;
- $list[$k]['ml'] = $ml;
- }
- return $list;
- }
- public static function stockOutGroup($list, $level = 0)
- {
- //各个等级对应的price addPrice字段
- $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
- $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
- foreach ($list as $k => $v) {
- $shortCover = $v['cover'] ?? '';
- $list[$k]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- $price = \bizGhs\product\classes\ProductClass::getFinalPrice($v, $level, $priceMap, $addPriceMap);
- $list[$k]['price'] = $price;
- $list[$k]['bigPrice'] = $price;
- $smallRatio = $v['smallRatio'] ?? 0;
- $ratio = isset($v['ratio']) && $v['ratio'] > 0 ? $v['ratio'] : 20;
- $smallPrice = bcdiv($price, $ratio, 2);
- $smallPrice = bcmul($smallPrice, $smallRatio, 2);
- $list[$k]['smallPrice'] = $smallPrice;
- }
- return $list;
- }
- }
|