<?php
namespace app\mainapp\controller;
use think\facade\Session;
use app\mainapp\BaseController;

use app\common\model\User as UserModel;
use app\common\model\Worker as WorkerModel;

class Wlogin extends BaseController
{
	
	// public function getIdentity()
	// {
	// 	$userid = input('userid/d');
	// 	$user = UserModel::findOrEmpty($userid);
	// 	if ($user->isEmpty()){
	// 		page_result(1, "用户信息不存在");
	// 	}
	// 	$workerall = WorkerModel::where('userid','=',$user->id)->select();
	// 	$agentall = AgentModel::where('userid','=',$user->id)->select();
	// 	$brokerall = BrokerModel::where('userid','=',$user->id)->select();
	// 	page_result(0, "", array(
	// 		'user'			=> $user,
	// 		'workerall'		=> $workerall->isEmpty() ? null : $workerall,
	// 		'agentall'		=> $agentall->isEmpty() ? null : $agentall,
	// 		'brokerall'		=> $brokerall->isEmpty() ? null : $brokerall
	// 	)); 
	// }
	
	
	public function regWorker()
	{
		$userid = input('userid/d', 0);
		$wtype = input('wtype/d', 1);
		$tilpic = input('tilpic/s', "");
		$title = input('title/s', "");
		$ftitle = input('ftitle/s', "");
		$realname = input('realname/s', "");
		$mobile = input('mobile/s', "");
		$province = input('province/s', "");
		$address = input('address/s', "");
		$picone = input('picone/s', "");
		if ( empty($tilpic) ){
			page_result(1, "微店图标不能为空，请上传企业LOGO或公司图片。");
		}
		if ( empty($title) || empty($ftitle) || empty($realname) || empty($mobile) || empty($province) || empty($address) || empty($picone) ){
			page_result(1, "公司名称，微店名称，负责人姓名电话职位，地址信息以及相关证件不能为空。");
		}
		if ( $wtype==2 && (empty($pictwo) || empty($picthr)) ){
			page_result(1, "相关证件不能为空。");
		}
		$data = [
			'userid'		=> $userid,
			'wtype'			=> $wtype,
			'title'			=> input('title/s', ""),
			'ftitle'		=> input('ftitle/s', ""),
			'tilpic'  		=> input('tilpic/s', ""),
			'realname'  	=> input('realname/s', ""),
			'mobile'    	=> input('mobile/s', ""),
			'weixin'    	=> input('weixin/s', ""),
			'latitude'		=> 0.000000,
			'longitude'		=> 0.000000,
			'province'		=> input('province/s', ""),
			'city'			=> input('city/s', ""),
			'district'		=> input('district/s', ""),
			'address'		=> input('address/s', ""),
			'picone'		=> input('picone/s', ""),
			'pictwo'		=> input('pictwo/s', ""),
			'picthr'		=> input('picthr/s', ""),
			'details'		=> input('details/s', ""),
			'priority'    	=> 0,
			'remark'  		=> "",
			'status'		=> 1,
			'createtime'	=> time()
		];
		$worker = WorkerModel::create($data);
		page_result(0, "", array(
			'worker'	=> $worker
			));
	}
	
	
	
}