NoticeController.php 50 KB

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