6
0
Fork 0
jiqu-library-server/app/Console/Commands/OrderProfitCheck.php

70 lines
1.9 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Order;
use App\Models\OrderProfit;
use App\Services\DistributeService;
use App\Services\Payment\WxpayService;
use Illuminate\Console\Command;
class OrderProfitCheck extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'order-profit:check';
/**
* The console command description.
*
* @var string
*/
protected $description = '检查提成支付结果';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
OrderProfit::where('status', 0)->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;
}
}