| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399 |
- <?php
- namespace hd\controllers;
- use biz\admin\classes\AdminClass;
- use biz\ghs\classes\GhsClass;
- use biz\notice\classes\NoticeClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExpressClass;
- use biz\shop\classes\ShopExtClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\express\services\DadaExpressServices;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\OrderItemClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\classes\PurchaseItemClass;
- use bizHd\purchase\services\PurchaseService;
- use bizGhs\product\classes\ProductClass;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dateUtil;
- use common\components\dict;
- use common\components\freight;
- use common\components\httpUtil;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use Yii;
- use common\components\util;
- use biz\wx\classes\WxMessageClass;
- use bizGhs\order\services\OrderService;
- use common\components\lakala\Lakala;
- use common\components\qrCodeUtil;
- class PurchaseController extends BaseController
- {
- public $guestAccess = ['detail', 'ali-pay', 'get-ali-pay-code', 'wx-pay'];
- //取消采购单 ssh 20250710
- public function actionCancel()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $info = PurchaseClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到采购单');
- }
- if (!isset($info->mainId) || $info->mainId != $this->mainId) {
- util::fail('访问错误');
- }
- if ($info->status == 5) {
- util::fail('已取消');
- }
- if ($info->status != 1) {
- util::fail('不能取消');
- }
- PurchaseService::expire($info);
- util::complete('已取消');
- }
- //获取支付宝付款码 ssh 20240713
- public function actionGetAliPayCode()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? '';
- $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($info)) {
- util::fail('没有找到采购单');
- }
- if (isset($info->mainId) == false || $info->mainId != $this->mainId) {
- util::fail('无法访问');
- }
- if (getenv('YII_ENV') == 'production') {
- $url = "https://mall.huahb.cn/#/admin/cg/alipay?orderSn={$orderSn}";
- } else {
- $url = "https://mall.huaml.com/#/admin/cg/alipay?orderSn={$orderSn}";
- }
- $unique = "order_ali_pay_" . $orderSn;
- $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
- $imageUrl = imgUtil::groupImg($imgUrl);
- util::success(['imgUrl' => $imageUrl]);
- }
- //确认收货 ssh 20231119
- public function actionConfirmTake()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = PurchaseClass::getById($id, true);
- if (empty($info)) {
- util::fail('没有找到采购单');
- }
- if (isset($info->mainId) == false || $info->mainId != $this->mainId) {
- util::fail('无法访问');
- }
- PurchaseClass::confirmTake($info);
- util::complete('确认成功');
- }
- public function actionGetFullInfo()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = PurchaseClass::getById($id);
- if (empty($info)) {
- util::fail('没有找到采购单');
- }
- if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
- util::fail('无法访问');
- }
- $orderSn = $info['orderSn'] ?? '';
- $ghsId = $info['ghsId'] ?? 0;
- $info['ghsShopId'] = 0;
- if (!empty($ghsId)) {
- $ghs = GhsClass::getById($ghsId, true);
- $info['ghsShopId'] = $ghs->shopId ?? 0;
- }
- $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($list)) {
- foreach ($list as $key => $item) {
- $shortCover = $item['cover'] ?? '';
- $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $list[$key]['cover'] = $cover;
- $list[$key]['bigCover'] = $bigCover;
- $list[$key]['shortCover'] = $shortCover;
- }
- }
- $info['product'] = $list;
- util::success($info);
- }
- //虚拟供货商的采购 ssh 20230308
- public function actionAddVirtualCg()
- {
- $post = Yii::$app->request->post();
- $ghsId = $post['ghsId'] ?? 0;
- $payMode = $post['payMode'] ?? 0;
- $payWay = $post['payWay'] ?? 0;
- $ghsInfo = GhsClass::getById($ghsId);
- if (empty($ghsInfo)) {
- util::fail('没有找到供货商');
- }
- if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
- util::fail('不能向自己的店买花');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $post['book'] = $post['book'] ?? 0;
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['shopAdminId'] = $this->shopAdminId;
- $post['ghsId'] = $ghsId;
- $post['ghsName'] = $ghsInfo['name'] ?? '';
- $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
- $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
- $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
- $customId = $ghsInfo['customId'] ?? 0;
- $post['customId'] = $customId;
- $shopAdmin = $this->shopAdmin ?? null;
- $name = $shopAdmin->name ?? '';
- $post['shopAdminName'] = $name;
- $post['mainId'] = $this->mainId;
- $product = $post['product'] ?? '';
- $productList = json_decode($product, true);
- //判断product数据是不是同个供货商的
- $ids = array_unique(array_filter(array_column($productList, 'productId')));
- $productInfoList = ProductClass::getByIds($ids, null, 'id');
- if (!empty($productInfoList)) {
- foreach ($productInfoList as $currentInfo) {
- if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
- util::fail('只能选择同一家的商品哦');
- }
- }
- if (count($productInfoList) != count($ids)) {
- util::fail('存在无效商品');
- }
- } else {
- util::fail('花材不存在');
- }
- //供货商预订单最低公斤数要求和每公斤服务费
- $ghsInfo['kiloFee'] = 0;
- $ghsInfo['miniKilo'] = 0;
- $post['product'] = $productList;
- $packCost = 0;
- $post['packCost'] = $packCost;
- $post['sendCost'] = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
- $respond = PurchaseService::createPurchase($post, $ghsInfo);
- if ($payMode == 0) {
- //欠款
- PurchaseService::debt($respond);
- } else {
- //线下支付
- PurchaseService::payAfter($respond, $payWay);
- $saleId = $respond->saleId ?? 0;
- $order = OrderClass::getById($saleId, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- OrderService::payAfter($order, $payWay, true);
- }
- $transaction->commit();
- util::success($respond);
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail();
- }
- }
- //生成采购单 ssh 2021.1.17
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $version = $post['version'] ?? 0;
- $direct = $post['direct'] ?? 0;
- //多颜色数据整理
- $colorItem = $post['xj'] ?? [];
- $newXj = [];
- if (!empty($colorItem)) {
- $colorData = json_decode($colorItem, true);
- if (!empty($colorData) && is_array($colorData)) {
- foreach ($colorData as $colorInfo) {
- $ptItemId = $colorInfo['ptItemId'] ?? 0;
- $colorList = $colorInfo['list'] ?? [];
- if (!empty($colorList)) {
- foreach ($colorList as $colorItemKey => $colorItem) {
- $newXj[$ptItemId][] = $colorItem;
- }
- }
- }
- }
- }
- $post['xj'] = $newXj;
- $ghsId = $post['ghsId'] ?? 0;
- //供货商
- $ghsInfo = GhsClass::getById($ghsId);
- if (empty($ghsInfo)) {
- util::fail('没有找到供货商');
- }
- $ghsShopId = $ghsInfo['shopId'] ?? 0;
- if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
- util::fail('不能跟自己的店买花');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $post['book'] = $post['book'] ?? 0;
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['shopAdminId'] = $this->shopAdminId;
- $post['ghsId'] = $ghsId;
- $post['ghsName'] = $ghsInfo['name'] ?? '';
- $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
- $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
- $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
- $customId = $ghsInfo['customId'] ?? 0;
- $post['customId'] = $customId;
- $shopAdmin = $this->shopAdmin ?? null;
- $name = $shopAdmin->name ?? '';
- $post['shopAdminName'] = $name;
- $post['mainId'] = $this->mainId;
- $product = $post['product'] ?? '';
- $productList = json_decode($product, true);
- //判断product数据是不是同个供货商的
- $ghsShopInfo = ShopClass::getById($ghsShopId, true);
- $ghsMainId = $ghsShopInfo->mainId ?? 0;
- $isOpen = ShopClass::isOpen($ghsShopInfo);
- $book = $post['book'] ?? 0;
- if ($isOpen == 0 && $book == 0) {
- util::fail('本店已休息,请选择其它门店');
- }
- if (isset($post['transType']) && $post['transType'] == 4) {
- if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
- $notSameCity = PurchaseClass::notSameCity($this->shop, $ghsShopInfo);
- if ($notSameCity == false) {
- util::fail('距离太远,不能选择同城配送');
- }
- }
- }
- if ($book == 1) {
- $sendTimeWant = isset($post['sendTimeWant']) && !empty($post['sendTimeWant']) ? $post['sendTimeWant'] : date("Y-m-d");
- $future = date("Y-m-d", strtotime('+2 day'));
- if (strtotime($sendTimeWant) < strtotime($future)) {
- //util::fail('请选择时间');
- }
- $nowTime = strtotime(date("Y-m-d"));
- if (strtotime($sendTimeWant) < $nowTime) {
- util::fail('不能选择过去时间');
- }
- }
- //收集客户要下单的花材数量
- $orderNum = [];
- foreach ($productList as $key => $product) {
- $bigNum = $product['bigNum'] ?? 0;
- $smallNum = $product['smallNum'] ?? 0;
- $pName = $product['name'] ?? '';
- if ($smallNum > 0) {
- util::fail($pName . '不能选小单位');
- }
- $productId = $product['productId'] ?? 0;
- $orderNum[$productId] = ['num' => $bigNum];
- }
- $lackList = [];
- $changeList = [];
- $ids = array_unique(array_filter(array_column($productList, 'productId')));
- $productInfoList = ProductClass::getByIds($ids, null, 'id');
- if (!empty($productInfoList)) {
- $presellData = [];
- $nowTime = strtotime(date("Y-m-d"));
- foreach ($productInfoList as $currentInfo) {
- if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $ghsMainId) {
- util::fail('只能选择同一家的商品哦');
- }
- $currentName = $currentInfo['name'] ?? '';
- if (isset($currentInfo['frontHide']) && $currentInfo['frontHide'] == 1) {
- util::fail($currentName . '没有库存,请删除');
- }
- $presell = $currentInfo['presell'] ?? 0;
- $presellData[] = $presell;
- if ($presell == 1) {
- if ($book == 1) {
- util::fail('预订时不能选择预售花材');
- } else {
- if (isset($post['sendTimeWant']) == false || empty($post['sendTimeWant'])) {
- util::fail('请选择配送日期');
- }
- $sendTimeWant = $post['sendTimeWant'];
- if (strtotime($sendTimeWant) < $nowTime) {
- util::fail('不能选择过去时间');
- }
- $hasDateStr = $currentInfo['presellDate'] ?? [];
- $hasDate = explode(',', trim($hasDateStr));
- if (empty($hasDate)) {
- util::fail('预售日期有问题,请提醒门店');
- }
- if (in_array(strtotime($sendTimeWant), $hasDate) == false) {
- util::fail("有预售花材在{$sendTimeWant}没到货");
- }
- $post['presell'] = 1;
- }
- }
- if ($version >= 10) {
- $stock = $currentInfo['stock'] ?? 0;
- $stock = floatval($stock);
- //会有0.5扎和2.5扎问题,所以要转成整数,不然会出严重问题 ssh 20250503
- $stock = intval($stock);
- $productId = $currentInfo['id'] ?? 0;
- $productName = $currentInfo['name'] ?? '';
- $num = $orderNum[$productId] && $orderNum[$productId]['num'] ? $orderNum[$productId]['num'] : 0;
- $num = floatval($num);
- if ($num > $stock) {
- $lackList[] = ['name' => $productName, 'stock' => $stock];
- $changeList[$productId] = $stock;
- }
- }
- }
- if (count($productInfoList) != count($ids)) {
- util::fail('存在无效商品');
- }
- $presellData = array_unique($presellData);
- if (count($presellData) > 1) {
- util::fail('预售和非预售花材不能一起下单');
- }
- if ($version >= 10) {
- if ($direct == 1) {
- //直接更换库存并提交
- $allNoStock = true;
- foreach ($productList as $pKey => $pVal) {
- $productId = $pVal['productId'] ?? 0;
- if (isset($changeList[$productId])) {
- $changeStock = $changeList[$productId];
- $productList[$pKey]['bigNum'] = $changeStock;
- }
- if ($productList[$pKey]['bigNum'] > 0) {
- $allNoStock = false;
- }
- if ($productList[$pKey]['bigNum'] <= 0) {
- unset($productList[$pKey]);
- }
- }
- if ($allNoStock) {
- util::fail('全部没库存了');
- }
- } else {
- //前台提示库存不足
- if (!empty($lackList)) {
- util::success(['lackList' => $lackList, 'hasLackError' => 1]);
- }
- }
- }
- } else {
- util::fail('花材不存在');
- }
- //供货商预订单最低公斤数要求和每公斤服务费
- $ghsInfo['kiloFee'] = $ghsShopInfo->kiloFee ?? 0;
- $ghsInfo['miniKilo'] = $ghsShopInfo->miniKilo ?? 0;
- //旭海银柳的临时解决办法
- if (getenv('YII_ENV') == 'production') {
- if ($ghsShopInfo->mainId == 41121) {
- $mer = [1903693, 1903712, 1903789, 1903796, 1903816, 1903841, 1903855, 1903859, 1903860, 1903864];
- $getIds = array_column($productList, 'productId');
- $hasYl = false;
- foreach ($productList as $ylVal) {
- $ylProductId = $ylVal['productId'];
- if (in_array($ylProductId, $mer)) {
- $hasYl = true;
- }
- }
- if ($hasYl) {
- $myInfoList = ProductClass::getAllByCondition(['id' => ['in', $getIds]], null, '*', 'id');
- $currentMap = [1903693 => 220, 1903712 => 150, 1903789 => 100, 1903796 => 60, 1903816 => 45, 1903841 => 80, 1903855 => 55, 1903859 => 40, 1903860 => 25, 1903864 => 20];
- foreach ($productList as $ylKey => $ylValue) {
- $ylProductId = $ylValue['productId'];
- $num = $ylValue['bigNum'] ?? 0;
- if (!isset($currentMap[$ylProductId])) {
- util::fail('花材有问题');
- }
- $mustBeNum = $currentMap[$ylProductId];
- $myInfo = $myInfoList[$ylProductId] ?? [];
- if (empty($myInfo)) {
- util::fail('花材有问题哦');
- }
- $myName = $myInfo['name'] ?? '';
- if ($num >= $mustBeNum) {
- $curVal = $num / $mustBeNum;
- if ($curVal != intval($curVal)) {
- util::fail($myName . ' 要' . $mustBeNum . '捆或' . $mustBeNum . '的倍数');
- }
- } else {
- util::fail($myName . ' 数量要' . $mustBeNum . '捆');
- }
- }
- }
- }
- }
- $post['product'] = $productList;
- $sendType = $post['sendType'] ?? 0;
- $transType = $post['transType'] ?? 0;
- if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
- //昆明发货包装费和运费的计算
- $totalWeight = 0;
- $totalItemNum = 0;
- foreach ($productList as $itemData) {
- $bigNum = $itemData['bigNum'] ?? 0;
- $thisWeight = $itemData['weight'] ?? 0;
- $currentWeight = bcmul($thisWeight, $bigNum, 2);
- $totalWeight = bcadd($currentWeight, $totalWeight, 2);
- $totalItemNum = bcadd($totalItemNum, $bigNum, 2);
- }
- $totalItemNum = floatval($totalItemNum);
- $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
- $packCost = 0;
- if (!empty($kmPackCost)) {
- foreach ($kmPackCost as $itemPack) {
- $kiloNum = $itemPack['num'] ?? 0;
- if ($kiloNum >= $totalWeight) {
- $packCost = $itemPack['amount'] ?? 0;
- break;
- }
- }
- if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
- noticeUtil::push("总重量" . $totalWeight, '15280215347');
- }
- }
- if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
- noticeUtil::push("走的pfLevel=1", '15280215347');
- }
- //同城配送和到店自取免打包费
- if ($transType == 4 || $transType == 5) {
- $packCost = 0;
- if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
- noticeUtil::push("没有计算打包费原因:transType = 4 =5", '15280215347');
- }
- }
- //如果已经算过一次打包费和运费了,则不再费了
- $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId);
- if ($needAdd == false) {
- $packCost = 0;
- if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
- noticeUtil::push("没有计算打包费原因:已经算过一次了", '15280215347');
- }
- }
- $post['packCost'] = $packCost;
- $transCost = dict::getDict('transCost', null, null, $ghsShopInfo->mainId);
- $sendCost = 0;
- if (!empty($transCost)) {
- foreach ($transCost as $trans) {
- $sign = $trans['sign'] ?? 0;
- if ($sign == $transType) {
- if ($sign == 2) {
- //冷链物流
- $llOption = $trans['option'] ?? [];
- if (!empty($llOption)) {
- $largeInfo = end($llOption);
- $largeNum = $largeInfo['num'] ?? 0;
- $largeAmount = $largeInfo['amount'] ?? 0;
- $bs = intval($totalItemNum / $largeNum);
- if ($bs > 0) {
- $addSendCost = bcmul($bs, $largeAmount, 2);
- $sendCost = bcadd($sendCost, $addSendCost, 2);
- $subNum = bcmul($bs, $largeNum, 2);
- $subNum = floatval($subNum);
- $totalItemNum = bcsub($totalItemNum, $subNum, 2);
- $totalItemNum = floatval($totalItemNum);
- }
- foreach ($llOption as $miniItem) {
- if ($miniItem['num'] >= $totalItemNum) {
- $sendCost = bcadd($sendCost, $miniItem['amount'], 2);
- break;
- }
- }
- }
- } else {
- //其它物流
- $perKiloCost = $trans['perKiloCost'] ?? 0;
- $sendCost = bcmul($perKiloCost, $totalWeight, 3);
- $sendCost = round($sendCost, 2);
- }
- }
- }
- }
- //如果已经算过一次打包费和运费了,则不再费了
- $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId);
- if ($needAdd == false) {
- $sendCost = 0;
- }
- $post['sendCost'] = $sendCost;
- //标记为昆明到地方订单
- $post['localOrder'] = 1;
- } else {
- //同城发货包装费和运费的计算
- $sendCost = 0;
- if ($sendType == dict::getDict('sendType', 'thirdSend')) {
- $weight = 0;
- foreach ($productList as $itemData) {
- $bigNum = $itemData['bigNum'] ?? 0;
- $thisWeight = $itemData['weight'] ?? 0;
- $currentWeight = bcmul($thisWeight, $bigNum, 2);
- $weight = bcadd($currentWeight, $weight, 2);
- }
- $result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight);
- $sendCost = $result['fee'] ?? 0;
- }
- $post['sendCost'] = $sendCost;
- //出车、发快递、发物流可以算包装费
- $packCost = 0;
- if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
- noticeUtil::push("走的pfLevel=0", '15280215347');
- }
- $itemTotalAmount = $post['itemTotalAmount'] ?? 0;
- unset($post['itemTotalAmount']);
- if ($sendType == dict::getDict('sendType', 'express')) {
- $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId, $itemTotalAmount);
- if ($needAdd) {
- $packCost = $ghsShopInfo->packCost ?? 0;
- }
- }
- $post['packCost'] = $packCost;
- }
- if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
- noticeUtil::push("包装费:" . $packCost, '15280215347');
- }
- $respond = PurchaseService::createPurchase($post, $ghsInfo);
- if ($sendType == 0) {
- if (getenv('YII_ENV') == 'production') {
- //杭州斗南鲜花批发部,满500,10公里内免费配送,满1000,20公里免费配送
- if ($ghsShopId == 4608) {
- if ($respond->actPrice < 500) {
- $transaction->rollBack();
- util::fail('满500元支持免费配送');
- }
- }
- //叶上花,满500元市区免费配送
- if ($ghsShopId == 4804) {
- if ($respond->actPrice < 500) {
- $transaction->rollBack();
- util::fail('满500元支持免费配送');
- }
- }
- //花悠星 国恋 勇记 万丽 陆丰暂时不支持免费配送
- if ($ghsShopId == 7687 || $ghsShopId == 7831 || $ghsShopId == 7778 || $ghsShopId == 12003 || $ghsShopId == 38128) {
- util::fail('暂不支持送货上门,请选其它配送方式!');
- }
- }
- if (isset($ghsInfo['home'])) {
- if ($ghsInfo['home'] == 0) {
- util::fail('暂不支持送货上门,请选其它配送方式');
- }
- if (!empty($ghsInfo['homeAmount'])) {
- $homeType = $ghsInfo['homeType'] ?? 0;
- $homeAmount = floatval($ghsInfo['homeAmount']);
- if ($homeType == 0) {
- if ($homeAmount > $respond->actPrice) {
- util::fail("满{$homeAmount}元 可送货上门");
- }
- }
- if ($homeType == 1) {
- if ($homeAmount > $respond->bigNum) {
- util::fail("满{$homeAmount}扎 可送货上门");
- }
- }
- }
- }
- }
- if ($sendType == 2) {
- if (in_array($ghsShopId, [520, 1489, 13628, 3, 7855, 7687])) {
- util::fail('暂时不能使用跑腿');
- }
- }
- if (getenv('YII_ENV') == 'production') {
- //昆明花落谁家
- if ($ghsShopId == 13398) {
- if ($respond->bigNum < 15) {
- $transaction->rollBack();
- util::fail('不足15扎,请联系店长');
- }
- }
- //盛丰最少要20扎
- if ($ghsShopId == 44556) {
- if ($respond->bigNum < 20) {
- $transaction->rollBack();
- util::fail('最少要20扎');
- }
- }
- }
- $transaction->commit();
- util::success($respond);
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail();
- }
- }
- //赊账 ssh 2021.1.24
- public function actionDebtPay()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? 0;
- $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
- PurchaseService::valid($info, $this->shopId);
- //解决重复和并发提交
- $cacheKey = 'hd_debt_pay_' . $orderSn;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('请稍等...');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
- if ($info->status == 5) {
- util::fail('订单已取消');
- }
- if ($info->status != 1) {
- util::fail('订单不是待付款状态');
- }
- if ($info->book == 1) {
- util::fail('预售不能记欠款');
- }
- $ghsId = $info->ghsId;
- $ghs = GhsClass::getGhsInfo($ghsId);
- $customId = $ghs['customId'] ?? 0;
- $custom = CustomClass::getCustom($customId);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if (isset($custom['debt']) == false || $custom['debt'] == CustomClass::IS_DEBT_NO) {
- util::fail('请先申请赊账权限');
- }
- if (getenv('YII_ENV') == 'production') {
- //源花汇不允许客户自己下欠款单
- if ($ghs['mainId'] == 10536) {
- util::fail('暂未开通');
- }
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //延期支付
- PurchaseService::debt($info);
- $transaction->commit();
- if (isset($info->localOrder) && $info->localOrder == 1) {
- if ($info->transType != 5 && $info->transType != 4) {
- //昆明发货,客户算了一次打包费和运费,第二次就不再算了
- $current = date("Y_m_d");
- $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
- Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
- }
- } else {
- if (isset($info->sendType) && $info->sendType == 4) {
- //标记当天已收一次包装费,岭南批发市场用的功能
- $current = date("Y_m_d");
- $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
- Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
- }
- }
- //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
- $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
- if (!empty($cg)) {
- if (isset($cg->book) && $cg->book == 0) {
- $ghsShopId = $ghs['shopId'] ?? 0;
- if (getenv('YII_ENV') == 'production') {
- $specialList = [10649, 8042, 16454, 21319, 33668, 42345];
- } else {
- $specialList = [36523];
- }
- if (!in_array($ghsShopId, $specialList)) {
- PurchaseClass::confirmTake($cg);
- }
- }
- }
- //app新订单通知
- $saleId = $info->saleId ?? 0;
- $order = OrderClass::getById($saleId, true);
- if (!empty($order)) {
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (!empty($shop)) {
- //微信通知供货商
- //WxMessageClass::ghsHasNewOrderInform($shop, $order);
- $noticeText = json_encode(['orderId' => $saleId]);
- $noticeKey = "hdCgNoticeGhs";
- Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
- }
- //订单生成时唤起在线打印
- if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
- //有几个地方要同步去修改
- if (getenv('YII_ENV') == 'production') {
- //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
- $mallOrderNoPrint = [10536, 44282, 26374];
- } else {
- $mallOrderNoPrint = [];
- }
- if (in_array($order->mainId, $mallOrderNoPrint)) {
- } else {
- OrderClass::onlinePrint($order);
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (isset($ext->printSn) && !empty($ext->printSn)) {
- $order->printNum += 1;
- $order->save();
- }
- //xxx 打二次小票,有多处要修改搜索关键词tow_print
- if (in_array($order->mainId, [0])) {
- OrderClass::onlinePrint($order);
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- if (isset($ext->printSn) && !empty($ext->printSn)) {
- $order->printNum += 1;
- $order->save();
- }
- }
- }
- }
- //更新最后下单时间
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- $date = date("Y-m-d H:i:s");
- if (!empty($custom)) {
- $custom->recentExpend = $date;
- $custom->save();
- }
- $ghsId = $order->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (!empty($ghs)) {
- $ghs->recentExpend = $date;
- $ghs->save();
- }
- }
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail('支付失败');
- }
- util::success($info->attributes);
- }
- //余额支付 ssh 2021.1.24
- public function actionBalancePay()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? 0;
- $password = $get['password'] ?? '';
- // 重新获取,不加密的用户数据
- $admin = AdminClass::getById($this->adminId, true);
- if (password_verify($password, $admin->payPassword) == false) {
- util::fail('密码错误');
- }
- $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($info)) {
- util::fail('没有找到采购单');
- }
- if ($info->status == 5) {
- util::fail('订单已取消');
- }
- if ($info->status != 1) {
- util::fail('订单不是待付款状态');
- }
- PurchaseService::valid($info, $this->shopId);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- //余额支付
- purchaseService::balancePay($info);
- $transaction->commit();
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail('支付失败');
- }
- util::success($info->attributes);
- }
- //采购记录 ssh 2021.1.24
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = ['shopId' => $this->shopId];
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $ghsId = $get['ghsId'] ?? 0;
- if (!empty($ghsId)) {
- $where['ghsId'] = $ghsId;
- }
- $status = $get['status'] ?? 0;
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $respond = PurchaseService::getPurchaseList($where);
- $respond['shop'] = $this->shop->attributes;
- util::success($respond);
- }
- //采购详情 ssh 2021.01.25
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = PurchaseService::getInfo($id, true, true);
- if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
- //不能注释,分享付款功能要用,客户没有登录也能付款
- //util::fail('无法访问');
- }
- $customId = $info['customId'] ?? 0;
- $custom = CustomClass::getById($customId);
- $customName = $custom['name'] ?? '';
- $customMobile = $custom['mobile'] ?? '';
- $info['customName'] = $customName;
- $info['customMobile'] = $customMobile;
- $hasDebtPay = $custom['debt'] ?? 0;
- $book = $info['book'] ?? 0;
- $presell = $info['presell'] ?? 0;
- //预售不能记欠款
- if ($book == 1) {
- $hasDebtPay = 0;
- }
- if ($presell == 1) {
- $hasDebtPay = 0;
- }
- $shop = $this->shop;
- $info['pfShopId'] = $shop->pfShopId ?? 0;
- $info['hasDebtPay'] = $hasDebtPay;
- $info['balance'] = $shop->balance ?? 0;
- $getPayType = dict::getDict('getPayType');
- $info['getPayType'] = $getPayType;
- //获取售后条件
- $ghsId = $info['ghsId'] ?? 0;
- $ghsInfo = GhsClass::getById($ghsId, true);
- if (empty($ghsInfo)) {
- util::fail('没有找到供货商');
- }
- $info['afterSale'] = $ghsInfo->afterSale ?? 1;
- //重要,客户看到的电话修改成门店的联系电话
- $ghsShopId = $ghsInfo->shopId ?? 0;
- $ghsShopInfo = ShopClass::getById($ghsShopId, true);
- $info['ghsMobile'] = $ghsShopInfo->telephone ?? '';
- $info['ghsMobile2'] = $ghsShopInfo->telephone2 ?? '';
- $info['hasRenew'] = 1;
- util::success($info);
- }
- //可用的支付方式 ssh 2021.1.25
- public function actionPayWay()
- {
- $button = [
- ['type' => 'wxPay', 'show' => 1, 'disable' => 1],
- ['type' => 'debtPay', 'show' => 1, 'disable' => 0],
- ['type' => 'balancePay', 'show' => 1, 'disable' => 0],
- ];
- util::success(['button' => $button]);
- }
- //待结款明细 ssh 2021.1.26
- public function actionDebtList()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = GhsClass::getGhsInfo($id);
- GhsClass::valid($info, $this->shopId);
- $where = ['ghsId' => $id, 'debt' => PurchaseClass::DEBT_YES];
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $respond = PurchaseService::getDebtList($where);
- util::success($respond);
- }
- //支付宝支付 ssh 2021.4.11
- public function actionAliPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $post = Yii::$app->request->post();
- $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
- $order = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- util::fail('订单号无效');
- }
- if ($order->status == 5) {
- util::fail('订单已取消');
- }
- if ($order->status != 1) {
- util::fail('订单不是待付款状态');
- }
- $deadline = $order->deadline;
- $current = time();
- if (($current + 50) > strtotime($deadline)) {
- util::fail('订单已失效,请重新下单');
- }
- $ghsId = $order->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有供货商信息');
- }
- $ghsShopId = $ghs->shopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- if (empty($ghsShop)) {
- util::fail('没有供货商门店信息');
- }
- if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
- util::fail('商家支付功能未开通');
- }
- //避免重复提交
- util::checkRepeatCommit($orderSn, 8);
- //已经唤起过支付了,根据拉卡拉的规则,需要生成新的订单号
- if ($order->changePrice == 2) {
- $oldOrderSn = $orderSn;
- //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
- $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' => $ghsShop->lklSjNo,
- 'term_no' => $ghsShop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $closeParams = [
- 'orderSn' => $oldOrderSn,
- ];
- $response = $laResource->cashClose($closeParams);
- if (isset($response['code']) == false || $response['code'] != '000000') {
- $msg = $response['msg'] ?? '';
- $code = $response['code'] ?? 0;
- if (!in_array($code, ['000091'])) {
- noticeUtil::push('注意花店买花更换单号:' . $oldOrderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
- }
- }
- $newOrderSn = orderSn::getPurchaseSn();
- $orderSn = $newOrderSn;
- $order->orderSn = $newOrderSn;
- $order->save();
- PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
- }
- $order->changePrice = 2;
- $order->save();
- $ghsShopName = $ghsShop->shopName ?? '';
- //要带上哪个店的,这样才知道客户下的单是哪个店的,客户很多有多家店
- $name = $ghsShopName . " 花材 " . $orderSn;
- $totalFee = $order->realPrice;
- $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
- $ghsId = $order->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有供货商信息');
- }
- $ghsShopId = $ghs->shopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- if (empty($ghsShop)) {
- util::fail('没有供货商门店信息');
- }
- $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' => $ghsShop->lklSjNo,
- 'term_no' => $ghsShop->lklB2BTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
- $wxParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $purchaseCapital,
- 'notifyUrl' => $notifyUrl,
- 'subject' => $name,
- ];
- $response = $laResource->cashierPay($wxParams);
- if (isset($response['code']) == false || $response['code'] != '000000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push('编号AA90:' . $errMsg, '15280215347');
- util::fail('发起支付失败');
- }
- $counter_url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
- $hasRenew = $ghsShop->hasRenew ?? 0;
- $new = [
- 'payUrl' => $counter_url,
- 'orderSn' => $orderSn,
- 'hasRenew' => 1,
- ];
- util::success($new);
- }
- //微信支付 ssh 2021.4.11
- public function actionWxPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $post = Yii::$app->request->post();
- $couponId = $post['couponId'] ?? 0;
- $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
- $order = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- util::fail('订单号无效');
- }
- if ($order->status == 5) {
- util::fail('订单已取消');
- }
- if ($order->status != 1) {
- util::fail('订单不是待付款状态');
- }
- $deadline = $order->deadline;
- $current = time();
- if (($current + 50) > strtotime($deadline)) {
- util::fail('订单已失效,请重新下单');
- }
- //避免重复提交
- util::checkRepeatCommit($orderSn, 8);
- $ghsId = $order->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有供货商信息');
- }
- $ghsShopId = $ghs->shopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- if (empty($ghsShop)) {
- util::fail('没有供货商门店信息');
- }
- if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
- util::fail('商家支付功能未开通');
- }
- //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号
- if ($order->changePrice == 2) {
- $oldOrderSn = $orderSn;
- //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
- $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' => $ghsShop->lklSjNo,
- 'term_no' => $ghsShop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $closeParams = [
- 'orderSn' => $oldOrderSn,
- ];
- $response = $laResource->close($closeParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- $msg = $response['msg'] ?? '';
- $code = $response['code'] ?? 0;
- if (!in_array($code, ['BBS11114'])) {
- noticeUtil::push('重点注意,花店买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . $code, '15280215347');
- util::fail('出错了,请重新下单');
- }
- }
- $newOrderSn = orderSn::getPurchaseSn();
- $orderSn = $newOrderSn;
- $order->orderSn = $newOrderSn;
- $order->save();
- PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
- }
- $id = $order->id;
- $order->changePrice = 2;
- $order->save();
- $ghsShopName = $ghsShop->shopName ?? '';
- //要带上哪个店的,这样才知道客户下的单是哪个店的,客户很多有多家店
- $name = $ghsShopName . " 花材 " . $orderSn;
- $totalFee = $order->realPrice;
- $openId = '';
- if (isset($post['currentMiniOpenId']) && !empty($post['currentMiniOpenId'])) {
- $openId = $post['currentMiniOpenId'];
- //noticeUtil::push('花店采购下单时,通过前端获取了openId:' . $openId, '15280215347');
- }
- if (empty($openId)) {
- if (isset($this->admin) && !empty($this->admin)) {
- if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
- $openId = $this->admin->miniOpenId;
- noticeUtil::push('花店采购下单时,通过数据库获取了openId:' . $openId, '15280215347');
- }
- }
- }
- if (empty($openId)) {
- $currentShopId = $order->shopId ?? 0;
- $currentShop = ShopClass::getById($currentShopId, true);
- $currentShopName = $currentShop->merchantName . ' ' . $currentShop->shopName;
- $currentMobile = $currentShop->mobile ?? '';
- noticeUtil::push("花店采购时,发现没有openId,请跟进是否采购成功。{$currentShopName} {$currentMobile}", '15280215347');
- util::success(['hasError' => 1, 'hasNoMiniOpenId' => 1]);
- }
- $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
- //花卉宝代为申请的微信支付
- $merchantExtend = WxOpenClass::getWxInfo();
- $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' => $ghsShop->lklSjNo,
- 'term_no' => $ghsShop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
- $wxParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $purchaseCapital,
- 'notifyUrl' => $notifyUrl,
- 'wxAppId' => $merchantExtend['miniAppId'],
- 'openId' => $openId,
- 'subject' => $name,
- 'couponId' => $couponId,
- ];
- $response = $laResource->driveWxPay($wxParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push('编号129680931:' . $errMsg, '15280215347');
- util::fail('支付失败');
- }
- $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
- $appId = $newParams['app_id'] ?? '';
- $nonceStr = $newParams['nonce_str'] ?? '';
- $paySign = $newParams['pay_sign'] ?? '';
- $package = $newParams['package'] ?? '';
- $signType = $newParams['sign_type'] ?? '';
- $timeStamp = $newParams['time_stamp'] ?? '';
- $new = [
- 'id' => $id,
- 'appId' => $appId,
- 'nonceStr' => $nonceStr,
- 'paySign' => $paySign,
- 'package' => $package,
- 'signType' => $signType,
- 'timeStamp' => $timeStamp,
- 'orderSn' => $orderSn,
- ];
- util::success($new);
- }
- //计算运费 ssh 20221003
- public function actionFreight()
- {
- $get = Yii::$app->request->get();
- $shop = $this->shop;
- $shopLat = isset($shop->lat) ? $shop->lat : '';
- $shopLong = isset($shop->long) ? $shop->long : '';
- if (empty($shopLat) || empty($shopLong)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $ghsId = $get['ghsId'] ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $ghsShopId = $ghs->shopId ?? 0;
- $ghsShop = ShopClass::getById($ghsShopId, true);
- if (empty($ghsShop)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $ghsShopLat = isset($ghsShop->lat) ? $ghsShop->lat : '';
- $ghsShopLong = isset($ghsShop->long) ? $ghsShop->long : '';
- if (empty($ghsShopLat) || empty($ghsShopLong)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $weight = $get['weight'] ?? 0;
- if (empty($weight)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $respond = PurchaseClass::getDistanceFee($this->shop, $ghsShop, $weight);
- util::success($respond);
- }
- //运费计算 lqh 2021.4.12 暂时返回固定值
- public function actionFreight2()
- {
- //lqh 2021.6.25 运费固定返回0
- util::success(['sedCost' => 0]);
- $post = Yii::$app->request->post();
- $ghsId = $post['ghsId'] ?? 0;
- //供货商
- $ghsInfo = GhsClass::getById($ghsId);
- if (empty($ghsInfo)) {
- util::fail('没有找到供货商');
- }
- //花材信息
- $productJson = $post['product'] ?? '';
- // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
- if (empty($productJson)) {
- util::fail('请选择花材');
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- util::fail('请选择花材25');
- }
- $productList = PurchaseClass::mergeItemInfo($productList);
- $weight = 0;
- $price = 0;
- $productData = ProductClass::getProductMapData($productList);
- $bigNum = 0;
- foreach ($productList as $key => $val) {
- $productId = $val['productId'];
- $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
- $bigNum += $val['bigNum'];
- $weight = bcadd($w, $weight, 2);
- $ratio = $productData[$productId]['ratio'] ?? 0;
- //大小数量合并多少扎
- $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
- //售卖价格
- $itemPrice = $productData[$productId]['price'] ?? 0;
- //合计价格
- $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
- }
- $ghsShopId = $ghsInfo['shopId'] ?? 0;
- $ghsSjId = $ghsInfo['sjId'] ?? 0;
- $sendTime = $post['sendTime'] ?? '';
- if (!empty($sendTime)) {
- //配送时间不为空
- // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
- $sendTimeInt = strtotime($sendTime);
- $now = time();
- $diff = $sendTimeInt - $now;
- //因服务器写入时间,改为至少提前6分钟
- if ($diff <= 360) {
- util::fail('配送时间至少提前6分钟');
- }
- $sendTime = date('Y-m-d H:i', strtotime($sendTime));
- } else {
- $sendTime = date('Y-m-d H:i', strtotime("+30 minute"));
- }
- //找供货商的客户信息,用里面的配送相关地址信息
- $customId = $ghsInfo['customId'] ?? 0;
- $customInfo = CustomClass::getById($customId);
- if (empty($customInfo)) {
- util::fail('没有找到客户');
- }
- //判断商家是否开启达达,若未开启,则使用自定义运费计算
- $shopNo = ShopExpressClass::getShopNo($ghsSjId, $ghsShopId);
- if (!$shopNo) {
- //使用自定义运费
- //util::fail('供货商暂未开通配送');
- $cost = freight::getCost($ghsInfo['lat'], $ghsInfo['long'], $customInfo['lat'], $customInfo['long'], $weight);
- util::success(['sedCost' => $cost]);
- }
- //组装订单信息
- $info = [];
- //发送放的商家信息,即供货商的相关信息
- $info['sjId'] = $ghsSjId;
- $info['shopId'] = $ghsShopId;
- $info['actPrice'] = $price;//价格
- $info['weight'] = $weight;
- $info['orderSn'] = \common\components\orderSn::getGhsOrderSn();
- $info['bigNum'] = $bigNum;
- //配送地址,当前零售端的门店地址
- $info['customName'] = $customInfo['name'] ?? '';
- $info['customMobile'] = $customInfo['mobile'] ?? '';
- $info['province'] = $customInfo['province'] ?? '';
- $info['city'] = $customInfo['city'] ?? '';;
- $info['address'] = $customInfo['address'] ?? '';;
- $info['floor'] = $customInfo['floor'] ?? '';;
- $info['fullAddress'] = $customInfo['fullAddress'] ?? '';;
- $info['lat'] = $customInfo['lat'] ?? '';;
- $info['long'] = $customInfo['long'] ?? '';;
- $info['sendTime'] = $sendTime;
- $res = DadaExpressServices::queryDeliverFee($info);
- util::success(['sedCost' => $res['fee']]);
- }
- }
|