| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Console\Commands;
- use App\Services\OwnerService;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class CreateOwnerBillReport extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'createOwnerBillReport';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'create owner bill report';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 1号生成账单确认,确认金额由人工填写
- *
- * @return void
- */
- public function handle()
- {
- $year = (int)date('Y');
- $month = (int)date('m');
- if ($month == 1){
- $year--;
- $lastMonth = '12';
- }else $lastMonth = ($month-1) < 10 ? "0".($month-1) : ($month-1);
- $bills = DB::select(DB::raw("select owner_id,SUM(work_fee)+SUM(logistic_fee) as total from owner_fee_details where worked_at like ? GROUP BY owner_id"),[$year."-".$lastMonth."%"]);
- $chunks = array_chunk($bills,50);
- foreach ($chunks as $bills){
- $date = date('Y-m-d H:i:s');
- $createOwnerBillReport = [];
- foreach ($bills as $bill){
- $createOwnerBillReport[] = [
- "owner_id" => $bill->owner_id, //项目ID
- "counting_month" => $year."-".$lastMonth."-01", //结算月
- "initial_fee" => $bill->total, //原始账单金额
- "created_at" => $date,
- ];
- }
- DB::table("owner_bill_reports")->insert($createOwnerBillReport);
- }
- }
- }
|