| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228 |
- <?php
- namespace bizHd\order\classes;
- use biz\goods\classes\GoodsClass;
- use biz\goods\models\Goods;
- use biz\shop\classes\ShopCapitalClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use biz\stat\classes\StatOrderCountClass;
- use biz\stock\classes\GoodsStockRecordClass;
- use bizGhs\order\classes\CheckOrderClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\stock\classes\StockRecordClass;
- use bizHd\custom\classes\CustomClass;
- use bizHd\item\classes\ItemClass;
- use bizHd\merchant\classes\SjClass;
- use bizHd\refund\classes\HdRefundClass;
- use bizHd\shop\classes\MainClass;
- use bizHd\shop\classes\ShopMoneyChangeClass;
- use bizHd\user\classes\UserClass;
- use bizHd\work\classes\WorkClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- use common\components\lakala\Lakala;
- class OrderClass extends BaseClass
- {
- public static $baseFile = '\bizHd\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 ORDER_TOTAL_FLOW = 4;
- //未确认配送方式
- const SEND_TYPE_UNKNOWN = 0;
- //自取
- const SEND_TYPE_NO = 1;
- //自己送
- const SEND_TYPE_MYSELF = 2;
- //快递送
- const SEND_TYPE_THIRD = 3;
- //正常订单
- const REFUND_NO = 0;
- //已退款订单
- const REFUND_YES = 1;
- //送达时间段
- public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
- //优惠金额
- public static $randDiscount = [
- 50 => [1, 3],
- 100 => [5, 9],
- 300 => [10, 15],
- 500 => [16, 18],
- 1000 => [18, 30],
- 20000 => [90, 100],
- ];
- //因为开负数订单时引导库存变化 ssh 20250731
- public static function shPayChange($order, $shop, $staff, $originOrder = null)
- {
- $forward = $order['forward'] ?? 0;
- if ($forward == 0) {
- return false;
- }
- $forwardStock = $order['forwardStock'] ?? 0;
- $orderSn = $order['orderSn'] ?? '';
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- $orderGoodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (empty($orderItemList) && empty($orderGoodsList)) {
- return false;
- }
- $shopId = $shop->id ?? 0;
- $sjId = $shop->sjId ?? 0;
- $adminId = $staff->adminId;
- $staffName = $staff->name ?? '';
- $mainId = $shop->mainId;
- if (!empty($orderItemList)) {
- $itemInfo = [];
- $ids = array_column($orderItemList, 'itemId');
- $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
- foreach ($orderItemList as $orderItem) {
- $unitType = $orderItem['unitType'] ?? 0;
- $num = $orderItem['num'] ?? 0;
- $productId = $orderItem['itemId'] ?? 0;
- $info = $infoList[$productId] ?? [];
- $stock = $info['stock'] ?? 0;
- $ratio = $info['ratio'] ?? 20;
- $map = ProductClass::formatStock($stock, $ratio);
- $bigNum = $map['bigNum'] ?? 0;
- $smallNum = $map['smallNum'] ?? 0;
- $num = $forwardStock == 0 ? $num * 2 : $num;
- if ($unitType == 0) {
- $bigNum = $bigNum + $num;
- } else {
- $smallNum = $smallNum + $num;
- }
- $itemInfo[] = ['productId' => $productId, 'bigNum' => $bigNum, 'smallNum' => $smallNum];
- }
- $remark = $forwardStock == 0 ? '开售后付款单,退货并退款' : '开售后付款单,只退款';
- $itemData = [
- 'remark' => $remark,
- 'itemInfo' => $itemInfo,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'adminId' => $adminId,
- 'staffName' => $staffName,
- ];
- CheckOrderClass::opOrder($itemData);
- }
- if (!empty($orderGoodsList)) {
- foreach ($orderGoodsList as $orderGoods) {
- $goodsId = $orderGoods['goodsId'] ?? 0;
- $num = $orderGoods['num'] ?? 0;
- $num = $forwardStock == 0 ? $num * 2 : $num;
- $ret = \bizHd\goods\classes\GoodsClass::addStock($goodsId, $mainId, $num);
- $oldStock = $ret['oldStock'] ?? 0;
- $newStock = $ret['newStock'] ?? 0;
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $shopId;
- $recordData['mainId'] = $mainId;
- $recordData['orderSn'] = '';
- $recordData['goodsId'] = $goodsId;
- $recordData['goodsNum'] = $num;
- $recordData['oldStock'] = $oldStock;
- $recordData['newStock'] = $newStock;
- $recordData['relateName'] = $staffName;
- GoodsStockRecordClass::pdGoods($recordData);
- }
- }
- if (is_object($order) && !empty($originOrder)) {
- //建立关系
- $originOrder->hasForward = 1;
- $originOrder->save();
- $orderId = $originOrder->id ?? 0;
- $orderSn = $originOrder->orderSn ?? '';
- $shOrderId = $order->id ?? 0;
- $shOrderSn = $order->orderSn ?? '';
- $map = ['orderId' => $orderId, 'orderSn' => $orderSn, 'shOrderId' => $shOrderId, 'shOrderSn' => $shOrderSn];
- OrderForwardClass::add($map, true);
- }
- return true;
- }
- /**
- * @param $order
- * @param $mainId
- * @return array
- * $shAddPay 0走正常流程售后,1走售后付款单
- * $shAddPayReason 走售后付款单的原因:0、售后金额大于剩余欠款(剩余欠款可能没有了,可能还有);1、可售后时间到了
- */
- public static function ifShPay($order, $main, $refundAmount = 0)
- {
- $shAddPay = 0;
- $shAddPayReason = 0;
- $payStatus = $order['payStatus'] ?? 0;
- if ($payStatus == 1) {
- if ($order['payWay'] == 3) {
- if ($order['remainDebtPrice'] <= 0) {
- //不管是否要售后,没有剩余欠款了,只能走开负数订单模式
- $shAddPay = 1;
- } else {
- if ($refundAmount > 0 && $refundAmount > $order['remainDebtPrice']) {
- //如果需要售后,并且售后金额大于剩余欠款,走开负数订单模式
- $shAddPay = 1;
- }
- }
- }
- $cRet = OrderClass::couldRefund($order, $main);
- $could = $cRet['could'];
- if (!$could) {
- //可售后时间到了
- $shAddPay = 1;
- $shAddPayReason = 1;
- }
- }
- return ['shAddPay' => $shAddPay, 'shAddPayReason' => $shAddPayReason];
- }
- //订单是否过了可以售后的时间 ssh 20250730
- // $could false 过了售后时间,不能售后,true可以
- public static function couldRefund($order, $main)
- {
- $refundLimit = $main->refundLimit ?? 0;
- $payTime = $order['payTime'];
- $currentPayTime = strtotime($payTime);
- $addDateTime = $refundLimit * 86400;
- $couldRefundTime = $currentPayTime + $addDateTime;
- $now = time();
- $could = $couldRefundTime > $now;
- return ['could' => $could];
- }
- public static function valid($order, $mainId)
- {
- if (!isset($order->mainId) || $order->mainId != $mainId) {
- Yii::info(json_encode($order));
- Yii::info('mainId: ' . $mainId);
- util::fail('无法访问的订单');
- }
- return true;
- }
- //添加订单 ssh 2019.12.5
- public static function addOrder($data)
- {
- $data['orderSn'] = $data['orderSn'] ?? orderSn::getOrderSn();
- $data['payStatus'] = $data['payStatus'] ?? 0;
- $shopId = $data['shopId'] ?? 0;
- //累计订单增加
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店信息54');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有找到main信息');
- }
- $main->unPayOrder += 1;
- $main->totalOrder += 1;
- $main->save();
- $address = $data['address'] ?? '';
- $floor = $data['floor'] ?? '';
- if (empty($data['fullAddress'])) {
- $data['fullAddress'] = $address . $floor;
- }
- $sendType = $data['sendType'] ?? 0;
- if ($sendType == 1) {
- //到店自取,默认当天23点前,没有用,为了方便查询排序
- $data['reachDate'] = date("Y-m-d");
- $data['reachPeriod'] = '22:00';
- } else {
- //如果不是到店自取的,则必须要有配送时间,默认当天
- $data['reachDate'] = !empty($data['reachDate']) ? $data['reachDate'] : date("Y-m-d");
- if (empty($data['reachPeriod'])) {
- util::fail('请选择配送时间');
- }
- }
- $data['reachTime'] = strtotime($data['reachDate'] . ' ' . $data['reachPeriod']);
- //将花店每月的总订单数作为编号
- $riseNum = StatOrderCountClass::addOrder($shop, $main);
- $data['sendNum'] = date("d") . $riseNum;
- $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
- $salt = stringUtil::charsShuffleLowerCase(10);
- $data['salt'] = $salt;
- return self::add($data, true);
- }
- public static function getByOrderSn($orderSn)
- {
- return self::getByCondition(['orderSn' => $orderSn]);
- }
- //评价 ssh 2019.12.16
- public static function comment($data)
- {
- $id = $data['id'];
- unset($data['id']);
- return self::updateById($id, $data);
- }
- public static function getFullInfo($id)
- {
- $order = self::getById($id);
- if (empty($order)) {
- return [];
- }
- $sn = $order['orderSn'] ?? '';
- $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
- $order['itemInfoList'] = OrderItemClass::getListBySn($sn);
- $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*');
- if (!empty($workList)) {
- foreach ($workList as $key => $work) {
- $shortCover = $work['cover'] ?? '';
- $workList[$key]['shortCover'] = $shortCover;
- $workList[$key]['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- }
- }
- $order['workList'] = $workList;
- $debtPrice = $order['debtPrice'] ?? 0;
- $remainDebtPrice = $order['remainDebtPrice'] ?? 0;
- $orderId = $order['id'] ?? 0;
- $osList = [];
- if ($debtPrice > $remainDebtPrice) {
- $osList = OrderSettleClass::getAllByCondition(['orderId' => $orderId, 'status' => 1], null, '*', null, true);
- }
- //结账记录关系
- $order['orderSettleList'] = $osList;
- $order['today'] = date("Y-m-d");
- $order['tomorrow'] = date("Y-m-d", strtotime("+1 day"));
- return $order;
- }
- //订单
- public static function getOrderById($id)
- {
- $order = self::getById($id);
- if (empty($order)) {
- return [];
- }
- $sn = $order['orderSn'] ?? '';
- $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
- return $order;
- }
- //根据订单查询 ssh 2020.1.4
- public static function getOrderBySn($orderSn)
- {
- $order = self::getByCondition(['orderSn' => $orderSn]);
- if (empty($order)) {
- return [];
- }
- $id = $order['id'];
- $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
- return $order;
- }
- //返回随机优惠金额 ssh 2019.9.12
- public static function getRandDiscount($amount)
- {
- if ($amount <= 0) {
- return 0;
- }
- $randDiscount = self::$randDiscount;
- krsort($randDiscount);
- $rand = 0;
- foreach ($randDiscount as $currentAmount => $val) {
- if ($amount >= $currentAmount) {
- $rand = rand($val[0], $val[1]);
- break;
- }
- }
- return $rand / 10;
- }
- //第三方支付后回调处理流程 ssh 2021.4.30
- public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
- {
- $order = self::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- noticeUtil::push('散客下单,付款成功,支付回调,单号:' . $orderSn . ' 金额:' . $totalFee . ' 回调id:' . $transactionId . ' 附件:' . $attach . ',没有找到订单', '15280215347');
- $msg = "没有找到零售订单 orderSn:{$orderSn}";
- Yii::info($msg);
- util::fail($msg);
- }
- if ($order->mainPay != $totalFee) {
- noticeUtil::push("散客下单,付款成功,支付回调错误,零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->mainPay} {$totalFee} 附件:{$attach}", '15280215347');
- $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->mainPay} {$totalFee}";
- Yii::info($msg);
- util::fail($msg);
- }
- $id = $order->id;
- $order = self::getLockById($id);
- $date = date("Y-m-d H:i:s");
- $order->payTime = $date;
- $order->thirdNo = $transactionId;
- $order->onlinePay = dict::getDict('onlinePay', 'yes');
- $order->save();
- self::payAfter($order, $payWay);
- }
- //订单完成 ssh 2021.4.20
- public static function payAfter($order, $payWay)
- {
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if (!isset($order->status)) {
- util::fail('没有找到订单的状态');
- }
- $orderSn = $order->orderSn ?? '';
- if ($order->status == self::ORDER_STATUS_CANCEL) {
- $shopId = $order->shopId;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- noticeUtil::push('注意,零售订单:' . $orderSn . ',付款成功但订单已取消,没有找到门店,关键词 cancel_get_money', '15280215347');
- util::stop("SUCCESS");
- }
- Yii::$app->params['errorReport'] = 1;
- try {
- //恢复取消的订单
- self::recoverOrderToPay($order);
- noticeUtil::push('注意,零售订单:' . $orderSn . ',付款成功,取消的订单,已恢复 SUCCESS', '15280215347');
- } catch (\Exception $exception) {
- $ret = HdRefundClass::onlyRefundAmount($shop, $order);
- if ($ret['status'] == 0) {
- $errMsg = $exception->getMessage();
- noticeUtil::push('注意,零售订单:' . $orderSn . ',付款成功但订单取消。订单没有恢复成功,原因' . $errMsg . ',也没有退款成功。请手动处理。关键词 cancel_get_money', '15280215347');
- }
- util::stop("SUCCESS");
- }
- }
- if ($order->payStatus == 1) {
- noticeUtil::push('注意,零售订单:' . $orderSn . ',已经付过款了,无需重复请求和操作', '15280215347');
- util::fail('订单已经付过款了');
- }
- $orderId = $order->id ?? 0;
- $customId = $order->customId ?? 0;
- $order->status = self::ORDER_STATUS_UN_SEND; // 付款后,订单状态设置为:已付款(待配送)
- $order->payWay = $payWay;
- $order->payStatus = 1;
- $order->payTime = date("Y-m-d H:i:s");
- $order->stockChange = 1;
- $order->save();
- $myCustom = CustomClass::getLockById($customId);
- if (!empty($myCustom)) {
- if ($order->forward == 0) {
- $myCustom->recentExpend = date("Y-m-d H:i:s");
- $myCustom->visitTime = date("Y-m-d H:i:s");
- $myCustom->save();
- }
- }
- $realPrice = $order->realPrice ?? 0;
- $shopId = $order->shopId;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店,编号5115');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息,编号3096');
- }
- $main->unSendOrder += 1;
- $main->unPayOrder -= 1;
- $currentTotalIncome = bcadd($main->totalIncome, $realPrice, 2);
- $main->totalIncome = $currentTotalIncome;
- $main->save();
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $shopAdminId = $order->shopAdminId ?? 0;
- $shopAdminName = $order->shopAdminName ?? '';
- $sjId = $order->sjId;
- $fromType = $order->fromType ?? 1;
- $event = !empty($shopAdminId) ? '员工开单' : '客户下单';
- $capital = [
- 'capitalType' => $capitalType,
- 'relateId' => $orderId,
- 'io' => 1,
- 'totalIncome' => $currentTotalIncome,
- 'payWay' => $payWay,
- 'event' => $event,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'shopAdminId' => $shopAdminId,
- 'shopAdminName' => $shopAdminName,
- 'amount' => $realPrice,
- 'fromType' => $fromType,
- 'mainId' => $mainId,
- ];
- ShopCapitalClass::addCapital($capital);
- //每天和每月收入增加
- //StatIncomeClass::updateOrInsert($main, $shop, $realPrice);
- //今日订单+1
- //StatOrderClass::updateOrInsert($main, $shop);
- //销售收入增加
- //StatSaleClass::replace($main, $shop, $realPrice);
- //各渠道收入金额统计
- //StatKdClass::replace($shop, $realPrice, $payWay);
- //当天同个人同地址的订单汇总
- $sameDate = date("Y_m_d");
- $sameAddress = $order->showAddress ?? '';
- $addressMd5 = md5($sameAddress);
- $sameKey = $customId . '_' . $addressMd5 . '_' . $sameDate . '_retail';
- $sameString = Yii::$app->redis->executeCommand('GET', [$sameKey]);
- if (!empty($sameString)) {
- $newString = $sameString . ',' . $orderId;
- $newIdsArray = explode(',', $newString);
- if (count($newIdsArray) <= 90) {
- Yii::$app->redis->executeCommand('SETEX', [$sameKey, 186400, $newString]);
- foreach ($newIdsArray as $currentOrderId) {
- OrderClass::updateById($currentOrderId, ['sameTimeIds' => $newString]);
- }
- //noticeUtil::push($sameKey . '' . $sameAddress . " 花掌柜当天汇总ids:" . $newString, '15280215347');
- }
- } else {
- Yii::$app->redis->executeCommand('SETEX', [$sameKey, 186400, $orderId]);
- $order->sameTimeIds = $orderId;
- $order->save();
- //noticeUtil::push($sameKey . '' . $sameAddress . " 花掌柜当天汇总ids:" . $orderId, '15280215347');
- }
- //客户在线支付下单增加商家可提现余额
- if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
- $amount = $order->mainPay;
- ShopClass::customKdAddBalance($main, $shop, $amount, $order, $capitalType);
- }
- //客户使用余额付款
- if ($payWay == dict::getDict('payWay', 'balancePay')) {
- CustomClass::payToChangeBalance($order);
- }
- //有欠款时
- if ($payWay == dict::getDict('payWay', 'debtPay')) {
- if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
- CustomClass::skCgDebtAmountAdd($myCustom, $order);
- }
- }
- //全部现金付款余额增加
- if ($payWay == dict::getDict('payWay', 'cash')) {
- $moneyBalance = bcadd($main->money, $order->mainPay, 2);
- $main->money = $moneyBalance;
- $main->save();
- $moneyEvent = "客户现金下单" . floatval($order->mainPay) . "元(单号 {$order->orderSn})";
- $moneyRemark = '';
- $change = [
- 'relateId' => $orderId,
- 'amount' => $order->mainPay,
- 'balance' => $moneyBalance,
- 'io' => 1,
- 'mainId' => $mainId,
- 'capitalType' => $capitalType,
- 'ptStyle' => dict::getDict('ptStyle', 'hd'),
- 'event' => $moneyEvent,
- 'remark' => $moneyRemark,
- ];
- ShopMoneyChangeClass::addData($change);
- } else {
- //部分现金付款
- $orderCash = $order->cash ?? 0;
- $orderCash = floatval($orderCash);
- if ($orderCash > 0) {
- $moneyBalance = bcadd($main->money, $orderCash, 2);
- $main->money = $moneyBalance;
- $main->save();
- $moneyEvent = "客户部分现金付款{$orderCash}元(单号 {$order->orderSn})";
- $moneyRemark = '';
- $change = [
- 'relateId' => $orderId,
- 'amount' => $orderCash,
- 'balance' => $moneyBalance,
- 'io' => 1,
- 'mainId' => $mainId,
- 'capitalType' => $capitalType,
- 'ptStyle' => dict::getDict('ptStyle', 'hd'),
- 'event' => $moneyEvent,
- 'remark' => $moneyRemark,
- ];
- ShopMoneyChangeClass::addData($change);
- }
- }
- }
- //转化出送到时间 ssh 2020.3.15
- public static function getReachTime($order)
- {
- $reachTime = '';
- if (isset($order['reachDate']) && !empty($order['reachDate'])) {
- $prev = date("n-j", strtotime($order['reachDate']));
- $periodData = self::$reachPeriod;
- $periodKey = $order['reachPeriod'];
- $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
- $reachTime = $prev . ' ' . $period;
- }
- return $reachTime;
- }
- //支付成功获取unionId ssh 2020.5.12
- public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
- {
- $mcId = $merchantExtend['wxPayMerchantId'];
- $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
- $unionId = isset($user['unionId']) ? $user['unionId'] : '';
- $userId = $user['id'];
- if (empty($unionId)) {
- $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
- if (!empty($unionId)) {
- $findUser = UserClass::getByUnionId($unionId);
- if (empty($findUser)) {
- UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
- } else {
- UserClass::mergeUser($findUser, $user);
- }
- }
- }
- }
- //订单取消 ssh 20220516
- public static function setExpire($order, $force = false, $staff = null)
- {
- $now = time();
- if ($order->deadline > $now && $force == false) {
- return false;
- }
- if ($order->status != 1) {
- return false;
- }
- $order->status = 5;
- $order->cancelTime = date("Y-m-d H:i:s");
- $order->save();
- $orderSn = $order->orderSn ?? '';
- $relateName = $staff->name ?? '系统';
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- $ptItemId = $item->ptItemId ?? 0;
- $sjId = $item->sjId ?? 0;
- $shopId = $item->shopId ?? 0;
- $mainId = $item->mainId ?? 0;
- $ratio = $item->ratio ?? 20;
- $unitType = $item->unitType ?? 0;
- if ($unitType == 0) {
- $bigNum = $item->num;
- $smallNum = 0;
- } else {
- $bigNum = 0;
- $smallNum = $item->num;
- }
- $itemId = $item->itemId ?? 0;
- $stockInfo = ProductClass::addStock($itemId, $bigNum, $smallNum);
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $shopId;
- $recordData['mainId'] = $mainId;
- $recordData['itemId'] = $ptItemId;
- $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $itemId;
- $recordData['orderSn'] = $orderSn;
- $recordData['relateName'] = $relateName;
- StockRecordClass::addSellStockOrderCancelRecord($recordData);
- }
- }
- $goodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($goodsList)) {
- foreach ($goodsList as $goods) {
- $goodsId = $goods->goodsId ?? 0;
- $num = $goods->num ?? 0;
- $mainId = $goods->mainId ?? 0;
- $orderSn = $goods->orderSn ?? '';
- $shopId = $goods->shopId ?? 0;
- $sjId = $goods->sjId ?? 0;
- $params = ['reduceSale' => 1];
- $respond = \bizHd\goods\classes\GoodsClass::addStock($goodsId, $mainId, $num, $params);
- $oldStock = $respond['oldStock'] ?? 0;
- $newStock = $respond['newStock'] ?? 0;
- $data = [];
- $data['sjId'] = $sjId;
- $data['shopId'] = $shopId;
- $data['mainId'] = $mainId;
- $data['orderSn'] = $orderSn;
- $data['goodsId'] = $goodsId;
- $data['goodsNum'] = $num;
- $data['oldStock'] = $oldStock;
- $data['newStock'] = $newStock;
- $data['relateName'] = $relateName;
- GoodsStockRecordClass::cancelOrder($data);
- }
- }
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (!empty($shop)) {
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $shop->lklSjNo,
- 'term_no' => $shop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $closeParams = [
- 'orderSn' => $orderSn,
- ];
- $response = $laResource->close($closeParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- //noticeUtil::push('零售订单:' . $orderSn . ',关单没有成功。', '15280215347');
- } else {
- //noticeUtil::push('零售订单:' . $orderSn . ',关单成功。', '15280215347');
- }
- }
- }
- // 恢复订单 -- 即:把订单的状态从取消状态变成待付款状态
- public static function recoverOrderToPay($order)
- {
- $now = time();
- $order->status = 1;
- $order->deadline = $now + 86400;
- $order->save();
- // 重新占用库存(与取消订单时的库存回滚相反)
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $order->orderSn], null, '*', null, true);
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- $ptItemId = $item->ptItemId ?? 0;
- $sjId = $item->sjId ?? 0;
- $shopId = $item->shopId ?? 0;
- $mainId = $item->mainId ?? 0;
- $ratio = $item->ratio ?? 20;
- $unitType = $item->unitType ?? 0;
- if ($unitType == 0) {
- $bigNum = $item->num;
- $smallNum = 0;
- } else {
- $bigNum = 0;
- $smallNum = $item->num;
- }
- $itemId = $item->itemId ?? 0;
- // 重新扣减库存(占用库存)
- $stockInfo = ProductClass::decreaseStock($itemId, $bigNum, $smallNum, true);
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $shopId;
- $recordData['mainId'] = $mainId;
- $recordData['itemId'] = $ptItemId;
- $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $itemId;
- $recordData['orderSn'] = $order->orderSn;
- $recordData['relateName'] = $order->customName ?? '';
- StockRecordClass::hdKdAddRecord($recordData);
- }
- }
- return true;
- }
- // 扣库存
- protected static function decGoodsStock($orderGoods)
- {
- foreach ($orderGoods as $goods) {
- GoodsClass::counters([
- 'stock' => -$goods['num']
- ], [
- 'and',
- ['id' => $goods['goodsId']],
- ['<>', 'stock', Goods::FULL_STOCK]
- ]);
- }
- }
- //云打印 ssh 20210709
- public static function onlinePrint($order, $must = false, $port = 'front')
- {
- if (empty($order)) {
- return false;
- }
- if (!$must) {
- if ($order->needPrint != dict::getDict('needPrint', 'need')) {
- return false;
- }
- if ($order->payStatus != 1) {
- return false;
- }
- }
- if ($order->forward == 1) {
- //售后付款单暂时不能打印
- return false;
- }
- $shopId = $order->shopId ?? 0;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if ($port == 'make') {
- $printSn = $ext['makePrintSn'] ?? '';
- if ($order->fromType == 4) {
- $printSn = $ext['mtPrintSn'] ?? '';
- }
- $workList = WorkClass::getAllByCondition(['orderId' => $order->id], null, '*', null, true);
- $hasSh = 0;
- if (!empty($workList)) {
- foreach ($workList as $work) {
- $sh = $work->sh ?? 0;
- if ($sh == 1) {
- $hasSh = 1;
- }
- }
- }
- if ($hasSh == 1) {
- $printSn = $ext['printSn'] ?? '';
- }
- }
- if (empty($printSn)) {
- return false;
- }
- $order->printNum += 1;
- $order->save();
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId);
- $debtAmount = $custom['debtAmount'] ?? 0;
- $respond = self::getPrintData($order, $debtAmount);
- $fromType = $order->fromType ?? dict::getDict('fromType', 'shop');
- $fromTypeMap = dict::getDict('fromTypeMap');
- $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
- //客服下的单则显示客服号和客户名称
- if ($fromType == dict::getDict('fromType', 'friend')) {
- $staffName = $order->shopAdminName ?? '';
- $bookName = $order->bookName ?? '';
- $fromTypeName = $staffName . ' ' . $bookName;
- }
- $content = '';
- //$content .= "<CB>【零售】</CB><BR>";
- if ($fromType == dict::getDict('fromType', 'mt')) {
- $content .= '<B>美团 ' . $order->thirdSn . '</B><BR>';
- if (isset($order->goodsNum) && $order->goodsNum > 1) {
- $content .= '<B>美团 ' . $order->thirdSn . ' (' . $order->goodsNum . '份)</B><BR>';
- }
- $content .= '--------------------------------<BR>';
- $content .= date("Y-m-d", strtotime($order->addTime)) . '<BR>';
- } else {
- $content .= '<CB>' . $fromTypeName . ' ' . $respond['sendNum'] . '</CB><BR>';
- $content .= '--------------------------------<BR>';
- }
- $readPeriod = $order->reachPeriod ?? 0;
- if ($order->sendType == 1) {
- if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
- $currentReachDate = date("m-d", strtotime($order->reachDate));
- $content .= '<B>' . $currentReachDate . ' ' . $readPeriod . '前</B><BR>';
- $content .= '<B>到店自取</B><BR><BR>';
- } else {
- $content .= '<B>到店自取</B><BR><BR>';
- }
- } else {
- if ($order->sendType == 0) {
- $content .= '<B>送货上门</B><BR><BR>';
- } else if ($order->sendType == 2) {
- $content .= '<B>请跑腿送</B><BR><BR>';
- } else if ($order->sendType == 3) {
- $content .= '<B>物流到付</B><BR><BR>';
- } else if ($order->sendType == 4) {
- $content .= '<B>快递到付</B><BR><BR>';
- } else {
- $content .= '';
- }
- if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
- $currentReachDate = date("m-d", strtotime($order->reachDate));
- $content .= '<B>' . $currentReachDate . ' ' . $readPeriod . '前</B><BR><BR>';
- }
- }
- if (isset($order->receiveUserName) && !empty($order->receiveUserName)) {
- $content .= '收花人:<BR>';
- $content .= '<B>' . $order->receiveUserName . '</B><BR>';
- }
- if (isset($order->receiveMobile) && !empty($order->receiveMobile)) {
- $content .= '<B>' . $order->receiveMobile . '</B><BR><BR>';
- }
- if (isset($order->fullAddress) && !empty($order->fullAddress)) {
- $content .= '<B>' . $order->fullAddress . '(' . $order->showAddress . ')' . '</B><BR><BR>';
- }
- if (isset($order->cardInfo) && !empty($order->cardInfo)) {
- $content .= '<B>贺卡内容:' . $order->cardInfo . '</B><BR><BR>';
- }
- if ($order->anonymity == 1) {
- $content .= '<B>匿名派送!!</B><BR><BR>';
- } else {
- if (isset($order->bookMobile) && !empty($order->bookMobile)) {
- $bookName = $order->bookName ?? '';
- $bookMobile = $order->bookMobile ?? '';
- $content .= '订花人:<BR>';
- if (!empty($bookName)) {
- $content .= '<B>' . $bookName . '</B><BR>';
- }
- if (!empty($bookMobile)) {
- $content .= '<B>' . $bookMobile . '</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>';
- if (isset($respond['product']) && !empty($respond['product'])) {
- foreach ($respond['product'] as $current) {
- $content = self::printGroup($current, $content);
- }
- $content .= '--------------------------------<BR>';
- }
- if (isset($respond['refund']) && !empty($respond['refund'])) {
- $content .= '<B>已退款:</B><BR>';
- foreach ($respond['refund'] as $current) {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $content .= $name . '<BR>';
- $name = str_repeat(' ', 10);
- $productNum = $current['num'] ?? '';
- $blankNum = bcsub(12, strlen($productNum));
- if ($blankNum > 0) {
- $productNum = $productNum . str_repeat(' ', $blankNum);
- }
- $productPrice = $current['price'] ?? '';
- $blankNum = bcsub(7, strlen($productPrice));
- if ($blankNum > 0) {
- $productPrice = $productPrice . str_repeat(' ', $blankNum);
- }
- $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
- }
- $content .= '--------------------------------<BR>';
- }
- if (isset($order->goodsPrice) && $order->goodsPrice > 0) {
- $content .= '商品合计:' . floatval($order->goodsPrice) . '<BR>';
- }
- if (isset($respond['sendCost']) && $respond['sendCost'] > 0 && $order->sendType == 2) {
- $content .= '运费:' . floatval($respond['sendCost']) . '<BR>';
- }
- if (isset($order->serviceFee) && $order->serviceFee > 0) {
- $content .= '手续费:' . floatval($order->serviceFee) . '<BR>';
- }
- if (isset($order->labourCost) && $order->labourCost > 0) {
- $content .= '包装费:' . floatval($order->labourCost) . '<BR>';
- }
- if (isset($order->prePrice) && $order->prePrice > 0) {
- $content .= '总计:' . floatval($order->prePrice) . '<BR>';
- }
- if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
- $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
- }
- $content .= '订单金额:' . floatval($respond['orderPrice']) . '<BR>';
- if (isset($respond['refundPrice']) && $respond['refundPrice'] > 0) {
- $content .= '退款金额:' . floatval($respond['refundPrice']) . '<BR>';
- }
- if (isset($respond['debt']) && $respond['debt'] == 1) {
- $content .= '实付金额:0<BR>';
- } else {
- $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
- }
- if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
- $content .= '<B>待付尾款:' . floatval($order->remainDebtPrice) . '</B><BR>';
- }
- $shop = ShopClass::getById($shopId, true);
- $sjId = $shop->sjId ?? 0;
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $shopName = $shop->shopName ?? '';
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $content .= '--------------------------------<BR>';
- $content .= '订单日期:' . $order->addTime . '<BR>';
- $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
- $content .= '门店名称:' . $currentName . '<BR>';
- $content .= "<BR>";
- $p = new printUtil($printSn);
- $orderSn = $order->orderSn ?? '';
- $workList = WorkClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($workList)) {
- $content .= "<BR>";
- $content .= '--------------------------------<BR>';
- foreach ($workList as $work) {
- $goodsSn = $work->goodsSn ?? '';
- $sn = $work->sn ?? '';
- $content .= '<B>制作号:' . $sn . '<B>';
- // 1-523 有-特殊符号,使用飞鹅自带的函数处理
- $content .= $p->bar_code($goodsSn);
- $content .= "<BR>";
- }
- }
- $p->printMsg($content);
- }
- //打印数据 ssh 20210702
- public static function getPrintData($order, $debtAmount)
- {
- $orderSn = $order->orderSn ?? '';
- $printProduct = [];
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $itemKey => $itemVal) {
- $unitName = $itemVal['unitName'] ?? '';
- $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
- 'price' => floatval($itemVal['price']),
- ];
- }
- }
- $orderGoodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($orderGoodsList)) {
- foreach ($orderGoodsList as $itemKey => $itemVal) {
- $unitName = $itemVal['unitName'] ?? '份';
- $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
- 'price' => floatval($itemVal['price']),
- ];
- }
- }
- $sendNum = $order['sendNum'] ?? '';
- //退款记录
- $refundList = [];
- $printData = [
- 'address' => '',
- 'sendCost' => $order->sendCost ?? '0.00',
- 'prePrice' => $order->prePrice ?? '0.00',
- 'orderPrice' => $order->orderPrice ?? '0',
- 'discountAmount' => $order->discountAmount ?? '0.00',
- 'realPrice' => $order->realPrice ?? '0.00',
- 'refundPrice' => $order->refundPrice ?? '0.00',
- 'debt' => $order->debt ?? 0,
- 'orderSn' => $order->orderSn ?? '',
- 'date' => $order->addTime ?? '',
- 'remark' => $order->remark ?? '',
- 'custom' => [
- 'customName' => $order->customName ?? '',
- 'customMobile' => $order->customMobile ?? '',
- 'fullAddress' => $order->fullAddress ?? '',
- ],
- 'product' => $printProduct,
- 'refund' => $refundList,
- 'sendNum' => $sendNum,
- 'debtAmount' => $debtAmount,
- ];
- return $printData;
- }
- public static function printGroup($current, $content)
- {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $content .= $name . '<BR>';
- $name = str_repeat(' ', 10);
- $productNum = $current['num'] ?? '';
- $blankNum = bcsub(12, strlen($productNum));
- if ($blankNum > 0) {
- $productNum = $productNum . str_repeat(' ', $blankNum);
- }
- $productPrice = $current['price'] ?? '';
- $blankNum = bcsub(7, strlen($productPrice));
- if ($blankNum > 0) {
- $productPrice = $productPrice . str_repeat(' ', $blankNum);
- }
- $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
- return $content;
- }
- //扫码收款的,减少库存 ssh 20250822
- public static function reduceMyStock($data, $shop, $custom)
- {
- $mainId = $shop->mainId;
- $customId = $custom->id;
- $orderId = $data['orderId'] ?? '';
- $sjId = $shop->sjId;
- $hdId = $custom->hdId;
- $shopId = $shop->id;
- $order = self::getById($orderId, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $shop->mainId) {
- util::fail('并不是你的订单');
- }
- if ($order->repeat == 0) {
- util::fail('已经扣过了');
- }
- if ($order->tkPrice > 0) {
- util::fail('已经发生退款,无法操作');
- }
- if ($order->customId != $customId) {
- util::fail('订单对应客户有问题,无法扣库存,编号:' . $customId . ' ' . $order->customId);
- }
- $orderSn = $order->orderSn ?? '';
- $product = $data['product'] ?? [];
- if (empty($product)) {
- util::fail('请选择商品呢');
- }
- $orderItemList = OrderItemClass::getAllbyCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $orderItem->unitPrice = 0;
- $orderItem->save();
- }
- }
- $actPrice = $order->actPrice ?? 0;
- if ($actPrice <= 0) {
- util::fail('订单金额为0');
- }
- $ids = array_column($product, 'productId');
- $productInfo = ItemClass::getByIds($ids, null, 'id');
- $goodsPrice = 0;
- foreach ($product as $key => $val) {
- $property = $val['property'] ?? 0;
- if ($property != 1) {
- util::fail('暂时只支持花材');
- }
- $unitPrice = $val['unitPrice'] ?? 0;
- $unitType = $val['unitType'] ?? 0;
- $currentId = $val['productId'] ?? 0;
- $num = $val['num'] ?? 0;
- $currentInfo = $productInfo[$currentId] ?? [];
- if (empty($currentInfo)) {
- util::fail('存在无效花材,编号:' . $currentId);
- }
- $name = $currentInfo['name'] ?? '';
- $cover = $currentInfo['cover'] ?? '';
- $ratio = $currentInfo['ratio'] ?? 20;
- $itemMainId = $currentInfo['mainId'] ?? 0;
- if ($itemMainId != $mainId) {
- util::fail('不是您的花材,请勿使用,编号:' . $mainId . ' ' . $itemMainId);
- }
- if ($unitType == 0) {
- $unitName = $currentInfo['bigUnit'] ?? '';
- $unitId = $currentInfo['bigUnitId'] ?? 0;
- $totalNum = $num;
- } else {
- $unitName = $currentInfo['smallUnit'] ?? '';
- $unitId = $currentInfo['smallUnitId'] ?? 0;
- $totalNum = bcdiv($num, $ratio, 2);
- }
- $ptItemId = $currentInfo['itemId'] ?? 0;
- $classId = $currentInfo['classId'] ?? 0;
- $belongCost = $currentInfo['belongCost'] ?? 0;
- $currentPrice = bcmul($unitPrice, $num, 2);
- $goodsPrice = bcadd($goodsPrice, $currentPrice, 2);
- $currentItemData = [
- 'name' => $name,
- 'cover' => $cover,
- 'ratio' => $ratio,
- 'unitType' => $unitType,
- 'unitName' => $unitName,
- 'unitId' => $unitId,
- 'unitPrice' => $unitPrice,
- 'num' => $num,
- 'orderSn' => $orderSn,
- 'itemId' => $currentId,
- 'ptItemId' => $ptItemId,
- 'totalNum' => $totalNum,
- 'totalPrice' => 0,
- 'customId' => $customId,
- 'hdId' => $hdId,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'classId' => $classId,
- 'price' => $currentPrice,
- 'belongCost' => $belongCost,
- ];
- //库存变化在这里
- OrderItemClass::addData($currentItemData, $custom);
- }
- $labourCost = 0;
- $discountType = 0;
- $discountAmount = 0;
- if ($goodsPrice > $actPrice) {
- $prePrice = $goodsPrice;
- $discountAmount = bcsub($goodsPrice, $actPrice, 2);
- if ($discountAmount > 0) {
- $discountType = 3;
- }
- } else {
- $prePrice = $actPrice;
- $labourCost = bcsub($actPrice, $goodsPrice, 2);
- }
- $order->goodsPrice = $goodsPrice;
- $order->prePrice = $prePrice;
- $order->labourCost = $labourCost;
- $order->discountAmount = $discountAmount;
- $order->discountType = $discountType;
- $order->repeat = 0;
- $order->save();
- return $order;
- }
- }
|