NoticeController.php 49 KB

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