params['ptStyle'] = dict::getDict('ptStyle', 'hd');
$postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
if (empty($postStr)) {
util::end();
}
$headers = Yii::$app->getRequest()->getHeaders();
$Authorization = $headers->get('Authorization');
$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',
'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
'lklCertificatePath' => $lklCertificatePath,
];
$laResource = new Lakala($params);
$return = $laResource->signatureVerification($Authorization, $postStr);
$postData = json_decode($postStr, true);
$orderSn = $postData['out_order_no'] ?? '';
$merchant_no = $postData['merchant_no'] ?? '';
$orderTradeInfo = $postData['order_trade_info'] ?? [];
$payMode = $orderTradeInfo['pay_mode'] ?? null;
if (empty($payMode)) {
noticeUtil::push('收银台支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
util::end();
}
$trade_amount = $orderTradeInfo['trade_amount'] ?? 0;
$totalFee = $trade_amount / 100;
if ($totalFee <= 0) {
noticeUtil::push('收银台支付回调验证失败了,金额错误,请注意,orderSn:' . $orderSn, '15280215347');
util::end();
}
$transactionId = $orderTradeInfo['trade_no'] ?? 0;
if ($return == false) {
noticeUtil::push('收银台支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
util::end();
}
$orderStatus = $postData['order_status'];
$tradeType = $orderTradeInfo['trade_type'] ?? '';
if ($tradeType != 'PAY') {
noticeUtil::push('收银台支付回调验证失败了,不是消费的回调,orderSn:' . $orderSn, '15280215347');
util::end();
}
//接收流水类型、代金劵
$remarkString = $orderTradeInfo['trade_remark'] ?? '';
$remarkData = json_decode($remarkString, true);
//流水类型
$capitalType = $remarkData['capitalType'] ?? null;
if (!isset($capitalType)) {
noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
util::end();
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
if ($orderStatus == 2) {
$payWayType = null;
if ($payMode == 'ALIPAY') {
$payWayType = dict::getDict('payWay', 'alipay');
}
if ($payMode == 'WECHAT') {
$payWayType = dict::getDict('payWay', 'wxPay');
}
if (isset($payWayType) == false) {
noticeUtil::push('收银台支付回调验证失败了,没有找到支付方式,orderSn:' . $orderSn, '15280215347');
util::end();
}
$attach = 'merchant_no=' . $merchant_no;
payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
$transaction->commit();
}
//请不要修改
echo "SUCCESS";
//解决重复通知
$cacheKey = 'pay_success_notice_' . $orderSn;
$has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
if (!empty($has)) {
Yii::$app->end();
}
Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
//客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
$customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
$customId = $customRecharge->customId ?? 0;
$ghsId = $customRecharge->ghsId ?? 0;
$ghs = GhsClass::getLockById($ghsId);
$ghsShopId = $ghs->shopId ?? 0;
$custom = CustomClass::getLockById($customId);
$shop = ShopClass::getById($ghsShopId, true);
// 销账已在 CustomRechargeClass::thirdPay 内按本次来款 FIFO 完成,勿再 useBalanceClear
//充值销账通知
WxMessageClass::customRechargeClearInform($shop, $customRecharge);
}
//零售线上结账通知
if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
$clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
$customId = $clearInfo->customId ?? 0;
$ghsShopId = $clearInfo->ghsShopId ?? 0;
$ghsShop = ShopClass::getById($ghsShopId, true);
$custom = CustomClass::getById($customId, true);
if (!empty($custom) && !empty($ghsShop)) {
WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
}
}
//零售采购通知
if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
$cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
$saleId = $cg->saleId ?? 0;
$order = OrderClass::getById($saleId, true);
//付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
GhsDeliveryOrderClass::payAfter($order);
//不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
if (!empty($cg) && !empty($order)) {
if (isset($cg->book) && $cg->book == 0) {
$ghsShopId = $order->shopId ?? 0;
$ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
if ($ext->orderFlow == 0) {
PurchaseClass::confirmTake($cg);
}
}
}
//更新最后下单时间
$customId = $order->customId ?? 0;
$custom = CustomClass::getById($customId, true);
$date = date("Y-m-d H:i:s");
if (!empty($custom)) {
$custom->recentExpend = $date;
$custom->save();
}
$ghsId = $order->ghsId ?? 0;
$ghs = GhsClass::getById($ghsId, true);
if (!empty($ghs)) {
$ghs->recentExpend = $date;
$ghs->save();
}
if (isset($cg->localOrder) && $cg->localOrder == 1) {
if ($cg->transType != 5 && $cg->transType != 4) {
//昆明发货,客户算了一次打包费和运费,第二次就不再算了
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
$key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
}
} else {
//标记当配送方式已成功下过单,后续不再要求门槛或加收费用
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
if (isset($cg->sendType)) {
$key = 'ghs_custom_today_has_get_pack_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
$sendKey = 'ghs_custom_today_has_get_send_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$sendKey, 86400, '1']);
}
}
if (!empty($cg) && $cg->payStatus == 1) {
//微信通知
if (!empty($order)) {
//订单生成时唤起在线打印
if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
//有几个地方要同步去修改
if (getenv('YII_ENV') == 'production') {
//源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
$mallOrderNoPrint = [10536, 44282, 26374];
} else {
$mallOrderNoPrint = [];
}
if (in_array($order->mainId, $mallOrderNoPrint)) {
} else {
OrderClass::onlinePrint($order);
$order->printNum += 1;
$order->save();
if (getenv('YII_ENV') == 'production') {
//福州我要花、花路鲜花批发、小齐鲜花、花镜打二次小票,有多处要修改搜索关键词tow_print
$needTwoPrint = [7538, 36707, 76796, 94589];
} else {
$needTwoPrint = [644];
}
if (in_array($order->mainId, $needTwoPrint)) {
if ($order->mainId == 7538) {
OrderClass::onlinePrint($order, 0);
} else {
OrderClass::onlinePrint($order);
}
$order->printNum += 1;
$order->save();
}
}
}
$cgShopId = $cg->shopId ?? 0;
$cgShop = ShopClass::getById($cgShopId, true);
if (!empty($cgShop)) {
//NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
}
//如果是门店用手机开单,让客户扫码付款的,则也要语音提示
if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
ShopExtClass::ghsGatheringReport($order);
}
$shopId = $order->shopId ?? 0;
$shop = ShopClass::getById($shopId, true);
if (!empty($shop)) {
GhsNotifyClass::newOrderNotify($saleId);
}
}
}
}
exit();
} catch (\Exception $e) {
$transaction->rollBack();
Yii::error("失败原因:" . $e->getMessage());
}
}
//拉卡拉回调通知 ssh 20231009
public function actionPayCallback()
{
$postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
if (empty($postStr)) {
util::end();
}
$headers = Yii::$app->getRequest()->getHeaders();
$Authorization = $headers->get('Authorization');
$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',
'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
'lklCertificatePath' => $lklCertificatePath,
];
$laResource = new Lakala($params);
$return = $laResource->signatureVerification($Authorization, $postStr);
$postData = json_decode($postStr, true);
$orderSn = $postData['out_trade_no'] ?? '';
$total_amount = $postData['total_amount'] ?? 0;
$account_type = $postData['account_type'] ?? '';
$merchant_no = $postData['merchant_no'] ?? '';
if (empty($account_type)) {
noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
util::end();
}
$totalFee = $total_amount / 100;
$transactionId = $postData['trade_no'] ?? 0;
if ($return == false) {
noticeUtil::push('支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
util::end();
}
//接收流水类型、代金劵
$remarkString = $postData['remark'] ?? '';
$remarkData = json_decode($remarkString, true);
//流水类型
$capitalType = isset($remarkData['capitalType']) ? $remarkData['capitalType'] : null;
if (isset($capitalType) == false) {
noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
util::end();
}
$currentPayWay = null;
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
if ($account_type == 'WECHAT') {
$currentPayWay = dict::getDict('payWay', 'wxPay');
} elseif ($account_type == 'ALIPAY') {
$currentPayWay = dict::getDict('payWay', 'alipay');
} else {
noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
util::end();
}
//支付成功后续流程
$attach = 'merchant_no=' . $merchant_no;
payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
$transaction->commit();
echo "SUCCESS";
//解决重复通知
$cacheKey = 'pay_success_notice_' . $orderSn;
$has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
if (!empty($has)) {
Yii::$app->end();
}
Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
//客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
$customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
$customId = $customRecharge->customId ?? 0;
$ghsId = $customRecharge->ghsId ?? 0;
$ghs = GhsClass::getLockById($ghsId);
$ghsShopId = $ghs->shopId ?? 0;
$custom = CustomClass::getLockById($customId);
$shop = ShopClass::getById($ghsShopId, true);
// 销账已在 CustomRechargeClass::thirdPay 内按本次来款 FIFO 完成,勿再 useBalanceClear
//充值销账通知
WxMessageClass::customRechargeClearInform($shop, $customRecharge);
}
//零售线上结账通知
if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
$clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
$customId = $clearInfo->customId ?? 0;
$ghsShopId = $clearInfo->ghsShopId ?? 0;
$ghsShop = ShopClass::getById($ghsShopId, true);
$custom = CustomClass::getById($customId, true);
if (!empty($custom) && !empty($ghsShop)) {
WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
}
}
//零售采购成功后续流程
if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
$cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
$saleId = $cg->saleId ?? 0;
$order = OrderClass::getById($saleId, true);
//付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
GhsDeliveryOrderClass::payAfter($order);
//不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔、镜中花卉,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
if (!empty($cg) && !empty($order)) {
if (isset($cg->book) && $cg->book == 0) {
$ghsShopId = $order->shopId ?? 0;
$ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
if ($ext->orderFlow == 0) {
PurchaseClass::confirmTake($cg);
}
}
}
//更新最后下单时间
$customId = $order->customId ?? 0;
$custom = CustomClass::getById($customId, true);
$date = date("Y-m-d H:i:s");
if (!empty($custom)) {
$custom->recentExpend = $date;
$custom->save();
}
$ghsId = $order->ghsId ?? 0;
$ghs = GhsClass::getById($ghsId, true);
if (!empty($ghs)) {
$ghs->recentExpend = $date;
$ghs->save();
}
if (isset($cg->localOrder) && $cg->localOrder == 1) {
if ($cg->transType != 5 && $cg->transType != 4) {
//昆明发货,客户算了一次打包费和运费,第二次就不再算了
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
$key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
}
} else {
//标记当配送方式已成功下过单,后续不再要求门槛或加收费用
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
if (isset($cg->sendType)) {
$key = 'ghs_custom_today_has_get_pack_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
$sendKey = 'ghs_custom_today_has_get_send_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$sendKey, 86400, '1']);
}
}
if (!empty($cg) && $cg->payStatus == 1) {
//微信通知
if (!empty($order)) {
//订单生成时唤起在线打印
if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
//有几个地方要同步去修改
if (getenv('YII_ENV') == 'production') {
//源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
$mallOrderNoPrint = [10536, 44282, 26374];
} else {
$mallOrderNoPrint = [];
}
if (in_array($order->mainId, $mallOrderNoPrint)) {
} else {
$shopId = $order->shopId ?? 0;
$ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
OrderClass::onlinePrint($order);
if (isset($ext->printSn) && !empty($ext->printSn)) {
$order->printNum += 1;
$order->save();
}
if (getenv('YII_ENV') == 'production') {
//福州我要花、花路鲜花批发、花镜打二次小票,有多处要修改搜索关键词tow_print
$needTwoPrint = [7538, 36707, 76796, 94589];
} else {
$needTwoPrint = [];
}
if (in_array($order->mainId, $needTwoPrint)) {
if ($order->mainId == 7538) {
OrderClass::onlinePrint($order, 0);
} else {
OrderClass::onlinePrint($order);
}
if (isset($ext->printSn) && !empty($ext->printSn)) {
$order->printNum += 1;
$order->save();
}
}
}
}
$cgShopId = $cg->shopId ?? 0;
$cgShop = ShopClass::getById($cgShopId, true);
if (!empty($cgShop)) {
//NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
}
//如果是门店用手机开单,让客户扫码付款的,则也要语音提示
if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
ShopExtClass::ghsGatheringReport($order);
}
$shopId = $order->shopId ?? 0;
$shop = ShopClass::getById($shopId, true);
if (!empty($shop)) {
//花店采购供货商端微信收到通知
//WxMessageClass::ghsHasNewOrderInform($shop, $order);
// $noticeText = json_encode(['orderId' => $saleId]);
// $noticeKey = "hdCgNoticeGhs";
// Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
GhsNotifyClass::newOrderNotify($saleId);
//向供货商APP发通知
// $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
// $push = new push('ghs', push::MSG_TYPE_ORDER);
// $push->ghsOrderMessage($shop, $cgShop, $order);
}
//花店采购供货商端APP收到通知
//NoticeClass::ghsNewOrderNotice($order);
}
}
}
//散客下单买花,回调通知后,播报声音提示,这个方法本来不能写在这边要写在app-mall里的
if ($capitalType == dict::getDict('capitalType', 'xhOrder', 'id')) {
$cacheKey = 'hd_shop_order_pay_' . $orderSn;
$has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
if (empty($has)) {
Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
$newOrder = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
if ($newOrder->onlinePay == 2) {
//语音播报
ShopExtClass::hdGatheringReport($newOrder);
}
}
}
exit();
} catch (\Exception $e) {
$transaction->rollBack();
$msg = $e->getMessage();
noticeUtil::push(" PayCallback 报错了 " . $currentPayWay . " capitalType:" . $capitalType . " orderSn:" . $orderSn . " totalFee:" . $totalFee . " 第三方id:" . $transactionId . " 原因:" . $msg, '15280215347');
Yii::error("失败原因:" . $msg);
}
}
//微信支付异步回调
public function actionWxCallback()
{
$postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
if (empty($postStr)) {
util::end();
}
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($postObj->return_code != 'SUCCESS') {
Yii::warning('return_code error:' . $postObj->return_code);
util::end();
}
$orderSn = $postObj->out_trade_no;
$total_fee = $postObj->total_fee;
$totalFee = $total_fee / 100;
$attach = $postObj->attach;
$transactionId = $postObj->transaction_id ?? '';
//接收流水类型、代金劵
parse_str($attach);
//流水类型
$capitalType = isset($capitalType) ? $capitalType : null;
if (isset($capitalType) == false) {
Yii::warning('capitalType empty,orderSn:' . $orderSn);
util::end();
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
$wxPay = dict::getDict('payWay', 'wxPay');
//支付成功后续流程
payUtil::thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
$transaction->commit();
echo '';
//解决重复通知
$cacheKey = 'pay_success_notice_' . $orderSn;
$has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
if (!empty($has)) {
Yii::$app->end();
}
Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
//零售采购结账通知
if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
$cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
if (isset($cg->localOrder) && $cg->localOrder == 1) {
if ($cg->transType != 5 && $cg->transType != 4) {
//昆明发货,客户算了一次打包费和运费,第二次就不再算了
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
$key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
}
} else {
//标记当配送方式已成功下过单,后续不再要求门槛或加收费用
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
if (isset($cg->sendType)) {
$key = 'ghs_custom_today_has_get_pack_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
$sendKey = 'ghs_custom_today_has_get_send_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$sendKey, 86400, '1']);
}
}
if (!empty($cg) && $cg->payStatus == 1) {
//微信通知
$saleId = $cg->saleId ?? 0;
$order = OrderClass::getById($saleId, true);
if (!empty($order)) {
//付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
GhsDeliveryOrderClass::payAfter($order);
//订单生成时唤起在线打印
if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
//有几个地方要同步去修改
if (getenv('YII_ENV') == 'production') {
//源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
$mallOrderNoPrint = [10536, 44282, 26374];
} else {
$mallOrderNoPrint = [];
}
if (in_array($order->mainId, $mallOrderNoPrint)) {
} else {
OrderClass::onlinePrint($order);
$order->printNum += 1;
$order->save();
}
}
$cgShopId = $cg->shopId ?? 0;
$cgShop = ShopClass::getById($cgShopId, true);
if (!empty($cgShop)) {
//NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
}
//如果是门店用手机开单,让客户扫码付款的,则也要语音提示
if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
ShopExtClass::ghsGatheringReport($order);
}
$shopId = $order->shopId ?? 0;
$shop = ShopClass::getById($shopId, true);
if (!empty($shop)) {
//花店采购供货商端微信收到通知
//WxMessageClass::ghsHasNewOrderInform($shop, $order);
// $noticeText = json_encode(['orderId' => $saleId]);
// $noticeKey = "hdCgNoticeGhs";
// Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
GhsNotifyClass::newOrderNotify($saleId);
//向供货商端APP发通知
// $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
// $push = new push('ghs', push::MSG_TYPE_ORDER);
// $push->ghsOrderMessage($shop, $cgShop, $order);
}
//花店采购供货商端APP收到通知
//NoticeClass::ghsNewOrderNotice($order);
}
}
}
exit();
} catch (\Exception $e) {
$transaction->rollBack();
Yii::error("失败原因:" . $e->getMessage());
}
}
//微信退款结果通知
public function actionWxRefundCallback()
{
$postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
if (empty($postStr)) {
util::end();
}
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($postObj->return_code != 'SUCCESS') {
$msg = $postObj->return_msg ?? '';
$text = '微信退款结果通知,报错了,报错内容:' . $msg;
Yii::warning($text);
noticeUtil::push($text, '15280215347');
util::end();
}
//解密req_info
$wx = WxOpenClass::getWxInfo();
$req_info = $postObj->req_info ?? '';
$key = $wx['wxPayKey'] ?? '';
$xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
$req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$refund_status = $req_info_obj->refund_status ?? '';
$orderSn = $req_info_obj->out_trade_no ?? '';
$out_refund_no = $req_info_obj->out_refund_no ?? '';
//订单总金额
$total_fee = $req_info_obj->total_fee ?? 0.00;
//申请退款金额
//$refund_fee = $req_info_obj->refund_fee ?? 0.00;
//退款金额
$settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
$new_total_fee = bcdiv($total_fee, 100, 2);
$new_total_fee = floatval($new_total_fee);
$new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
$new_settlement_refund_fee = floatval($new_settlement_refund_fee);
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
$text = '';
try {
if ($refund_status == 'SUCCESS') {
$cgRefund = CgRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
if (!empty($cgRefund)) {
$cgRefund->status = CgRefundClass::STATUS_COMPLETE;
$cgRefund->save();
$saleRefundId = $cgRefund->saleRefundId ?? 0;
$saleRefund = RefundOrderClass::getById($saleRefundId, true);
if (!empty($saleRefund)) {
$saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
$saleRefund->save();
}
}
//$text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
} elseif ($refund_status == 'REFUNDCLOSE') {
$text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
} else {
$text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
}
$transaction->commit();
if (!empty($text)) {
noticeUtil::push($text, '15280215347');
}
echo '';
exit();
} catch (\Exception $e) {
$transaction->rollBack();
Yii::error("失败原因:" . $e->getMessage());
}
}
//采购后支付宝异步通知
public function actionCgAliCallback()
{
header("Content-type: text/html; charset=utf-8");
$aliWap = Yii::getAlias("@vendor/alipayWap");
//商户订单号
$orderSn = $_POST['out_trade_no'];
// $aliPId = '2017041906821571';
// $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/Ha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EFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
$config = [
//应用ID,您的APP_ID
'app_id' => $aliPId,
//商户私钥,您的原始格式RSA私钥
'merchant_private_key' => $aliKey,
//异步通知地址
'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
//同步跳转
'return_url' => "",
//编码格式
'charset' => "UTF-8",
//签名方式
'sign_type' => "RSA2",
//支付宝网关
'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
'alipay_public_key' => $aliPublicKey,
];
require_once($aliWap . '/wappay/service/AlipayTradeService.php');
require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
$arr = $_POST;
$aliService = new \AlipayTradeService($config);
$aliService->writeLog(var_export($_POST, true));
$result = $aliService->check($arr);
Yii::info('check:' . $result);
if ($result == false) {
//请不要修改
echo "fail";
util::end();
}
//验证成功后续
$tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
$tradeStatus = $_POST['trade_status'] ?? '';//交易状态
$totalFee = $_POST['total_amount'] ?? '';
$appId = $_POST['app_id'] ?? '';
$attach = $_POST['passback_params'] ?? '';
$attach = urldecode($attach);
//接收流水类型、代金劵
parse_str($attach);
$capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
$RequestBuilder = new \AlipayTradeQueryContentBuilder();
$RequestBuilder->setTradeNo($tradeNo);
//$queryResult = $aliService->Query($RequestBuilder);
//$aliId = $queryResult->buyer_user_id;
//买家的支付宝帐号,不完整,带*号
//$aliAccount = $queryResult->buyer_logon_id;
if ($config['app_id'] != $appId) {
Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
util::end();
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
$aliPay = dict::getDict('payWay', 'alipay');
//支付成功后续流程
payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
$transaction->commit();
//请不要修改
echo "success";
//解决重复通知
$cacheKey = 'pay_success_notice_' . $orderSn;
$has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
if (!empty($has)) {
Yii::$app->end();
}
Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
//零售采购通知
if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
$cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
if (!empty($cg) && $cg->payStatus == 1) {
if (isset($cg->localOrder) && $cg->localOrder == 1) {
if ($cg->transType != 5 && $cg->transType != 4) {
//昆明发货,客户算了一次打包费和运费,第二次就不再算了
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
$key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
}
} else {
//标记当配送方式已成功下过单,后续不再要求门槛或加收费用
$customId = $cg->customId ?? 0;
$current = date("Y_m_d");
if (isset($cg->sendType)) {
$key = 'ghs_custom_today_has_get_pack_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
$sendKey = 'ghs_custom_today_has_get_send_cost_' . $cg->sendType . '_' . $current . '_' . $customId;
Yii::$app->redis->executeCommand('SETEX', [$sendKey, 86400, '1']);
}
}
//微信通知
$saleId = $cg->saleId ?? 0;
$order = OrderClass::getById($saleId, true);
if (!empty($order)) {
//付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
GhsDeliveryOrderClass::payAfter($order);
//订单生成时唤起在线打印
if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
//有几个地方要同步去修改
if (getenv('YII_ENV') == 'production') {
//源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
$mallOrderNoPrint = [10536, 44282, 26374];
} else {
$mallOrderNoPrint = [];
}
if (in_array($order->mainId, $mallOrderNoPrint)) {
} else {
OrderClass::onlinePrint($order);
$order->printNum += 1;
$order->save();
}
}
//如果是门店用手机开单,让客户扫码付款的,则也要语音提示
if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
ShopExtClass::ghsGatheringReport($order);
}
$cgShopId = $cg->shopId ?? 0;
$cgShop = ShopClass::getById($cgShopId, true);
if (!empty($cgShop)) {
NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
}
$shopId = $order->shopId ?? 0;
$shop = ShopClass::getById($shopId, true);
if (!empty($shop)) {
//花店采购供货商端微信收到通知
//WxMessageClass::ghsHasNewOrderInform($shop, $order);
$noticeText = json_encode(['orderId' => $saleId]);
$noticeKey = "hdCgNoticeGhs";
Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
GhsNotifyClass::newOrderNotify($saleId);
//向供货商端APP发通知
// $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
// $push = new push('ghs', push::MSG_TYPE_ORDER);
// $push->ghsOrderMessage($shop, $cgShop, $order);
}
//花店采购供货商端APP收到通知
//NoticeClass::ghsNewOrderNotice($order);
}
}
}
}
exit();
} catch (\Exception $e) {
$transaction->rollBack();
Yii::error("失败原因:" . $e->getMessage());
}
}
//支付宝异步通知
public function actionAliCallback()
{
header("Content-type: text/html; charset=utf-8");
$aliWap = Yii::getAlias("@vendor/alipayWap");
//商户订单号
$orderSn = $_POST['out_trade_no'];
// $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+Jp0T5R21pzuYaJkPuGlNEHA13b5T3r1l2ltomSEdaShvD5EZ9WtErYV5zpSv7FjjIGkbwa0H3A8Ydnvw5z4A9TZjjHLjC2GtVGJReqHGglMECgYEAydddA4NRPxmXvIjjmLb1Ft1qwHuyv3vvWhi50foGZXNEnBcfP/OkfyBDDpOEu34GZBMXK9ykHBs1l93OEFGXh7AwW0Lp5lARahBEfBZ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PqpB/yYaxeqgIEfnvGY9ILXCuvbePfYqFmMwzALWvZ+v7uVKa2M7HstWCrq7O+m/lQFN/ut8ZnUDcBn4WwwHa/PjCYietetO2gpDRmAdSqrWGH8CgYBkwp+r6pkJzW60kHSZIlEKAe7oJMwLNC2ZqQ4MwGwzfBaH+E34kCuR8ZqYzyAIVOa/Nwi5By1Zvi1KzBwJmUUTJ3o7WCOE96EzSrmOZlqXNCwO/36Vh6dshhhE/birIlXJSP0xdzpBQy2ksyli9eGy8cdJ2Y72Wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
$aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
$config = [
//应用ID,您的APP_ID
'app_id' => $aliPId,
//商户私钥,您的原始格式RSA私钥
'merchant_private_key' => $aliKey,
//异步通知地址
'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
//同步跳转
'return_url' => "",
//编码格式
'charset' => "UTF-8",
//签名方式
'sign_type' => "RSA2",
//支付宝网关
'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
'alipay_public_key' => $aliPublicKey,
];
require_once($aliWap . '/wappay/service/AlipayTradeService.php');
require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
$arr = $_POST;
$aliService = new \AlipayTradeService($config);
$aliService->writeLog(var_export($_POST, true));
$result = $aliService->check($arr);
Yii::info('check:' . $result);
if ($result == false) {
//请不要修改
echo "fail";
util::end();
}
//验证成功后续
$tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
$tradeStatus = $_POST['trade_status'] ?? '';//交易状态
$totalFee = $_POST['total_amount'] ?? '';
$appId = $_POST['app_id'] ?? '';
$attach = $_POST['passback_params'] ?? '';
$attach = urldecode($attach);
//接收流水类型、代金劵
parse_str($attach);
//流水类型
$capitalType = isset($capitalType) ? $capitalType : null;
$RequestBuilder = new \AlipayTradeQueryContentBuilder();
$RequestBuilder->setTradeNo($tradeNo);
//$queryResult = $aliService->Query($RequestBuilder);
//$aliId = $queryResult->buyer_user_id;
//买家的支付宝帐号,不完整,带*号
//$aliAccount = $queryResult->buyer_logon_id;
if (isset($capitalType) == false) {
Yii::warning('capitalType empty, orderSn:' . $orderSn);
util::end();
}
if ($config['app_id'] != $appId) {
Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
util::end();
}
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
$aliPay = dict::getDict('payWay', 'alipay');
//支付成功后续流程
payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
$transaction->commit();
}
//请不要修改
echo "success";
exit();
} catch (\Exception $e) {
$transaction->rollBack();
Yii::error("失败原因:" . $e->getMessage());
}
}
}