NoticeController.php 51 KB

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