2024-06-24 11:52:30 +08:00
|
|
|
<?php
|
2024-06-24 20:58:23 +08:00
|
|
|
|
2024-06-24 11:52:30 +08:00
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
use app\model\Admins;
|
|
|
|
use app\model\Orders;
|
|
|
|
use app\model\Works;
|
|
|
|
use support\Redis;
|
|
|
|
use support\Request;
|
2024-06-24 20:58:23 +08:00
|
|
|
use function Symfony\Component\Translation\t;
|
2024-06-24 11:52:30 +08:00
|
|
|
|
|
|
|
class WorkController extends base
|
|
|
|
{
|
2024-06-24 20:58:23 +08:00
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2024-06-24 11:52:30 +08:00
|
|
|
$admin_id = $request->get('id');
|
|
|
|
$admin = $request->get('username');
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($admin) {
|
|
|
|
$admin_id = Admins::where('username', $admin)->value('id');
|
2024-06-24 11:52:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$query = Works::with('admin')->where('status', 1)->order('start', 'desc');
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($admin_id) $query->where('admin_id', $admin_id);
|
2024-06-24 11:52:30 +08:00
|
|
|
$list = $query->paginate($request->get('limit', 30));
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
return $this->success($list->append(['total', 'oss']), '', ['oss' => Orders::OSS]);
|
2024-06-24 11:52:30 +08:00
|
|
|
}
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
public function saves(Request $request)
|
|
|
|
{
|
2024-06-24 11:52:30 +08:00
|
|
|
return '';
|
|
|
|
$admin_id = $request->post('admin_id');
|
|
|
|
$dates = $request->post('dates');
|
|
|
|
$time = $request->post('time');
|
2024-06-24 20:58:23 +08:00
|
|
|
$oss = $request->post('oss', []);
|
2024-06-24 11:52:30 +08:00
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
if (empty($dates)) return $this->error(2001, '');
|
2024-06-24 11:52:30 +08:00
|
|
|
|
|
|
|
$timeS = strtotime($time[0]);
|
|
|
|
$timeE = strtotime($time[1]);
|
|
|
|
|
|
|
|
$timeL = $timeE - $timeS;
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
foreach ($dates as $date) {
|
2024-06-24 11:52:30 +08:00
|
|
|
$d = strtotime($date);
|
2024-06-24 20:58:23 +08:00
|
|
|
$dS = date('Y-m-d', $d) . ' ' . date('H:i:s', $timeS);
|
2024-06-24 11:52:30 +08:00
|
|
|
$dE = date('Y-m-d H:i:s', strtotime($dS) + $timeL);
|
|
|
|
|
|
|
|
$month = Date('Ym', $d);
|
|
|
|
|
|
|
|
$works = new Works();
|
|
|
|
$works->admin_id = $admin_id;
|
|
|
|
$works->month = $month;
|
|
|
|
$works->start = $dS;
|
|
|
|
$works->end = $dE;
|
|
|
|
$works->status = 1;
|
2024-06-24 20:58:23 +08:00
|
|
|
$works->os = join(',', $oss);
|
2024-06-24 11:52:30 +08:00
|
|
|
$works->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success($date);
|
|
|
|
}
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
public function save2(Request $request)
|
|
|
|
{
|
2024-06-24 11:52:30 +08:00
|
|
|
$times = $request->post('times');
|
2024-06-24 20:58:23 +08:00
|
|
|
if (!empty($times)) {
|
2024-06-24 11:52:30 +08:00
|
|
|
$times = $request->post('times');
|
|
|
|
$os = $request->post('os');
|
2024-06-24 20:58:23 +08:00
|
|
|
|
2024-06-24 11:52:30 +08:00
|
|
|
$start = strtotime($times[0]);
|
|
|
|
$end = strtotime($times[1]);
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
if (count($os) <= 0) return $this->error(2001, '请选择平台');
|
|
|
|
if ($start >= $end) return $this->error(2001, '播放时间太短了');
|
|
|
|
if ($end - $start <= 3600) return $this->error(2001, '时间太短了');
|
|
|
|
if (time() - $start > 3600 * 24 || time() - $end) return $this->error(2001, '时间太久远了,没有办法自己排班,找主管排吧');
|
|
|
|
|
2024-06-24 11:52:30 +08:00
|
|
|
$os = join(',', $os);
|
|
|
|
|
|
|
|
Works::create([
|
|
|
|
'admin_id' => $request->admin->id,
|
|
|
|
'month' => date('Ym', $start),
|
|
|
|
'os' => $os,
|
2024-06-24 20:58:23 +08:00
|
|
|
'start' => date('Y-m-d H:i:s', $start),
|
2024-06-24 11:52:30 +08:00
|
|
|
'end' => date('Y-m-d H:i:s', $end),
|
|
|
|
'status' => 1,
|
|
|
|
]);
|
|
|
|
return $this->success(null);
|
|
|
|
}
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($request->admin->is_super == 0) return $this->error(2001, '管理员才可以添加');
|
2024-06-24 11:52:30 +08:00
|
|
|
$all = $request->post();
|
2024-06-24 20:58:23 +08:00
|
|
|
foreach ($all as $a) {
|
|
|
|
|
|
|
|
if (!isset($a['times'])) continue;
|
2024-06-24 11:52:30 +08:00
|
|
|
|
|
|
|
$start = strtotime($a['times'][0]);
|
|
|
|
$end = strtotime($a['times'][1]);
|
|
|
|
$os = join(',', $a['os']);
|
|
|
|
|
|
|
|
Works::create([
|
|
|
|
'admin_id' => $a['id'],
|
|
|
|
'month' => date('Ym', $start),
|
|
|
|
'os' => $os,
|
2024-06-24 20:58:23 +08:00
|
|
|
'start' => date('Y-m-d H:i:s', $start),
|
2024-06-24 11:52:30 +08:00
|
|
|
'end' => date('Y-m-d H:i:s', $end),
|
|
|
|
'status' => 1,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->success(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @保存一天的时间
|
2024-06-24 20:58:23 +08:00
|
|
|
*/
|
|
|
|
public function save(Request $request)
|
|
|
|
{
|
2024-06-24 11:52:30 +08:00
|
|
|
$id = $request->post('id', 0);
|
|
|
|
$date = $request->post('date');
|
|
|
|
$oss = $request->post('oss');
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($id) {
|
2024-06-24 11:52:30 +08:00
|
|
|
$item = Works::find($id);
|
|
|
|
}
|
2024-06-24 20:58:23 +08:00
|
|
|
if (empty($item)) {
|
2024-06-24 11:52:30 +08:00
|
|
|
return $this->error(2101);
|
|
|
|
}
|
|
|
|
|
|
|
|
$start = date('Y-m-d H:i:s', strtotime($date[0]));
|
|
|
|
$end = date('Y-m-d H:i:s', strtotime($date[1]));
|
2024-06-24 20:58:23 +08:00
|
|
|
|
2024-06-24 11:52:30 +08:00
|
|
|
$item->start = $start;
|
|
|
|
$item->end = $end;
|
|
|
|
$item->status = 1;
|
2024-06-24 20:58:23 +08:00
|
|
|
$item->os = join(',', $oss);
|
2024-06-24 11:52:30 +08:00
|
|
|
|
|
|
|
$back = $item->save();
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($back)
|
2024-06-24 11:52:30 +08:00
|
|
|
return $this->success($item);
|
|
|
|
|
|
|
|
return $this->error(2003);
|
|
|
|
}
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
public function del(Request $request)
|
|
|
|
{
|
2024-06-24 11:52:30 +08:00
|
|
|
$id = $request->post('id', 0);
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($id) {
|
2024-06-24 11:52:30 +08:00
|
|
|
$item = Works::find($id);
|
2024-06-24 20:58:23 +08:00
|
|
|
if ($item) {
|
2024-06-24 11:52:30 +08:00
|
|
|
$item->status = 0;
|
|
|
|
$item->save();
|
|
|
|
return $this->success(null);
|
|
|
|
}
|
2024-06-24 20:58:23 +08:00
|
|
|
} else {
|
|
|
|
return $this->error(2002, '没有提交ID');
|
2024-06-24 11:52:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
public function anchor(Request $request)
|
|
|
|
{
|
|
|
|
$anchor = Admins::where('status', 1)->where('is_anchor', 1)->select();
|
|
|
|
foreach ($anchor as &$an) {
|
2024-06-24 11:52:30 +08:00
|
|
|
$an->os = [];
|
|
|
|
}
|
2024-06-24 20:58:23 +08:00
|
|
|
return $this->success($anchor->hidden(['password', 'remember_token']));
|
2024-06-24 11:52:30 +08:00
|
|
|
}
|
|
|
|
|
2024-06-24 20:58:23 +08:00
|
|
|
public function getworkstatus(Request $request)
|
|
|
|
{
|
|
|
|
// $workstatus = Redis::get("CRM:USER:ENDWORK:" . $request->admin->id);
|
|
|
|
$data = Admins::where('id' , $request->admin->id)->find();
|
|
|
|
$workstatus = !$data->is_order;
|
2024-06-24 11:52:30 +08:00
|
|
|
return $this->success((bool)$workstatus);
|
|
|
|
}
|
|
|
|
}
|