Commit bed115f0 authored by hj's avatar hj

更新提交

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