125 lines
3.8 KiB
PHP
125 lines
3.8 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/06/23
|
|
* Time: 14:08
|
|
*/
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
class Employees extends Wxapp{
|
|
|
|
function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg =array();//授权微信信息
|
|
}
|
|
|
|
public function get(){
|
|
$ifconf = $this->input_param('ifconf');
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
$uid = $this->session['uid'];
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
|
|
if($ifconf){
|
|
$where = [
|
|
"(biz_id=$biz_id or id=$uid)" => null,
|
|
'status' => 1
|
|
];
|
|
}else{
|
|
$where = [
|
|
'biz_id' => $biz_id,
|
|
'status>' => -1
|
|
];
|
|
}
|
|
|
|
$count = $this->app_user_model->count($where);
|
|
$lists = [];
|
|
if($count){
|
|
$fileds = 'id,uname,mobile,status';
|
|
$rows = $this->app_user_model->select($where,'id desc',$page,$size,$fileds);
|
|
$lists = $rows;
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
protected function post(){
|
|
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
$group_id = $this->session['group_id'];
|
|
|
|
$name = $this->input_param('name');
|
|
$mobile = $this->input_param('mobile');
|
|
|
|
if($group_id!=2){
|
|
throw new Exception('无法添加店员', ERR_PARAMS_ERROR);
|
|
}
|
|
if(!mobile_valid($mobile)||!$name){
|
|
throw new Exception('请输入正确手机号和姓名', ERR_PARAMS_ERROR);
|
|
}
|
|
|
|
$row = $this->app_user_model->get(['mobile'=>$mobile,'status>=0'=>null]);
|
|
if($row){
|
|
throw new Exception('手机号已存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$data = [
|
|
'pid' => $this->session['uid'],
|
|
'mobile' => $mobile,
|
|
'uname' => $name,
|
|
'group_id' => 1,
|
|
'biz_id' => $biz_id,
|
|
'c_time' => time()
|
|
];
|
|
$result = $this->app_user_model->add($data);
|
|
if($result){
|
|
throw new Exception('创建成功', API_CODE_SUCCESS);
|
|
}else{
|
|
throw new Exception('创建失败', ERR_PARAMS_ERROR);
|
|
}
|
|
}
|
|
|
|
protected function put(){
|
|
$id = $this->input_param('id');
|
|
$status = $this->input_param('status');
|
|
$where = [
|
|
'pid' => $this->session['uid'],
|
|
'id' => $id
|
|
];
|
|
$row = $this->app_user_model->get($where);
|
|
if(!$row){
|
|
throw new Exception('用户不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$update = [];
|
|
if(strlen($status)){
|
|
$update['status'] = $status ? 1 : 0;
|
|
}
|
|
$this->app_user_model->update($update,$where);
|
|
throw new Exception('更新成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
protected function delete(){
|
|
$id = $this->input_param('id');
|
|
$where = [
|
|
'pid' => $this->session['uid'],
|
|
'id' => $id
|
|
];
|
|
$row = $this->app_user_model->get($where);
|
|
if(!$row){
|
|
throw new Exception('用户不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$this->app_user_model->update(['status'=>-1],$where);
|
|
throw new Exception('删除成功', API_CODE_SUCCESS);
|
|
}
|
|
}
|