1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class StatementsFileDetail extends Model
- {
- protected $table = 'statements_file_detail';
- public $timestamps = false;
- protected static $unguarded = true;
- public static function saveData($data) {
- foreach($data as $item) {
- $model = self::query()->where('statements_id', $item['statements_id'])
- ->where('order_month', $item['order_month'])->where('project_name', $item['project_name'])->first();
- if(empty($model)) {
- $model = new self();
- }
- $model->enable = 1;
- $model->statements_id = $item['statements_id'];
- $model->project_name = $item['project_name'];
- $model->order_month = $item['order_month'];
- $model->order_amount = $item['order_amount'];
- $model->saler = $item['saler'];
- $model->handler = $item['handler'];
- $model->save();
- }
- }
- public static function updateData() {
- }
- public static function getDataBySearch($search) {
- $statementsFileDetailModel = self::query()->where('enable', 1);
- if(isset($search['order_month_start']) && !empty($search['order_month_start'])) {
- $statementsFileDetailModel->where('order_month', '>=', date('Y-m-01', strtotime($search['order_month_start'])));
- }
- if(isset($search['order_month_end']) && !empty($search['order_month_end'])) {
- $statementsFileDetailModel->where('order_month', '<=', date('Y-m-01', strtotime($search['order_month_end'])));
- }
- if(isset($search['project_name']) && !empty($search['project_name'])) {
- $statementsFileDetailModel->where('project_name', 'like', '%'.$search['project_name'].'%');
- }
- if(isset($search['statements_id']) && !empty($search['statements_id'])) {
- $statementsFileDetailModel->where('statements_id', $search['statements_id']);
- }
- if(isset($search['statements_id_list']) && !empty($search['statements_id_list'])) {
- $statementsFileDetailModel->whereIn('statements_id', $search['statements_id_list']);
- }
- return $statementsFileDetailModel;
- }
- }
|