OwnerPriceLogisticService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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, $withs=[])
  16. {
  17. return OwnerPriceLogistic::query()->with($withs)->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 destroyDetail($id)
  48. {
  49. return OwnerPriceLogisticDetail::destroy($id);
  50. }
  51. public function checkRange($range):bool
  52. {
  53. $arrRanges = explode(",",$range);
  54. $len = count($arrRanges);
  55. if ($len==0)return false; //范围为空 false
  56. $previous = []; //慢指针数组 不记录第一个值
  57. foreach ($arrRanges as $index => $value){
  58. if ($index == $len-1)$preg = "/\d*\-/"; //最后一个范围不允许封闭
  59. else $preg = "/\d*\-\d*/";
  60. preg_match($preg, $value, $match);
  61. if (!$match || $match[0]!=$value)return false;//匹配结果不等于值 false
  62. $arr = explode("-",$value); //二次切割判断是否连续
  63. if ($index != 0){
  64. if ($index == $len-1){
  65. if ((int)$arr[0] != (int)$previous[$index-1][1])return false; //最后一个范围只需要判断起始值
  66. }else{
  67. if ((int)$arr[0] != (int)$previous[$index-1][1] || (int)$arr[1] <= (int)$arr[0])return false; //普通范围起始值必须为上一个结束值 当前结束值必须大于起始值
  68. }
  69. }else{
  70. if ((int)$arr[1] <= (int)$arr[0])return false; //第一个范围只需判断当前结束值大于起始值
  71. }
  72. $previous[] = $arr;
  73. }
  74. return true;
  75. }
  76. }