updateOrCreate([ 'task_id' => $item['task_id'], 'month' => $item['month'], 'now_date' => $nowDate, ], $item); if(!$res) { \DB::rollBack(); return false; } } \DB::commit(); return true; } public static function getSearchQuery($search) { return self::query()->where('enable', 1) ->where(function($query) use($search) { if(isset($search['task_id']) && $search['task_id']) $query->where('task_id', $search['task_id']); if(isset($search['media_name']) && $search['media_name']) $query->where('media_name', $search['media_name']); if(isset($search['launch_platform']) && $search['launch_platform']) $query->where('launch_platform', $search['launch_platform']); if(isset($search['internet_celebrity_id']) && $search['internet_celebrity_id']) $query->where('internet_celebrity_id', $search['internet_celebrity_id']); if(isset($search['internet_celebrity_name']) && $search['internet_celebrity_name']) $query->where('internet_celebrity_name', 'like', $search['internet_celebrity_name'].'%'); if(isset($search['company']) && $search['company']) $query->where('company', 'like', '%'.$search['company'].'%'); if(isset($search['handler']) && $search['handler']) $query->where('handler', $search['handler']); if(isset($search['customer_name']) && $search['customer_name']) $query->where('customer_name', 'like', '%'.$search['customer_name'].'%'); if(isset($search['project_name']) && $search['project_name']) $query->where('project_name', $search['project_name']); if(isset($search['cost_company_name']) && $search['cost_company_name']) $query->where('cost_company_name', 'like', '%'.$search['cost_company_name'].'%'); if(isset($search['cost_owner']) && $search['cost_owner']) $query->where('cost_owner', $search['cost_owner']); if(isset($search['rebate_expense_receiving_unit']) && $search['rebate_expense_receiving_unit']) $query->where('rebate_expense_receiving_unit', $search['rebate_expense_receiving_unit']); if(isset($search['month']) && $search['month']) $query->where('month', '=', date('Y-m-01', strtotime($search['month']) ) ); if(!empty($search['mcn_name'])) $query->where('mcn_name', 'like', '%'.$search['mcn_name'].'%'); }); } }