| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427 |
- <?php
- namespace bizGhs\order\classes;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopCapitalClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use biz\shop\models\Shop;
- use biz\sj\classes\SjClass;
- use biz\stat\classes\StatItemClass;
- use biz\stat\classes\StatKdClass;
- use biz\stat\classes\StatKhCgClass;
- use biz\stat\classes\StatOrderCountClass;
- use biz\stat\classes\StatOutClass;
- use biz\stat\classes\StatRefundClass;
- use biz\stat\classes\StatSaleClass;
- use biz\stock\classes\StockClass;
- use bizGhs\custom\models\Custom;
- use bizGhs\express\services\DadaExpressServices;
- use bizGhs\order\models\Order;
- use bizGhs\order\traits\OrderTrait;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\stat\classes\StatYjClass;
- use bizGhs\stock\classes\StockRecordClass;
- use bizGhs\stock\services\StockRecordService;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\stat\classes\StatIncomeClass;
- use bizHd\stat\classes\StatOrderClass;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\imgUtil;
- use common\components\orderSn;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use bizGhs\base\classes\BaseClass;
- use Yii;
- class OrderClass extends BaseClass
- {
- use OrderTrait;
- public static $baseFile = '\bizGhs\order\models\Order';
- //已取消
- const ORDER_STATUS_CANCEL = 5;
- //已完成
- const ORDER_STATUS_COMPLETE = 4;
- //配送中
- const ORDER_STATUS_SENDING = 3;
- //待配送
- const ORDER_STATUS_UN_SEND = 2;
- //待付款,待确认
- const ORDER_STATUS_UN_PAY = 1;
- //出车
- const SEND_TYPE_CAR_GET = 0;
- //到店自取
- const SEND_TYPE_SHOP_GET = 1;
- //发快递
- const SEND_TYPE_THIRD_SEND = 2;
- //未确认
- const SEND_TYPE_UNKNOWN = 1;
- //自取
- const SEND_TYPE_NO = 2;
- //自己送
- const SEND_TYPE_MYSELF = 3;
- //快递送
- const SEND_TYPE_THIRD = 4;
- public static $sendTypeMap = [
- self::SEND_TYPE_UNKNOWN => '未确认',
- self::SEND_TYPE_NO => '自取',
- self::SEND_TYPE_MYSELF => '商家配送',
- self::SEND_TYPE_THIRD => '快递配送',
- ];
- //待付款
- const PAY_STATUS_UN_PAY = 0;
- //已付款
- const PAY_STATUS_HAS_PAY = 1;
- //待配送
- const SEND_STATUS_UN_SEND = 1;
- //配送中
- const SEND_STATUS_SENDING = 2;
- //配送完成
- const SEND_STATUS_COMPLETE = 3;
- //订单总流程数
- const TOTAL_FLOW = 3;
- //清算方式
- //欠款
- const CLEAR_DEBT = 1;
- //已付款
- const CLEAR_HAS_GATHERING = 2;
- //没有欠款
- const DEBT_NO = 0;
- //欠款
- const DEBT_YES = 1;
- //正常订单
- const REFUND_NO = 1;
- //已退款订单
- const REFUND_YES = 2;
- public static $refundMap = [
- self::REFUND_NO => '',
- self::REFUND_YES => '有退款',
- ];
- public static function arrival($order, $data)
- {
- if ($order->stockChange == 1) {
- util::fail('您已操作过了');
- }
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $mainId = $order->mainId ?? 0;
- //product [{"productId":"3674","num":0,"price":1}]
- $product = $data['product'] ?? '';
- if (empty($product)) {
- util::fail('没有花材?');
- }
- $ids = [];
- $format = [];
- foreach ($product as $val) {
- $productId = $val['productId'] ?? 0;
- $ids[] = $productId;
- $format[$productId] = $val;
- }
- $info = ProductClass::getByIds($ids, null, 'id');
- $orderSn = $order->orderSn ?? '';
- $customName = $order->customName ?? '';
- $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (empty($list)) {
- util::fail('没有找到订单的花材');
- }
- $itemPrice = 0;
- $weight = 0;
- foreach ($list as $key => $val) {
- $productId = $val->productId ?? 0;
- $num = $format[$productId]['num'] ?? 0;
- $unitPrice = $format[$productId]['price'] ?? 0;
- $price = bcmul($unitPrice, $num, 2);
- $name = $val->name ?? '';
- $xhUnitName = $val->xhUnitName ?? '';
- $xhPreNum = $val->xhPreNum ?? 0;
- if ($unitPrice <= 0) {
- util::fail('花材金额需要大于0');
- }
- if ($num > $xhPreNum) {
- util::fail($name . "数量不能超过{$xhPreNum}{$xhUnitName}");
- }
- $val->cost = $unitPrice;
- $val->unitPrice = $unitPrice;
- $val->price = $price;
- $val->bigNum = $num;
- $val->num = $num;
- $val->xhNum = $num;
- $val->xhUnitPrice = $unitPrice;
- $val->xhPrice = $price;
- $val->save();
- if ($val->xhPreNum > $num) {
- //客户下单退货数增加
- $subNum = bcsub($val->xhPreNum, $num);
- StatKhCgClass::ghsBookOrderRefundNum($order, $subNum);
- //花材销量榜减少
- StatItemClass::ghsBookOrderRefundNum($order, $val, $subNum);
- }
- $itemPrice = bcadd($itemPrice, $price, 2);
- $productWeight = $info[$productId]['weight'] ?? 0;
- $currentWeight = bcmul($productWeight, $num, 2);
- $weight = bcadd($currentWeight, $weight, 2);
- //减少库存
- $unitType = $val->xhUnitType ?? 0;
- $bigNum = 0;
- $smallNum = 0;
- if ($unitType == dict::getDict('unitType', 'big')) {
- $bigNum = $num;
- $itemNum = $num;
- } else {
- $smallNum = $num;
- $itemNum = bcdiv($num, $val->ratio, 2);
- }
- $checkStock = true;
- $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $shopId;
- $recordData['mainId'] = $mainId;
- $recordData['itemId'] = $val->itemId;
- $recordData['itemNum'] = $itemNum;
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $productId;
- $recordData['orderSn'] = $orderSn;
- $recordData['relateName'] = $customName;
- $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- StockRecordClass::addSellStockOrderRecord($recordData);
- }
- $order->itemPrice = $itemPrice;
- $sendCost = 0;
- $currentPrice = bcadd($itemPrice, $sendCost, 2);
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- $main->unSendOrder -= 1;
- $main->finishOrder += 1;
- $main->save();
- $kiloFee = $shop->kiloFee ?? 0;
- $miniKilo = $shop->miniKilo ?? 0;
- $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
- $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
- $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
- $order->prePrice = $currentPrice;
- $order->orderPrice = $currentPrice;
- $order->actPrice = $currentPrice;
- $order->realPrice = $currentPrice;
- $order->stockChange = 1;
- $order->status = self::ORDER_STATUS_COMPLETE;
- $order->save();
- $bookPrice = $order->bookPrice ?? 0;
- $mainId = $shop->mainId ?? 0;
- $sjId = $shop->sjId ?? 0;
- $customId = $order->customId ?? 0;
- $relateOrderSn = $order->orderSn ?? '';
- $shopAdminId = $data['shopAdminId'] ?? 0;
- $shopAdminName = $data['shopAdminName'] ?? '';
- $refund = null;
- if ($bookPrice != $currentPrice) {
- if ($bookPrice > $currentPrice) {
- $refundPrice = bcsub($bookPrice, $currentPrice, 2);
- $order->refundPrice = $refundPrice;
- $order->tkPrice = bcadd($order->tkPrice, $refundPrice, 2);
- $order->refund = self::REFUND_YES;
- $order->save();
- $orderSn = orderSn::getGhsRefundSn();
- $book = 1;
- $refundData = [
- 'mainId' => $mainId,
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'customId' => $customId,
- 'orderSn' => $orderSn,
- 'relateOrderSn' => $relateOrderSn,
- 'book' => $book,
- 'status' => RefundOrderClass::STATUS_UN_COMPLETE,
- 'shopAdminId' => $shopAdminId,
- 'shopAdminName' => $shopAdminName,
- 'refundPrice' => $refundPrice,
- 'refundType' => RefundOrderClass::REFUND_TYPE_MONEY,
- ];
- //退款
- $refund = RefundOrderClass::add($refundData, true);
- //余额减少
- ShopClass::ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice);
- //总支出增加
- $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
- $main->totalExpend = $currentTotalExpend;
- $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
- $main->totalRefund = $totalRefund;
- $main->save();
- //支出流水
- $thisType = dict::getDict('capitalType', 'ghsBookRefund', 'id');
- $sjId = $order->sjId ?? 0;
- $event = "预订单多付退给{$customName}";
- $capitalData = [
- 'capitalType' => $thisType,
- 'io' => 0,
- 'totalExpend' => $currentTotalExpend,
- 'payWay' => 0,
- 'amount' => $refundPrice,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'event' => $event,
- 'mainId' => $mainId,
- ];
- ShopCapitalClass::addCapital($capitalData);
- //支出统计
- StatOutClass::updateOrInsert($main, $shop, $refundPrice);
- //退款统计
- $payWay = $order->payWay ?? 0;
- StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
- //供货商预订单退款给客户,客户采购金额减少
- StatKhCgClass::ghsBookOrderChange(false, $order, $refundPrice);
- } else {
- //欠款
- $currentDebt = bcsub($currentPrice, $bookPrice, 2);
- $order->debtPrice = $currentDebt;
- $order->remainDebtPrice = $currentDebt;
- $order->debt = OrderClass::DEBT_YES;
- $order->save();
- $currentTotalIncome = bcadd($main->totalIncome, $currentDebt, 2);
- $main->totalIncome = $currentTotalIncome;
- $main->save();
- $payWay = dict::getDict('payWay', 'debtPay');
- $custom = CustomClass::getLockById($customId);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- CustomClass::cgDebtAmountAdd($custom, $order, true);
- //收入增加
- StatIncomeClass::updateOrInsert($main, $shop, $currentDebt);
- //收入流水增加
- $orderId = $order->id;
- $capitalType = dict::getDict('capitalType', 'ghsBookOrderGetBack', 'id');
- $shopAdminId = $order->shopAdminId ?? 0;
- $shopAdminName = $order->shopAdminName ?? '';
- $event = "预订单 {$orderSn} 差价补款";
- $mainId = $shop->mainId ?? 0;
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $capital = [
- 'capitalType' => $capitalType,
- 'relateId' => $orderId,
- 'io' => 1,
- 'amount' => $currentDebt,
- 'totalIncome' => $currentTotalIncome,
- 'payWay' => $payWay,
- 'event' => $event,
- 'mainId' => $mainId,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'shopAdminId' => $shopAdminId,
- 'shopAdminName' => $shopAdminName,
- ];
- ShopCapitalClass::addCapital($capital);
- //各渠道收入金额统计
- StatKdClass::replace($shop, $currentDebt, $payWay);
- //每天销售收入统计
- StatSaleClass::replace($main, $shop, $currentDebt);
- //预订单,客户补款给供货商,客户采购金额增加
- StatKhCgClass::ghsBookOrderChange(true, $order, $currentDebt);
- }
- }
- return ['kiloFee' => $kiloFee, 'refund' => $refund, 'miniKilo' => $miniKilo];
- }
- //添加订单 ssh 2019.12.5
- public static function addOrder($data)
- {
- $orderSn = orderSn::getGhsOrderSn();
- $data['orderSn'] = $orderSn;
- $data['payStatus'] = self::PAY_STATUS_UN_PAY;
- $data['customId'] = isset($data['customId']) && !empty($data['customId']) ? $data['customId'] : 0;
- $currentShopId = $data['shopId'] ?? 0;
- $shop = ShopClass::getLockById($currentShopId);
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- //花材
- $product = $data['product'];
- $book = $data['book'] ?? 0;
- $stockMayChange = true;
- $data['stockChange'] = 1;
- if ($book == 1) {
- $stockMayChange = false;
- $data['stockChange'] = 0;
- }
- $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange);
- $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
- $data['sendCost'] = $sendCost;
- $data['bigNum'] = $respond['bigNum'] ?? 0;
- $data['smallNum'] = $respond['smallNum'] ?? 0;
- $data['itemNum'] = $respond['totalItemNum'] ?? 0;
- //默认订单要打单
- $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
- $weight = $respond['weight'] ?? 0;
- $data['weight'] = $weight;
- $itemPrice = $respond['price'] ?? 0;
- $data['itemPrice'] = $itemPrice;
- $currentPrice = bcadd($itemPrice, $sendCost, 2);
- $packCost = isset($data['packCost']) && $data['packCost'] > 0 ? $data['packCost'] : 0;
- $currentPrice = bcadd($currentPrice, $packCost, 2);
- //预订单需要增加服务费
- if ($book == 1) {
- $kiloFee = $shop->kiloFee ?? 0;
- $miniKilo = $shop->miniKilo ?? 0;
- $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
- $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
- $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
- $data['allKiloFee'] = $allKiloFee;
- $data['kiloFee'] = $kiloFee;
- $data['miniKilo'] = $miniKilo;
- }
- $data['prePrice'] = $currentPrice;
- $actPrice = $currentPrice;
- $realPrice = $currentPrice;
- //商家自己开单时
- if (isset($data['modifyPrice'])) {
- $modifyPrice = $data['modifyPrice'] ?? 0;
- if ($modifyPrice <= 0) {
- util::fail('收款金额必须大于0');
- }
- if ($modifyPrice > $currentPrice) {
- //人工和资材费用
- $data['labourCost'] = bcsub($modifyPrice, $currentPrice, 2);
- }
- if ($modifyPrice < $currentPrice) {
- //优惠金额
- $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
- $data['discountType'] = dict::getDict('discountType', 'discount');
- }
- $actPrice = $modifyPrice;
- $realPrice = $modifyPrice;
- }
- //客户采购时使用红包时
- if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'hb')) {
- $discountAmount = $data['discountAmount'] ?? 0;
- $currentDiscountPrice = bcsub($currentPrice, $discountAmount, 2);
- $actPrice = $currentDiscountPrice;
- $realPrice = $currentDiscountPrice;
- }
- $data['actPrice'] = $actPrice;
- $data['bookPrice'] = $actPrice;
- $data['orderPrice'] = $actPrice;
- $data['realPrice'] = $realPrice;
- $data['sendTimeWant'] = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
- //订单有效期
- $validTime = dict::getDict('order_pay_has_time');
- $current = time() + $validTime;
- $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
- $data['status'] = self::ORDER_STATUS_UN_PAY;
- $main->totalOrder += 1;
- $main->unPayOrder += 1;
- $main->save();
- //将当天日期+花店每天的总订单数作为编号
- $data['sendNum'] = date("j") . StatOrderCountClass::addOrder($shop, $main);
- //订单有效期
- $currentTime = time();
- $validTime = dict::getDict('order_pay_has_time');
- $current = $currentTime + $validTime;
- $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
- //订单自动记为欠款单时间
- $localConfirmTime = dict::getDict('local_gys_kd_auto_set_debt_time');
- $currentSet = $currentTime + $localConfirmTime;
- $data['autoSetTime'] = $data['autoSetTime'] ?? date("Y-m-d H:i:s", $currentSet);
- $return = self::add($data, true);
- return $return;
- }
- //修改订单 ssh 2019.12.5
- public static function updateOrder($order, $data)
- {
- $sjId = $order->sjId ?? 0;
- $orderSn = $order->orderSn ?? 0;
- $currentShopId = $order->shopId ?? 0;
- $data['payStatus'] = self::PAY_STATUS_UN_PAY;
- //花材列表
- $product = $data['product'];
- //删除花材再添加
- OrderItemClass::deleteByCondition(['orderSn' => $orderSn]);
- $respond = OrderItemClass::replaceItem($orderSn, $product, $data);
- $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
- $data['sendCost'] = $sendCost;
- $data['bigNum'] = $respond['bigNum'] ?? 0;
- $data['smallNum'] = $respond['smallNum'] ?? 0;
- $price = $respond['price'] ?? 0;
- $currentPrice = bcadd($price, $sendCost, 2);
- $data['prePrice'] = $currentPrice;
- if (isset($data['modifyPrice'])) {
- //商家打折,修改金额
- $modifyPrice = $data['modifyPrice'] ?? 0;
- if ($modifyPrice > $currentPrice) {
- util::fail('实收金额大于订单总金额');
- }
- if ($modifyPrice < $currentPrice) {
- $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
- $data['discountType'] = dict::getDict('discountType', 'discount');
- $currentPrice = $modifyPrice;
- }
- }
- $data['actPrice'] = $currentPrice;
- $data['realPrice'] = $currentPrice;
- //如果有平台补贴
- if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'usePtCoupon')) {
- $discountAmount = $data['discountAmount'] ?? 0;
- $data['realPrice'] = bcsub($currentPrice, $discountAmount, 2);
- }
- $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
- //订单有效期
- $validTime = dict::getDict('order_pay_has_time');
- $current = time() + $validTime;
- $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
- $data['status'] = self::ORDER_STATUS_UN_PAY;
- //计算总重量(kg)
- $weight = 0;
- $productMapData = ProductClass::getProductMapData($product);
- foreach ($product as $key => $val) {
- $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
- $productId = $val['productId'];
- $weight = bcadd($w, $weight, 2);
- $checkStock = true;
- $stockInfo = ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum'], $checkStock);
- //记录库存流水
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $currentShopId;
- $recordData['itemId'] = $productMapData[$productId]['itemId'] ?? 0;
- $ratio = $productMapData[$productId]['ratio'] ?? 0;
- $recordData['itemNum'] = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $productId;
- $recordData['orderSn'] = $orderSn;
- StockRecordClass::addSellStockOrderRecord($recordData);
- }
- $data['weight'] = $weight;
- $current = time() + 300;
- $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
- //修改订单暂时不打印
- $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
- $orderId = $order->id ?? 0;
- self::updateById($orderId, $data);
- $return = self::getLockById($orderId);
- //门店总订单数+1
- $shop = ShopClass::getLockById($currentShopId);
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $shop->unPayOrder += 1;
- $shop->cancelOrder -= 1;
- $shop->save();
- return $return;
- }
- //根据订单编号查询 ssh 2021.19
- public static function getByOrderSn($orderSn, $returnObj = false)
- {
- return self::getByCondition(['orderSn' => $orderSn], $returnObj);
- }
- //根据编号列表查订单
- public static function getOrderInfoBySnList($snList)
- {
- $list = self::getAllByCondition(['orderSn' => ['in', $snList]], null, '*', 'orderSn');
- $list = self::groupOrder($list, true, false, false, true);
- return $list;
- }
- //显示操作按钮
- public static function getShowButton($showButton, $isList, $order)
- {
- if ($showButton == false) {
- return [];
- }
- $print = ['type' => 'print', 'show' => 1, 'disable' => 0, 'name' => '打印'];
- $modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材'];
- $confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认'];
- $cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消'];
- $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '到货'];
- if ($isList) {
- //订单列表页显示的按钮
- $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
- $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
- if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
- //待确认订单,打印和修改花材按钮可以使用
- $send['disable'] = 1;
- $selfGet['disable'] = 1;
- $print['disable'] = 0;
- $confirm['disable'] = 0;
- }
- if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
- //待配送订单,改花材按钮不可点,自取可点
- $selfGet['disable'] = 0;
- }
- //自取订单发货按钮置灰
- if ($order['sendType'] == self::SEND_TYPE_NO) {
- $send['disable'] = 1;
- }
- //取消订单置灰
- if ($order['status'] == self::ORDER_STATUS_CANCEL) {
- $send['disable'] = 1;
- $selfGet['disable'] = 1;
- $print['disable'] = 1;
- }
- if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
- $send['name'] = '发货记录';
- }
- return [$send, $selfGet, $print, $confirm];
- } else {
- //订单详情页显示的按钮
- if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) {
- if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
- $arrival['show'] = 1;
- }
- }
- //待确认订单显示延期付和已付款
- if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
- $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款'];
- $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款'];
- $confirm['disable'] = 0;
- return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival];
- }
- //待配送订单显示打印、发货和自取
- if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
- $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
- $send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货'];
- if ($order['hasItem'] == 2) {
- return [$print, $selfGet, $send, $arrival];
- }
- $selfGet['disable'] = 0;
- $send['disable'] = 0;
- return [$print, $selfGet, $send, $arrival];
- }
- //配送中显示按钮
- if ($order['status'] == self::ORDER_STATUS_SENDING) {
- $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
- return [$print, $send, $arrival];
- }
- //完成
- if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
- $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货记录'];
- //自取订单不显示发货按钮
- if ($order['sendType'] == self::SEND_TYPE_NO) {
- $send['show'] = 0;
- }
- return [$print, $send, $arrival];
- }
- //取消订单置灰
- if ($order['status'] == self::ORDER_STATUS_CANCEL) {
- $selfGet['disable'] = 1;
- $send['disable'] = 1;
- $print['disable'] = 1;
- return [$modifyProduct, $arrival];
- }
- return [];
- }
- }
- //显示进度 ssh 2021.3.1
- public static function getShowProgress($showProgress, $order)
- {
- if ($showProgress == false) {
- return [];
- }
- $create = ['name' => '创建', 'complete' => 1];
- $unConfirm = ['name' => '待确认', 'complete' => 0];
- if ($order['status'] > 0) {
- $unConfirm['complete'] = 1;
- }
- $out = ['name' => '出库', 'complete' => 0];
- if ($order['status'] > 1) {
- $out['complete'] = 1;
- }
- return [$create, $unConfirm, $out];
- }
- //退款等需要使用原来的订单花材结构
- public static function getOriginalShowItem($showItem, $order)
- {
- if ($showItem == false) {
- return ['list' => [], 'itemStat' => []];
- }
- $orderSn = $order['orderSn'];
- $list = OrderItemClass::getOrderItem($orderSn);
- $totalPrice = 0;
- $totalBigNum = 0;
- $totalSmallNum = 0;
- $kind = 0;
- $itemStat = [];
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $list[$key]['property'] = $val['rank'] . '级';
- $price = $val['price'];
- $totalPrice = stringUtil::calcAdd($totalPrice, $price);
- $kind++;
- $currentBigNum = $val['bigNum'];
- $currentSmallNum = $val['smallNum'];
- $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
- $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
- }
- $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
- }
- return ['list' => $list, 'itemStat' => $itemStat];
- }
- public static function getShowItem($showItem, $order)
- {
- if ($showItem == false) {
- return ['list' => [], 'itemStat' => []];
- }
- $orderSn = $order['orderSn'];
- $list = OrderItemClass::getOrderItem($orderSn);
- $totalPrice = 0;
- $totalBigNum = 0;
- $totalSmallNum = 0;
- $kind = 0;
- $itemStat = [];
- //小菊增加部分
- $xjAddList = [];
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $price = $val['price'];
- $totalPrice = stringUtil::calcAdd($totalPrice, $price);
- $kind++;
- $currentBigNum = $val['bigNum'];
- $currentSmallNum = $val['smallNum'];
- $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
- $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
- $list[$key]['property'] = '';
- //小菊
- if (isset($val['variety']) && $val['variety'] == 1) {
- $currentItemId = $val['id'] ?? 0;
- $xjList = OrderXjClass::getAllByCondition(['itemId' => $currentItemId], null, '*');
- if (!empty($xjList)) {
- //选了有颜色的小菊才把原小菊删除不显示出来
- unset($list[$key]);
- foreach ($xjList as $xjKey => $xj) {
- $xjBase = $val;
- $num = $xj['num'] ?? 0;
- $price = $xj['price'] ?? 0;
- $name = $xj['name'] ?? '';
- $cover = $xj['cover'] ?? '';
- if ($num > 0) {
- $bigTotalPrice = bcmul($price, $num, 2);
- $xjBase['cover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $xjBase['unitPrice'] = $price;
- $xjBase['price'] = floatval($bigTotalPrice);
- $xjBase['num'] = floatval($num);
- $xjBase['bigNum'] = floatval($num);
- $xjBase['name'] = $name;
- $xjBase['property'] = '';
- $xjBase['userPrice'] = $bigTotalPrice;
- $xjBase['xhNum'] = floatval($num);
- $xjBase['xhPreNum'] = floatval($num);
- $xjBase['xhPrice'] = floatval($bigTotalPrice);
- $xjAddList[] = $xjBase;
- }
- }
- }
- }
- }
- if (!empty($xjAddList)) {
- $list = array_merge($list, $xjAddList);
- }
- $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
- }
- return ['list' => $list, 'itemStat' => $itemStat];
- }
- //订单列表 ssh 2021.1.19
- public static function getOrderList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- if (isset($data['list']) && !empty($data['list'])) {
- foreach ($data['list'] as $key => $val) {
- $data['list'][$key]['customAvatarUrl'] = imgUtil::groupImg('');
- }
- }
- return $data;
- }
- //整合订单员工和供货商等信息 ssh 2021.1.19
- //$isList 是否列表页
- public static function groupOrder($list, $showButton = false, $showItem = false, $showExpress = false, $isList = false)
- {
- if (empty($list)) {
- return $list;
- }
- $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
- $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
- $customIds = array_column($list, 'customId');
- $customIds = array_unique(array_filter($customIds));
- $customInfoList = CustomClass::getByIds($customIds, null, 'id');
- foreach ($list as $key => $val) {
- $adminId = $val['adminId'] ?? 0;
- $list[$key]['adminName'] = $adminInfo[$adminId]['name'] ?? '';
- $list[$key]['customAddress'] = $val['fullAddress'] ?? '';
- //显示列表页的操作按钮
- $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
- //为了列表页的打印按钮能用,列表也强制显示花材
- $showItem = true;
- //退款需要显示原有的花材结构,不显示小菊的多颜色
- $getOriginalItem = Yii::$app->request->get('getOriginalItem', 0);
- $getOriginalItem2 = Yii::$app->request->post('getOriginalItem', 0);
- if ($getOriginalItem == 1 || $getOriginalItem2 == 1) {
- $showItemData = self::getOriginalShowItem($showItem, $val);
- } else {
- $showItemData = self::getShowItem($showItem, $val);
- }
- $list[$key]['product'] = $showItemData['list'];
- $list[$key]['productStat'] = $showItemData['itemStat'];
- $showResetItem = 0;
- //待付款订单显示改花材按钮
- if ($val['status'] == self::PAY_STATUS_UN_PAY) {
- $showResetItem = 1;
- }
- $list[$key]['showResetItem'] = $showResetItem;
- //获取配送进展
- $expressProgress = '';
- if ($val['sendType'] == 4) {
- $expressInfo = OrderExpressClass::getByCondition(['orderSn' => $val['orderSn']]);
- if ($expressInfo) {
- $expressProgress = ['progressName' => OrderExpressClass::$statusMap[$expressInfo['status']] ?? ''];
- }
- }
- $list[$key]['sendTypeName'] = self::$sendTypeMap[$val['sendType']] ?? '未知';
- $list[$key]['expressProgress'] = $expressProgress;
- $list[$key]['customAvatarUrl'] = imgUtil::groupImg($val['customAvatar']);
- $list[$key]['customName'] = isset($val['customId']) && !empty($val['customId']) ? $val['customName'] : '散客';
- $customId = $val['customId'] ?? '';
- $debtAmount = $customInfoList[$customId]['debtAmount'] ?? 0.00;
- //打印数据组合
- $printData = self::getPrintData($val, $debtAmount, $showItemData);
- $list[$key]['printData'] = json_encode($printData);
- $list[$key]['debtAmount'] = $debtAmount;
- $list[$key]['customShopId'] = $customInfoList[$customId]['shopId'] ?? 0;
- }
- return $list;
- }
- public static function printGroup($current, $content, $showPrice = 1)
- {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $productNum = $current['num'] ?? '';
- $count = $current['count'] ?? '';
- $content .= '<B>' . $name . ' ' . $count . '</B><BR>';
- if ($showPrice == 1) {
- $productPrice = $current['price'] ?? '';
- $content .= $productNum . '=' . $productPrice . '<BR>';
- }
- $content .= '--------------------------------<BR>';
- return $content;
- }
- //云打印 ssh 20210709
- public static function onlinePrint($orderInfo, $showPrice = 1)
- {
- if (getenv('YII_ENV') == 'production') {
- //丽子鲜花,客户线上下单,小票上不显示价格
- if (isset($orderInfo->shopId) && $orderInfo->shopId == 1527) {
- if (isset($orderInfo->customShopAdminId) && !empty($orderInfo->customShopAdminId)) {
- $showPrice = 0;
- }
- }
- } else {
- // if (isset($orderInfo->shopId) && $orderInfo->shopId == 36523) {
- // if (isset($orderInfo->customShopAdminId) && !empty($orderInfo->customShopAdminId)) {
- // $showPrice = 0;
- // }
- // }
- }
- $showItem = OrderClass::getShowItem(true, $orderInfo);
- $customId = $orderInfo['customId'] ?? 0;
- $c = CustomClass::getById($customId);
- $debtAmount = $c['debtAmount'] ?? 0.00;
- $fromType = $orderInfo['fromType'] ?? dict::getDict('fromType', 'shop');
- $fromTypeMap = dict::getDict('fromTypeMap');
- $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
- $respond = self::getPrintData($orderInfo, $debtAmount, $showItem);
- $content = '<B>' . $respond['sendNum'] . ' ' . $fromTypeName . '</B><BR>';
- $content .= '--------------------------------<BR>';
- $content .= '<B>' . $respond['custom']['customName'] . '</B><BR><BR>';
- $content .= '<B>' . $respond['custom']['customMobile'] . '</B><BR>';
- $content .= $respond['custom']['fullAddress'] . '<BR>';
- $payDate = date("Y-m-d", strtotime($orderInfo['payTime']));
- $sendTimWant = $orderInfo['sendTimeWant'] ?? '';
- if ($payDate != $sendTimWant) {
- $content .= '<BR>';
- $content .= '送货时间:<BR>';
- $content .= '<B>' . $orderInfo['sendTimeWant'] . '</B><BR>';
- }
- if (isset($orderInfo['book']) && $orderInfo['book'] == 1) {
- $content .= '<B>预订单</B><BR>';
- }
- if (isset($orderInfo['sendType'])) {
- $sendName = '出车';
- if ($orderInfo['sendType'] == 1) {
- $sendName = '自取';
- }
- if ($orderInfo['sendType'] == 2) {
- $sendName = '发快递';
- }
- $content .= '<BR><B>' . $sendName . '</B><BR>';
- }
- if (isset($respond['remark']) && !empty($respond['remark'])) {
- $content .= '<BR>';
- $content .= '备注:<BR>';
- $content .= '<B>' . $respond['remark'] . '</B><BR>';
- }
- $content .= '<BR>';
- $content .= '花材 数量/单价 金额 <BR>';
- $content .= '--------------------------------<BR>';
- $content .= '--------------------------------<BR>';
- if (isset($respond['product']) && !empty($respond['product'])) {
- foreach ($respond['product'] as $current) {
- $content = self::printGroup($current, $content, $showPrice);
- }
- $content .= '--------------------------------<BR>';
- }
- if (isset($respond['refund']) && !empty($respond['refund'])) {
- $content .= '<CB>【已退款】</CB><BR>';
- foreach ($respond['refund'] as $current) {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $count = $current['count'] ?? '';
- $content .= '<B>' . $name . ' ' . $count . '</B><BR>';
- if ($showPrice == 1) {
- $productNum = $current['num'] ?? '';
- $productPrice = $current['price'] ?? '';
- $content .= $productNum . '=' . $productPrice . '<BR>';
- }
- }
- $content .= '--------------------------------<BR>';
- $content .= '--------------------------------<BR>';
- }
- if ($showPrice == 1) {
- if (isset($orderInfo['itemPrice']) && $orderInfo['itemPrice'] > 0) {
- $content .= '商品金额:' . floatval($orderInfo['itemPrice']) . '<BR>';
- }
- if (isset($respond['sendCost']) && $respond['sendCost'] > 0) {
- $content .= ' 运费:' . floatval($respond['sendCost']) . '<BR>';
- }
- if (isset($orderInfo['packCost']) && $orderInfo['packCost'] > 0) {
- $content .= ' 打包费:' . floatval($orderInfo['packCost']) . '<BR>';
- }
- $content .= '合计金额:' . floatval($respond['prePrice']) . '<BR>';
- if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
- $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
- }
- if (isset($respond['refundPrice']) && $respond['refundPrice'] > 0) {
- $content .= '退款金额:' . floatval($respond['refundPrice']) . '<BR>';
- }
- $content .= '<B>订单金额:' . floatval($respond['realPrice']) . '</B><BR>';
- if (isset($respond['debt']) && $respond['debt'] == 1) {
- $content .= '实付金额:0<BR>';
- } else {
- $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
- }
- if ($debtAmount > 0) {
- $content .= '累计欠款:' . floatval($debtAmount) . '<BR>';
- }
- }
- $shopId = $orderInfo['shopId'] ?? 0;
- $shop = ShopClass::getById($shopId, true);
- $sjId = $shop->sjId ?? 0;
- $telephone = $shop->telephone ?? '';
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $currentName = $sjName;
- if (isset($shop->default) == false || $shop->default != 1) {
- $shopName = $shop->shopName ?? '';
- if (!empty($shopName)) {
- $currentName = $currentName . ' ' . $shopName;
- }
- }
- $getInfo = self::getById($orderInfo['id']);
- $content .= '--------------------------------<BR>';
- $content .= '订单日期:' . date("Y-m-d H:i", strtotime($getInfo['addTime'])) . '<BR>';
- $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
- $content .= '门店名称:' . $currentName . '<BR>';
- if (!empty($telephone)) {
- $content .= '联系电话:' . $telephone . '<BR>';
- }
- $content .= "<BR>";
- if (getenv('YII_ENV') == 'production') {
- //丽子鲜花、花样年华 不显示扫码买花
- if (!in_array($orderInfo->shopId, [1527, 1585, 1596])) {
- $content .= "<BR>";
- $content .= "<CB>扫码买花</CB>";
- $content .= "<BR>";
- $host = Yii::$app->params['hdHost'];
- $content .= "<QR>" . $host . "/#/admin/home/workbench</QR>";
- }
- }
- $content .= "<BR>";
- $content .= "<BR>";
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- if (getenv('YII_ENV') == 'production') {
- //都市花季特殊情况,孙哥有一个小票机打印,其他人用一个小票机,客户下单二个小票机都打
- if ($shopId == 1212) {
- if (isset($orderInfo['shopAdminId']) && !empty($orderInfo['shopAdminId'])) {
- //员工开单的
- if ($orderInfo['shopAdminId'] == 127153) {
- //孙哥
- $printSn = '817003561';
- $p = new printUtil($printSn);
- $p->printMsg($content);
- } else {
- //其它人
- $printSn = '817003563';
- $p = new printUtil($printSn);
- $p->printMsg($content);
- }
- } else {
- //客户商城下单
- $printSn = '817003561';
- $p = new printUtil($printSn);
- $p->printMsg($content);
- $printSn = '817003563';
- $p = new printUtil($printSn);
- $p->printMsg($content);
- }
- return true;
- }
- }
- $printSn = $ext['printSn'] ?? '';
- if (!empty($printSn)) {
- $p = new printUtil($printSn);
- $p->printMsg($content);
- }
- }
- //打印数据 ssh 20210702
- public static function getPrintData($val, $debtAmount, $showItem)
- {
- $printProduct = [];
- if (isset($showItem['list']) && !empty($showItem['list'])) {
- foreach ($showItem['list'] as $itemKey => $itemVal) {
- $bigNum = $itemVal['bigNum'] ?? 0;
- $bigUnitPrice = $itemVal['unitPrice'] ?? 0;
- $smallUnitPrice = $itemVal['smallUnitPrice'] ?? 0;
- $smallNum = $itemVal['smallNum'] ?? 0;
- if ($bigNum > 0) {
- $bigTotalPrice = bcmul($bigUnitPrice, $bigNum, 2);
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => floatval($bigNum) . '扎*' . floatval($bigUnitPrice),
- 'count' => floatval($bigNum) . '扎',
- 'price' => floatval($bigTotalPrice),
- ];
- }
- if ($smallNum > 0) {
- $smallTotalPrice = bcmul($smallUnitPrice, $smallNum, 2);
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => floatval($smallNum) . '支*' . floatval($smallUnitPrice),
- 'count' => floatval($smallNum) . '支',
- 'price' => floatval($smallTotalPrice),
- ];
- }
- }
- }
- $sendNum = $val['sendNum'] ?? '';
- $relateOrderSn = $val['orderSn'] ?? '';
- $refundList = [];
- $refundData = RefundOrderClass::getAllByCondition(['relateOrderSn' => $relateOrderSn], null, '*', null, true);
- if (!empty($refundData)) {
- foreach ($refundData as $refund) {
- $refundOrderSn = $refund->orderSn ?? '';
- $refundProductList = RefundOrderItemClass::getAllByCondition(['orderSn' => $refundOrderSn], null, '*');
- if (!empty($refundProductList)) {
- foreach ($refundProductList as $currentRefund) {
- $num = $currentRefund['xhNum'] ?? 0;
- $unitName = $currentRefund['xhUnitName'] ?? '';
- $unitPrice = $currentRefund['xhUnitPrice'] ?? 0;
- $currentPrice = bcmul($unitPrice, $num, 2);
- $refundList[] = [
- 'name' => $currentRefund['name'] ?? '',
- 'num' => floatval($num) . $unitName . '*' . floatval($unitPrice),
- 'count' => floatval($num) . $unitName,
- 'price' => floatval($currentPrice),
- ];
- }
- }
- }
- }
- $printData = [
- 'address' => '',
- 'sendCost' => $val['sendCost'] ?? '0.00',
- 'prePrice' => $val['prePrice'] ?? '0.00',
- 'discountAmount' => $val['discountAmount'] ?? '0.00',
- 'realPrice' => $val['realPrice'] ?? '0.00',
- 'refundPrice' => $val['refundPrice'] ?? '0.00',
- 'debt' => $val['debt'] ?? 0,
- 'orderSn' => $val['orderSn'] ?? '',
- 'date' => $val['addTime'] ?? '',
- 'remark' => $val['remark'] ?? '',
- 'custom' => [
- 'customName' => $val['customName'] ?? '',
- 'customMobile' => $val['customMobile'] ?? '',
- 'fullAddress' => $val['fullAddress'] ?? '',
- ],
- 'product' => $printProduct,
- 'refund' => $refundList,
- 'sendNum' => $sendNum,
- 'debtAmount' => $debtAmount,
- ];
- return $printData;
- }
- //订单的验证 ssh 2021.3.2
- public static function valid($info, $shopId)
- {
- if (empty($info)) {
- util::fail('没有找到订单');
- }
- if (isset($info['shopId']) && $info['shopId'] == $shopId) {
- return true;
- }
- util::fail('没有权限操作的订单');
- }
- //快递送 ssh 2021.3.16
- public static function thirdSend($order, $expressInfo)
- {
- if ($order->status == self::ORDER_STATUS_UN_PAY) {
- util::fail('订单未付款');
- }
- if ($order->status != self::ORDER_STATUS_UN_SEND) {
- util::fail('不是待配送状态');
- }
- $id = $order->id;
- $expressId = $expressInfo['expressId'] ?? 1;
- $expressName = $expressInfo['deliveryName'] ?? '达达';
- $expressRemark = $expressInfo['remark'] ?? '';
- $order->status = self::ORDER_STATUS_SENDING;
- $order->sendType = self::SEND_TYPE_THIRD;
- $order->expressId = $expressId;
- $order->save();
- $shopId = $order->shopId;
- $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $shop->unSendOrder -= 1;
- $shop->sendingOrder += 1;
- $shop->save();
- $express = OrderExpressClass::getByCondition(['orderId' => $id]);
- if (!empty($express)) {
- util::fail('已经发过了');
- }
- //达达
- $dadaRes = DadaExpressServices::addOrder($order, $expressRemark);
- $orderSn = $order->orderSn;
- $sjId = $order->sjId ?? 0;
- /*
- $getInfo = ExpressClass::getExpressInfo($expressId);
- $hour = $expressInfo['sendTime'] ?? '12:00';
- $sendCost = 12;
- $distance = 5;
- $sendTime = strtotime(date("Y-m-d ") . $hour);
- OrderSendClass::thirdSend($order);
- */
- $sendTime = $order->sendTime;
- if ($sendTime == '0000-00-00 00:00:00') {
- $sendTime = time();
- } else {
- $sendTime = strtotime($order->sendTime);
- }
- $expData = [
- 'orderId' => $id,
- 'orderSn' => $orderSn,
- 'sjId' => $sjId,
- 'expressId' => $expressId,
- 'sendTime' => $sendTime,
- 'cost' => $dadaRes['fee'],
- 'distance' => $dadaRes['distance'],
- 'status' => 1,
- 'expressName' => $expressName,
- 'remark' => $expressRemark,
- ];
- OrderExpressClass::addExpress($expData);
- OrderSendClass::thirdSend($order);
- $respond = [
- 'expressName' => $expressName,
- 'expressId' => $expressId,
- 'distance' => $dadaRes['distance'],
- 'cost' => $dadaRes['fee'],
- 'status' => 2,
- 'tip' => 0,
- ];
- //采购单变成已发货
- $purchaseId = $order->purchaseId ?? 0;
- PurchaseClass::sending($purchaseId);
- return $respond;
- }
- //本店送 ssh 2021.1.24
- public static function selfSend($info)
- {
- if ($info->status == self::ORDER_STATUS_UN_PAY) {
- util::fail('订单未付款');
- }
- if ($info->status != self::ORDER_STATUS_UN_SEND) {
- util::fail('不是待配送状态');
- }
- $info->status = self::ORDER_STATUS_SENDING;
- $info->sendType = self::SEND_TYPE_MYSELF;
- $info->save();
- $shopId = $info->shopId;
- $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $shop->unSendOrder -= 1;
- $shop->sendingOrder += 1;
- $shop->save();
- OrderSendClass::selfSend($info);
- //采购单变成已发货
- $purchaseId = $info->purchaseId ?? 0;
- PurchaseClass::sending($purchaseId);
- }
- //订单完成 ssh 2020.3.12
- public static function complete($order, $shop)
- {
- $order->status = OrderClass::ORDER_STATUS_COMPLETE;
- $order->currentFlow = self::TOTAL_FLOW;
- $order->totalFlow = self::TOTAL_FLOW;
- $order->save();
- $shop->finishOrder += 1;
- $shop->sendingOrder -= 1;
- $shop->save();
- return $order;
- }
- //修改订单表的配送信息 lqh 2021.3.28
- public static function updateCustomExpressInfo($id, $expressAddInfo)
- {
- $data = [
- 'province' => $expressAddInfo['province'],
- 'city' => $expressAddInfo['city'],
- 'address' => $expressAddInfo['address'],
- 'floor' => $expressAddInfo['floor'],
- 'fullAddress' => $expressAddInfo['city'] . $expressAddInfo['address'] . $expressAddInfo['floor'],
- 'lat' => $expressAddInfo['lat'],
- 'long' => $expressAddInfo['long'],
- 'sendTime' => $expressAddInfo['sendTime'],
- ];
- return self::updateById($id, $data);
- }
- //最客户最近的订单 ssh 2021.5.4
- public static function getCustomOrder($id, $limit = 10, $order = null, $with = null)
- {
- $where = ['customId' => $id, 'payStatus' => 1];
- return self::getLimitList('*', $where, $limit, $order, $with);
- }
- //销售单取消 ssh 2021.5.14
- public static function cancel($id)
- {
- $order = self::getLockById($id);
- if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
- util::fail("销售单{$id}不是待付款状态,无法取消");
- }
- $order->status = self::ORDER_STATUS_CANCEL;
- $order->save();
- $shopId = $order->shopId;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- $main->unPayOrder -= 1;
- $main->cancelOrder += 1;
- $main->save();
- //加回库存
- $orderItem = OrderItemClass::getOrderItem($order->orderSn);
- foreach ($orderItem as $v) {
- $stockInfo = ProductClass::addStockByItemNum($v['productId'], $v['num']);
- $recordData = [];
- $recordData['sjId'] = $order->sjId;
- $recordData['shopId'] = $shopId;
- //增加中央ID
- $recordData['mainId'] = ProductClass::getMainIdByProductId($v['productId']);
- $recordData['itemId'] = $v['itemId'] ?? 0;
- $recordData['itemNum'] = $v['num'];
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $v['productId'];
- $recordData['orderSn'] = $order->orderSn;
- $recordData['relateName'] = $order->customName ?? '';
- $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- StockRecordClass::addSellStockOrderCancelRecord($recordData);
- }
- return $order;
- }
- //新订单入队列 ssh 20211012
- public static function newOrderAddQueue($order)
- {
- $shopId = $order->shopId ?? 0;
- if (empty($shopId)) {
- return false;
- }
- $id = $order->id ?? 0;
- if (empty($id)) {
- return false;
- }
- $newOrderKey = 'ghsNewOrder_' . $shopId;
- Yii::$app->redis->executeCommand('LPUSH', [$newOrderKey, $id]);
- }
- }
|