<?php
namespace app\mainapp\controller;
use think\facade\Session;
use app\common\model\User as UserModel;
use app\common\model\Worker as WorkerModel;

class Identity 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);
		$title = input('title/s', "");
		$ftitle = input('ftitle/s', "");
		$realname = input('realname/s', "");
		$mobile = input('mobile/s', "");
		$position = input('position/s', "");
		$province = input('province/s', "");
		$address = input('address/s', "");
		if ( empty($title) || empty($ftitle) || empty($realname) || empty($mobile) || empty($position) || empty($province) || empty($address) ){
			page_result(1, "公司名称，微店名称，负责人姓名电话职位，地址信息不能为空。");
		}
		$data = [
			'userid'		=> $userid,
			'loginname'		=> $userid ."-". date("YmdHis"),
			'password'		=> md5("123456789"),
			'wtype'			=> input('wtype/d', 1),
			'title'			=> input('title/s', ""),
			'ftitle'		=> input('ftitle/s', ""),
			'tilpic'  		=> input('tilpic/s', ""),
			'realname'  	=> input('realname/s', ""),
			'mobile'    	=> input('mobile/s', ""),
			'position'    	=> input('position/s', ""),
			'weixin'    	=> input('weixin/s', ""),
			'latitude'		=> input('latitude/f'),
			'longitude'		=> input('longitude/f'),
			'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'    	=> input('priority/d', 0),
			'remark'  		=> input('remark/s', ""),
			'status'		=> input('status/d', 1),
			'createtime'	=> time()
		];
		$worker = WorkerModel::create($data);
	}
	
	
	
}