MemberSalesModel.php 1.7 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/8/9
 * Time: 14:34
 */

namespace app\member\model;

use think\Db;
use think\Model;

class MemberSalesModel extends Model
{
    protected $autoWriteTimestamp = true;

    /**
     * 添加销售人员
     */
    public function addMemberSales($data) {
        $this->allowField(true)->data($data,true)->isUpdate(false)->save();
        return $this;
    }

    /**
     * 编辑销售人员
     */
    public function editMemberSales($data) {
        $this->allowField(true)->data($data,true)->isUpdate(true)->save();
        return $this;
    }

    public function doName($user)
    {
        $userQuery = $this;

        $result = $userQuery->where('user_login', $user['user_login'])->find();
        if (!empty($result)) {
            $comparePasswordResult = cmf_compare_password($user['user_pass'], $result['user_pass']);
            $hookParam =[
                'user'=>$user,
                'compare_password_result'=>$comparePasswordResult
            ];
            hook_one("user_login_start",$hookParam);
            if ($comparePasswordResult) {
                //拉黑判断。
//                if($result['user_status']==0){
//                    return 3;
//                }
                session('user_sale', $result);
                $data = [
                    'last_login_time' => time(),
                    'last_login_ip'   => get_client_ip(0, true),
                ];
                $userQuery->where('id', $result["id"])->update($data);
                return 0;
            }
            return 1;
        }
        $hookParam =[
            'user'=>$user,
            'compare_password_result'=>false
        ];
        hook_one("user_login_start",$hookParam);
        return 2;
    }

}