OwnerPriceLogisticService.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerPriceLogistic;
  4. Class OwnerPriceLogisticService
  5. {
  6. public function paginate()
  7. {
  8. return OwnerPriceLogistic::query()->with(["owners","logistics","unit","otherUnit"])->paginate(50);
  9. }
  10. public function create(array $params)
  11. {
  12. return OwnerPriceLogistic::query()->create($params);
  13. }
  14. public function find($id)
  15. {
  16. return OwnerPriceLogistic::query()->find($id);
  17. }
  18. public function update(array $params, array $values)
  19. {
  20. $query = OwnerPriceLogistic::query();
  21. foreach ($params as $column=>$param){
  22. $query->where($column,$params);
  23. }
  24. return $query->update($values);
  25. }
  26. public function checkRange($range):bool
  27. {
  28. $arrRanges = explode(",",$range);
  29. $len = count($arrRanges);
  30. if ($len==0)return false; //范围为空 false
  31. $previous = []; //慢指针数组 不记录第一个值
  32. foreach ($arrRanges as $index => $value){
  33. if ($index == $len-1)$preg = "/\d*\-/"; //最后一个范围不允许封闭
  34. else $preg = "/\d*\-\d*/";
  35. preg_match($preg, $value, $match);
  36. if (!$match || $match[0]!=$value)return false;//匹配结果不等于值 false
  37. $arr = explode("-",$value); //二次切割判断是否连续
  38. if ($index != 0){
  39. if ($index == $len-1){
  40. if ((int)$arr[0] != (int)$previous[$index-1][1])return false; //最后一个范围只需要判断起始值
  41. }else{
  42. if ((int)$arr[0] != (int)$previous[$index-1][1] || (int)$arr[1] <= (int)$arr[0])return false; //普通范围起始值必须为上一个结束值 当前结束值必须大于起始值
  43. }
  44. }else{
  45. if ((int)$arr[1] <= (int)$arr[0])return false; //第一个范围只需判断当前结束值大于起始值
  46. }
  47. $previous[] = $arr;
  48. }
  49. return true;
  50. }
  51. }