<?php namespace App\Http\Controllers; use App\Http\Services\LogService; use App\Http\Services\RegionService; use App\Http\Services\SupplierAttachmentService; use App\Http\Services\SupplierService; use App\Http\Services\SupplierStatisticsService; use App\Http\Transformers\LogTransformer; use App\Http\Transformers\SupplierTransformer; use App\Model\IntracodeModel; use App\Model\LogModel; use App\Model\SupplierChannelModel; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class SupplierController extends Controller { public function info(Request $request, $id = '') { { if ($request->path() == '/') { $path = 'web/index'; } else { $path = $request->path(); } $this->data = [ 'menus' => $request->menus, 'header' => $request->user->header, 'username' => $request->user->email, 'user_email' => $request->user->email, 'uri' => '/' . $path, 'id' => $id ]; $userId = $request->user->userId; $canAudit = perm($userId, 'AuditSupplier'); $this->data['canAudit'] = $canAudit; //把是否是领导查看放到模板,用来区分部门老大能干的权限 $leaderView = perm($userId, 'LeaderView'); $this->data['leaderView'] = $leaderView; return $this->$id($request); } } public function __call($name, $arr) { $data['errinfo'] = '访问路径错误'; return view('errors.error', $data); } //供应商列表 public function SupplierList($request) { //判断权限 $intracodeModel = new IntracodeModel(); $this->data['userCodes'] = $intracodeModel->getChannelUsersEncode(); $this->data['users'] = $intracodeModel->getAdminUserAndCode(); $supplierStatisticsService = new SupplierStatisticsService(); $statistics = $supplierStatisticsService->getSupplierListStatistics(); $this->data['statistics'] = $statistics; $this->data['validPerms'] = []; return $this->view('供应商列表'); } //供应商详情 public function SupplierDetail($request) { $supplierId = $request->get('supplier_id'); $supplierService = new SupplierService(); $supplier = $supplierService->getSupplier($supplierId); if (empty($supplier)) { return '供应商不存在'; } //记录查看日志(1个小时内查看的跳过) $logModel = new LogModel(); $lastViewAddTime = $logModel->where('supplier_id', $supplierId)->where('admin_id', $request->user->userId) ->where('type', LogModel::VIEW_OPERATE)->orderBy('id', 'desc')->value('add_time'); $oneHourTimestamp = 3600; if (time() - $lastViewAddTime > $oneHourTimestamp) { $logService = new LogService(); $logService->AddLog($supplierId, LogModel::VIEW_OPERATE, '查看', '查看供应商详情'); } $this->data['operate'] = 'detail'; $this->data['supplier'] = $supplier; $regionService = new RegionService(); $regionNames = $regionService->getRegionNameByIds([ $supplier['province_id'], $supplier['city_id'] ]); $this->data['province_city'] = implode(' | ', $regionNames); $this->data['address'] = $supplierService->getAddress($supplierId); $supplierAttachmentService = new SupplierAttachmentService(); $this->data['attachment'] = $supplierAttachmentService->getAttachment($supplierId); // dd($supplierAttachmentService->getAttachment($supplierId)); return $this->view('供应商详情'); } //添加供应商 public function AddSupplier($request) { $supplierId = $request->get('supplier_id'); $supplierService = new SupplierService(); $intracodeModel = new IntracodeModel(); $this->data['outside_contact_status'] = Config('fixed.OutsideContactStatus'); $this->data['outside_contact_type'] = Config('fixed.OutsideContactType'); $userCodes = $intracodeModel->getChannelUsersEncode(); $this->data['userCodes'] = $userCodes; $this->data['user'] = $userCodes; $this->data['purchase_users'] = []; foreach ($userCodes as $userId => $code) { $this->data['purchase_users'][] = [ 'name' => $code, 'value' => $userId, ]; } $this->data['operate'] = 'add'; //省市区数据放到script模板 $regionService = new RegionService(); $this->data['region_data'] = $regionService->getCityRegionData(); //编辑 if (!empty($supplierId)) { $this->data['title'] = '编辑供应商'; $this->data['supplierInfo'] = $supplierService->getSupplier($supplierId); $DB = DB::connection('yunxin'); $supplierAccountInfo = $DB->table('supplier_account')->where("supplier_com_id", "=", $supplierId)->select('mobile', "password_raw")->first(); $this->data['supplier_account_info'] = $supplierAccountInfo; $this->data['address'] = $supplierService->getAddress($supplierId); } else { $this->data['title'] = '添加供应商'; } return $this->view('新增供应商'); } //编辑供应商 public function UpdateSupplier($request) { $intracodeModel = new IntracodeModel(); $userCodes = $intracodeModel->getSampleEncode(); $this->data['userCodes'] = $intracodeModel->getChannelUsersEncode(); $this->data['user'] = $userCodes; $this->data['purchase_users'] = []; $this->data['operate'] = 'update'; foreach ($userCodes as $userId => $code) { $this->data['purchase_users'][] = [ 'name' => $code, 'value' => $userId, ]; } //省市区数据放到script模板 $regionService = new RegionService(); $this->data['region_data'] = $regionService->getCityRegionData(); //编辑 $this->data['title'] = '编辑供应商'; $supplierId = $request->get('supplier_id'); $supplierService = new SupplierService(); $supplier = $supplierService->getSupplier($supplierId); if (empty($supplier)) { return '供应商不存在'; } //省市id,给控件用 $this->data['province_city'] = [$supplier['province_id'], $supplier['city_id']]; $this->data['supplier'] = $supplier; $this->data['address'] = $supplierService->getAddress($supplierId); $supplierAttachmentService = new SupplierAttachmentService(); $this->data['attachment'] = $supplierAttachmentService->getAttachment($supplierId); return $this->view('编辑供应商'); } //审核供应商 public function AuditSupplier($request) { $supplierId = $request->get('supplier_id'); $model = new SupplierChannelModel(); $supplier = $model->where('supplier_id', $supplierId)->first(); //获取最后一条非分配渠道员的日志 $logModel = new LogModel(); $auditContent = $logModel->where('supplier_id', $supplierId) // ->where('action', '!=', '分配渠道开发员') ->where('action', '!=', '') ->where('type', '!=', 3) ->orderBy('id', 'desc')->first(); if (!empty($auditContent)) { $logTransformer = new LogTransformer(); $auditContent = $logTransformer->transformInfo($auditContent); } else { $auditContent = []; } $this->data['auditContent'] = $auditContent; $this->data['supplier'] = $supplier ? $supplier->toArray() : []; return $this->view('审核供应商'); } //分配渠道员 public function AllocatePurchaseUser($request) { $supplierId = $request->get('supplier_id'); $model = new SupplierChannelModel(); $supplier = $model->where('supplier_id', $supplierId)->first(); $supplier = $supplier ? $supplier->toArray() : []; $transformer = new SupplierTransformer(); $supplier = $transformer->transformInfo($supplier); $this->data['supplier'] = $supplier; $intracodeModel = new IntracodeModel(); $this->data['userCodes'] = $intracodeModel->getChannelUsersEncode(); $logModel = new LogModel(); $this->data['logs'] = $logModel->where('supplier_id', $supplierId) ->where('action', '分配渠道开发员')->orderBy('id', 'desc') ->limit(10)->get(); return $this->view('审核供应商'); } //批量分配渠道开发员 public function BatchAllocatePurchaseUser($request) { $supplierIds = $request->get('supplier_ids'); $this->data['supplierIds'] = $supplierIds; $supplierIds = explode(',', $supplierIds); $model = new SupplierChannelModel(); $suppliers = $model->whereIn('supplier_id', $supplierIds)->get()->toArray(); $transformer = new SupplierTransformer(); $suppliers = $transformer->transformList($suppliers); $this->data['suppliers'] = $suppliers; $intracodeModel = new IntracodeModel(); $this->data['userCodes'] = $intracodeModel->getChannelUsersEncode(); return $this->view('批量分配渠道开发员'); } //添加采购员 public function AllocateChannelUser($request) { $supplierId = $request->get('supplier_id'); $model = new SupplierChannelModel(); $supplier = $model->where('supplier_id', $supplierId)->first(); $supplier = $supplier ? $supplier->toArray() : []; $transformer = new SupplierTransformer(); $supplier = $transformer->transformInfo($supplier); $this->data['supplier'] = $supplier; $intracodeModel = new IntracodeModel(); $this->data['userCodes'] = $intracodeModel->getChannelUsersEncode(); return $this->view('添加采购员'); } //操作日志列表 public function LogList($request, $data) { $intracodeModel = new IntracodeModel(); $data['userCodes'] = $intracodeModel->getSampleEncode(); $data['title'] = '操作日志记录'; return view('web', $data); } //分配云芯采购员 public function SetYunxinChannelUser($request) { $supplierId = $request->get('supplier_id'); $model = new SupplierChannelModel(); $supplier = $model->where('supplier_id', $supplierId)->first(); $supplier = $supplier ? $supplier->toArray() : []; $this->data['supplier'] = $supplier; $intracodeModel = new IntracodeModel(); $userCodes = $intracodeModel->getSampleEncode(); //去除非当前供应商所拥有的采购的人员,只能从当前供应商设置的采购里面选择云芯采购员 $channelUids = explode(',', $supplier['channel_uid']); foreach ($userCodes as $codeId => $value) { if (!in_array($codeId, $channelUids)) { unset($userCodes[$codeId]); } } $this->data['userCodes'] = $userCodes; return $this->view('审核供应商'); } //拉黑供应商 public function BlockSupplier($request) { $supplierId = $request->get('supplier_id'); $supplierModel = new SupplierChannelModel(); $supplier = $supplierModel->where('supplier_id', $supplierId)->first()->toArray(); $this->data['supplier'] = $supplier; return $this->view('加入黑名单'); } //导出供应商详情表格 public function PrintSupplier($request) { $supplierService = new SupplierService(); $supplierId = $request->get('supplier_id'); $printData = $supplierService->getSupplierPrintData($supplierId); $this->data['printData'] = $printData; return $this->view('打印供应商详情'); } //批量申请审批供应商 public function BatchApplyInReviewSupplier($request) { $supplierIds = $request->get('supplier_ids'); $this->data['supplierIds'] = $supplierIds; $supplierIds = explode(',', $supplierIds); $model = new SupplierChannelModel(); $suppliers = $model->whereIn('supplier_id', $supplierIds)->get()->toArray(); $transformer = new SupplierTransformer(); $suppliers = $transformer->transformList($suppliers); $this->data['suppliers'] = $suppliers; return $this->view('批量分配渠道开发员'); } }