OwnerLogisticFeeDetailSeeder.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. use App\OwnerFeeDetail;
  3. use App\OwnerLogisticFeeDetail;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Seeder;
  6. class OwnerLogisticFeeDetailSeeder extends Seeder
  7. {
  8. /**
  9. * Run the database seeds.
  10. *
  11. * @return void
  12. */
  13. public function run()
  14. {
  15. // $ownerFeeDetails = OwnerFeeDetail::query()
  16. // ->with('items')
  17. // ->where('type', '发货')
  18. // ->where('outer_table_name', 'orders')
  19. // ->whereHas('logistic', function ($query) {
  20. // $query->where('type', '快递');
  21. // })
  22. // ->where('owner_id', [12])
  23. // ->where('worked_at', '>=', Carbon::parse('2021-05-30')->startOfDay())
  24. // ->where('worked_at', '<=', Carbon::parse('2021-05-31')->endOfDay())
  25. // ->get();
  26. // foreach ($ownerFeeDetails as $ownerFeeDetail) {
  27. // factory(\App\OwnerLogisticFeeDetail::class)->create([
  28. // 'owner_fee_detail_id' => $ownerFeeDetail->id,
  29. // 'logistic_bill' => $ownerFeeDetail->items->first()->logistic_bill??$ownerFeeDetail->logistic_bill,
  30. // 'logistic_id'=>$ownerFeeDetail->logistic_id,
  31. // 'province'=>$ownerFeeDetail->province
  32. // ]);
  33. // }
  34. // factory(\App\OwnerLogisticFeeDetail::class)->times(200)->create(
  35. // [
  36. // 'created_at' =>now()->subMonth()->startOfMonth()->addDays(1),
  37. // 'updated_at' => now()->subMonth()->startOfMonth()->addDays(2)
  38. // ]
  39. // );
  40. //
  41. // factory(\App\OwnerLogisticFeeDetail::class)->times(200)->create(
  42. // [
  43. // 'created_at' =>now()->subMonth()->startOfMonth()->addDays(2),
  44. // 'updated_at' => now()->subMonth()->startOfMonth()->addDays(3)
  45. // ]
  46. // );
  47. //
  48. // factory(\App\OwnerLogisticFeeDetail::class)->times(200)->create(
  49. // [
  50. // 'created_at' =>now()->subMonth()->startOfMonth()->addDays(3),
  51. // 'updated_at' => now()->subMonth()->startOfMonth()->addDays(4)
  52. // ]
  53. // );
  54. OwnerLogisticFeeDetail::query()->truncate();
  55. OwnerFeeDetail::query()->truncate();
  56. factory(OwnerLogisticFeeDetail::class)->times(200)->create();
  57. $details = OwnerLogisticFeeDetail::all();
  58. foreach ($details as $detail) {
  59. factory(OwnerFeeDetail::class)->create([
  60. 'type' => '发货',
  61. 'outer_table_name'=>'orders',
  62. 'logistic_id'=>$detail->logistic_id,
  63. 'owner_id'=>$detail->owner_id,
  64. 'worked_at'=>now()->subMonth()->startOfMonth()->addDays(random_int(1,28)) ->toDateTimeString(),
  65. ]);
  66. }
  67. }
  68. }