<?php
namespace app\common\listener\activity;
use app\common\model\manystore\Shop;
use app\common\model\school\activity\Activity;
use app\common\model\school\classes\Visit;
use app\common\model\school\Message;
use app\common\model\school\MessageConfig;
use app\common\model\User;

class ActivityHook
{




        public function newActivityViewAfter(&$params)
        {
            ['activity' => $activity,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;
//访问记录
            Visit::create([
                "classes_lib_id"=>0,
                "classes_activity_id"=>$activity["id"],
//                "shop_id"=>$activity["shop_id"],
                "status"=>'2',
                "user_id"=>$user_id,
            ]);
        }



    public function newActivityCollectSuccessAfter(&$params)
    {
        ['activity' => $activity,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;

    }

    public function newActivityCollectCancelAfter(&$params)
    {
        ['activity' => $activity,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;

    }



    public function newActivityAuthNeedAfter(&$params)
    {
        ['activity' => $activity,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;


            //课程推送给老师

            $mini_type = "activity_apply";
        $system_user_id = config("site.system_user_id");//系统用户
            $to_id = $system_user_id;
            $status ="activity";

            $params=[
                "event"=>"new_activity_auth_need_after",
                "activity_id"=>$activity["id"],
                "title"=>$activity["title"],
                "images"=>$activity["images"],
            ];


            $param = [
                "title" => $activity['title'],
                "address"=>$activity["address"]."(".$activity["address_detail"].")",
                "price" => $activity["price"],
                "start_time" => date("Y-m-d H:i",$activity["start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
                "end_time" =>   date("Y-m-d H:i",$activity["end_time"]),
                "sign_start_time" => date("Y-m-d H:i",$activity["sign_start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
                "sign_end_time" =>   date("Y-m-d H:i",$activity["sign_end_time"]),
                "reason" => $activity['reason'],
            ];

            //发给用户
            (new MessageConfig)
                ->setTemplate($params["event"])
                ->setTemplateData($param)
                ->setToUid($to_id)
                ->setMessageStatus($status)
                ->setMessageMiniType($mini_type)
                ->setMessageParams($params)
                ->sendMessage();




    }



    // 课程审核通过后
    public function newActivityAuthSuccessAfter(&$params)
    {
        ['activity' => $activity,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;

            $system_user_id = config("site.system_user_id");//系统用户

            $user = User::where("id",$user_id)->find();
            //课程推送给老师
            $mini_type = "activity_apply";
            $to_id = $user_id;
            $status ="activity";
            $params=[
                "event"=>"new_activity_auth_success_after",
                "activity_id"=>$activity["id"],
                "title"=>$activity["title"],
                "images"=>$activity["images"],
            ];

            $param = [
                "realname"=> $user["realname"],
                "nickname"=> $user["nickname"],
                "mobile"=> $user["mobile"],
                "title" => $activity['title'],
                "address"=>$activity["address"]."(".$activity["address_detail"].")",
                "price" => $activity["price"],
                "start_time" => date("Y-m-d H:i",$activity["start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
                "end_time" =>   date("Y-m-d H:i",$activity["end_time"]),
                "sign_start_time" => date("Y-m-d H:i",$activity["sign_start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
                "sign_end_time" =>   date("Y-m-d H:i",$activity["sign_end_time"]),
                "reason" => $activity['reason'],
            ];

            //发给用户
            (new MessageConfig)
                ->setTemplate($params["event"])
                ->setTemplateData($param)
                ->setToUid($to_id)
                ->setMessageStatus($status)
                ->setMessageMiniType($mini_type)
                ->setMessageParams($params)
                ->sendMessage();




    }

    // 课程审核失败后
    public function newActivityAuthFailAfter(&$params)
    {
        ['activity' => $activity,"user_id"=>$user_id,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;
        $system_user_id = config("site.system_user_id");//系统用户
        $user = User::where("id",$user_id)->find();
//课程推送给老师
        $mini_type = "activity_apply";
        $to_id = $user_id;
        $status ="activity";
        $params=[
                "event"=>"new_activity_auth_fail_after",
                "activity_id"=>$activity["id"],
            "title"=>$activity["title"],
            "images"=>$activity["images"],
            ];

            $param = [
                "realname"=> $user["realname"],
                "nickname"=> $user["nickname"],
                "mobile"=> $user["mobile"],
                "title" => $activity['title'],
                "address"=>$activity["address"]."(".$activity["address_detail"].")",
                "price" => $activity["price"],
                "start_time" => date("Y-m-d H:i",$activity["start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
                "end_time" =>   date("Y-m-d H:i",$activity["end_time"]),
                "sign_start_time" => date("Y-m-d H:i",$activity["sign_start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
                "sign_end_time" =>   date("Y-m-d H:i",$activity["sign_end_time"]),
                "reason" => $activity['reason'],
            ];

            //发给用户
            (new MessageConfig())
                ->setTemplate($params["event"])
                ->setTemplateData($param)
                ->setToUid($to_id)
                ->setMessageStatus($status)
                ->setMessageMiniType($mini_type)
                ->setMessageParams($params)
                ->sendMessage();


            //调用取消活动接口
        (new Activity)->cancel($activity["id"],"1",false,$oper_type,$oper_id);


    }


    public function newActivityCancelSuccessAfter(&$params)
    {
        ['activity' => $activity,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params;


        $user = User::where("id",$activity["user_id"])->find();
//课程推送给老师
        $mini_type = "activity_apply";
        $to_id = $user["id"];
        $status ="activity";
        $params=[
            "event"=>"new_activity_cancel_success_after",
            "activity_id"=>$activity["id"],
            "title"=>$activity["title"],
            "images"=>$activity["images"],
            //活动名
            //活动头像
        ];

        $param = [
            "realname"=> $user["realname"],
            "nickname"=> $user["nickname"],
            "mobile"=> $user["mobile"],
            "title" => $activity['title'],
            "address"=>$activity["address"]."(".$activity["address_detail"].")",
            "price" => $activity["price"],
            "start_time" => date("Y-m-d H:i",$activity["start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
            "end_time" =>   date("Y-m-d H:i",$activity["end_time"]),
            "sign_start_time" => date("Y-m-d H:i",$activity["sign_start_time"]), //格式化日期格式 $order["start_time"], //格式化日期格式
            "sign_end_time" =>   date("Y-m-d H:i",$activity["sign_end_time"]),
            "reason" => $activity['reason'],
        ];

        //发给用户
        (new MessageConfig)
            ->setTemplate($params["event"])
            ->setTemplateData($param)
            ->setToUid($to_id)
            ->setMessageStatus($status)
            ->setMessageMiniType($mini_type)
            ->setMessageParams($params)
            ->sendMessage();

    }







}