| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/1/15 20:36
- */
- namespace ghs\controllers;
- use biz\admin\classes\AdminRoleClass;
- use biz\item\classes\PtItemClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\merchant\classes\ShopClass;
- 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\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class ProductController extends BaseController
- {
- public $guestAccess = ['index'];
- //停止预售 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 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->save();
- util::complete();
- }
- //打印花材的标签 ssh 20220602
- public function actionPrint()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $num = $get['num'] ?? 1;
- $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) > 7) {
- $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 (isset($get['type']) == false && $this->shopId == 4608) {
- $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
- $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
- } else {
- 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>';
- } else {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
- }
- } else {
- //打价码
- $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
- $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</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', '');
- $requestType = Yii::$app->request->get('requestType', 'common');
- //默认显示上架商品
- $status = Yii::$app->request->get('status', 1);
- //默认显示未删除商品
- $delStatus = Yii::$app->request->get('delStatus', 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;
- }
- $where['delStatus'] = $delStatus;
- //客户等级
- $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,name,classId,itemId,price,skPrice,stock';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- } elseif ($requestType == 'changePrice') {
- //修改价格列表
- $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
- } elseif ($requestType == 'kd') {
- //开单的花材列表
- $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
- } elseif ($requestType == 'itemList') {
- //花材列表
- $field = 'id,py,cover,name,cost,itemId,classId,skPrice,bigUnit,smallUnit,ratio,ratioType,variety,price,discountPrice,skMore,stock,actualSold,stockWarning,status,presell';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::itemListGroup($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') {
- //停用花材列表
- $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';
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
- $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
- } elseif ($requestType == 'removeList') {
- //删除花材列表
- $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';
- $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';
- $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';
- $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';
- $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,actualSold,presell,bigUnit,stockWarning,status';
- $itemInfoData = Product::find()->where("mainId={$this->mainId}")
- ->andWhere('`stock`<`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,presellDate';
- $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,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 actionList()
- {
- $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 {
- $respond = ProductClass::getList("*", $where, "inTurn desc");
- }
- $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
- $respond['list'] = ProductClass::groupClassName($this->sjId, $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->sjId, $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) {
- 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];
- $data = Yii::$app->request->post('data', '');
- if (empty($data)) {
- util::fail('没有修改');
- }
- $arr = json_decode($data, true);
- if (empty($arr)) {
- util::fail('没有修改哦');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $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;
- PurchaseOrderClass::putIn($cg, $data);
- }
- }
- $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']) == false) {
- util::fail('没有花材');
- }
- if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
- util::fail('请填写' . $productName . '的批发价');
- }
- $price = $product['price'];
- if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
- util::fail('请填写' . $productName . '的零售价');
- }
- $skPrice = $product['skPrice'];
- if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
- util::fail('没有权限访问');
- }
- if (empty($price)) {
- continue;
- }
- $ptItemId = $productInfo->itemId;
- ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $changeParams);
- //在首店修改需要同步到所有直营店
- if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
- foreach ($chainShopList as $chain) {
- if ($chain->id == $shop->id) {
- continue;
- }
- $chainMainId = $chain->mainId ?? 0;
- $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
- $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
- ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $changeParams2);
- }
- }
- }
- $mainId = $shop->mainId ?? 0;
- if (!empty($mainId)) {
- //提醒零售收银台界面要刷新
- $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;
- if ($default == 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('超管才能操作');
- }
- $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) {
- 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) == false || $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('请先开通超管权限');
- }
- }
- $post = Yii::$app->request->post();
- $post['adminId'] = $this->adminId;
- $post['staffId'] = $this->shopAdmin->id;
- $post['staffName'] = $this->shopAdmin->name;
- ProductClass::updateProduct($post, $this->shop);
- util::complete();
- }
- //上下架状态控制 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 20210804
- 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('请在首店操作');
- }
- $shopAdmin = $this->shopAdmin;
- $roleId = $shopAdmin['roleId'] ?? 0;
- $role = AdminRoleClass::getById($roleId);
- $roleName = $role['roleName'] ?? '';
- if ($roleName == '员工') {
- util::fail('没有权限操作');
- }
- $id = $post['id'] ?? 0;
- $delStatus = $post['delStatus'] ?? 0;
- $product = ProductClass::getById($id, true);
- if ($product->mainId != $this->mainId) {
- util::fail('没有权限操作');
- }
- $product->delStatus = $delStatus;
- $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;
- $chainProduct->save();
- }
- }
- }
- util::complete();
- }
- //详情 ruidian 2021.5.3
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $respond = ProductClass::getItemInfo($id);
- $ptItemId = $respond['itemId'] ?? 0;
- $ptItemInfo = PtItemClass::getById($ptItemId);
- $respond['ptItemInfo'] = $ptItemInfo;
- util::success($respond);
- }
- //新增花材 2021.6.21
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $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) {
- util::fail('加价不能大于售价');
- }
- $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
- if ($weight <= 0) {
- util::fail('请填写重量,最小0.1');
- }
- $post['staffName'] = $shopAdmin->name ?? '';
- 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();
- $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;
- $addPrice = $post['addPrice'] ?? 0;
- if ($addPrice > $price) {
- util::fail('加价不能大于售价');
- }
- //复制标识
- $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]);
- }
- 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;
- $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;
- }
- $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();
- }
- }
- }
- }
- }
- }
- }
- $transaction->commit();
- util::complete('修改成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("修改失败原因:" . $e->getMessage());
- util::fail('修改失败');
- }
- }
- }
|