Commit d7765ded by 杨树贤

完成相关接口

parent 14564ffe
...@@ -5,17 +5,24 @@ namespace App\Http\Controllers\Api; ...@@ -5,17 +5,24 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Controllers\Filter\SupplierFilter; use App\Http\Controllers\Filter\SupplierFilter;
use App\Http\Services\AdminUserService; use App\Http\Services\AdminUserService;
use App\Http\Services\SupplierApplyService;
use App\Http\Services\SupplierService; use App\Http\Services\SupplierService;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
//提供外部系统的接口 //提供外部系统的接口
class ExternalApiController extends Controller class ExternalApiController extends Controller
{ {
public function __construct()
{
}
public function searchSupplier(Request $request) public function searchSupplier(Request $request)
{ {
$map = $request->only(['keyword','channel_uid']); $map = $request->only(['keyword', 'channel_uid']);
$map['supplier_name'] = $map['keyword']; $map['supplier_name'] = $map['keyword'];
if (empty($map['supplier_name'])) { if (empty($map['supplier_name'])) {
$this->externalResponse(-1, '搜索的供应商名称不能为空'); $this->externalResponse(-1, '搜索的供应商名称不能为空');
...@@ -23,4 +30,53 @@ class ExternalApiController extends Controller ...@@ -23,4 +30,53 @@ class ExternalApiController extends Controller
$suppliers = SupplierService::searchSupplier($map); $suppliers = SupplierService::searchSupplier($map);
$this->externalResponse(0, 'ok', $suppliers['data'], $suppliers['total']); $this->externalResponse(0, 'ok', $suppliers['data'], $suppliers['total']);
} }
public function checkSupplierApply(Request $request)
{
$supplierName = $request->get('supplier_name');
$result = (new SupplierApplyService())->checkCanApplySupplier($supplierName);
if ($result !== true) {
$this->externalResponse(-1, $result);
}
$this->externalResponse(0, '可以申请供应商');
}
//申请供应商
public function applySupplier(Request $request)
{
$data = $request->only([
'supplier_name',
'main_product',
'contact_name',
'email',
'mobile',
]);
$rules = [
"supplier_name" => "required|max:300",
"main_product" => "required|max:100",
"contact_name" => "required|max:10",
"email" => "required|email",
'mobile' => 'required',
];
$attributes = [
'supplier_name' => '公司名称',
'main_product' => '主营产品',
'contact_name' => '联系人',
'email' => '邮箱',
'mobile' => '注册手机号',
];
$validator = Validator::make($data, $rules, [], $attributes);
if ($validator->fails()) {
$this->externalResponse(-1, $validator->errors()->first());
}
$canApplySupplier = (new SupplierApplyService())->checkCanApplySupplier($data['supplier_name']);
if ($canApplySupplier !== true) {
$this->externalResponse(-1, $canApplySupplier);
}
$result = (new SupplierApplyService())->applySupplier($data);
if (!$result) {
$this->externalResponse(-1, '申请供应商失败');
}
$this->externalResponse(0, '申请供应商成功');
}
} }
...@@ -31,16 +31,21 @@ class CheckLogin ...@@ -31,16 +31,21 @@ class CheckLogin
} }
$hasSyncRoute = strpos($request->path(), 'sync/'); $hasSyncRoute = strpos($request->path(), 'sync/');
if ($hasSyncRoute === 0) { if ($hasSyncRoute === 0) {
return $next($request); return $next($request);
} }
//跳过特定的路由
$hasExternalRoute = strpos($request->path(), 'external/');
if ($hasExternalRoute !== false) {
return $next($request);
}
if (!$userId || !$skey || (string)((int)$userId) != $userId || !preg_match('/^[a-zA-Z0-9]+$/', $skey)) { if (!$userId || !$skey || (string)((int)$userId) != $userId || !preg_match('/^[a-zA-Z0-9]+$/', $skey)) {
if ($isApi) { if ($isApi) {
return ["errcode" => 101, "errmsg" => "没有登录"]; return ["errcode" => 101, "errmsg" => "没有登录"];
} }
return redirect($login['login'] . '?redirect=' . urlencode($request->fullUrl().'?from=login')); return redirect($login['login'] . '?redirect=' . urlencode($request->fullUrl() . '?from=login'));
} }
$cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $skey; $cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $skey;
......
<?php
namespace App\Http\Services;
//后台用户相关信息服务
use App\Model\SupplierApplyModel;
use App\Model\SupplierBlacklistModel;
use App\Model\SupplierChannelModel;
use Illuminate\Support\Facades\DB;
class SupplierApplyService
{
//判断是否能申请供应商
public function checkCanApplySupplier($supplierName)
{
//先去判断是否已经有申请,并且是通过或者待审核的,如果是的话,直接返回已申请
$supplierName = trim($supplierName);
$supplier = SupplierChannelModel::where('supplier_name', $supplierName)->first();
$supplier = !empty($supplier) ? $supplier->toArray() : [];
if ($supplier) {
$existSupplierApply = SupplierApplyModel::where('supplier_id', $supplier['supplier_id'])
->whereIn('status', [SupplierApplyModel::STATUS_NEED_AUDIT, SupplierApplyModel::STATUS_PASS])->exists();
if ($existSupplierApply) {
return '贵司已申请云芯入驻,无需重复申请';
}
//再去判断是否有上传sku
$uploadedSku = $supplier['uploaded_sku'];
if ($uploadedSku != SupplierChannelModel::HAS_UPLOADED_SKU) {
return '贵司暂未与猎芯进行商品接入合作,请先联系猎芯对应采购经理或渠道经理进行商品合作';
}
}else{
//供应商不存在
return '贵司暂未入驻猎芯网,请先申请供应商入驻';
}
return true;
}
//申请供应商(通过供应商名称,申请已经存在的供应商)
public function applySupplier($data)
{
$supplierId = SupplierChannelModel::where('supplier_name', $data['supplier_name'])->value('supplier_id');
$data['create_time'] = time();
$data['supplier_id'] = $supplierId;
return SupplierApplyModel::insert($data);
}
//审核供应商申请
public function auditSupplierApply($applyId,$status,$auditReason)
{
return SupplierApplyModel::where('id',$applyId)->update([
'status' => $status,
'audit_reason' => $auditReason,
'update_time' => time(),
'audit_time' => time(),
'audit_name'=> request()->user->name,
'audit_uid' => request()->user->userId,
]);
}
}
\ No newline at end of file
...@@ -53,6 +53,8 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -53,6 +53,8 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
//提供给其它系统使用的接口,不需要验证那种 //提供给其它系统使用的接口,不需要验证那种
Route::group(['middleware' => ['external'], 'namespace' => 'Api'], function () { Route::group(['middleware' => ['external'], 'namespace' => 'Api'], function () {
Route::get('/api/external/searchSupplier', 'ExternalApiController@searchSupplier'); Route::get('/api/external/searchSupplier', 'ExternalApiController@searchSupplier');
Route::match(['get', 'post'], '/api/external/checkSupplierApply', 'ExternalApiController@checkSupplierApply');
Route::match(['get', 'post'], '/api/external/applySupplier', 'ExternalApiController@applySupplier');
}); });
//同步相关的接口 //同步相关的接口
...@@ -63,5 +65,4 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function () ...@@ -63,5 +65,4 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
// (new \App\Http\Services\DataService())->exportSupplier();
}); });
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class SupplierApplyModel extends Model
{
protected $connection='web';
protected $table='supplier_apply';
protected $primaryKey = 'id';
public $timestamps = false;
const STATUS_PASS = 2;
const STATUS_NEED_AUDIT = 1;
const STATUS_REJECT = -1;
public function supplierChannel()
{
return $this->hasOne(SupplierChannelModel::class, 'supplier_id', 'supplier_id');
}
}
...@@ -41,6 +41,9 @@ class SupplierChannelModel extends Model ...@@ -41,6 +41,9 @@ class SupplierChannelModel extends Model
//供应商地区 //供应商地区
const REGION_CN = 2; //国内 const REGION_CN = 2; //国内
//有上传过SKU
const HAS_UPLOADED_SKU = 1;
//黑名单信息 //黑名单信息
public function blacklist() public function blacklist()
......
...@@ -35,7 +35,7 @@ return [ ...@@ -35,7 +35,7 @@ return [
'digits' => 'The :attribute must be :digits digits.', 'digits' => 'The :attribute must be :digits digits.',
'digits_between' => 'The :attribute must be between :min and :max digits.', 'digits_between' => 'The :attribute must be between :min and :max digits.',
'distinct' => 'The :attribute field has a duplicate value.', 'distinct' => 'The :attribute field has a duplicate value.',
'email' => 'The :attribute must be a valid email address.', 'email' => '邮箱地址不合法',
'exists' => 'The selected :attribute is invalid.', 'exists' => 'The selected :attribute is invalid.',
'filled' => 'The :attribute field is required.', 'filled' => 'The :attribute field is required.',
'image' => 'The :attribute must be an image.', 'image' => 'The :attribute must be an image.',
...@@ -45,23 +45,23 @@ return [ ...@@ -45,23 +45,23 @@ return [
'ip' => 'The :attribute must be a valid IP address.', 'ip' => 'The :attribute must be a valid IP address.',
'json' => 'The :attribute must be a valid JSON string.', 'json' => 'The :attribute must be a valid JSON string.',
'max' => [ 'max' => [
'numeric' => 'The :attribute may not be greater than :max.', 'numeric' => ':attribute 不能超过最大值 :max',
'file' => 'The :attribute may not be greater than :max kilobytes.', 'file' => 'The :attribute may not be greater than :max kilobytes.',
'string' => 'The :attribute may not be greater than :max characters.', 'string' => ':attribute 不能超过 :max 个字符',
'array' => 'The :attribute may not have more than :max items.', 'array' => 'The :attribute may not have more than :max items.',
], ],
'mimes' => 'The :attribute must be a file of type: :values.', 'mimes' => 'The :attribute must be a file of type: :values.',
'min' => [ 'min' => [
'numeric' => 'The :attribute must be at least :min.', 'numeric' => ':attribute 最小为 :min',
'file' => 'The :attribute must be at least :min kilobytes.', 'file' => 'The :attribute must be at least :min kilobytes.',
'string' => 'The :attribute must be at least :min characters.', 'string' => ':attribute 必须最少 :min 个字符',
'array' => 'The :attribute must have at least :min items.', 'array' => 'The :attribute must have at least :min items.',
], ],
'not_in' => 'The selected :attribute is invalid.', 'not_in' => 'The selected :attribute is invalid.',
'numeric' => 'The :attribute must be a number.', 'numeric' => 'The :attribute must be a number.',
'present' => 'The :attribute field must be present.', 'present' => 'The :attribute field must be present.',
'regex' => 'The :attribute format is invalid.', 'regex' => 'The :attribute format is invalid.',
'required' => 'The :attribute field is required.', 'required' => ':attribute 不能为空',
'required_if' => 'The :attribute field is required when :other is :value.', 'required_if' => 'The :attribute field is required when :other is :value.',
'required_unless' => 'The :attribute field is required unless :other is in :values.', 'required_unless' => 'The :attribute field is required unless :other is in :values.',
'required_with' => 'The :attribute field is required when :values is present.', 'required_with' => 'The :attribute field is required when :values is present.',
......
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