NoticeController.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <?php
  2. namespace hd\controllers;
  3. use biz\common\classes\GhsNotifyClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\custom\classes\CustomRechargeClass;
  7. use bizGhs\express\classes\GhsDeliveryOrderClass;
  8. use bizGhs\order\classes\RefundOrderClass;
  9. use bizHd\cg\classes\CgRefundClass;
  10. use bizHd\ghs\classes\GhsClass;
  11. use bizHd\notice\classes\NoticeClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use bizHd\purchase\classes\PurchaseClearClass;
  14. use bizHd\wx\classes\WxOpenClass;
  15. use common\components\dict;
  16. use common\components\noticeUtil;
  17. use common\components\payUtil;
  18. use Yii;
  19. use common\components\util;
  20. use biz\wx\classes\WxMessageClass;
  21. use bizGhs\order\classes\OrderClass;
  22. use bizGhs\order\classes\ShMethodClass;
  23. use biz\shop\classes\ShopExtClass;
  24. use common\components\lakala\Lakala;
  25. use common\components\push;
  26. class NoticeController extends PublicController
  27. {
  28. public $categoryList;
  29. //收银台的回调通知 ssh 20231229
  30. public function actionCashPayCallback()
  31. {
  32. header("Content-type: text/html; charset=utf-8");
  33. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  34. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  35. if (empty($postStr)) {
  36. util::end();
  37. }
  38. $headers = Yii::$app->getRequest()->getHeaders();
  39. $Authorization = $headers->get('Authorization');
  40. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  41. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  42. $params = [
  43. 'appid' => 'OP00002119',
  44. 'serial_no' => '018b08cfddbd',
  45. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  46. 'lklCertificatePath' => $lklCertificatePath,
  47. ];
  48. $laResource = new Lakala($params);
  49. $return = $laResource->signatureVerification($Authorization, $postStr);
  50. $postData = json_decode($postStr, true);
  51. $orderSn = $postData['out_order_no'] ?? '';
  52. $merchant_no = $postData['merchant_no'] ?? '';
  53. $orderTradeInfo = $postData['order_trade_info'] ?? [];
  54. $payMode = $orderTradeInfo['pay_mode'] ?? null;
  55. if (empty($payMode)) {
  56. noticeUtil::push('收银台支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  57. util::end();
  58. }
  59. $trade_amount = $orderTradeInfo['trade_amount'] ?? 0;
  60. $totalFee = $trade_amount / 100;
  61. if ($totalFee <= 0) {
  62. noticeUtil::push('收银台支付回调验证失败了,金额错误,请注意,orderSn:' . $orderSn, '15280215347');
  63. util::end();
  64. }
  65. $transactionId = $orderTradeInfo['trade_no'] ?? 0;
  66. if ($return == false) {
  67. noticeUtil::push('收银台支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
  68. util::end();
  69. }
  70. $orderStatus = $postData['order_status'];
  71. $tradeType = $orderTradeInfo['trade_type'] ?? '';
  72. if ($tradeType != 'PAY') {
  73. noticeUtil::push('收银台支付回调验证失败了,不是消费的回调,orderSn:' . $orderSn, '15280215347');
  74. util::end();
  75. }
  76. //接收流水类型、代金劵
  77. $remarkString = $orderTradeInfo['trade_remark'] ?? '';
  78. $remarkData = json_decode($remarkString, true);
  79. //流水类型
  80. $capitalType = $remarkData['capitalType'] ?? null;
  81. if (!isset($capitalType)) {
  82. noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
  83. util::end();
  84. }
  85. $connection = Yii::$app->db;
  86. $transaction = $connection->beginTransaction();
  87. try {
  88. if ($orderStatus == 2) {
  89. $payWayType = null;
  90. if ($payMode == 'ALIPAY') {
  91. $payWayType = dict::getDict('payWay', 'alipay');
  92. }
  93. if ($payMode == 'WECHAT') {
  94. $payWayType = dict::getDict('payWay', 'wxPay');
  95. }
  96. if (isset($payWayType) == false) {
  97. noticeUtil::push('收银台支付回调验证失败了,没有找到支付方式,orderSn:' . $orderSn, '15280215347');
  98. util::end();
  99. }
  100. $attach = 'merchant_no=' . $merchant_no;
  101. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  102. $transaction->commit();
  103. }
  104. //请不要修改
  105. echo "SUCCESS";
  106. //解决重复通知
  107. $cacheKey = 'pay_success_notice_' . $orderSn;
  108. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  109. if (!empty($has)) {
  110. Yii::$app->end();
  111. }
  112. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  113. //客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
  114. if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
  115. $customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
  116. $customId = $customRecharge->customId ?? 0;
  117. $ghsId = $customRecharge->ghsId ?? 0;
  118. $ghs = GhsClass::getLockById($ghsId);
  119. $ghsShopId = $ghs->shopId ?? 0;
  120. $custom = CustomClass::getLockById($customId);
  121. $shop = ShopClass::getById($ghsShopId, true);
  122. // 销账已在 CustomRechargeClass::thirdPay 内按本次来款 FIFO 完成,勿再 useBalanceClear
  123. //充值销账通知
  124. WxMessageClass::customRechargeClearInform($shop, $customRecharge);
  125. }
  126. //零售线上结账通知
  127. if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
  128. $clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
  129. $customId = $clearInfo->customId ?? 0;
  130. $ghsShopId = $clearInfo->ghsShopId ?? 0;
  131. $ghsShop = ShopClass::getById($ghsShopId, true);
  132. $custom = CustomClass::getById($customId, true);
  133. if (!empty($custom) && !empty($ghsShop)) {
  134. WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  135. }
  136. }
  137. //零售采购通知
  138. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  139. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  140. $saleId = $cg->saleId ?? 0;
  141. $order = OrderClass::getById($saleId, true);
  142. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  143. GhsDeliveryOrderClass::payAfter($order);
  144. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  145. if (!empty($cg) && !empty($order)) {
  146. if (isset($cg->book) && $cg->book == 0) {
  147. $ghsShopId = $order->shopId ?? 0;
  148. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  149. if ($ext->orderFlow == 0) {
  150. PurchaseClass::confirmTake($cg);
  151. }
  152. }
  153. }
  154. //更新最后下单时间
  155. $customId = $order->customId ?? 0;
  156. $custom = CustomClass::getById($customId, true);
  157. $date = date("Y-m-d H:i:s");
  158. if (!empty($custom)) {
  159. $custom->recentExpend = $date;
  160. $custom->save();
  161. }
  162. $ghsId = $order->ghsId ?? 0;
  163. $ghs = GhsClass::getById($ghsId, true);
  164. if (!empty($ghs)) {
  165. $ghs->recentExpend = $date;
  166. $ghs->save();
  167. }
  168. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  169. if ($cg->transType != 5 && $cg->transType != 4) {
  170. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  171. $customId = $cg->customId ?? 0;
  172. $current = date("Y_m_d");
  173. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  174. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  175. }
  176. } else {
  177. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  178. $customId = $cg->customId ?? 0;
  179. if (isset($cg->sendType)) {
  180. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  181. $customId,
  182. $cg->sendType,
  183. $cg->sendCost ?? 0,
  184. $cg->packCost ?? 0
  185. );
  186. }
  187. }
  188. if (!empty($cg) && $cg->payStatus == 1) {
  189. //微信通知
  190. if (!empty($order)) {
  191. //订单生成时唤起在线打印
  192. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  193. //有几个地方要同步去修改
  194. if (getenv('YII_ENV') == 'production') {
  195. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  196. $mallOrderNoPrint = [10536, 44282, 26374];
  197. } else {
  198. $mallOrderNoPrint = [];
  199. }
  200. if (in_array($order->mainId, $mallOrderNoPrint)) {
  201. } else {
  202. OrderClass::onlinePrint($order);
  203. $order->printNum += 1;
  204. $order->save();
  205. if (getenv('YII_ENV') == 'production') {
  206. //福州我要花、花路鲜花批发、小齐鲜花、花镜打二次小票,有多处要修改搜索关键词tow_print
  207. $needTwoPrint = [7538, 36707, 76796, 94589];
  208. } else {
  209. $needTwoPrint = [644];
  210. }
  211. if (in_array($order->mainId, $needTwoPrint)) {
  212. if ($order->mainId == 7538) {
  213. OrderClass::onlinePrint($order, 0);
  214. } else {
  215. OrderClass::onlinePrint($order);
  216. }
  217. $order->printNum += 1;
  218. $order->save();
  219. }
  220. }
  221. }
  222. $cgShopId = $cg->shopId ?? 0;
  223. $cgShop = ShopClass::getById($cgShopId, true);
  224. if (!empty($cgShop)) {
  225. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  226. }
  227. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  228. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  229. ShopExtClass::ghsGatheringReport($order);
  230. }
  231. $shopId = $order->shopId ?? 0;
  232. $shop = ShopClass::getById($shopId, true);
  233. if (!empty($shop)) {
  234. GhsNotifyClass::newOrderNotify($saleId);
  235. }
  236. }
  237. }
  238. }
  239. exit();
  240. } catch (\Exception $e) {
  241. $transaction->rollBack();
  242. Yii::error("失败原因:" . $e->getMessage());
  243. }
  244. }
  245. //拉卡拉回调通知 ssh 20231009
  246. public function actionPayCallback()
  247. {
  248. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  249. if (empty($postStr)) {
  250. util::end();
  251. }
  252. $headers = Yii::$app->getRequest()->getHeaders();
  253. $Authorization = $headers->get('Authorization');
  254. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  255. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  256. $params = [
  257. 'appid' => 'OP00002119',
  258. 'serial_no' => '018b08cfddbd',
  259. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  260. 'lklCertificatePath' => $lklCertificatePath,
  261. ];
  262. $laResource = new Lakala($params);
  263. $return = $laResource->signatureVerification($Authorization, $postStr);
  264. $postData = json_decode($postStr, true);
  265. $orderSn = $postData['out_trade_no'] ?? '';
  266. $total_amount = $postData['total_amount'] ?? 0;
  267. $account_type = $postData['account_type'] ?? '';
  268. $merchant_no = $postData['merchant_no'] ?? '';
  269. if (empty($account_type)) {
  270. noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  271. util::end();
  272. }
  273. $totalFee = $total_amount / 100;
  274. $transactionId = $postData['trade_no'] ?? 0;
  275. if ($return == false) {
  276. noticeUtil::push('支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
  277. util::end();
  278. }
  279. //接收流水类型、代金劵
  280. $remarkString = $postData['remark'] ?? '';
  281. $remarkData = json_decode($remarkString, true);
  282. //流水类型
  283. $capitalType = isset($remarkData['capitalType']) ? $remarkData['capitalType'] : null;
  284. if (isset($capitalType) == false) {
  285. noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
  286. util::end();
  287. }
  288. $currentPayWay = null;
  289. $connection = Yii::$app->db;
  290. $transaction = $connection->beginTransaction();
  291. try {
  292. if ($account_type == 'WECHAT') {
  293. $currentPayWay = dict::getDict('payWay', 'wxPay');
  294. } elseif ($account_type == 'ALIPAY') {
  295. $currentPayWay = dict::getDict('payWay', 'alipay');
  296. } else {
  297. noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
  298. util::end();
  299. }
  300. //支付成功后续流程
  301. $attach = 'merchant_no=' . $merchant_no;
  302. payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  303. $transaction->commit();
  304. echo "SUCCESS";
  305. //解决重复通知
  306. $cacheKey = 'pay_success_notice_' . $orderSn;
  307. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  308. if (!empty($has)) {
  309. Yii::$app->end();
  310. }
  311. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  312. //客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
  313. if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
  314. $customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
  315. $customId = $customRecharge->customId ?? 0;
  316. $ghsId = $customRecharge->ghsId ?? 0;
  317. $ghs = GhsClass::getLockById($ghsId);
  318. $ghsShopId = $ghs->shopId ?? 0;
  319. $custom = CustomClass::getLockById($customId);
  320. $shop = ShopClass::getById($ghsShopId, true);
  321. // 销账已在 CustomRechargeClass::thirdPay 内按本次来款 FIFO 完成,勿再 useBalanceClear
  322. //充值销账通知
  323. WxMessageClass::customRechargeClearInform($shop, $customRecharge);
  324. }
  325. //零售线上结账通知
  326. if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
  327. $clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
  328. $customId = $clearInfo->customId ?? 0;
  329. $ghsShopId = $clearInfo->ghsShopId ?? 0;
  330. $ghsShop = ShopClass::getById($ghsShopId, true);
  331. $custom = CustomClass::getById($customId, true);
  332. if (!empty($custom) && !empty($ghsShop)) {
  333. WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  334. }
  335. }
  336. //零售采购成功后续流程
  337. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  338. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  339. $saleId = $cg->saleId ?? 0;
  340. $order = OrderClass::getById($saleId, true);
  341. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  342. GhsDeliveryOrderClass::payAfter($order);
  343. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔、镜中花卉,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  344. if (!empty($cg) && !empty($order)) {
  345. if (isset($cg->book) && $cg->book == 0) {
  346. $ghsShopId = $order->shopId ?? 0;
  347. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  348. if ($ext->orderFlow == 0) {
  349. PurchaseClass::confirmTake($cg);
  350. }
  351. }
  352. }
  353. //更新最后下单时间
  354. $customId = $order->customId ?? 0;
  355. $custom = CustomClass::getById($customId, true);
  356. $date = date("Y-m-d H:i:s");
  357. if (!empty($custom)) {
  358. $custom->recentExpend = $date;
  359. $custom->save();
  360. }
  361. $ghsId = $order->ghsId ?? 0;
  362. $ghs = GhsClass::getById($ghsId, true);
  363. if (!empty($ghs)) {
  364. $ghs->recentExpend = $date;
  365. $ghs->save();
  366. }
  367. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  368. if ($cg->transType != 5 && $cg->transType != 4) {
  369. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  370. $customId = $cg->customId ?? 0;
  371. $current = date("Y_m_d");
  372. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  373. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  374. }
  375. } else {
  376. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  377. $customId = $cg->customId ?? 0;
  378. if (isset($cg->sendType)) {
  379. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  380. $customId,
  381. $cg->sendType,
  382. $cg->sendCost ?? 0,
  383. $cg->packCost ?? 0
  384. );
  385. }
  386. }
  387. if (!empty($cg) && $cg->payStatus == 1) {
  388. //微信通知
  389. if (!empty($order)) {
  390. //订单生成时唤起在线打印
  391. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  392. //有几个地方要同步去修改
  393. if (getenv('YII_ENV') == 'production') {
  394. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  395. $mallOrderNoPrint = [10536, 44282, 26374];
  396. } else {
  397. $mallOrderNoPrint = [];
  398. }
  399. if (in_array($order->mainId, $mallOrderNoPrint)) {
  400. } else {
  401. $shopId = $order->shopId ?? 0;
  402. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  403. OrderClass::onlinePrint($order);
  404. if (isset($ext->printSn) && !empty($ext->printSn)) {
  405. $order->printNum += 1;
  406. $order->save();
  407. }
  408. if (getenv('YII_ENV') == 'production') {
  409. //福州我要花、花路鲜花批发、花镜打二次小票,有多处要修改搜索关键词tow_print
  410. $needTwoPrint = [7538, 36707, 76796, 94589];
  411. } else {
  412. $needTwoPrint = [];
  413. }
  414. if (in_array($order->mainId, $needTwoPrint)) {
  415. if ($order->mainId == 7538) {
  416. OrderClass::onlinePrint($order, 0);
  417. } else {
  418. OrderClass::onlinePrint($order);
  419. }
  420. if (isset($ext->printSn) && !empty($ext->printSn)) {
  421. $order->printNum += 1;
  422. $order->save();
  423. }
  424. }
  425. }
  426. }
  427. $cgShopId = $cg->shopId ?? 0;
  428. $cgShop = ShopClass::getById($cgShopId, true);
  429. if (!empty($cgShop)) {
  430. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  431. }
  432. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  433. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  434. ShopExtClass::ghsGatheringReport($order);
  435. }
  436. $shopId = $order->shopId ?? 0;
  437. $shop = ShopClass::getById($shopId, true);
  438. if (!empty($shop)) {
  439. //花店采购供货商端微信收到通知
  440. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  441. // $noticeText = json_encode(['orderId' => $saleId]);
  442. // $noticeKey = "hdCgNoticeGhs";
  443. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  444. GhsNotifyClass::newOrderNotify($saleId);
  445. //向供货商APP发通知
  446. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  447. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  448. // $push->ghsOrderMessage($shop, $cgShop, $order);
  449. }
  450. //花店采购供货商端APP收到通知
  451. //NoticeClass::ghsNewOrderNotice($order);
  452. }
  453. }
  454. }
  455. //散客下单买花,回调通知后,播报声音提示,这个方法本来不能写在这边要写在app-mall里的
  456. if ($capitalType == dict::getDict('capitalType', 'xhOrder', 'id')) {
  457. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  458. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  459. if (empty($has)) {
  460. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  461. $newOrder = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  462. if ($newOrder->onlinePay == 2) {
  463. //语音播报
  464. ShopExtClass::hdGatheringReport($newOrder);
  465. }
  466. }
  467. }
  468. exit();
  469. } catch (\Exception $e) {
  470. $transaction->rollBack();
  471. $msg = $e->getMessage();
  472. noticeUtil::push(" PayCallback 报错了 " . $currentPayWay . " capitalType:" . $capitalType . " orderSn:" . $orderSn . " totalFee:" . $totalFee . " 第三方id:" . $transactionId . " 原因:" . $msg, '15280215347');
  473. Yii::error("失败原因:" . $msg);
  474. }
  475. }
  476. //微信支付异步回调
  477. public function actionWxCallback()
  478. {
  479. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  480. if (empty($postStr)) {
  481. util::end();
  482. }
  483. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  484. if ($postObj->return_code != 'SUCCESS') {
  485. Yii::warning('return_code error:' . $postObj->return_code);
  486. util::end();
  487. }
  488. $orderSn = $postObj->out_trade_no;
  489. $total_fee = $postObj->total_fee;
  490. $totalFee = $total_fee / 100;
  491. $attach = $postObj->attach;
  492. $transactionId = $postObj->transaction_id ?? '';
  493. //接收流水类型、代金劵
  494. parse_str($attach);
  495. //流水类型
  496. $capitalType = isset($capitalType) ? $capitalType : null;
  497. if (isset($capitalType) == false) {
  498. Yii::warning('capitalType empty,orderSn:' . $orderSn);
  499. util::end();
  500. }
  501. $connection = Yii::$app->db;
  502. $transaction = $connection->beginTransaction();
  503. try {
  504. $wxPay = dict::getDict('payWay', 'wxPay');
  505. //支付成功后续流程
  506. payUtil::thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  507. $transaction->commit();
  508. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  509. //解决重复通知
  510. $cacheKey = 'pay_success_notice_' . $orderSn;
  511. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  512. if (!empty($has)) {
  513. Yii::$app->end();
  514. }
  515. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  516. //零售采购结账通知
  517. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  518. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  519. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  520. if ($cg->transType != 5 && $cg->transType != 4) {
  521. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  522. $customId = $cg->customId ?? 0;
  523. $current = date("Y_m_d");
  524. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  525. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  526. }
  527. } else {
  528. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  529. $customId = $cg->customId ?? 0;
  530. if (isset($cg->sendType)) {
  531. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  532. $customId,
  533. $cg->sendType,
  534. $cg->sendCost ?? 0,
  535. $cg->packCost ?? 0
  536. );
  537. }
  538. }
  539. if (!empty($cg) && $cg->payStatus == 1) {
  540. //微信通知
  541. $saleId = $cg->saleId ?? 0;
  542. $order = OrderClass::getById($saleId, true);
  543. if (!empty($order)) {
  544. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  545. GhsDeliveryOrderClass::payAfter($order);
  546. //订单生成时唤起在线打印
  547. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  548. //有几个地方要同步去修改
  549. if (getenv('YII_ENV') == 'production') {
  550. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  551. $mallOrderNoPrint = [10536, 44282, 26374];
  552. } else {
  553. $mallOrderNoPrint = [];
  554. }
  555. if (in_array($order->mainId, $mallOrderNoPrint)) {
  556. } else {
  557. OrderClass::onlinePrint($order);
  558. $order->printNum += 1;
  559. $order->save();
  560. }
  561. }
  562. $cgShopId = $cg->shopId ?? 0;
  563. $cgShop = ShopClass::getById($cgShopId, true);
  564. if (!empty($cgShop)) {
  565. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  566. }
  567. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  568. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  569. ShopExtClass::ghsGatheringReport($order);
  570. }
  571. $shopId = $order->shopId ?? 0;
  572. $shop = ShopClass::getById($shopId, true);
  573. if (!empty($shop)) {
  574. //花店采购供货商端微信收到通知
  575. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  576. // $noticeText = json_encode(['orderId' => $saleId]);
  577. // $noticeKey = "hdCgNoticeGhs";
  578. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  579. GhsNotifyClass::newOrderNotify($saleId);
  580. //向供货商端APP发通知
  581. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  582. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  583. // $push->ghsOrderMessage($shop, $cgShop, $order);
  584. }
  585. //花店采购供货商端APP收到通知
  586. //NoticeClass::ghsNewOrderNotice($order);
  587. }
  588. }
  589. }
  590. exit();
  591. } catch (\Exception $e) {
  592. $transaction->rollBack();
  593. Yii::error("失败原因:" . $e->getMessage());
  594. }
  595. }
  596. //微信退款结果通知
  597. public function actionWxRefundCallback()
  598. {
  599. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  600. if (empty($postStr)) {
  601. util::end();
  602. }
  603. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  604. if ($postObj->return_code != 'SUCCESS') {
  605. $msg = $postObj->return_msg ?? '';
  606. $text = '微信退款结果通知,报错了,报错内容:' . $msg;
  607. Yii::warning($text);
  608. noticeUtil::push($text, '15280215347');
  609. util::end();
  610. }
  611. //解密req_info
  612. $wx = WxOpenClass::getWxInfo();
  613. $req_info = $postObj->req_info ?? '';
  614. $key = $wx['wxPayKey'] ?? '';
  615. $xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
  616. $req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  617. $refund_status = $req_info_obj->refund_status ?? '';
  618. $orderSn = $req_info_obj->out_trade_no ?? '';
  619. $out_refund_no = $req_info_obj->out_refund_no ?? '';
  620. //订单总金额
  621. $total_fee = $req_info_obj->total_fee ?? 0.00;
  622. //申请退款金额
  623. //$refund_fee = $req_info_obj->refund_fee ?? 0.00;
  624. //退款金额
  625. $settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
  626. $new_total_fee = bcdiv($total_fee, 100, 2);
  627. $new_total_fee = floatval($new_total_fee);
  628. $new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
  629. $new_settlement_refund_fee = floatval($new_settlement_refund_fee);
  630. $connection = Yii::$app->db;
  631. $transaction = $connection->beginTransaction();
  632. $text = '';
  633. try {
  634. if ($refund_status == 'SUCCESS') {
  635. $cgRefund = CgRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
  636. if (!empty($cgRefund)) {
  637. $cgRefund->status = CgRefundClass::STATUS_COMPLETE;
  638. $cgRefund->save();
  639. $saleRefundId = $cgRefund->saleRefundId ?? 0;
  640. $saleRefund = RefundOrderClass::getById($saleRefundId, true);
  641. if (!empty($saleRefund)) {
  642. $saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
  643. $saleRefund->save();
  644. }
  645. }
  646. //$text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  647. } elseif ($refund_status == 'REFUNDCLOSE') {
  648. $text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  649. } else {
  650. $text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  651. }
  652. $transaction->commit();
  653. if (!empty($text)) {
  654. noticeUtil::push($text, '15280215347');
  655. }
  656. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  657. exit();
  658. } catch (\Exception $e) {
  659. $transaction->rollBack();
  660. Yii::error("失败原因:" . $e->getMessage());
  661. }
  662. }
  663. //采购后支付宝异步通知
  664. public function actionCgAliCallback()
  665. {
  666. header("Content-type: text/html; charset=utf-8");
  667. $aliWap = Yii::getAlias("@vendor/alipayWap");
  668. //商户订单号
  669. $orderSn = $_POST['out_trade_no'];
  670. // $aliPId = '2017041906821571';
  671. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7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wo+TjSclRbKiPQKBgQD1C/CJRQbahz6B3Sc4NOiFUQioM30qDKbDibzUq95u5PtQOx69+/h68tA2nj7ILZOXoh6/KF6LM9WK0QctY0HR5Uy4Uz8YkY/Y0L/LExSkNdpYqbpBc8DdIsKYHoMLNHDwc03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  675. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  676. $config = [
  677. //应用ID,您的APP_ID
  678. 'app_id' => $aliPId,
  679. //商户私钥,您的原始格式RSA私钥
  680. 'merchant_private_key' => $aliKey,
  681. //异步通知地址
  682. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  683. //同步跳转
  684. 'return_url' => "",
  685. //编码格式
  686. 'charset' => "UTF-8",
  687. //签名方式
  688. 'sign_type' => "RSA2",
  689. //支付宝网关
  690. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  691. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  692. 'alipay_public_key' => $aliPublicKey,
  693. ];
  694. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  695. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  696. $arr = $_POST;
  697. $aliService = new \AlipayTradeService($config);
  698. $aliService->writeLog(var_export($_POST, true));
  699. $result = $aliService->check($arr);
  700. Yii::info('check:' . $result);
  701. if ($result == false) {
  702. //请不要修改
  703. echo "fail";
  704. util::end();
  705. }
  706. //验证成功后续
  707. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  708. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  709. $totalFee = $_POST['total_amount'] ?? '';
  710. $appId = $_POST['app_id'] ?? '';
  711. $attach = $_POST['passback_params'] ?? '';
  712. $attach = urldecode($attach);
  713. //接收流水类型、代金劵
  714. parse_str($attach);
  715. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  716. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  717. $RequestBuilder->setTradeNo($tradeNo);
  718. //$queryResult = $aliService->Query($RequestBuilder);
  719. //$aliId = $queryResult->buyer_user_id;
  720. //买家的支付宝帐号,不完整,带*号
  721. //$aliAccount = $queryResult->buyer_logon_id;
  722. if ($config['app_id'] != $appId) {
  723. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  724. util::end();
  725. }
  726. $connection = Yii::$app->db;
  727. $transaction = $connection->beginTransaction();
  728. try {
  729. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  730. $aliPay = dict::getDict('payWay', 'alipay');
  731. //支付成功后续流程
  732. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  733. $transaction->commit();
  734. //请不要修改
  735. echo "success";
  736. //解决重复通知
  737. $cacheKey = 'pay_success_notice_' . $orderSn;
  738. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  739. if (!empty($has)) {
  740. Yii::$app->end();
  741. }
  742. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  743. //零售采购通知
  744. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  745. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  746. if (!empty($cg) && $cg->payStatus == 1) {
  747. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  748. if ($cg->transType != 5 && $cg->transType != 4) {
  749. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  750. $customId = $cg->customId ?? 0;
  751. $current = date("Y_m_d");
  752. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  753. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  754. }
  755. } else {
  756. // 标记附加费锁定:自然日 key + 实收时的间隔时间戳
  757. $customId = $cg->customId ?? 0;
  758. if (isset($cg->sendType)) {
  759. ShMethodClass::markFeeStateAfterPurchaseSuccess(
  760. $customId,
  761. $cg->sendType,
  762. $cg->sendCost ?? 0,
  763. $cg->packCost ?? 0
  764. );
  765. }
  766. }
  767. //微信通知
  768. $saleId = $cg->saleId ?? 0;
  769. $order = OrderClass::getById($saleId, true);
  770. if (!empty($order)) {
  771. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  772. GhsDeliveryOrderClass::payAfter($order);
  773. //订单生成时唤起在线打印
  774. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  775. //有几个地方要同步去修改
  776. if (getenv('YII_ENV') == 'production') {
  777. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  778. $mallOrderNoPrint = [10536, 44282, 26374];
  779. } else {
  780. $mallOrderNoPrint = [];
  781. }
  782. if (in_array($order->mainId, $mallOrderNoPrint)) {
  783. } else {
  784. OrderClass::onlinePrint($order);
  785. $order->printNum += 1;
  786. $order->save();
  787. }
  788. }
  789. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  790. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  791. ShopExtClass::ghsGatheringReport($order);
  792. }
  793. $cgShopId = $cg->shopId ?? 0;
  794. $cgShop = ShopClass::getById($cgShopId, true);
  795. if (!empty($cgShop)) {
  796. NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  797. }
  798. $shopId = $order->shopId ?? 0;
  799. $shop = ShopClass::getById($shopId, true);
  800. if (!empty($shop)) {
  801. //花店采购供货商端微信收到通知
  802. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  803. $noticeText = json_encode(['orderId' => $saleId]);
  804. $noticeKey = "hdCgNoticeGhs";
  805. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  806. GhsNotifyClass::newOrderNotify($saleId);
  807. //向供货商端APP发通知
  808. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  809. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  810. // $push->ghsOrderMessage($shop, $cgShop, $order);
  811. }
  812. //花店采购供货商端APP收到通知
  813. //NoticeClass::ghsNewOrderNotice($order);
  814. }
  815. }
  816. }
  817. }
  818. exit();
  819. } catch (\Exception $e) {
  820. $transaction->rollBack();
  821. Yii::error("失败原因:" . $e->getMessage());
  822. }
  823. }
  824. //支付宝异步通知
  825. public function actionAliCallback()
  826. {
  827. header("Content-type: text/html; charset=utf-8");
  828. $aliWap = Yii::getAlias("@vendor/alipayWap");
  829. //商户订单号
  830. $orderSn = $_POST['out_trade_no'];
  831. // $aliPId = '2017041906821571';
  832. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXr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2l6P7XOZSnCvE5Fw==';
  836. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  837. $config = [
  838. //应用ID,您的APP_ID
  839. 'app_id' => $aliPId,
  840. //商户私钥,您的原始格式RSA私钥
  841. 'merchant_private_key' => $aliKey,
  842. //异步通知地址
  843. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  844. //同步跳转
  845. 'return_url' => "",
  846. //编码格式
  847. 'charset' => "UTF-8",
  848. //签名方式
  849. 'sign_type' => "RSA2",
  850. //支付宝网关
  851. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  852. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  853. 'alipay_public_key' => $aliPublicKey,
  854. ];
  855. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  856. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  857. $arr = $_POST;
  858. $aliService = new \AlipayTradeService($config);
  859. $aliService->writeLog(var_export($_POST, true));
  860. $result = $aliService->check($arr);
  861. Yii::info('check:' . $result);
  862. if ($result == false) {
  863. //请不要修改
  864. echo "fail";
  865. util::end();
  866. }
  867. //验证成功后续
  868. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  869. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  870. $totalFee = $_POST['total_amount'] ?? '';
  871. $appId = $_POST['app_id'] ?? '';
  872. $attach = $_POST['passback_params'] ?? '';
  873. $attach = urldecode($attach);
  874. //接收流水类型、代金劵
  875. parse_str($attach);
  876. //流水类型
  877. $capitalType = isset($capitalType) ? $capitalType : null;
  878. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  879. $RequestBuilder->setTradeNo($tradeNo);
  880. //$queryResult = $aliService->Query($RequestBuilder);
  881. //$aliId = $queryResult->buyer_user_id;
  882. //买家的支付宝帐号,不完整,带*号
  883. //$aliAccount = $queryResult->buyer_logon_id;
  884. if (isset($capitalType) == false) {
  885. Yii::warning('capitalType empty, orderSn:' . $orderSn);
  886. util::end();
  887. }
  888. if ($config['app_id'] != $appId) {
  889. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  890. util::end();
  891. }
  892. $connection = Yii::$app->db;
  893. $transaction = $connection->beginTransaction();
  894. try {
  895. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  896. $aliPay = dict::getDict('payWay', 'alipay');
  897. //支付成功后续流程
  898. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  899. $transaction->commit();
  900. }
  901. //请不要修改
  902. echo "success";
  903. exit();
  904. } catch (\Exception $e) {
  905. $transaction->rollBack();
  906. Yii::error("失败原因:" . $e->getMessage());
  907. }
  908. }
  909. }