NoticeController.php 48 KB

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