Commit 1e52baeb by mushishixian

tem

parent bc5d4b0e
Showing with 258 additions and 105 deletions
......@@ -4,10 +4,6 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Filter\SupplierFilter;
use App\Http\Exporter\SupplierListExporter;
use App\Http\Exporter\SupplierWordExporter;
use App\Http\Services\BlacklistService;
use App\Http\Services\DepartmentService;
use App\Http\Services\LogService;
use App\Http\Services\MessageService;
use App\Http\Services\SupplierAuditService;
......@@ -15,10 +11,9 @@ use App\Http\Services\SupplierService;
use App\Http\Services\SyncSupplierService;
use App\Http\Transformers\SupplierTransformer;
use App\Http\Validators\SupplierValidator;
use App\Model\SupplierBlacklistModel;
use App\Model\RedisModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
//通用API,比如获取品牌列表,分类列表等
class SupplierApiController extends Controller
......@@ -89,6 +84,7 @@ class SupplierApiController extends Controller
if (!$result) {
$this->response(-1, '操作失败');
}
$this->response(0, '操作成功');
}
......@@ -115,26 +111,30 @@ class SupplierApiController extends Controller
public function GetSupplierList(Request $request)
{
$model = new SupplierChannelModel();
$query = $model;
$query = $model->orderBy('update_time', 'desc');
$filter = new SupplierFilter();
$query = $filter->listFilter($request, $query);
$limit = $request->get('limit', 10);
$list = $query->paginate($limit)->toArray();
$transformer = new SupplierTransformer();
$list['data'] = $transformer->transformList($list['data']);
if (env('LOGIN_DOMAIN') == 'user.liexin.net') {
$list['total'] = $list['total'] > 10 ? 10 : $list['total'];
}
// if (env('LOGIN_DOMAIN') == 'user.liexin.net') {
// $list['total'] = $list['total'] > 10 ? 10 : $list['total'];
// }
$this->response(0, 'ok', $list['data'], $list['total']);
}
public function DisableSupplier($request)
{
//禁用不是直接修改为无法交易,而是改为待审核,然后审核通过后,变成无法交易
$supplierId = $request->get('supplier_id');
$model = new SupplierChannelModel();
$redis = new RedisModel();
//存到redis做数据对比
$redis->hset('audit_disable_supplier_list', $supplierId, 1);
$result = $model->where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => $model::STATUS_DISABLE,
'status' => $model::STATUS_IN_REVIEW,
]);
if ($result) {
//发送队列消息同步到金蝶
......
......@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Filter;
use App\Http\Services\AdminUserService;
use App\Http\Services\DepartmentService;
use App\Model\SupplierChannelModel;
use Illuminate\Support\Facades\DB;
class SupplierFilter
......@@ -14,60 +15,10 @@ class SupplierFilter
public function listFilter($request, $query)
{
$map = $request->all();
//判断权限,如果有审核权限的,可以查看所有成员的数据
//超管可以查看所有
$userId = $request->user->userId;
$isLeader = perm($userId, 'LeaderView');
$query = $query->with([
'blacklist'
]);
//先判断获取类型
$sourceType = array_get($map, 'source_type');
switch ($sourceType) {
case "all":
//这个页面会给部门老大查看的,只能看到自己下面的人员申请的供应商
//审核人或者超管,看全部
if ($isLeader) {
$departmentService = new DepartmentService();
//下属用户id
$subordinateUserIds = $departmentService->getSubordinateUserIds($userId);
$query->whereIn('create_uid', $subordinateUserIds);
}
$query->where('status', '!=', -3)->where('status', '!=', -1);
$query->orderBy('supplier_id', 'desc');
break;
case "own":
//自己的供应商,只显示属于自己的(排除黑名单)
$adminUserService = new AdminUserService();
$userCode = $adminUserService->getCodeIdByUserId($userId);
if ($userCode && empty($map['create_uid'])) {
$query->whereRaw(DB::raw("(create_uid = $userId or purchase_uid = $userCode or channel_uid like '%${userCode}%') "));
// $query->whereRaw(DB::raw("(create_uid = $userId or channel_uid like '%${userCode}%') "));
} else {
$query->where('create_uid', $userId);
}
$query->where('status', '!=', -3);
$query->orderBy('supplier_id', 'desc');
break;
case "audited":
//已审核列表只显示 启用,禁用,驳回
$query->whereIn('status', [2, 3, -2]);
$query->orderBy('audit_time', 'desc');
break;
default:
$status = $request->get('status', 0);
$statusArray = explode(',', $status);
if (!empty($statusArray)) {
$query->whereIn('status', $statusArray);
}
$query->orderBy('supplier_id', 'desc');
break;
}
//显示默认的数据(有权限逻辑)
$query = $this->defaultFilter($query, $map['source_type']);
//判断筛选参数
if ($request->user->userId != 1443) {
$query->where('is_type', 0);
}
if (!empty($map['supplier_name'])) {
$query->where('supplier_name', 'like', "%{$map['supplier_name']}%");
......@@ -94,6 +45,15 @@ class SupplierFilter
if (!empty($map['status'])) {
$query->where('status', $map['status']);
}
if (!empty($map['has_sku'])) {
if ($map['has_sku'] == 1) {
$query->where('sku_num', '>', 0);
} else {
$query->where('sku_num', 0);
}
}
if (!empty($map['create_time'])) {
$times = explode('~', $map['create_time']);
$startTime = strtotime($times[0]);
......@@ -111,4 +71,99 @@ class SupplierFilter
return $query;
}
public function defaultFilter($query, $sourceType)
{
$userId = request()->user->userId;
$codeId = request()->user->codeId;
$canViewAllSupplier = checkPerm('ViewAllSupplier');
$canViewSubordinateSupplier = checkPerm('ViewSubordinateSupplier');
if (request()->user->userId != 1443 || !$canViewAllSupplier) {
$query->where('is_type', 0);
}
//默认展示的数据查询
//看全部的权限,优先级最高
if ($canViewAllSupplier) {
//能查看所有的话,限制基本没有
} else {
//如果能看部下的,那需要判断的地方就多了不少
if ($canViewSubordinateSupplier) {
$departmentService = new DepartmentService();
//下属用户id(结果包括自己的id)
$subordinateUserIds = $departmentService->getSubordinateUserIds($userId);
$adminUserService = new AdminUserService();
$subordinateCodeIds = $adminUserService->getCodeIdsByUserIds($subordinateUserIds);
//因为可以查看自己部下相关的采购员,开发员的供应商,所以要构建复杂likeIn语句需要的数据
//注意下面三个条件最外层要用()包围起来,要不然mysql数据会有问题,具体自己查询mysql的and和or的语法注意事项
$likeSqlRaw = implode('|', $subordinateCodeIds);
$inCodeIdSql = implode(',', $subordinateCodeIds);
$inUserIdSql = implode(',', $subordinateUserIds);
$inCodeIdSql = "(" . $inCodeIdSql . ")";
$inUserIdSql = "(" . $inUserIdSql . ")";
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql or purchase_uid in $inCodeIdSql or channel_uid REGEXP '$likeSqlRaw') "));
} else {
//剩下的就只是看自己相关的
$query->whereRaw(DB::raw("(create_uid = $userId or purchase_uid = $codeId or channel_uid like '%${codeId}%') "));
}
}
//先判断获取类型
switch ($sourceType) {
case "all":
break;
case "pending":
//待审核供应商(其实就是没有提交审核申请的,默认是草稿
$query->where('status', SupplierChannelModel::STATUS_PENDING);
break;
case "in_review":
//审核中
$query->where('status', SupplierChannelModel::STATUS_IN_REVIEW);
break;
case "passed":
//已通过
$query->where('status', SupplierChannelModel::STATUS_PASSED);
break;
case "rejected":
//未通过
$query->where('status', SupplierChannelModel::STATUS_REJECT);
break;
case "disable":
//未通过
$query->where('status', SupplierChannelModel::STATUS_DISABLE);
break;
case "no_purchase_uid":
//没有渠道开发
$query->where('status', '!=', SupplierChannelModel::STATUS_DISABLE)
->where('purchase_uid', '');
break;
case "invalid_channel_uid":
//不合理的采购(比如采购离职了)
$adminUserService = new AdminUserService();
$resignedUsers = $adminUserService->getResignedUsers();
$resignedUserCodes = array_column($resignedUsers, 'code_id');
//存在无效(离职)开发员
$query->where('status', '!=', SupplierChannelModel::STATUS_DISABLE)
->whereIn('purchase_uid', $resignedUserCodes);
break;
case "invalid_purchase_uid":
//不合理的渠道开发(比如渠道开发离职了)
$adminUserService = new AdminUserService();
$resignedUsers = $adminUserService->getResignedUsers();
$resignedUserCodes = array_column($resignedUsers, 'code_id');
//存在无效(离职)开发员
$query->where('status', '!=', SupplierChannelModel::STATUS_DISABLE)
->whereIn('purchase_uid', $resignedUserCodes);
break;
case "to_follow_up":
//待跟进
$query->where('to_follow_up', 1);
break;
case "no_sku":
//没有sku
$query->where('sku_num', 0);
break;
}
return $query;
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@
namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\IntracodeModel;
use App\Model\UserInfoModel;
use Illuminate\Support\Facades\DB;
class AdminUserService
......@@ -11,26 +13,37 @@ class AdminUserService
public function getAdminUserInfoByCodeId($codeId)
{
$adminId = DB::connection()->table('lie_intracode')->where('code_id', $codeId)->value('admin_id');
return DB::connection()->table('user_info')->where('userId', $adminId)->first();
$intracodeModel = new IntracodeModel();
$userInfoModel = new UserInfoModel();
$adminId = $intracodeModel->where('code_id', $codeId)->value('admin_id');
return $userInfoModel->where('userId', $adminId)->first();
}
public function getCodeIdByUserId($userId)
{
return DB::connection()->table('lie_intracode')->where('admin_id', $userId)->value('code_id');
$intracodeModel = new IntracodeModel();
return $intracodeModel->where('admin_id', $userId)->value('code_id');
}
public function getAdminUserInfo($userId)
{
$user = DB::connection()->table('user_info')->where('userId', $userId)->first();
$userInfoModel = new UserInfoModel();
$user = $userInfoModel->where('userId', $userId)->first();
return $user ?: [];
}
//获取离职人员列表
public function getResignedUsers()
{
$user = DB::connection()->table('user_info')->leftJoin('lie_intracode','user_info.userId','=','lie_intracode.admin_id')
->where('user_info.status', 4)->where('lie_intracode.code_id','!=','')->get();
return $user ?: [];
$userInfoModel = new UserInfoModel();
$user = $userInfoModel->leftJoin('lie_intracode', 'user_info.userId', '=', 'lie_intracode.admin_id')
->where('user_info.status', 4)->where('lie_intracode.code_id', '!=', '')->get();
return $user ? $user->toArray() : [];
}
public function getCodeIdsByUserIds($userIds)
{
$intracodeModel = new IntracodeModel();
return $intracodeModel->whereIn('admin_id', $userIds)->pluck('code_id');
}
}
\ No newline at end of file
......@@ -9,6 +9,10 @@ use Illuminate\Support\Facades\DB;
class LogService
{
//供应商不同数据库字段对应的中文,用于日志记录
public $fieldMapToLogContent = [
'supplier_name' => '供应商名称',
];
//添加日志
public function AddLog($supplierId, $type, $action, $content, $remark = '')
{
......
......@@ -89,17 +89,27 @@ class SupplierService
$channel['create_time'] = time();
$supplierId = $model->insertGetId($channel);
$this->saveSupplierCode($supplierId);
$logAction = "新增供应商";
$logContent = '新增供应商';
$logRemark = '';
} else {
$extraFaxService = new SupplierExtraFeeService();
$extraFaxService->saveSupplierExtraFee($extraFax);
$supplierId = $channel['supplier_id'];
$supplierData = $model->where('supplier_id', $supplierId)->first();
$model->where('supplier_id', $supplierId)->update($channel);
$this->saveSupplierCode($supplierId);
$logAction = "更新供应商";
$logContent = "更新供应商";
$logRemark = json_encode($supplierData);
}
//插入系数到redis
$this->saveRatioToRedis($supplierId);
//重新生成外部显示的编码
$supplierSn = $this->generateSupplierSn($supplierId, $channel['supplier_group']);
//保存日志
$logService = new LogService();
$logService->AddLog($supplierId, 1, $logAction, $logContent, $logRemark);
//修改数据
$model->where('supplier_id', $supplierId)->update(['supplier_sn' => $supplierSn]);
// $messageService = new MessageService();
......
......@@ -3,6 +3,7 @@
namespace App\Http\Services;
use App\Http\Controllers\Filter\SupplierFilter;
use App\Model\SupplierChannelModel;
use Illuminate\Support\Facades\DB;
......@@ -11,37 +12,30 @@ class SupplierStatisticsService
//获取供应商列表需要统计的信息
public function getSupplierListStatistics()
{
$model = new SupplierChannelModel();
$total = $model->count();
$total = $this->getStatisticsCount('all');
//待审核,就是以前的草稿
$pending = $model->where('status', $model::STATUS_PENDING)->count();
$pending = $this->getStatisticsCount('pending');
//审核中
$inReview = $model->where('status', $model::STATUS_IN_REVIEW)->count();
$inReview = $this->getStatisticsCount('in_review');
//通过
$passed = $model->where('status', $model::STATUS_PASSED)->count();
$passed = $this->getStatisticsCount('passed');
//未通过
$rejected = $model->where('status', $model::STATUS_REJECT)->count();
$rejected = $this->getStatisticsCount('rejected');
//禁用
$disable = $model->where('status', $model::STATUS_DISABLE)->count();
$disable = $this->getStatisticsCount('disable');
//没有渠道开发员
$noPurchaseUid = $model->where('status', '!=', $model::STATUS_DISABLE)->where('purchase_uid', '=', '')->count();
//没有sku的
$noSku = $model->where('sku_num', '==', 0)->count();
$adminUserService = new AdminUserService();
$resignedUsers = $adminUserService->getResignedUsers();
$resignedUserCodes = array_column($resignedUsers, 'code_id');
//存在无效(离职)开发员
$invalidPurchaseUid = $model->where('status', '!=', $model::STATUS_DISABLE)
->whereIn('purchase_uid', $resignedUserCodes)->count();
//构建likeIn语句需要的数据
$likeSqlRaw = implode('|', $resignedUserCodes);
$noPurchaseUid = $this->getStatisticsCount('no_purchase_uid');
//存在无效(离职)采购员
$invalidChannelUid = $model->where('status', '!=', $model::STATUS_DISABLE)
->whereRaw(DB::raw("channel_uid REGEXP '$likeSqlRaw'"))->count();
//待跟进
$toFollowUp = $model->where('status', '!=', $model::STATUS_DISABLE)->where('to_follow_up', 1)->count();
$invalidChannelUid = $this->getStatisticsCount('invalid_channel_uid');
//存在无效(离职)开发员
$invalidPurchaseUid = $this->getStatisticsCount('invalid_purchase_uid');
//需要跟进的
$toFollowUp = $this->getStatisticsCount('to_follow_up');
//没有sku的
$noSku = $this->getStatisticsCount('no_sku');
$result = [
$result = [
'total' => $total,
'pending' => $pending,
'in_review' => $inReview,
......@@ -59,8 +53,17 @@ class SupplierStatisticsService
$value = '999+';
}
return $value;
},$result);
}, $result);
return $result;
}
private function getStatisticsCount($type)
{
$model = new SupplierChannelModel();
$model = $model->where('supplier_id','>',0);
//显示默认的数据(有权限逻辑)
$filter = new SupplierFilter();
return $filter->defaultFilter($model, $type)->count();
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class UserInfoModel extends Model
{
protected $table='user_info';
protected $primaryKey = 'userId';
public $timestamps = false;
}
......@@ -6,7 +6,7 @@ namespace App\Presenters\Filter;
class DayTypePresenter
{
public function render($map = [], $linkageName = '')
public function render($relateObjName = '')
{
$unique = "unique_" . mt_rand(1, 100000);
$html = <<<EOF
......
......@@ -27,6 +27,7 @@ class TransformableInputPresenter
</div>
</div>
<script>
$(function() {
layui.use(['form', 'element'], function () {
let form = layui.form;
form.on('select($unique)', function(data){
......@@ -34,6 +35,8 @@ class TransformableInputPresenter
form.render();
});
});
});
</script>
EOF;
return $html;
......
......@@ -29,12 +29,15 @@ class TransformableSelectPresenter
</div>
</div>
<script>
layui.use(['form', 'element'], function () {
$(function() {
layui.use(['form', 'element'], function () {
let form = layui.form;
form.on('select($unique)', function(data){
data.othis.parent().parent().parent().find('.value_select').attr('name',data.value);
});
});
});
</script>
EOF;
return $html;
......
......@@ -4,16 +4,21 @@
namespace App\Presenters\Filter;
use Carbon\Carbon;
class TransformableTimeIntervalPresenter
{
public function render($map = [])
{
$unique = "unique_" . mt_rand(1, 100000);
$defaultKey = array_keys($map)[0];
$todayTimeInterval = Carbon::now()->startOfDay()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$threeDayTimeInterval = Carbon::now()->subDay(3)->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$thisWeekTimeInterval = Carbon::now()->startOfWeek()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$thisMonthTimeInterval = Carbon::now()->startOfMonth()->toDateString() . ' ~ ' . Carbon::now()->addDay(1)->toDateString();
$html = <<<EOF
<div class="layui-row" style="width:268px;margin-bottom: 3px;">
<div class="layui-row" style="margin-bottom: 3px;">
<div class="layui-col-md6">
<div class="layui-col-md5">
<div class="layui-input-inline" style="width: 100px;margin-left: 10px">
<select lay-filter="$unique">
......@@ -21,14 +26,42 @@ class TransformableTimeIntervalPresenter
</select>
</div>
</div>
<div class="layui-col-md7" style="margin-left: -3px">
<div class="layui-col-md7" style="margin-left: -15px">
<div class="layui-input-inline" style="min-width: 150px;width: 158px">
<input type="text" name="$defaultKey" id="$unique" placeholder="请选择时间区间" autocomplete="off" class="layui-input">
</div>
</div>
</div>
<div class="layui-col-md6">
<div style="margin-top: 5px;">
<div class="layui-col-md2" style="margin-left: 5px">
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm day_type_button"
dateInterval="$todayTimeInterval"
id="${unique}_today">今日</button>
</div>
<div class="layui-col-md2">
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm day_type_button"
dateInterval="$threeDayTimeInterval"
id="${unique}_last_days">近三天</button>
</div>
<div class="layui-col-md2">
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm day_type_button" style="margin-left: 11px"
dateInterval="$thisWeekTimeInterval"
id="${unique}_this_week">本周</button>
</div>
<div class="layui-col-md2">
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm day_type_button" style="margin-left: 10px"
dateInterval="$thisMonthTimeInterval"
id="${unique}_this_month">本月</button>
</div>
<div class="layui-col-md3">
</div>
</div>
</div>
</div>
<script>
layui.use(['form', 'element','laydate'], function(){
$(function() {
layui.use(['form', 'element','laydate'], function(){
let laydate = layui.laydate;
let form = layui.form;
form.on('select($unique)', function(data){
......@@ -38,9 +71,23 @@ class TransformableTimeIntervalPresenter
elem: '#$unique'
,type: 'date'
,trigger:'click'
,range: '-' //或 range: '~' 来自定义分割字符
,range: '~' //或 range: '~' 来自定义分割字符
});
$('.day_type_button').click(function() {
$('.day_type_button').attr('class','layui-btn layui-btn-primary layui-btn-sm day_type_button');
$(this).attr('class','layui-btn layui-btn-sm layui-btn-normal day_type_button');
alert($(this).attr('dateInterval'));
laydate.render({
elem: '#$unique'
,type: 'date'
,value: $(this).attr('dateInterval')
,trigger:'click'
,range: '~' //或 range: '~' 来自定义分割字符
});
});
});
})
</script>
EOF;
......
......@@ -7,7 +7,7 @@ layui.config({ // common.js是配置layui扩展模块的目录,每个页面
steps: 'steps/steps',
notice: 'notice/notice',
cascader: 'cascader/cascader',
dropdown: 'dropdown/dropdown',
// dropdown: 'dropdown/dropdown',
fileChoose: 'fileChoose/fileChoose',
Split: 'Split/Split',
Cropper: 'Cropper/Cropper',
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment