新版订单消耗系统

StatementsFileDetail.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class StatementsFileDetail extends Model
  5. {
  6. protected $table = 'statements_file_detail';
  7. public $timestamps = false;
  8. protected static $unguarded = true;
  9. public static function saveData($data) {
  10. foreach($data as $item) {
  11. $model = self::query()->where('statements_id', $item['statements_id'])
  12. ->where('order_month', $item['order_month'])->where('project_name', $item['project_name'])->first();
  13. if(empty($model)) {
  14. $model = new self();
  15. }
  16. $model->enable = 1;
  17. $model->statements_id = $item['statements_id'];
  18. $model->project_name = $item['project_name'];
  19. $model->order_month = $item['order_month'];
  20. $model->order_amount = $item['order_amount'];
  21. $model->saler = $item['saler'];
  22. $model->handler = $item['handler'];
  23. $model->save();
  24. }
  25. }
  26. public static function updateData() {
  27. }
  28. public static function getDataBySearch($search) {
  29. $statementsFileDetailModel = self::query()->where('enable', 1);
  30. if(isset($search['order_month_start']) && !empty($search['order_month_start'])) {
  31. $statementsFileDetailModel->where('order_month', '>=', date('Y-m-01', strtotime($search['order_month_start'])));
  32. }
  33. if(isset($search['order_month_end']) && !empty($search['order_month_end'])) {
  34. $statementsFileDetailModel->where('order_month', '<=', date('Y-m-01', strtotime($search['order_month_end'])));
  35. }
  36. if(isset($search['project_name']) && !empty($search['project_name'])) {
  37. $statementsFileDetailModel->where('project_name', 'like', '%'.$search['project_name'].'%');
  38. }
  39. if(isset($search['statements_id']) && !empty($search['statements_id'])) {
  40. $statementsFileDetailModel->where('statements_id', $search['statements_id']);
  41. }
  42. if(isset($search['statements_id_list']) && !empty($search['statements_id_list'])) {
  43. $statementsFileDetailModel->whereIn('statements_id', $search['statements_id_list']);
  44. }
  45. return $statementsFileDetailModel;
  46. }
  47. }