<?php
namespace app\workerapi\controller;

use app\adminapi\logic\property\PropertyHeadLogic;
use app\adminapi\logic\user\UserLogic;
use app\adminapi\validate\property\PropertyHeadValidate;
use app\common\enum\notice\NoticeEnum;
use app\common\model\master_worker\MasterWorker;
use app\common\model\master_worker_register\MasterWorkerRegister;
use app\common\model\notice\NoticeSetting;
use app\common\model\sale\Sale;
use app\common\service\wechat\WeChatOaService;
use app\workerapi\lists\MasterWorkerRegisterLists;
use app\workerapi\lists\PropertyHeadLists;
use app\workerapi\lists\TenantRegisterLists;
use app\workerapi\logic\DictLogic;
use app\workerapi\logic\LoginLogic;
use app\workerapi\logic\MasterWorkerRegisterLogic;

use app\workerapi\logic\SaleLogic;
use app\workerapi\logic\TenantRegisterLogic;
use app\workerapi\validate\LoginAccountValidate;
use app\workerapi\validate\RegisterValidate;


/**
 * 销售
 * Class PropertyHeadController
 * @package app\workerapi\controller
 */
class PropertyHeadController extends BaseApiController
{

    public array $notNeedLogin = ['register'];


    /**
     * @notes 注册代理
     * @return \think\response\Json
     * @author 段誉
     * @date 2022/9/7 15:38
     */
    public function register()
    {
        $params = (new PropertyHeadValidate())->post()->goCheck('add');
        $params['sale_type'] = 1;
        $params['is_cooperate'] = 3;
        // 通过 $params['city'] 查询省市区
        if(isset($params['city']) && !empty($params['city'])){
            $postageRegion = array_column(getPostageRegion(), null, 'id');
            $params['province'] = $postageRegion[$params['city']]['pid'];
            $params['province'] && $params['area_name'] = $postageRegion[$params['province']]['name'].$postageRegion[$params['city']]['name'];
        }
        $result = PropertyHeadLogic::add($params);
        if (true === $result) {
            // 通过手机号查询用户是否注册 - 已注册绑定id ，未注册注册再绑定id
            $userId = UserLogic::getUserIdByMobile($params['head_mobile'], true);
            PropertyHeadLogic::updateUserId($params['head_mobile'],$userId);
            return $this->success('入驻成功', [], 1, 1);
        }
        return $this->fail(PropertyHeadLogic::getError());
    }


}