NoticeController.php 52 KB

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