作者 lyh

gx

... ... @@ -55,77 +55,6 @@ class TaskController extends BaseController
}
/**
* @remark :获取任务列表
* @name :getTaskList
* @author :lyh
* @method :post
* @time :2023/8/23 15:44
*/
public function getTaskList(&$task,$ids){
$lists = $task->list(['id'=>['in',$ids]]);
foreach ($lists as $k => $v){
$v = $this->getFileUrl($v);
$lists[$k] = $v;
}
return $lists;
}
/**
* @remark :处理文件
* @name :getFileUrl
* @author :lyh
* @method :post
* @time :2023/8/23 16:15
*/
public function getFileUrl(&$v){
$fileModel = new File();
$file_info = $fileModel->read(['hash'=>$v['attachment']]);
if($file_info !== false){
$v['attachment_name'] = basename($file_info['path']);
if($file_info['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$v['attachment'] = $cosCdn.$file_info['path'];
}else{
$v['attachment'] = url('a/download_files?hash='.$v['attachment']);
}
}
return $v;
}
public function items(Request $request, TaskLogic $logic)
{
$request->validate([
'own_manage_id'=>'required'
],[
'own_manage_id.required' => '所属人ID不能为空'
]);
$map[] = ['id', 'in', TaskOwner::where('manage_id', $this->param['own_manage_id'])->pluck('id')->toArray()];
if(!empty($this->param['search']) && !empty($this->param['search_type'])){
if($this->param['search_type'] == 'project'){
$map[] = ['project_id', 'in', Project::where('title', 'like', "%{$this->param['search']}%")->pluck('id')->toarray()];
}else{
$map[] = [$this->param['search_type'], 'like', "%{$this->param['search']}%"];
}
}
if(!empty($this->param['dep_id'])){
$manage_ids = Manage::where('dept_id', $this->param['dep_id'])->pluck('id')->toArray();
$map[] = ['id', 'in', TaskOwner::whereIn('manage_id',$manage_ids)->pluck('task_id')->toArray()];
}
if(!empty($this->param['manage_id']) && !empty($this->param['type'])){
if($this->param['type'] == 1){
$map[] = ['created_manage_id', $this->param['manage_id']];
}else{
$map[] = ['id', 'in', TaskOwner::where('manage_id', $this->param['manage_id'])->pluck('task_id')->toArray()];
}
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'project_id', 'workload', 'priority', 'content', 'attachment', 'status', 'end_at', 'created_manage_id']);
return $this->success($data);
}
/**
* @remark :获取详情
* @name :info
* @author :lyh
... ... @@ -138,7 +67,7 @@ class TaskController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getTaskInfo($this->param['id']);
$data = $logic->getTaskInfo();
return $this->response('success',Code::SUCCESS,$data);
}
... ... @@ -157,7 +86,7 @@ class TaskController extends BaseController
* @date 2023/4/27
*/
public function status(Request $request, TaskLogic $logic){
$request->validate([
$this->request->validate([
'id'=>'required',
'status' => ['required', Rule::in(array_keys(Task::statusMap()))]
],[
... ... @@ -181,4 +110,43 @@ class TaskController extends BaseController
$data = $logic->save($this->param);
return $this->success($data);
}
/**
* @remark :获取任务列表
* @name :getTaskList
* @author :lyh
* @method :post
* @time :2023/8/23 15:44
*/
public function getTaskList(&$task,$ids){
$lists = $task->list(['id'=>['in',$ids]]);
foreach ($lists as $k => $v){
$v = $this->getFileUrl($v);
$lists[$k] = $v;
}
return $lists;
}
/**
* @remark :处理文件
* @name :getFileUrl
* @author :lyh
* @method :post
* @time :2023/8/23 16:15
*/
public function getFileUrl(&$v){
$fileModel = new File();
$file_info = $fileModel->read(['hash'=>$v['attachment']]);
if($file_info !== false){
$v['attachment_name'] = basename($file_info['path']);
if($file_info['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$v['attachment'] = $cosCdn.$file_info['path'];
}else{
$v['attachment'] = url('a/download_files?hash='.$v['attachment']);
}
}
return $v;
}
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\Arr;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\LoginLogic;
use App\Http\Logic\Aside\Manage\ManageLogic;
use App\Models\File\File;
use App\Models\Task\Task;
use App\Models\Task\TaskOwner;
use Illuminate\Support\Facades\DB;
... ... @@ -23,49 +24,45 @@ class TaskLogic extends BaseLogic
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Task();
}
public function getUserlist(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20){
$where = array_map(function ($v) {
if(!Str::startsWith($v[0], 'gto.')) {
$v[0] = 'gl_task.' . $v[0];
}
return $v;
}, $map);
$data = $this->formatQuery($where)->leftJoin('gl_task_owner as gto', 'gl_task.id', '=', 'gto.task_id')
->select('gto.manage_id', DB::raw('COUNT(*) as count'))
->groupBy('gto.manage_id')
->paginate($limit)->toArray();
$list = [];
$map = array_map(function ($v) {
if(!Str::startsWith($v[0], 'gto.')) {
return $v;
}
return [];
}, $map);
$map = array_filter($map);
foreach ($data['list'] as $v){
$ids = TaskOwner::where('manage_id', $v['manage_id'])->pluck('task_id')->toArray();
$list[] = [
"manage_id" => $v['manage_id'],
"manage_id_text" => (new ManageLogic)->getCacheName($v['manage_id']),
"count" => $v['count'],
"task_list" => $this->model->list(['id'=>['in',$ids]]),
];
}
return $this->success($list);
}
public function getTaskInfo($id)
/**
* @remark :获取数据详情
* @name :getTaskInfo
* @author :lyh
* @method :post
* @time :2023/8/23 16:42
*/
public function getTaskInfo()
{
$info = $this->model->where(['id'=>$id])->with('owner')->with('follow')->first();
$info = $this->model->where(['id'=>$this->param['id']])->with('owner')->with('follow')->first();
return $this->success($info);
}
/**
* @remark :处理文件
* @name :getFileUrl
* @author :lyh
* @method :post
* @time :2023/8/23 16:15
*/
public function getFileUrl(&$v){
$fileModel = new File();
$file_info = $fileModel->read(['hash'=>$v['attachment']]);
if($file_info !== false){
$v['attachment_name'] = basename($file_info['path']);
if($file_info['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$v['attachment'] = $cosCdn.$file_info['path'];
}else{
$v['attachment'] = url('a/download_files?hash='.$v['attachment']);
}
}
return $v;
}
public function save($param){
DB::beginTransaction();
... ...
... ... @@ -31,7 +31,7 @@ class CategoryLogic extends BaseLogic
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data as &$v){
$v['url'] = $this->user['domain'] . $v['route'] ;
$v['product_num'] = $this->getProductNum($v['id']);
$v['product_num'] = Product::where('category_id','like' ,'%,'.$v['category_id'].',%')->count();;
$v['image_link'] = getImageUrl($v['image']);
}
if(!$map){
... ... @@ -129,14 +129,6 @@ class CategoryLogic extends BaseLogic
if(!$info){
continue;
}
//是否有子分类
if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){
$this->fail("分类{$info['title']}存在子分类,不能删除");
}
//是否有对应商品
if(CategoryRelated::where('cate_id', $id)->count()){
$this->fail("分类{$info['title']}存在产品,不能删除");
}
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
}
... ... @@ -153,15 +145,4 @@ class CategoryLogic extends BaseLogic
return $this->success();
}
/**
* 关联产品数量
* @param $cate_id
* @return mixed
* @author zbj
* @date 2023/4/28
*/
public function getProductNum($cate_id){
$cate_ids = $this->model->getChildIdsArr($cate_id);
return CategoryRelated::whereIn('cate_id', $cate_ids)->distinct()->count('product_id');
}
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use Illuminate\Support\Facades\DB;
... ... @@ -29,13 +30,20 @@ class KeywordLogic extends BaseLogic
{
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data['list'] as &$v){
$v['product_num'] = $this->getProductNum($v['id']);
$v['product_num'] = Product::where('keyword_id','like' ,'%,'.$v['keyword_id'].',%')->count();
$v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']);
$v['url'] = $this->user['domain'] . $v['route'];
}
return $this->success($data);
}
/**
* @remark :获取数据详情
* @name :getInfo
* @author :lyh
* @method :post
* @time :2023/8/23 16:50
*/
public function getInfo($id)
{
$info = parent::getInfo($id);
... ... @@ -43,6 +51,13 @@ class KeywordLogic extends BaseLogic
return $this->success($info);
}
/**
* @remark :保存
* @name :keywordSave
* @author :lyh
* @method :post
* @time :2023/8/23 16:50
*/
public function keywordSave(){
DB::beginTransaction();
try {
... ... @@ -77,17 +92,10 @@ class KeywordLogic extends BaseLogic
if(!$info){
continue;
}
//是否有对应商品
if(KeywordRelated::where('keyword_id', $id)->count()){
$this->fail("关键词{$info['title']}存在产品,不能删除");
}
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
}
parent::delete($ids);
DB::commit();
} catch (BsideGlobalException $e){
DB::rollBack();
... ... @@ -96,11 +104,7 @@ class KeywordLogic extends BaseLogic
DB::rollBack();
$this->fail('删除失败');
}
return $this->success();
}
public function getProductNum($keyword_id){
return KeywordRelated::where('keyword_id', $keyword_id)->distinct()->count('product_id');
}
}
... ...
... ... @@ -293,12 +293,6 @@ class ProductLogic extends BaseLogic
'status'=>$this->param['status']
];
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
//新增关联分类
foreach ($this->param['id'] as $v1){
foreach ($this->param['category_id'] as $v2){
CategoryRelated::saveRelated($v1,$v2);
}
}
DB::commit();
//对应添加关联表
}catch (\Exception $e){
... ...
... ... @@ -21,41 +21,4 @@ class Category extends Base
const STATUS_ACTIVE = 1;
/**
* 子分类
* @var array
*/
protected $child_ids_arr = [];
/**
* 获取指定分类的所有子分类IDS(包括自己)
* @param $id
* @return array
* @author zbj
* @date 2023/4/28
*/
public function getChildIdsArr($id)
{
$this->child_ids_arr = [$id];
return $this->getChildrenIdArr($id);
}
/**
* 递归获取指定分类的所有子孙
* @param $id
* @return array
* @author zbj
* @date 2023/4/28
*/
protected function getChildrenIdArr($id)
{
$list = parent::where("pid", $id)->pluck('pid', 'id');
if ($list) {
foreach ($list as $id => $pid) {
$this->child_ids_arr[] = $id;
$this->getChildrenIdArr($id);
}
}
return $this->child_ids_arr;
}
}
... ...
... ... @@ -168,7 +168,6 @@ Route::middleware(['aloginauth'])->group(function () {
//工单管理
Route::prefix('task')->group(function () {
Route::get('/', [Aside\Task\TaskController::class, 'list'])->name('admin.task');
Route::get('/items', [Aside\Task\TaskController::class, 'items'])->name('admin.task_items');
Route::get('/info', [Aside\Task\TaskController::class, 'info'])->name('admin.task_info');
Route::post('/save', [Aside\Task\TaskController::class, 'save'])->name('admin.task_save');
Route::post('/status', [Aside\Task\TaskController::class, 'status'])->name('admin.task_status');
... ...