NoticeController.php 55 KB

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