Commit bed115f0 authored by hj's avatar hj

更新提交

parent 702b1cb1
...@@ -51,7 +51,7 @@ class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements Chems ...@@ -51,7 +51,7 @@ class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements Chems
*/ */
public function getCustomerDiscountByCusCode($cusCode) public function getCustomerDiscountByCusCode($cusCode)
{ {
$customerDiscount = RhawnCustomer::query() $customerDiscount = ChemsiteCustomer::query()
->join('cusdiscount','cusdiscount.cus_id','customers.cus_id') ->join('cusdiscount','cusdiscount.cus_id','customers.cus_id')
->where('customers.cus_no',$cusCode) ->where('customers.cus_no',$cusCode)
->get(); ->get();
...@@ -61,7 +61,6 @@ class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements Chems ...@@ -61,7 +61,6 @@ class ChemsiteCustomerRepositoryEloquent extends BaseRepository implements Chems
$customerDiscount = $customerDiscount->toArray(); $customerDiscount = $customerDiscount->toArray();
foreach($customerDiscount as $k=>$v){ foreach($customerDiscount as $k=>$v){
$cusdiscountArr[$v['b_id']]['cd_discount'] = $v['cd_discount']; $cusdiscountArr[$v['b_id']]['cd_discount'] = $v['cd_discount'];
$cusdiscountArr[$v['b_id']]['cd_pre_discount'] = $v['cd_pre_discount'];
} }
} }
return $cusdiscountArr; return $cusdiscountArr;
......
...@@ -40,7 +40,7 @@ class ChemsiteProductRepositoryEloquent extends BaseRepository implements Chemsi ...@@ -40,7 +40,7 @@ class ChemsiteProductRepositoryEloquent extends BaseRepository implements Chemsi
return null; return null;
} }
public function getProductByPcodeAndBid($pCode,$bId) public function getProductByPcodeAndBid($pCode,$bId, $comId)
{ {
$productsModel = ChemsiteProducts::query(); $productsModel = ChemsiteProducts::query();
if(!is_array($pCode)){ if(!is_array($pCode)){
...@@ -49,6 +49,7 @@ class ChemsiteProductRepositoryEloquent extends BaseRepository implements Chemsi ...@@ -49,6 +49,7 @@ class ChemsiteProductRepositoryEloquent extends BaseRepository implements Chemsi
$productsModel->whereIn('products.p_code',$pCode); $productsModel->whereIn('products.p_code',$pCode);
} }
$productsModel->where('products.b_id',$bId); $productsModel->where('products.b_id',$bId);
$productsModel->where('products.com_id',$comId);
$product = $productsModel->get(); $product = $productsModel->get();
if($product){ if($product){
return $product->toArray(); return $product->toArray();
......
...@@ -11,34 +11,35 @@ ...@@ -11,34 +11,35 @@
namespace App\Rhawn\Services\Chemsite; namespace App\Rhawn\Services\Chemsite;
use App\Rhawn\Repositories\Contracts\BhuaSordersRepository; use App\Rhawn\Repositories\Contracts\Chemsite\ChemsiteSordersRepository;
use App\Rhawn\Repositories\Eloquent\BhuaCustomerRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\BhuaProductRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\BhuaSoitemsRepositoryEloquent; use App\Rhawn\Repositories\Eloquent\BhuaSoitemsRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\Chemsite\ChemsiteCompanyRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\Chemsite\ChemsiteCustomerRepositoryEloquent;
use App\Rhawn\Repositories\Eloquent\Chemsite\ChemsiteProductRepositoryEloquent;
use App\Support\Facades\SimpleLogs; use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class ChemsiteOrdersService class ChemsiteOrdersService
{ {
public function __construct(BhuaSordersRepository $bhuaSorderRepository) public function __construct(ChemsiteSordersRepository $chemsiteSordersRepository)
{ {
$this->bhuaSorderRepository = $bhuaSorderRepository; $this->chemsiteSordersRepository = $chemsiteSordersRepository;
} }
public function getCustomerOrderItems($cusCode, $soItems) public function getCustomerOrderItems($comId, $cusCode, $soItems)
{ {
if(empty($soItems)){ if(empty($soItems)){
throw new \Exception('订单项为空',500); throw new \Exception('订单项为空',500);
} }
$customerReopository = app(BhuaCustomerRepositoryEloquent::class); $customerReopository = app(ChemsiteCustomerRepositoryEloquent::class);
$discount = $customerReopository->getCustomerDiscountByCusCode($cusCode); $discount = $customerReopository->getCustomerDiscountByCusCode($cusCode);
$total = 0; $total = 0;
$weight = 0; $weight = 0;
$productRepository = app(BhuaProductRepositoryEloquent::class); $productRepository = app(ChemsiteProductRepositoryEloquent::class);
foreach($soItems as $k => $v){ foreach($soItems as $k => $v){
$productInfo = $productRepository->getProductByPcodeAndBid($v['p_code'],$v['brand_id']); $productInfo = $productRepository->getProductByPcodeAndBid($v['p_code'],$v['brand_id'], $comId);
if(!$productInfo){ if(!$productInfo){
throw new \Exception($v['p_code'].'产品不存在!',500); throw new \Exception($v['p_code'].'产品不存在!',500);
} }
...@@ -56,7 +57,7 @@ class ChemsiteOrdersService ...@@ -56,7 +57,7 @@ class ChemsiteOrdersService
$soItems[$k]['amount'] = round(bcmul($productInfo['p_discount'],$v['num'],3),2); $soItems[$k]['amount'] = round(bcmul($productInfo['p_discount'],$v['num'],3),2);
$soItems[$k]['weight'] = round(bcmul($productInfo['p_weight'],$v['num'],3),3); $soItems[$k]['weight'] = round(bcmul($productInfo['p_weight'],$v['num'],3),3);
//得到品牌 //得到品牌
$brands = DB::connection($this->bhuaSorderRepository->getConnectionName()) $brands = DB::connection($this->chemsiteSordersRepository->getConnectionName())
->table('brands') ->table('brands')
->where('b_id',$productInfo['b_id']) ->where('b_id',$productInfo['b_id'])
->first(); ->first();
...@@ -83,14 +84,16 @@ class ChemsiteOrdersService ...@@ -83,14 +84,16 @@ class ChemsiteOrdersService
* @param $data * @param $data
* @return false * @return false
*/ */
public function createOrders($data) public function createOrders($data, $comId)
{ {
$connection = DB::connection($this->bhuaSorderRepository->getConnectionName()); $connection = DB::connection($this->chemsiteSordersRepository->getConnectionName());
try{ try{
$connection->beginTransaction(); $connection->beginTransaction();
$data['sorders']['so_no'] = ''; $data['sorders']['so_no'] = '';
$data['sorders']['so_ctime'] = time(); $data['sorders']['so_ctime'] = time();
$data['sorders']['com_id'] = $comId;
//$data['sorders']['so_creater'] = $data['sorders']['creater'];
//$data['sorders']['so_creater'] = $data['sorders']['creater']; //$data['sorders']['so_creater'] = $data['sorders']['creater'];
$orderId = $connection->table('sorders')->insertGetId($data['sorders']); $orderId = $connection->table('sorders')->insertGetId($data['sorders']);
...@@ -177,12 +180,12 @@ class ChemsiteOrdersService ...@@ -177,12 +180,12 @@ class ChemsiteOrdersService
public function getCustomerOrderItemsByOrderId($cusId, $orderId) public function getCustomerOrderItemsByOrderId($cusId, $orderId)
{ {
return $this->bhuaSorderRepository->getCustomerOrderItemsByOrderId($cusId, $orderId); return $this->chemsiteSordersRepository->getCustomerOrderItemsByOrderId($cusId, $orderId);
} }
public function getSordersByOrderNo($orderNo) public function getSordersByOrderNo($orderNo)
{ {
$order = $this->bhuaSorderRepository->getSorderFromOrderNo($orderNo); $order = $this->chemsiteSordersRepository->getSorderFromOrderNo($orderNo);
if($order){ if($order){
return $order->toArray(); return $order->toArray();
} }
...@@ -196,7 +199,7 @@ class ChemsiteOrdersService ...@@ -196,7 +199,7 @@ class ChemsiteOrdersService
public function getOrderDispatchDetail($orderNumber) public function getOrderDispatchDetail($orderNumber)
{ {
try{ try{
$dpdetail = $this->bhuaSorderRepository->getOrderDispatch($orderNumber); $dpdetail = $this->chemsiteSordersRepository->getOrderDispatch($orderNumber);
$soItemIds = []; $soItemIds = [];
if($dpdetail){ if($dpdetail){
foreach($dpdetail as $detail){ foreach($dpdetail as $detail){
......
...@@ -13,6 +13,7 @@ namespace App\Services\Api\Chemsite; ...@@ -13,6 +13,7 @@ namespace App\Services\Api\Chemsite;
use App\Repositories\Transformers\Rhawn\OrderDetailTransformer; use App\Repositories\Transformers\Rhawn\OrderDetailTransformer;
use App\Repositories\Transformers\Rhawn\OrdersDispatchTransformer; use App\Repositories\Transformers\Rhawn\OrdersDispatchTransformer;
use App\Rhawn\Repositories\Eloquent\Chemsite\ChemsiteCompanyRepositoryEloquent;
use App\Support\Facades\SimpleLogs; use App\Support\Facades\SimpleLogs;
class ChemsiteOrdersService class ChemsiteOrdersService
...@@ -29,25 +30,31 @@ class ChemsiteOrdersService ...@@ -29,25 +30,31 @@ class ChemsiteOrdersService
*/ */
public function createNewCustomerOrders($requestParams) public function createNewCustomerOrders($requestParams)
{ {
try{ try {
$customer = $this->chemsiteCustomerService->checkCustomerExist($requestParams['customer_code']); $customer = $this->chemsiteCustomerService->checkCustomerExist($requestParams['customer_code']);
if(!isset($requestParams['so_ca_county'])){ if (!isset($requestParams['so_ca_county'])) {
$requestParams['so_ca_county'] = ''; $requestParams['so_ca_county'] = '';
} }
$orderItems = $this->chemsiteOrdersService->getCustomerOrderItems($customer['cus_no'],$requestParams['items']); $companyInfo = app(ChemsiteCompanyRepositoryEloquent::class)->getCompanyThroughCusCode($requestParams['company_code']);
if(!$orderItems){ $companyInfo = $companyInfo->toArray();
throw new \Exception('货号无法匹配',500); if(!$companyInfo){
throw new \Exception('未找到相应供应商',500);
} }
$express = $this->bhuaOrdersService->getExpress( $orderItems = $this->chemsiteOrdersService->getCustomerOrderItems($companyInfo['com_id'], $customer['cus_no'], $requestParams['items']);
$orderItems['weight'],$requestParams['so_ca_province'],$orderItems['total'] if (!$orderItems) {
throw new \Exception('货号无法匹配', 500);
}
$express = $this->chemsiteOrdersService->getExpress(
$orderItems['weight'], $requestParams['so_ca_province'], $orderItems['total']
); );
$order = $this->bhuaOrdersService->bhuaSorderRepository->getSorderFromOrderCusPo($requestParams['so_cus_po']); $order = $this->chemsiteOrdersService->chemsiteSordersRepository->getSorderFromOrderCusPo($requestParams['so_cus_po']);
if($order){ if ($order) {
throw new \Exception('不能重复创建新订单!',500); throw new \Exception('不能重复创建新订单!', 500);
} }
$data = []; $data = [];
...@@ -57,60 +64,64 @@ class ChemsiteOrdersService ...@@ -57,60 +64,64 @@ class ChemsiteOrdersService
$data['sorders']['so_ca_mobile'] = $requestParams['so_ca_mobile']; $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_phone'] = !isset($requestParams['so_ca_phone']) ? '' : $requestParams['so_ca_phone'];
if(!isset($requestParams['so_ca_province']) || empty($requestParams['so_ca_province'])){ if (!isset($requestParams['so_ca_province']) || empty($requestParams['so_ca_province'])) {
throw new \Exception('省份必填'); throw new \Exception('省份必填');
}else{ } else {
$data['sorders']['so_ca_province'] = $requestParams['so_ca_province']; $data['sorders']['so_ca_province'] = $requestParams['so_ca_province'];
} }
if(!isset($requestParams['so_ca_city']) || empty($requestParams['so_ca_city'])){ if (!isset($requestParams['so_ca_city']) || empty($requestParams['so_ca_city'])) {
throw new \Exception('城市必填'); throw new \Exception('城市必填');
}else{ } else {
$data['sorders']['so_ca_city'] = $requestParams['so_ca_city']; $data['sorders']['so_ca_city'] = $requestParams['so_ca_city'];
} }
if(!isset($requestParams['so_ca_county']) || empty($requestParams['so_ca_county'])){ if (!isset($requestParams['so_ca_county']) || empty($requestParams['so_ca_county'])) {
throw new \Exception('区县必填'); throw new \Exception('区县必填');
}else{ } else {
$data['sorders']['so_ca_county'] = $requestParams['so_ca_county']; $data['sorders']['so_ca_county'] = $requestParams['so_ca_county'];
} }
if(!isset($requestParams['so_ca_street']) || empty($requestParams['so_ca_street'])){ if (!isset($requestParams['so_ca_street']) || empty($requestParams['so_ca_street'])) {
throw new \Exception('街道必填'); throw new \Exception('街道必填');
}else{ } else {
$data['sorders']['so_ca_street'] = $requestParams['so_ca_street']; $data['sorders']['so_ca_street'] = $requestParams['so_ca_street'];
} }
//得到收票地址 if ($requestParams['so_ci_method'] != 3) {
$cusiaddrs_arr = $this->bhuaCustomerService->customerRepository->getCustomerAddressByCusCode($customer['cus_no']);
$cusinvoice_arr = $this->bhuaCustomerService->customerRepository->getCustomerInvoiceByCusCode($customer['cus_no']);
if(!$cusiaddrs_arr){ //得到收票地址
throw new \Exception('请至会员中心设置收票地址',500); $cusiaddrs_arr = $this->chemsiteCustomerService->chemsiteCustomerRepository->getCustomerAddressByCusCode($customer['cus_no']);
} $cusinvoice_arr = $this->chemsiteCustomerService->chemsiteCustomerRepository->getCustomerInvoiceByCusCode($customer['cus_no']);
if(!$cusinvoice_arr){
throw new \Exception('请至会员中心设置发票信息',500);
}
$cusiaddrs_arr = current($cusiaddrs_arr); if (!$cusiaddrs_arr) {
$cusinvoice_arr = current($cusinvoice_arr); throw new \Exception('请至会员中心设置收票地址', 500);
}
$data['sorders']['so_cia_name'] = $cusiaddrs_arr['cia_name']; if (!$cusinvoice_arr) {
$data['sorders']['so_cia_mobile'] = $cusiaddrs_arr['cia_mobile']; throw new \Exception('请至会员中心设置发票信息', 500);
$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']; $cusiaddrs_arr = current($cusiaddrs_arr);
$data['sorders']['so_cia_county'] = $cusiaddrs_arr['cia_county']; $cusinvoice_arr = current($cusinvoice_arr);
$data['sorders']['so_cia_street'] = $cusiaddrs_arr['cia_street'];
$data['sorders']['so_cia_name'] = $cusiaddrs_arr['cia_name'];
$data['sorders']['so_cia_name'] = $cusiaddrs_arr['cia_name']; $data['sorders']['so_cia_mobile'] = $cusiaddrs_arr['cia_mobile'];
$data['sorders']['so_ci_type'] = $cusinvoice_arr['ci_type']; $data['sorders']['so_cia_phone'] = $cusiaddrs_arr['cia_phone'];
$data['sorders']['so_ci_title'] = $cusinvoice_arr['ci_title']; $data['sorders']['so_cia_province'] = $cusiaddrs_arr['cia_province'];
$data['sorders']['so_ci_vatno'] = $cusinvoice_arr['ci_vatno']; $data['sorders']['so_cia_city'] = $cusiaddrs_arr['cia_city'];
$data['sorders']['so_ci_bank'] = $cusinvoice_arr['ci_bank']; $data['sorders']['so_cia_county'] = $cusiaddrs_arr['cia_county'];
$data['sorders']['so_ci_bknum'] = $cusinvoice_arr['ci_bknum']; $data['sorders']['so_cia_street'] = $cusiaddrs_arr['cia_street'];
$data['sorders']['so_ci_addr'] = $cusinvoice_arr['ci_addr'];
$data['sorders']['so_ci_phone'] = $cusinvoice_arr['ci_phone']; $data['sorders']['so_cia_name'] = $cusiaddrs_arr['cia_name'];
$data['sorders']['so_standard'] = 0; $data['sorders']['so_ci_type'] = $cusinvoice_arr['ci_type'];
$data['sorders']['so_from'] = 4; $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'];
$data['sorders']['so_standard'] = 0;
$data['sorders']['so_from'] = 4;
}
$data['sorders']['so_creater'] = 0;//$customer['cus_id']; $data['sorders']['so_creater'] = 0;//$customer['cus_id'];
...@@ -137,9 +148,9 @@ class ChemsiteOrdersService ...@@ -137,9 +148,9 @@ class ChemsiteOrdersService
array_push($data['soitems'],$soitem); array_push($data['soitems'],$soitem);
} }
$orderId = $this->bhuaOrdersService->createOrders($data); $orderId = $this->chemsiteOrdersService->createOrders($data, $companyInfo['com_id']);
if($orderId){ if($orderId){
$orderDetail = $this->bhuaOrdersService->getCustomerOrderItemsByOrderId($customer['cus_id'],$orderId); $orderDetail = $this->chemsiteOrdersService->getCustomerOrderItemsByOrderId($customer['cus_id'],$orderId);
//处理运费 //处理运费
if($orderDetail){ if($orderDetail){
$orderDetail['so_freight_price'] = 0; $orderDetail['so_freight_price'] = 0;
......
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