314 行
11 KiB
PHP
可执行文件
314 行
11 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Retail\Business;
|
|
|
|
use Common\Business\Role;
|
|
use Common\Model\JurisdictionUserModel;
|
|
use Common\Model\RetailGuideModel;
|
|
use Common\Model\RetailStoreModel;
|
|
use Common\Model\RetailVipModel;
|
|
|
|
//[1.9.17]
|
|
|
|
/**
|
|
* 导购员
|
|
* Class Guide
|
|
* [
|
|
* getGuideList 获取导购员列表
|
|
* addGuideUser 添加导购员
|
|
* guideVerify 导购添加参数验证
|
|
* editGuideUser 编辑导购员
|
|
* delGuideUser 删除导购员
|
|
* ]
|
|
* @package Retail\Business
|
|
* @author GuYunQinFeng
|
|
*/
|
|
class Guide
|
|
{
|
|
private static $GuideModel;
|
|
|
|
public function __construct()
|
|
{
|
|
self::$GuideModel = new RetailGuideModel();
|
|
}
|
|
|
|
/**
|
|
* 获取导购员列表
|
|
* @param $param
|
|
* $param['store_id'] 门店id
|
|
* $param['merchant_id'] 商户id
|
|
* $param['guide_name'] 导购名称
|
|
* $param['add_time'] 添加时间
|
|
* @return array
|
|
*/
|
|
public function getGuideList($param)
|
|
{
|
|
$store_id = $param['store_id'];
|
|
$merchant_id = $param['merchant_id'];
|
|
$guidename = $param['guide_name'];
|
|
$add_time = $param['add_time'];
|
|
if (trim($guidename)) {
|
|
$map['guidename|phone'] = ['like', "%" . trim($guidename) . "%"];
|
|
}
|
|
$map['status'] = 1; // 在职导购
|
|
$map['storeid'] = $store_id;
|
|
$map['merchantid'] = $merchant_id;
|
|
if (!empty($add_time)) {
|
|
$start_time = strtotime($add_time[0]);
|
|
$end_time = strtotime($add_time[1]);
|
|
$map['addtime'] = ['between', [$start_time, $end_time]];
|
|
}
|
|
$guideList = self::$GuideModel->getSelect($map, '', 'addtime desc', "{$param['page']}, {$param['limit']}");
|
|
if ($guideList) {
|
|
$count = self::$GuideModel->getCount($map);
|
|
$RetailVipModel = new RetailVipModel();
|
|
$RetailStoreModel = new RetailStoreModel();
|
|
$store_name = $RetailStoreModel->getFindField(['id' => $store_id], 'storetag');
|
|
foreach ($guideList as $key => &$val) {
|
|
$val['index'] = $key + 1;
|
|
$val['status_name'] = $val['status'] == 1 ? '在职' : '离职';
|
|
$val['entrytime'] = date("Y-m-d", $val['entrytime']);
|
|
$val['storetag'] = $store_name;
|
|
$val['vip_number'] = $RetailVipModel->getCount(['guideid' => $val['id'], 'status' => 1]);
|
|
}
|
|
return callBack(statusCode()['success'], '数据获取成功', [
|
|
'list' => $guideList,
|
|
'count' => $count,
|
|
]);
|
|
} else {
|
|
return callBack(statusCode()['success'], '暂无数据', [
|
|
'list' => [],
|
|
'count' => 0,
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加导购员
|
|
* @param $param
|
|
* $param['store_id'] 门店id
|
|
* $param['merchant_id']商户id
|
|
* $param['operate_id'] 操作人员id
|
|
* $param['phone'] 手机号
|
|
* $param['pass'] 密码
|
|
* $param['guidename'] 名称
|
|
* $param['entrytime'] 入职时间
|
|
* $param['address'] 地址
|
|
* $param['jobnum'] 工号
|
|
* $param['paynumber'] 支付宝账号
|
|
* $param['chatnumber'] 微信账号
|
|
* $param['bank'] 提现银行id
|
|
* $param['cardholder'] 持卡人
|
|
* $param['cardnumber'] 银行卡号
|
|
* @return array
|
|
*/
|
|
public function addGuideUser($param)
|
|
{
|
|
$verifyResult = $this->guideVerify($param);
|
|
if ($verifyResult['status'] != 1) {
|
|
return $verifyResult;
|
|
}
|
|
$find = self::$GuideModel->getFind(['phone' => $param['phone'], 'status' => 1]);
|
|
if ($find) {
|
|
return callBack(statusCode()['error'], '该手机号已存在');
|
|
}
|
|
$jobNum = self::$GuideModel->getFind(['storeid' => $param['store_id'], 'jobnum' => $param['jobnum'], 'status' => 1]);
|
|
if ($jobNum) {
|
|
return callBack(statusCode()['error'], '该工号已被使用');
|
|
}
|
|
if (strlen($param['pass']) > 18 || strlen($param['pass']) < 6) {
|
|
return callBack(statusCode()['error'], '密码格式有误');
|
|
}
|
|
$time = time();
|
|
$data = [
|
|
'phone' => $param['phone'],
|
|
'guidename' => $param['guidename'],
|
|
'address' => $param['address'],
|
|
'jobnum' => $param['jobnum'],
|
|
'paynumber' => $param['paynumber'],
|
|
'chatnumber' => $param['chatnumber'],
|
|
'bank' => $param['bank'],
|
|
'cardholder' => $param['cardholder'],
|
|
'cardnumber' => $param['cardnumber'],
|
|
'pass' => createPassword($param['pass'], $time),
|
|
'entrytime' => strtotime($param['entrytime']),
|
|
'storeid' => $param['store_id'],
|
|
'merchantid' => $param['merchant_id'],
|
|
'addtime' => $time,
|
|
];
|
|
|
|
$guide_id = self::$GuideModel->addOrder($data);
|
|
if ($guide_id) {
|
|
//添加ls_jurisdiction_user
|
|
$Role = new Role();
|
|
$jurData = [
|
|
'login_name' => $data['phone'],
|
|
'password' => $data['pass'],
|
|
'name' => $data['guidename'],
|
|
'add_time' => $data['addtime'],
|
|
'user_type' => 5,
|
|
'system_user_id' => $guide_id,
|
|
'pid' => $param['operate_id'],
|
|
'jurisdiction_group_id' => $Role->createSystemGroup(['type' => 5]),
|
|
];
|
|
$JurisdictionUserModel = new JurisdictionUserModel();
|
|
$JurisdictionUserModel->addOrder($jurData);
|
|
return callBack(statusCode()['success'], '添加成功');
|
|
} else {
|
|
return callBack(statusCode()['error'], '添加失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加、编辑导购参数验证
|
|
* @param $param
|
|
* $param['phone'] 手机号
|
|
* $param['guidename'] 名称
|
|
* $param['entrytime'] 入职时间
|
|
* $param['address'] 地址
|
|
* $param['jobnum'] 工号
|
|
* $param['paynumber'] 支付宝账号
|
|
* $param['chatnumber'] 微信账号
|
|
* $param['bank'] 提现银行id
|
|
* $param['cardholder'] 持卡人
|
|
* $param['cardnumber'] 银行卡号
|
|
* @return array
|
|
*/
|
|
private function guideVerify($param)
|
|
{
|
|
if (!$param['phone']
|
|
|| !$param['guidename']
|
|
|| !$param['entrytime']
|
|
|| !$param['address']
|
|
|| !$param['jobnum']
|
|
|| !$param['paynumber']
|
|
|| !$param['chatnumber']
|
|
|| !$param['bank']
|
|
|| !$param['cardholder']
|
|
|| !$param['cardnumber']) {
|
|
return callBack(statusCode()['error'], '参数缺失');
|
|
}
|
|
return callBack(statusCode()['success'], '验证成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑导购员
|
|
* @param $param
|
|
* $param['data']
|
|
* $param['store_id'] 门店id
|
|
* @return array
|
|
*/
|
|
public function editGuideUser($param)
|
|
{
|
|
$verifyResult = $this->guideVerify($param);
|
|
if ($verifyResult['status'] != 1) {
|
|
return $verifyResult;
|
|
}
|
|
if (!$param['id']) {
|
|
return callBack(statusCode()['error'], '参数缺失');
|
|
}
|
|
$map = [
|
|
'id' => $param['id'],
|
|
'storeid' => $param['store_id'],
|
|
'status' => 1,
|
|
];
|
|
$find = self::$GuideModel->getFind($map);
|
|
if (!$find) {
|
|
return callBack(statusCode()['error'], '未查询到该导购');
|
|
}
|
|
if ($find['guidename'] != $param['guidename']) {
|
|
$update['guidename'] = $param['guidename'];
|
|
}
|
|
if ($find['jobnum'] != $param['jobnum']) {
|
|
$update['jobnum'] = $param['jobnum'];
|
|
}
|
|
if ($find['phone'] != $param['phone']) {
|
|
$old = self::$GuideModel->getFind(['id' => ['neq', $param['id'], 'phone' => $param['phone'], 'status' => 1]]);
|
|
if ($old) {
|
|
return callBack(statusCode()['error'], '该手机号已存在');
|
|
}
|
|
$update['phone'] = $param['phone'];
|
|
}
|
|
if ($param['pass']) {
|
|
$pass = createPassword($param['pass'], $find['addtime']);
|
|
if ($find['pass'] != $pass) {
|
|
$update['pass'] = $pass;
|
|
}
|
|
}
|
|
if ($find['entrytime'] != strtotime($param['entrytime'])) {
|
|
$update['entrytime'] = strtotime($param['entrytime']);
|
|
}
|
|
if ($find['address'] != $param['address']) {
|
|
$update['address'] = $param['address'];
|
|
}
|
|
if ($find['chatnumber'] != $param['chatnumber']) {
|
|
$update['chatnumber'] = $param['chatnumber'];
|
|
}
|
|
if ($find['paynumber'] != $param['paynumber']) {
|
|
$update['paynumber'] = $param['paynumber'];
|
|
}
|
|
if ($find['bank'] != $param['bank']) {
|
|
$update['bank'] = $param['bank'];
|
|
}
|
|
if ($find['cardholder'] != $param['cardholder']) {
|
|
$update['cardholder'] = $param['cardholder'];
|
|
}
|
|
if ($find['cardnumber'] != $param['cardnumber']) {
|
|
$update['cardnumber'] = $param['cardnumber'];
|
|
}
|
|
if (empty($update)) {
|
|
return callBack(statusCode()['error'], '您未修改导购员信息');
|
|
}
|
|
$save = self::$GuideModel->updateOrder(['id' => $param['id']], $update);
|
|
if ($save) {
|
|
if ($update['phone'] || $update['pass']) {
|
|
|
|
$JurUserModel = new JurisdictionUserModel();
|
|
$map = [
|
|
'user_type' => 5,
|
|
'system_user_id' => $param['id'],
|
|
];
|
|
if ($update['phone']) {
|
|
$up['login_name'] = $update['phone'];
|
|
}
|
|
if ($update['pass']) {
|
|
$up['password'] = $update['pass'];
|
|
}
|
|
$JurUserModel->updateOrder($map, $up);
|
|
}
|
|
return callBack(statusCode()['success'], '修改成功');
|
|
} else {
|
|
return callBack(statusCode()['error'], '修改失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除导购员
|
|
* @param $param
|
|
* $param $id 导购员id
|
|
* $param $store_id 门店id
|
|
* @return array
|
|
*/
|
|
public function delGuideUser($param)
|
|
{
|
|
$guide = self::$GuideModel->getFind(['id' => $param['id'], 'storeid' => $param['store_id'], 'status' => 1]);
|
|
if (!$guide) {
|
|
return callBack(statusCode()['error'], '未查询到该导购');
|
|
}
|
|
$save = self::$GuideModel->updateOrder(['id' => $param['id']], ['status' => 2]);
|
|
$JurisdictionModel = new JurisdictionUserModel();
|
|
$map = [
|
|
'system_user_id' => $param['id'],
|
|
'state' => 1,
|
|
'status' => 1,
|
|
'user_type' => 5,
|
|
];
|
|
$JurisdictionModel->updateOrder($map, ['state' => 0]);
|
|
if ($save) {
|
|
return callBack(statusCode()['success'], '删除成功');
|
|
} else {
|
|
return callBack(statusCode()['error'], '删除失败');
|
|
}
|
|
}
|
|
}
|