NoticeController.php 54 KB

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