<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\validate\group_activity;

use app\common\model\group_activity\GroupActivity;
use app\common\validate\BaseValidate;


/**
 * 拼团活动分类验证器
 * Class GroupActivityCategoryValidate
 * @package app\adminapi\validate\group_activity
 */
class GroupActivityCategoryValidate extends BaseValidate
{

     /**
      * 设置校验规则
      * @var string[]
      */
    protected $rule = [
        'id' => 'require',
        'title' => 'require',
        'start_time' => 'require',
        'end_time' => 'require',
        'participant_num' => 'require',
        'type' => 'require',
        'form_time_limit' => 'require',
        'is_simulate_form' => 'require',
        'images' => 'require',
        'block_data' => 'require',

    ];


    /**
     * 参数描述
     * @var string[]
     */
    protected $field = [
        'id' => 'id',
        'title' => '活动名称',
        'start_time' => '活动开始时间',
        'end_time' => '活动结束时间',
        'participant_num' => '参团人数',
        'type' => '活动类型',
        'form_time_limit' => '成团时限',
        'is_simulate_form' => '是否开启模拟成团',
        'images' => '活动图片',
        'block_data' => '活动分类板块',

    ];


    /**
     * @notes 添加场景
     * @return GroupActivityValidate
     * @author likeadmin
     * @date 2025/03/13 10:31
     */
    public function sceneAdd()
    {
        return $this->only(['title','images','block_data','start_time','end_time','participant_num','type','form_time_limit','is_simulate_form']);
    }


    /**
     * @notes 编辑场景
     * @return GroupActivityValidate
     * @author likeadmin
     * @date 2025/03/13 10:31
     */
    public function sceneEdit()
    {
        return $this->only(['id','title','images','block_data','start_time','end_time','participant_num','type','form_time_limit','is_simulate_form']);
    }


    /**
     * @notes 删除场景
     * @return GroupActivityValidate
     * @author likeadmin
     * @date 2025/03/13 10:31
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }


    /**
     * @notes 详情场景
     * @return GroupActivityValidate
     * @author likeadmin
     * @date 2025/03/13 10:31
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * 活动分类统计
     */
    public static function total($id)
    {
        $result = GroupActivity::alias('a')
        ->leftJoin('group_user_order b', 'a.id = b.group_activity_id')
        ->leftJoin('group_service_work c', 'b.id = c.group_user_order_id and c.service_status = 3')
        ->field('a.*, SUM(CASE WHEN c.id IS NOT NULL THEN 1 ELSE 0 END) as order_total')
        ->where('a.group_category_id', $id)
        ->group('a.id')
        ->select()
        ->toArray();
        return $result;
    }

}