NoticeController.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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\OrderClearClass;
  9. use bizGhs\order\classes\RefundOrderClass;
  10. use bizHd\cg\classes\CgRefundClass;
  11. use bizHd\ghs\classes\GhsClass;
  12. use bizHd\notice\classes\NoticeClass;
  13. use bizHd\purchase\classes\PurchaseClass;
  14. use bizHd\purchase\classes\PurchaseClearClass;
  15. use bizHd\wx\classes\WxOpenClass;
  16. use common\components\dict;
  17. use common\components\noticeUtil;
  18. use common\components\payUtil;
  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. 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. OrderClearClass::useBalanceClear($custom, $ghs, $shop, null);
  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. if (isset($cg->sendType) && $cg->sendType == 4) {
  178. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  179. $customId = $cg->customId ?? 0;
  180. $current = date("Y_m_d");
  181. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  182. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  183. }
  184. }
  185. if (!empty($cg) && $cg->payStatus == 1) {
  186. //微信通知
  187. if (!empty($order)) {
  188. //订单生成时唤起在线打印
  189. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  190. //有几个地方要同步去修改
  191. if (getenv('YII_ENV') == 'production') {
  192. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  193. $mallOrderNoPrint = [10536, 44282, 26374];
  194. } else {
  195. $mallOrderNoPrint = [];
  196. }
  197. if (in_array($order->mainId, $mallOrderNoPrint)) {
  198. } else {
  199. OrderClass::onlinePrint($order);
  200. $order->printNum += 1;
  201. $order->save();
  202. if (getenv('YII_ENV') == 'production') {
  203. //福州我要花、花路鲜花批发、小齐鲜花、花镜打二次小票,有多处要修改搜索关键词tow_print
  204. $needTwoPrint = [7538, 36707,76796];
  205. } else {
  206. $needTwoPrint = [644];
  207. }
  208. if (in_array($order->mainId, $needTwoPrint)) {
  209. if ($order->mainId == 7538) {
  210. OrderClass::onlinePrint($order, 0);
  211. } else {
  212. OrderClass::onlinePrint($order);
  213. }
  214. $order->printNum += 1;
  215. $order->save();
  216. }
  217. }
  218. }
  219. $cgShopId = $cg->shopId ?? 0;
  220. $cgShop = ShopClass::getById($cgShopId, true);
  221. if (!empty($cgShop)) {
  222. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  223. }
  224. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  225. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  226. ShopExtClass::ghsGatheringReport($order);
  227. }
  228. $shopId = $order->shopId ?? 0;
  229. $shop = ShopClass::getById($shopId, true);
  230. if (!empty($shop)) {
  231. GhsNotifyClass::newOrderNotify($saleId);
  232. }
  233. }
  234. }
  235. }
  236. exit();
  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::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  331. }
  332. }
  333. //零售采购成功后续流程
  334. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  335. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  336. $saleId = $cg->saleId ?? 0;
  337. $order = OrderClass::getById($saleId, true);
  338. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  339. GhsDeliveryOrderClass::payAfter($order);
  340. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔、镜中花卉,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  341. if (!empty($cg) && !empty($order)) {
  342. if (isset($cg->book) && $cg->book == 0) {
  343. $ghsShopId = $order->shopId ?? 0;
  344. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  345. if ($ext->orderFlow == 0) {
  346. PurchaseClass::confirmTake($cg);
  347. }
  348. }
  349. }
  350. //更新最后下单时间
  351. $customId = $order->customId ?? 0;
  352. $custom = CustomClass::getById($customId, true);
  353. $date = date("Y-m-d H:i:s");
  354. if (!empty($custom)) {
  355. $custom->recentExpend = $date;
  356. $custom->save();
  357. }
  358. $ghsId = $order->ghsId ?? 0;
  359. $ghs = GhsClass::getById($ghsId, true);
  360. if (!empty($ghs)) {
  361. $ghs->recentExpend = $date;
  362. $ghs->save();
  363. }
  364. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  365. if ($cg->transType != 5 && $cg->transType != 4) {
  366. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  367. $customId = $cg->customId ?? 0;
  368. $current = date("Y_m_d");
  369. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  370. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  371. }
  372. } else {
  373. if (isset($cg->sendType) && $cg->sendType == 4) {
  374. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  375. $customId = $cg->customId ?? 0;
  376. $current = date("Y_m_d");
  377. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  378. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  379. }
  380. }
  381. if (!empty($cg) && $cg->payStatus == 1) {
  382. //微信通知
  383. if (!empty($order)) {
  384. //订单生成时唤起在线打印
  385. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  386. //有几个地方要同步去修改
  387. if (getenv('YII_ENV') == 'production') {
  388. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  389. $mallOrderNoPrint = [10536, 44282, 26374];
  390. } else {
  391. $mallOrderNoPrint = [];
  392. }
  393. if (in_array($order->mainId, $mallOrderNoPrint)) {
  394. } else {
  395. $shopId = $order->shopId ?? 0;
  396. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  397. OrderClass::onlinePrint($order);
  398. if (isset($ext->printSn) && !empty($ext->printSn)) {
  399. $order->printNum += 1;
  400. $order->save();
  401. }
  402. if (getenv('YII_ENV') == 'production') {
  403. //福州我要花、花路鲜花批发、花镜打二次小票,有多处要修改搜索关键词tow_print
  404. $needTwoPrint = [7538, 36707,76796];
  405. } else {
  406. $needTwoPrint = [];
  407. }
  408. if (in_array($order->mainId, $needTwoPrint)) {
  409. if ($order->mainId == 7538) {
  410. OrderClass::onlinePrint($order, 0);
  411. } else {
  412. OrderClass::onlinePrint($order);
  413. }
  414. if (isset($ext->printSn) && !empty($ext->printSn)) {
  415. $order->printNum += 1;
  416. $order->save();
  417. }
  418. }
  419. }
  420. }
  421. $cgShopId = $cg->shopId ?? 0;
  422. $cgShop = ShopClass::getById($cgShopId, true);
  423. if (!empty($cgShop)) {
  424. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  425. }
  426. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  427. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  428. ShopExtClass::ghsGatheringReport($order);
  429. }
  430. $shopId = $order->shopId ?? 0;
  431. $shop = ShopClass::getById($shopId, true);
  432. if (!empty($shop)) {
  433. //花店采购供货商端微信收到通知
  434. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  435. // $noticeText = json_encode(['orderId' => $saleId]);
  436. // $noticeKey = "hdCgNoticeGhs";
  437. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  438. GhsNotifyClass::newOrderNotify($saleId);
  439. //向供货商APP发通知
  440. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  441. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  442. // $push->ghsOrderMessage($shop, $cgShop, $order);
  443. }
  444. //花店采购供货商端APP收到通知
  445. //NoticeClass::ghsNewOrderNotice($order);
  446. }
  447. }
  448. }
  449. //散客下单买花,回调通知后,播报声音提示,这个方法本来不能写在这边要写在app-mall里的
  450. if ($capitalType == dict::getDict('capitalType', 'xhOrder', 'id')) {
  451. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  452. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  453. if (empty($has)) {
  454. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  455. $newOrder = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  456. if ($newOrder->onlinePay == 2) {
  457. //语音播报
  458. ShopExtClass::hdGatheringReport($newOrder);
  459. }
  460. }
  461. }
  462. exit();
  463. } catch (\Exception $e) {
  464. $transaction->rollBack();
  465. Yii::error("失败原因:" . $e->getMessage());
  466. }
  467. }
  468. //微信支付异步回调
  469. public function actionWxCallback()
  470. {
  471. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  472. if (empty($postStr)) {
  473. util::end();
  474. }
  475. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  476. if ($postObj->return_code != 'SUCCESS') {
  477. Yii::warning('return_code error:' . $postObj->return_code);
  478. util::end();
  479. }
  480. $orderSn = $postObj->out_trade_no;
  481. $total_fee = $postObj->total_fee;
  482. $totalFee = $total_fee / 100;
  483. $attach = $postObj->attach;
  484. $transactionId = $postObj->transaction_id ?? '';
  485. //接收流水类型、代金劵
  486. parse_str($attach);
  487. //流水类型
  488. $capitalType = isset($capitalType) ? $capitalType : null;
  489. if (isset($capitalType) == false) {
  490. Yii::warning('capitalType empty,orderSn:' . $orderSn);
  491. util::end();
  492. }
  493. $connection = Yii::$app->db;
  494. $transaction = $connection->beginTransaction();
  495. try {
  496. $wxPay = dict::getDict('payWay', 'wxPay');
  497. //支付成功后续流程
  498. payUtil::thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  499. $transaction->commit();
  500. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  501. //解决重复通知
  502. $cacheKey = 'pay_success_notice_' . $orderSn;
  503. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  504. if (!empty($has)) {
  505. Yii::$app->end();
  506. }
  507. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  508. //零售采购结账通知
  509. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  510. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  511. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  512. if ($cg->transType != 5 && $cg->transType != 4) {
  513. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  514. $customId = $cg->customId ?? 0;
  515. $current = date("Y_m_d");
  516. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  517. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  518. }
  519. } else {
  520. if (isset($cg->sendType) && $cg->sendType == 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. }
  528. if (!empty($cg) && $cg->payStatus == 1) {
  529. //微信通知
  530. $saleId = $cg->saleId ?? 0;
  531. $order = OrderClass::getById($saleId, true);
  532. if (!empty($order)) {
  533. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  534. GhsDeliveryOrderClass::payAfter($order);
  535. //订单生成时唤起在线打印
  536. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  537. //有几个地方要同步去修改
  538. if (getenv('YII_ENV') == 'production') {
  539. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  540. $mallOrderNoPrint = [10536, 44282, 26374];
  541. } else {
  542. $mallOrderNoPrint = [];
  543. }
  544. if (in_array($order->mainId, $mallOrderNoPrint)) {
  545. } else {
  546. OrderClass::onlinePrint($order);
  547. $order->printNum += 1;
  548. $order->save();
  549. }
  550. }
  551. $cgShopId = $cg->shopId ?? 0;
  552. $cgShop = ShopClass::getById($cgShopId, true);
  553. if (!empty($cgShop)) {
  554. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  555. }
  556. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  557. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  558. ShopExtClass::ghsGatheringReport($order);
  559. }
  560. $shopId = $order->shopId ?? 0;
  561. $shop = ShopClass::getById($shopId, true);
  562. if (!empty($shop)) {
  563. //花店采购供货商端微信收到通知
  564. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  565. // $noticeText = json_encode(['orderId' => $saleId]);
  566. // $noticeKey = "hdCgNoticeGhs";
  567. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  568. GhsNotifyClass::newOrderNotify($saleId);
  569. //向供货商端APP发通知
  570. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  571. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  572. // $push->ghsOrderMessage($shop, $cgShop, $order);
  573. }
  574. //花店采购供货商端APP收到通知
  575. //NoticeClass::ghsNewOrderNotice($order);
  576. }
  577. }
  578. }
  579. exit();
  580. } catch (\Exception $e) {
  581. $transaction->rollBack();
  582. Yii::error("失败原因:" . $e->getMessage());
  583. }
  584. }
  585. //微信退款结果通知
  586. public function actionWxRefundCallback()
  587. {
  588. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  589. if (empty($postStr)) {
  590. util::end();
  591. }
  592. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  593. if ($postObj->return_code != 'SUCCESS') {
  594. $msg = $postObj->return_msg ?? '';
  595. $text = '微信退款结果通知,报错了,报错内容:' . $msg;
  596. Yii::warning($text);
  597. noticeUtil::push($text, '15280215347');
  598. util::end();
  599. }
  600. //解密req_info
  601. $wx = WxOpenClass::getWxInfo();
  602. $req_info = $postObj->req_info ?? '';
  603. $key = $wx['wxPayKey'] ?? '';
  604. $xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
  605. $req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  606. $refund_status = $req_info_obj->refund_status ?? '';
  607. $orderSn = $req_info_obj->out_trade_no ?? '';
  608. $out_refund_no = $req_info_obj->out_refund_no ?? '';
  609. //订单总金额
  610. $total_fee = $req_info_obj->total_fee ?? 0.00;
  611. //申请退款金额
  612. //$refund_fee = $req_info_obj->refund_fee ?? 0.00;
  613. //退款金额
  614. $settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
  615. $new_total_fee = bcdiv($total_fee, 100, 2);
  616. $new_total_fee = floatval($new_total_fee);
  617. $new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
  618. $new_settlement_refund_fee = floatval($new_settlement_refund_fee);
  619. $connection = Yii::$app->db;
  620. $transaction = $connection->beginTransaction();
  621. $text = '';
  622. try {
  623. if ($refund_status == 'SUCCESS') {
  624. $cgRefund = CgRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
  625. if (!empty($cgRefund)) {
  626. $cgRefund->status = CgRefundClass::STATUS_COMPLETE;
  627. $cgRefund->save();
  628. $saleRefundId = $cgRefund->saleRefundId ?? 0;
  629. $saleRefund = RefundOrderClass::getById($saleRefundId, true);
  630. if (!empty($saleRefund)) {
  631. $saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
  632. $saleRefund->save();
  633. }
  634. }
  635. //$text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  636. } elseif ($refund_status == 'REFUNDCLOSE') {
  637. $text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  638. } else {
  639. $text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  640. }
  641. $transaction->commit();
  642. if (!empty($text)) {
  643. noticeUtil::push($text, '15280215347');
  644. }
  645. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  646. exit();
  647. } catch (\Exception $e) {
  648. $transaction->rollBack();
  649. Yii::error("失败原因:" . $e->getMessage());
  650. }
  651. }
  652. //采购后支付宝异步通知
  653. public function actionCgAliCallback()
  654. {
  655. header("Content-type: text/html; charset=utf-8");
  656. $aliWap = Yii::getAlias("@vendor/alipayWap");
  657. //商户订单号
  658. $orderSn = $_POST['out_trade_no'];
  659. // $aliPId = '2017041906821571';
  660. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAH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03tpINRLrmq00sD0907oeuY8/2l6P7XOZSnCvE5Fw==';
  664. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  665. $config = [
  666. //应用ID,您的APP_ID
  667. 'app_id' => $aliPId,
  668. //商户私钥,您的原始格式RSA私钥
  669. 'merchant_private_key' => $aliKey,
  670. //异步通知地址
  671. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  672. //同步跳转
  673. 'return_url' => "",
  674. //编码格式
  675. 'charset' => "UTF-8",
  676. //签名方式
  677. 'sign_type' => "RSA2",
  678. //支付宝网关
  679. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  680. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  681. 'alipay_public_key' => $aliPublicKey,
  682. ];
  683. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  684. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  685. $arr = $_POST;
  686. $aliService = new \AlipayTradeService($config);
  687. $aliService->writeLog(var_export($_POST, true));
  688. $result = $aliService->check($arr);
  689. Yii::info('check:' . $result);
  690. if ($result == false) {
  691. //请不要修改
  692. echo "fail";
  693. util::end();
  694. }
  695. //验证成功后续
  696. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  697. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  698. $totalFee = $_POST['total_amount'] ?? '';
  699. $appId = $_POST['app_id'] ?? '';
  700. $attach = $_POST['passback_params'] ?? '';
  701. $attach = urldecode($attach);
  702. //接收流水类型、代金劵
  703. parse_str($attach);
  704. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  705. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  706. $RequestBuilder->setTradeNo($tradeNo);
  707. //$queryResult = $aliService->Query($RequestBuilder);
  708. //$aliId = $queryResult->buyer_user_id;
  709. //买家的支付宝帐号,不完整,带*号
  710. //$aliAccount = $queryResult->buyer_logon_id;
  711. if ($config['app_id'] != $appId) {
  712. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  713. util::end();
  714. }
  715. $connection = Yii::$app->db;
  716. $transaction = $connection->beginTransaction();
  717. try {
  718. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  719. $aliPay = dict::getDict('payWay', 'alipay');
  720. //支付成功后续流程
  721. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  722. $transaction->commit();
  723. //请不要修改
  724. echo "success";
  725. //解决重复通知
  726. $cacheKey = 'pay_success_notice_' . $orderSn;
  727. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  728. if (!empty($has)) {
  729. Yii::$app->end();
  730. }
  731. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  732. //零售采购通知
  733. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  734. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  735. if (!empty($cg) && $cg->payStatus == 1) {
  736. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  737. if ($cg->transType != 5 && $cg->transType != 4) {
  738. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  739. $customId = $cg->customId ?? 0;
  740. $current = date("Y_m_d");
  741. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  742. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  743. }
  744. } else {
  745. if (isset($cg->sendType) && $cg->sendType == 4) {
  746. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  747. $customId = $cg->customId ?? 0;
  748. $current = date("Y_m_d");
  749. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  750. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  751. }
  752. }
  753. //微信通知
  754. $saleId = $cg->saleId ?? 0;
  755. $order = OrderClass::getById($saleId, true);
  756. if (!empty($order)) {
  757. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  758. GhsDeliveryOrderClass::payAfter($order);
  759. //订单生成时唤起在线打印
  760. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  761. //有几个地方要同步去修改
  762. if (getenv('YII_ENV') == 'production') {
  763. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  764. $mallOrderNoPrint = [10536, 44282, 26374];
  765. } else {
  766. $mallOrderNoPrint = [];
  767. }
  768. if (in_array($order->mainId, $mallOrderNoPrint)) {
  769. } else {
  770. OrderClass::onlinePrint($order);
  771. $order->printNum += 1;
  772. $order->save();
  773. }
  774. }
  775. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  776. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  777. ShopExtClass::ghsGatheringReport($order);
  778. }
  779. $cgShopId = $cg->shopId ?? 0;
  780. $cgShop = ShopClass::getById($cgShopId, true);
  781. if (!empty($cgShop)) {
  782. NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  783. }
  784. $shopId = $order->shopId ?? 0;
  785. $shop = ShopClass::getById($shopId, true);
  786. if (!empty($shop)) {
  787. //花店采购供货商端微信收到通知
  788. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  789. $noticeText = json_encode(['orderId' => $saleId]);
  790. $noticeKey = "hdCgNoticeGhs";
  791. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  792. GhsNotifyClass::newOrderNotify($saleId);
  793. //向供货商端APP发通知
  794. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  795. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  796. // $push->ghsOrderMessage($shop, $cgShop, $order);
  797. }
  798. //花店采购供货商端APP收到通知
  799. //NoticeClass::ghsNewOrderNotice($order);
  800. }
  801. }
  802. }
  803. }
  804. exit();
  805. } catch (\Exception $e) {
  806. $transaction->rollBack();
  807. Yii::error("失败原因:" . $e->getMessage());
  808. }
  809. }
  810. //支付宝异步通知
  811. public function actionAliCallback()
  812. {
  813. header("Content-type: text/html; charset=utf-8");
  814. $aliWap = Yii::getAlias("@vendor/alipayWap");
  815. //商户订单号
  816. $orderSn = $_POST['out_trade_no'];
  817. // $aliPId = '2017041906821571';
  818. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12Eko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yvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  823. $config = [
  824. //应用ID,您的APP_ID
  825. 'app_id' => $aliPId,
  826. //商户私钥,您的原始格式RSA私钥
  827. 'merchant_private_key' => $aliKey,
  828. //异步通知地址
  829. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  830. //同步跳转
  831. 'return_url' => "",
  832. //编码格式
  833. 'charset' => "UTF-8",
  834. //签名方式
  835. 'sign_type' => "RSA2",
  836. //支付宝网关
  837. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  838. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  839. 'alipay_public_key' => $aliPublicKey,
  840. ];
  841. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  842. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  843. $arr = $_POST;
  844. $aliService = new \AlipayTradeService($config);
  845. $aliService->writeLog(var_export($_POST, true));
  846. $result = $aliService->check($arr);
  847. Yii::info('check:' . $result);
  848. if ($result == false) {
  849. //请不要修改
  850. echo "fail";
  851. util::end();
  852. }
  853. //验证成功后续
  854. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  855. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  856. $totalFee = $_POST['total_amount'] ?? '';
  857. $appId = $_POST['app_id'] ?? '';
  858. $attach = $_POST['passback_params'] ?? '';
  859. $attach = urldecode($attach);
  860. //接收流水类型、代金劵
  861. parse_str($attach);
  862. //流水类型
  863. $capitalType = isset($capitalType) ? $capitalType : null;
  864. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  865. $RequestBuilder->setTradeNo($tradeNo);
  866. //$queryResult = $aliService->Query($RequestBuilder);
  867. //$aliId = $queryResult->buyer_user_id;
  868. //买家的支付宝帐号,不完整,带*号
  869. //$aliAccount = $queryResult->buyer_logon_id;
  870. if (isset($capitalType) == false) {
  871. Yii::warning('capitalType empty, orderSn:' . $orderSn);
  872. util::end();
  873. }
  874. if ($config['app_id'] != $appId) {
  875. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  876. util::end();
  877. }
  878. $connection = Yii::$app->db;
  879. $transaction = $connection->beginTransaction();
  880. try {
  881. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  882. $aliPay = dict::getDict('payWay', 'alipay');
  883. //支付成功后续流程
  884. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  885. $transaction->commit();
  886. }
  887. //请不要修改
  888. echo "success";
  889. exit();
  890. } catch (\Exception $e) {
  891. $transaction->rollBack();
  892. Yii::error("失败原因:" . $e->getMessage());
  893. }
  894. }
  895. }