| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\sj\classes\SjClass;
- use bizGhs\book\classes\BookItemClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\order\classes\PurchaseOrderItemClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\shop\classes\ShopClass;
- use bizHd\purchase\classes\PurchaseClass;
- use common\components\dateUtil;
- use common\components\dirUtil;
- use common\components\noticeUtil;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class PurchaseOrderController extends BaseController
- {
- public $guestAccess = ['detail', 'check-seat-update', 'assign-seat'];
- //打印多联 ssh 2024509
- public function actionPrintPaper()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到采购信息');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('不是你的采购单哦');
- }
- if ($cg->status != 4) {
- util::fail('请先确认入库');
- }
- $orderSn = $cg->orderSn ?? '';
- //增加打印次数
- PurchaseOrderClass::addPrintNum($cg);
- $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- $table = [];
- $totalItemNum = 0;
- $kind = 0;
- if (!empty($itemList)) {
- foreach ($itemList as $key => $val) {
- $kind++;
- $currentName = $val['name'] ?? '';
- $preNum = $val['itemNum'] ?? 0;
- $preNum = floatval($preNum);
- $refundNum = $val['refundNum'] ?? 0;
- $num = bcsub($preNum, $refundNum);
- $totalItemNum = bcadd($totalItemNum, $num);
- $unitPrice = $val['bigPrice'] ?? 0;
- $unitPrice = floatval($unitPrice);
- $orderNum = bcadd($key, 1);
- $currentPrice = $val['totalPrice'] ?? 0;
- $currentPrice = floatval($currentPrice);
- $table[] = [
- 'orderNum' => $orderNum,
- 'name' => $currentName,
- 'num' => $preNum,
- 'unitPrice' => '¥' . $unitPrice,
- 'refundNum' => $refundNum,
- 'remark' => '',
- 'price' => '¥' . $currentPrice,
- ];
- }
- }
- $shortOrderSn = substr($orderSn, -4);
- $ghsName = $cg->ghsName ?? '';
- $entryTime = $cg->entryTime ?? '';
- $entryTime = substr($entryTime, 0, 16);
- $addTime = $cg->addTime ?? '';
- $addTime = substr($addTime, 0, 16);
- $shopAdminName = $cg->shopAdminName ?? '';
- $shopId = $cg->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- $telephone = $shop->telephone ?? '';
- $shopName = $shop->shopName ?? '';
- $sjId = $shop->sjId ?? 0;
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $prePrice = $cg->prePrice ?? 0;
- $prePrice = floatval($prePrice);
- $tkPrice = $cg->tkPrice ?? 0;
- $tkPrice = floatval($tkPrice);
- $realPrice = $cg->realPrice ?? 0;
- $realPrice = floatval($realPrice);
- $printData = [
- 'table' => $table,
- 'addTime' => $addTime,
- 'entryTime' => $entryTime,
- 'ghsName' => $ghsName,
- 'clearCode' => $shortOrderSn,
- 'staffName' => $shopAdminName,
- 'telephone' => '-',
- 'kind' => $kind,
- 'orderSn' => $orderSn,
- 'sjShopName' => $sjShopName . ' 采购单',
- 'prePrice' => '¥' . $prePrice,
- 'tkPrice' => '¥' . $tkPrice,
- 'realPrice' => '¥' . $realPrice,
- 'totalItemNum' => $totalItemNum,
- 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
- ];
- $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":49.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName","testData":"小向花卉 采购单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":55,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":192.5,"top":120,"height":16,"width":178,"title":"制单时间","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":365,"top":120,"height":16,"width":178,"title":"供货商","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"入库时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":170,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
- if (getenv('YII_ENV') == 'production') {
- //集花舍 三等分
- if ($this->mainId == 42490) {
- $template = '{"panels":[{"index":0,"name":1,"height":94,"width":210,"paperHeader":49.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName","testData":"小向花卉 采购单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":55,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":192.5,"top":120,"height":16,"width":178,"title":"制单时间","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":365,"top":120,"height":16,"width":178,"title":"供货商","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"入库时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":170,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
- }
- }
- util::success(['template' => $template, 'printData' => $printData]);
- }
- //修改货位号 ssh 20240410
- public function actionModifySeatSn()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $seatSn = $get['seatSn'] ?? '';
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到采购单');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- $cg->seatSn = $seatSn;
- $cg->save();
- }
- //获取零售端在进行中的订单 ssh 20231201
- public function actionGetLsRunningOrderNum()
- {
- $lsFhNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 2]);
- $lsShNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 3]);
- util::success(['lsFhNum' => $lsFhNum, 'lsShNum' => $lsShNum]);
- }
- //打印小票 ssh 20230608
- public function actionPrintBill()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $order = $get['order'] ?? 1;
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到采购单');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- if (getenv('YII_ENV') == 'production') {
- //小向的采购单要打印二张
- if ($this->mainId == 23390) {
- //PurchaseOrderClass::printTicket($cg, false, $order);
- }
- }
- PurchaseOrderClass::printTicket($cg, false, $order);
- util::complete();
- }
- //增加打印次数 ssh 20240511
- public function actionAddPrintNum()
- {
- util::complete();
- }
- //打印全部 ssh 20220602
- public function actionPrintAll()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? 0;
- $type = $get['type'] ?? 0;
- $priceOption = $get['priceOption'] ?? 0;
- $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (empty($itemList)) {
- util::fail('没有商品');
- }
- $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
- $mainId = $order->mainId ?? 0;
- $ext = $this->shopExt;
- $printLabelSn = $ext->printLabelSn ?? '';
- if (empty($printLabelSn)) {
- util::fail('请设置标签打印机');
- }
- $p = new printUtil($printLabelSn);
- $ids = [];
- foreach ($itemList as $key => $item) {
- $productId = $item->productId ?? 0;
- $ids[] = $productId;
- }
- $ids = array_unique($ids);
- $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- foreach ($itemList as $key => $item) {
- $name = $item->name ?? '';
- $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
- if (empty($num)) {
- util::fail('没有花材数量');
- }
- $ptItemId = $item->itemId ?? '';
- $productId = $item->productId ?? 0;
- $p->times = $num;
- $smallUnit = $item->smallUnit ?? '';
- $ratio = $item->ratio ?? 0;
- $unit = $ratio . $smallUnit . '装';
- if (isset($item->ratioType) && $item->ratioType == 1) {
- $unit = '若干' . $smallUnit . '装';
- }
- $price = $infoList[$productId] && $infoList[$productId]['skPrice'] ? $infoList[$productId]['skPrice'] : 0;
- $price = floatval($price);
- 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 ($key % 2 == 1) {
- $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="0">.</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>';
- } elseif ($mainId == 72057) {
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里小榄店</TEXT>';
- } else {
- if($priceOption == 0){
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
- }else{
- $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . ' ' . $price . '元</TEXT>';
- }
- }
- } else {
- if (getenv('YII_ENV') == 'production') {
- $doublePrice = [52, 1459];
- } else {
- $doublePrice = [];
- }
- if (in_array($this->mainId, $doublePrice)) {
- //惠雅鲜花,打价格,显示正价和会员价,多处同步修改,关键词 hy_print_label_price ssh 20260101
- $hyPrice = $infoList[$productId] && $infoList[$productId]['price'] ? $infoList[$productId]['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>';
- }elseif ($this->mainId == 4556) {
- //打价格,显示零售价,并且不带元,杭州斗南鲜花不要带元
- $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '</TEXT>';
- } else {
- $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '元</TEXT>';
- }
- }
- $p->printLabelMsg($content);
- }
- util::complete();
- }
- //打印全部 ssh 20220
- public function actionPrintItem()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $type = $get['type'] ?? 0;
- $item = PurchaseOrderItemClass::getById($id, true);
- if (empty($item)) {
- util::fail('没有找到花材');
- }
- $name = $item->name ?? '';
- $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
- if (empty($num)) {
- util::fail('没有花材数量');
- }
- $orderSn = $item->orderSn ?? '';
- $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
- $mainId = $order->mainId ?? 0;
- $ext = $this->shopExt;
- $printLabelSn = $ext->printLabelSn ?? '';
- if (empty($printLabelSn)) {
- util::fail('请设置标签打印机');
- }
- $p = new printUtil($printLabelSn);
- $productId = $item->productId ?? 0;
- $product = ProductClass::getById($productId, true);
- $smallUnit = $product->smallUnit ?? '';
- $bigUnit = $product->bigUnit ?? '';
- $ratio = $product->ratio ?? 20;
- $ratioType = $product->ratioType ?? 0;
- if ($ratioType == 1) {
- $unit = '若干' . $smallUnit . '/' . $bigUnit;
- } else {
- $unit = $ratio . $smallUnit . '/' . $bigUnit;
- }
- $ptItemId = $item->itemId ?? '';
- $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 ($type == 0) {
- $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $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>';
- } elseif ($mainId == 72057) {
- $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=" . $productId . '</QR>';
- $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
- }
- $p->printLabelMsg($content);
- util::complete();
- }
- //取消入库单 ssh 20221211
- public function actionCancel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseOrderClass::getLockById($id);
- if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
- util::fail('请确认是否您的采购单');
- }
- if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
- util::fail('已取消过了');
- }
- if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
- util::fail('已入库,无法取消');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
- PurchaseOrderClass::cancel($cg, $shop, $params);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- util::fail('取消失败');
- }
- }
- //确认入库 sssh 20221211
- public function actionConfirmPutIn()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopAdmin = $this->shopAdmin;
- if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseOrderClass::getLockById($id);
- if (!isset($cg->mainId) || $cg->mainId != $this->mainId) {
- util::fail('请确认是否您的采购单');
- }
- //解决重复请求问题
- $cacheKey = 'confirm_put_in_action_' . $id;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('请5秒后操作');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
- $staff = $this->shopAdmin;
- $data = [];
- $data['staffId'] = $staff->id ?? 0;
- $data['staffName'] = $staff->name ?? '';
- $data['adminId'] = $this->adminId ?? 0;
- $data['shop'] = $this->shop;
- $return = PurchaseOrderClass::putIn($cg, $data);
- $transaction->commit();
- //入库成功通知相关人员,关键词 put_in_notice
- //$shop = $this->shop;
- //WxMessageClass::ghsCgEntryInform($shop, $cg);
- util::success($return);
- } catch (\Exception $e) {
- $transaction->rollBack();
- noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
- Yii::error("确认入库失败,原因:" . $e->getMessage());
- util::fail('确认失败');
- }
- }
- //新增采购订单
- public function actionCreateOrder()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- //避免重复提交
- $adminId = $this->adminId;
- util::checkRepeatCommit($adminId, 10);
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $staff = $this->shopAdmin;
- //以下二个都需要保留
- $post['staffId'] = $staff->id ?? 0;
- $post['staffName'] = $staff->name ?? '';
- $post['shopAdminId'] = $staff->id ?? 0;
- $post['shopAdminName'] = $staff->name ?? '';
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- if (getenv('YII_ENV') == 'production') {
- //小向花卉采购控制
- if ($this->mainId == 23390) {
- if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
- util::fail('你不能采购哦');
- }
- }
- }
- $shop = $this->shop;
- $carSale = $shop->carSale ?? 0;
- if ($carSale == 1) {
- util::fail('车销不能采购');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
- $ghsItemInfo = $post['itemInfo'] ?? '';
- if (empty($ghsItemInfo)) {
- util::fail('请选择花材');
- }
- $ghsItemInfo = json_decode($ghsItemInfo, true);
- if (!is_array($ghsItemInfo)) {
- util::fail('花材格式不正确');
- }
- //合并
- $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
- //判断花材格式,是否属于当前门店
- ProductClass::valid($ghsItemInfo, $this->mainId);
- $cgStaffId = $post['cgStaffId'] ?? 0;
- if (empty($cgStaffId)) {
- $mainId = $this->mainId;
- if (getenv('YII_ENV') == 'production') {
- //花大苪、鹏诚康乃馨 采购入库必须选择采购人
- if (in_array($mainId, [8164, 19606])) {
- util::fail('请选择采购人');
- }
- } else {
- if (in_array($mainId, [])) {
- util::fail('请选择采购人');
- }
- }
- }
- //获取供货商信息
- $ghsId = $post['ghsId'];
- if (empty($ghsId)) {
- util::fail("请选择供货商");
- }
- $ghsInfo = GhsClass::getGhsInfo($ghsId);
- GhsClass::valid($ghsInfo, $this->shopId);
- $post['ghsInfo'] = json_encode($ghsInfo);
- $post['ghsName'] = $ghsInfo['name'] ?? '';
- $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if (!empty($bookSn)) {
- if (empty($cgStaffId)) {
- util::fail('请选择采购人哦');
- }
- }
- //只查我负责的花材
- $globalCgMyCharge = $post['globalCgMyCharge'] ?? 0;
- $needCgList = [];
- if ($globalCgMyCharge == 1) {
- $staffId = $staff->id ?? 0;
- if (!empty($bookSn)) {
- $bList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
- if (!empty($bList)) {
- $myIds = [];
- foreach ($bList as $bInfo) {
- $biProductId = $bInfo->itemId ?? 0;
- if ($bInfo->needCgNum > 0) {
- $myIds[] = $biProductId;
- $needCgList[$biProductId] = $bInfo->needCgNum;
- }
- }
- }
- }
- }
- //判断花材里的信息
- foreach ($ghsItemInfo as $v) {
- $bigNum = $v['bigNum'] ?? 0;
- $productId = $v['productId'] ?? 0;
- $smallNum = $v['smallNum'] ?? 0;
- $name = $v['name'] ?? '';
- if (!isset($v['itemPrice'])) {
- util::fail('采购价格不能为空');
- }
- if (!$productId) {
- util::fail('花材不存在');
- }
- if ($bigNum <= 0 && $smallNum <= 0) {
- util::fail('花材数量不能为0');
- }
- //城市批发店限制不能让其录小单位,太多人录错,昆明批发不知道有没人录,暂时不限制。 ssh 20250308
- if ($shop->pfLevel == 0) {
- if ($smallNum > 0) {
- util::fail('不能录小单位:' . $name);
- }
- }
- if ($globalCgMyCharge == 1) {
- if (isset($needCgList[$productId]) == false) {
- util::fail($name . ' 不需要采购');
- }
- $needNum = $needCgList[$productId];
- if ($bigNum > $needNum) {
- util::fail($name . ' 只要采' . $needNum . '份');
- }
- }
- }
- $post['itemInfo'] = $ghsItemInfo;
- //0稍后入库 1直接入库
- $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
- if (!empty($bookSn)) {
- //有预订,不要直接入库
- $inType = PurchaseOrderClass::IN_TYPE_LATER;
- $post['inType'] = $inType;
- }
- if ($shop->pfLevel == 1) {
- //昆明批发,不要直接入库
- $inType = PurchaseOrderClass::IN_TYPE_LATER;
- $post['inType'] = $inType;
- }
- $post['bookSn'] = $bookSn;
- $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
- $post['debt'] = $debtStatus;
- $order = PurchaseOrderClass::addOrder($post);
- //如果是附近供货商,则采购单标记为外采单
- if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
- $order->location = 1;
- $order->save();
- }
- $transaction->commit();
- if (isset($order->needPrint) && $order->needPrint == 1) {
- PurchaseOrderClass::printTicket($order);
- }
- if (!empty($bookSn) && $inType == 0) {
- //如果是昆明批发,有开启预订则直接分配货位
- $key = 'ghs_cg_order_scan_seat_' . $order->id;
- $noLock = util::lock($key);
- if ($noLock) {
- //没有锁定,即没有在分配货位,可以进行货位分配
- $params = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name];
- PurchaseOrderClass::assign($order, $shop, $params);
- util::unlock($key);
- }
- }
- util::success($order);
- } catch (\Exception $e) {
- $transaction->rollBack();
- noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
- Yii::error("操作失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //分配货位号 ssh 20240619
- public function actionAssignSeat()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $salt = $get['salt'] ?? '';
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到采购单');
- }
- //不是待入库状态不需要分配
- if ($cg->status != 3) {
- util::success(['assign' => 0, 'hint' => 'cg is no wait for entry']);
- }
- $cgBookSn = $cg->bookSn ?? 0;
- if (empty($cgBookSn)) {
- util::success(['assign' => 0, 'hint' => 'cg bookSn is empty']);
- }
- $adminId = $this->adminId;
- if (!empty($adminId) && empty($salt)) {
- if ($cg->mainId != $this->mainId) {
- util::success(['assign' => 0, 'hint' => 'cg mainId != this mainId']);
- }
- $shop = $this->shop;
- $bookSn = $shop->bookSn ?? 0;
- if ($bookSn != $cgBookSn) {
- util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn']);
- }
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $staffName = $staff->name ?? '';
- $params = ['staffId' => $staffId, 'staffName' => $staffName];
- } else {
- if ($cg->salt != $salt) {
- util::success(['assign' => 0, 'hint' => 'cg salt != post salt']);
- }
- $shopId = $cg->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::success(['assign' => 0, 'hint' => 'shop empty']);
- }
- if ($shop->bookSn != $cgBookSn) {
- util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn o']);
- }
- $staffId = $cg->shopAdminId ?? 0;
- $staffName = $cg->shopAdminName ?? '';
- $params = ['staffId' => $staffId, 'staffName' => $staffName];
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- PurchaseOrderClass::assign($cg, $shop, $params);
- $transaction->commit();
- util::success(['assign' => 1]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- util::fail('获取失败');
- }
- }
- //订单列表
- public function actionList()
- {
- $where = [];
- $get = Yii::$app->request->get();
- $export = $get['export'] ?? 0;
- $where['shopId'] = $this->shopId;
- $orderStatus = $get['status'] ?? '';
- if ($orderStatus) {
- $where['status'] = $orderStatus;
- }
- $ghsId = $get['ghsId'] ?? 0;
- if (!empty($ghsId)) {
- $where['ghsId'] = $ghsId;
- }
- $search = '';
- $name1 = $get['search'] ?? '';
- if (!empty($name1)) {
- $search = $name1;
- }
- $name2 = $get['name'] ?? '';
- if (!empty($name2)) {
- $search = $name2;
- }
- if (!empty($search)) {
- $ret = strstr($search, 'PH');
- if (is_numeric($search) && strlen($search) == 4) {
- $where['checkCode'] = $search;
- } elseif (!empty($ret)) {
- $where['orderSn'] = $search;
- } else {
- $where['ghsName'] = ['like', $search];
- }
- }
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $cgStaffId = $get['cgStaffId'] ?? 0;
- if (!empty($cgStaffId)) {
- $where['cgStaffId'] = $cgStaffId;
- }
- if ($export == 1) {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- if (isset($where['entryTime']) == false) {
- util::fail('请选时间段');
- }
- $start = $where['entryTime'][1][0];
- $end = $where['entryTime'][1][1];
- $monthTime = bcmul(31, 86400);
- $startArea = strtotime($start);
- $endArea = strtotime($end);
- $diff = bcsub($endArea, $startArea);
- if ($diff > $monthTime) {
- util::fail('最长可导出一个月');
- }
- }
- $adminId = $this->adminId;
- $mainId = $this->mainId;
- //采购限制访问,有多处要同步修改,权限管理问题,关键词cg_limit_access
- if (getenv('YII_ENV') == 'production') {
- //纯彩花艺
- if ($this->mainId == 10) {
- if (!in_array($this->adminId, [37, 988, 14346])) {
- util::fail('没有数据哦,编号1792');
- }
- }
- //天天鲜花十堰店
- if ($this->mainId == 7184) {
- if (!in_array($this->adminId, [8340, 8345, 9433])) {
- util::fail('没有数据哦,编号1592');
- }
- }
- //小向花卉采购控制
- if ($this->mainId == 23390) {
- if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
- util::fail('没有数据哦,编号2292');
- }
- }
- //中山淘花里采购控制,多处要修改,搜索关键词 thl_cg_control
- if ($mainId == 16948) {
- if (!in_array($adminId, [55494, 55445, 17908, 55459, 55707, 4, 55709])) {
- util::fail('暂时不能查看哦,编号6811');
- }
- }
- //贴心鲜花批发,只有老板可以查看
- if ($mainId == 15144) {
- if (!in_array($adminId, [16163])) {
- util::fail('暂时不能查看哦,编号6818');
- }
- }
- //捷芳鲜花批发,限制不能查看采购权限的人
- if ($mainId == 45354) {
- if (in_array($adminId, [47094, 47130])) {
- util::fail('暂时不能查看哦,编号6822');
- }
- }
- }
- $data = PurchaseOrderClass::getOrderList($where);
- if ($export == 1) {
- PurchaseOrderClass::exportOrderData($data, $this->mainId);
- }
- //状态统计,很慢,暂时隐藏
- //$statData = PurchaseOrderClass::statNum($this->shopId);
- $statData = [
- 'allNum' => 0,
- 'unPayNum' => 0,
- 'unSendNum' => 0,
- 'sendingNum' => 0,
- 'finishNum' => 0,
- ];
- $data = array_merge($data, $statData);
- util::success($data);
- }
- //订单详情
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? '';
- $salt = $get['salt'] ?? '';
- $adminId = $this->adminId ?? 0;
- $onBooking = 0;
- if (!empty($adminId) && empty($salt)) {
- $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
- $shop = $this->shop;
- $bookSn = $orderData['bookSn'] ?? 0;
- $shopBookSn = $shop->bookSn ?? 0;
- if (!empty($shopBookSn) && $shopBookSn == $bookSn) {
- $onBooking = 1;
- }
- $pfLevel = $shop->pfLevel ?? 0;
- } else {
- $info = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($info)) {
- util::fail('没有找到采购单');
- }
- if ($info->salt != $salt) {
- util::fail('不是你的采购单');
- }
- $shopId = $info->shopId ?? 0;
- $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $shopId);
- $shop = ShopClass::getById($shopId, true);
- $pfLevel = $shop->pfLevel ?? 0;
- }
- $mainId = $this->mainId;
- $staff = $this->shopAdmin;
- $addTime = $orderData['addTime'] ?? '';
- $currentTime = time();
- $hasOver = false;
- $overTime = $currentTime - strtotime($addTime);
- $overDay = ceil($overTime / 86400);
- if ($overDay > 3) {
- $hasOver = true;
- }
- if (getenv('YII_ENV') == 'production') {
- //花大苪没有财务权限的人,采购单只能看最近3天
- if ($mainId == 8164) {
- if (!isset($staff->finance) || $staff->finance == 0) {
- if ($hasOver) {
- util::fail('超过3天,暂时无法查看');
- }
- }
- }
- //中山淘花里采购控制,多处要修改,搜索关键词 thl_cg_control
- if ($mainId == 16948) {
- if (!in_array($adminId, [55494, 55445, 17908, 55459, 55707, 4, 55709])) {
- util::fail('暂时不能查看哦,编号6892');
- }
- }
- }
- $orderData['onBooking'] = $onBooking;
- $orderData['pfLevel'] = $pfLevel;
- util::success($orderData);
- }
- //采购页,定时检测货位有没更新 ssh 20240709
- public function actionCheckSeatUpdate()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? '';
- $salt = $get['salt'] ?? '';
- if (empty($orderSn)) {
- util::success(['need' => 0, 'hint' => 'empty orderSn']);
- }
- $cg = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($cg)) {
- util::success(['need' => 0, 'hint' => 'empty cg info']);
- }
- $adminId = $this->adminId ?? 0;
- $cgId = $cg->id ?? 0;
- $cgBookSn = $cg->bookSn ?? 0;
- if (!empty($adminId) && empty($salt)) {
- if ($cg->mainId != $this->mainId) {
- util::success(['need' => 0, 'hint' => 'cgMainId != thisMainId']);
- }
- $shop = $this->shop;
- $shopBookSn = $shop->bookSn ?? 0;
- if (empty($shopBookSn)) {
- util::success(['need' => 0, 'hint' => 'empty shopBookSn']);
- }
- if ($shopBookSn != $cgBookSn) {
- util::success(['need' => 0, 'hint' => 'shopBookSn!=cgBookSn']);
- }
- $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $cgBookSn;
- $staff = $this->shopAdmin;
- $staffId = $staff->id ?? 0;
- $element = $cgId . '-' . $staffId;
- $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $element]);
- if (!empty($exists)) {
- Yii::$app->redis->executeCommand('SREM', [$cacheKey, $element]);
- util::success(['need' => 1]);
- }
- } else {
- if ($cg->salt != $salt) {
- util::success(['need' => 0, 'hint' => 'cg salt != post salt']);
- }
- $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $cgBookSn;
- $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $cgId]);
- if (!empty($exists)) {
- Yii::$app->redis->executeCommand('SREM', [$cacheKey, $cgId]);
- util::success(['need' => 1]);
- }
- }
- util::success(['need' => 0, 'hint' => 'real no need']);
- }
- //修改备注
- public function actionUpdateRemark()
- {
- $remark = Yii::$app->request->post('remark', '');
- $id = Yii::$app->request->post('id', '');
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到订单');
- }
- if ($cg->shopId != $this->shopId) {
- util::fail('没有权限修改');
- }
- $cg->remark = $remark;
- $cg->save();
- util::complete('修改成功');
- }
- //应付款统计 ssh 20240528
- public function actionDueList()
- {
- $get = Yii::$app->request->get();
- $mainId = $this->mainId;
- $export = $get['export'] ?? 0;
- $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : 0;
- $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
- $start = $period['startTime'];
- $end = $period['endTime'];
- $ghsList = GhsClass::getAllByCondition(['ownShopId' => $this->shopId], null, 'id,name', 'id');
- $currentStartDate = date('Y-m-d', strtotime($start));
- $currentEndDate = date('Y-m-d', strtotime($end));
- $currentStartTime = $currentStartDate . ' 00:00:00';
- $currentEndTime = $currentEndDate . ' 23:59:59';
- $cgWhere = ['mainId' => $mainId, 'status' => 4];
- if ($debt > 0) {
- $cgWhere['debt'] = $debt;
- }
- $cgWhere['entryTime'] = ['between', [$currentStartTime, $currentEndTime]];
- $cgList = PurchaseOrderClass::getAllByCondition($cgWhere, null, '*');
- $list = [];
- $totalAmount = 0;
- if (!empty($cgList)) {
- foreach ($cgList as $cgInfo) {
- $actPrice = $cgInfo['actPrice'] ?? 0;
- $ghsId = $cgInfo['ghsId'] ?? 0;
- if (isset($list[$ghsId])) {
- $list[$ghsId]['amount'] = bcadd($list[$ghsId]['amount'], $actPrice, 2);
- $list[$ghsId]['num'] = bcadd($list[$ghsId]['num'], 1);
- } else {
- $name = $ghsList[$ghsId] && $ghsList[$ghsId]['name'] ? $ghsList[$ghsId]['name'] : '未命名';
- $list[$ghsId] = ['id' => $ghsId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
- }
- $totalAmount = bcadd($totalAmount, $actPrice, 2);
- }
- $list = array_values($list);
- }
- if ($export == 1) {
- if (empty($list)) {
- util::fail('没有数据需要导出');
- }
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- PurchaseOrderClass::exportDueList($list, $mainId);
- util::stop();
- }
- util::success(['list' => $list, 'totalAmount' => $totalAmount]);
- }
- //修改入库时间 ssh 20240511
- public function actionModifyEntryTime()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $date = $get['date'] ?? '';
- if (empty($date)) {
- util::fail('请选择日期');
- }
- $cg = PurchaseOrderClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到订单');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $mainId = $this->mainId;
- //超管或者约定的人可以修改日期
- if (getenv('YII_ENV') == 'production') {
- if (in_array($mainId, [23390])) {
- if (!in_array($this->adminId, [24586, 23960])) {
- util::fail('你不能修改哦');
- }
- }
- } else {
- if (in_array($mainId, [644])) {
- if (!in_array($this->adminId, [919])) {
- }
- }
- }
- $entryTime = $cg->entryTime;
- $time = strtotime($entryTime);
- $after = date("H:i:s", $time);
- $new = $date . ' ' . $after;
- $cg->entryTime = $new;
- $cg->save();
- util::complete('修改成功');
- }
- //导入采购 ssh 20241126
- public function actionImportCreate()
- {
- $get = Yii::$app->request->get();
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $ghsId = $get['id'] ?? '';
- $file = $_FILES['file'];
- if (!is_uploaded_file($file['tmp_name'])) {
- util::fail('please upload img');
- }
- $mainId = $this->sjId;
- $shopId = $this->shopId;
- $month = date("Ym");
- $date = date("d");
- $path = dirUtil::getImgUploadDir() . "/{$mainId}/cg/{$shopId}/{$month}/{$date}/";
- if (!file_exists($path)) {
- //检查是否有该文件夹,如果没有就创建,并给予最高权限
- mkdir($path, 0700, true);
- }
- $preFileName = stringUtil::uniqueFileName();
- $newFile = $preFileName . ".xls";
- $fullPathFile = $path . $newFile;
- if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
- $arr = [];
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
- $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
- // 获取活动工作表
- $worksheet = $spreadsheet->getActiveSheet();
- // 遍历每一行
- foreach ($worksheet->getRowIterator() as $key => $row) {
- $cellIterator = $row->getCellIterator();
- // 这里设置为迭代所有单元格,包括空单元格
- $cellIterator->setIterateOnlyExistingCells(FALSE);
- // 遍历每列
- $rowData = [];
- foreach ($cellIterator as $cell) {
- $option = $cell->getValue();
- $rowData[] = trim($option);
- }
- $arr[] = $rowData;
- }
- array_shift($arr);
- $productIds = [];
- foreach ($arr as $k => $v) {
- $productId = $v[0] ?? 0;
- $productId = trim($productId);
- if (is_numeric($productId) && $productId > 0) {
- $productIds[] = $productId;
- }
- }
- if (empty($productIds)) {
- util::fail('没有识别出花材');
- }
- $productInfo = ProductClass::getByIds($productIds, null, 'id');
- if (empty($productInfo)) {
- util::fail('没有找到有效花材');
- }
- $ghsItemInfo = [];
- foreach ($arr as $k => $v) {
- $productId = $v[0] ?? 0;
- $productId = trim($productId);
- $num = $v[2] ?? 0;
- $num = trim($num);
- $unitPrice = $v[3] ?? 0;
- $unitPrice = trim($unitPrice);
- if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
- $price = bcmul($unitPrice, $num, 2);
- $product = $productInfo[$productId] ?? [];
- $ptItemId = $product['itemId'] ?? 0;
- $ratio = $product['ratio'] ?? 20;
- $ratioType = $product['ratioType'] ?? 0;
- $ghsItemInfo[] = [
- 'productId' => $productId,
- 'bigNum' => $num,
- 'smallNum' => 0,
- 'itemId' => $ptItemId,
- 'itemPrice' => $unitPrice,
- 'totalPrice' => $price,
- 'assignSeat' => 0,
- 'ratio' => $ratio,
- 'ratioType' => $ratioType,
- 'aboutPrice' => 0,
- ];
- }
- }
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $post = [];
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $post['mainId'] = $this->mainId;
- $staff = $this->shopAdmin;
- //以下二个都需要保留
- $post['staffId'] = $staff->id ?? 0;
- $post['staffName'] = $staff->name ?? '';
- $post['shopAdminId'] = $staff->id ?? 0;
- $post['shopAdminName'] = $staff->name ?? '';
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('没有权限导入库存');
- }
- if (getenv('YII_ENV') == 'production') {
- //小向花卉采购控制
- if ($this->mainId == 23390) {
- if (!in_array($this->adminId, [24586, 24115, 24759, 26390, 23960, 25011, 25004, 24655, 28521, 4, 24043, 77951])) {
- util::fail('你不能采购哦');
- }
- }
- }
- $shop = $this->shop;
- $carSale = $shop->carSale ?? 0;
- if ($carSale == 1) {
- util::fail('车销不能采购');
- }
- //合并
- $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
- //判断花材格式,是否属于当前门店
- ProductClass::valid($ghsItemInfo, $this->mainId);
- $ghsInfo = GhsClass::getGhsInfo($ghsId);
- GhsClass::valid($ghsInfo, $this->shopId);
- $post['ghsId'] = $ghsId;
- $post['ghsInfo'] = json_encode($ghsInfo);
- $post['ghsName'] = $ghsInfo['name'] ?? '';
- $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
- $shop = $this->shop;
- $post['itemInfo'] = $ghsItemInfo;
- //0稍后入库
- $inType = PurchaseOrderClass::IN_TYPE_LATER;
- $post['inType'] = $inType;
- $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
- $post['debt'] = $debtStatus;
- $order = PurchaseOrderClass::addOrder($post);
- $transaction->commit();
- util::success($order);
- } else {
- util::fail('导入失败了哦!');
- }
- } catch (\Exception $e) {
- $transaction->rollBack();
- noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
- Yii::error("导入失败原因:" . $e->getMessage());
- $msg = $e->getMessage();
- util::fail('导入失败:' . $msg);
- }
- }
- }
|