号源模板创建
parent
cf1eb92d8d
commit
8c63097f2a
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\Admin\YeWu;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanModelController extends Controller
|
||||
{
|
||||
public function timeList()
|
||||
{
|
||||
$TimeRange = request('TimeRange');
|
||||
if(count($TimeRange)<>2){
|
||||
return \Yz::echoError1('起止时间格式错误');
|
||||
}
|
||||
$start_time=$TimeRange[0];
|
||||
$end_time=$TimeRange[1];
|
||||
if (count(explode(':', $start_time)) == 1) $start_time = date('H:i:s', $start_time / 1000);
|
||||
if (count(explode(':', $end_time)) == 1) $end_time = date('H:i:s', $end_time / 1000);
|
||||
$interval_time = request('interval_time');
|
||||
$list=$this->timeArr($start_time, $end_time, $interval_time);
|
||||
return \Yz::Return(true,"查询完成",['list' =>$list]);
|
||||
|
||||
|
||||
}
|
||||
public function GetList()
|
||||
{
|
||||
$page =request('page');
|
||||
$pageSize =request('pageSize');
|
||||
$searchInfo=request('searchInfo');
|
||||
$list=DB::table('plan_model as a')
|
||||
->leftJoin('plan_type as b','a.plan_type','=','b.id')
|
||||
->select('a.*','b.name as plan_type_name')
|
||||
->where(['a.is_del'=>0]);
|
||||
if(isset($searchInfo['name'])){
|
||||
$list = $list->where('a.name', 'like','%'.$searchInfo['name'].'%');
|
||||
}
|
||||
if(isset($searchInfo['status'])){
|
||||
$list = $list->where('a.status',$searchInfo['status']);
|
||||
}
|
||||
$count=$list->count();
|
||||
if(isset($page) and isset($pageSize)){
|
||||
$list=$list->orderBy('a.id', 'desc')->limit($pageSize)->skip(($page - 1) * $pageSize)->take($pageSize);
|
||||
}
|
||||
$list=$list ->get();
|
||||
foreach ($list as $l){
|
||||
$l->y_number=json_decode($l->y_number,true);
|
||||
}
|
||||
return \Yz::Return(true,'查询完成',['list'=>$list,'count'=>$count]);
|
||||
}
|
||||
public function Save()
|
||||
{
|
||||
$Info =request('Info');
|
||||
$params = [
|
||||
'name' => isset($Info['name']) ? $Info['name'] : null,
|
||||
'interval_time' => isset($Info['interval_time']) ? $Info['interval_time'] : null,
|
||||
'plan_type' => isset($Info['plan_type']) ? $Info['plan_type'] : null,
|
||||
'y_number' => isset($Info['y_number']) ? json_encode($Info['y_number']) : [],
|
||||
'count' => isset($Info['count']) ? $Info['count'] : 0,
|
||||
'status'=>isset($Info['status']) ? $Info['status'] : 0,
|
||||
];
|
||||
$requiredFields = ['name'=>'名称','interval_time'=>'时间间隔','plan_type'=>'号源类型'];
|
||||
// 判断是否为空
|
||||
foreach ($requiredFields as $key=> $field) {
|
||||
if (!isset($params[$key]) || $params[$key] === null) {
|
||||
return \Yz::echoError1('参数 ' . $field . ' 不能为空');
|
||||
}
|
||||
}
|
||||
if(!isset($Info['TimeRange']) or count($Info['TimeRange'])<>2){
|
||||
return \Yz::echoError1('起止时间格式错误');
|
||||
}
|
||||
$params['start_time']=$Info['TimeRange'][0];
|
||||
$params['end_time']=$Info['TimeRange'][1];
|
||||
$do=false;
|
||||
$table=DB::table('plan_model');
|
||||
if($Info['id']==0){
|
||||
$do=$table->insert($params);
|
||||
}
|
||||
if($Info['id']>0){
|
||||
$do=$table->where(['id'=>$Info['id']])->update($params);
|
||||
}
|
||||
if($do){
|
||||
return \Yz::Return(true,'操作成功',[]);
|
||||
}else{
|
||||
return \Yz::echoError1('操作失败');
|
||||
}
|
||||
|
||||
}
|
||||
public function GetDetail()
|
||||
{
|
||||
$id =request('id');
|
||||
$info=DB::table('plan_model')->where(['id'=>$id,'is_del'=>0])->first();
|
||||
if(!!$info){
|
||||
$info->TimeRange=[$info->start_time,$info->end_time];
|
||||
$info->y_number=json_decode($info->y_number,true);
|
||||
return \Yz::Return(true,'查询完成',$info);
|
||||
}else{
|
||||
return \Yz::echoError1('查询失败');
|
||||
}
|
||||
}
|
||||
function timeArr($start_time, $end_time, $interval_time, $arr = [])
|
||||
{
|
||||
|
||||
if (strtotime($start_time) > strtotime($end_time)) return $arr;
|
||||
$arr[] = date('H:i', strtotime($start_time));
|
||||
return $this->timeArr(date('Y-m-d H:i:s', strtotime($start_time) + ($interval_time * 60)), $end_time, $interval_time, $arr);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue