BookSettlementTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Tests\ContentManage\Services\CpManage;
  3. use Illuminate\Support\Facades\DB;
  4. use Modules\Common\Support\Trace\TraceContext;
  5. use Modules\ContentManage\Services\CpManage\BookSettlement;
  6. use PHPUnit\Framework\TestCase;
  7. class BookSettlementTest extends \Tests\TestCase
  8. {
  9. private $bid = 10002;
  10. protected function setUp11(): void
  11. {
  12. parent::setUp(); // TODO: Change the autogenerated stub
  13. $startDate = '2023-01-23';
  14. $endDate = '2023-05-13';
  15. $date = $startDate;
  16. DB::table('cp_subscribe_statistic_data')
  17. ->where(['bid' => $this->bid])
  18. ->delete();
  19. while ($date <= $endDate) {
  20. $nextDate = date_add(date_create($date), date_interval_create_from_date_string('1 day'))->format('Y-m-d');
  21. DB::table('cp_subscribe_statistic_data')
  22. ->insert([
  23. 'bid' => $this->bid,
  24. 'calculate_date' => $nextDate,
  25. 'settlement_date' => $date,
  26. 'month' => date_create($date)->format('Y-m'),
  27. 'cp_name' => 'kanshu',
  28. 'yesterday_available_amount' => rand(1000 , 5000),
  29. 'yesterday_final_amount' => rand(100, 500),
  30. 'yesterday_total_coins' => rand(10000, 50000),
  31. 'book_settlement_type' => array_rand(['share', 'bottomline', 'buyout'])
  32. ]);
  33. $date = $nextDate;
  34. }
  35. }
  36. public function testRun()
  37. {
  38. $bid = 10002;
  39. $month = '2023-03';
  40. dump($pInfo = app(TraceContext::class)->getTraceInfo());
  41. $service = new BookSettlement($bid, $month);
  42. $service->traceContext = TraceContext::newFromParent($pInfo);
  43. dump($service->detail());
  44. }
  45. }