Commit 769dbce0 authored by hangjun83's avatar hangjun83

百化接口

parent e243164c
......@@ -68,6 +68,7 @@ class Authenticate
}
$params = $request->all();
// 内部平台调用
if(isset($params['platform']) && !empty($params['platform'])){
switch($params['platform']){
case 'zkh' : $platformToken = app(ZhenKhService::class)->apiService->getPlatformInfo('platform_token');break;
......
<?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\Bhua;
use App\Services\Api\BhuaOrdersService;
use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response;
use App\Http\Controllers\V1\Controller;
use App\Support\Traits\Helpers;
use OpenApi\Annotations\Post;
use OpenApi\Annotations\RequestBody;
use OpenApi\Annotations\MediaType;
use OpenApi\Annotations\Schema;
use OpenApi\Annotations\Property;
use OpenApi\Annotations\Response as AnnotationResponse;
use OpenApi\Annotations as OA;
class OrdersController extends Controller
{
use Helpers;
public function __construct(BhuaOrdersService $bhuaOrdersService)
{
$this->bhuaOrdersService = $bhuaOrdersService;
}
/**
*
* @Post(
* path="/openapi/orders/createRhawnOrders",
* tags={"订单相关接口"},
* summary="生成用户新订单",
* description="生成新订单",
* @RequestBody(
* @MediaType(
* mediaType="application/json",
* @Schema(
* required={"soCusPo", "soCaName","soCaMobile","soCaPhone","soCaProvince","soCaCity","soCaStreet","soNote","items"},
* @Property(property="soCusPo", @Schema(type="string"),description="客户编号"),
* @Property(property="soCaName", @Schema(type="string"),description="收货人"),
* @Property(property="soCaMobile", @Schema(type="string"),description="收货人手机"),
* @Property(property="soCaPhone", @Schema(type="string"),description="收货人电话"),
* @Property(property="soCaProvince", @Schema(type="string"),description="收货人省份"),
* @Property(property="soCaCity", @Schema(type="string"),description="收货人城市"),
* @Property(property="soCaStreet", @Schema(type="string"),description="收货人区县"),
* @Property(property="soNote", @Schema(type="string"),description="备注"),
* @Property(property="items", type="array",
* @OA\items(
* @Property(property="pCode", @Schema(type="string"),description="产品code"),
* @Property(property="num", @Schema(type="integer"),description="产品数量"),
* ),description="当前页数"),
* example={
"soCusPo": "2000000011111",
"soCaName": "张三",
"soCaMobile": "13321686555",
"soCaPhone": "61111111",
"soCaProvince": "上海",
"soCaCity": "上海市",
"soCaStreet": "望园路88888号888室",
"soNote": "测试",
"items": {{
"pCode": "R000001-20mg",
"num" : "1",
* }}
* }
* )
* )
* ),
* @OA\Parameter(
* description="用户获取的token值",
* in="header",
* name="authorization",
* required=true,
* @OA\Schema(type="string"),
* @OA\Examples(example="authorization", value="bearerNWJiNDhkNzlmNjg0N2FlMmZiYjliZWM3NGVkNzIyMjNleUpsZUhCcGNtVWlPakUyTmpRMk1EazJORGNzSW1oaGMyZ2lPaUl5ZEhsc1JIQlhkWFpNUVdaWGJVRllJbjA9",summary=""),
* ),
* @AnnotationResponse(
* response="200",
* description="正常操作响应",
* @MediaType(
* mediaType="application/json",
* @Schema(
* allOf={
* @Schema(ref="#/components/schemas/ApiResponse"),
* @Schema(
* type="object",
* @Property(property="data", ref="#/components/schemas/OrdersDetail")
* )
* }
* )
* )
* ),
* security={
* {"bearer_token":{}}
* }
* )
*/
public function createCustomerNewOrder(Request $request)
{
$customerCode = $request->get('customer_code');
if(!$customerCode){
return Response::ok('客户编号不存在!');
}
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
$requestParams = array_merge($requestParams,['customer_code' => $customerCode]);
try{
$orderDetail = $this->bhuaOrdersService->createNewCustomerOrders($requestParams);
if($orderDetail){
$orderDetail = $this->formatKeysfromArray($orderDetail,'toCamelCase');
}
return Response::success($orderDetail,'操作成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'生成订单失败');
}
}
}
<?php
namespace App\Http\Controllers\V1\Bhua;
use App\Services\Api\BhuaProductsService;
use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response;
use App\Http\Controllers\V1\Controller;
use App\Support\Traits\Helpers;
use OpenApi\Annotations\Post;
use OpenApi\Annotations\RequestBody;
use OpenApi\Annotations\MediaType;
use OpenApi\Annotations\Schema;
use OpenApi\Annotations\Property;
use OpenApi\Annotations\Response as AnnotationResponse;
use OpenApi\Annotations as OA;
class ProductsController extends Controller
{
use Helpers;
public function __construct(BhuaProductsService $bhuaProductService)
{
$this->bhuaProdcutService = $bhuaProductService;
}
public function getAllBrands(Request $request)
{
$customerCode = $request->get('customer_code');
if(!$customerCode){
return Response::ok('客户编号不存在!');
}
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
$requestParams = array_merge($requestParams,['customer_code' => $customerCode]);
try{
$brandsList = $this->bhuaProdcutService->getAllBrands($requestParams);
if($brandsList){
$brandsList = $this->formatKeysfromArray($brandsList,'toCamelCase');
}
return Response::success($brandsList,'操作成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'获取品牌列表失败');
}
}
}
<?php
namespace App\Http\Controllers\V1;
use App\Services\Api\BhuaProductsService;
use App\Services\CustomerService;
use Illuminate\Http\Request;
use Jiannei\Response\Laravel\Support\Facades\Response;
use App\Http\Controllers\V1\Controller;
use App\Support\Traits\Helpers;
class CustomersController extends Controller
{
use Helpers;
public function __construct(CustomerService $customerService)
{
$this->customerService = $customerService;
}
public function createCustomer(Request $request)
{
$message = [
'customerCode.required' => "客户编号必传",
'customerType.required' => "客户类型必传",
];
$this->validateRequest($request, $message);
$requestParams = $this->formatKeysfromArray($request->all(),'toUnderScore');
try{
$customer = $this->customerService->createPlatformCustomer($requestParams);
return Response::success($customer,'操作成功');
}catch(\Throwable $exception){
return $this->returnErrorExecptionResponse($exception,'生成订单失败');
}
}
}
<?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\Repositories\Transformers\Rhawn\Bhua;
use League\Fractal\TransformerAbstract;
class BrandsTransformer extends TransformerAbstract
{
public function transform($brands)
{
$brandsTransReturn = [];
if($brands){
foreach($brands as $brand){
$temp = [];
$temp['b_id'] = $brand['b_id'];//中文别名
$temp['b_cn_name'] = $brand['b_cn_name'];//CAS号
$temp['b_en_name'] = $brand['b_en_name'];//中文名
array_push($brandsTransReturn,$temp);
}
}
return $brandsTransReturn;
}
}
<?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;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhuaBrandsRepository extends RepositoryInterface
{
}
<?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;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhuaCustomerRepository extends RepositoryInterface
{
}
<?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;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhuaProductRepository extends RepositoryInterface
{
}
<?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;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhuaSoitemsRepository extends RepositoryInterface
{
}
<?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;
use Prettus\Repository\Contracts\RepositoryInterface;
/**
* Interface UserRepository.
*/
interface BhuaSordersRepository extends RepositoryInterface
{
}
<?php
namespace App\Rhawn\Repositories\Eloquent;
use App\Rhawn\Repositories\Contracts\BhuaBrandsRepository;
use App\Rhawn\Repositories\Models\BhuaBrands;
use Illuminate\Support\Facades\DB;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhuaBrandsRepositoryEloquent extends BaseRepository implements BhuaBrandsRepository
{
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhuaBrands::class;
}
/**
* 获取产品信息
* @param $where
* @param $offset
* @param $pageSize
* @return null
*/
public function getList($where, $offset, $limit)
{
$model = BhuaBrands::query();
if(!empty($where)){
foreach($where as $key => $w){
if(!is_array($w)){
$model->where($key,$w);
}else{
$model->whereIn($key,$w);
}
}
}
$brandslist = $model->offset($offset)->limit($limit)->get();
if($brandslist){
return $brandslist->toArray();
}
return null;
}
}
<?php
namespace App\Rhawn\Repositories\Eloquent;
use App\Rhawn\Repositories\Contracts\RhawnCustomerRepository;
use App\Rhawn\Repositories\Models\BhuaCustomer;
use Illuminate\Support\Facades\DB;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhuaCustomerRepositoryEloquent extends BaseRepository implements RhawnCustomerRepository
{
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhuaCustomer::class;
}
public function getCustomerThroughtCusCode($cusCode)
{
$customer = $this->findWhere(['cus_no' => $cusCode])->first();
if($customer){
return $customer->toArray();
}
return null;
}
/**
* 获取客户折扣信息
* @param $cusCode
* @return array
*/
public function getDiscountByCusCode($cusCode)
{
$customerDiscount = $this
->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 = $this
->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 = $this
->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\Eloquent;
use App\Rhawn\Repositories\Contracts\RhawnProductRepository;
use App\Rhawn\Repositories\Models\BhuaProducts;
use Illuminate\Support\Facades\DB;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhuaProductRepositoryEloquent extends BaseRepository implements RhawnProductRepository
{
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhuaProducts::class;
}
/**
* 根据p_code获取产品信息
* @param $pCode
* @return null
*/
public function getProductByPcode($pCode)
{
$productsModel = $this->join('chemicals', 'chemicals.c_id','products.c_id')->join('raw', 'raw.r_id','products.r_id');
if(!is_array($pCode)){
$productsModel->where('products.p_code',$pCode);
}else{
$productsModel->whereIn('products.p_code',$pCode);
}
$product = $productsModel->get();
if($product){
return $product->toArray();
}
return null;
}
public function getProductsByWhere(array $where)
{
$productsModel = $this->join('chemicals', 'chemicals.c_id','products.c_id');
foreach($where as $key => $w){
if(!is_array($w)){
$productsModel->where($key,$w);
}else{
$productsModel->whereIn($key,$w);
}
}
$product = $productsModel->get();
if($product){
return $product->toArray();
}
return null;
}
/**
* 根据pid获取产品对应的促销信息
* @param $pId
* @return array|null
*/
public function getProductPromotionByPid($pId)
{
$promotionsModel = DB::connection($this->getConnectionName())
->table('promotions_products')
->join('promotions','promotions.pt_id','promotions_products.pt_id');
if(is_array($pId)){
$promotionsModel->whereIn('promotions_products.p_id',$pId);
}else{
$promotionsModel->where('promotions_products.p_id',$pId);
}
/*$promotions = $promotionsModel->where('promotions.pt_start','<=',time())
->where('promotions.pt_end','>=',time())
->get();*/
$promotions = $promotionsModel->get();
if($promotions){
$promotions = $promotions->toArray();
return $promotions;
}
return null;
}
/**
* 获取所有产品的包装规格
* @return array
*/
public function getProductPackagesThroughGroupByPackUnit()
{
$packages = $this
->select('p_pack','p_pack_unit')
->groupBy('p_pack','p_pack_unit')
->get();
return $packages->toArray();
}
/**
* 获取产品信息
* @param $where
* @param $offset
* @param $pageSize
* @return null
*/
public function getProductsList($where, $offset, $limit)
{
$productsModel = $this->join('chemicals', 'chemicals.c_id','products.c_id')->join('raw', 'raw.r_id','products.r_id');
if(!empty($where)){
foreach($where as $key => $w){
if(!is_array($w)){
$productsModel->where($key,$w);
}else{
$productsModel->whereIn($key,$w);
}
}
}
$product = $productsModel->offset($offset)->limit($limit)->get();
if($product){
return $product->toArray();
}
return null;
}
public function getProductsByCas($cas)
{
$productsModel = $this->join('chemicals', 'chemicals.c_id','products.c_id')->join('raw', 'raw.r_id','products.r_id');
$product = $productsModel->where('chemicals.c_cas',$cas)->get();
if($product){
return $product->toArray();
}
return null;
}
}
<?php
namespace App\Rhawn\Repositories\Eloquent;
use App\Rhawn\Repositories\Contracts\BhuaSordersRepository;
use App\Rhawn\Repositories\Contracts\RhawnSoitemsRepository;
use App\Rhawn\Repositories\Contracts\RhawnSordersRepository;
use App\Rhawn\Repositories\Models\BhuaSoitems;
use App\Rhawn\Repositories\Models\RhawnSoitems;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhuaSoitemsRepositoryEloquent extends BaseRepository implements RhawnSoitemsRepository
{
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhuaSoitems::class;
}
/**
* 获取订单详情
* @param $orderId
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function getSorderItemsDetailFromOrderId($orderId)
{
$order = app(BhuaSordersRepository::class)->find($orderId);
if(!$order){
throw new \LogicException('该订单不存在!',500);
}
//查询订单的详情
$soItems = $this
->join('products','soitems.p_id','products.p_id')
->join('chemicals','products.c_id','chemicals.c_id')
->join('brands','products.b_id','brands.b_id')
->where('soitems.so_id',$order->so_id)->get();
if($soItems){
return $soItems->toArray();
}
return null;
}
public function getSorderItemsDetailFromItemId($itemId,$pid=null)
{
//查询订单的详情
$soItems = $this
->join('sorders','sorders.so_id','soitems.so_id')
->join('products','soitems.p_id','products.p_id')
->join('chemicals','products.c_id','chemicals.c_id')
->join('brands','products.b_id','brands.b_id')
->where('soitems.si_id',$itemId);
if(!is_null($pid)){
$soItems = $soItems->where('soitems.p_id',$pid);
}
$soItems = $soItems->get();
if($soItems){
return $soItems->toArray();
}
return null;
}
/**
* 根据si_id获取订单明细项
* @param $si_id
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
*/
public function getSorderItemFromItemId($si_id)
{
$item = $this->find($si_id);
if(!$item){
throw new \LogicException('该订单项不存在!',500);
}
//查询订单的详情
$soModel = $this
->join('products','soitems.p_id','products.p_id')
->join('chemicals','chemicals.c_id','products.c_id');
if(is_array($si_id)){
$soModel->whereIn('soitems.si_id',$si_id);
}else{
$soModel->where('soitems.si_id',$si_id);
}
$soItems = $soModel->get();
if($soItems){
return $soItems->toArray();
}
return null;
}
public function getOrderItemsStockFromItemIds($id)
{
if(!is_array($id)){
$item = $this->find($id);
$id = (array)$id;
}else{
$item = $this->whereIn('si_id',$id)->get();
}
if(!$item){
throw new \LogicException('该订单项不存在!',500);
}
//查询订单的详情
$soItemStock = $this
->join('dpdetail','dpdetail.si_id','soitems.si_id')
->join('pstock','pstock.pstk_id','dpdetail.pstk_id')
->join('products','soitems.p_id','products.p_id')
->whereIn('soitems.si_id',$id)
->where('si_if_cancel',0)
//->where('dpdetail.dpd_invoiced','=',0)
->get();
if($soItemStock){
return $soItemStock->toArray();
}
return null;
}
}
<?php
namespace App\Rhawn\Repositories\Eloquent;
use App\Rhawn\Repositories\Contracts\BhuaBrandsRepository;
use App\Rhawn\Repositories\Models\BhuaSorders;
use Illuminate\Support\Facades\DB;
use Prettus\Validator\Contracts\ValidatorInterface;
/**
* Class UserRepositoryEloquent.
*/
class BhuaSordersRepositoryEloquent extends BaseRepository implements BhuaBrandsRepository
{
/**
* Specify Model class name.
*
* @return string
*/
public function model()
{
return BhuaSorders::class;
}
/**
* 返回指定订单编号的订单信息
* @param $order_no
* @return mixed
*/
public function getSorderFromOrderNo($orderNo)
{
$where = [
'so_no' => $orderNo
];
return $this->findWhere($where)->first();
}
public function getSorderFromOrderCusPo($orderNo)
{
$where = [
'so_cus_po' => $orderNo
];
return $this->findWhere($where)->first();
}
/**
* 获取订单详情
* @param $orderNo
* @return mixed
*/
public function getSorderItemsFromOrderNo($orderNo){
$soItems = $this
->join('soitems','soitems.so_id','sorders.so_id')
->where('sorders.so_no',$orderNo)->get();
if($soItems){
return $soItems->toArray();
}
return null;
}
/**
* 获取订单相关信息(包括,产品,客户,品牌等)
* @param $so_id
* @return mixed
*/
public function getSorderDetailFromOrderId($so_id)
{
$sOrderInfo = $this
->join('customers','sorders.cus_id','customers.cus_id')
->where('sorders.so_id',$so_id)
->get();
if(!$sOrderInfo){
return null;
}
$sOrderInfo = current($sOrderInfo->toArray());
$items = DB::connection($this->getConnectionName())->table('soitems')
->join('products','soitems.p_id','products.p_id')
->join('chemicals','products.c_id','chemicals.c_id')
->join('brands','products.b_id','brands.b_id')
->where('soitems.so_id',$so_id)
->get();
if(!$items){
$sOrderInfo['items'] = [];
}
$sOrderInfo['items'] = $items->toArray();
return $sOrderInfo;
}
/**
* 获取客户订单
* @param $userId
* @param $pageSize
* @param $offset
* @return array|null
*/
public function getOrdersListThroughtUserId($userId,$offset,$limit)
{
$sOrderInfo = DB::connection($this->getConnectionName())->table($this->getTableName())
->join('customers','customers.cus_id','sorders.cus_id')
->where('sorders.cus_id',$userId)
->offset($offset)
->limit($limit)
->get();
if($sOrderInfo){
return $sOrderInfo->toArray();
}
return null;
}
/**
* 获取客户订单详情
* @param $cusId
* @param $orderId
* @return null
*/
public function getCustomerOrderItemsByOrderId($cusId,$orderId)
{
$sOrderInfo = $this
->join('customers','sorders.cus_id','customers.cus_id')
->where('sorders.so_id',$orderId)
->where('sorders.cus_id',$cusId)
->first();
if(!$sOrderInfo){
return null;
}
$sOrderInfo = $sOrderInfo->toArray();
$itemRepository = app(BhuaSoitemsRepositoryEloquent::class);
$items = $itemRepository->getSorderItemsDetailFromOrderId($sOrderInfo['so_id']);
$sOrderInfo['items'] = [];
if($items){
$sOrderInfo['items'] = $items;
}
return $sOrderInfo;
}
public function getOrderDispatch($orderNumber)
{
$dpModel = $this->join('dispatch','dispatch.so_id','sorders.so_id')
->join('dpdetail','dpdetail.dp_id','dispatch.dp_id');
if(is_array($orderNumber)){
$dpModel->whereIn('sorders.so_no',$orderNumber);
}else{
$dpModel->where('sorders.so_no',$orderNumber);
}
$dpdetail = $dpModel->get();
if($dpdetail){
return $dpdetail->toArray();
}
return null;
}
}
......@@ -131,8 +131,6 @@ class RhawnSordersRepositoryEloquent extends BaseRepository implements RhawnSord
$itemRepository = app(RhawnSoitemsRepositoryEloquent::class);
$items = $itemRepository->getSorderItemsDetailFromOrderId($sOrderInfo['so_id']);
var_dump($items);
exit;
$sOrderInfo['items'] = [];
if($items){
$sOrderInfo['items'] = $items;
......
<?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\Models;
use App\Repositories\Models\Model;
class BhuaBrands extends Model
{
// 产品
protected $table = 'brands';
protected $connection = 'bh_mysql';
protected $primaryKey = 'b_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
];
/**
* 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
/*
* 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\Models;
use App\Repositories\Models\Model;
class BhuaCustomer extends Model
{
protected $table = 'customers';
protected $connection = 'bh_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
/*
* 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\Models;
use App\Repositories\Models\Model;
class BhuaProducts extends Model
{
// 产品
protected $table = 'products';
protected $connection = 'bh_mysql';
protected $primaryKey = 'p_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
];
/**
* 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
/*
* 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\Models;
use App\Repositories\Models\Model;
class BhuaSoitems extends Model
{
// 销售订单
protected $table = 'soitems';
protected $connection = 'bh_mysql';
protected $primaryKey = 'si_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
/*
* 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\Models;
use App\Repositories\Models\Model;
class BhuaSorders extends Model
{
// 产品
protected $table = 'sorders';
protected $connection = 'bh_mysql';
protected $primaryKey = 'so_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
];
/**
* 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
/*
* 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\Services;
use App\Rhawn\Repositories\Contracts\BhuaCustomerRepository;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class BhuaCustomerService
{
public function __construct(BhuaCustomerRepository $bhuaCustomerRepository)
{
$this->bhuaCustomerRepository = $bhuaCustomerRepository;
}
/**
* 检查客户信息是否存在
* @param $cusCode
* @return mixed
* @throws \Exception
*/
public function checkCustomerExist($cusCode)
{
//查询用户是否存在
$customer = $this->bhuaCustomerRepository->getCustomerThroughtCusCode($cusCode);
if(!$customer){
throw new \Exception('客户编号为:['.$cusCode.']的用户不存在!',500);
}
return $customer;
}
}
<?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\Services;
use App\Rhawn\Repositories\Contracts\BhuaSordersRepository;
use App\Rhawn\Repositories\Eloquent\BhuaCustomerRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\BhuaProductRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\BhuaSordersRepositoryEloquent;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class BhuaOrdersService
{
public function __construct(BhuaSordersRepository $bhuaSorderRepository)
{
$this->bhuaSorderRepository = $bhuaSorderRepository;
}
public function getCustomerOrderItems($cusCode, $soItems)
{
$customerReopository = app(BhuaCustomerRepositoryEloquent::class);
$discount = $customerReopository->getCustomerDiscountByCusCode($cusCode);
$total = 0;
$weight = 0;
$productRepository = app(BhuaProductRepositoryEloquent::class);
foreach($soItems as $k => $v){
$productInfo = $productRepository->getProductByPcode($v['p_code']);
if(!$productInfo){
throw new \Exception($v['p_code'].'不存在!',500);
}
$productInfo = current($productInfo);
if($productInfo['p_status'] == 0 || $productInfo['p_show'] == 0){
throw new \Exception($v['p_code'].'已下架!',500);
}
if(isset($discount[$productInfo['b_id']])){
$productInfo['p_discount'] = round($discount[$productInfo['b_id']]['cd_discount'] * $productInfo['p_price']);
}else{
$productInfo['p_discount'] = $productInfo['p_price'];
}
if(isset($v['si_molbase_pog'])){
$soItems[$k]['si_molbase_pog'] = $v['si_molbase_pog'];
}
//当前产品是否在促销设定里
$promotions = $productRepository->getProductPromotionByPid($productInfo['p_id']);
if($promotions){
foreach($promotions as $promotion){
if($promotion->pt_discount != 0){
$productInfo['p_discount'] = round($promotion->pt_discount * $productInfo['p_discount']);
}
}
}
$soItems[$k]['amount'] = round(bcmul($productInfo['p_discount'],$v['num'],3),2);
$soItems[$k]['weight'] = round(bcmul($productInfo['p_weight'],$v['num'],3),3);
//得到品牌
$brands = DB::connection($this->bhuaSorderRepository->getConnectionName())
->table('brands')
->where('b_id',$productInfo['b_id'])
->first();
if(!$brands){
throw new \Exception('品牌不存在',500);
}
$productInfo['b_cn_name'] = $brands->b_cn_name;
$soItems[$k]['product_info'] = $productInfo;
$total += $soItems[$k]['amount'];
$weight += $soItems[$k]['weight'];
}
$returnItems = [];
$returnItems['total'] = $total;
$returnItems['weight'] = $weight;
$returnItems['rows'] = $soItems;
return $returnItems;
}
/**
* 新增订单
* @param $data
* @return false
*/
public function createOrders($data)
{
$connection = DB::connection($this->bhuaSorderRepository->getConnectionName());
try{
$connection->beginTransaction();
$data['sorders']['so_no'] = '';
$data['sorders']['so_ctime'] = time();
//$data['sorders']['so_creater'] = $data[''];
$orderId = $connection->table('sorders')->insertGetId($data['sorders']);
$soNo = 1000000 + $orderId;
$soNo = date('Ymd',time()).'-'.$soNo;
$connection->table('sorders')
->where('so_id',$orderId)
->update([
'so_no' => $soNo
]);
$soitems = [];
foreach($data['soitems'] as $k => $v){
$soitems[$k]['so_id'] = $orderId;
$soitems[$k]['p_id'] = $v['p_id'];
$soitems[$k]['si_price'] = $v['si_price'];
$soitems[$k]['si_discount'] = $v['si_discount'];
$soitems[$k]['si_num'] = $v['si_num'];
$soitems[$k]['si_amount'] = $v['si_amount'];
$soitems[$k]['si_p_tod'] = $v['si_p_tod'];
/*if(isset($v['si_cus_note'])){
$soitems[$k]['si_cus_note'] = $v['si_cus_note'];
}else{
$soitems[$k]['si_cus_note'] = '';
}
if(isset($v['si_molbase_pog'])){
$soitems[$k]['si_molbase_pog'] = $v['si_molbase_pog'];
}else{
$soitems[$k]['si_molbase_pog'] = '';
}
$soitems[$k]['si_nodes'] = '';*/
$soitems[$k]['si_notes'] = '';
//$soitems[$k]['si_sales_note'] = '';
}
if($data['express'] > 0){
$soitems_count = count($soitems);
$soitems[$soitems_count]['so_id'] = $orderId;
$soitems[$soitems_count]['p_id'] = 0;
$soitems[$soitems_count]['si_price'] = 0;
$soitems[$soitems_count]['si_discount'] = 0;
$soitems[$soitems_count]['si_num'] = 0;
$soitems[$soitems_count]['si_amount'] = $data['express'];
/*$soitems[$soitems_count]['si_vamount'] = 0;
$soitems[$soitems_count]['si_p_tod'] = '';
$soitems[$soitems_count]['si_cus_note'] = '';
$soitems[$soitems_count]['si_molbase_pog'] = '';
$soitems[$soitems_count]['si_nodes'] = '';*/
$soitems[$soitems_count]['si_notes'] = '';
//$soitems[$soitems_count]['si_sales_note'] = '';
}
$connection->table('soitems')->insert($soitems);
$connection->table('logs')->insert(
[
'l_obj'=>$orderId,
'l_type'=>'sorders_mng',
'l_op'=>'add',
'l_op_name'=>'新增',
'l_note'=>$data['sorders']['so_note'],
'l_timestamp'=>time(),'u_id'=>$data['sorders']['creater']
]
);
$connection->commit();
return $orderId;
}catch(\Throwable $exception){
$connection->rollBack();
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':createOrders','error');
throw $exception;
}
}
/**
* 计算运费
* @param $weight
* @param $province
* @param $total
* @param $if_free_express
* @param $cus_level
* @return float|int
*/
public function getExpress($weight,$province,$total,$if_free_express,$cus_level){
//计算运费 (运费=首重(1kg)*运输系数(首重)+续重(总重量-1kg)*运输系数(续重))
$express = 0;
if($if_free_express == 1 || $cus_level == 3){
return $express;
}else{
if($cus_level == 0){
$max_amount = 150;
}
if($cus_level == 1){
$max_amount = 99;
}
if($cus_level == 2){
$max_amount = 66;
}
//统一调整为满66免运费
//$max_amount = 66;
if($weight == 0){
$weight = 0.1;
}
if($total < $max_amount && $weight > 0){
$weight = ceil($weight);
if($province == '江苏省' || $province == '浙江省' || $province == '上海' || $province == '上海市'){
$express = ($weight - 1)*2 + 6;
}else{
$express = ($weight - 1)*8 + 10;
}
}
return $express;
}
}
public function getCustomerOrderItemsByOrderId($cusId, $orderId)
{
return $this->bhuaSorderRepository->getCustomerOrderItemsByOrderId($cusId, $orderId);
}
}
<?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\Services;
use App\Rhawn\Repositories\Contracts\RhawnProductRepository;
use App\Rhawn\Repositories\Eloquent\BhuaBrandsRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\RhawnCustomerRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\RhawnRawRepositoryEloquent;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class BhuaProductService
{
public function __construct()
{
$this->brandsRepository = app(BhuaBrandsRepositoryEloquent::class);
}
/**
* 获取品牌列表
* @param array $where
* @param int $offset
* @param int $limit
* @return null
*/
public function getBrandsList($where = [],$offset = 0, $limit = 100)
{
$brandsList = $this->brandsRepository->getList($where,$limit,$offset);
if($brandsList){
return $brandsList;
}
return null;
}
}
......@@ -28,4 +28,20 @@ class RhawnCustomerService
return $customerInfo;
}
/**
* 检查客户信息是否存在
* @param $cusCode
* @return mixed
* @throws \Exception
*/
public function checkCustomerExist($cusCode)
{
//查询用户是否存在
$customer = $this->rhawnCustomerRepository->getRhawnCustomerThroughtCusCode($cusCode);
if(!$customer){
throw new \Exception('客户编号为:['.$cusCode.']的用户不存在!',500);
}
return $customer;
}
}
<?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\Services\Api;
use App\Repositories\Transformers\Rhawn\OrderDetailTransformer;
use App\Rhawn\Services\BhuaCustomerService;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class BhuaOrdersService
{
public function __construct(\App\Rhawn\Services\BhuaOrdersService $bhuaOrdersService)
{
$this->bhuaOrdersService = $bhuaOrdersService;
$this->bhuaCustomerService = app(BhuaCustomerService::class);
}
/**
* 新增订单
* @param $requestParams
*/
public function createNewCustomerOrders($requestParams)
{
try{
$customer = $this->bhuaCustomerService->checkCustomerExist($requestParams['customer_code']);
if(!isset($requestParams['so_ca_county'])){
$requestParams['so_ca_county'] = '';
}
$orderItems = $this->bhuaOrdersService->getCustomerOrderItems($customer['cus_no'],$requestParams['items']);
if(!$orderItems){
throw new \Exception('货号无法匹配',500);
}
$express = $this->bhuaOrdersService->getExpress(
$orderItems['weight'],$requestParams['so_ca_province'],$orderItems['total'],$customer['cus_free_express'],$customer['cus_level']
);
$order = $this->bhuaOrdersService->bhuaSorderRepository->getSorderFromOrderCusPo($requestParams['so_cus_po']);
if($order){
throw new \Exception('不能重复创建新订单!',500);
}
$data = [];
$data['sorders']['cus_id'] = $customer['cus_id'];
$data['sorders']['so_cus_po'] = $requestParams['so_cus_po'];
$data['sorders']['so_ca_name'] = $requestParams['so_ca_name'];
$data['sorders']['so_ca_mobile'] = $requestParams['so_ca_mobile'];
$data['sorders']['so_ca_phone'] = !isset($requestParams['so_ca_phone']) ? '' : $requestParams['so_ca_phone'];
$data['sorders']['so_ca_province'] = $requestParams['so_ca_province'];
$data['sorders']['so_ca_city'] = $requestParams['so_ca_city'];
$data['sorders']['so_ca_county'] = $requestParams['so_ca_county'];
$data['sorders']['so_ca_street'] = $requestParams['so_ca_street'];
//得到收票地址
$cusiaddrs_arr = $this->bhuaCustomerService->bhuaCustomerRepository->getCustomerAddressByCusCode($customer['cus_no']);
$cusinvoice_arr = $this->bhuaCustomerService->bhuaCustomerRepository->getCustomerInvoiceByCusCode($customer['cus_no']);
if(!$cusiaddrs_arr){
throw new \Exception('请至会员中心设置收票地址',500);
}
if(!$cusinvoice_arr){
throw new \Exception('请至会员中心设置发票信息',500);
}
$cusiaddrs_arr = current($cusiaddrs_arr);
$cusinvoice_arr = current($cusinvoice_arr);
$data['sorders']['so_cia_name'] = $cusiaddrs_arr['cia_name'];
$data['sorders']['so_cia_mobile'] = $cusiaddrs_arr['cia_mobile'];
$data['sorders']['so_cia_phone'] = $cusiaddrs_arr['cia_phone'];
$data['sorders']['so_cia_province'] = $cusiaddrs_arr['cia_province'];
$data['sorders']['so_cia_city'] = $cusiaddrs_arr['cia_city'];
$data['sorders']['so_cia_county'] = $cusiaddrs_arr['cia_county'];
$data['sorders']['so_cia_street'] = $cusiaddrs_arr['cia_street'];
$data['sorders']['so_cia_name'] = $cusiaddrs_arr['cia_name'];
$data['sorders']['so_ci_type'] = $cusinvoice_arr['ci_type'];
$data['sorders']['so_ci_title'] = $cusinvoice_arr['ci_title'];
$data['sorders']['so_ci_vatno'] = $cusinvoice_arr['ci_vatno'];
$data['sorders']['so_ci_bank'] = $cusinvoice_arr['ci_bank'];
$data['sorders']['so_ci_bknum'] = $cusinvoice_arr['ci_bknum'];
$data['sorders']['so_ci_addr'] = $cusinvoice_arr['ci_addr'];
$data['sorders']['so_ci_phone'] = $cusinvoice_arr['ci_phone'];
if(!isset($requestParams['so_note'])){
$requestParams['so_note'] = '';
}
$data['sorders']['so_note'] = $requestParams['so_note'];
$data['sorders']['so_send_note'] = $customer['cus_send_note'];
$data['sorders']['so_if_wx'] = 0;
$data['sorders']['so_if_api'] = 1;
$data['sorders']['so_ci_method'] = 1;
$data['sorders']['so_total'] = $orderItems['total'] + $express;
$data['express'] = $express;
$data['v_id'] = '';
$data['soitems'] = [];
foreach($orderItems['rows'] as $k => $v){
$soitem = [];
$soitem['p_id'] = $v['product_info']['p_id'];
$soitem['si_price'] = $v['product_info']['p_price'];
$soitem['si_discount'] = $v['product_info']['p_discount'];
$soitem['si_num'] = $v['num'];
$soitem['si_amount'] = $v['product_info']['p_discount'] * $v['num'];
$soitem['si_p_tod'] = $v['product_info']['p_tod'];
$soitem['si_vamount'] = 0;
if(isset($v['si_cus_note'])){
$soitem['si_cus_note'] = $v['si_cus_note'];
}
if(isset($v['si_molbase_pog'])){
$soitem['si_molbase_pog'] = $v['si_molbase_pog'];
}
array_push($data['soitems'],$soitem);
}
$orderId = $this->bhuaOrdersService->createOrders($data);
if($orderId){
$orderDetail = $this->bhuaOrdersService->getCustomerOrderItemsByOrderId($customer['cus_id'],$orderId);
$orderDetail = app(OrderDetailTransformer::class)->transform([$orderDetail]);
return current($orderDetail);
}
return null;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':createNewCustomerOrders','error');
throw $exception;
}
}
}
<?php
namespace App\Services\Api;
use App\Repositories\Transformers\Rhawn\Bhua\BrandsTransformer;
use App\Rhawn\Services\BhuaCustomerService;
use App\Rhawn\Services\BhuaProductService;
use App\Rhawn\Services\RhawnCustomerService;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class BhuaProductsService
{
public function __construct()
{
$this->bhuaProductService = app(BhuaProductService::class);
$this->bhuaCustomerService = app(BhuaCustomerService::class);
}
public function getAllBrands($requestParams)
{
$offset = !isset($requestParams['page_size']) || empty($requestParams['page_size']) ? 2000 : $requestParams['page_size'];
if($offset > 100){
$offset = 100;
}
$pageNo = !isset($requestParams['page_no']) || empty($requestParams['page_no']) ? 1 : $requestParams['page_no'];
$limit = $pageNo == 1 ? 0 : $pageNo * $offset;
try{
$where = [];
$brandsList = $this->bhuaProductService->getBrandsList($where,$offset,$limit);
$brandsTotal = 0;
if($brandsList){
$brandsList = app(BrandsTransformer::class)->transform($brandsList);
$brandsTotal = $this->bhuaProductService->brandsRepository->count($where);
}
$dataReturn = [];
$dataReturn['data'] = $brandsList;
$dataReturn['total_page'] = ceil($brandsTotal / $offset);
$dataReturn['page_no'] = $pageNo;
return $dataReturn;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getAllBrands','error');
throw $exception;
}
}
}
......@@ -25,6 +25,7 @@ class RhawnOrdersService
public function __construct(\App\Rhawn\Services\RhawnOrdersService $rhawnOrdersService)
{
$this->rhawnOrdersService = $rhawnOrdersService;
$this->rhawnCustomerService = app(RhawnCustomerService::class);
}
/**
......@@ -34,7 +35,7 @@ class RhawnOrdersService
public function getCustomerRhawnOrdersList($requestParams)
{
try{
$customer = $this->checkCustomerExist($requestParams['customer_code']);
$customer = $this->rhawnCustomerService->checkCustomerExist($requestParams['customer_code']);
$offset = !isset($requestParams['page_size']) || empty($requestParams['page_size']) ? 100 : $requestParams['page_size'];
if($offset > 100){
......@@ -68,7 +69,7 @@ class RhawnOrdersService
public function getCustomerOrderDetail($requestParams)
{
try{
$customer = $this->checkCustomerExist($requestParams['customer_code']);
$customer = $this->rhawnCustomerService->checkCustomerExist($requestParams['customer_code']);
$order = $this->rhawnOrdersService->getSordersByOrderNo($requestParams['order_number']);
if(!$order){
......@@ -91,7 +92,7 @@ class RhawnOrdersService
public function createNewCustomerOrders($requestParams)
{
try{
$customer = $this->checkCustomerExist($requestParams['customer_code']);
$customer = $this->rhawnCustomerService->checkCustomerExist($requestParams['customer_code']);
if(!isset($requestParams['so_ca_county'])){
$requestParams['so_ca_county'] = '';
......@@ -204,7 +205,7 @@ class RhawnOrdersService
public function cancelCustomerOrder($requestParams)
{
try{
$customer = $this->checkCustomerExist($requestParams['customer_code']);
$customer = $this->rhawnCustomerService->checkCustomerExist($requestParams['customer_code']);
$order = $this->rhawnOrdersService->getSordersByOrderNo($requestParams['order_number']);
if(!$order){
throw new \Exception('订单编号不存在',500);
......@@ -227,7 +228,7 @@ class RhawnOrdersService
public function getOrderDispatchByOrderNumber($requestParams)
{
try{
$customer = $this->checkCustomerExist($requestParams['customer_code']);
$customer = $this->rhawnCustomerService->checkCustomerExist($requestParams['customer_code']);
$order = $this->rhawnOrdersService->getSordersByOrderNo($requestParams['order_number']);
if(!$order){
throw new \Exception('订单编号不存在',500);
......@@ -246,21 +247,4 @@ class RhawnOrdersService
}
}
/**
* 检查客户信息是否存在
* @param $cusCode
* @return mixed
* @throws \Exception
*/
private function checkCustomerExist($cusCode)
{
//查询用户是否存在
$rhawnCustomerService = app(RhawnCustomerService::class);
$customer = $rhawnCustomerService->getRhawnCustomerThroughtCusCode($cusCode);
if(!$customer){
throw new \Exception('客户编号为:['.$cusCode.']的用户不存在!',500);
}
return $customer;
}
}
......@@ -12,6 +12,7 @@
namespace App\Services;
use App\Repositories\Contracts\PlatformCustomerRepository;
use App\Rhawn\Services\BhuaCustomerService;
use App\Rhawn\Services\RhawnCustomerService;
use App\Support\Facades\SimpleLogs;
use App\Support\Traits\Helpers;
......@@ -25,6 +26,7 @@ class CustomerService
{
$this->platformCustomerRepository = $platformCustomerRepository;
$this->rhawnCustomerService = app(RhawnCustomerService::class);
$this->bhuaCustomerService = app(BhuaCustomerService::class);
}
/**
......@@ -35,7 +37,14 @@ class CustomerService
public function createPlatformCustomer($requestParams)
{
try{
$customer = $this->rhawnCustomerService->getRhawnCustomerThroughtCusCode($requestParams['customer_code']);
switch($requestParams['customer_type']){
case 'rhawn' :
$customer = $this->rhawnCustomerService->getRhawnCustomerThroughtCusCode($requestParams['customer_code']);
break;
case 'bh' :
$customer = $this->bhuaCustomerService->getRhawnCustomerThroughtCusCode($requestParams['customer_code']);
break;
}
if(!$customer){
throw new \Exception('没有找到该客户',500);
}
......@@ -56,7 +65,11 @@ class CustomerService
$newCustomer['platform_params'] = '';
$newCustomer['status'] = 1;
return $this->platformCustomerRepository->create($newCustomer);
$this->platformCustomerRepository->create($newCustomer);
$platformCustomer = $this->platformCustomerRepository->findWhere(['cus_number' => $customer['cus_no']]);
return $platformCustomer;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':createCustomer','error');
throw $exception;
......
......@@ -9,3 +9,4 @@ $api = app('Dingo\Api\Routing\Router');
require __DIR__.'/../routes/api/zhenkunhang.php';
require __DIR__.'/../routes/api/rhawn.php';
require __DIR__.'/../routes/api/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->group(['namespace'=>'App\Http\Controllers\V1','middleware' => ['throttle:60,1']], function($api) {
$api->post('/openapi/customer/createPlatformCustomer', ['permission' => 'customer.createPlatformCustomer', 'uses'=>'CustomersController@createCustomer']);
});
});
......@@ -20,20 +20,30 @@ $api->version('v1', function($api) {
$api->group(['namespace'=>'App\Http\Controllers\V1\Rhawn','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
// 获取订单列表
$api->post('/openapi/orders/getRhawnOrders', ['permission' => 'orders.getCustomerOrders', 'uses'=>'OrdersController@getCustomerOrders']);
$api->post('/openapi/rhawn/orders/getRhawnOrders', ['permission' => 'orders.getCustomerOrders', 'uses'=>'OrdersController@getCustomerOrders']);
// 获取订单详情
$api->post('/openapi/orders/getRhawnOrderDetail', ['permission' => 'orders.getCustomerOrders', 'uses'=>'OrdersController@getCustomerOrderDetail']);
$api->post('/openapi/rhawn/orders/getRhawnOrderDetail', ['permission' => 'orders.getCustomerOrders', 'uses'=>'OrdersController@getCustomerOrderDetail']);
// 新建订单
$api->post('/openapi/orders/createRhawnOrders', ['permission' => 'orders.createRhawnOrders', 'uses'=>'OrdersController@createCustomerNewOrder']);
$api->post('/openapi/rhawn/orders/createRhawnOrders', ['permission' => 'orders.createRhawnOrders', 'uses'=>'OrdersController@createCustomerNewOrder']);
// 取消订单
//$api->post('/openapi/orders/cancelRhawnOrders', ['permission' => 'orders.cancelRhawnOrders', 'uses'=>'OrdersController@cancelCustomerOrder']);
$api->post('/openapi/orders/getOrdersDispatch', ['permission' => 'orders.getOrdersDispatch', 'uses'=>'OrdersController@getOrdersDispatch']);
//$api->post('/openapi/rhawn/orders/cancelRhawnOrders', ['permission' => 'orders.cancelRhawnOrders', 'uses'=>'OrdersController@cancelCustomerOrder']);
$api->post('/openapi/rhawn/orders/getOrdersDispatch', ['permission' => 'orders.getOrdersDispatch', 'uses'=>'OrdersController@getOrdersDispatch']);
});
$api->group(['namespace'=>'App\Http\Controllers\V1\Rhawn','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
$api->post('/openapi/products/getAllProducts', ['permission' => 'orders.getProductList', 'uses'=>'ProductsController@getAllProductsList']);
$api->post('/openapi/products/getProductDetail', ['permission' => 'orders.getProductDetail', 'uses'=>'ProductsController@getProductDetail']);
$api->post('/openapi/products/getProductByCas', ['permission' => 'orders.getProductByCas', 'uses'=>'ProductsController@getProductByCas']);
$api->post('/openapi/rhawn/products/getAllProducts', ['permission' => 'orders.getProductList', 'uses'=>'ProductsController@getAllProductsList']);
$api->post('/openapi/rhawn/products/getProductDetail', ['permission' => 'orders.getProductDetail', 'uses'=>'ProductsController@getProductDetail']);
$api->post('/openapi/rhawn/products/getProductByCas', ['permission' => 'orders.getProductByCas', 'uses'=>'ProductsController@getProductByCas']);
});
// 百化接口
$api->group(['namespace'=>'App\Http\Controllers\V1\Bhua','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
// 新建订单
$api->post('/openapi/Bhua/orders/createBhuaOrders', ['permission' => 'orders.createBhuaOrders', 'uses'=>'OrdersController@createCustomerNewOrder']);
});
$api->group(['namespace'=>'App\Http\Controllers\V1\Bhua','middleware' => ['throttle:60,1','apiAuth'], 'providers' => 'jwt'], function($api) {
$api->post('/openapi/Bhua/products/getAllBrands', ['permission' => 'orders.getAllBrands', 'uses'=>'ProductsController@getAllBrands']);
});
});
......
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