| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopExtClass;
- use bizGhs\express\services\DadaExpressServices;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\services\PurchaseService;
- use bizHd\wx\classes\WxOpenClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\services\OrderService;
- use bizHd\saas\services\RegionService;
- use bizGhs\product\classes\ProductClass;
- use common\components\baiduAip;
- use common\components\dict;
- use common\components\dateUtil;
- use common\components\freight;
- use common\components\httpUtil;
- use common\components\noticeUtil;
- use common\components\oss;
- use common\components\payUtil;
- use common\components\qrCodeUtil;
- use Yii;
- use common\components\util;
- use biz\shop\classes\ShopAdminClass;
- use biz\notice\classes\NoticeClass;
- use biz\wx\classes\WxMessageClass;
- use biz\shop\classes\ShopClass;
- use common\components\lakala\Lakala;
- class OrderController extends BaseController
- {
- public $guestAccess = ['create-order', 'order-relate', 'fast-pay', 'info'];
- //确认送达
- public function actionConfirmReach()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? '';
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- if ($order->status == 1) {
- util::fail('订单待付款');
- }
- if ($order->status == 4) {
- util::fail('订单已完成');
- }
- if ($order->status == 5) {
- util::fail('订单已取消');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderClass::confirmReach($order);
- $transaction->commit();
- util::complete('操作成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("操作失败原因:" . $e->getMessage());
- util::fail('确认失败');
- }
- }
- public function actionAllFh()
- {
- $post = Yii::$app->request->post();
- $ids = $post['ids'] ?? '';
- if (empty($ids)) {
- util::fail('请选择要合并发货的订单');
- }
- $arr = explode(',', $ids);
- if (empty($arr)) {
- util::fail('请选择要合并发货的订单哦');
- }
- $fhWl = $post['fhWl'] ?? '';
- $fhWlNo = $post['fhWlNo'] ?? '';
- $fhType = 0;
- $params = [
- 'fhType' => $fhType,
- 'fhWl' => $fhWl,
- 'fhWlNo' => $fhWlNo,
- ];
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $all = OrderClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true);
- foreach ($all as $order) {
- if ($order->book == 1) {
- util::fail('有预订单,不能一起发货');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单哦');
- }
- OrderClass::orderSend($order, $params, true);
- }
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("操作失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //发货 ssh 20230613
- public function actionFh()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? '';
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $fhWl = $post['fhWl'] ?? '';
- $fhWlNo = $post['fhWlNo'] ?? '';
- $fhType = $post['fhType'] ?? '';
- $params = [
- 'fhType' => $fhType,
- 'fhWl' => $fhWl,
- 'fhWlNo' => $fhWlNo,
- ];
- if ($order->book == 1) {
- util::fail('预订单不支持这个发货方式');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderClass::orderSend($order, $params);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("操作失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //合并打印 ssh 20230929
- public function actionMergePrint()
- {
- $post = Yii::$app->request->post();
- $ids = $post['ids'] ?? '';
- if (empty($ids)) {
- util::fail('请选择要合并打印的订单');
- }
- $arr = explode(',', $ids);
- if (empty($arr)) {
- util::fail('请选择要合并打印的订单哦');
- }
- if (getenv('YII_ENV') == 'production') {
- if ($this->mainId != 10536 && $this->mainId != 50) {
- //util::fail('功能开发中');
- }
- } else {
- if ($this->mainId != 11) {
- //util::fail('功能开发中');
- }
- }
- OrderClass::mergePrintOrder($arr, $this->mainId);
- util::complete('打印成功');
- }
- //修改分工 ssh 20221129
- public function actionChangeWorker()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $shopAdminId = $post['shopAdminId'] ?? 0;
- $shopAdminName = $post['shopAdminName'] ?? '';
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $preShopAdminId = $order->shopAdminId ?? 0;
- if (!empty($preShopAdminId)) {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('管理员才能操作');
- }
- }
- $order->shopAdminId = $shopAdminId;
- $order->shopAdminName = $shopAdminName;
- $order->save();
- util::complete();
- }
- //预订单到货 ssh 20220321
- public function actionArrival()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $post['shopAdminId'] = $this->shopAdminId;
- $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
- OrderService::arrival($order, $post);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("操作失败原因:" . $e->getMessage());
- util::fail('操作失败');
- }
- }
- //到货获取订单详情 ssh 20220323
- public function actionArrivalDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = OrderClass::getById($id);
- OrderClass::valid($info, $this->shopId);
- $showItemData = OrderClass::getOriginalShowItem(true, $info);
- $itemList = $showItemData['list'] ?? [];
- $info['product'] = $itemList;
- $kiloFee = $this->shop->kiloFee ?? 0;
- $miniKilo = $this->shop->miniKilo ?? 0;
- $info['kiloFee'] = $kiloFee;
- $info['miniKilo'] = $miniKilo;
- util::success($info);
- }
- //支付宝扫码支付 ssh 20210103
- public function actionScanPayCheck()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $order = OrderClass::getById($id, true);
- if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
- util::success(['returnStatus' => 'SUCCESS']);
- }
- $deadline = $order->deadline ?? '';
- $deadTime = strtotime($deadline);
- $current = time();
- $diff = bcsub($deadTime, $current);
- if ($diff <= 60) {
- util::success(['returnStatus' => 'EXPIRE']);
- }
- util::success(['returnStatus' => 'FAILURE']);
- }
- //微信和支付宝扫码支付 ssh 20210103
- public function actionScanPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- header("Content-type: text/html; charset=utf-8");
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $order = OrderClass::getById($id, true);
- if (isset($order->status) == false || $order->status != 1) {
- util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
- }
- OrderClass::valid($order, $this->shopId);
- $cgId = $order->purchaseId ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- $orderSn = $cg->orderSn ?? '';
- if (empty($orderSn)) {
- util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
- }
- $deadline = $cg->deadline;
- $current = date("Y-m-d H:i:s");
- if ((strtotime($deadline) + 20) < strtotime($current)) {
- util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
- }
- $totalFee = $cg->actPrice ?? 0;
- $subject = '购买鲜花';
- $totalAmount = $totalFee;
- $body = "到店订单";
- //标记为扫码支付 和 自取订单
- $order->codePay = 2;
- $order->sendType = OrderClass::SEND_TYPE_NO;
- $order->save();
- $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
- $cg->codePay = 2;
- $cg->save();
- $shop = $this->shop;
- $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
- $wxPayWay = dict::getDict('payWay', 'wxPay');
- $aliPayWay = dict::getDict('payWay', 'alipay');
- $payWay = Yii::$app->request->get('payWay', $wxPayWay);
- if ($payWay == $wxPayWay) {
- if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
- $url = $order->wxPayUrl;
- } else {
- util::fail('暂不支持');
- $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' => $shop->lklSjNo,
- 'term_no' => $shop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
- $wxParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $currentCapitalType,
- 'notifyUrl' => $notifyUrl,
- 'subject' => $subject,
- 'couponId' => 0,
- 'wxAppId' => $merchantExtend['miniAppId'],
- ];
- $response = $laResource->driveNativeWxPay($wxParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- $msg = $response['msg'] ?? '';
- noticeUtil::push($msg, '15280215347');
- util::fail('二维码生成失败');
- }
- $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
- if (empty($url)) {
- util::fail('二维码生成失败..');
- }
- $order->wxPayUrl = $url;
- $order->save();
- }
- $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
- $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
- util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
- }
- if ($payWay == $aliPayWay) {
- if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
- $url = $order->aliPayUrl;
- } else {
- $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);
- $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
- $aliParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $currentCapitalType,
- 'notifyUrl' => $notifyUrl,
- 'subject' => $subject,
- ];
- $response = $laResource->driveAliPay($aliParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- util::fail('二维码生成失败');
- }
- $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
- if (empty($url)) {
- util::fail('二维码生成失败..');
- }
- $order->aliPayUrl = $url;
- $order->save();
- }
- $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
- $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
- util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
- }
- util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
- }
- //微信和支付宝付款码支付复查 ssh 20211231
- public function actionCodePayCheck()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- header("Content-type: text/html; charset=utf-8");
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::success(['returnStatus' => 'SUCCESS']);
- }
- if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
- util::complete('订单已付款');
- }
- if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
- util::complete('订单不是待付款状态');
- }
- OrderClass::valid($order, $this->shopId);
- $cgId = $order->purchaseId ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- $orderSn = $cg->orderSn ?? '';
- $totalFee = $cg->actPrice ?? 0;
- if (empty($orderSn)) {
- util::complete('没有找到采购单');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
- $shop = $this->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);
- $scanParams = ['orderSn' => $orderSn,];
- $response = $laResource->query($scanParams);
- if (isset($response['code']) && $response['code'] == 'BBS00000') {
- if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
- //支付成功
- $transactionId = $response['resp_data']['trade_no'] ?? '';
- $openId = '';
- $aliUserId = '';
- $cg->onlinePay = dict::getDict('onlinePay', 'yes');
- $cg->codePay = 1;
- $cg->payOpenId = $openId;
- $cg->aliUserId = $aliUserId;
- //自取订单
- $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
- $cg->save();
- $order->onlinePay = dict::getDict('onlinePay', 'yes');
- $order->codePay = 1;
- //自取订单
- $order->sendType = OrderClass::SEND_TYPE_NO;
- $order->save();
- $payWayType = dict::getDict('payWay', 'wxPay');
- $account_type = $response['resp_data']['account_type'] ?? '';
- if ($account_type == 'WECHAT') {
- $payWayType = dict::getDict('payWay', 'wxPay');
- }
- if ($account_type == 'ALIPAY') {
- $payWayType = dict::getDict('payWay', 'alipay');
- }
- $order->payWay = $payWayType;
- $order->save();
- $cg->payWay = $payWayType;
- $cg->save();
- $attach = '';
- payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
- $transaction->commit();
- $saleId = $order->id ?? 0;
- $order = OrderClass::getById($saleId, true);
- if (!empty($order)) {
- //订单生成时唤起在线打印
- if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
- if ($order->status != 1 && $order->status != 5) {
- OrderClass::onlinePrint($order);
- $order->printNum += 1;
- $order->save();
- }
- }
- ShopExtClass::ghsGatheringReport($order);
- }
- util::success(['returnStatus' => 'SUCCESS']);
- } else {
- util::complete('未知状态..');
- }
- } else {
- util::complete('未知状态....');
- }
- } catch (\Exception $e) {
- $transaction->rollBack();
- noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
- util::fail('支付失败');
- }
- }
- //微信和支付宝付款码支付 ssh 2021.4.11
- public function actionCodePay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- header("Content-type: text/html; charset=utf-8");
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $order = OrderClass::getById($id, true);
- if (isset($order->status) == false || $order->status != 1) {
- util::fail('不是待付款订单');
- }
- OrderClass::valid($order, $this->shopId);
- $cgId = $order->purchaseId ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- $orderSn = $cg->orderSn ?? '';
- if (empty($orderSn)) {
- util::fail('没有找到采购单');
- }
- //付款码
- $authCode = (string)$get['authCode'] ?? '';
- if (empty($authCode)) {
- util::fail('支付失败');
- }
- $deadline = $cg->deadline;
- $current = date("Y-m-d H:i:s");
- if ((strtotime($deadline) + 20) < strtotime($current)) {
- util::fail('订单已经失效');
- }
- $totalFee = $cg->actPrice ?? 0;
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $subject = '购买花材';
- $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
- $shop = $this->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);
- $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
- $scanParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'subject' => $subject,
- 'authCode' => $authCode,
- ];
- $response = $laResource->scanPay($scanParams);
- if (isset($response['code']) && $response['code'] == 'BBS00000') {
- $account_type = $response['resp_data']['account_type'] ?? '';
- $payWayType = dict::getDict('payWay', 'wxPay');
- if ($account_type == 'WECHAT') {
- $payWayType = dict::getDict('payWay', 'wxPay');
- }
- if ($account_type == 'ALIPAY') {
- $payWayType = dict::getDict('payWay', 'alipay');
- }
- $order->payWay = $payWayType;
- $order->save();
- $cg->payWay = $payWayType;
- $cg->save();
- $transactionId = $response['resp_data']['trade_no'] ?? '';
- $openId = '';
- $aliUserId = '';
- $cg->onlinePay = dict::getDict('onlinePay', 'yes');
- $cg->codePay = 1;
- $cg->payOpenId = $openId;
- $cg->aliUserId = $aliUserId;
- //自取订单
- $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
- $cg->save();
- $order->onlinePay = dict::getDict('onlinePay', 'yes');
- $order->codePay = 1;
- //自取订单
- $order->sendType = OrderClass::SEND_TYPE_NO;
- $order->save();
- $attach = '';
- payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
- $transaction->commit();
- $saleId = $order->id ?? 0;
- $order = OrderClass::getById($saleId, true);
- if (!empty($order)) {
- //订单生成时唤起在线打印
- if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
- if ($order->status != 1 && $order->status != 5) {
- OrderClass::onlinePrint($order);
- $order->printNum += 1;
- $order->save();
- }
- }
- ShopExtClass::ghsGatheringReport($order);
- }
- util::success(['returnStatus' => 'SUCCESS']);
- } else {
- $msg = $response['msg'] ?? '';
- util::success(['returnStatus' => 'FAILURE'], $msg);
- }
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("支付失败原因:" . $e->getMessage());
- util::fail('支付失败');
- }
- }
- //订单列表 ssh 2021.1.20
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where['mainId'] = $this->mainId;
- $status = $get['status'] ?? 0;
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $book = $get['book'] ?? -1;
- if ($book > -1) {
- $where['book'] = $book;
- }
- $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']]];
- }
- $name = $get['name'] ?? '';
- if (!empty($name)) {
- $searchType = $get['searchType'] ?? 0;
- if (empty($searchType)) {
- //订单编号
- if (strpos($name, 'XSD') === 0) {
- $where['orderSn'] = $name;
- } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
- $where['customNamePy'] = ['like', $name];
- } else {
- $where['customName'] = ['like', $name];
- }
- } elseif ($searchType == 1) {
- $where['sendNum'] = $name;
- } else {
- }
- }
- if (isset($get['customId']) && !empty($get['customId'])) {
- $where['customId'] = $get['customId'];
- }
- if (isset($get['ids']) && !empty($get['ids'])) {
- $stringIds = $get['ids'];
- $newIds = explode(',', $stringIds);
- $where['id'] = ['in', $newIds];
- }
- $respond = OrderClass::getOrderList($where);
- $respond['shop'] = $this->shop;
- $respond['shopExt'] = $this->shopExt;
- util::success($respond);
- }
- // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
- public function actionNewOrderList()
- {
- $get = Yii::$app->request->get();
- $where['shopId'] = $this->shopId;
- /*$status = $get['status'] ?? 0;
- if (!empty($status)) {
- $where['status'] = $status;
- }*/
- // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
- if (isset($get['type'])) {
- $type = $get['type'];
- if ($type == 1) { // 今日实收
- $get['searchTime'] = 'today';
- $where['debt'] = 0;
- $where['debtPrice'] = '0.00';
- $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
- } elseif ($type == 2) { // 今日欠款
- $get['searchTime'] = 'today';
- $where['debt'] = 1;
- } elseif ($type == 3) { // 总欠款
- $where['debt'] = 1;
- } else {
- util::fail('查询的订单类别不存在');
- }
- }
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = '';
- $endTime = '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $name = $get['name'] ?? '';
- if (!empty($name)) {
- $searchType = $get['searchType'] ?? 0;
- if (empty($searchType)) {
- //订单编号
- if (strpos($name, 'XSD') === 0) {
- $where['orderSn'] = $name;
- } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
- $where['customNamePy'] = ['like', $name];
- } else {
- $where['customName'] = ['like', $name];
- }
- } elseif ($searchType == 1) {
- $where['sendNum'] = $name;
- } else {
- util::fail('搜索的订单类别不存在');
- }
- }
- $respond = OrderClass::getOrderList($where);
- $respond['shop'] = $this->shop;
- $respond['shopExt'] = $this->shopExt;
- $respond['type'] = $type; //把查询类别返回
- util::success($respond);
- }
- //商城下单操作 ssh 2021.1.14
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $shopId = $this->shopId;
- $customId = $post['customId'] ?? 0;
- $post['customId'] = $customId;
- //开单必须选客户
- if (empty($customId)) {
- util::fail('请选择客户');
- }
- $custom = CustomClass::getCustom($customId);
- if (empty($custom)) {
- util::fail('请选客户哦');
- }
- CustomClass::valid($custom, $this->shopId);
- if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
- util::fail('不能给自己的零售店开单');
- }
- $post['ghsId'] = $custom['ghsId'] ?? 0;
- $post['customMobile'] = $custom['mobile'] ?? '';
- $customName = $custom['name'] ?? '';
- $post['customName'] = $customName;
- $post['customNamePy'] = $custom['py'] ?? '';
- $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
- $post['province'] = $custom['province'] ?? '';
- $post['city'] = $custom['city'] ?? '';
- $post['dist'] = $custom['dist'] ?? '';
- $post['address'] = $custom['address'] ?? '';
- $post['floor'] = $custom['floor'] ?? '';
- $post['fullAddress'] = $custom['fullAddress'] ?? '';
- $post['showAddress'] = $custom['showAddress'] ?? '';
- $post['long'] = $custom['long'] ?? '';
- $post['lat'] = $custom['lat'] ?? '';
- $shopAdmin = $this->shopAdmin;
- $shopAdminId = $this->shopAdminId;
- $shopAdminName = $shopAdmin->name ?? '';
- if (isset($post['getStaffId']) == true && !empty($post['getStaffId'])) {
- $getStaffName = $post['getStaffName'] ?? '';
- $shopAdminId = $post['getStaffId'];
- $shopAdminName = $getStaffName;
- }
- //开单人和收款人必定是同个人
- $post['shopAdminId'] = $shopAdminId;
- $post['shopAdminName'] = $shopAdminName;
- $post['getStaffId'] = $shopAdminId;
- $post['getStaffName'] = $shopAdminName;
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $shopId;
- $post['mainId'] = $this->mainId;
- $post['fromType'] = 1;
- $post['expressId'] = $post['expressId'] ?? 0;
- $book = $post['book'] ?? 0;
- $post['book'] = $book;
- $sendType = $post['sendType'] ?? 0;
- $transType = $post['transType'] ?? 0;
- $shop = $this->shop;
- if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
- //昆明发往全国
- $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
- $post['sendCost'] = $sendCost;
- $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
- $post['packCost'] = $packCost;
- $post['transType'] = $transType;
- $post['localOrder'] = 1;
- } else {
- //同步配送
- $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
- if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
- util::fail('填了运费,请选择代叫跑腿');
- }
- $post['sendCost'] = $sendCost;
- $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
- }
- $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
- $post['debt'] = OrderClass::DEBT_NO;
- if ($hasPay == dict::getDict('hasPay', 'debt')) {
- $post['debt'] = OrderClass::DEBT_YES;
- }
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- if ($hasPay == dict::getDict('hasPay', 'payed')) {
- //util::fail('没有权限');
- }
- }
- //多颜色数据整理
- $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;
- $productJson = $post['product'] ?? '';
- if (empty($productJson)) {
- util::fail('请选择花材');
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- util::fail('请选择花材');
- }
- $dealPrice = $post['dealPrice'] ?? 0;
- $ids = array_unique(array_filter(array_column($productList, 'productId')));
- $itemInfo = ProductClass::getByIds($ids, null, 'id');
- if (empty($itemInfo)) {
- util::fail('请选择花材哦');
- }
- //判断花材有效性
- foreach ($itemInfo as $itemData) {
- if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
- util::fail('只能选择同一家的商品哈');
- }
- }
- //开单提交订单时,别人修改价格,暂成提交价格不是真实卖价问题解决!!
- if ($dealPrice == 0) {
- $diff = [];
- $priceMap = CustomClass::$levelPriceKeyMap;
- $addPriceMap = CustomClass::$levelAddPriceKeyMap;
- $level = $custom['level'] ?? 1;
- foreach ($productList as $currentKey => $currentProduct) {
- $currentPrice = $currentProduct['price'] ?? 0;
- $currentId = $currentProduct['productId'] ?? 0;
- $systemInfo = $itemInfo[$currentId] ?? [];
- $name = $systemInfo['name'] ?? '';
- $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
- if (floatval($currentPrice) != floatval($systemPrice)) {
- $diff[] = [
- 'name' => $name,
- 'price' => $systemPrice,
- 'kdPrice' => $currentPrice,
- ];
- }
- }
- if (!empty($diff)) {
- util::success(['diff' => $diff, 'respondType' => 'priceError']);
- }
- }
- if ($book == 1) {
- foreach ($productList as $currentKey => $currentProduct) {
- //帮开预订单没有价格
- $productList[$currentKey]['price'] = 0.06;
- }
- $post['hasPay'] = 2;
- $post['payWay'] = 0;
- } else {
- foreach ($productList as $currentKey => $currentProduct) {
- //预订单用了0.06这个价格
- $nowPrice = $currentProduct['price'];
- if ($nowPrice == 0.06) {
- util::fail('花材不允许使用0.06元,请改其它价');
- }
- }
- }
- //4秒内不允许重复开单
- $staffId = $this->shopAdminId ?? 0;
- $cacheKey = 'ghs_create_order_' . $staffId . '_' . $customId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('请稍等');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
- $post['product'] = $productList;
- //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
- $time = time();
- $hasTime = dict::getDict('order_pay_has_time');
- $totalTime = bcadd($time, $hasTime);
- $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
- $return = OrderService::createFinishOrder($post, $custom, $hasPay);
- $transaction->commit();
- $saleId = $return->id ?? 0;
- $order = OrderClass::getById($saleId, true);
- if (!empty($order)) {
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (isset($order->payStatus) && $order->payStatus == 1) {
- if (!empty($shop)) {
- //通知员工
- $noticeText = json_encode(['orderId' => $saleId]);
- $noticeKey = "hdCgNoticeGhs";
- Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
- //通知花店
- // $noticeText = json_encode(['id' => $order->purchaseId]);
- // $noticeKey = "ghsKdNoticeHd";
- // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
- }
- }
- //订单生成时唤起在线打印
- if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
- if ($order->status != 1 && $order->status != 5) {
- OrderClass::onlinePrint($order);
- $order->printNum += 1;
- $order->save();
- }
- }
- //前台提醒出示付款码
- if (isset($order->status) && $order->status == 1) {
- if (isset($post['isCashier']) && $post['isCashier'] == 1) {
- ShopExtClass::ghsPleasePayReport($order);
- }
- }
- }
- util::success($return);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("下单失败原因:" . $e->getMessage());
- noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
- util::fail('下单失败');
- }
- }
- //修改订单 ssh 20210810
- public function actionUpdateOrder()
- {
- $post = Yii::$app->request->post();
- util::fail('订单不可修改');
- //PC端开单
- if (isset($post['clearType'])) {
- $clearType = $post['clearType'];
- if ($clearType == OrderClass::CLEAR_DEBT) {
- $post['debt'] = OrderClass::DEBT_YES;
- $post['payWay'] = dict::getDict('payWay', 'debtPay');
- } else {
- $post['debt'] = OrderClass::DEBT_NO;
- }
- }
- //员工不能开已收款订单
- $debt = $post['debt'] ?? OrderClass::DEBT_YES;
- if ($debt == OrderClass::DEBT_NO) {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('不能开已收款订单');
- }
- }
- //PC端开单
- if (isset($post['getType'])) {
- util::fail('暂不支持PC端修改订单');
- $getType = $post['getType'];
- //自取
- if ($getType == 1) {
- $post['sendType'] = OrderClass::SEND_TYPE_NO;
- } else {
- //选择配送时,在发货时让商家自己再确认一下用什么方式
- $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
- }
- }
- //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
- if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
- $post['debt'] = OrderClass::DEBT_NO;
- }
- $id = $post['id'] ?? 0;
- $order = OrderClass::getLockById($id);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- OrderClass::valid($order, $this->shopId);
- unset($post['id']);
- $shopAdmin = $this->shopAdmin;
- $post['shopAdminId'] = $this->shopAdminId;
- $post['shopAdminName'] = $shopAdmin->name ?? '';
- $post['fromType'] = 1;
- $post['sendCost'] = $post['sendCost'] ?? '0.00';
- $productJson = $post['product'] ?? '';
- if (empty($productJson)) {
- util::fail('请选择花材');
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- util::fail('请选择花材');
- }
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
- //判断花材有效性
- ProductClass::valid($productList, $this->mainId);
- $post['product'] = $productList;
- //商家开单订单有效期,到期记欠款
- $validTime = dict::getDict('order_pay_has_time');
- $current = time() + $validTime;
- $post['deadline'] = date("Y-m-d H:i:s", $current);
- $upData = [
- 'payWay' => $post['payWay'],
- 'sendType' => $post['sendType'],
- 'debt' => $post['debt'],
- 'needPrint' => $post['needPrint'],
- 'modifyPrice' => $post['modifyPrice'],
- 'shopAdminId' => $post['shopAdminId'],
- 'shopAdminName' => $post['shopAdminName'],
- 'fromType' => 1,
- 'sendCost' => $post['sendCost'],
- 'product' => $post['product'],
- 'deadline' => $post['deadline'],
- 'debt' => $post['debt'],
- ];
- $return = OrderService::updateOrder($order, $upData);
- $transaction->commit();
- util::success($return);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("下单失败原因:" . $e->getMessage());
- util::fail('下单失败');
- }
- }
- //取消订单 shizhongqi 20220619
- public function actionCancelOrder()
- {
- $post = Yii::$app->request->post();
- $id = $post['orderId'] ?? 0;
- if (empty($id)) {
- util::fail('请选择订单');
- }
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('请选择订单...');
- }
- OrderClass::valid($order, $this->shopId);
- if (isset($order->status) == false || $order->status != 1) {
- util::fail('不是待付款状态,无法取消');
- }
- $purchaseId = $order->purchaseId ?? 0;
- $purchase = PurchaseClass::getById($purchaseId);
- if (empty($purchase)) {
- util::fail('没有找到采购单');
- }
- $deadLineTime = strtotime($purchase['deadline']);
- $diff = $deadLineTime - time();
- if ($diff <= 60) {
- util::fail('1分钟后订单将自动取消');
- }
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- $orderSn = $purchase['orderSn'];
- try {
- $current = PurchaseClass::getById($purchaseId, true);
- PurchaseService::expire($current);
- $transaction->commit();
- //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
- }
- util::complete();
- }
- //延期支付 ssh 2021.1.19
- public function actionDebt()
- {
- $id = Yii::$app->request->get('id');
- //4秒内不允许重复提交
- $cacheKey = 'ghs_set_order_debt_' . $id;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('请稍等');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $payWay = dict::getDict('payWay', 'debtPay');
- $cgId = $order->purchaseId ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- if (empty($cg)) {
- util::fail('没有找到采购单');
- }
- if ($order->book == 1) {
- util::fail('预订单不能记欠款');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- PurchaseService::payAfter($cg, $payWay);
- OrderService::payAfter($order, $payWay);
- $transaction->commit();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("延期支付报错:" . $exception->getMessage());
- util::fail('操作失败');
- }
- $order = OrderClass::getById($id, true);
- if (!empty($order)) {
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (!empty($shop)) {
- //花店采购供货商端微信收到通知
- //WxMessageClass::ghsHasNewOrderInform($shop, $order);
- $noticeText = json_encode(['orderId' => $id]);
- $noticeKey = "hdCgNoticeGhs";
- Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
- }
- //订单生成时唤起在线打印
- if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
- if ($order->status != 1 && $order->status != 5) {
- OrderClass::onlinePrint($order);
- $order->printNum += 1;
- $order->save();
- }
- }
- if ($order->status != 1 && $order->status != 5) {
- //花店采购供货商端APP收到通知
- //NoticeClass::ghsNewOrderNotice($order);
- }
- }
- util::complete();
- }
- //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
- 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 = OrderClass::getByOrderSn($orderSn);
- if (empty($order)) {
- util::fail('订单号无效');
- }
- $id = $order['id'];
- //支付前验证订单有效性
- if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
- util::fail('无法操作');
- }
- $name = $order['orderName'] ?? '购买商品';
- $totalFee = $order['actPrice'];
- //强制使用小程序的miniOpenId
- $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
- if (empty($openId)) {
- util::fail('没有找到openId');
- }
- $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
- $wxPayType = 0;
- if (httpUtil::isMiniProgram()) {
- $wxPayType = 1;
- }
- $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
- //订单30分钟后过期
- $now = time();
- $expireTime = $now + 1800;
- $wx = Yii::getAlias("@vendor/weixin");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.JsApiPay.php');
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($name);
- $input->SetOut_trade_no($orderSn);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetTime_start(date("YmdHis", $now));
- $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
- $input->SetTime_expire(date("YmdHis", $expireTime));
- $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("JSAPI");
- //花卉宝代为申请的微信支付
- //$sjExtend = $this->sjExtend->attributes;
- $sjExtend = WxOpenClass::getGhsWxInfo();
- if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
- $input->SetSub_openid($openId);
- } else {
- $input->SetOpenid($openId);
- }
- //强制使用小程序的miniAppId
- $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
- $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
- $tools = new \JsApiPay();
- $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
- $newParams = json_decode($jsApiParameters, true);
- //微信不能修改价格
- $current = date("Y-m-d H:i:s");
- $updateData = ['deadline' => $current, 'modPrice' => 0];
- OrderClass::updateById($id, $updateData);
- util::success($newParams);
- }
- //获取订单详情 ssh 2021.1.21
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = OrderService::getOrderInfo($id, true, true, true, false);
- OrderClass::valid($info, $this->shopId);
- //A4打印需要用到的数据
- $customId = $info['customId'] ?? 0;
- $remark = $info['remark'] ?? '';
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- $customName = $custom->name ?? '';
- $customMobile = $custom->customMobile ?? '';
- if (empty($customMobile)) {
- $customShopId = $custom->shopId ?? 0;
- $customShop = ShopClass::getById($customShopId, true);
- if (!empty($customShop)) {
- $customMobile = $customShop->mobile ?? '';
- }
- }
- $fullCustom = $customName . ' ' . $customMobile;
- if ($this->mainId == 8164) {
- //花大苪不显示客户名称
- $fullCustom = '';
- }
- $seatSn = $custom->seatSn ?? '';
- $sendTimeWant = $info['sendTimeWant'] ?? '';
- $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
- $table = [];
- if (isset($info['product']) && !empty($info['product'])) {
- foreach ($info['product'] as $key => $val) {
- $currentName = $val['name'] ?? '';
- $num = $val['xhNum'] ?? 0;
- $table[] = [
- 'name' => $currentName,
- 'num' => $num,
- 'confirmNum' => '',
- 'remark' => '',
- 'wxNumber' => 'shish3508',
- ];
- }
- }
- $a4Print = [
- 'customName' => $fullCustom,
- 'seatSn' => $seatSn,
- 'shortSendTimeWant' => $shortSendTimeWant,
- 'table' => $table,
- 'remark' => $remark,
- ];
- $info['printData'] = $a4Print;
- //是否有云打印判断
- $hasCloudPrint = 0;
- $shopExt = $this->shopExt;
- if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
- $hasCloudPrint = 1;
- }
- $info['hasCloudPrint'] = $hasCloudPrint;
- $purchaseId = $info['purchaseId'] ?? 0;
- $cg = PurchaseClass::getById($purchaseId);
- $info['cgInfo'] = $cg;
- //店长信息
- $mainId = $cg['mainId'] ?? 0;
- $superInfo = ShopAdminClass::getManager($mainId);
- $info['customSuper'] = $superInfo;
- util::success($info);
- }
- //获取订单信息 ssh 20240102
- public function actionGetInfoByOrderSn()
- {
- $get = Yii::$app->request->get();
- $orderSn = $get['orderSn'] ?? '';
- $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
- if (empty($info)) {
- util::fail('没有找到订单');
- }
- if ($info->mainId != $this->mainId) {
- util::fail('不是你的订单哦');
- }
- util::success(['info' => $info]);
- }
- //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
- public function actionInfo()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = OrderService::getOrderInfo($id, true, true, true, false);
- if (empty($info)) {
- util::fail('没有找到订单');
- }
- //是否有云打印判断
- $hasCloudPrint = 0;
- $shopExt = $this->shopExt;
- if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
- $hasCloudPrint = 1;
- }
- $info['hasCloudPrint'] = $hasCloudPrint;
- $purchaseId = $info['purchaseId'] ?? 0;
- $cg = PurchaseClass::getById($purchaseId);
- $info['cgInfo'] = $cg;
- //店长信息
- $mainId = $cg['mainId'] ?? 0;
- $superInfo = ShopAdminClass::getManager($mainId);
- $info['customSuper'] = $superInfo;
- util::success($info);
- }
- //自取免发货流程处理 ssh 2021.1.22
- public function actionWithoutSend()
- {
- util::complete();
- }
- //本店送 ssh 2021.1.24
- public function actionSelfSend()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $info = OrderClass::getById($id, true);
- OrderClass::valid($info->attributes, $this->shopId);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderClass::selfSend($info);
- $transaction->commit();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("本店送操作报错:" . $exception->getMessage());
- util::fail('操作失败');
- }
- util::complete();
- }
- //运费计算 ssh 2021.1.24
- public function actionFreight()
- {
- //2021.3.28 接入达达
- $get = Yii::$app->request->get();
- $post = Yii::$app->request->post();
- if (empty($get)) {
- $get = $post;
- }
- $orderId = $get['id'] ?? 0; //订单ID
- $customId = $get['customId'] ?? 0;
- if (empty($orderId)) {
- //自定义运费
- //freight::getCost();
- if (empty($customId)) {
- util::fail("请选择客户");
- }
- $customInfo = CustomClass::getById($customId);
- if (empty($customInfo)) {
- util::fail('没有找到客户');
- }
- $shop = $this->shop;
- //花材信息
- $productJson = $get['product'] ?? '';
- // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
- if (empty($productJson)) {
- util::fail('请选择花材');
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- util::fail('请选择花材');
- }
- $productList = ProductClass::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);
- }
- //没有经纬度的客户运费直接返回空 ssh 20210612
- if (empty($customInfo['lat']) || empty($customInfo['long'])) {
- util::success(['sedCost' => '']);
- }
- $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
- util::success(['sedCost' => $cost]);
- }
- $province = $get['province'] ?? '';
- $city = $get['city'] ?? '';
- $address = $get['address'] ?? '';
- $floor = $get['floor'] ?? '';
- $customName = $get['customName'] ?? '';
- $customMobile = $get['customMobile'] ?? '';
- $fullAddress = $province . $city . $address . $floor;
- $sendTime = $get['sendTime'] ?? '';
- $lat = $get['lat'] ?? '';
- $lng = $get['long'] ?? '';
- if (empty($lat) || empty($lng) || empty($fullAddress)) {
- util::fail('请填写客户地址');
- }
- ini_set('date.timezone', 'Asia/Shanghai');
- if (!empty($sendTime)) {
- //配送时间不为空
- // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
- $sendTimeInt = strtotime($sendTime);
- $now = time();
- $diff = $sendTimeInt - $now;
- //因服务器写入时间,改为至少提前6分钟
- if ($diff <= 360) {
- util::fail('配送时间至少提前6分钟');
- }
- } else {
- //默认立即发送
- $sendTime = 0;
- }
- //更新订单表
- $info = OrderService::getOrderInfo($orderId);
- OrderClass::valid($info, $this->shopId);
- if ($sendTime) {
- $sendTime = date('Y-m-d H:i', strtotime($sendTime));
- } else {
- $sendTime = '0000-00-00 00:00:00';
- }
- $expressAddInfo = [
- 'customName' => $customName,
- 'customMobile' => $customMobile,
- 'province' => $province,
- 'city' => $city,
- 'address' => $address,
- 'floor' => $floor,
- 'lat' => $lat,
- 'long' => $lng,
- 'sendTime' => $sendTime,
- ];
- OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
- //计算运费
- $info['province'] = $province;
- $info['city'] = $city;
- $info['address'] = $address;
- $info['floor'] = $floor;
- $info['fullAddress'] = $fullAddress;
- $info['lat'] = $lat;
- $info['long'] = $lng;
- $info['sendTime'] = $expressAddInfo['sendTime'];
- $res = DadaExpressServices::queryDeliverFee($info);
- util::success(['sedCost' => $res['fee']]);
- }
- //发快递和第三方配送 ssh 2021.1.24
- public function actionThirdSend()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $info = OrderService::getById($id, true);
- OrderClass::valid($info->attributes, $this->shopId);
- if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
- util::fail('请填写客户地址');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $respond = OrderClass::thirdSend($info, $get);
- $transaction->commit();
- util::success($respond);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("发快递操作报错:" . $exception->getMessage());
- util::fail('操作失败' . $exception->getMessage());
- }
- }
- //确认送达 ssh 2021.1.24
- public function actionReach()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $info = OrderClass::getById($id, true);
- OrderClass::valid($info->attributes, $this->shopId);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- OrderService::reach($info);
- $transaction->commit();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("送达操作报错:" . $exception->getMessage());
- util::fail('操作失败');
- }
- util::complete();
- }
- //下单要用到的相关信息 ssh 2019.12.6
- public function actionOrderRelate()
- {
- $regionTree = RegionService::tree();
- $shop = $this->shop->attributes;
- $freight = ['first' => 5, 'add' => 2];
- $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
- $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
- util::success($out);
- }
- //客户欠款的订单 ssh 2021.2.4
- public function actionDebtList()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = CustomClass::getCustom($id);
- CustomClass::valid($info, $this->shopId);
- $where = ['customId' => $id, 'debt' => 1];
- $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']]];
- }
- $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
- $result = ['customInfo' => $info, 'list' => $list];
- util::success($result);
- }
- //更新打印次数
- public function actionAddPrintNum()
- {
- $id = Yii::$app->request->get('id', 0);
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $order->printNum += 1;
- $order->save();
- util::complete();
- }
- //打印订单 ssh 20210714
- public function actionCloudPrintOrder()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $showPrice = $get['showPrice'] ?? 1;
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
- util::fail('订单还没有付款');
- }
- if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
- util::fail('订单已取消');
- }
- $ext = $this->shopExt;
- if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
- util::success(['hasNoPrint' => 1]);
- }
- OrderClass::onlinePrint($order, $showPrice);
- $order->printNum += 1;
- $order->save();
- util::complete();
- }
- //订单确认完成 ssh 20210809
- public function actionConfirmFinish()
- {
- $payWay = Yii::$app->request->get('payWay', -1);
- $id = Yii::$app->request->get('id', 0);
- $clearType = Yii::$app->request->get('clearType', 0);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $order = OrderClass::getById($id, true);
- OrderClass::valid($order, $this->shopId);
- $purchaseId = $order->purchaseId ?? 0;
- $purchase = PurchaseClass::getById($purchaseId, true);
- if (empty($purchase)) {
- util::fail('没有采购信息');
- }
- if ($clearType == 1) {
- //欠款
- $payWay = dict::getDict('payWay', 'debtPay');
- } elseif ($clearType == 2) {
- //已收款
- if ($payWay == -1) {
- util::fail('请选择收款方式');
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能发起已收款');
- }
- } else {
- util::fail('请选择结算方式');
- }
- //不需要打印
- $order->needPrint = dict::getDict('needPrint', 'noNeed');
- $order->save();
- //支付
- PurchaseService::payAfter($purchase, $payWay);
- OrderService::payAfter($order, $payWay);
- //自己送
- $info = OrderClass::getById($id, true);
- OrderClass::selfSend($info);
- //确认送达,并且不需要微信通知
- Yii::$app->params['noNeedWxNotice'] = 1;
- $info = OrderClass::getById($id, true);
- OrderService::reach($info);
- $transaction->commit();
- util::complete('操作成功');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("确认完成订单报错:" . $exception->getMessage());
- util::fail('操作失败');
- }
- }
- //取消订单 ssh 20220110
- public function actionCancel()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能取消订单');
- }
- $id = Yii::$app->request->get('id');
- $order = OrderClass::getById($id, true);
- if ($order->orderType == 2) {
- util::fail('客户下单,不能主动取消');
- }
- OrderClass::valid($order, $this->shopId);
- OrderService::expire($order, true);
- util::complete('已取消');
- }
- //获取收款语音播报地址 ssh 20211231
- public function actionGetPayVoice()
- {
- $id = Yii::$app->request->get('id');
- $order = OrderClass::getById($id, true);
- $payWay = $order->payWay ?? 0;
- $money = floatval($order->actPrice);
- $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
- $msg = $payment . '收款' . $money . '元';
- $audio = baiduAip::transfer($msg, 4, 0);
- //上传到oss
- $file = time() . rand(10000, 999999) . '.mp3';
- $filePath = 'tmp/arrival/money/' . $file;
- oss::uploadTmpAudio($filePath, $audio);
- $url = Yii::$app->params['ghsImgHost'] . $filePath;
- util::success(['url' => $url]);
- }
- //修改备注
- public function actionModifyRemark()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $remark = $post['remark'] ?? '';
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $cgId = $order->purchaseId ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- if (empty($cg)) {
- util::fail('采购单没有找到');
- }
- $order->remark = $remark;
- $order->save();
- $cg->remark = $remark;
- $cg->save();
- util::complete('修改成功');
- }
- }
|