6
0
Fork 0

order-profit send

base
panliang 2022-09-19 17:43:13 +08:00
parent 406a3d17b5
commit 81ba6f420d
5 changed files with 67 additions and 24 deletions

View File

@ -79,7 +79,7 @@ class OrderProfitCommand extends Command
} }
// 没有待付款的提成记录 // 没有待付款的提成记录
Order::where(fn($q) => $q->whereHas('profits', fn($q) => $q->where('status', 2))->orWhereDoesntHave('profits')) Order::where(fn($q) => $q->whereHas('profits', fn($q) => $q->where('status', '!=', 2))->orWhereDoesntHave('profits'))
// 订单已完成 // 订单已完成
->where('status', Order::STATUS_COMPLETED) ->where('status', Order::STATUS_COMPLETED)
// 没有售后订单 // 没有售后订单

View File

@ -191,6 +191,7 @@ class DistributeService
$filtered->push($item); $filtered->push($item);
} }
} }
dd($filtered->toArray(), $money);
if ($money < 1) { if ($money < 1) {
throw new BizException('金额小于 1, 无法打款'); throw new BizException('金额小于 1, 无法打款');
} }

View File

@ -0,0 +1,34 @@
<?php
namespace Database\Factories;
use App\Models\Order;
use App\Models\OrderProfit;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class OrderProfitFactory extends Factory
{
protected $model = OrderProfit::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$order = Order::inRandomOrder()->first();
$user = User::inRandomOrder()->whereHas('agent')->first();
$agent = $user->agent;
return [
'order_id' => $order->id,
'from_user_id' => $order->user_id,
'user_id' => $user->id,
'role' => $agent->slug . '-' . $agent->sort,
'role_name' => $agent->name,
'growth_value' => 0,
'ratio' => 0,
'money' => $this->faker->randomFloat(2, 0, 1),
];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Database\Seeders;
use App\Models\OrderProfit;
use Illuminate\Database\Seeder;
class OrderProfitSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
OrderProfit::truncate();
OrderProfit::factory()->count(100)->create(['status' => 4]);
}
}

View File

@ -2,10 +2,11 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Agent; use App\Models\OrderProfit;
use App\Services\DistributeService;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase; use Tests\TestCase;
use Illuminate\Support\Str;
class ExampleTest extends TestCase class ExampleTest extends TestCase
{ {
@ -16,26 +17,13 @@ class ExampleTest extends TestCase
*/ */
public function test_example() public function test_example()
{ {
// 过滤掉 不是代理身份 的用户 $service = new DistributeService();
// 过滤掉 相同等级 的 后者 用户 try {
// 过滤掉等级 低于 上一个分钱 的用户 DB::beginTransaction();
$parents = [2, 3, 1, 5, 6, null]; $service->wechatTransfers(OrderProfit::whereIn('id', [1, 5])->get());
$filtered = []; DB::commit();
$last = null; } catch (\Exception $e) {
foreach($parents as $item) { DB::rollBack();
if (!$item) { }
continue;
}
if (in_array($item, $filtered)) {
continue;
}
if ($last && $item < $last) {
continue;
}
$last = $item;
array_push($filtered, $item);
}
dd($filtered);
} }
} }