<?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\controller\master_worker_register;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\master_worker_register\MasterWorkerRegisterLists;
use app\adminapi\logic\master_worker_register\MasterWorkerRegisterLogic;
use app\adminapi\validate\master_worker_register\MasterWorkerRegisterValidate;


/**
 * MasterWorkerRegister控制器
 * Class MasterWorkerRegisterController
 * @package app\adminapi\controller\master_worker_register
 */
class MasterWorkerRegisterController extends BaseAdminController
{


    /**
     * @notes 获取列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/09 19:45
     */
    public function lists()
    {
        return $this->dataLists(new MasterWorkerRegisterLists());
    }


    /**
     * @notes 添加
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/09 19:45
     */
    public function add()
    {
        $params = (new MasterWorkerRegisterValidate())->post()->goCheck('add');
        $result = MasterWorkerRegisterLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(MasterWorkerRegisterLogic::getError());
    }


    /**
     * @notes 编辑
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/09 19:45
     */
    public function edit()
    {
        $params = (new MasterWorkerRegisterValidate())->post()->goCheck('edit');
        $result = MasterWorkerRegisterLogic::edit($params);
        if (true === $result) {
            //审批通过 - 后续事件处理
            if($params['status'] == 1){
                // 工程师入驻结果通知：【给工程师的通知】
                event('Notice',  [
                    'scene_id' => 110,
                    'params' => [
                        'user_id' => 0,
                        'mobile' => $params['mobile'],
                    ]
                ]);
                // 通知发送 账号密码
                MasterWorkerRegisterLogic::eventNotice($params);
            }else{
                // 工程师入驻失败通知：【给工程师的通知】
                event('Notice',  [
                    'scene_id' => 111,
                    'params' => [
                        'user_id' => 0,
                        'mobile' => $params['mobile'],
                    ]
                ]);
            }
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(MasterWorkerRegisterLogic::getError());
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/09 19:45
     */
    public function delete()
    {
        $params = (new MasterWorkerRegisterValidate())->post()->goCheck('delete');
        MasterWorkerRegisterLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/09 19:45
     */
    public function detail()
    {
        $params = (new MasterWorkerRegisterValidate())->goCheck('detail');
        $result = MasterWorkerRegisterLogic::detail($params);
        return $this->data($result);
    }


}