| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007 |
- <?php
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\item\classes\PtItemClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\product\services\ProductService;
- use bizHd\admin\classes\ShopAdminClass;
- use bizHd\item\classes\UnitChangeClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\classes\PurchaseItemClass;
- use bizHd\pictext\classes\PicTextGhsItemClass;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use yii\helpers\ArrayHelper;
- class ProductController extends BaseController
- {
- public $guestAccess = ['ghs-item', 'ghs-product-detail'];
- //复制新建花材 ssh 20250523
- public function actionClone()
- {
- $post = Yii::$app->request->post();
- $appVersion = $post['appVersion'] ?? 0;
- if ($appVersion != 1) {
- util::fail('请先升级应用');
- }
- $discountPrice = $post['discountPrice'] ?? 0;
- if ($discountPrice > 0) {
- if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
- $addPrice = $post['addPrice'] ?? 0;
- $hjAddPrice = $post['hjAddPrice'] ?? 0;
- $skMore = $post['skMore'] ?? 0;
- $diff = bcsub($addPrice, $hjAddPrice, 2);
- if ($diff > 0 && $discountPrice > $diff) {
- $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
- } else {
- $hjDiscountPrice = $discountPrice;
- }
- $diff = bcsub($skMore, $addPrice, 2);
- if ($diff > 0) {
- $skDiscountPrice = bcadd($diff, $discountPrice, 2);
- } else {
- $skDiscountPrice = $discountPrice;
- }
- $post['skDiscountPrice'] = $skDiscountPrice;
- $post['hjDiscountPrice'] = $hjDiscountPrice;
- }
- }
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('请在首店操作');
- }
- $shopAdmin = $this->shopAdmin;
- if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
- util::fail('管理员才能添加花材');
- }
- $post['sjId'] = $this->sjId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $post['staffName'] = $shopAdmin->name ?? '';
- $price = $post['price'] ?? 0;
- if (empty($price) || $price <= 0) {
- util::fail('请填写批发价');
- }
- $skPrice = $post['skPrice'] ?? 0;
- if (empty($skPrice) || $skPrice <= 0) {
- util::fail('请填写零售价');
- }
- $hjPrice = $post['hjPrice'] ?? 0;
- if (empty($hjPrice) || $hjPrice <= 0) {
- util::fail('请填写会员价');
- }
- $addPrice = $post['addPrice'] ?? 0;
- if ($addPrice > $price) {
- util::fail('批发价的加价不能大于售价');
- }
- // 图片列表数组转换为字符串
- if (is_array($post['images'])) {
- $post['images'] = implode(',', $post['images']);
- }
- //复制标识
- $post['copy'] = 1;
- //去除无用的字段
- unset($post['viewNum']);
- unset($post['actualSold']);
- unset($post['itemId']);
- unset($post['id']);
- unset($post['delStatus']);
- ProductClass::addProduct($post, $this->shop);
- util::complete('复制成功');
- }
- //花材展示状态控制 ssh 20250519
- public function actionDelStatusUpdate()
- {
- $post = Yii::$app->request->post();
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('请在首店操作');
- }
- $id = $post['id'] ?? 0;
- $delStatus = $post['delStatus'] ?? 0;
- $product = ProductClass::getById($id, true);
- if ($product->mainId != $this->mainId) {
- util::fail('不是你的花材哦!!');
- }
- //扫码收款、直接收款和特价商品,不可删除,多处要同步修改 system_item
- if (getenv('YII_ENV') == 'production') {
- $systemItem = [78076, 80960, 81004];
- $adminList = [4, 1960];
- } else {
- $systemItem = [11157, 11156, 11158];
- $adminList = [919, 932];
- }
- if (in_array($product->itemId, $systemItem)) {
- $adminId = $this->adminId;
- if (!in_array($adminId, $adminList)) {
- util::fail('系统花材,不可删除');
- }
- }
- $product->delStatus = $delStatus;
- if ($delStatus == 1) {
- $product->stock = 0;
- $product->status = 2;
- }
- $product->save();
- $ptItemId = $product->itemId ?? 0;
- if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- //总店修改同步到所有门店
- $sjId = $shop->sjId ?? 0;
- $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
- foreach ($chainShopList as $chainShop) {
- $chainShopId = $chainShop->id ?? 0;
- if (isset($chainShop->join) && $chainShop->join == 1) {
- continue;
- }
- if ($chainShopId == $shop->id) {
- continue;
- }
- $chainMainId = $chainShop->mainId ?? 0;
- $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
- if (!empty($chainProduct)) {
- $chainProduct->delStatus = $delStatus;
- if ($delStatus == 1) {
- $chainProduct->stock = 0;
- $chainProduct->status = 2;
- }
- $chainProduct->save();
- }
- }
- }
- util::complete();
- }
- //打印花材的标签 ssh 20220602
- public function actionPrint()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $num = $get['num'] ?? 1;
- $num = floatval($num);
- $num = (int)$num;
- $type = $get['type'] ?? 0;
- $info = ProductClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到花材');
- }
- $name = $info->name ?? '';
- $ptItemId = $info->itemId ?? 0;
- $mainId = $info->mainId ?? 0;
- $shopId = $this->shopId;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($ext)) {
- util::fail('没有找到门店信息');
- }
- $printLabelSn = $ext->printLabelSn ?? '';
- if (empty($printLabelSn)) {
- util::fail('请设置标签打印机');
- }
- $p = new printUtil($printLabelSn);
- $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
- if (isset($info->ratioType) && $info->ratioType == 1) {
- $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
- }
- $p->times = $num;
- if (stringUtil::getWordNum($name) > 8) {
- $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
- } else {
- $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
- }
- if ($type == 0) {
- //打标签
- $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
- if (in_array($mainId, [52, 1459])) {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
- } elseif ($mainId == 16948) {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里鲜花</TEXT>';
- } else {
- $content .= '<TEXT x="30" y="250" font="12" w="1" h="1" r="0">' . $unit . '</TEXT>';
- }
- } else {
- if (getenv('YII_ENV') == 'production') {
- $doublePrice = [52, 1459];
- } else {
- $doublePrice = [];
- }
- if (in_array($this->mainId, $doublePrice)) {
- //打价格,显示正价和会员价
- $price = $info->skPrice ?? 0;
- $price = floatval($price);
- $hyPrice = $info->price ?? 0;
- $hyPrice = floatval($hyPrice);
- $content .= '<TEXT x="35" y="90" font="12" w="2" h="2" r="0">----------</TEXT>';
- $content .= '<TEXT x="35" y="150" font="12" w="2" h="2" r="0">正价 ' . $price . '元</TEXT>';
- $content .= '<TEXT x="35" y="230" font="12" w="2" h="2" r="0">会员价 ' . $hyPrice . '元</TEXT>';
- } else {
- //打价格,显示零售价,并且不带元,杭州斗南鲜花不要带元
- $price = $info->skPrice ?? 0;
- $price = floatval($price);
- $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '</TEXT>';
- }
- }
- $p->printLabelMsg($content);
- util::complete();
- }
- //新增花材 20250523 ssh
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $discountPrice = $post['discountPrice'] ?? 0;
- if ($discountPrice > 0) {
- if (empty($post['hjDiscountPrice'])) {
- $addPrice = $post['addPrice'] ?? 0;
- $hjAddPrice = $post['hjAddPrice'] ?? 0;
- $skMore = $post['skMore'] ?? 0;
- $diff = bcsub($addPrice, $hjAddPrice, 2);
- if ($diff > 0 && $discountPrice > $diff) {
- $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
- } else {
- $hjDiscountPrice = $discountPrice;
- }
- $diff = bcsub($skMore, $addPrice, 2);
- if ($diff > 0) {
- $skDiscountPrice = bcadd($diff, $discountPrice, 2);
- } else {
- $skDiscountPrice = $discountPrice;
- }
- $post['skDiscountPrice'] = $skDiscountPrice;
- $post['hjDiscountPrice'] = $hjDiscountPrice;
- }
- }
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('当前直营分店,请切回总店添加花材');
- }
- $shopAdmin = $this->shopAdmin;
- if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
- util::fail('管理员才能添加花材');
- }
- $post['sjId'] = $this->sjId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $price = $post['price'] ?? 0;
- $addPrice = $post['addPrice'] ?? 0;
- if ($addPrice > $price) {
- util::fail('加价不能大于售价');
- }
- $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
- if ($weight <= 0) {
- util::fail('请填写重量,最小0.1');
- }
- $post['staffName'] = $shopAdmin->name ?? '';
- // 图片列表数组转换为字符串
- if (is_array($post['images'])) {
- $post['images'] = implode(',', $post['images']);
- }
- ProductClass::addProduct($post, $this->shop);
- util::complete('添加成功');
- }
- //获取拼音缩写 ssh 20210707
- public function actionPy()
- {
- $name = Yii::$app->request->get('name');
- $py = stringUtil::py($name);
- util::success(['py' => $py]);
- }
- //所有花材
- public function actionAll()
- {
- $where = [];
- $where['mainId'] = $this->mainId;
- $classId = Yii::$app->request->get('classId', 0);
- if (!empty($classId)) {
- $where['classId'] = $classId;
- }
- $status = Yii::$app->request->get('status', 0);
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $delStatus = Yii::$app->request->get('delStatus', 0);
- if ($delStatus != 2) {
- $where['delStatus'] = $delStatus;
- }
- //零售价
- $level = 0;
- $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
- $data = ProductClass::groupProductInfo($data, $level);
- util::success(['list' => $data]);
- }
- public function actionIndex()
- {
- $py = Yii::$app->request->get('py', '');
- //默认显示上架商品
- $status = Yii::$app->request->get('status', 1);
- //默认显示未删除商品
- $delStatus = Yii::$app->request->get('delStatus', 0);
- //获取所有当前供货商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- //中央ID
- $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
- $where['mainId'] = $this->mainId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $where['delStatus'] = $delStatus;
- $level = 0;
- $field = 'id,cover,name,cost,itemId,classId,property,skPrice,skMore,addPrice,variety,price,discountPrice,skDiscountPrice,stock,stockWarning,presell,ratioType,smallRatio,smallUnit,bigUnit,ratio,actualSold';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
- $respond = ProductService::assembleData($classIds, $itemInfoData, true);
- $classItem = $respond['classItem'] ?? [];
- util::success($classItem);
- }
- //当前门店所有花材分类
- public function actionList()
- {
- $classId = Yii::$app->request->get('classId', 0);
- $pyName = Yii::$app->request->get('py', '');
- if ($pyName) {
- $pyName = strtolower($pyName);
- $where['py'] = $pyName;
- }
- $where['mainId'] = $this->mainId;
- if (!empty($classId)) {
- $where['classId'] = $classId;
- }
- $type = Yii::$app->request->get('type', '');
- $showPage = Yii::$app->request->get('showPage', 0);
- //需要显示分页
- if ($showPage) {
- $respond = ProductClass::getList("*", $where, "inTurn desc");
- $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
- $respond['list'] = ProductClass::groupProductInfo($respond['list']);
- util::success($respond);
- }
- $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
- $data = ProductClass::groupProductInfo($data);
- if ($type == 'waring') {
- //库存预警
- $newData = [];
- foreach ($data as $v) {
- if ($v['stock'] <= $v['stockWarning']) {
- $newData[] = $v;
- }
- }
- util::success(['list' => $newData]);
- }
- util::success(['list' => $data]);
- }
- //批量改价
- public function actionBatchChangePrice()
- {
- $shop = $this->shop ?? [];
- $shopId = $shop->id ?? 0;
- $default = $shop->default ?? 0;
- $join = $shop->join ?? 0;
- $shopAdmin = $this->shopAdmin;
- $adminId = $this->adminId ?? 0;
- //normal常规改价,cg采购改价
- $changeType = Yii::$app->request->post('changeType', 'normal');
- $doType = Yii::$app->request->post('doType', 0);
- if ($changeType == 'cg' && $doType == 0) {
- if (getenv('YII_ENV') == 'production') {
- //小蔡鲜花的几个分店的零售店不能修改价格
- if (in_array($shopId, [29153, 29155, 29157, 29162, 29164])) {
- util::fail('本店不能改价哦');
- }
- } else {
- if (in_array($shopId, [36545])) {
- util::fail('本店无法改价哈');
- }
- }
- }
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- if ($join == 0 && $default == 0) {
- //util::fail('当前直营分店,只能回总店修改价格');
- }
- $targetId = Yii::$app->request->post('targetId', 0);
- $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
- $post = Yii::$app->request->post();
- $data = $post['data'] ?? '';
- if (empty($data)) {
- util::fail('没有修改');
- }
- $arr = json_decode($data, true);
- if (empty($arr)) {
- util::fail('没有修改!');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- if ($doType == 0 || $doType == 1) {
- $cg = PurchaseClass::getLockById($targetId);
- if (!empty($cg)) {
- if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
- util::fail('不是您的采购单');
- }
- if ($cg->status == PurchaseClass::STATUS_UN_SEND && $cg->book == 1) {
- util::fail('预订单只有发货后,才能确认收货');
- }
- //没有发货则先发货
- if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
- $cg = PurchaseClass::orderSend($cg, [], true);
- }
- //确认收货并入库
- if ($cg->status == PurchaseClass::STATUS_SENDING) {
- // 构建“冲销”函数的参数 -- 变动前的花材存库数据
- $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
- $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
- $oldStocks = [];
- foreach ($productIds as $productId) {
- $product = ProductClass::getById($productId, true);
- $oldStocks[$productId] = $product;
- }
- PurchaseClass::takeToPutIn($cg);
- // “冲销”本次入库的数量
- PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $this->mainId, $this->shopAdmin->name);
- if ($doType == 1) {
- $transaction->commit();
- util::complete('入库成功');
- }
- } else {
- util::fail('订单不是待入库状态');
- }
- } else {
- if ($doType == 1) {
- util::fail('入库失败,没有找到采购单');
- }
- }
- }
- $ids = array_column($arr, 'id');
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $sjId = $shop->sjId ?? 0;
- $chainShopList = [];
- if ($default == 1) {
- $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
- }
- $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
- foreach ($arr as $product) {
- if (isset($product['price']) == false) {
- util::fail('没有价格');
- }
- if (isset($product['id']) == false) {
- util::fail('没有花材');
- }
- $price = $product['price'];
- $productId = $product['id'];
- $productInfo = $productList[$productId] ?? [];
- if (empty($productInfo)) {
- util::fail('没有找到花材');
- }
- $productName = $productInfo->name ?? '';
- if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
- util::fail('请填写' . $productName . '的批发价');
- }
- if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
- util::fail('请填写' . $productName . '的零售价');
- }
- $skPrice = $product['skPrice'];
- if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
- util::fail('请填写' . $productName . '的会员价');
- }
- $hjPrice = $product['hjPrice'] ?? 0;
- if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
- util::fail('无法访问');
- }
- if ($hjPrice > $price) {
- util::fail($productName . ' 批发价要大于会员价');
- }
- if ($price > $skPrice) {
- util::fail($productName . ' 零售价要大于批发价');
- }
- $ptItemId = $productInfo->itemId;
- ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
- //在首店修改需要同步到所有直营店
- if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- foreach ($chainShopList as $chain) {
- if ($chain->id == $shop->id) {
- continue;
- }
- $chainMainId = $chain->mainId ?? 0;
- $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
- $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
- ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
- }
- }
- }
- $mainId = $shop->mainId ?? 0;
- if (!empty($mainId)) {
- //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
- $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($staffList)) {
- foreach ($staffList as $staff) {
- $staffId = $staff->id ?? 0;
- Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
- Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
- }
- }
- }
- $transaction->commit();
- util::complete('操作成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- //从零售端采购入库,查看供货商的某个门店的product
- public function actionGhsItem()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghs = GhsClass::getGhsInfo($id);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $shopId = $ghs['shopId'] ?? 0;
- $black = $ghs['black'] ?? 2;
- if ($black == 2) {
- util::fail('暂无花材');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //获取所有当前供货商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- $shop = ShopClass::getById($shopId, true);
- $mainId = $shop->mainId ?? 0;
- $classIds = ItemClassClass::getGhsItemClassAll($mainId);
- $where['mainId'] = $mainId;
- $where['delStatus'] = 0;
- //是否显示全部花材,包括下架的
- $showAll = $get['showAll'] ?? 0;
- if ($showAll == 0) {
- $where['status'] = 1;
- }
- $where['frontHide'] = 0;
- $level = $ghs['giveLevel'] ?? 1;
- $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount,limitBuy';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
- $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
- if (!empty($itemInfoData)) {
- $myShop = $this->shop;
- $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
- foreach ($itemInfoData as $key => $val) {
- $ptItemId = $val['itemId'] ?? 0;
- $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
- $myStock = floatval($myStock);
- $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
- $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
- $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
- $itemInfoData[$key]['myStock'] = $myStock;
- $itemInfoData[$key]['myOnStock'] = $myOnStock;
- $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
- $itemInfoData[$key]['myLack'] = $myLack;
- $itemInfoData[$key]['myDisplay'] = $myDisplay;
- }
- }
- $respond = ProductService::assembleData($classIds, $itemInfoData, true);
- $classItem = $respond['classItem'] ?? [];
- util::success($classItem);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("报错内容:" . $e->getMessage());
- util::fail();
- }
- }
- public function actionGhsItemV2()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghs = GhsClass::getGhsInfo($id);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $shopId = $ghs['shopId'] ?? 0;
- $black = $ghs['black'] ?? 2;
- if ($black == 2) {
- util::fail('暂无花材');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //获取所有当前供货商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- $shop = ShopClass::getById($shopId, true);
- $mainId = $shop->mainId ?? 0;
- $open = $shop->open ?? 1;
- $openStartTime = $shop->openStartTime;
- $openEndTime = $shop->openEndTime;
- if (!empty($openStartTime) && !empty($openEndTime)) {
- $date = date('Y-m-d');
- $openStartDate = $date . ' ' . $openStartTime;
- $openEndDate = $date . ' ' . $openEndTime;
- $startTime = strtotime($openStartDate);
- $endTime = strtotime($openEndDate);
- $currentTime = time();
- if ($currentTime < $startTime || $currentTime > $endTime) {
- $open = 0;
- }
- }
- if ($open == 0) {
- if (getenv('YII_ENV') == 'production') {
- //九江云朵、丽子鲜花、沈阳市云花鲜花,休店不让看花材
- if (in_array($mainId, [26374, 1496, 67094])) {
- util::fail('已休店');
- }
- } else {
- if (in_array($mainId, [644, 1])) {
- util::fail('已休店');
- }
- }
- }
- $classIds = ItemClassClass::getGhsItemClassAll($mainId);
- $where['mainId'] = $mainId;
- $where['delStatus'] = 0;
- //是否显示全部花材,包括下架的
- $showAll = $get['showAll'] ?? 0;
- if ($showAll == 0) {
- $where['status'] = 1;
- }
- $where['frontHide'] = 0;
- $level = $ghs['giveLevel'] ?? 1;
- $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount,limitBuy';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level);
- $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
- if (!empty($itemInfoData)) {
- $myShop = $this->shop;
- $myDisplay = 0;
- if (isset($myShop->pfShopId) && $myShop->pfShopId > 0) {
- $myDisplay = 1;
- }
- foreach ($itemInfoData as $key => $val) {
- $ptItemId = $val['itemId'] ?? 0;
- $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
- $myStock = floatval($myStock);
- $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
- $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
- $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
- $itemInfoData[$key]['myStock'] = $myStock;
- $itemInfoData[$key]['myOnStock'] = $myOnStock;
- $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
- $itemInfoData[$key]['myLack'] = $myLack;
- $itemInfoData[$key]['myDisplay'] = $myDisplay;
- }
- }
- $respond = ProductService::assembleData($classIds, $itemInfoData, true);
- if ($showAll == 1) {
- if (isset($respond['classItem']) && !empty($respond['classItem'])) {
- foreach ($respond['classItem'] as $bigKey => $bigVal) {
- if (isset($bigVal['child']) && !empty($bigVal['child'])) {
- foreach ($bigVal['child'] as $key => $val) {
- unset($bigVal['child'][$key]['cover']);
- unset($bigVal['child'][$key]['actualSold']);
- unset($bigVal['child'][$key]['defaultGradePrice']);
- unset($bigVal['child'][$key]['discountPrice']);
- unset($bigVal['child'][$key]['hjDiscountPrice']);
- unset($bigVal['child'][$key]['hjPrice']);
- unset($bigVal['child'][$key]['presellDateShow']);
- unset($bigVal['child'][$key]['prePrice']);
- unset($bigVal['child'][$key]['print']);
- unset($bigVal['child'][$key]['reachNum']);
- unset($bigVal['child'][$key]['reachNumDiscount']);
- unset($bigVal['child'][$key]['reachPrice']);
- unset($bigVal['child'][$key]['skDiscountPrice']);
- unset($bigVal['child'][$key]['skPrice']);
- unset($bigVal['child'][$key]['bigUnit']);
- unset($bigVal['child'][$key]['weight']);
- unset($bigVal['child'][$key]['stockWarning']);
- //unset($bigVal['child'][$key]['smallPrice']);
- //unset($bigVal['child'][$key]['smallRatio']);
- }
- $respond['classItem'][$bigKey]['child'] = $bigVal['child'];
- }
- }
- }
- }
- util::success($respond);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("报错内容:" . $e->getMessage());
- util::fail();
- }
- }
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $respond = ProductClass::getItemInfo($id);
- $ptItemId = $respond['itemId'] ?? 0;
- $ptItemInfo = PtItemClass::getById($ptItemId);
- $respond['ptItemInfo'] = $ptItemInfo;
- // 封面图与多花材图片的兼容处理
- if ($respond['images'] == '' && $respond['shortCover'] != '') {
- $respond['images'] = $respond['shortCover'];
- }
- //查出拆散的子花材
- $part = UnitChangeClass::getByCondition(['big' => $id], true);
- $partAcceptItem = 0;
- $partAcceptItemName = '';
- if (!empty($part)) {
- $partAcceptItem = $part->small;
- $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
- $partAcceptItemName = $small->name ?? '';;
- }
- $respond['partAcceptItem'] = $partAcceptItem;
- $respond['partAcceptItemName'] = $partAcceptItemName;
- util::success($respond);
- }
- public function actionUpdate()
- {
- $shopAdmin = $this->shopAdmin;
- if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
- if ($shopAdmin->super != 1) {
- util::fail('请先开通超管权限');
- }
- }
- $deadline = $shop->deadline;
- $deadTime = strtotime($deadline);
- if (time() > $deadTime) {
- util::fail('系统已到期,编号563');
- }
- $post = Yii::$app->request->post();
- $discountPrice = $post['discountPrice'] ?? 0;
- if ($discountPrice > 0) {
- if (empty($post['hjDiscountPrice'])) {
- $addPrice = $post['addPrice'] ?? 0;
- $hjAddPrice = $post['hjAddPrice'] ?? 0;
- $skMore = $post['skMore'] ?? 0;
- $diff = bcsub($addPrice, $hjAddPrice, 2);
- if ($diff > 0 && $discountPrice > $diff) {
- $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
- } else {
- $hjDiscountPrice = $discountPrice;
- }
- $diff = bcsub($skMore, $addPrice, 2);
- if ($diff > 0) {
- $skDiscountPrice = bcadd($diff, $discountPrice, 2);
- } else {
- $skDiscountPrice = $discountPrice;
- }
- $post['skDiscountPrice'] = $skDiscountPrice;
- $post['hjDiscountPrice'] = $hjDiscountPrice;
- }
- $reachNum = $post['reachNum'] ?? 0;
- $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
- if ($reachNum > 0 && $reachNumDiscount > 0) {
- util::fail('特价和满减不能同时进行');
- }
- }
- $post['adminId'] = $this->adminId;
- $post['staffId'] = $this->shopAdmin->id;
- $post['staffName'] = $this->shopAdmin->name;
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- ProductClass::updateProduct($post, $this->shop);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- Yii::info("操作失败:" . $e->getMessage());
- $transaction->rollBack();
- util::fail('操作失败');
- }
- }
- //批量修改product 排序,成本价,加价
- public function actionBatchUpdate()
- {
- //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
- $data = Yii::$app->request->post('data', '');
- $type = Yii::$app->request->post('type', '');
- if (empty($data) || empty($type)) {
- util::fail("参数错误");
- }
- if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
- $data = json_decode($data, true);
- foreach ($data as $v) {
- $id = $v['id'];
- $val = $v[$type] ?? '';
- $where = [];
- $where['id'] = $id;
- $where['shopId'] = $this->shopId;
- $where['sjId'] = $this->sjId;
- if (empty($val)) {
- util::fail("参数错误1");
- }
- $data = [
- $type => $val
- ];
- ProductClass::updateByCondition($where, $data);
- ProductClass::autoPriceById($id);
- }
- util::complete();
- }
- //供货商产品的详情 ssh 20230111
- public function actionGhsProductDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghsId = $get['ghsId'] ?? 0;
- $product = ProductClass::getById($id);
- if (empty($product)) {
- util::fail('没有花材信息');
- }
- $ghsInfo = GhsClass::getById($ghsId, true, 'giveLevel');
- $level = isset($ghsInfo->giveLevel) ? $ghsInfo->giveLevel : 1;
- $list = ProductClass::groupProductInfo([$product], $level);
- $product = current($list);
- $mainId = $product['mainId'] ?? 0;
- $pixTextGoods = PicTextGhsItemClass::getByCondition(['mainId' => $mainId, 'ghsItemId' => $id], true);
- $product['picTextGoods'] = $pixTextGoods;
- // 封面图与多花材图片的兼容处理
- if ($product['images'] == '' && $product['shortCover'] != '') {
- $product['images'] = $product['shortCover'];
- }
- util::success($product);
- }
- //批量修改加价 ssh 20211211
- public function actionBatchChangeAddPrice()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $shop = $this->shop;
- $pfShopId = $shop->pfShopId ?? 0;
- if (!empty($pfShopId)) {
- util::fail('请在批发端操作');
- }
- $addData = Yii::$app->request->post('addData', '');
- if (empty($addData)) {
- util::fail('没有花材');
- }
- $itemData = json_decode($addData, true);
- if (is_array($itemData) == false) {
- util::fail('没有花材...');
- }
- $ids = array_column($itemData, 'id');
- $infoList = ProductClass::getByIds($ids);
- if (empty($infoList)) {
- util::fail('没有花材');
- }
- foreach ($infoList as $info) {
- if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
- util::fail('非常访问,不是你的花材不能修改');
- }
- }
- foreach ($itemData as $key => $data) {
- $id = $data['id'] ?? 0;
- ProductClass::updateById($id, $data);
- }
- util::complete('修改成功');
- }
- //修改拆散接收的花材 ssh 20251124
- public function actionModifyPartAcceptItem()
- {
- $get = Yii::$app->request->get();
- $smallId = $get['small'] ?? 0;
- $bigId = $get['big'] ?? 0;
- $small = ProductClass::getById($smallId, true);
- if (empty($small)) {
- util::fail('子花材没找到');
- }
- $smallName = $small->name ?? '';
- if ($small->mainId != $this->mainId) {
- util::fail($smallName . '不是你的花材');
- }
- if ($small->ratio != 1) {
- util::fail($smallName . '不是1支装的');
- }
- $big = ProductClass::getById($bigId, true);
- if (empty($big)) {
- util::fail('没有找到花材');
- }
- if ($big->mainId != $this->mainId) {
- util::fail('不是你的花材呢');
- }
- $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
- if (empty($change)) {
- UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
- } else {
- $change->small = $smallId;
- $change->save();
- }
- util::complete('修改成功');
- }
- public function actionCancelDiscount()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = ProductClass::getById($id, true);
- ProductClass::check($info, $this->mainId);
- $info->discountPrice = 0;
- $info->skDiscountPrice = 0;
- $info->hjDiscountPrice = 0;
- $info->save();
- util::complete('取消成功');
- }
- }
|