| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243 |
- <?php
- namespace ghs\controllers;
- 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\oss;
- use common\components\payUtil;
- use common\components\qrCodeUtil;
- use Yii;
- use common\components\util;
- use biz\shop\classes\ShopAdminClass;
- class OrderController extends BaseController
- {
- public $guestAccess = ['create-order', 'order-relate', 'fast-pay'];
- //支付宝扫码支付 shish 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']);
- }
- util::success(['returnStatus' => 'FAILURE']);
- }
- //微信和支付宝扫码支付 shish 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;
- $outTradeNo = $orderSn;
- $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();
- $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 {
- $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.NativePay.php');
- //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
- $wxPayType = 0;
- if (httpUtil::isMiniProgram()) {
- $wxPayType = 1;
- }
- $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
- $attach = "couponId=0&capitalType=" . $purchaseCapital . '&wxPayType=' . $wxPayType;
- $input = new \WxPayUnifiedOrder();
- $input->SetBody($subject);
- $input->SetOut_trade_no($orderSn);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetAttach($attach);
- $input->SetTime_start(date("YmdHis"));
- $input->SetTime_expire(date("YmdHis", time() + 600));
- $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
- $input->SetTrade_type("NATIVE");
- //native支付必传
- $input->SetProduct_id("hdCG_" . $cgId);
- //获取微信商户号等信息
- $sjExtend = WxOpenClass::getWxInfo();
- $notify = new \NativePay();
- $result = $notify->GetPayUrl($input, $sjExtend);
- $url = $result["code_url"] ?? '';
- if (empty($url)) {
- util::success(['returnStatus' => 'FAILURE'], '二维码生成失败');
- }
- $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 {
- $aliF2F = Yii::getAlias("@vendor/alipayF2F");
- require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
- require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
- $aliPId = '2017041906821571';
- $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2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eBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==';
- $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB';
- $config = array(
- //签名方式,默认为RSA2(RSA2048)
- 'sign_type' => "RSA2",
- //支付宝公钥
- 'alipay_public_key' => $aliPublicKey,
- //商户私钥
- 'merchant_private_key' => $aliKey,
- //编码格式
- 'charset' => "UTF-8",
- //支付宝网关
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
- //应用ID
- 'app_id' => $aliPId,
- //异步通知地址,只有扫码支付预下单可用
- 'notify_url' => Yii::$app->params['hdHost'] . "/notice/cg-ali-callback",
- //最大查询重试次数
- 'MaxQueryRetry' => "10",
- //查询间隔
- 'QueryDuration' => "3"
- );
- // 支付超时,线下扫码交易定义为5分钟
- $timeExpress = "5m";
- // 创建请求builder,设置请求参数
- $qrPayRequestBuilder = new \AlipayTradePayContentBuilder();
- $qrPayRequestBuilder->setOutTradeNo($outTradeNo);
- $qrPayRequestBuilder->setTotalAmount($totalAmount);
- $qrPayRequestBuilder->setTimeExpress($timeExpress);
- $qrPayRequestBuilder->setSubject($subject);
- $qrPayRequestBuilder->setBody($body);
- // 调用barPay方法获取当面付应答
- $qrPay = new \AlipayTradeService($config);
- $qrPayResult = $qrPay->qrPay($qrPayRequestBuilder);
- if ($qrPayResult->getTradeStatus() != 'SUCCESS') {
- util::success(['returnStatus' => 'FAILURE'], '二维码生成失败..');
- }
- $respond = $qrPayResult->getResponse();
- $url = $respond->qr_code ?? '';
- if (empty($url)) {
- util::success(['returnStatus' => 'FAILURE'], '二维码生成失败');
- }
- $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'], '不支持的收款方式');
- }
- //微信和支付宝付款码支付复查 shish 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::complete('没有找到订单');
- }
- if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
- if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
- util::complete('订单已付款');
- }
- 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('没有找到采购单');
- }
- $payWay = $cg->payWay ?? dict::getDict('payWay', 'wxPay');
- $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
- if ($payWay == dict::getDict('payWay', 'wxPay')) {
- //微信付款
- $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.MicroPay.php');
- //获取微信商户号等信息
- $sjExtend = WxOpenClass::getWxInfo();
- $microPay = new \MicroPay();
- $payReturn = $microPay->query($orderSn, $sjExtend);
- if ($payReturn["return_code"] == "SUCCESS" && $payReturn["result_code"] == "SUCCESS") {
- if ($payReturn["trade_state"] == "SUCCESS") {
- //支付成功
- $transactionId = $payReturn['transaction_id'] ?? '';
- $openId = $payReturn['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($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
- util::success(['returnStatus' => 'SUCCESS']);
- } else if ($payReturn["trade_state"] == "USERPAYING") {
- //用户支付中
- util::complete('正在付款,请稍候..');
- }
- }
- if ($payReturn["err_code"] == "ORDERNOTEXIST") {
- //交易订单号不存在
- util::complete('订单没有付款');
- } else {
- util::complete('系统错误,请稍候再试');
- }
- } elseif ($payWay == dict::getDict('payWay', 'alipay')) {
- //支付宝付款
- $aliF2F = Yii::getAlias("@vendor/alipayF2F");
- require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
- require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
- $aliPId = '2017041906821571';
- $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+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FAMqgfFWoL6zoaYAmJBnxO4oZPTYI+ilnQcts5VLFaChx0GCvS2BZgy2W0QKBgQDjP2VtRq4aVSLUq2z1KIDI7GJBbOM5KSW1OEj4sfEdViozPh3Ar/FQWiij1oCZF+iJdKkonHoDbDd+Q0ykcpQ+5Gv07iiT8wJYFR/0j8g2kfql7bVQhGSBeBMS5sawKR3CvkfW73WX+CNnf0PklTY0kTyt6WRXDnKSeyxFVwSZ7g==';
- $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsz3m9juAR1xew4DY6c34gvbwNg8pZ92f932tseKs+4+pF0e+jTDiUo/xHImNDi1KXt1B+s3LxY9L/sxEksbavwmhgbz/igN1cAEwS2YM+Gnf0csDrxAPJhoKL5FTwxPEQ/8VSgroU+6GlF3LAx4VHa1qfn5MqRPfLroJcyPDyGfNe9vna2FnO4E/PH+hVbvPUAwX3XrUvJIm4OgY0JE3HYFlu+O7F4Ln6+Sl+Zv/ZE2nZAvNiyAwW5iVKhKXLieExqwd0NdrP28baBqkkIY+tmV7butGjB52iK1UbU0+1uiaPL4xBxRy6d0LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB';
- $config = array(
- //签名方式,默认为RSA2(RSA2048)
- 'sign_type' => "RSA2",
- //支付宝公钥
- 'alipay_public_key' => $aliPublicKey,
- //商户私钥
- 'merchant_private_key' => $aliKey,
- //编码格式
- 'charset' => "UTF-8",
- //支付宝网关
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
- //应用ID
- 'app_id' => $aliPId,
- //异步通知地址,只有扫码支付预下单可用
- 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
- //最大查询重试次数
- 'MaxQueryRetry' => "10",
- //查询间隔
- 'QueryDuration' => "3"
- );
- //构造查询业务请求参数对象
- $queryContentBuilder = new \AlipayTradeQueryContentBuilder();
- $queryContentBuilder->setOutTradeNo($orderSn);
- //初始化类对象,调用queryTradeResult方法获取查询应答
- $queryResponse = new \AlipayTradeService($config);
- $queryResult = $queryResponse->queryTradeResult($queryContentBuilder);
- if ($queryResult->getTradeStatus() == 'SUCCESS') {
- $respond = $queryResult->getResponse();
- $openId = '';
- $aliUserId = $respond->buyer_user_id ?? '';
- $transactionId = $respond->trade_no ?? '';
- $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($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
- util::success(['returnStatus' => 'SUCCESS']);
- }
- } else {
- util::fail('还没有付款哦');
- }
- }
- //微信和支付宝付款码支付 shish 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('支付失败');
- }
- $wxPrefix = ['10', '11', '12', '13', '14', '15'];
- $isWx = false;
- foreach ($wxPrefix as $wxId) {
- if (strpos($authCode, $wxId) === 0) {
- $isWx = true;
- }
- }
- $deadline = $cg->deadline;
- $current = date("Y-m-d H:i:s");
- if ((strtotime($deadline) + 20) < strtotime($current)) {
- util::fail('订单已经失效');
- }
- $totalFee = $cg->actPrice ?? 0;
- $outTradeNo = $orderSn;
- $subject = '购买商品';
- $totalAmount = $totalFee;
- $body = "门店";
- $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
- if ($isWx) {
- $wxPayWay = dict::getDict('payWay', 'wxPay');
- $order->payWay = $wxPayWay;
- $order->save();
- $cg->payWay = $wxPayWay;
- $cg->save();
- $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
- require_once($wx . '/lib/WxPay.Api.php');
- require_once($wx . '/example/WxPay.MicroPay.php');
- $input = new \WxPayMicroPay();
- $input->SetAuth_code($authCode);
- $input->SetBody($subject);
- $input->SetTotal_fee($totalFee * 100);
- $input->SetOut_trade_no($orderSn);
- //获取微信商户号等信息
- $sjExtend = WxOpenClass::getWxInfo();
- $microPay = new \MicroPay();
- $res = $microPay->pay($input, $sjExtend);
- if (isset($res["return_code"]) && $res["return_code"] == "SUCCESS" && isset($res["result_code"]) && $res["result_code"] == 'SUCCESS') {
- $transactionId = $res['transaction_id'] ?? '';
- $openId = $res['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($wxPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
- util::success(['returnStatus' => 'SUCCESS']);
- } else {
- Yii::info(json_encode($res));
- $errCode = $res['err_code'] ?? '';
- $msg = '';
- if ($errCode == 'NOTENOUGH') {
- $msg = '余额不足';
- }
- if ($errCode == 'USERPAYING') {
- $msg = '等待客户输入支付密码';
- }
- util::success(['returnStatus' => 'FAILURE'], $msg);
- }
- } else {
- $aliPayWay = dict::getDict('payWay', 'alipay');
- $order->payWay = $aliPayWay;
- $order->save();
- $cg->payWay = $aliPayWay;
- $cg->save();
- $aliF2F = Yii::getAlias("@vendor/alipayF2F");
- require_once($aliF2F . '/f2fpay/model/builder/AlipayTradePayContentBuilder.php');
- require_once($aliF2F . '/f2fpay/service/AlipayTradeService.php');
- $aliPId = '2017041906821571';
- $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFXBrmdKjAcRJ8Q7ZHUmzIqAV+IMV+RD4J5mZHeJgdAECgYEA8J+Hp1M6eYbT4CPLXa//yRP6Xo+qSzrKHaRB1LRAjYhvKpx/TQetYpNCJ5bWpa+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA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LZmYlvdVHp0JRUuwxBLChGgOCo/76DQIDAQAB';
- $config = array(
- //签名方式,默认为RSA2(RSA2048)
- 'sign_type' => "RSA2",
- //支付宝公钥
- 'alipay_public_key' => $aliPublicKey,
- //商户私钥
- 'merchant_private_key' => $aliKey,
- //编码格式
- 'charset' => "UTF-8",
- //支付宝网关
- 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
- //应用ID
- 'app_id' => $aliPId,
- //异步通知地址,只有扫码支付预下单可用
- 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
- //最大查询重试次数
- 'MaxQueryRetry' => "10",
- //查询间隔
- 'QueryDuration' => "3"
- );
- // 支付超时,线下扫码交易定义为5分钟
- $timeExpress = "5m";
- // 创建请求builder,设置请求参数
- $barPayRequestBuilder = new \AlipayTradePayContentBuilder();
- $barPayRequestBuilder->setOutTradeNo($outTradeNo);
- $barPayRequestBuilder->setTotalAmount($totalAmount);
- $barPayRequestBuilder->setAuthCode($authCode);
- $barPayRequestBuilder->setTimeExpress($timeExpress);
- $barPayRequestBuilder->setSubject($subject);
- $barPayRequestBuilder->setBody($body);
- // 调用barPay方法获取当面付应答
- $barPay = new \AlipayTradeService($config);
- $barPayResult = $barPay->barPay($barPayRequestBuilder);
- if ($barPayResult->getTradeStatus() == 'SUCCESS') {
- $respond = $barPayResult->getResponse();
- $openId = '';
- $aliUserId = $respond->buyer_user_id ?? '';
- $transactionId = $respond->trade_no ?? '';
- $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($aliPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
- util::success(['returnStatus' => 'SUCCESS']);
- }
- util::success(['returnStatus' => 'FAILURE']);
- }
- }
- //订单列表 ssh 2021.1.20
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $status = $get['status'] ?? 0;
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $where['sjId'] = $this->sjId;
- if (isset($get['shopId'])) {
- $shopId = $get['shopId'] ?? 0;
- if (!empty($shopId)) {
- $where['shopId'] = $this->shopId;
- }
- } else {
- $where['shopId'] = $this->shopId;
- }
- $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 {
- }
- }
- $respond = OrderClass::getOrderList($where);
- $respond['shop'] = $this->shop;
- $respond['shopExt'] = $this->shopExt;
- 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);
- $post['ghsId'] = $custom['ghsId'] ?? 0;
- $post['customMobile'] = $custom['mobile'] ?? '';
- $customName = $custom['name'] ?? '';
- $post['customName'] = $customName;
- $post['customNamePy'] = $custom['py'] ?? '';
- $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
- $post['shopAdminId'] = $this->shopAdminId;
- $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->attributes;
- $post['shopAdminName'] = $shopAdmin['name'] ?? '';
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $shopId;
- $post['fromType'] = 1;
- $post['expressId'] = $post['expressId'] ?? 0;
- $post['sendCost'] = $post['sendCost'] ?? '0.00';
- $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
- $post['debt'] = OrderClass::DEBT_NO;
- if ($hasPay == dict::getDict('hasPay', 'debt')) {
- $post['debt'] = OrderClass::DEBT_YES;
- }
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- if ($hasPay == dict::getDict('hasPay', 'payed')) {
- util::fail('没有权限');
- }
- }
- $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;
- //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
- $post['deadline'] = date("Y-m-d H:i:s", strtotime('+360 day'));
- $return = OrderService::createFinishOrder($post, $custom, $hasPay);
- $transaction->commit();
- util::success($return);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("下单失败原因:" . $e->getMessage());
- util::fail('下单失败');
- }
- }
- //修改订单 ssh 20210810
- public function actionUpdateOrder()
- {
- $post = Yii::$app->request->post();
- //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('下单失败');
- }
- }
- //延期支付 ssh 2021.1.19
- public function actionDebt()
- {
- $id = Yii::$app->request->get('id');
- $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('没有找到采购单');
- }
- PurchaseService::payAfter($cg, $payWay);
- OrderService::payAfter($order, $payWay);
- 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);
- //是否有云打印判断
- $hasCloudPrint = 0;
- $shopExt = $this->shopExt;
- if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
- $hasCloudPrint = 1;
- }
- $info['hasCloudPrint'] = $hasCloudPrint;
- //店长信息
- $customShopId = $info['customShopId'] ?? 0;
- $superInfo = ShopAdminClass::getManager($customShopId);
- $info['customSuper'] = $superInfo;
- $purchaseId = $info['purchaseId'] ?? 0;
- $cg = PurchaseClass::getById($purchaseId);
- $info['cgInfo'] = $cg;
- util::success($info);
- }
- //自取免发货流程处理 ssh 2021.1.22
- public function actionWithoutSend()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $info = OrderService::getById($id, true);
- OrderClass::valid($info, $this->shopId);
- $purchaseId = $info->purchaseId;
- $purchase = PurchaseClass::getById($purchaseId, true);
- OrderService::withoutSend($info, $purchase);
- 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);
- }
- //没有经纬度的客户运费直接返回空 shish 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', 'realPrice', 'actPrice', 'addTime']);
- $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();
- }
- //打印订单 shish 20210714
- public function actionCloudPrintOrder()
- {
- $id = Yii::$app->request->get('id', 0);
- $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);
- $order->printNum += 1;
- $order->save();
- util::complete();
- }
- //订单确认完成 shish 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('操作失败');
- }
- }
- //取消订单 shish 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('已取消');
- }
- //获取收款语音播报地址 shish 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]);
- }
- }
|