where('money', 0)->update(['status' => 2]); $service = new WxpayService(); $service1 = new DistributeService(); $list = OrderProfit::where('status', 1)->get()->groupBy('order_id'); foreach ($list as $order_id => $profits) { $order = Order::findOrFail($order_id); $transaction_id = $order->out_trade_no; $sn = data_get($profits->first(), 'pay_no'); if ($transaction_id) { $result = $service->queryShare($transaction_id, $sn); $status = data_get($result, 'status'); if ($status == 'FINISHED') { // 修改订单分账状态 $attributes = ['share_sn' => $sn, 'status' => 'N']; $order->update([ 'wx_share' => $order->wx_share ? array_merge($order->wx_share, $attributes) : $attributes, 'profit_paid' => now(), ]); $service1->success($profits, $result); } } } return 0; } }