NoticeController.php 54 KB

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