HdOrderController.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace console\controllers;
  3. use bizHd\order\classes\OrderClass;
  4. use bizHd\order\models\Order;
  5. use common\components\dict;
  6. use common\components\noticeUtil;
  7. use common\components\util;
  8. use yii\console\Controller;
  9. use Yii;
  10. use bizHd\wx\classes\WxOpenClass;
  11. class HdOrderController extends Controller
  12. {
  13. //查询散客的订单是否有付款 ssh 20221231
  14. public function actionSelect()
  15. {
  16. util::stop();
  17. $query = new \yii\db\Query();
  18. $query->from(Order::tableName());
  19. $now = time();
  20. $current = bcsub($now, 100);
  21. $time = date("Y-m-d H:i:s", $current);
  22. $query->where(['status' => 1])->andWhere(['<=', 'addTime', $time]);
  23. $query->orderBy('addTime ASC');
  24. foreach ($query->batch() as $batchOrder) {
  25. foreach ($batchOrder as $order) {
  26. $connection = Yii::$app->db;
  27. $transaction = $connection->beginTransaction();
  28. $id = $order['id'] ?? 0;
  29. $orderSn = $order['orderSn'] ?? '';
  30. try {
  31. $order = OrderClass::getById($id, true);
  32. $orderSn = $order->orderSn ?? '';
  33. $totalFee = $order->mainPay ?? 0;
  34. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  35. //查询微信是否付款成功
  36. $payWay = dict::getDict('payWay', 'wxPay');
  37. $wx = Yii::getAlias("@vendor/wxPayApi_v3.0.10");
  38. require_once($wx . '/lib/WxPay.Api.php');
  39. require_once($wx . '/example/WxPay.MicroPay.php');
  40. //获取微信商户号等信息
  41. $sjExtend = WxOpenClass::getMallWxInfo();
  42. $microPay = new \MicroPay();
  43. $payReturn = $microPay->query($orderSn, $sjExtend);
  44. if ($payReturn["return_code"] == "SUCCESS" && $payReturn["result_code"] == "SUCCESS") {
  45. if ($payReturn["trade_state"] == "SUCCESS") {
  46. // //支付成功
  47. // $transactionId = $payReturn['transaction_id'] ?? '';
  48. // $order->onlinePay = dict::getDict('onlinePay', 'yes');
  49. // $order->save();
  50. // $attach = '';
  51. // payUtil::thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  52. //
  53. // $transaction->commit();
  54. //
  55. // //打印小票和语音播报
  56. // $newOrder = OrderClass::getById($id, true);
  57. // OrderClass::onlinePrint($newOrder);
  58. // ShopExtClass::hdGatheringReport($newOrder);
  59. //
  60. // $shopId = $newOrder->shopId ?? 0;
  61. // $shop = ShopClass::getById($shopId, true);
  62. // WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  63. noticeUtil::push("订单号{$orderSn}已付款,但还是待付款状态", '15280215347');
  64. }
  65. }
  66. //noticeUtil::push("订单号{$orderSn}没有付款", '15280215347');
  67. } catch (\Exception $e) {
  68. $transaction->rollBack();
  69. $msg = $e->getMessage();
  70. noticeUtil::push("查询订单是否付款出错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  71. }
  72. }
  73. }
  74. }
  75. }