| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300 |
- <?php
- namespace ghs\controllers;
- use biz\item\classes\PtItemClass;
- use biz\item\classes\UnitClass;
- use biz\shop\classes\ShopExtClass;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use common\components\arrayUtil;
- use bizGhs\pictext\classes\PicTextGhsItemClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\noticeUtil;
- use common\components\stringUtil;
- use common\components\util;
- use bizGhs\product\classes\ProductClass;
- use bizHd\wx\classes\WxOpenClass;
- use Yii;
- class ItemController extends BaseController
- {
- //花材已购客户列表 ssh 20250710
- public function actionHasLimitBuyCustomList()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $customList = ProductClass::getHasLimitBuyList($item);
- util::success(['customList' => $customList]);
- }
- //清空单个客户的已购 ssh 20250710
- public function actionClearOneLimitBuy()
- {
- $get = Yii::$app->request->get();
- $productId = $get['productId'] ?? '';
- $customId = $get['customId'] ?? 0;
- $item = ItemClass::getById($productId, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户');
- }
- ProductClass::baseClearLimitBuy($productId, $customId);
- util::complete('清除成功');
- }
- //取消花材全部客户的已限数,重新开始计算
- public function actionClearLimitBuy()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- ProductClass::cancelLimitBuy($id);
- util::complete('清除成功');
- }
- public function actionModifyWeight()
- {
- $shop = $this->shop;
- if ($shop->default == 0) {
- util::fail('请在总店(首店)修改');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $weight = $get['weight'] ?? 1;
- if ($weight <= 0) {
- util::fail('重量不能小于0');
- }
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $adminId = $this->adminId;
- $ptItemId = $item->itemId ?? 0;
- $respond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
- $hasRightChange = $respond['hasRightChange'];
- if ($hasRightChange == 0) {
- util::fail('不能修改');
- }
- $ptItem = PtItemClass::getById($ptItemId, true);
- if (empty($ptItem)) {
- util::fail('花材信息缺失');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $ptItem->weight = $weight;
- $ptItem->save();
- ItemClass::updateByCondition(['itemId' => $ptItemId], ['weight' => $weight]);
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("修改失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- public function actionModifyRatio()
- {
- $shop = $this->shop;
- if ($shop->default == 0) {
- util::fail('请在总店(首店)修改');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $ratio = $get['ratio'] ?? 20;
- if ($ratio < 1) {
- util::fail('单位比不能小于1');
- }
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $adminId = $this->adminId;
- $ptItemId = $item->itemId ?? 0;
- $respond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
- $hasRightChange = $respond['hasRightChange'];
- if ($hasRightChange == 0) {
- util::fail('不能修改');
- }
- $ptItem = PtItemClass::getById($ptItemId, true);
- if (empty($ptItem)) {
- util::fail('花材信息缺失');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $ptItem->ratio = $ratio;
- $ptItem->save();
- ItemClass::updateByCondition(['itemId' => $ptItemId], ['ratio' => $ratio]);
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("修改失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- public function actionModifyUnit()
- {
- $shop = $this->shop;
- if ($shop->default == 0) {
- util::fail('请在总店(首店)修改');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $unitId = $get['unitId'] ?? 1;
- $unit = UnitClass::getById($unitId, true);
- $type = $get['type'] ?? 'big';
- if (empty($unit)) {
- util::fail('没有找到单位');
- }
- $unitName = $unit->name;
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $adminId = $this->adminId;
- $ptItemId = $item->itemId ?? 0;
- $respond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
- $hasRightChange = $respond['hasRightChange'];
- if ($hasRightChange == 0) {
- util::fail('不能修改');
- }
- $ptItem = PtItemClass::getById($ptItemId, true);
- if (empty($ptItem)) {
- util::fail('花材信息缺失');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- if ($type == 'big') {
- $ptItem->bigUnit = $unitName;
- $ptItem->bigUnitId = $unitId;
- $ptItem->save();
- ItemClass::updateByCondition(['itemId' => $ptItemId], ['bigUnit' => $unitName, 'bigUnitId' => $unitId]);
- } else {
- $ptItem->smallUnit = $unitName;
- $ptItem->smallUnitId = $unitId;
- $ptItem->save();
- ItemClass::updateByCondition(['itemId' => $ptItemId], ['smallUnit' => $unitName, 'smallUnitId' => $unitId]);
- }
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("修改失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- //挪到处理区 ssh 20250418
- public function actionMoveToLosing()
- {
- //避免重复提交
- util::checkRepeatCommit($this->adminId, 4);
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $num = $get['num'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- if ($num <= 0) {
- util::fail('请输入数量');
- }
- $remark = '挪到处理区';
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $staffId = $staff->id;
- $adminId = $this->adminId;
- $params = [
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'adminId' => $adminId,
- 'remark' => $remark,
- ];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- ItemClass::moveLose($item, $num, $shop, $params);
- $transaction->commit();
- util::complete('挪动成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("挪动失败原因:" . $e->getMessage());
- util::fail('挪动失败');
- }
- }
- //设为处理区用的花材 ssh 20250418
- public function actionSetLosing()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $shopAdmin = $this->shopAdmin;
- if ($shopAdmin->founder == 1) {
- util::fail('请用超管手机操作');
- }
- $shopId = $this->shopId;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (empty($ext)) {
- util::fail('设置失败,没有找到门店信息');
- }
- $ext->losingItem = $id;
- $ext->save();
- util::complete('设置成功');
- }
- //增加和减少半扎 ssh 20250417
- public function actionChangeHalf()
- {
- util::fail('此功能已停用');
- $post = Yii::$app->request->post();
- $productId = $post['productId'] ?? '';
- $add = $post['add'] ?? 0;
- $remark = $post['remark'] ?? '';
- $product = ProductClass::getLockById($productId);
- if (empty($product)) {
- util::fail('没有找到花材');
- }
- if ($product->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- if ($product->ratioType == 1) {
- util::fail('若干扎的花材不能减半份');
- }
- //避免重复提交
- util::checkRepeatCommit($this->adminId, 4);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $staffId = $staff->id;
- $adminId = $this->adminId;
- $params = [
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'adminId' => $adminId,
- 'remark' => $remark,
- ];
- ItemClass::modifyHalf($shop, $product, $params, $add);
- $product = ProductClass::getLockById($productId);
- $stock = $product->stock;
- $stock = floatval($stock);
- $transaction->commit();
- util::success(['stock' => $stock]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("加减半份失败原因:" . $e->getMessage());
- util::fail('加减半份失败');
- }
- }
- //修改一个花材的采购人 ssh 20240719
- public function actionModifyCgStaff()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $staffId = $get['staffId'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $staff = ShopAdminClass::getById($staffId, true);
- if (empty($staff) || $staff->mainId != $this->mainId) {
- util::fail('不是你的员工');
- }
- $staffName = $staff->name ?? '';
- $item->cgStaffId = $staffId;
- $item->cgStaffName = $staffName;
- $item->save();
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (!empty($bookSn)) {
- BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $id], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
- }
- util::complete('修改成功');
- }
- //获取花材最新信息,库存 ssh 20240318
- public function actionGetNewInfo()
- {
- $post = Yii::$app->request->post();
- $str = $post['data'] ?? '';
- if (empty($str)) {
- util::fail('请传花材信息');
- }
- $arr = json_decode($str, true);
- if (empty($arr)) {
- util::fail('请传花材信息哈');
- }
- $ids = array_column($arr, 'productId');
- $list = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,stock,mainId', 'id', true);
- if (!empty($list)) {
- foreach ($list as $item) {
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- }
- }
- util::success(['list' => $list]);
- }
- //列出所有花材 ssh 20240222
- public function actionGetItemList()
- {
- $get = Yii::$app->request->get();
- $search = $get['search'] ?? '';
- $requestType = $get['requestType'] ?? 'kd';
- $classId = $get['classId'] ?? 0;
- $lookStock = $get['lookStock'] ?? 0;
- $where['mainId'] = $this->mainId;
- if ($requestType == 'kd') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } elseif ($requestType == 'itemList') {
- $where['delStatus'] = 0;
- if ($lookStock == 1) {
- $where['stock>'] = 0;
- }
- if ($lookStock == 2) {
- $where['stock'] = 0;
- }
- unset($where['status']);
- } elseif ($requestType == 'changePrice') {
- $where['delStatus'] = 0;
- $where['stock>'] = 0;
- } elseif ($requestType == 'hasStockList') {
- $where['delStatus'] = 0;
- $where['stock>'] = 0;
- } elseif ($requestType == 'book') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'outList') {
- $where['delStatus'] = 0;
- $where['status'] = 2;
- $where['removeStatus'] = 0;
- } elseif ($requestType == 'stopList') {
- $where['delStatus'] = 1;
- unset($where['status']);
- $where['removeStatus'] = 0;
- } elseif ($requestType == 'removeList') {
- $where['delStatus'] = 1;
- unset($where['status']);
- $where['removeStatus'] = 1;
- } elseif ($requestType == 'cg') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'changeStock') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'check') {
- $where['delStatus'] = 0;
- unset($where['status']);
- } elseif ($requestType == 'stockOut') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } elseif ($requestType == 'break') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } elseif ($requestType == 'part') {
- $where['delStatus'] = 0;
- $where['status'] = 1;
- } else {
- util::fail('没有定义的请求方式');
- }
- if (!empty($search)) {
- if (stringUtil::isLetter($search)) {
- $search = strtolower($search);
- $where['py'] = ['like', $search];
- } else {
- $where['name'] = ['like', $search];
- }
- } else {
- if (!empty($classId)) {
- if ($classId == -1) {
- $where['discountPrice>'] = 0;
- } elseif ($classId == -2) {
- $where['reachNum>'] = 0;
- } elseif ($classId == -3) {
- $where['presell'] = 1;
- } else {
- $where['classId'] = $classId;
- }
- }
- }
- $customId = $get['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (!empty($custom)) {
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户');
- }
- }
- $level = $custom->level ?? 1;
- $field = '*';
- //只查我负责的花材
- $globalCgMyCharge = $get['globalCgMyCharge'] ?? 0;
- $needCgList = [];
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- if (!empty($bookSn)) {
- $biList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
- if (!empty($biList)) {
- $myIds = [];
- foreach ($biList as $biInfo) {
- $biProductId = $biInfo->itemId ?? 0;
- if ($biInfo->needCgNum > 0) {
- $myIds[] = $biProductId;
- $needCgList[$biProductId] = $biInfo->needCgNum;
- }
- }
- if ($globalCgMyCharge == 1) {
- if (!empty($myIds)) {
- $where['id'] = ['in', $myIds];
- } else {
- $where['id'] = ['in', [0]];
- }
- }
- } else {
- if ($globalCgMyCharge == 1) {
- $where['id'] = ['in', [0]];
- }
- }
- }
- $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
- $list = $result['list'] ?? [];
- if ($requestType == 'hasStockList') {
- util::fail('无效方式');
- } elseif ($requestType == 'changePrice') {
- $list = ProductClass::changePriceGroup($list, $level);
- } elseif ($requestType == 'changeStock') {
- $list = ProductClass::changeStockGroup($list, $level);
- } elseif ($requestType == 'kd') {
- $list = ProductClass::kdItemGroup($list, $level);
- } elseif ($requestType == 'book') {
- $list = ProductClass::bookItemGroup($list, $level);
- } elseif ($requestType == 'itemList') {
- $list = ProductClass::itemListGroup($list, $level);
- } elseif ($requestType == 'outList') {
- $list = ProductClass::simpleGroup($list, $level);
- } elseif ($requestType == 'stopList') {
- $list = ProductClass::simpleGroup($list, $level);
- } elseif ($requestType == 'removeList') {
- $list = ProductClass::simpleGroup($list, $level);
- } elseif ($requestType == 'check') {
- $list = ProductClass::checkItemGroup($list, $level);
- } elseif ($requestType == 'break') {
- $list = ProductClass::breakItemGroup($list, $level);
- } elseif ($requestType == 'part') {
- $list = ProductClass::partItemGroup($list, $level);
- } elseif ($requestType == 'stockOut') {
- $list = ProductClass::stockOutGroup($list, $level);
- } elseif ($requestType == 'cg') {
- $list = ProductClass::cgItemGroup($list, $level);
- } elseif ($requestType == 'warning') {
- util::fail('无效方式');
- // $itemInfoData = Product::find()->where("mainId={$this->mainId}")
- // ->andWhere('`stock`+`onStock`<`stockWarning`')
- // ->andWhere("delStatus=0")
- // ->select($field)->asArray()->all();
- // $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
- } else {
- util::fail('没有数据');
- }
- if (!empty($needCgList)) {
- //采购人采自己花材需要知道要采多少
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $productId = $val['id'] ?? 0;
- if (isset($needCgList[$productId])) {
- $needCgNum = $needCgList[$productId];
- $list[$key]['needCgNum'] = $needCgNum;
- }
- }
- }
- }
- if (!empty($list) && $classId == -1) {
- //限购的排在最前面,多处同步修改limit_ahead
- $list = arrayUtil::arraySort($list, 'limitBuy');
- }
- $result['list'] = $list;
- util::success($result);
- }
- //花材申请平台认证 ssh 20231125
- public function actionApplyAuth()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = ItemClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到花材');
- }
- if ($info->mainId != $this->mainId) {
- util::fail('不是你的花材哦');
- }
- $shop = $this->shop;
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $ptItemId = $info->itemId ?? 0;
- $ptItem = PtItemClass::getById($ptItemId, true);
- if (empty($ptItem)) {
- util::fail('没有找到平台花材');
- }
- $ptItemName = $ptItem->name ?? '';
- noticeUtil::push($name . " 申请将【{$ptItemName}/{$ptItemId}】进行认证", '15280215347');
- util::complete();
- }
- //简单花材的列表
- public function actionSimpleList()
- {
- $get = Yii::$app->request->get();
- $name = $get['name'] ?? '';
- $num = $get['num'] ?? 0;
- $where = ['mainId' => $this->mainId, 'delStatus' => 0];
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $respond = ItemClass::getSimpleList($where, $num);
- util::success($respond);
- }
- //可借库存的花材列表 ssh 20240720
- public function actionGetLoanList()
- {
- $get = Yii::$app->request->get();
- $name = $get['name'] ?? '';
- $where = ['mainId' => $this->mainId, 'delStatus' => 0];
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $shop = $this->shop;
- $respond = ItemClass::getLoanList($where, $shop);
- util::success($respond);
- }
- public function actionChangeFrontHide()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $status = $get['status'] ?? '';
- if (is_numeric($status) == false) {
- util::fail('请选择方式');
- }
- $info = ItemClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到花材');
- }
- if ($info->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- $info->frontHide = $status;
- $info->save();
- util::complete();
- }
- //检测是否要刷新
- public function actionCheckRefresh()
- {
- $mainId = $this->mainId;
- $staffId = $this->shopAdminId;
- $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- if ($respond == 'yes') {
- util::success(['remind' => 1]);
- }
- util::complete();
- }
- //批量恢复花材 ssh 20230206
- public function actionBatchRecover()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材6');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦8');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $info->removeStatus = 0;
- $info->save();
- }
- util::complete('操作成功');
- }
- //批量删除花材 ssh 202302026
- public function actionBatchRemove()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材7');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦10');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $name = $info->name ?? '';
- if ($info->delStatus != 1) {
- util::fail($name . ' 停用了才能删除');
- }
- $info->removeStatus = 1;
- $info->save();
- }
- util::complete('操作成功');
- }
- //批量启用花材 ssh 20230206
- public function actionBatchEnable()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材11');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦12');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $info->delStatus = 0;
- $info->save();
- }
- util::complete('操作成功');
- }
- //批量停用花材 20230206
- public function actionBatchStop()
- {
- $post = Yii::$app->request->post();
- $string = $post['ids'] ?? '';
- $ids = json_decode($string, true);
- $ids = array_unique(array_filter($ids));
- if (empty($ids)) {
- util::fail('请选择花材13');
- }
- $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
- if (empty($infoList)) {
- util::fail('请选择花材哦14');
- }
- foreach ($infoList as $info) {
- if ($info->mainId != $this->mainId) {
- util::fail('请选择自己的花材');
- }
- $name = $info->name ?? '';
- if ($info->status != 2) {
- util::fail($name . ' 下载了才能停用');
- }
- $info->delStatus = 1;
- $info->save();
- }
- util::complete('操作成功');
- }
- //获取给散客下单的花材海报 ssh 20220111
- public function actionGetSkPoster()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item) || $item->mainId != $this->mainId) {
- util::fail('获取失败');
- }
- $cover = $item->cover ?? '';
- if (empty($cover)) {
- util::fail('获取失败');
- }
- $merchant = WxOpenClass::getMallWxInfo();
- $page = 'pages/item/detail';
- $ptStyle = dict::getDict('ptStyle', 'mall');
- $shop = $this->shop;
- $lsShopId = $shop->lsShopId ?? 0;
- //scene不能超过32个字条
- $scene = "id=" . $id . '&a=' . $lsShopId;
- $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
- $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
- $miniCodeBase64 = stringUtil::ossBase64($miniCode);
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
- $prefix = imgUtil::getPrefix();
- $price = $item->skPrice ?? 0;
- if ($item->discountPrice > 0) {
- $skMore = $item->skMore ?? 0;
- $price = bcadd($item->discountPrice, $skMore, 2);
- }
- $newPrice = '¥' . floatval($price);
- $priceBase64 = stringUtil::ossBase64($newPrice);
- $name = $item->name ?? '';
- $nameBase64 = stringUtil::ossBase64($name);
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $newStaffName = $staffName . ' 为您推荐';
- $staffNameBase64 = stringUtil::ossBase64($newStaffName);
- //花材主图
- $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
- $itemCoverBase64 = stringUtil::ossBase64($itemCover);
- $logoBase64 = '';
- if (in_array($this->mainId, [52, 1459, 13495])) {
- $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- if ($this->mainId == 1459) {
- $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- }
- if ($this->mainId == 13495) {
- $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- }
- $logoBase64 = stringUtil::ossBase64($logo);
- }
- $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
- //花材主图
- $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
- //小程序码
- $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
- if (!empty($logoBase64)) {
- //logo
- $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
- }
- //为你推荐
- $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
- //标题
- $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
- //价格
- $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
- $respond = ['imgUrl' => $url];
- util::success($respond);
- }
- //下载商品码,用于花市卖花 ssh 20240823
- public function actionDownMiniCode()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $merchant = WxOpenClass::getWxInfo();
- $page = 'admin/ghsProduct/detail';
- $ptStyle = dict::getDict('ptStyle', 'hd');
- //小程序码,scene不能超过32个字条
- $scene = "id=" . $id . '&sId=' . $this->shopId;
- $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
- $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_450,w_450';
- $miniCodeBase64 = stringUtil::ossBase64($miniCode);
- $prefix = imgUtil::getPrefix();
- $url = $prefix . 'poster/mini_bg.jpg?x-oss-process=image';
- //小程序码
- $url .= '/watermark,image_' . $miniCodeBase64 . ',g_north,x_0,y_25';
- $name = $item->name ?? '';
- $nameBase64 = stringUtil::ossBase64($name);
- //标题
- $url .= '/watermark,text_' . $nameBase64 . ',g_south,x_0,y_35';
- $file = fopen($url, "rb");
- Header("Content-type: application/octet-stream ");
- Header("Accept-Ranges: bytes ");
- Header("Content-Disposition: attachment;filename={$name}.jpg");
- $contents = "";
- while (!feof($file)) {
- $contents .= fread($file, 8192);
- }
- echo $contents;
- fclose($file);
- }
- //获取给花店下单的花材海报 ssh 20220111
- public function actionGetHdPoster()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item) || $item->mainId != $this->mainId) {
- util::fail('获取失败');
- }
- $cover = $item->cover ?? '';
- if (empty($cover)) {
- util::fail('获取失败');
- }
- $merchant = WxOpenClass::getWxInfo();
- $page = 'admin/ghsProduct/detail';
- $ptStyle = dict::getDict('ptStyle', 'hd');
- //小程序码,scene不能超过32个字条
- $scene = "id=" . $id . '&sId=' . $this->shopId;
- $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
- $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
- $miniCodeBase64 = stringUtil::ossBase64($miniCode);
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- $prefix = imgUtil::getPrefix();
- $price = $item->price ?? 0;
- if ($item->discountPrice > 0) {
- $price = $item->discountPrice;
- }
- $newPrice = '¥' . floatval($price);
- $priceBase64 = stringUtil::ossBase64($newPrice);
- $name = $item->name ?? '';
- $nameBase64 = stringUtil::ossBase64($name);
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $newStaffName = $staffName . ' 为您推荐';
- $staffNameBase64 = stringUtil::ossBase64($newStaffName);
- //花材主图
- $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
- $itemCoverBase64 = stringUtil::ossBase64($itemCover);
- $logoBase64 = '';
- if (in_array($this->mainId, [52, 1459, 13495])) {
- $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- if ($this->mainId == 1459) {
- $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- }
- if ($this->mainId == 13495) {
- $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
- }
- $logoBase64 = stringUtil::ossBase64($logo);
- }
- $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
- //花材主图
- $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
- //小程序码
- $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
- if (!empty($logoBase64)) {
- //logo
- $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
- }
- //为你推荐
- $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
- //标题
- $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
- //价格
- $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
- $respond = ['imgUrl' => $url];
- util::success($respond);
- }
- //是否有C级价格大于B级的 ssh 20221204
- public function actionGetErrorPrice()
- {
- $shop = $this->shop;
- $ret = ItemClass::errorPrice($shop);
- $list = $ret['data'] ?? [];
- $map = $ret['map'] ?? [];
- util::success(['list' => $list, 'map' => $map]);
- }
- //列出所有花材,包括特价花材列表 ssh 20220315
- public function actionShowList()
- {
- $get = Yii::$app->request->get();
- $customId = $get['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- $where['mainId'] = $this->mainId;
- $where['delStatus'] = 0;
- $where['status'] = 1;
- $list = ItemClass::getShowList($where, $custom);
- $mainId = $this->mainId;
- $get = Yii::$app->request->get();
- $isCashier = $get['isCashier'] ?? 0;
- if ($isCashier == 1) {
- //去掉收银台提示价格更新
- $staffId = $this->shopAdminId;
- Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- }
- $productList = [];
- if (!empty($list)) {
- foreach ($list as $key => $item) {
- if (!empty($item)) {
- $productList = array_merge($productList, $item);
- }
- }
- }
- util::success(['list' => $list, 'productList' => $productList]);
- }
- public function actionAdd()
- {
- util::fail('开发中');
- }
- //批量添加花材
- public function actionBatchAdd()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
- $data = $post['data'];
- if (empty($data)) {
- util::fail("请选花材");
- }
- $data = json_decode($data, true);
- if (is_array($data) == false || empty($data)) {
- util::fail("请选花材");
- }
- $shop = $this->shop;
- $shopId = $this->shopId;
- $mainId = $this->mainId;
- $sjId = $this->sjId;
- $adminId = $this->adminId;
- $ids = array_column($data, 'itemId');
- $ids = array_unique(array_filter($ids));
- $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
- if (!empty($has)) {
- $hasName = $has->name ?? '';
- util::fail($hasName . " 已经添加过了");
- }
- $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- foreach ($data as $v) {
- $ptItemId = $v['itemId'] ?? 0;
- $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
- $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
- $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
- $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
- $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
- $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
- $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
- $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
- $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
- $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
- $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
- $v['ratio'] = $ratio;
- $v['cover'] = $cover;
- $v['shelfLife'] = $shelfLife;
- $v['ratioType'] = $ratioType;
- $v['variety'] = $variety;
- $v['stockWarning'] = $stockWarning;
- $v['weight'] = $weight;
- $v['bigUnit'] = $bigUnit;
- $v['smallUnit'] = $smallUnit;
- $v['bigUnitId'] = $bigUnitId;
- $v['smallUnitId'] = $smallUnitId;
- $v['adminId'] = $adminId;
- $v['sjId'] = $sjId;
- $v['shopId'] = $shopId;
- $v['mainId'] = $mainId;
- $v['staffName'] = $shopAdmin->name ?? '';
- $name = $v['name'] ?? '';
- $price = is_numeric($v['price']) ? $v['price'] : 0;
- $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
- $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
- if ($price <= 0) {
- util::fail("请填写{$name}的批发价");
- }
- if ($skPrice <= 0) {
- util::fail("请填写{$name}的零售价");
- }
- if ($cost <= 0) {
- util::fail("请填写{$name}的成本价");
- }
- if ($price > $skPrice) {
- util::fail("{$name}的批发价比零售价还高");
- }
- if ($cost > $price) {
- util::fail("{$name}的成本价比批发价还高");
- }
- $skMore = bcsub($skPrice, $price, 2);
- $addPrice = bcsub($price, $cost, 2);
- $v['skMore'] = $skMore;
- $v['addPrice'] = $addPrice;
- $v['hjAddPrice'] = $addPrice;
- $v['hjPrice'] = $price;
- ProductClass::addProduct($v, $shop);
- }
- $transaction->commit();
- util::complete('添加成功');
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail();
- }
- }
- public function actionDelete()
- {
- util::fail('不能删除哦!');
- }
- //获取平台里的花材信息
- public function actionPlatformItem()
- {
- $py = Yii::$app->request->get('py', '');
- $where = [];
- if ($py) {
- $where = ['py' => $py];
- }
- $list = PtItemClass::getItemList($where);
- util::success($list);
- }
- //列出需要进行颜色管理的花材 ssh 20220820
- public function actionColorList()
- {
- $mainId = $this->mainId ?? 0;
- $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
- util::success(['list' => $list]);
- }
- //多颜色管理启用与停用 ssh 20221229
- public function actionChangeVariety()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $variety = $get['variety'] ?? 0;
- $info = ItemClass::getById($id, true);
- if (empty($info) || $info->mainId != $this->mainId) {
- util::fail('操作失败');
- }
- $info->variety = $variety;
- $info->save();
- util::complete('操作成功');
- }
- //拆散花材 ssh 20221229
- public function actionBreakItem()
- {
- util::fail('开发中');
- util::complete();
- }
- //批量修改花材的负责人 ssh 20240718
- public function actionChangeCgStaff()
- {
- $get = Yii::$app->request->get();
- $beforeId = $get['beforeId'] ?? 0;
- $newId = $get['newId'] ?? 0;
- if (empty($beforeId) || empty($newId)) {
- util::fail('员工信息有问题');
- }
- $new = ShopAdminClass::getById($newId, true);
- if (empty($new) || $new->mainId != $this->mainId) {
- util::fail('错误的员工信息');
- }
- $before = ShopAdminClass::getById($beforeId, true);
- if (empty($before) || $before->mainId != $this->mainId) {
- util::fail('错误的员工信息2');
- }
- $newName = $new->name ?? '';
- ItemClass::updateByCondition(['mainId' => $this->mainId, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (!empty($bookSn)) {
- BookItemClass::updateByCondition(['bookSn' => $bookSn, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
- }
- util::complete('修改成功');
- }
- //获取花材描述
- public function actionDesc()
- {
- $itemId = Yii::$app->request->get('itemId', 0);
- $picText = PicTextGhsItemClass::getByCondition(['mainId' => $this->mainId, 'ghsItemId' => $itemId, 'delStatus' => 0], true);
- if (empty($picText)) {
- // 适配前端的返回处理 -- 本来要使用 util::fail()
- util::success('not_exist');
- }
- if ($picText->mainId != $this->mainId) {
- util::fail('没有找到描述');
- }
- util::success($picText);
- }
- //创建花材描述(花材介绍)
- public function actionCreateDesc()
- {
- $form = new \ghs\models\item\CreateDescForm();
- $form->load(Yii::$app->request->post(), '');
- if (!$form->validateForm()) {
- return;
- }
- $data = $form->attributes;
- $exists = PicTextGhsItemClass::exists(['mainId' => $this->mainId, 'ghsItemId' => $data['itemId'], 'delStatus' => 0]);
- if ($exists) {
- util::fail('该商品已存在图文内容,请勿重复添加');
- }
- $data['mainId'] = $this->mainId;
- $data['ghsItemId'] = $data['itemId'];
- $result = PicTextGhsItemClass::add($data);
- if ($result) {
- util::success($result);
- }
- util::fail('创建失败');
- }
- //更新花材描述(花材介绍)
- public function actionUpdateDesc()
- {
- $form = new \ghs\models\item\CreateDescForm();
- $form->load(Yii::$app->request->post(), '');
- if (!$form->validateForm()) {
- return;
- }
- $data = $form->attributes;
- $id = $data['id'];
- $info = PicTextGhsItemClass::getById($id, false, 'id');
- if (empty($info)) {
- util::fail('描述不存在');
- }
- $data['mainId'] = $this->mainId;
- $result = PicTextGhsItemClass::updateById($id, $data);
- if ($result) {
- util::success($result);
- }
- util::fail('更新失败');
- }
- public function actionChangeVirtualStock()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $virtualStock = $get['virtualStock'] ?? 0;
- $item = ItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- if ($item->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $item->virtualStock = $virtualStock;
- $item->save();
- util::complete('修改成功');
- }
- }
|