NoticeController.php 55 KB

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