NoticeController.php 52 KB

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