Commit f3014987 by mushishixian

审核状态

parent aef138ec
......@@ -7,6 +7,7 @@ use App\Http\Services\LogService;
use App\Http\Services\SupplierContactService;
use App\Http\Transformers\SupplierContactTransformer;
use App\Http\Validators\SupplierContactValidator;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use Illuminate\Http\Request;
......@@ -69,6 +70,12 @@ class SupplierContactApiController extends Controller
if (!$result) {
$this->response(-1, '删除失败');
}
$supplierId = $model->where('contact_id', $contactId)->value('supplier_id');
$supplierModel = new SupplierChannelModel();
$supplierModel->where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => 1,
]);
$this->response(0, '删除成功');
}
$this->response(-1, '找不到删除对象');
......
......@@ -8,6 +8,7 @@ use App\Http\Transformers\LogTransformer;
use App\Http\Transformers\ReceiptTransformer;
use App\Http\Validators\ReceiptValidator;
use App\Model\LogModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierReceiptModel;
use Illuminate\Http\Request;
......@@ -66,6 +67,12 @@ class SupplierReceiptApiController extends Controller
$result = $model->insert($receipt);
}
if ($result) {
//供应商变成待审核
$supplierModel = new SupplierChannelModel();
$supplierModel->where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => 1,
]);
$logService = new LogService();
$content = !empty($receipt['receipt_id']) ? '修改银行信息' : '添加银行信息';
$remark = json_encode($receipt);
......@@ -82,6 +89,13 @@ class SupplierReceiptApiController extends Controller
$model = new SupplierReceiptModel();
$result = $model->where('receipt_id', $receiptId)->delete();
if ($result) {
//修改供应商为审核状态
$supplierId = $model->where('receipt_id', $receiptId)->value('supplier_id');
$supplierModel = new SupplierChannelModel();
$supplierModel->where('supplier_id', $supplierId)->update([
'update_time' => time(),
'status' => 1,
]);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
......
......@@ -40,14 +40,13 @@ class LogController extends Controller
public function SupplierLog($request)
{
$supplierId = $request->get('supplier_id',1);
$supplierId = $request->get('supplier_id', 1);
$logModel = new LogModel();
// $logs = $logModel->where('supplier_id', $supplierId)->get();
$logs = $logModel->orderBy('id', 'desc')->get();
$updateLogs = $logModel->orderBy('id', 'desc')->get();
$viewLogs = $logModel->orderBy('id', 'desc')->get();
$logs = $logModel->where('supplier_id', $supplierId)->orderBy('id', 'desc')->get();
$updateLogs = $logModel->where('supplier_id', $supplierId)->where('type', LogModel::UPDATE_OPERATE)->orderBy('id', 'desc')->get();
$viewLogs = $logModel->where('supplier_id', $supplierId)->where('type', LogModel::VIEW_OPERATE)->orderBy('id', 'desc')->get();
$supplierLogModel = new SupplierLogModel();
$supplierLogs = $supplierLogModel->orderBy('id', 'desc')->get();
$supplierLogs = $supplierLogModel->where('supplier_id', $supplierId)->orderBy('id', 'desc')->get();
$this->data['logs'] = $logs;
$this->data['supplierId'] = $supplierId;
$this->data['updateLogs'] = $updateLogs;
......
......@@ -5,6 +5,7 @@ namespace App\Http\Services;
use App\Model\LogModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
class SupplierContactService
......@@ -49,10 +50,19 @@ class SupplierContactService
$contact['add_time'] = time();
$result = $model->insert($contact);
}
$logService = new LogService();
$content = !empty($contact['contact_id'])?'修改联系人':'添加联系人';
$remark = json_encode($contact);
$logService->AddLog($contact['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
if ($result) {
//修改供应商为审核状态
$supplierModel = new SupplierChannelModel();
$supplierModel->where('supplier_id', $contact['supplier_id'])->update([
'update_time' => time(),
'status' => 1,
]);
$logService = new LogService();
$content = !empty($contact['contact_id'])?'修改联系人':'添加联系人';
$remark = json_encode($contact);
$logService->AddLog($contact['supplier_id'], LogModel::UPDATE_OPERATE, '修改供应商基本资料', $content, $remark);
}
return $result;
}
......
......@@ -88,6 +88,7 @@ class SupplierService
$channel['create_uid'] = request()->user->userId;
$channel['create_name'] = request()->user->name;
$channel['create_time'] = time();
$channel['status'] = SupplierChannelModel::STATUS_PENDING;
$supplierId = $model->insertGetId($channel);
$this->saveSupplierCode($supplierId);
$logAction = "新增供应商";
......@@ -99,15 +100,16 @@ class SupplierService
$extraFaxService->saveSupplierExtraFee($extraFax);
$supplierId = $channel['supplier_id'];
$oldSupplier = $model->where('supplier_id', $supplierId)->first();
$channel['status'] = SupplierChannelModel::STATUS_IN_REVIEW;
$model->where('supplier_id', $supplierId)->update($channel);
$newSupplier = $model->where('supplier_id', $supplierId)->first();
$this->saveSupplierCode($supplierId);
$logAction = "更新供应商";
$logContent = "更新供应商";
$logRemark = json_encode([
'old' => $oldSupplier,
'new' => $newSupplier
]);
'old' => $oldSupplier,
'new' => $newSupplier
]);
}
//插入系数到redis
$this->saveRatioToRedis($supplierId);
......
......@@ -7,6 +7,7 @@ namespace App\Http\Transformers;
use App\Http\Services\AdminUserService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\LogModel;
use App\Model\RedisModel;
use App\Model\SupplierContactModel;
use App\Model\SupplierExtendModel;
......@@ -126,6 +127,11 @@ class SupplierTransformer
$ExtendModel = new SupplierExtendModel();
//获取该supplier_code对应的数据
$supplier['extra_fee'] = $ExtendModel->getExtendExtra($supplier['supplier_code'], $supplier['supplier_id']);
//获取最近修改信息
$logModel = new LogModel();
$log = $logModel->where('supplier_id',$supplier['supplier_id'])->orderBy('id','desc')->first();
$supplier['last_update_name'] = $log['admin_name'];
$supplier['last_update_time'] = date('Y-m-d H:i:s',$log['add_time']);
return $supplier;
}
......
......@@ -36,22 +36,22 @@ class SupplierValidator
if ($requestData['currency'] == 1) {
$rules['tax_number'] = 'required';
}
// if ($requestData['status'] == -1) {
// $rules = ['supplier_name' => 'required'];
// }
$messages = $this->messages();
$validator = Validator::make($requestData, $rules, $messages);
//判断联系方式的表单验证
if ($validator->fails()) {
// dd($validator->errors());
return $validator->errors()->first();
}
//检验名称是否已经存在数据库
$supplierModel = new SupplierChannelModel();
$companyNameCount = 0;
if (empty($request->get('supplier_id'))) {
$count = $supplierModel->where('supplier_name', $request->get('supplier_name'))->count();
$companyNameCount = $supplierModel->where('register_company_name',
$request->get('register_company_name'))->count();
} else {
$count = $supplierModel->where('supplier_name', $request->get('supplier_name'))
->where('supplier_id', '!=', $request->get('supplier_id'))->count();
......@@ -59,6 +59,9 @@ class SupplierValidator
if ($count) {
return "该供应商名称已经存在,请核验后再提交";
}
if ($companyNameCount) {
return "该注册公司名已经存在,请核验后再提交";
}
}
private function messages()
......
......@@ -2,21 +2,24 @@
namespace App\Model;
use Request;
use Illuminate\Database\Eloquent\Model;
use DB;
use RedisDB;
class SupplierChannelModel extends Model
{
protected $connection = 'web';
protected $table = 'supplier_channel';
public $timestamps = false;
//待审核(没有补充所有必填信息)
const STATUS_PENDING = -1;
//审核中
const STATUS_IN_REVIEW = 1;
//通过
const STATUS_PASSED = 2;
//未通过
const STATUS_REJECT = 3;
//禁止交易(禁用)
const STATUS_DISABLE = -2;
protected $connection = 'web';
protected $table = 'supplier_channel';
public $timestamps = false;
//黑名单信息
public function blacklist()
......@@ -29,777 +32,4 @@ class SupplierChannelModel extends Model
{
return $this->hasMany(SupplierContactModel::class, 'supplier_id', 'supplier_id');
}
private function getEncode()
{
$redis = RedisDB::connection();
$codelist = json_decode($redis->get('EncodedList_supplier'), true);
if (!$codelist) {
$codelist = DB::connection()->table('lie_intracode')->where('admin_id', '>', 0)->select('code_id',
'admin_id')->get();
if ($codelist) {
foreach ($codelist as $k => $v) {
$codelist[$k] = (array)$codelist[$k];
$codelist[$k] = $this->code_info($codelist[$k]);
$redis->set('EncodedList_supplier', json_encode($codelist));
$redis->expire('EncodedList_supplier', 60 * 10);//缓存10分钟
}
}
}
return $codelist;
}
// 获取符合条件的供应商列表
public function CheckSupplierListByAudit()
{
$logRemark = []; // 日志记录
$time = time() - 60 * 60 * 24 * 7;
// 联营供应商创建7天后不审核,推送消息给采购经理:供应商L00001创建超过7天未审核,请及时审核
$res = $this->select(['supplier_code', 'supplier_name'])->where('create_time', '<', $time)->where('status', '=',
'1')->get()->toArray();
$remark = '';
foreach ($res as $key => $value) {
$remark .= $value['supplier_name'] . ' ' . $value['supplier_code'] . ', ';
}
$remark = rtrim($remark, ', ');
$data['supplier_remark'] = $remark;
if ($remark) {
$re = SendAlarmMsg($data);
if (!$re) {
$logRemark[] = '联营供应商 ' . $remark . ',联营供应商创建7天后不审核,推送消息给采购经理失败';
}
}
// 联营供应商审核7天后在基石无相应关联的上架sku。推送消息给采购经理、对应渠道开发:供应商L00001审核超过7天未上传sku,已停用请及时处理
// 推送给经理
$start_time = strtotime(date("Y-m-d", strtotime("-8 day"))); //例如今天10.18 ,查询10.10 0:00 到10.11 0:00 期间是否有审核通过的渠道商
$end_time = $start_time + 24 * 60 * 60; //结束时间
$res = $this->select([
'supplier_id',
'supplier_code',
'channel_uid',
'supplier_name',
'purchase_uid'
])->whereBetween('audit_time', [$start_time, $end_time])->where('status', '=', '2')->get()->toArray();
$url = env('ES_SKU_URL', '');
$sendArr = []; // 获取符合发送的所有数据
foreach ($res as $key => $value) {
$map['status/condition'] = 1;
$map['canal/condition'] = $value['supplier_code'];
$return = curl($url, $map, 1);
$data = json_decode($return, true);
if (isset($data['error_code']) && strval($data['error_code']) !== '0') { // error_code 不为0时,则表明该渠道商无关联sku
$sendArr[] = $value;
}
}
// 整理数据,以发送渠道开发为单位,10033=>array('supplier_code'=>'拼接片段','user' => 'lfc@ichunt.com');
$listArr = [];
$sendEmailListArr = [];
foreach ($sendArr as $key => $value) {
if (!empty($value['channel_uid'])) {
if (!in_array($value['channel_uid'], $listArr)) { // 表明有新的渠道开发需要通知
$listArr[] = $value['channel_uid'];
$sendEmailListArr[$value['channel_uid']]['supplier_remark'] = $value['supplier_name'] . ' ' . $value['supplier_code'];
} else { // 表明该渠道开发已经包含,无需重复再发一次
$sendEmailListArr[$value['channel_uid']]['supplier_remark'] .= ', ' . $value['supplier_name'] . ' ' . $value['supplier_code'];
}
}
// 渠道维护也要通知
if ($value['channel_uid'] !== $value['purchase_uid']) {
if (!in_array($value['purchase_uid'], $listArr)) { // 表明有新的渠道开发需要通知
$listArr[] = $value['purchase_uid'];
$sendEmailListArr[$value['purchase_uid']]['supplier_remark'] = $value['supplier_name'] . ' ' . $value['supplier_code'];
} else { // 表明该渠道开发已经包含,无需重复再发一次
$sendEmailListArr[$value['purchase_uid']]['supplier_remark'] .= ', ' . $value['supplier_name'] . ' ' . $value['supplier_code'];
}
}
}
$encode = $this->getEncode();
$encodeList = []; // 获取渠道开发人员的邮件
foreach ($encode as $key => $value) {
$encodeList[$value['code_id']] = $value['email'];
}
$toMangerListArr = [];
$toMangerList = '';
foreach ($sendEmailListArr as $key => $value) {
$res = '';
$data = [];
$data['supplier_remark'] = $value['supplier_remark'];
if ($value['supplier_remark']) {
$res = SendAlarmMsg($data, 'supplier-sku-alarm', $encodeList[$key]);
if (!$res) {
$logRemark[] = '供应商为' . $data['supplier_remark'] . ',发送失败邮件为' . $encodeList[$key];
}
if (!in_array($value['supplier_remark'], $toMangerListArr)) {
$toMangerList .= $value['supplier_remark'] . ', ';
$toMangerListArr[] = $value['supplier_remark'];
}
}
}
// 发送给采购经理
$toMangerList = rtrim($toMangerList, ', ');
$reData['supplier_remark'] = $toMangerList;
if ($toMangerList) {
$resu = SendAlarmMsg($reData, 'supplier-sku-alarm');
if (!$resu) {
$logRemark[] = '采购经理supplier-sku-alarm邮件发送失败,供应商为' . $reData['supplier_remark'];
}
}
// 记录日志
$result = true;
if ($logRemark) {
loggerDawn($logRemark);
$result = false;
$dataRes['time'] = date('Y-m-d H:i:s', time());
SendAlarmMsg($dataRes, 'supplier-alarm');
} else {
//停用供应商 -2
foreach ($sendArr as $key => $value) {
$data = [];
$data['status'] = '-2';
$this->where('supplier_id', '=', $value['supplier_id'])->update($data);//写code
}
}
return $result;
}
private function code_info($return)
{
$return = (array)$return;
$admin = DB::connection()
->table('user_info')
->where('userId', $return['admin_id'])
->select('name', 'email', 'status')
->first();
if ($admin) {
if (!$admin['name'] && $admin['email']) {
$admin['name'] = $admin['email'];
}
$return = array_merge($return, (array)$admin);
}
return $return;
}
// 导出
public function export()
{
$res = $this->select(['supplier_name', 'supplier_code'])->where('purchase_uid', '=', '10033')->get()->toArray();
dump($res);
die;
$column = array('供应商名称', '供应商编码'); // 表头
$fileName = '渠道维护杨雨柔' . date('YmdHis', time()) . '.csv';
export_csv($data[2], $column, $fileName);
}
public function ApiSupplierList($request = array())
{
$arr = [
'supplier_group',
'pay_type',
'status',
"outside_contact_type",
'supplier_name',
'supplier_id',
'self',
'purchase_uid',
'channel_uid',
'supplier_code',
'p',
'limit',
];
$collert = Request::only($arr);
array_splice($arr, -2, 2);
$limit = !empty($collert['limit']) ? $collert['limit'] : 10;
$p = !empty($collert['p']) ? $collert['p'] : 1;
$collert = TrimX($collert, true, $arr);
$map = $this->HandleMap($collert);
if (empty($map['status'])) {
// $map['status'] = ['-2', '-1', '1', '2'];
}
//如果是竞调账户就是升序,否则就是降序
$sql_sort = $request->user->userId == 1442 ? "asc" : "desc";
$result = $this->where(function ($query) use ($map, $request) {
//查看所有
$canViewAll = perm($request->user->userId,'ViewAllSupplier');
if ($request->user->userId != 1442 && !$canViewAll) {
$query->where('is_type', '=', 0);
}
if (is_array($map)) {
foreach ($map as $k => $v) {
if ($k == 'supplier_name') {
$re = is_numeric($v);
if ($re || substr_count($v, 'L0')) {
$query->where('supplier_code', 'like', '%' . $v . '%');
} else {
$query->where($k, 'like', '%' . $v . '%');
}
} else {
if ($k == "outside_contact_type") {
$query->where('outside_contact_status', '=', 2);
}
$query->whereIn($k, $v);
}
}
}
//获取超级管理权限
$perm = perm($request->user->userId, 'group_super_perm');
if ($canViewAll) {
} elseif (!$perm) {
//获取组管理权限
$GroupModel = new GroupModel();
$GroupPerm = $GroupModel->where('admin_id', '=', $request->user->userId)->orWhere('examine_id', '=',
$request->user->userId)
->select('group_id')->first();
if ($GroupPerm) {//有组管理员或者审核者的权限
$GroupPerm = $GroupPerm->toArray();
//查找组成员
$GroupUserModel = new GroupUserModel();
$code_id = $GroupUserModel->where('group_id', '=',
$GroupPerm['group_id'])->lists('code_id')->toArray();
$code_id[] = $request->user->code['code_id'];
$query->whereIn('channel_uid', $code_id);
} else {//普通成员
$query->whereRaw('(channel_uid = ? or purchase_uid = ?)',
[$request->user->code['code_id'], $request->user->code['code_id']]);
}
}
})->orderBy('supplier_id', $sql_sort)->paginate($limit, ['*'], 'p', $p)->toArray();
if (!$result) {
return [10001, '查询失败'];
}
if (count($result['data']) > 0) {
$SupplierReceiptModel = new SupplierReceiptModel();
$url = env('ES_SKU_URL', '');
foreach ($result['data'] as $k => $v) {
$map = [];
$map['status/condition'] = 1;
$map['canal/condition'] = $v['supplier_code'];
$return = curl($url, $map, 1);
$data = json_decode($return, true);
$result['data'][$k]['skuCount'] = 0;
if (isset($data['error_code']) && $data['error_code'] == 0) {
$result['data'][$k]['skuCount'] = $data['data']['total'];
}
$result['data'][$k]['Receipt'] = $SupplierReceiptModel->ReceiptInfo($v['supplier_id']);
}
// 判断是否具有审核权限(即是经理还是普通采购)
$perm = perm($request->user->userId, 'ApiAuthSupplier');
$ApiAuthSupplier = false;
if ($perm == true) {
$ApiAuthSupplier = true;
}
} else {
$SupplierReceiptModel = new SupplierReceiptModel();
$url = env('ES_SKU_URL', '');
foreach ($result['data'] as $k => $v) {
$map = [];
$map['status/condition'] = 1;
$map['canal/condition'] = $v['supplier_code'];
$return = curl($url, $map, 1);
$data = json_decode($return, true);
$result['data'][$k]['skuCount'] = 0;
if (isset($data['error_code']) && $data['error_code'] == 0) {
$result['data'][$k]['skuCount'] = $data['data']['total'];
}
$result['data'][$k]['Receipt'] = $SupplierReceiptModel->ReceiptInfo($v['supplier_id']);
}
// 判断是否具有审核权限(即是经理还是普通采购)
$perm = perm($request->user->userId, 'ApiAuthSupplier');
$ApiAuthSupplier = false;
if ($perm == true) {
$ApiAuthSupplier = true;
}
}
empty($result['data']) || $result['data'] = $this->Machining($result['data'], $ApiAuthSupplier); // 数据整理
if ($request->user->userId == 1442) {
if (!$collert) {
$result['total'] = ceil($result['total'] - 4000);
}
}
return [0, '查询成功', $result['data'], $result['total']];
}
private function HandleMap($map = '')
{
if (empty($map) || !is_array($map)) {
return false;
}
foreach ($map as $k => $v) {
if ($k == 'supplier_name') {
continue;
}/*elseif ($k=='self'){
$map[$k]=rtrim($v,',');
}*/ else {
$map[$k] = explode(',', $v);
}
}
foreach ($map as $k => $v) {
is_array($v) && $map[$k] = array_filter($v);
}
return $map;
}
private function Machining($data = '', $ApiAuthSupplier = false)
{
$StockupType = Config('fixed.SupplierStockupType');
$PayType = Config('fixed.SupplierPayType');
$Status = Config('fixed.SupplierStatus');
$Currency = Config('fixed.Currency');
$supplier_group = Config('fixed.SupplierGroup');
$UserModel = new UserModel();
foreach ($data as $k => $v) {
$data[$k]['ApiAuthSupplier'] = $ApiAuthSupplier; // 是否有审核权限
$data[$k]['stockup_type_name'] = !empty($StockupType[$v['stockup_type']]) ? $StockupType[$v['stockup_type']] : '';
$data[$k]['pay_type_name'] = !empty($PayType[$v['pay_type']]) ? $PayType[$v['pay_type']] : '';
$data[$k]['supplier_group_name'] = !empty($supplier_group[$v['supplier_group']]) ? $supplier_group[$v['supplier_group']] : '';
$data[$k]['status_name'] = !empty($Status[$v['status']]) ? $Status[$v['status']] : '';
$data[$k]['currency_name'] = !empty($Currency[$v['currency']]) ? $Currency[$v['currency']] : '';
$data[$k]['pay_type'] == 1 && $data[$k]['Requirement'] = '入仓后下个月' . $data[$k]['day_num'] . '号付款';
$data[$k]['pay_type'] == 2 && $data[$k]['Requirement'] = '入仓后' . $data[$k]['day_num'] . '天付款';
$data[$k]['pay_type'] == 4 && $data[$k]['Requirement'] = '首款' . $data[$k]['advance_proportion'] . '%,尾款' . (100 - $data[$k]['advance_proportion']) . '%';
empty($data[$k]['purchase_uid']) || $data[$k]['purchase_uid_name'] = $UserModel->FinduserInfoAdminid($data[$k]['purchase_uid']);
empty($data[$k]['channel_uid']) || $data[$k]['channel_uid_name'] = $UserModel->FinduserInfoAdminid($data[$k]['channel_uid']);
empty($data[$k]['audit_uid']) || $data[$k]['audit_uid_name'] = $UserModel->FinduserInfoName($data[$k]['audit_uid']);
empty($data[$k]['create_time']) || $data[$k]['create_time_s'] = date('Y/m/d H:i', $data[$k]['create_time']);
empty($data[$k]['audit_time']) || $data[$k]['audit_time_s'] = date('Y/m/d H:i', $data[$k]['audit_time']);
}
return $data;
}
//新增编辑供应商
public function ApiHoldSupplier($IsAdd = false, $userID = 0)
{
$arr = ['channel', 'receipt', 'address', 'supplier_id', 'contact', 'extend'];
$collert = Request::only($arr);
$collert = TrimX($collert, true, $arr);
if ($IsAdd == false && empty($collert['supplier_id'])) {
return [10001, '缺少必须参数'];
}
$channel = $collert['channel'];
unset($channel['supplier_id']);
$channel['update_time'] = time();
$ReceiptModel = new SupplierReceiptModel();
$AddressModel = new SupplierAddressModel();
$ContactModel = new SupplierContactModel();
$SupplierExtendModel = new SupplierExtendModel();
$Receipt = $collert['receipt'];
$Address = $collert['address'];
$Contact = $collert['contact'];
$Extend = $collert['extend'];
if ($IsAdd) {
if (!empty($collert['supplier_id'])) {
return [10002, '参数有误,不能新增'];
}
$channel['create_uid'] = $userID;
$channel['create_time'] = time();
try {
DB::connection('web')->beginTransaction();
$find = $this->where('supplier_name', '=', $channel['supplier_name'])->where('stockup_type', '=',
$channel['stockup_type'])->select('supplier_id')->first();
if ($find && $find['supplier_id'] > 0) {
return [30001, '该供应商已经存在'];
}
$result = $this->insertGetId($channel);
if ($result > 0) {
$supplierID = $result;
//$SnModel=new SnModel();
//$update['supplier_code']=$SnModel->Sn('supplier_code');
$update['supplier_code'] = 'L' . str_pad($supplierID, 7, "0", STR_PAD_LEFT);
$this->where('supplier_id', '=', $supplierID)->update($update);//写code
$ReceiptModel->AddInfo($supplierID, $Receipt);//写银行信息
$AddressModel->AddInfo($supplierID, $Address);//写地址
$ContactModel->AddInfo($supplierID, $Contact);//写地址
$SupplierExtendModel->AddInfo($supplierID, $update['supplier_code'], $Extend[1]); // 写附加费
DB::connection('web')->commit();
$this->getRelationBySupplierCode($update['supplier_code'], $channel['supplier_name'],
''); // 映射关系存进redis
return [0, '新增供应商成功'];
} else {
return [20002, '新增供应商失败'];
}
} catch (\Exception $e) {
echo $e;
exit;
DB::connection('web')->rollBack();
return [20001, '新增供应商失败'];
}
} else {
if (empty($collert['supplier_id'])) {
return [10002, '缺少参数,不能修改'];
}
unset($channel['stockup_type']);
try {
if ($channel['status'] == 2) {
//先去查找是否之前的状态,如果之前是2了,就不要去修改审核信息了
$status = $this->where('supplier_id', $collert['supplier_id'])->value('status');
if ($status == 1) {
$channel['audit_uid'] = $userID;
$channel['audit_time'] = time();
}
}
$this->where('supplier_id', '=', $collert['supplier_id'])->update($channel);
$ReceiptModel->SaveInfo($collert['supplier_id'], $Receipt);
$AddressModel->SaveInfo($Address);
$ContactModel->SaveInfo($collert['supplier_id'], $Contact);//写地址
// $Extend[1]['status'] = $status = $Extend['status'] ? $Extend['status'] : '';
$SupplierExtendModel->AddInfo($collert['supplier_id'], $channel['supplier_code'], $Extend[1], true);
DB::connection('web')->commit();
$this->getRelationBySupplierCode($channel['supplier_code'], $channel['supplier_name'],
''); // 映射关系存进redis
if ($channel['status'] == 2) {
$this->UpdateNnionCanalEncode((int)$channel['channel_uid'], $channel['supplier_code']);
}
return [0, '修改供应商成功'];
} catch (\Exception $e) {
DB::connection('web')->rollBack();
return [20001, '修改供应商失败', $e->getMessage()];
}
}
}
// 根据supplier_code 供应商编码映射供应商名称 ,并存进redis缓存
public function getRelationBySupplierCode($supplier_code = '', $supplier_name = '', $Redis = '')
{
if (empty($supplier_code) || empty($supplier_name)) {
return false;
}
if (empty($Redis)) {
$Redis = RedisDB::connection();
}
$pre = Config('fixed.SUPPLIER_INFO_REDIS_PRE');
$Redis->hset($pre, $supplier_code, $supplier_name);
}
public function UpdateNnionCanalEncode($encode, $canal, $Redis = '')
{
if (empty($Redis)) {
$Redis = RedisDB::connection();
}
return $Redis->hset('union_canal_encode', $canal, $encode);
}
public function SupplierInfo($SupplierID = '')
{
$collert = Request::only('supplier_id');
$collert = TrimX($collert, true, ['supplier_id']);
empty($collert) && $collert['supplier_id'] = $SupplierID;
if (empty($collert['supplier_id'])) {
return false;
}
$info = $this->where('supplier_id', '=', $collert['supplier_id'])->first();
if (!$info) {
return false;
}
return $info->toArray();
}
public function GetSupplierInfoBySupplierCode($SupplierCode = '')
{
$collert = Request::only('supplier_code');
$collert = TrimX($collert, true, ['supplier_code']);
empty($collert) && $collert['supplier_code'] = $SupplierCode;
if (empty($collert['supplier_code'])) {
return false;
}
$info = $this->where('supplier_code', '=', $collert['supplier_code'])->first();
if (!$info) {
return false;
}
return $info->toArray();
}
public function ApiAuthSupplier($UserID = '')
{
$Arr = ['supplier_id', 'status'];
$collert = Request::only($Arr);
$collert = TrimX($collert, true, $Arr);
if (empty($collert['supplier_id']) || empty($collert['status'])) {
return [10001, '缺少必须参数'];
}
if ($collert['status'] != '2' && $collert['status'] != '-1') {
return [10002, '参数错误'];
}
$Find = $this->where('supplier_id', '=', $collert['supplier_id'])->select('status', 'channel_uid',
'supplier_code')->first();
if (!$Find) {
return [20001, '没有找到这个供应商'];
}
if ($Find['status'] != 1) {
return [20002, '这个供应商不在审核中'];
}
$collert['status'] == 2 && $errinfo = '审核';
$collert['status'] == '-1' && $errinfo = '驳回';
$collert['audit_uid'] = $UserID;
$collert['audit_time'] = time();
DB::connection($this->connection)->beginTransaction();
$result = $this->where('supplier_id', '=', $collert['supplier_id'])->update($collert);
if (!$result) {
return [30001, $errinfo . '失败'];
}
DB::connection($this->connection)->commit();
return [0, $errinfo . '成功'];
}
// 更改状态并推入到队列
public function ApiChangeSupplierStatus($request)
{
$collert = Request::input();
if (empty($collert['supplier_id']) || empty($collert['status'])) {
return [10001, '缺少必须参数'];
}
$update = $this->where('supplier_id', '=', $collert['supplier_id'])->update(['status' => $collert['status']]);
if ($collert['status'] == 2) {
$status = '启用';
} else {
$status = '禁用';
}
$message = '修改供应商状态为:' . $status . "\r";
$message .= '修改供应商ID:' . $collert['supplier_id'] . "\r";
$message .= '操作人:' . $request->user->email;
SendRobot('https://oapi.dingtalk.com/robot/send?access_token=92917a6e090a8a39832c4843a579d6c6f9dfecc46fa275f8753ddee2b4399045',
$message);
return [0, '操作成功'];
}
// 初始化 供应商数据
public function initSupplier()
{
$supplier = $this->get();
if (!$supplier) {
return [10002, '无供应商数据'];
}
foreach ($supplier as $v) {
$info['type'] = 'supplier.syn';
$info['data']['supplier_id'] = $v->supplier_id;
$info['data']['supplier_code'] = $v->supplier_code;
$info['data']['supplier_name'] = $v->supplier_name;
$info['data']['stockup_type'] = $v->stockup_type;
$info['data']['status'] = $v->status == 2 ? 1 : -1;
// 推入到队列
$queue = new QueuedModel();
$queue->pushAmq(json_encode($info));
}
return [0, '成功并推入到队列'];
}
public function SupplierData($supplier_name = '')
{
$collert = Request::only('supplier_name');
$collert = TrimX($collert, true, ['supplier_name']);
empty($collert) && $collert['supplier_name'] = $supplier_name;
if (empty($collert['supplier_name'])) {
return 1002;
}
$info = $this->where('supplier_name', '=', trim($collert['supplier_name']))->where('status', '=', 2)->first();
if (!$info) {
return 1;
}
//$res = $info->toArray();
return 2;
}
// 根据采购员id获取到他对应的渠道商列表
public function getSupplierCodeByUserId($user_id)
{
if (!$user_id) {
return false;
}
$info = $this->select(['supplier_code'])->where('purchase_uid', '=', $user_id)->get()->toArray();
if (!$info) {
return false;
}
return $info;
}
public function getSupplierList($input = array(), $request = array())
{
$arr = [
'supplier_group',
'pay_type',
'status',
'supplier_name',
'supplier_id',
'self',
'purchase_uid',
'channel_uid',
'supplier_code',
'p',
'limit',
'is_type'
];
$collert = Request::only($arr);
array_splice($arr, -2, 2);
$collert = TrimX($collert, true, $arr);
$map = $this->HandleMap($collert);
if (empty($map['status'])) {
$map['status'] = ['-2', '-1', '1', '2']; // 排除掉已删除的供应商
}
$map["is_type"] = ['0'];
$result = $this->where(function ($query) use ($map, $request) {
if (is_array($map)) {
foreach ($map as $k => $v) {
if ($k == 'supplier_name') {
$re = is_numeric($v);
if ($re || substr_count($v, 'L0')) {
$query->where('supplier_code', 'like', '%' . $v . '%');
} else {
$query->where($k, 'like', '%' . $v . '%');
}
} else {
$query->whereIn($k, $v);
}
}
}
$perm = json_decode(perm($request->user->userId, 'ApiAuthSupplier'), true);
if (!$perm) { // 没有审核权限,即表明该用户不是主管,只能查看该用户具有绑定关系的列表(渠道开发或渠道维护 )
$query->whereRaw('(channel_uid = ? or purchase_uid = ?)',
[$request->user->code['code_id'], $request->user->code['code_id']]);
}
})->get()->toArray();
$url = env('ES_SKU_URL', '');
foreach ($result as $k => &$v) {
$map = [];
$map['status/condition'] = 1;
$map['canal/condition'] = $v['supplier_code'];
$return = curl($url, $map, 1);
$data = json_decode($return, true);
$result[$k]['skuCount'] = 0;
if (isset($data['error_code']) && $data['error_code'] == 0) {
$result[$k]['skuCount'] = $data['data']['total'];
}
}
if (!$result) {
return [10001, '查询失败'];
}
return $result;
}
// 导出
public function supplierListExport($request = array())
{
$arr = [
'p',
'limit',
'supplier_group',
'pay_type',
'status',
'supplier_name',
'supplier_code',
'channel_uid',
'purchase_uid',
'is_type'
];
$input = Request::only($arr);
$data = $this->getSupplierList($input, $request);
$exData = [];
$UserModel = new UserModel();
foreach ($data as $k => $v) {
$exData[$k]['supplier_code'] = $v['supplier_code'];
$exData[$k]['supplier_name'] = $v['supplier_name'];
$exData[$k]['purchase_uid'] = $UserModel->FinduserInfoAdminid($v['purchase_uid']);
$exData[$k]['channel_uid'] = $UserModel->FinduserInfoAdminid($v['channel_uid']);
$exData[$k]['create_uid'] = $UserModel->FinduserInfoName($v['create_uid']);
$exData[$k]['create_time'] = $v['create_time'] ? date('Y/m/d', $v['create_time']) . "\n" : '';
$exData[$k]['audit_uid'] = $UserModel->FinduserInfoName($v['audit_uid']);
$exData[$k]['audit_time'] = $v['audit_time'] ? date('Y/m/d', $v['audit_time']) . "\n" : '';
$exData[$k]['skuCount'] = $v['skuCount'] ? $v['skuCount'] : '0';
}
$column = array(
'供应商编码',
'供应商名称',
'渠道维护',
'渠道开发',
'创建人',
'创建时间',
'审核人',
'审核时间',
'sku数量',
); // 表头
$fileName = '渠道商数据下载' . date('YmdHis', time()) . '.csv';
export_csv($exData, $column, $fileName);
}
public function ApiSaveSupplierRatio()
{
$collert = TrimX('', true,
['cn_delivery_time', 'us_delivery_time', 'cn_ratio', 'us_ratio', 'supplier_id', 'canal']);
$MustField = [
'cn_delivery_time' => '大陆货期',
'us_delivery_time' => '香港货期',
'cn_ratio' => '人民币系数',
'us_ratio' => '美金系数',
'supplier_id' => '供应商ID',
'canal' => '供应商编码'
];
foreach ($MustField as $k => $v) {
if (empty($collert[$k])) {
return [10001, '参数' . $v . '未填写'];
}
}
if (preg_match('/^\d+\-\d+(工作日|周)$/', $collert['cn_delivery_time']) == false) {
return [10002, '大陆货期格式不正确'];
}
if (preg_match('/^\d+\-\d+(工作日|周)$/', $collert['us_delivery_time']) == false) {
return [10003, '香港货期格式不正确'];
}
if ((float)$collert['cn_ratio'] < 1) {
return [10004, '人民币系数必须是大于1的浮点数'];
}
if ((float)$collert['cn_ratio'] < 1) {
return [10005, '人民币系数必须是大于1的浮点数'];
}
$canal = $collert['canal'];
unset($collert['canal']);
$result = $this->where('supplier_id', '=', $collert['supplier_id'])->update($collert);
if (!$result && $result !== 0) {
return [10006, '修改失败'];
}
$Redis = new RedisModel();
$pre = config('fixed.SUPPLIER_RATION');
$Redis->hset($pre, $canal, json_encode($collert));
return [0, '修改成功'];
}
}
......@@ -24,7 +24,9 @@
});
}
@if(checkPerm('SupplierLog'))
openLogView();
@endif
//判断是否要切换tab
let tab = '{{request()->get('tab')}}';
......
......@@ -10,7 +10,7 @@
upload.render({
elem: '.uploadButton'
, url: '{{config('website.UploadUrl')}}' //改成您自己的上传接口
, accept: 'file' //音频
, accept: 'file' //文件
, field: 'upload'
, data: {
k1: k1,
......
......@@ -33,7 +33,14 @@
<div class="layui-row">
<a id="updateSupplierUrl"
href="/supplier/UpdateSupplier?view=iframe&supplier_id={{$supplier['supplier_id']}}"
style="margin-bottom: 25px;margin-top: 5px" class="layui-btn layui-btn">点击修改</a>
style="margin-bottom: 25px;margin-top: 5px" class="layui-btn layui-btn">修改</a>
</div>
@endif
@if($supplier['status']==\App\Model\SupplierChannelModel::STATUS_DISABLE)
<div class="layui-row">
<a id="updateSupplierUrl"
href="/supplier/UpdateSupplier?view=iframe&supplier_id={{$supplier['supplier_id']}}"
style="margin-bottom: 25px;margin-top: 5px" class="layui-btn layui-btn">申请重新入驻</a>
</div>
@endif
</div>
......@@ -160,10 +167,10 @@
</div>
<div class="layui-row">
<div class="layui-col-md2">
最近修改人 :{{$supplier['supplier_name']}}
最近修改人 :{{$supplier['last_update_name']}}
</div>
<div class="layui-col-md2">
最近修改时间 :{{$supplier['update_time']}}
最近修改时间 :{{$supplier['last_update_time']}}
</div>
</div>
<hr/>
......
......@@ -52,11 +52,11 @@
<div class="layui-row">
<div class="layui-btn-group" style="margin-bottom: 25px;margin-top: 5px">
<button type="button" class="layui-btn layui-btn" lay-submit
lay-filter="updateSupplier">保存修改
lay-filter="updateSupplier">提交
</button>
<a id="supplierDetailUrl"
href="/supplier/SupplierDetail?view=iframe&supplier_id={{$supplier['supplier_id']}}"
class="layui-btn layui-btn-warm">返回详情</a>
class="layui-btn layui-btn-warm">取消</a>
</div>
</div>
</div>
......@@ -160,10 +160,10 @@
</div>
<div class="layui-row">
<div class="layui-col-md2">
最近修改人:{{$supplier['supplier_name']}}
最近修改人:{{$supplier['last_update_name']}}
</div>
<div class="layui-col-md2">
最近修改时间:{{$supplier['update_time']}}
最近修改时间:{{$supplier['last_update_time']}}
</div>
</div>
<hr/>
......
......@@ -3,148 +3,145 @@
</blockquote>
@if($operate=='add')
<form class="layui-form" action="">
@endif
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>供应商名称 : </label>
<div class="layui-input-block">
<input type="text" name="supplier_name" id="supplier_name"
placeholder="请输入供应商名称" class="layui-input"
value="{{$supplier['supplier_name'] or ''}}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>注册公司名 : </label>
<div class="layui-input-block">
<input type="text" name="register_company_name" id="register_company_name"
@if(!empty($supplier))
disabled
@endif
placeholder="请输入注册公司名" class="layui-input"
value="{{$supplier['register_company_name'] or ''}}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文名称 : </label>
<div class="layui-input-block">
<input type="text" name="supplier_name_en" id="supplier_name_en"
placeholder="请输入供应商英文名称" class="layui-input"
value="{{$supplier['supplier_name_en'] or ''}}">
</div>
</div>
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-md4">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('region','所在区域',!empty($supplier)?array_get($supplier,'region',''):'',
config('fixed.Region'),['required'=>true,'width'=>'150px']) !!}
@endif
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>供应商名称 : </label>
<div class="layui-input-block">
<input type="text" name="supplier_name" id="supplier_name"
placeholder="请输入供应商名称" class="layui-input"
value="{{$supplier['supplier_name'] or ''}}">
</div>
</div>
<div class="layui-col-md8">
<label class="layui-form-label">注册地址 :
</label>
<div class="layui-form-item">
<label class="layui-form-label"><span class="require">*</span>注册公司名 : </label>
<div class="layui-input-block">
<input type="text" name="supplier_address" id="supplier_address"
placeholder="请输入注册地址" class="layui-input"
value="{{$supplier['supplier_address'] or ''}}">
<input type="text" name="register_company_name" id="register_company_name"
placeholder="请输入注册公司名" class="layui-input @if(!empty($supplier))layui-disabled @endif"
value="{{$supplier['register_company_name'] or ''}}">
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-md4">
<label class="layui-form-label"><span class="require">*</span>法人代表 :
</label>
<div class="layui-form-item">
<label class="layui-form-label">英文名称 : </label>
<div class="layui-input-block">
<input type="text" style="width: 150px" name="legal_representative" id="legal_representative"
placeholder="请输入法人代表" class="layui-input"
value="{{$supplier['legal_representative'] or ''}}">
<input type="text" name="supplier_name_en" id="supplier_name_en"
placeholder="请输入供应商英文名称" class="layui-input"
value="{{$supplier['supplier_name_en'] or ''}}">
</div>
</div>
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-md4">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('region','所在区域',!empty($supplier)?array_get($supplier,'region',''):'',
config('fixed.Region'),['required'=>true,'width'=>'150px']) !!}
</div>
<div class="layui-col-md8">
<label class="layui-form-label">注册地址 :
</label>
<div class="layui-input-block">
<input type="text" name="supplier_address" id="supplier_address"
placeholder="请输入注册地址" class="layui-input"
value="{{$supplier['supplier_address'] or ''}}">
</div>
</div>
</div>
</div>
<div class="layui-col-md8">
<label class="layui-form-label" style="width: 80px">成立时间 :
</label>
<div class="layui-input-block" style="width: 150px">
<input type="text" id="established_time" name="established_time"
placeholder="请输入成立时间"
class="layui-input"
autocomplete="off"
value="{{$supplier['established_time'] or ''}}">
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-md4">
<label class="layui-form-label"><span class="require">*</span>法人代表 :
</label>
<div class="layui-input-block">
<input type="text" style="width: 150px" name="legal_representative" id="legal_representative"
placeholder="请输入法人代表" class="layui-input"
value="{{$supplier['legal_representative'] or ''}}">
</div>
</div>
<div class="layui-col-md8">
<label class="layui-form-label" style="width: 80px">成立时间 :
</label>
<div class="layui-input-block" style="width: 150px">
<input type="text" id="established_time" name="established_time"
placeholder="请输入成立时间"
class="layui-input"
autocomplete="off"
value="{{$supplier['established_time'] or ''}}">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">资信调查 : </label>
<div class="layui-input-block">
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">资信调查 : </label>
<div class="layui-input-block">
<textarea name="credit_investigation" placeholder="请输入资信调查"
class="layui-textarea">{{$supplier['credit_investigation'] or ''}}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">
主营品牌</label>
<div class="layui-input-block" style="margin-top: 15px">
<div id="brand_selector" class="layui-input-inline" style="width: 100%;">
</div>
</div>
<input type="hidden" name="main_brands" value="{{$supplier['main_brands'] or ''}}"
id="main_brands">
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label"><span class="require">*</span>合作类型</label>
<div class="layui-input-block">
<input type="hidden" name="stockup_type"
value="{{$supplier['stockup_type'] or ''}}">
@foreach(config('fixed.StockupType') as $k=>$type)
<input type="checkbox" name="stockup_type[{{$k}}]"
lay-skin="primary"
@if(!empty($supplier['stockup_type_data'])&&in_array($k,$supplier['stockup_type_data']))
checked
@endif
title="{{$type}}">
@endforeach
<div class="layui-form-item">
<label class="layui-form-label">
主营品牌</label>
<div class="layui-input-block" style="margin-top: 15px">
<div id="brand_selector" class="layui-input-inline" style="width: 100%;">
</div>
<input type="hidden" name="main_brands" value="{{$supplier['main_brands'] or ''}}"
id="main_brands">
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-md4">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('supplier_group','公司性质',!empty($supplier)?array_get($supplier,'supplier_group',null):'',
config('fixed.SupplierGroup'),['required'=>true,'width'=>'150px']) !!}
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label"><span class="require">*</span>合作类型</label>
<div class="layui-input-block">
<input type="hidden" name="stockup_type"
value="{{$supplier['stockup_type'] or ''}}">
@foreach(config('fixed.StockupType') as $k=>$type)
<input type="checkbox" name="stockup_type[{{$k}}]"
lay-skin="primary"
@if(!empty($supplier['stockup_type_data'])&&in_array($k,$supplier['stockup_type_data']))
checked
@endif
title="{{$type}}">
@endforeach
</div>
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('currency','结算币种',
isset($supplier)?$supplier['currency']:'',config('fixed.Currency'),['required'=>false]) !!}
</div>
<div class="layui-inline" id="tax_number_div"
@if(empty($supplier) || (!empty($supplier)&&$supplier['currency']!=1))
style="display: none;"
@endif
>
<label class="layui-form-label"><span class="require">*</span>公司税号</label>
<div class="layui-input-inline">
<input type="text" name="tax_number" placeholder="请输入公司税号" class="layui-input"
value="{{$supplier['tax_number'] or ''}}">
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-md4">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('supplier_group','公司性质',!empty($supplier)?array_get($supplier,'supplier_group',null):'',
config('fixed.SupplierGroup'),['required'=>true,'width'=>'150px']) !!}
</div>
</div>
</div>
</div>
</div>
@include('web.supplier.SupplierFile')
@if($operate=='add')
<blockquote class="layui-elem-quote layui-text">
<b>跟进人</b>
</blockquote>
@inject('statusPresenter','App\Presenters\StatusPresenter')
<div class="layui-form-item">
{!! $statusPresenter->render('region','渠道开发员','',$userCodes,['required'=>true,'width'=>'150px']) !!}
</div>
@endif
@include('script.supplier.SupplierBaseScript')
<div class="layui-form-item">
<div class="layui-inline">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('currency','结算币种',
isset($supplier)?$supplier['currency']:'',config('fixed.Currency'),['required'=>false]) !!}
</div>
<div class="layui-inline" id="tax_number_div"
@if(empty($supplier) || (!empty($supplier)&&$supplier['currency']!=1))
style="display: none;"
@endif
>
<label class="layui-form-label"><span class="require">*</span>公司税号</label>
<div class="layui-input-inline">
<input type="text" name="tax_number" placeholder="请输入公司税号" class="layui-input"
value="{{$supplier['tax_number'] or ''}}">
</div>
</div>
</div>
@include('web.supplier.SupplierFile')
@if($operate=='add')
<blockquote class="layui-elem-quote layui-text">
<b>跟进人</b>
</blockquote>
@inject('statusPresenter','App\Presenters\StatusPresenter')
<div class="layui-form-item">
{!! $statusPresenter->render('region','渠道开发员','',$userCodes,['required'=>true,'width'=>'150px']) !!}
</div>
@endif
@include('script.supplier.SupplierBaseScript')
@if($operate=='add')
</form>
@endif
\ No newline at end of file
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