Files
2022-07-28 13:57:32 +08:00

193 lines
6.7 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
{
private $biz_id;
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();//授权微信信息
$this->biz_id = $this->get_biz_id();
}
/**
* Notes:获取离职
* Created on: 2022/7/25 16:30
* Created by: dengbw
* @return mixed
* @throws Exception
*/
public function get_leave()
{
$id = $this->input_param('id');
if (!$id) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$this->load->model('receiver/receiver_customers_model', 'mdCustomer');
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
$count_1 = $this->mdCustomer->count(['biz_id' => $this->biz_id, 'admin_id' => $id]);
$count_2 = $this->mdOrders->count(['biz_id' => $this->biz_id, 'sale_id' => $id]);
$data['transfer'] = ['title' => '移交', 'list' => [['id' => 1, 'name' => "客户($count_1)", 'checked' => false]
, ['id' => 2, 'name' => "订单($count_2)", 'checked' => false]]];
$where = ['status' => 1, 'id<>' => $id, 'biz_id' => $this->biz_id];
$res = $this->app_user_model->select($where, 'id desc', 0, 0, 'id,uname as name');
$data['adviser'] = ['title' => '顾问', 'list' => $res ? $res : []];
return $data;
}
/**
* Notes:提交离职
* Created on: 2022/7/25 16:58
* Created by: dengbw
* @throws Exception
*/
public function put_leave()
{
$out_id = $this->input_param('out_id');
$in_id = $this->input_param('in_id');
$transfer = $this->input_param('transfer');
if (!$out_id || !$in_id || !$transfer) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$this->load->model('receiver/receiver_customers_model', 'mdCustomer');
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
$if_transfer = false;
foreach ($transfer['list'] as $k => $v) {
if ($v['id'] == 1 && $v['checked'] == true) {//移交客户
$this->mdCustomer->update(['admin_id' => $in_id], ['biz_id' => $this->biz_id, 'admin_id' => $out_id]);
$if_transfer = true;
} else if ($v['id'] == 2 && $v['checked'] == true) {//移交订单
$this->mdOrders->update(['admin_id' => $in_id], ['biz_id' => $this->biz_id, 'admin_id' => $out_id]);
$if_transfer = true;
}
}
if (!$if_transfer) {
throw new Exception('请选择移交选项', ERR_PARAMS_ERROR);
}
//更新顾问状态暂停
$this->app_user_model->update(['status' => 0], ['id' => $out_id]);
throw new Exception('操作成功', API_CODE_SUCCESS);
}
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'];
if ($ifconf) {
$where = [
"(biz_id=$this->biz_id or id=$uid)" => null,
'status' => 1
];
} else {
$where = [
'biz_id' => $this->biz_id,
'status>' => -1
];
}
$count = $this->app_user_model->count($where);
$lists = $tabs = $bizs = [];
if ($count) {
$fileds = 'id,uname,mobile,status';
$rows = $this->app_user_model->select($where, 'id desc', $page, $size, $fileds);
$lists = $rows;
}
$this->load->model("biz/biz_model");
$re_biz = $this->biz_model->get(['id' => $this->biz_id, 'status' => 1]);
if ($re_biz['type'] == 1) {//品牌店
$tabs = [['id' => 1, 'name' => '本店'], ['id' => 2, 'name' => '其它门店']];
$bizs = $this->biz_model->select(['type' => 1, 'status' => 1], 'id desc', 0, 0, 'id, biz_name as name');
}
$data = [
'list' => $lists,
'total' => $count,
'tabs' => $tabs,
'bizs' => $bizs,
];
return $data;
}
protected function post()
{
$group_id = $this->session['group_id'];
$name = $this->input_param('name');
$mobile = $this->input_param('mobile');
if ($group_id == 1) {
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' => $this->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 = [
'biz_id' => $this->biz_id,
'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 = [
'biz_id' => $this->biz_id,
'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);
}
}