NoticeController.php 50 KB

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