| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Services;
- use App\OwnerPriceLogistic;
- use App\OwnerPriceLogisticDetail;
- Class OwnerPriceLogisticService
- {
- public function paginate()
- {
- return OwnerPriceLogistic::query()->with(["owners","logistics","unit","otherUnit"])->paginate(50);
- }
- public function create(array $params)
- {
- return OwnerPriceLogistic::query()->create($params);
- }
- public function find($id, $withs=[])
- {
- return OwnerPriceLogistic::query()->with($withs)->find($id);
- }
- public function update(array $params, array $values)
- {
- $query = OwnerPriceLogistic::query();
- foreach ($params as $column=>$param){
- $query->where($column,$params);
- }
- return $query->update($values);
- }
- public function updateDetail(array $params, array $values)
- {
- $query = OwnerPriceLogisticDetail::query();
- foreach ($params as $column => $param){
- $query->where($column,$param);
- }
- return $query->update($values);
- }
- public function isExistDetail(array $params)
- {
- $query = OwnerPriceLogisticDetail::query();
- foreach ($params as $column => $param){
- $query->where($column,$param);
- }
- return $query->count();
- }
- public function createDetail(array $params)
- {
- return OwnerPriceLogisticDetail::query()->create($params);
- }
- public function destroyDetail($id)
- {
- return OwnerPriceLogisticDetail::destroy($id);
- }
- public function checkRange($range):bool
- {
- $arrRanges = explode(",",$range);
- $len = count($arrRanges);
- if ($len==0)return false; //范围为空 false
- $previous = []; //慢指针数组 不记录第一个值
- foreach ($arrRanges as $index => $value){
- if ($index == $len-1)$preg = "/\d*\-/"; //最后一个范围不允许封闭
- else $preg = "/\d*\-\d*/";
- preg_match($preg, $value, $match);
- if (!$match || $match[0]!=$value)return false;//匹配结果不等于值 false
- $arr = explode("-",$value); //二次切割判断是否连续
- if ($index != 0){
- if ($index == $len-1){
- if ((int)$arr[0] != (int)$previous[$index-1][1])return false; //最后一个范围只需要判断起始值
- }else{
- if ((int)$arr[0] != (int)$previous[$index-1][1] || (int)$arr[1] <= (int)$arr[0])return false; //普通范围起始值必须为上一个结束值 当前结束值必须大于起始值
- }
- }else{
- if ((int)$arr[1] <= (int)$arr[0])return false; //第一个范围只需判断当前结束值大于起始值
- }
- $previous[] = $arr;
- }
- return true;
- }
- }
|