redis-queue 消息里面调用think-orm save方法update方法都报错

yulinzhihou

问题描述

webman redis-queue 消息里面调用think-orm出现更新数据时save方法update方法都报错
这里详细描述问题
"workerman/webman-framework": "^1.5.0",
webman/think-orm": "^1.1",
"webman/redis-queue": "^1.2",
"w7corp/easywechat": "^6.7",

程序代码

 // 第三重验证
                if ($order['order_sn'] == $data['order_sn'] && $user['id'] == $order['user_id']) {
                    // 查询订单验证是否为支付
                    $app = new Application(config('wxpay'));
                    $response = $app->getClient()->get("v3/pay/transactions/out-trade-no/{$data['order_sn']}", [
                        'query'=>[
                            'mchid' =>  $app->getMerchant()->getMerchantId()
                        ]
                    ]);

//                    {
//                        "amount": {
//                        "currency": "CNY",
//                        "payer_currency": "CNY",
//                        "payer_total": 3,
//                        "total": 3
//                      },
//                      "appid": "wx6fb*****9",
//                      "attach": "",
//                      "bank_type": "OTHERS",
//                      "mchid": "160****4",
//                      "out_trade_no": "GS202310***2459799",
//                      "payer": {
//                                            "openid": "oCsvH*****5Moxrjy-ag"
//                      },
//                      "promotion_detail": {
//
//                                        },
//                      "success_time": "2023-10-26T21:12:52+08:00",
//                      "trade_state": "SUCCESS",
//                      "trade_state_desc": "支付成功",
//                      "trade_type": "JSAPI",
//                      "transaction_id": "4200002******01424672"
//                    }
//                    Cache::set('query_order',$response->toArray(),600);
                    // 第四重验证,查询数据订单是否真实
                    $payOrder = $response->toArray();
                    if (!isset($payOrder['transaction_id'])) {
                        throw new \Exception('订单查询失败。'.json_encode($payOrder));
                    }
                    // 真正的逻辑
                    $orderData = [
                        'package'           => $payOrder,
                        'transaction_id'    => $payOrder['transaction_id'],
                        'pay_type'          => $payOrder['bank_type'],
                        'status'            => 1
                    ];
                    // 报错这下面的代码,用 save($orderData) 以及 update($orderData) 等方法都尝试了,都报错
                    $order = Order::where('order_sn',$payOrder['out_trade_no'])->find();
                    $order->package = $payOrder;
                    $order->transaction_id = $payOrder['transaction_id'];
                    $order->pay_type = $payOrder['bank_type'];
                    $order->status = 1;
                    $result = $order->save();

报错信息

#0 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/Builder.php(81): {closure}()
#1 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/builder/Mysql.php(263): think\db\Builder->parseData()
#2 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/PDOConnection.php(1164): think\db\builder\Mysql->update()
#3 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/BaseQuery.php(1260): think\db\PDOConnection->update()
#4 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/Model.php(673): think\db\BaseQuery->update()
#5 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/PDOConnection.php(1521): think\Model->think\{closure}()
#6 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/concern/Transaction.php(47): think\db\PDOConnection->transaction()
#7 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/Model.php(665): think\db\BaseQuery->transaction()
#8 /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/Model.php(564): think\Model->updateData()
#9 /www/wwwroot/脱敏标志/app/queue/redis/WeChatPay.php(157): think\Model->save()
#10 /www/wwwroot/脱敏标志/vendor/workerman/redis-queue/src/Client.php(221): app\queue\redis\WeChatPay->consume()
#11 /www/wwwroot/脱敏标志/vendor/workerman/redis/src/Client.php(421): Workerman\RedisQueue\Client->Workerman\RedisQueue\{closure}()
#12 /www/wwwroot/脱敏标志/vendor/workerman/workerman/Connection/TcpConnection.php(646): Workerman\Redis\Client->Workerman\Redis\{closure}()
#13 /www/wwwroot/脱敏标志/vendor/workerman/workerman/Events/Select.php(311): Workerman\Connection\TcpConnection->baseRead()
#14 /www/wwwroot/脱敏标志/vendor/workerman/workerman/Worker.php(1635): Workerman\Events\Select->loop()
#15 /www/wwwroot/脱敏标志/vendor/workerman/workerman/Worker.php(1426): Workerman\Worker::forkOneWorkerForLinux()
#16 /www/wwwroot/脱敏标志/vendor/workerman/workerman/Worker.php(1400): Workerman\Worker::forkWorkersForLinux()
#17 /www/wwwroot/脱敏标志/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#18 /www/wwwroot/脱敏标志/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\Worker::runAll()
#19 /www/wwwroot/脱敏标志/start.php(4): support\App::run()
#20 {main}#20 {main}ErrorException: Undefined array key 0 in /www/wwwroot/脱敏标志/vendor/topthink/think-orm/src/db/Builder.php:81
Stack trace

截图报错信息里报错文件相关代码

引用关系都没有问题,类名以及命名空间都是没有问题的。

561 2 0
2个回答

yulinzhihou

截图
截图
截图

  • yulinzhihou 2023-10-26

    查询写缓存是可以查询到的,但凡调用save方法,就提示不让更新?消息队列里面不支执行orm更新?只能查询 ?好像我用create方法也不行。

damao
$order->package = $payOrder;
$order->save();

这句代码有问题,$payOrder是数组,php数组无法直接存入数据库,一般是转换为json字符串再存入

$order->package = json_encode($payOrder);
$order->save();
  • yulinzhihou 2023-10-27

    好的。应该是这个问题,看来还是得仔细检查。现在想想,其实报错已经很明显在告诉是数据异常了。

  • yulinzhihou 2023-10-27

    感谢感谢

年代过于久远,无法发表回答
×
🔝