OwnerPriceLogisticService.php 2.6 KB

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