Commit 9687d606 authored by hj's avatar hj

更新

parent 71715610
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Http\Controllers\V1\Chemsite;
use App\Services\Api\Chemsite\ChemsiteCustomerService;
use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response;
use App\Http\Controllers\V1\Controller;
use App\Support\Traits\Helpers;
class CustomerController extends Controller
{
use Helpers;
public function __construct(ChemsiteCustomerService $chemsiteCustomerService)
{
$this->chemsiteCustomerService= $chemsiteCustomerService;
$this->controllerType = 'chemsite';
}
public function getCustomer(Request $request)
{
$customerCode = $request->get('customer_code');
if(!$customerCode){
return Response::ok('客户编号不存在!');
}
try{
$customer = $this->chemsiteCustomerService->getCustomerByNumber($customerCode);
return Response::success($this->formatKeysfromArray($customer),'操作成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'获取订单列表失败');
}
}
}
...@@ -14,6 +14,7 @@ namespace App\Repositories\Eloquent; ...@@ -14,6 +14,7 @@ namespace App\Repositories\Eloquent;
use App\Repositories\Presenters\Presenter; use App\Repositories\Presenters\Presenter;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Arr;
use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent; use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent;
abstract class BaseRepository extends BaseRepositoryEloquent abstract class BaseRepository extends BaseRepositoryEloquent
...@@ -82,6 +83,14 @@ abstract class BaseRepository extends BaseRepositoryEloquent ...@@ -82,6 +83,14 @@ abstract class BaseRepository extends BaseRepositoryEloquent
return $returnRecord; return $returnRecord;
} }
public function transformData($datas, $modelName = null)
{
if(is_null($modelName)){
return Arr::pluck($datas, null);
}
return app($modelName)->transform(Arr::pluck($datas, null));
}
protected function getConnectionName() protected function getConnectionName()
{ {
return app($this->model())->getConnectionName(); return app($this->model())->getConnectionName();
......
...@@ -23,13 +23,9 @@ class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements Chems ...@@ -23,13 +23,9 @@ class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements Chems
return ChemsiteCustomer::class; return ChemsiteCustomer::class;
} }
public function getRhawnCustomerThroughtCusCode($cusCode) public function getCustomerThroughCusCode($cusCode)
{ {
$customer = $this->findWhere(['cus_no' => $cusCode])->first(); return $this->findWhere(['cus_no' => $cusCode])->first();
if($customer){
return $customer->toArray();
}
return null;
} }
public function getCustomerList($where,$offset,$limit) public function getCustomerList($where,$offset,$limit)
......
...@@ -16,28 +16,12 @@ class ChemsiteCustomerService ...@@ -16,28 +16,12 @@ class ChemsiteCustomerService
public function getCustomerThroughCusCode($cusCode) public function getCustomerThroughCusCode($cusCode)
{ {
return $this->customerRepository->getRhawnCustomerThroughtCusCode($cusCode); $customer = $this->customerRepository->getCustomerThroughCusCode($cusCode);
return $customer->toArray();
} }
public function getCustomerListByCusCode($cusNo,$offset,$limit): ?array public function getCustomerListByCusCode($cusNo,$offset,$limit): ?array
{ {
return $this->customerRepository->getCustomerList(['cus_no' => $cusNo],$offset,$limit); return $this->customerRepository->getCustomerList(['cus_no' => $cusNo],$offset,$limit);
} }
/**
* 检查客户信息是否存在
* @param $cusCode
* @return mixed
* @throws ServerRunTimeException
*/
public function checkCustomerExist($cusCode)
{
//查询用户是否存在
$customer = $this->customerRepository->getRhawnCustomerThroughtCusCode($cusCode);
if(!$customer){
throw new ServerRunTimeException('客户编号为:['.$cusCode.']的用户不存在!');
}
return $customer;
}
} }
<?php
namespace App\Services\Api\Chemsite;
use App\Repositories\Eloquent\BaseRepository;
class ChemsiteCustomerService
{
private $chemsiteCustomerService;
public function __construct(\App\Rhawn\Services\Chemsite\ChemsiteCustomerService $chemsiteCustomerService)
{
$this->chemsiteCustomerService = $chemsiteCustomerService;
}
public function getCustomerByNumber($customerNumber)
{
$customer = $this->chemsiteCustomerService->getCustomerThroughCusCode($customerNumber);
return app(BaseRepository::class)->transformData($customer);
}
}
<?php <?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$api->version('v1', function($api) { $api->version('v1', function($api) {
//获取token //获取token
...@@ -59,5 +48,10 @@ $api->version('v1', function($api) { ...@@ -59,5 +48,10 @@ $api->version('v1', function($api) {
$api->group(['namespace'=>'App\Http\Controllers\V1\Bhua','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) { $api->group(['namespace'=>'App\Http\Controllers\V1\Bhua','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
$api->post('/openapi/bhua/invoice/getInvoiceSorderItems', ['permission' => 'orders.getInvoiceSorderItems', 'uses'=>'InvoiceController@getInvoiceSorderItems']); $api->post('/openapi/bhua/invoice/getInvoiceSorderItems', ['permission' => 'orders.getInvoiceSorderItems', 'uses'=>'InvoiceController@getInvoiceSorderItems']);
}); });
// chemsite接口
$api->group(namespace'=>'App\Http\Controllers\V1\Chemsite','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
$api->post('/openapi/chemsite/orders/getCustomer', ['permission' => 'chemsite.customer.search', 'uses'=>'CustomerController@getCustomer']);
});
}); });
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 to comment