NoticeController.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. <?php
  2. namespace hd\controllers;
  3. use biz\common\classes\GhsNotifyClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\custom\classes\CustomRechargeClass;
  7. use bizGhs\express\classes\GhsDeliveryOrderClass;
  8. use bizGhs\order\classes\OrderClearClass;
  9. use bizGhs\order\classes\RefundOrderClass;
  10. use bizHd\cg\classes\CgRefundClass;
  11. use bizHd\ghs\classes\GhsClass;
  12. use bizHd\notice\classes\NoticeClass;
  13. use bizHd\purchase\classes\PurchaseClass;
  14. use bizHd\purchase\classes\PurchaseClearClass;
  15. use bizHd\wx\classes\WxOpenClass;
  16. use common\components\dict;
  17. use common\components\noticeUtil;
  18. use common\components\payUtil;
  19. use Yii;
  20. use common\components\util;
  21. use biz\wx\classes\WxMessageClass;
  22. use bizGhs\order\classes\OrderClass;
  23. use biz\shop\classes\ShopExtClass;
  24. use common\components\lakala\Lakala;
  25. use common\components\push;
  26. class NoticeController extends PublicController
  27. {
  28. public $categoryList;
  29. //收银台的回调通知 ssh 20231229
  30. public function actionCashPayCallback()
  31. {
  32. header("Content-type: text/html; charset=utf-8");
  33. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  34. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  35. if (empty($postStr)) {
  36. util::end();
  37. }
  38. $headers = Yii::$app->getRequest()->getHeaders();
  39. $Authorization = $headers->get('Authorization');
  40. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  41. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  42. $params = [
  43. 'appid' => 'OP00002119',
  44. 'serial_no' => '018b08cfddbd',
  45. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  46. 'lklCertificatePath' => $lklCertificatePath,
  47. ];
  48. $laResource = new Lakala($params);
  49. $return = $laResource->signatureVerification($Authorization, $postStr);
  50. $postData = json_decode($postStr, true);
  51. $orderSn = $postData['out_order_no'] ?? '';
  52. $merchant_no = $postData['merchant_no'] ?? '';
  53. $orderTradeInfo = $postData['order_trade_info'] ?? [];
  54. $payMode = $orderTradeInfo['pay_mode'] ?? null;
  55. if (empty($payMode)) {
  56. noticeUtil::push('收银台支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
  57. util::end();
  58. }
  59. $trade_amount = $orderTradeInfo['trade_amount'] ?? 0;
  60. $totalFee = $trade_amount / 100;
  61. if ($totalFee <= 0) {
  62. noticeUtil::push('收银台支付回调验证失败了,金额错误,请注意,orderSn:' . $orderSn, '15280215347');
  63. util::end();
  64. }
  65. $transactionId = $orderTradeInfo['trade_no'] ?? 0;
  66. if ($return == false) {
  67. noticeUtil::push('收银台支付回调验证失败了,请注意,orderSn:' . $orderSn, '15280215347');
  68. util::end();
  69. }
  70. $orderStatus = $postData['order_status'];
  71. $tradeType = $orderTradeInfo['trade_type'] ?? '';
  72. if ($tradeType != 'PAY') {
  73. noticeUtil::push('收银台支付回调验证失败了,不是消费的回调,orderSn:' . $orderSn, '15280215347');
  74. util::end();
  75. }
  76. //接收流水类型、代金劵
  77. $remarkString = $orderTradeInfo['trade_remark'] ?? '';
  78. $remarkData = json_decode($remarkString, true);
  79. //流水类型
  80. $capitalType = $remarkData['capitalType'] ?? null;
  81. if (!isset($capitalType)) {
  82. noticeUtil::push('支付回调失败了,没有找到capitalType,orderSn:' . $orderSn . ' remark:' . $remarkString, '15280215347');
  83. util::end();
  84. }
  85. $connection = Yii::$app->db;
  86. $transaction = $connection->beginTransaction();
  87. try {
  88. if ($orderStatus == 2) {
  89. $payWayType = null;
  90. if ($payMode == 'ALIPAY') {
  91. $payWayType = dict::getDict('payWay', 'alipay');
  92. }
  93. if ($payMode == 'WECHAT') {
  94. $payWayType = dict::getDict('payWay', 'wxPay');
  95. }
  96. if (isset($payWayType) == false) {
  97. noticeUtil::push('收银台支付回调验证失败了,没有找到支付方式,orderSn:' . $orderSn, '15280215347');
  98. util::end();
  99. }
  100. $attach = 'merchant_no=' . $merchant_no;
  101. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  102. $transaction->commit();
  103. }
  104. //请不要修改
  105. echo "SUCCESS";
  106. //解决重复通知
  107. $cacheKey = 'pay_success_notice_' . $orderSn;
  108. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  109. if (!empty($has)) {
  110. Yii::$app->end();
  111. }
  112. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  113. //客户向供货商充值然后进行清账,关键词 custom_recharge_ghs_clear_action
  114. if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
  115. $customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
  116. $customId = $customRecharge->customId ?? 0;
  117. $ghsId = $customRecharge->ghsId ?? 0;
  118. $ghs = GhsClass::getLockById($ghsId);
  119. $ghsShopId = $ghs->shopId ?? 0;
  120. $custom = CustomClass::getLockById($customId);
  121. $shop = ShopClass::getById($ghsShopId, true);
  122. OrderClearClass::useBalanceClear($custom, $ghs, $shop, null);
  123. //充值销账通知
  124. WxMessageClass::customRechargeClearInform($shop, $customRecharge);
  125. }
  126. //零售线上结账通知
  127. if ($capitalType == dict::getDict('capitalType', 'hdPurchaseClear', 'id')) {
  128. $clearInfo = PurchaseClearClass::getByCondition(['orderSn' => $orderSn], true);
  129. $customId = $clearInfo->customId ?? 0;
  130. $ghsShopId = $clearInfo->ghsShopId ?? 0;
  131. $ghsShop = ShopClass::getById($ghsShopId, true);
  132. $custom = CustomClass::getById($customId, true);
  133. if (!empty($custom) && !empty($ghsShop)) {
  134. WxMessageClass::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  135. }
  136. }
  137. //零售采购通知
  138. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  139. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  140. $saleId = $cg->saleId ?? 0;
  141. $order = OrderClass::getById($saleId, true);
  142. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  143. GhsDeliveryOrderClass::payAfter($order);
  144. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  145. if (!empty($cg) && !empty($order)) {
  146. if (isset($cg->book) && $cg->book == 0) {
  147. $ghsShopId = $order->shopId ?? 0;
  148. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  149. if ($ext->orderFlow == 0) {
  150. PurchaseClass::confirmTake($cg);
  151. }
  152. }
  153. }
  154. //更新最后下单时间
  155. $customId = $order->customId ?? 0;
  156. $custom = CustomClass::getById($customId, true);
  157. $date = date("Y-m-d H:i:s");
  158. if (!empty($custom)) {
  159. $custom->recentExpend = $date;
  160. $custom->save();
  161. }
  162. $ghsId = $order->ghsId ?? 0;
  163. $ghs = GhsClass::getById($ghsId, true);
  164. if (!empty($ghs)) {
  165. $ghs->recentExpend = $date;
  166. $ghs->save();
  167. }
  168. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  169. if ($cg->transType != 5 && $cg->transType != 4) {
  170. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  171. $customId = $cg->customId ?? 0;
  172. $current = date("Y_m_d");
  173. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  174. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  175. }
  176. } else {
  177. if (isset($cg->sendType) && $cg->sendType == 4) {
  178. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  179. $customId = $cg->customId ?? 0;
  180. $current = date("Y_m_d");
  181. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  182. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  183. }
  184. }
  185. if (!empty($cg) && $cg->payStatus == 1) {
  186. //微信通知
  187. if (!empty($order)) {
  188. //订单生成时唤起在线打印
  189. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  190. //有几个地方要同步去修改
  191. if (getenv('YII_ENV') == 'production') {
  192. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  193. $mallOrderNoPrint = [10536, 44282, 26374];
  194. } else {
  195. $mallOrderNoPrint = [];
  196. }
  197. if (in_array($order->mainId, $mallOrderNoPrint)) {
  198. } else {
  199. OrderClass::onlinePrint($order);
  200. $order->printNum += 1;
  201. $order->save();
  202. if (getenv('YII_ENV') == 'production') {
  203. //福州我要花、花路鲜花批发、小齐鲜花、花镜打二次小票,有多处要修改搜索关键词tow_print
  204. $needTwoPrint = [7538, 36707,76796];
  205. } else {
  206. $needTwoPrint = [644];
  207. }
  208. if (in_array($order->mainId, $needTwoPrint)) {
  209. if ($order->mainId == 7538) {
  210. OrderClass::onlinePrint($order, 0);
  211. } else {
  212. OrderClass::onlinePrint($order);
  213. }
  214. $order->printNum += 1;
  215. $order->save();
  216. }
  217. }
  218. }
  219. $cgShopId = $cg->shopId ?? 0;
  220. $cgShop = ShopClass::getById($cgShopId, true);
  221. if (!empty($cgShop)) {
  222. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  223. }
  224. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  225. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  226. ShopExtClass::ghsGatheringReport($order);
  227. }
  228. $shopId = $order->shopId ?? 0;
  229. $shop = ShopClass::getById($shopId, true);
  230. if (!empty($shop)) {
  231. GhsNotifyClass::newOrderNotify($saleId);
  232. }
  233. }
  234. }
  235. }
  236. } 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::customHasClearToGhsInform($ghsShop, $clearInfo, $custom);
  330. }
  331. }
  332. //零售采购成功后续流程
  333. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  334. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  335. $saleId = $cg->saleId ?? 0;
  336. $order = OrderClass::getById($saleId, true);
  337. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  338. GhsDeliveryOrderClass::payAfter($order);
  339. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔、镜中花卉,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  340. if (!empty($cg) && !empty($order)) {
  341. if (isset($cg->book) && $cg->book == 0) {
  342. $ghsShopId = $order->shopId ?? 0;
  343. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  344. if ($ext->orderFlow == 0) {
  345. PurchaseClass::confirmTake($cg);
  346. }
  347. }
  348. }
  349. //更新最后下单时间
  350. $customId = $order->customId ?? 0;
  351. $custom = CustomClass::getById($customId, true);
  352. $date = date("Y-m-d H:i:s");
  353. if (!empty($custom)) {
  354. $custom->recentExpend = $date;
  355. $custom->save();
  356. }
  357. $ghsId = $order->ghsId ?? 0;
  358. $ghs = GhsClass::getById($ghsId, true);
  359. if (!empty($ghs)) {
  360. $ghs->recentExpend = $date;
  361. $ghs->save();
  362. }
  363. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  364. if ($cg->transType != 5 && $cg->transType != 4) {
  365. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  366. $customId = $cg->customId ?? 0;
  367. $current = date("Y_m_d");
  368. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  369. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  370. }
  371. } else {
  372. if (isset($cg->sendType) && $cg->sendType == 4) {
  373. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  374. $customId = $cg->customId ?? 0;
  375. $current = date("Y_m_d");
  376. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  377. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  378. }
  379. }
  380. if (!empty($cg) && $cg->payStatus == 1) {
  381. //微信通知
  382. if (!empty($order)) {
  383. //订单生成时唤起在线打印
  384. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  385. //有几个地方要同步去修改
  386. if (getenv('YII_ENV') == 'production') {
  387. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  388. $mallOrderNoPrint = [10536, 44282, 26374];
  389. } else {
  390. $mallOrderNoPrint = [];
  391. }
  392. if (in_array($order->mainId, $mallOrderNoPrint)) {
  393. } else {
  394. $shopId = $order->shopId ?? 0;
  395. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  396. OrderClass::onlinePrint($order);
  397. if (isset($ext->printSn) && !empty($ext->printSn)) {
  398. $order->printNum += 1;
  399. $order->save();
  400. }
  401. if (getenv('YII_ENV') == 'production') {
  402. //福州我要花、花路鲜花批发、花镜打二次小票,有多处要修改搜索关键词tow_print
  403. $needTwoPrint = [7538, 36707,76796];
  404. } else {
  405. $needTwoPrint = [];
  406. }
  407. if (in_array($order->mainId, $needTwoPrint)) {
  408. if ($order->mainId == 7538) {
  409. OrderClass::onlinePrint($order, 0);
  410. } else {
  411. OrderClass::onlinePrint($order);
  412. }
  413. if (isset($ext->printSn) && !empty($ext->printSn)) {
  414. $order->printNum += 1;
  415. $order->save();
  416. }
  417. }
  418. }
  419. }
  420. $cgShopId = $cg->shopId ?? 0;
  421. $cgShop = ShopClass::getById($cgShopId, true);
  422. if (!empty($cgShop)) {
  423. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  424. }
  425. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  426. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  427. ShopExtClass::ghsGatheringReport($order);
  428. }
  429. $shopId = $order->shopId ?? 0;
  430. $shop = ShopClass::getById($shopId, true);
  431. if (!empty($shop)) {
  432. //花店采购供货商端微信收到通知
  433. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  434. // $noticeText = json_encode(['orderId' => $saleId]);
  435. // $noticeKey = "hdCgNoticeGhs";
  436. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  437. GhsNotifyClass::newOrderNotify($saleId);
  438. //向供货商APP发通知
  439. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  440. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  441. // $push->ghsOrderMessage($shop, $cgShop, $order);
  442. }
  443. //花店采购供货商端APP收到通知
  444. //NoticeClass::ghsNewOrderNotice($order);
  445. }
  446. }
  447. }
  448. //散客下单买花,回调通知后,播报声音提示,这个方法本来不能写在这边要写在app-mall里的
  449. if ($capitalType == dict::getDict('capitalType', 'xhOrder', 'id')) {
  450. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  451. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  452. if (empty($has)) {
  453. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  454. $newOrder = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  455. if ($newOrder->onlinePay == 2) {
  456. //语音播报
  457. ShopExtClass::hdGatheringReport($newOrder);
  458. }
  459. }
  460. }
  461. } catch (\Exception $e) {
  462. $transaction->rollBack();
  463. Yii::error("失败原因:" . $e->getMessage());
  464. }
  465. }
  466. //微信支付异步回调
  467. public function actionWxCallback()
  468. {
  469. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  470. if (empty($postStr)) {
  471. util::end();
  472. }
  473. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  474. if ($postObj->return_code != 'SUCCESS') {
  475. Yii::warning('return_code error:' . $postObj->return_code);
  476. util::end();
  477. }
  478. $orderSn = $postObj->out_trade_no;
  479. $total_fee = $postObj->total_fee;
  480. $totalFee = $total_fee / 100;
  481. $attach = $postObj->attach;
  482. $transactionId = $postObj->transaction_id ?? '';
  483. //接收流水类型、代金劵
  484. parse_str($attach);
  485. //流水类型
  486. $capitalType = isset($capitalType) ? $capitalType : null;
  487. if (isset($capitalType) == false) {
  488. Yii::warning('capitalType empty,orderSn:' . $orderSn);
  489. util::end();
  490. }
  491. $connection = Yii::$app->db;
  492. $transaction = $connection->beginTransaction();
  493. try {
  494. $wxPay = dict::getDict('payWay', 'wxPay');
  495. //支付成功后续流程
  496. payUtil::thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  497. $transaction->commit();
  498. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  499. //解决重复通知
  500. $cacheKey = 'pay_success_notice_' . $orderSn;
  501. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  502. if (!empty($has)) {
  503. Yii::$app->end();
  504. }
  505. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  506. //零售采购结账通知
  507. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  508. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  509. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  510. if ($cg->transType != 5 && $cg->transType != 4) {
  511. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  512. $customId = $cg->customId ?? 0;
  513. $current = date("Y_m_d");
  514. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  515. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  516. }
  517. } else {
  518. if (isset($cg->sendType) && $cg->sendType == 4) {
  519. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  520. $customId = $cg->customId ?? 0;
  521. $current = date("Y_m_d");
  522. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  523. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  524. }
  525. }
  526. if (!empty($cg) && $cg->payStatus == 1) {
  527. //微信通知
  528. $saleId = $cg->saleId ?? 0;
  529. $order = OrderClass::getById($saleId, true);
  530. if (!empty($order)) {
  531. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  532. GhsDeliveryOrderClass::payAfter($order);
  533. //订单生成时唤起在线打印
  534. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  535. //有几个地方要同步去修改
  536. if (getenv('YII_ENV') == 'production') {
  537. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  538. $mallOrderNoPrint = [10536, 44282, 26374];
  539. } else {
  540. $mallOrderNoPrint = [];
  541. }
  542. if (in_array($order->mainId, $mallOrderNoPrint)) {
  543. } else {
  544. OrderClass::onlinePrint($order);
  545. $order->printNum += 1;
  546. $order->save();
  547. }
  548. }
  549. $cgShopId = $cg->shopId ?? 0;
  550. $cgShop = ShopClass::getById($cgShopId, true);
  551. if (!empty($cgShop)) {
  552. //NoticeClass::cgSuccessMiniNotice($cgShop, $cg);
  553. }
  554. //如果是门店用手机开单,让客户扫码付款的,则也要语音提示
  555. if (isset($order->shopAdminId) && $order->shopAdminId > 0) {
  556. ShopExtClass::ghsGatheringReport($order);
  557. }
  558. $shopId = $order->shopId ?? 0;
  559. $shop = ShopClass::getById($shopId, true);
  560. if (!empty($shop)) {
  561. //花店采购供货商端微信收到通知
  562. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  563. // $noticeText = json_encode(['orderId' => $saleId]);
  564. // $noticeKey = "hdCgNoticeGhs";
  565. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  566. GhsNotifyClass::newOrderNotify($saleId);
  567. //向供货商端APP发通知
  568. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  569. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  570. // $push->ghsOrderMessage($shop, $cgShop, $order);
  571. }
  572. //花店采购供货商端APP收到通知
  573. //NoticeClass::ghsNewOrderNotice($order);
  574. }
  575. }
  576. }
  577. } catch (\Exception $e) {
  578. $transaction->rollBack();
  579. Yii::error("失败原因:" . $e->getMessage());
  580. }
  581. }
  582. //微信退款结果通知
  583. public function actionWxRefundCallback()
  584. {
  585. $postStr = file_get_contents('php://input');//接收微信服务器返回的xml消息体
  586. if (empty($postStr)) {
  587. util::end();
  588. }
  589. $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  590. if ($postObj->return_code != 'SUCCESS') {
  591. $msg = $postObj->return_msg ?? '';
  592. $text = '微信退款结果通知,报错了,报错内容:' . $msg;
  593. Yii::warning($text);
  594. noticeUtil::push($text, '15280215347');
  595. util::end();
  596. }
  597. //解密req_info
  598. $wx = WxOpenClass::getWxInfo();
  599. $req_info = $postObj->req_info ?? '';
  600. $key = $wx['wxPayKey'] ?? '';
  601. $xml = openssl_decrypt(base64_decode($req_info), 'AES-256-ECB', MD5($key), OPENSSL_RAW_DATA, '');
  602. $req_info_obj = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  603. $refund_status = $req_info_obj->refund_status ?? '';
  604. $orderSn = $req_info_obj->out_trade_no ?? '';
  605. $out_refund_no = $req_info_obj->out_refund_no ?? '';
  606. //订单总金额
  607. $total_fee = $req_info_obj->total_fee ?? 0.00;
  608. //申请退款金额
  609. //$refund_fee = $req_info_obj->refund_fee ?? 0.00;
  610. //退款金额
  611. $settlement_refund_fee = $req_info_obj->settlement_refund_fee ?? 0.00;
  612. $new_total_fee = bcdiv($total_fee, 100, 2);
  613. $new_total_fee = floatval($new_total_fee);
  614. $new_settlement_refund_fee = bcdiv($settlement_refund_fee, 100, 2);
  615. $new_settlement_refund_fee = floatval($new_settlement_refund_fee);
  616. $connection = Yii::$app->db;
  617. $transaction = $connection->beginTransaction();
  618. $text = '';
  619. try {
  620. if ($refund_status == 'SUCCESS') {
  621. $cgRefund = CgRefundClass::getByCondition(['orderSn' => $out_refund_no], true);
  622. if (!empty($cgRefund)) {
  623. $cgRefund->status = CgRefundClass::STATUS_COMPLETE;
  624. $cgRefund->save();
  625. $saleRefundId = $cgRefund->saleRefundId ?? 0;
  626. $saleRefund = RefundOrderClass::getById($saleRefundId, true);
  627. if (!empty($saleRefund)) {
  628. $saleRefund->status = RefundOrderClass::STATUS_COMPLETE;
  629. $saleRefund->save();
  630. }
  631. }
  632. //$text = "【退款成功】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  633. } elseif ($refund_status == 'REFUNDCLOSE') {
  634. $text = "【退款关闭】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  635. } else {
  636. $text = "【退款失败】退款单号:{$orderSn} {$out_refund_no} 订单金额:{$new_total_fee} 退款金额:{$new_settlement_refund_fee} ";
  637. }
  638. $transaction->commit();
  639. if (!empty($text)) {
  640. noticeUtil::push($text, '15280215347');
  641. }
  642. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  643. } catch (\Exception $e) {
  644. $transaction->rollBack();
  645. Yii::error("失败原因:" . $e->getMessage());
  646. }
  647. }
  648. //采购后支付宝异步通知
  649. public function actionCgAliCallback()
  650. {
  651. header("Content-type: text/html; charset=utf-8");
  652. $aliWap = Yii::getAlias("@vendor/alipayWap");
  653. //商户订单号
  654. $orderSn = $_POST['out_trade_no'];
  655. // $aliPId = '2017041906821571';
  656. // $aliKey = 'MIIEpAIBAAKCAQEAvbeu6o90L+0AilI+mbhuJJH0lUv7hWQCEC+XUc+cWlC9ulKC3cSVScVLJHpUc09aj6v/iD1p9iVfgMxjeADNVKiQC2RJyRshAjzyTq+2bTcODp619iV2y4qW8UM65VcP7Ide3P0uT5xC2ReW0HpkdHZgm4F+P7mh1VhGt9qOP3hjvoraAHhtGACvsGvy8H69HhSAG+CEmFt7f2tKNWJ8xEUvkfhDvys93PfTk4xMWj048hJE2r38+2mWI/Il5dFQHWXXTVl2x9yi7uhEEW42a+7s9Q3HgqEvZiQ2NI1FTeEAPLFBApiEsNLY/smaszwqqfWGAyTMvtQ6T4K96GcTLQIDAQABAoIBAHwYTj33n9RJfnT73x7F2KXrIsUVcmyKQh88Q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E5Fw==';
  660. $aliPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgEb9zdQQDva63DhksZHPZCDrRe2xvZcTRy9mEiWs/pUhCG0QABkuePUyvqTAKINiCEv2QJmdF8qt3hmTSXuME5bT4vghckSGUTp4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/9pusrj2t6FCyCkFeWbRDzKhplPQejaET2p5yplwSUpd1gqF+3srIn3erW5uAR6F0Z0NoCMzlo5TEXKWY2XMq97ubueE7Cgp8/c3dh5dkscAT2CCWwRq23aKozp+XMwIDAQAB';
  661. $config = [
  662. //应用ID,您的APP_ID
  663. 'app_id' => $aliPId,
  664. //商户私钥,您的原始格式RSA私钥
  665. 'merchant_private_key' => $aliKey,
  666. //异步通知地址
  667. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-async",
  668. //同步跳转
  669. 'return_url' => "",
  670. //编码格式
  671. 'charset' => "UTF-8",
  672. //签名方式
  673. 'sign_type' => "RSA2",
  674. //支付宝网关
  675. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  676. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  677. 'alipay_public_key' => $aliPublicKey,
  678. ];
  679. require_once($aliWap . '/wappay/service/AlipayTradeService.php');
  680. require_once($aliWap . '/wappay/buildermodel/AlipayTradeQueryContentBuilder.php');//查询接口
  681. $arr = $_POST;
  682. $aliService = new \AlipayTradeService($config);
  683. $aliService->writeLog(var_export($_POST, true));
  684. $result = $aliService->check($arr);
  685. Yii::info('check:' . $result);
  686. if ($result == false) {
  687. //请不要修改
  688. echo "fail";
  689. util::end();
  690. }
  691. //验证成功后续
  692. $tradeNo = $_POST['trade_no'] ?? '';//支付宝交易号
  693. $tradeStatus = $_POST['trade_status'] ?? '';//交易状态
  694. $totalFee = $_POST['total_amount'] ?? '';
  695. $appId = $_POST['app_id'] ?? '';
  696. $attach = $_POST['passback_params'] ?? '';
  697. $attach = urldecode($attach);
  698. //接收流水类型、代金劵
  699. parse_str($attach);
  700. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  701. $RequestBuilder = new \AlipayTradeQueryContentBuilder();
  702. $RequestBuilder->setTradeNo($tradeNo);
  703. //$queryResult = $aliService->Query($RequestBuilder);
  704. //$aliId = $queryResult->buyer_user_id;
  705. //买家的支付宝帐号,不完整,带*号
  706. //$aliAccount = $queryResult->buyer_logon_id;
  707. if ($config['app_id'] != $appId) {
  708. Yii::warning('app_id disagree, orderSn:' . $orderSn . ' config app_id:' . $config['app_id'] . ' appId:' . $appId);
  709. util::end();
  710. }
  711. $connection = Yii::$app->db;
  712. $transaction = $connection->beginTransaction();
  713. try {
  714. if ($tradeStatus == 'TRADE_FINISHED' || $tradeStatus == 'TRADE_SUCCESS') {
  715. $aliPay = dict::getDict('payWay', 'alipay');
  716. //支付成功后续流程
  717. payUtil::thirdPay($aliPay, $capitalType, $orderSn, $totalFee, $attach, $tradeNo);
  718. $transaction->commit();
  719. //请不要修改
  720. echo "success";
  721. //解决重复通知
  722. $cacheKey = 'pay_success_notice_' . $orderSn;
  723. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  724. if (!empty($has)) {
  725. Yii::$app->end();
  726. }
  727. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  728. //零售采购通知
  729. if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
  730. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  731. if (!empty($cg) && $cg->payStatus == 1) {
  732. if (isset($cg->localOrder) && $cg->localOrder == 1) {
  733. if ($cg->transType != 5 && $cg->transType != 4) {
  734. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  735. $customId = $cg->customId ?? 0;
  736. $current = date("Y_m_d");
  737. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  738. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  739. }
  740. } else {
  741. if (isset($cg->sendType) && $cg->sendType == 4) {
  742. //标记当天发快递方式已收一次包装费,岭南批发市场用的功能
  743. $customId = $cg->customId ?? 0;
  744. $current = date("Y_m_d");
  745. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  746. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  747. }
  748. }
  749. //微信通知
  750. $saleId = $cg->saleId ?? 0;
  751. $order = OrderClass::getById($saleId, true);
  752. if (!empty($order)) {
  753. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  754. GhsDeliveryOrderClass::payAfter($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+Jb2qej8GXgCj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p4CNzsT90Vfjk4wci+bpAqNnpUASDuqZLCzebTuOhxYtGVBqYzhp/CxcC/Mag3ISjUG6jRqyUi15R1e2ruq74sohLGnb4m3nnwRVwnNVAaUcVfV1J0Nb0/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. }