Commit 71715610 authored by hj's avatar hj

更新

parent 60432502
<?php
namespace App\Exceptions;
use Illuminate\Auth\AuthenticationException;
class AuthenticateException extends AuthenticationException
{
public function __construct(string $message = '', array $guards = [], $redirectTo = null)
{
$this->code = 401;
parent::__construct($message, $guards, $redirectTo);
}
}
\ No newline at end of file
<?php
namespace App\Exceptions;
use Symfony\Component\HttpKernel\Exception\HttpException;
class NotFoundHttpException extends HttpException
{
public function __construct(string $message = '', \Throwable $previous = null)
{
parent::__construct(404, $message, $previous);
}
}
<?php
namespace App\Exceptions;
class ResourcesException extends \Exception
{
public function __construct(string $message = '', \Throwable $previous = null)
{
parent::__construct($message,200, $previous);
}
}
<?php
namespace App\Exceptions;
class ServerRunTimeException extends \Exception
{
public function __construct(string $message = '', \Throwable $previous = null)
{
parent::__construct($message,500, $previous);
}
}
<?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\Rhawn\Repositories\Contracts\Chemsite;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface ChemsiteCustomerRepository extends RepositoryInterface
{
}
...@@ -16,17 +16,17 @@ use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent; ...@@ -16,17 +16,17 @@ use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent;
abstract class BaseRepository extends BaseRepositoryEloquent abstract class BaseRepository extends BaseRepositoryEloquent
{ {
protected function getConnectionName() protected function getConnectionName(): ?string
{ {
return app($this->model())->getConnectionName(); return $this->makeModel()->getConnectionName();
} }
protected function getTableName() protected function getTableName(): string
{ {
return app($this->model())->getTable(); return $this->makeModel()->getTable();
} }
public function getConnection() public function getConnection(): \Illuminate\Database\ConnectionInterface
{ {
return DB::connection($this->getConnectionName()); return DB::connection($this->getConnectionName());
} }
......
...@@ -17,7 +17,7 @@ class BhuaBrandsRepositoryEloquent extends BaseRepository implements BhuaBrandsR ...@@ -17,7 +17,7 @@ class BhuaBrandsRepositoryEloquent extends BaseRepository implements BhuaBrandsR
* *
* @return string * @return string
*/ */
public function model() public function model(): string
{ {
return BhuaBrands::class; return BhuaBrands::class;
} }
...@@ -48,7 +48,7 @@ class BhuaBrandsRepositoryEloquent extends BaseRepository implements BhuaBrandsR ...@@ -48,7 +48,7 @@ class BhuaBrandsRepositoryEloquent extends BaseRepository implements BhuaBrandsR
return null; return null;
} }
public function getBrandById($id) public function getBrandById($id): array
{ {
$brand = $this->findWhere(['b_id' => $id]); $brand = $this->findWhere(['b_id' => $id]);
return $brand->toArray(); return $brand->toArray();
......
<?php
namespace App\Rhawn\Repositories\Eloquent\Chemsite;
use App\Rhawn\Repositories\Contracts\Chemsite\ChemsiteCustomerRepository;
use App\Rhawn\Repositories\Eloquent\BaseRepository;
use App\Rhawn\Repositories\Models\Chemsite\ChemsiteCustomer;
use App\Rhawn\Repositories\Models\RhawnCustomer;
use Illuminate\Support\Facades\DB;
/**
* Class UserRepositoryEloquent.
*/
class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements ChemsiteCustomerRepository
{
/**
* Specify Model class name.
*
* @return string
*/
public function model(): string
{
return ChemsiteCustomer::class;
}
public function getRhawnCustomerThroughtCusCode($cusCode)
{
$customer = $this->findWhere(['cus_no' => $cusCode])->first();
if($customer){
return $customer->toArray();
}
return null;
}
public function getCustomerList($where,$offset,$limit)
{
$customerModel = DB::connection($this->getConnectionName())->table($this->getTableName());
if(!empty($where)){
$customerModel = $customerModel->where($where);
}
$customerInfo = $customerModel->offset($offset)
->limit($limit)
->get();
if($customerInfo){
return $customerInfo->toArray();
}
return null;
}
/**
* 获取客户折扣信息
* @param $cusCode
* @return array
*/
public function getCustomerDiscountByCusCode($cusCode)
{
$customerDiscount = RhawnCustomer::query()
->join('cusdiscount','cusdiscount.cus_id','customers.cus_id')
->where('customers.cus_no',$cusCode)
->get();
$cusdiscountArr = [];
if($customerDiscount){
$customerDiscount = $customerDiscount->toArray();
foreach($customerDiscount as $k=>$v){
$cusdiscountArr[$v['b_id']]['cd_discount'] = $v['cd_discount'];
$cusdiscountArr[$v['b_id']]['cd_pre_discount'] = $v['cd_pre_discount'];
}
}
return $cusdiscountArr;
}
/**
* 获取客户地址信息
* @param $cusCode
* @return array|null
*/
public function getCustomerAddressByCusCode($cusCode)
{
$customerAddress = RhawnCustomer::query()
->join('cusiaddrs','cusiaddrs.cus_id','customers.cus_id')
->where('customers.cus_no',$cusCode)
->orderBy('cusiaddrs.cia_if_default','DESC')
->orderBy('cusiaddrs.cia_id','DESC')
->get();
if($customerAddress){
return $customerAddress->toArray();
}
return null;
}
/**
* 获取客户开票信息
* @param $cusCode
* @return array
*/
public function getCustomerInvoiceByCusCode($cusCode)
{
$customerInvoice = RhawnCustomer::query()
->join('cusinvoice','cusinvoice.cus_id','customers.cus_id')
->where('customers.cus_no',$cusCode)
->orderBy('cusinvoice.ci_if_default','DESC')
->orderBy('cusinvoice.ci_id','DESC')
->get();
if($customerInvoice){
$customerInvoice = $customerInvoice->toArray();
foreach($customerInvoice as &$invoice){
if($invoice['ci_type'] == 1){
$invoice['ci_type_name'] = '普票';
}
if($invoice['ci_type'] == 2){
$invoice['ci_type_name'] = '专票';
}
}
return $customerInvoice;
}
return null;
}
}
<?php
namespace App\Rhawn\Repositories\Models\Chemsite;
use App\Repositories\Models\Model;
class ChemsiteCustomer extends Model
{
protected $table = 'customers';
protected $connection = 'chemsite_mysql';
protected $primaryKey = 'cus_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
];
protected $guarded = ['created_at', 'updated_at'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
];
/**
* update时不做自动更新时间操作
* @return null
*/
public function getUpdatedAtColumn()
{
return null;
}
public function getCreatedAtColumn()
{
return null;
}
}
\ No newline at end of file
<?php
namespace App\Rhawn\Services\Chemsite;
use App\Exceptions\ServerRunTimeException;
use App\Rhawn\Repositories\Contracts\Chemsite\ChemsiteCustomerRepository;
class ChemsiteCustomerService
{
private ChemsiteCustomerRepository $customerRepository;
public function __construct(ChemsiteCustomerRepository $chemsiteCustomerRepository)
{
$this->customerRepository = $chemsiteCustomerRepository;
}
public function getCustomerThroughCusCode($cusCode)
{
return $this->customerRepository->getRhawnCustomerThroughtCusCode($cusCode);
}
public function getCustomerListByCusCode($cusNo,$offset,$limit): ?array
{
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;
}
}
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