<?php
namespace MpSmi\Model;

use Think\Model;

header("Content-type:text/html;charset=utf-8");
class StoresModel extends Model
{
    /**
     * 检查用户名、密码
     */
    public function check($mobile, $password)
    {
        $time = time();
        $row = $this->where("`mobile` = '$mobile'")->find();
        if (!$row) {
            // 账号不存在
            return array("status" => -1, "msg" => "账号不存在");
        }
        $password = md5($password);
        if ($row['password'] != $password) {
            // 密码错误
            return array("status" => -1, "msg" => "密码错误");
        } else {
            // 正常登陆
            $this->where("`id` = {$row['id']}")->save($save);
            session("store", $row['name']);
            session("store_id", $row['id']);
            session("mobile", $row['mobile']);
            return array("status" => 1, "msg" => "登陆成功");
        }
    }
    
    /**
     * 名称查重
     */
    public function check_same($mobile, $id = 0)
    {
        if (!$id) {
            //添加记录查重
            if ($mobile) {
                $row = $this->where("`mobile` = '$mobile'")->find();
            }
        } else {
            //修改记录查重
            if ($mobile) {
                $row = $this->where("`id` != $id AND `mobile` = '$mobile'")->find();
            }
        }
        if ($row) {
            return true;
        } else {
            return false;
        }
    }
}