| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/1/15 20:36
- */
- namespace ghs\controllers;
- use biz\admin\classes\AdminRoleClass;
- use biz\item\classes\PtItemClass;
- use biz\wx\classes\WxMessageClass;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\cp\classes\CpClass;
- use bizGhs\cp\classes\CpItemClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\item\classes\UnitChangeClass;
- use bizGhs\merchant\classes\ShopClass;
- use bizGhs\notify\classes\NotifyClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\product\models\Product;
- use bizGhs\product\services\ProductService;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\stock\classes\StockInDayClass;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use bizGhs\stock\classes\OnStockRecordClass;
- use Yii;
- class ProductController extends BaseController
- {
- public $guestAccess = ['index'];
- //修改平均成本 ssh 2025114
- public function actionModifyAvCost()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $amount = $get['avCost'] ?? 0;
- $product = ProductClass::getById($id, true);
- if (empty($product)) {
- util::fail('没有找到花材');
- }
- if ($product->mainId != $this->mainId) {
- util::fail('不是你的花材');
- }
- $product->avCost = $amount;
- $product->save();
- util::complete('修改成功');
- }
- //修改路上库存 ssh 20231219
- public function actionModifyOnStock()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $onStock = $get['onStock'] ?? 0;
- $info = ProductClass::getLockById($id);
- ProductClass::check($info, $this->mainId);
- $oldOnStock = $info->onStock ?? 0;
- $newOnStock = $onStock;
- $num = bcsub($newOnStock, $oldOnStock);
- $num = abs($num);
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $onRecord = [];
- $onRecord['sjId'] = $this->sjId;
- $onRecord['shopId'] = $this->shopId;
- $onRecord['mainId'] = $this->mainId;
- $onRecord['orderSn'] = '';
- $onRecord['productId'] = $id;
- $onRecord['itemId'] = $info->itemId ?? 0;
- $onRecord['relateName'] = $staffName;
- $onRecord['itemNum'] = $num;
- $onRecord['oldStock'] = $oldOnStock;
- $onRecord['newStock'] = $newOnStock;
- $onRecord['ptStyle'] = 2;
- OnStockRecordClass::modify($onRecord);
- $info->onStock = $newOnStock;
- $info->save();
- util::complete('修改成功');
- }
- //停止预售 ssh 20230224
- public function actionCancelPreSell()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = ProductClass::getById($id, true);
- ProductClass::check($info, $this->mainId);
- if ($info->stock > 0) {
- util::fail('没有库存才能停止预售');
- }
- $info->presell = 0;
- $info->presellDate = '';
- $info->save();
- util::complete();
- }
- //修改预售 ssh 20221214
- public function actionChangePresell()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $info = ProductClass::getById($id, true);
- ProductClass::check($info, $this->mainId);
- $str = $post['date'] ?? '';
- $presell = $post['presell'] ?? 0;
- $newStr = '';
- if ($presell == 1) {
- if (empty($str)) {
- util::fail('请填写预售日期');
- }
- $arr = json_decode($str, true);
- if (empty($arr)) {
- util::fail('请填写预售日期');
- }
- $new = [];
- foreach ($arr as $date) {
- $new[] = strtotime($date);
- }
- $new = array_unique(array_filter($new));
- asort($new);
- $newStr = implode(',', $new);
- }
- $info->presell = $presell;
- $info->presellDate = $newStr;
- $info->discountPrice = 0;
- $info->save();
- util::complete();
- }
- //取消满减 ssh 20231216
- public function actionCancelFullOff()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = ProductClass::getById($id, true);
- ProductClass::check($info, $this->mainId);
- $info->reachNum = 0;
- $info->reachNumDiscount = 0;
- $info->save();
- util::complete('取消成功');
- }
- //取消特价 ssh 20220901
- 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('取消成功');
- }
- //打印花材的标签 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;
- $ext = $this->shopExt;
- $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();
- }
- //取出今天有入库的花材 ssh 20221024
- public function actionStockIn()
- {
- $py = Yii::$app->request->get('py', '');
- $version = Yii::$app->request->get('version', 0);
- if ($version == 0) {
- util::fail('请先升级版本到1.0.70以上');
- }
- $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
- $mainId = $this->mainId ?? 0;
- $where['mainId'] = $mainId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
- if (empty($arr)) {
- util::fail('没有花材需要盘点');
- }
- $ids = array_column($arr, 'itemId');
- $ids = array_unique($ids);
- $where['id'] = ['in', $ids];
- $level = 1;
- $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
- $data = ProductService::assembleData($classInfo, $itemInfoData, true);
- util::success($data);
- }
- //按分类列出所有花材
- public function actionShow()
- {
- $py = Yii::$app->request->get('py', '');
- $name = Yii::$app->request->get('name', '');
- $requestType = Yii::$app->request->get('requestType', 'common');
- //默认显示上架商品
- $status = Yii::$app->request->get('status', 1);
- //默认显示未删除商品
- $delStatus = Yii::$app->request->get('delStatus', 0);
- $classId = Yii::$app->request->get('classId', 0);
- //获取所有当前供货商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- //中央ID
- $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
- $where['mainId'] = $this->mainId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- //改价和全部有库存花材列表
- if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
- $where['stock>'] = 0;
- }
- if (!empty($status)) {
- $where['status'] = $status;
- if ($requestType == 'itemList') {
- unset($where['status']);
- }
- }
- if ($requestType == 'book') {
- unset($where['status']);
- }
- $where['delStatus'] = $delStatus;
- if (!empty($classId)) {
- $where['classId'] = $classId;
- }
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $name = strtolower($name);
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- //客户等级
- $customId = Yii::$app->request->get('customId', 0);
- $level = 1;
- if (!empty($customId)) {
- $custom = CustomClass::getById($customId, true);
- $level = $custom->level ?? 1;
- }
- $itemInfoData = [];
- if ($requestType == 'hasStockList') {
- //有库存的花材列表
- $field = 'id,py,cover,name,classId,itemId,price,skPrice,hjPrice,stock,onStock,cost,avCost,addPrice,hjAddPrice,skMore';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- if (!empty($itemInfoData)) {
- foreach ($itemInfoData as $key => $val) {
- //以下参数主要是网页批量改价要用到
- $shortCover = $val['cover'] ?? '';
- $itemInfoData[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_100,w_100";
- $itemInfoData[$key]['shortCover'] = $shortCover;
- }
- }
- } elseif ($requestType == 'changePrice') {
- $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,onStock,presell,frontHide,reachNum,reachNumDiscount';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
- } elseif ($requestType == 'changeStock') {
- //修改库存列表
- $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
- } elseif ($requestType == 'kd') {
- //开单的花材列表
- $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide,reachNum,reachNumDiscount';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'book') {
- //预订花材列表
- $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::bookItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'itemList') {
- //花材列表
- $field = 'id,py,cover,name,cost,avCost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount,addPrice,hjAddPrice,skMore';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
- } elseif ($requestType == 'cgStaffList') {
- unset($where['status']);
- $where['delStatus'] = 0;
- $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount,cgStaffId,cgStaffName';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::cgStaffListGroup($itemInfoData, $level);
- } elseif ($requestType == 'outList') {
- //下架花材列表
- $where['status'] = 2;
- $where['delStatus'] = 0;
- $where['removeStatus'] = 0;
- $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
- } elseif ($requestType == 'stopList') {
- //停用花材列表
- unset($where['status']);
- $where['delStatus'] = 1;
- $where['removeStatus'] = 0;
- $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status,delStatus';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
- } elseif ($requestType == 'removeList') {
- //删除花材列表
- unset($where['status']);
- $where['delStatus'] = 1;
- $where['removeStatus'] = 1;
- $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
- } elseif ($requestType == 'check') {
- $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'break') {
- $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'part') {
- //拆散花材
- $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'stockOut') {
- $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
- } elseif ($requestType == 'cg') {
- $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'warning') {
- $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,onStock,actualSold,presell,bigUnit,stockWarning,status,frontHide';
- $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('没有数据');
- }
- $data = ProductService::assembleItemData($classInfo, $itemInfoData);
- util::success($data);
- }
- //取出今天有入库的花材 ssh 20221224
- public function actionGetStockIn()
- {
- $py = Yii::$app->request->get('py', '');
- $version = Yii::$app->request->get('version', 0);
- if ($version == 0) {
- util::fail('请先升级版本到1.0.70以上');
- }
- $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
- $mainId = $this->mainId ?? 0;
- $where['mainId'] = $mainId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
- if (empty($arr)) {
- util::fail('没有花材需要盘点');
- }
- $ids = array_column($arr, 'itemId');
- $ids = array_unique($ids);
- $where['id'] = ['in', $ids];
- $level = 1;
- $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
- $data = ProductService::assembleItemData($classInfo, $itemInfoData);
- util::success($data);
- }
- //按分类列出所有花材
- public function actionIndex()
- {
- $py = Yii::$app->request->get('py', '');
- $requestType = Yii::$app->request->get('requestType', 'common');
- //默认显示上架商品
- $status = Yii::$app->request->get('status', 1);
- //默认显示未删除商品
- $delStatus = Yii::$app->request->get('delStatus', 0);
- $warning = Yii::$app->request->get('warning', 0);
- //获取所有当前供货商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- //中央ID
- $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
- $where['mainId'] = $this->mainId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- if ($requestType == 'hasStock') {
- //改价只显示库存大于0的
- $where['stock>'] = 0;
- }
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $where['delStatus'] = $delStatus;
- //客户等级
- $customId = Yii::$app->request->get('customId', 0);
- $level = 1;
- if (!empty($customId)) {
- $custom = CustomClass::getById($customId, true);
- $level = $custom->level ?? 1;
- }
- if ($warning == 1) {
- //库存预警
- $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
- $itemInfoData = Product::find()->where("mainId={$this->mainId}")
- ->andWhere('`stock`<`stockWarning`')
- ->andWhere("delStatus=0")
- ->select($field)->asArray()->all();
- } else {
- $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- }
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
- $data = ProductService::assembleData($classInfo, $itemInfoData, true);
- util::success($data);
- }
- //所有花材分页和不分页
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $classId = Yii::$app->request->get('classId', 0);
- if (!empty($classId)) {
- $where['classId'] = $classId;
- }
- $name = Yii::$app->request->get('name', '');
- if (empty($name)) {
- $py = Yii::$app->request->get('py', '');
- $name = !empty($py) ? $py : '';
- }
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $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;
- }
- $where['mainId'] = $this->mainId;
- $productIds = Yii::$app->request->get('ids', '');
- if (!empty($productIds)) {
- $productIdArr = explode(',', $productIds);
- if (!empty($productIdArr)) {
- $where['id'] = ['in', $productIdArr];
- }
- }
- //输出标准会员价,即批发价,默认显示的是批发价
- $level = 1;
- $type = Yii::$app->request->get('type', '');
- $showPage = Yii::$app->request->get('showPage', 0);
- if ($showPage) {
- if ($type == 'waring') {
- $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
- $lackIds = array_column($pro, 'id');
- if (empty($lackIds)) {
- util::success([]);
- }
- $lackIds = array_filter(array_unique($lackIds));
- $where['id'] = ['in', $lackIds];
- $respond = ProductClass::getList("*", $where, "actualSold desc");
- } else {
- $hasStock = $get['hasStock'] ?? -1;
- if ($hasStock == 0) {
- $where['stock'] = 0;
- }
- if ($hasStock == 1) {
- $where['stock>'] = 0;
- }
- $cgStaffId = $get['cgStaffId'] ?? 0;
- if (!empty($cgStaffId)) {
- $where['cgStaffId'] = $cgStaffId;
- }
- $respond = ProductClass::getList("*", $where, "inTurn desc");
- }
- $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
- $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
- util::success($respond);
- } else {
- if ($type == 'waring') {
- //库存预警 按库存从小到大排序
- $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
- } else {
- if (!empty($productIds)) {
- //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
- $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
- } else {
- $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
- }
- }
- $data = ProductClass::groupProductInfo($data, $level);
- $data = ProductClass::groupClassName($this->mainId, $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 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 = 1;
- $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
- $data = ProductClass::groupProductInfo($data, $level);
- util::success(['list' => $data]);
- }
- //批量改价
- public function actionBatchChangePrice()
- {
- $shop = $this->shop;
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- //除了小蔡鲜花的蔡总、郑总、苏南3007,其他人直营分店不能改价格,多处要同步修改,关键词 direct_price_change
- if (!in_array($this->adminId, [35725, 23659, 29264])) {
- util::fail('直营店不能改价');
- }
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $shop = $this->shop;
- $default = $shop->default ?? 0;
- $adminId = $this->adminId ?? 0;
- //normal常规改价,cg采购改价
- $changeType = Yii::$app->request->post('changeType', 'normal');
- $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('没有修改哦');
- }
- $appVersion = $post['appVersion'] ?? 0;
- if ($appVersion != 1) {
- util::fail('请先升级应用');
- }
- //解决重复请求问题
- $cacheKey = 'batch_change_price_' . $targetId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('请5秒后操作');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $needNotice = false;
- $cg = PurchaseOrderClass::getLockById($targetId);
- if (!empty($cg)) {
- if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
- util::fail('不是您的采购单');
- }
- //批量改价同时入库
- if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
- $staff = $this->shopAdmin;
- $data = [];
- $data['staffId'] = $staff->id ?? 0;
- $data['staffName'] = $staff->name ?? '';
- $data['adminId'] = $this->adminId ?? 0;
- $data['shop'] = $this->shop;
- PurchaseOrderClass::putIn($cg, $data);
- $needNotice = true;
- }
- }
- $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) {
- $productId = $product['id'];
- $productInfo = $productList[$productId] ?? [];
- if (empty($productInfo)) {
- util::fail('没有找到花材');
- }
- $productName = $productInfo->name ?? '';
- if (!isset($product['id'])) {
- util::fail('没有花材');
- }
- if (!isset($product['price']) || !is_numeric($product['price']) || $product['price'] < 0) {
- util::fail('请填写' . $productName . '的批发价');
- }
- $price = $product['price'];
- if (!isset($product['skPrice']) || !is_numeric($product['skPrice']) || $product['skPrice'] < 0) {
- util::fail('请填写' . $productName . '的零售价');
- }
- $skPrice = $product['skPrice'];
- if (!isset($product['hjPrice']) || !is_numeric($product['hjPrice']) || $product['hjPrice'] < 0) {
- util::fail('请填写' . $productName . '的会员价');
- }
- $hjPrice = $product['hjPrice'] ?? 0;
- if (!isset($productInfo->mainId) || $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);
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $changeParams2 = ['staffId' => $staffId, 'staffName' => $staffName, '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();
- //入库成功通知相关人员,关键词 put_in_notice
- if ($needNotice) {
- // $cg = PurchaseOrderClass::getLockById($targetId);
- // WxMessageClass::ghsCgEntryInform($shop, $cg);
- }
- util::complete('操作成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- Yii::info("修改失败原因:" . $msg);
- noticeUtil::push("修改价格出现失败情况,原因:" . $msg, '15280215347');
- util::fail('修改失败');
- }
- }
- //多个花材同时改成一个价 ssh 20231003
- public function actionManyItemChangeOnePrice()
- {
- $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) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $post = Yii::$app->request->post();
- $idsList = $post['ids'] ?? '';
- $ids = json_decode($idsList, true);
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($list)) {
- util::fail('请选择花材哦');
- }
- $mainId = $this->mainId;
- $adminId = $this->adminId ?? 0;
- $shop = $this->shop;
- $default = $shop->default ?? 0;
- $shopAdmin = $this->shopAdmin;
- $price = $post['price'] ?? 0;
- if (is_numeric($price) == false) {
- util::fail('批发价填写错误');
- }
- $skPrice = $post['skPrice'] ?? 0;
- if (is_numeric($skPrice) == false) {
- util::fail('散客价填写错误');
- }
- $hjPrice = $post['hjPrice'] ?? 0;
- if (is_numeric($hjPrice) == false) {
- util::fail('会员价填写错误');
- }
- if ($hjPrice > $price) {
- util::fail('会员价不能大于批发价');
- }
- if ($price > $skPrice) {
- util::fail('批发价不能大于零售价');
- }
- $sjId = $shop->sjId ?? 0;
- $chainShopList = [];
- if ($default == 1) {
- $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
- }
- //normal常规改价,cg采购改价
- $changeType = Yii::$app->request->post('changeType', 'normal');
- $targetId = 0;
- $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- foreach ($list as $product) {
- if ($product->mainId != $mainId) {
- util::fail('修改失败,不是你的花材');
- }
- $ptItemId = $product->itemId;
- ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
- //在首店修改需要同步到所有直营店
- if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- if (!empty($chainShopList)) {
- 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);
- }
- }
- }
- }
- 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('修改失败');
- }
- }
- //改价
- public function actionChangePrice()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $productId = Yii::$app->request->post('productId', 0);
- $productInfo = ProductClass::getById($productId, true);
- if (empty($productInfo)) {
- util::fail("花材不存在");
- }
- if ($productInfo->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- $price = Yii::$app->request->post('price', '');
- if (is_numeric($price) && $price > 0) {
- ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
- } else {
- $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
- ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
- }
- util::success(['price' => $price]);
- }
- //恢复自动调价
- public function actionAutoPrice()
- {
- $productId = Yii::$app->request->post('productId', 0);
- $productData = ProductClass::getById($productId);
- if (!$productData) {
- util::fail("花材不存在");
- }
- //2021.04.06改为用product中的成本价+加价
- $price = bcadd($productData['cost'], $productData['addPrice'], 2);
- ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
- util::complete("操作成功");
- }
- //修改加价
- public function actionChangeAddPrice()
- {
- $productId = Yii::$app->request->post('productId', 0);
- $addPrice = Yii::$app->request->post('addPrice', '');
- if ($addPrice < 0) {
- util::fail("加价不能小于0");
- }
- $productData = ProductClass::getProductData($productId, $this->mainId);
- if (!$productData) {
- util::fail("花材不存在");
- }
- ProductClass::changeAddPrice($productId, $addPrice);
- util::complete();
- }
- //批量修改更多,包括排序、重量和保质期 ssh 20211211
- public function actionBatchChangeMore()
- {
- $shop = $this->shop;
- $default = $shop->default ?? 0;
- $join = $shop->join ?? 0;
- if ($default == 0 && $join == 0) {
- util::fail('当前是直营店,请返回总店修改');
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- 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, null, 'id');
- if (empty($infoList)) {
- util::fail('没有花材');
- }
- foreach ($infoList as $info) {
- if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
- util::fail('不是你的花材不能修改');
- }
- }
- //总店修改同步到所有门店
- $sjId = $shop->sjId ?? 0;
- $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
- foreach ($itemData as $key => $data) {
- $id = $data['id'] ?? 0;
- unset($data['id']);
- ProductClass::updateById($id, $data);
- $ptItemId = $infoList[$id]['itemId'] ?? 0;
- if (empty($ptItemId)) {
- continue;
- }
- if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- foreach ($chainShopList as $chainShop) {
- $currentMainId = $chainShop->mainId ?? 0;
- if ($currentMainId == $shop->mainId) {
- //前面已经修改过了,不需要重复修改
- continue;
- }
- ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
- }
- }
- }
- util::complete('修改成功');
- }
- //批量修改加价 ssh 20211211
- public function actionBatchChangeAddPrice()
- {
- $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) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- $addData = $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, null, 'id');
- if (empty($infoList)) {
- util::fail('没有花材');
- }
- foreach ($infoList as $info) {
- if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
- util::fail('不能修改别人的花材');
- }
- }
- $appVersion = $post['appVersion'] ?? 0;
- if ($appVersion != 1) {
- util::fail('请先升级应用');
- }
- //总店修改同步到所有门店
- $sjId = $shop->sjId ?? 0;
- $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
- foreach ($itemData as $key => $data) {
- $id = $data['id'] ?? 0;
- unset($data['id']);
- ProductClass::updateById($id, $data);
- $ptItemId = $infoList[$id]['itemId'] ?? 0;
- if (empty($ptItemId)) {
- continue;
- }
- if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- foreach ($chainShopList as $chainShop) {
- if (isset($chainShop->join) && $chainShop->join == 1) {
- continue;
- }
- $currentMainId = $chainShop->mainId ?? 0;
- if ($currentMainId == $shop->mainId) {
- //前面已经修改过了,不需要重复修改
- continue;
- }
- ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
- }
- }
- }
- util::complete('修改成功');
- }
- 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('系统已到期,编号1689');
- }
- $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;
- // 图片列表数组转换为字符串
- if (is_array($post['images'])) {
- $post['images'] = implode(',', $post['images']);
- }
- $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('操作失败');
- }
- }
- //上下架状态控制 ssh 20210713
- public function actionStatusUpdate()
- {
- $post = Yii::$app->request->post();
- $shopAdmin = $this->shopAdmin;
- $roleId = $shopAdmin['roleId'] ?? 0;
- $role = AdminRoleClass::getById($roleId);
- $roleName = $role['roleName'] ?? '';
- if ($roleName == '员工') {
- util::fail('无法操作哦');
- }
- $id = $post['id'] ?? 0;
- $status = $post['status'] ?? 1;
- $product = ProductClass::getById($id, true);
- if ($product->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- $product->status = $status;
- if ($status == 2) {
- $product->discountPrice = 0;
- }
- $product->save();
- util::complete();
- }
- //花材展示状态控制 ssh 20231113
- 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];
- } else {
- $systemItem = [11157, 11156, 11158];
- }
- if (in_array($product->itemId, $systemItem)) {
- 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();
- }
- //详情 shish 20240115
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $source = Yii::$app->request->get('source', '');
- $respond = ProductClass::getItemInfo($id);
- $ptItemId = $respond['itemId'] ?? 0;
- // 封面图与多花材图片的兼容处理
- if ($respond['images'] == '' && $respond['shortCover'] != '') {
- $respond['images'] = $respond['shortCover'];
- }
- $ptItemInfo = PtItemClass::getById($ptItemId);
- $respond['ptItemInfo'] = $ptItemInfo;
- //通知提醒抹除
- if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
- $staff = $this->shopAdmin;
- $staffId = $this->shopAdminId;
- $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
- if (!empty($notify)) {
- if ($notify->read == 0) {
- $notify->read = 1;
- $notify->save();
- $notifyNum = $staff->notifyNum;
- if ($notifyNum > 0) {
- $notifyNum--;
- $staff->notifyNum = $notifyNum;
- $staff->save();
- }
- }
- }
- }
- //重复花材
- $repeatList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'itemId' => $ptItemId, 'delStatus' => 0], null, '*', null, true);
- $repeatId = 0;
- if (!empty($repeatList)) {
- foreach ($repeatList as $repeat) {
- if ($repeat->id != $id) {
- $repeatId = $repeat->id;
- }
- }
- }
- $respond['repeatId'] = $repeatId;
- $cpItemList = CpItemClass::getAllByCondition(['productId' => $id], null, '*', 'cpId');
- $cpInfo = [];
- if (!empty($cpItemList)) {
- $cpIds = array_column($cpItemList, 'cpId');
- $cpList = CpClass::getByIds($cpIds);
- if (!empty($cpList)) {
- foreach ($cpList as $key => $val) {
- $id = $val['id'] ?? 0;
- $name = $val['name'] ?? '';
- $cpInfo[] = ['cpId' => $id, 'cpName' => $name];
- }
- }
- }
- //判断这个花材能否被修改单位比和重量,同步参考ShopController actionMyShop方法,关键词has_right_shop_list
- //判断当前登录的人,在自己有财务权限的main里面,是否包括了这个花材所属的平台id,在这个平台id下所有花材的main
- $adminId = $this->adminId;
- $hasRightRespond = ShopAdminClass::changeWeightRight($adminId, $ptItemId);
- $respond['hasRightChange'] = $hasRightRespond['hasRightChange'];
- $respond['hasRightChangeReason'] = $hasRightRespond['reason'];
- //查出拆散的子花材
- $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;
- $respond['cpInfo'] = $cpInfo;
- util::success($respond);
- }
- //新增花材 2021.6.21
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $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) == false || $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) {
- //客户添加花材时,经常会出现加价大于售价的怦,这个时候就直接把加价全部设置为0
- $post['addPrice'] = 0;
- $post['hjAddPrice'] = 0;
- $post['skMore'] = 0;
- //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 actionClone()
- {
- $post = Yii::$app->request->post();
- $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) == false || $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 20210922
- public function actionGeneratePriceTable()
- {
- $level = Yii::$app->request->get('level', 0);
- $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
- $file = $respond['file'] ?? '';
- $shortFile = $respond['shortFile'] ?? '';
- $fileUrl = Yii::$app->params['ghsHost'] . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
- }
- //下载有库存花材,不含虚拟库存 ssh 20241-28
- public function actionGenerateStockTable()
- {
- $level = Yii::$app->request->get('level', 0);
- $respond = ProductService::generateStockTable($this->sjId, $level, $this->mainId);
- $file = $respond['file'] ?? '';
- $shortFile = $respond['shortFile'] ?? '';
- $fileUrl = Yii::$app->params['ghsHost'] . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
- }
- public function actionGenerateItemTable()
- {
- $level = Yii::$app->request->get('level', 0);
- $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
- $file = $respond['file'] ?? '';
- $shortFile = $respond['shortFile'] ?? '';
- $fileUrl = Yii::$app->params['ghsHost'] . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
- }
- //下载条形码 lqh 20211227
- public function actionGenerateBarcodeTable()
- {
- $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
- $file = $respond['file'] ?? '';
- $shortFile = $respond['shortFile'] ?? '';
- $fileUrl = Yii::$app->params['ghsHost'] . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
- }
- //批量修改花材的分类 ssh 20230405
- public function actionBatchModifyClass()
- {
- $post = Yii::$app->request->post();
- $shop = $this->shop;
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $sjShopName = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- //noticeUtil::push($sjShopName . ' 批量移动花材分类', '15280215347');
- $join = $shop->join ?? 0;
- $default = $shop->default ?? 0;
- if ($join == 0 && $default == 0) {
- util::fail('当前直营分店,请切回总店操作');
- }
- $classId = $post['classId'] ?? 0;
- $class = ItemClassClass::getById($classId, true);
- if (empty($class) || $class->mainId != $this->mainId) {
- util::fail('请选择您自己的分类');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $className = $class->name ?? '';
- $idsList = $post['ids'] ?? '';
- $ids = json_decode($idsList, true);
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($list)) {
- util::fail('请选择花材');
- }
- $ptItemList = [];
- foreach ($list as $item) {
- $name = $item->name ?? '';
- if ($item->mainId != $this->mainId) {
- util::fail($name . '不是您的花材');
- }
- $item->classId = $classId;
- $item->save();
- $ptItemId = $item->itemId ?? 0;
- $ptItemList[] = $ptItemId;
- //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
- $itemClassKey = 'item_class_modify_sync';
- Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $item->id]);
- }
- $shop = $this->shop;
- 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 ($chainShopId == $shop->id) {
- continue;
- }
- $chainManId = $chainShop->mainId ?? 0;
- $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
- if (!empty($chainAllClassList)) {
- foreach ($chainAllClassList as $chainClass) {
- $chainName = $chainClass->name ?? '';
- $chainClassId = $chainClass->id ?? 0;
- if ($chainName == $className) {
- $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
- if (!empty($chainProductList)) {
- foreach ($chainProductList as $currentProduct) {
- $currentProduct->classId = $chainClassId;
- $currentProduct->save();
- //如果有修改分类,则在多个订单表中同步修改,如需修改,多个地方要同步修改,请搜索关键词item_class_modify_sync
- $itemClassKey = 'item_class_modify_sync';
- Yii::$app->redis->executeCommand('LPUSH', [$itemClassKey, $currentProduct->id]);
- }
- }
- }
- }
- }
- }
- }
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("修改失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- //批量修改采购人 ssh 20240609
- public function actionBatchModifyCgStaff()
- {
- $post = Yii::$app->request->post();
- $staffId = $post['staffId'] ?? 0;
- $staff = ShopAdminClass::getById($staffId, true);
- if (empty($staff)) {
- util::fail('没有找到这个员工');
- }
- if ($staff->mainId != $this->mainId) {
- util::fail('不是你的员工');
- }
- $staffName = $staff->name ?? '';
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $idsList = $post['ids'] ?? '';
- $ids = json_decode($idsList, true);
- if (empty($ids)) {
- util::fail('请选择花材');
- }
- $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($list)) {
- util::fail('请选择花材');
- }
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- foreach ($list as $item) {
- $name = $item->name ?? '';
- if ($item->mainId != $this->mainId) {
- util::fail($name . '不是您的花材');
- }
- $item->cgStaffId = $staffId;
- $item->cgStaffName = $staffName;
- $item->save();
- $itemId = $item->id ?? 0;
- if (!empty($bookSn)) {
- //预订管理的花材需要变化
- BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $itemId], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
- }
- }
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("修改失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- //修改属于成本还是收入选项 ssh 20240514
- public function actionChangeBelongCost()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $belongCost = $get['belongCost'] ?? 0;
- $info = ProductClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到花材');
- }
- if ($info->mainId != $this->mainId) {
- util::fail('不是你的花材哦');
- }
- $info->belongCost = $belongCost;
- $info->save();
- //队列方式去处理
- $redisKey = 'change_belong_cost_item_list';
- $value = $id . '_' . $belongCost;
- Yii::$app->redis->executeCommand('LPUSH', [$redisKey, $value]);
- 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('修改成功');
- }
- }
|