NoticeController.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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)){
  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)){
  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. //订单生成时唤起在线打印
  536. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  537. //有几个地方要同步去修改
  538. if (getenv('YII_ENV') == 'production') {
  539. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  540. $mallOrderNoPrint = [10536, 44282, 26374];
  541. } else {
  542. $mallOrderNoPrint = [];
  543. }
  544. if (in_array($order->mainId, $mallOrderNoPrint)) {
  545. } else {
  546. OrderClass::onlinePrint($order);
  547. $order->printNum += 1;
  548. $order->save();
  549. }
  550. }
  551. $cgShopId = $cg->shopId ?? 0;
  552. $cgShop = ShopClass::getById($cgShopId, true);
  553. if (!empty($cgShop)) {
  554. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  555. }
  556. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  557. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  558. ShopExtClass::ghsGatheringReport($order);
  559. }
  560. $shopId = $order->shopId ?? 0;
  561. $shop = ShopClass::getById($shopId, true);
  562. if (!empty($shop)) {
  563. //花店采购供货商端微信收到通知
  564. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  565. // $noticeText = json_encode(['orderId' => $saleId]);
  566. // $noticeKey = "hdCgNoticeGhs";
  567. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  568. GhsNotifyClass::newOrderNotify($saleId);
  569. //向供货商端APP发通知
  570. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  571. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  572. // $push->ghsOrderMessage($shop, $cgShop, $order);
  573. }
  574. //花店采购供货商端APP收到通知
  575. //NoticeClass::ghsNewOrderNotice($order);
  576. }
  577. }
  578. }
  579. } catch (\Exception $e) {
  580. $transaction->rollBack();
  581. Yii::error("失败原因:" . $e->getMessage());
  582. }
  583. }
  584. //微信退款结果通知
  585. public function actionWxRefundCallback()
  586. {
  587. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  588. if (empty($postStr)) {
  589. util::end();
  590. }
  591. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  592. if ($postObj->return_code != 'SUCCESS') {
  593. $msg = $postObj->return_msg ?? '';
  594. $text = '微信退款结果通知,报错了,报错内容:' . $msg;
  595. Yii::warning($text);
  596. noticeUtil::push($text, '15280215347');
  597. util::end();
  598. }
  599. //解密req_info
  600. $wx = WxOpenClass::getWxInfo();
  601. $req_info = $postObj->req_info ?? '';
  602. $key = $wx['wxPayKey'] ?? '';
  603. $xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
  604. $req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  605. $refund_status = $req_info_obj->refund_status ?? '';
  606. $orderSn = $req_info_obj->out_trade_no ?? '';
  607. $out_refund_no = $req_info_obj->out_refund_no ?? '';
  608. //订单总金额
  609. $total_fee = $req_info_obj->total_fee ?? 0.00;
  610. //申请退款金额
  611. //$refund_fee = $req_info_obj->refund_fee ?? 0.00;
  612. //退款金额
  613. $settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
  614. $new_total_fee = bcdiv($total_fee, 100, 2);
  615. $new_total_fee = floatval($new_total_fee);
  616. $new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
  617. $new_settlement_refund_fee = floatval($new_settlement_refund_fee);
  618. $connection = Yii::$app->db;
  619. $transaction = $connection->beginTransaction();
  620. $text = '';
  621. try {
  622. if ($refund_status == 'SUCCESS') {
  623. $cgRefund = CgRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
  624. if (!empty($cgRefund)) {
  625. $cgRefund->status = CgRefundClass::STATUS_COMPLETE;
  626. $cgRefund->save();
  627. $saleRefundId = $cgRefund->saleRefundId ?? 0;
  628. $saleRefund = RefundOrderClass::getById($saleRefundId, true);
  629. if (!empty($saleRefund)) {
  630. $saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
  631. $saleRefund->save();
  632. }
  633. }
  634. //$text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  635. } elseif ($refund_status == 'REFUNDCLOSE') {
  636. $text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  637. } else {
  638. $text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  639. }
  640. $transaction->commit();
  641. if (!empty($text)) {
  642. noticeUtil::push($text, '15280215347');
  643. }
  644. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  645. } catch (\Exception $e) {
  646. $transaction->rollBack();
  647. Yii::error("失败原因:" . $e->getMessage());
  648. }
  649. }
  650. //采购后支付宝异步通知
  651. public function actionCgAliCallback()
  652. {
  653. header("Content-type: text/html; charset=utf-8");
  654. $aliWap = Yii::getAlias("@vendor/alipayWap");
  655. //商户订单号
  656. $orderSn = $_POST['out_trade_no'];
  657. // $aliPId = '2017041906821571';
  658. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8d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kiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  663. $config = [
  664. //应用ID,您的APP_ID
  665. 'app_id' => $aliPId,
  666. //商户私钥,您的原始格式RSA私钥
  667. 'merchant_private_key' => $aliKey,
  668. //异步通知地址
  669. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  670. //同步跳转
  671. 'return_url' => "",
  672. //编码格式
  673. 'charset' => "UTF-8",
  674. //签名方式
  675. 'sign_type' => "RSA2",
  676. //支付宝网关
  677. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  678. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  679. 'alipay_public_key' => $aliPublicKey,
  680. ];
  681. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  682. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  683. $arr = $_POST;
  684. $aliService = new \AlipayTradeService($config);
  685. $aliService->writeLog(var_export($_POST, true));
  686. $result = $aliService->check($arr);
  687. Yii::info('check:' . $result);
  688. if ($result == false) {
  689. //请不要修改
  690. echo "fail";
  691. util::end();
  692. }
  693. //验证成功后续
  694. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  695. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  696. $totalFee = $_POST['total_amount'] ?? '';
  697. $appId = $_POST['app_id'] ?? '';
  698. $attach = $_POST['passback_params'] ?? '';
  699. $attach = urldecode($attach);
  700. //接收流水类型、代金劵
  701. parse_str($attach);
  702. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  703. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  704. $RequestBuilder->setTradeNo($tradeNo);
  705. //$queryResult = $aliService->Query($RequestBuilder);
  706. //$aliId = $queryResult->buyer_user_id;
  707. //买家的支付宝帐号,不完整,带*号
  708. //$aliAccount = $queryResult->buyer_logon_id;
  709. if ($config['app_id'] != $appId) {
  710. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  711. util::end();
  712. }
  713. $connection = Yii::$app->db;
  714. $transaction = $connection->beginTransaction();
  715. try {
  716. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  717. $aliPay = dict::getDict('payWay', 'alipay');
  718. //支付成功后续流程
  719. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  720. $transaction->commit();
  721. //请不要修改
  722. echo "success";
  723. //解决重复通知
  724. $cacheKey = 'pay_success_notice_' . $orderSn;
  725. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  726. if (!empty($has)) {
  727. Yii::$app->end();
  728. }
  729. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  730. //零售采购通知
  731. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  732. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  733. if (!empty($cg) && $cg->payStatus == 1) {
  734. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  735. if ($cg->transType != 5 && $cg->transType != 4) {
  736. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  737. $customId = $cg->customId ?? 0;
  738. $current = date("Y_m_d");
  739. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  740. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  741. }
  742. } else {
  743. if (isset($cg->sendType) && $cg->sendType == 4) {
  744. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  745. $customId = $cg->customId ?? 0;
  746. $current = date("Y_m_d");
  747. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  748. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  749. }
  750. }
  751. //微信通知
  752. $saleId = $cg->saleId ?? 0;
  753. $order = OrderClass::getById($saleId, true);
  754. if (!empty($order)) {
  755. //订单生成时唤起在线打印
  756. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  757. //有几个地方要同步去修改
  758. if (getenv('YII_ENV') == 'production') {
  759. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  760. $mallOrderNoPrint = [10536, 44282, 26374];
  761. } else {
  762. $mallOrderNoPrint = [];
  763. }
  764. if (in_array($order->mainId, $mallOrderNoPrint)) {
  765. } else {
  766. OrderClass::onlinePrint($order);
  767. $order->printNum += 1;
  768. $order->save();
  769. }
  770. }
  771. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  772. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  773. ShopExtClass::ghsGatheringReport($order);
  774. }
  775. $cgShopId = $cg->shopId ?? 0;
  776. $cgShop = ShopClass::getById($cgShopId, true);
  777. if (!empty($cgShop)) {
  778. NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  779. }
  780. $shopId = $order->shopId ?? 0;
  781. $shop = ShopClass::getById($shopId, true);
  782. if (!empty($shop)) {
  783. //花店采购供货商端微信收到通知
  784. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  785. $noticeText = json_encode(['orderId' => $saleId]);
  786. $noticeKey = "hdCgNoticeGhs";
  787. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  788. GhsNotifyClass::newOrderNotify($saleId);
  789. //向供货商端APP发通知
  790. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  791. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  792. // $push->ghsOrderMessage($shop, $cgShop, $order);
  793. }
  794. //花店采购供货商端APP收到通知
  795. //NoticeClass::ghsNewOrderNotice($order);
  796. }
  797. }
  798. }
  799. }
  800. } catch (\Exception $e) {
  801. $transaction->rollBack();
  802. Yii::error("失败原因:" . $e->getMessage());
  803. }
  804. }
  805. //支付宝异步通知
  806. public function actionAliCallback()
  807. {
  808. header("Content-type: text/html; charset=utf-8");
  809. $aliWap = Yii::getAlias("@vendor/alipayWap");
  810. //商户订单号
  811. $orderSn = $_POST['out_trade_no'];
  812. // $aliPId = '2017041906821571';
  813. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88QgqtdmRNNA1QM3HESLJ8bu5pZhwW5/HaW8dOBKWRRKsHBnlUbPrXV4FcFDeLm0fPfd+iZ/2AaZ1+ix962f3BpYIiq7+f9zaMRazfnw9L8x31pByyMktLs12EkoQ0dHsMxxUzzKAOiiPnvCn8Pv+Jb2qej8GXgCjefutCVNMWGsdwJtMVXEbpdmMa48Wvw+0In5ZS/UG39YAreFzgDqI9jWHE1ZhkGmB1+8hKpeIlEeVGAeYVveUgssMORdA/YY8SWHk26KSIFX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UcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  818. $config = [
  819. //应用ID,您的APP_ID
  820. 'app_id' => $aliPId,
  821. //商户私钥,您的原始格式RSA私钥
  822. 'merchant_private_key' => $aliKey,
  823. //异步通知地址
  824. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  825. //同步跳转
  826. 'return_url' => "",
  827. //编码格式
  828. 'charset' => "UTF-8",
  829. //签名方式
  830. 'sign_type' => "RSA2",
  831. //支付宝网关
  832. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  833. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  834. 'alipay_public_key' => $aliPublicKey,
  835. ];
  836. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  837. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  838. $arr = $_POST;
  839. $aliService = new \AlipayTradeService($config);
  840. $aliService->writeLog(var_export($_POST, true));
  841. $result = $aliService->check($arr);
  842. Yii::info('check:' . $result);
  843. if ($result == false) {
  844. //请不要修改
  845. echo "fail";
  846. util::end();
  847. }
  848. //验证成功后续
  849. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  850. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  851. $totalFee = $_POST['total_amount'] ?? '';
  852. $appId = $_POST['app_id'] ?? '';
  853. $attach = $_POST['passback_params'] ?? '';
  854. $attach = urldecode($attach);
  855. //接收流水类型、代金劵
  856. parse_str($attach);
  857. //流水类型
  858. $capitalType = isset($capitalType) ? $capitalType : null;
  859. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  860. $RequestBuilder->setTradeNo($tradeNo);
  861. //$queryResult = $aliService->Query($RequestBuilder);
  862. //$aliId = $queryResult->buyer_user_id;
  863. //买家的支付宝帐号,不完整,带*号
  864. //$aliAccount = $queryResult->buyer_logon_id;
  865. if (isset($capitalType) == false) {
  866. Yii::warning('capitalType empty, orderSn:' . $orderSn);
  867. util::end();
  868. }
  869. if ($config['app_id'] != $appId) {
  870. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  871. util::end();
  872. }
  873. $connection = Yii::$app->db;
  874. $transaction = $connection->beginTransaction();
  875. try {
  876. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  877. $aliPay = dict::getDict('payWay', 'alipay');
  878. //支付成功后续流程
  879. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  880. $transaction->commit();
  881. }
  882. //请不要修改
  883. echo "success";
  884. } catch (\Exception $e) {
  885. $transaction->rollBack();
  886. Yii::error("失败原因:" . $e->getMessage());
  887. }
  888. }
  889. }