处理代发订单跨店铺的错误
This commit is contained in:
parent
90bbc61ed7
commit
d89f0983e7
@ -4,66 +4,96 @@ namespace app\controller\api\store\order;
|
|||||||
|
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use crmeb\basic\BaseController;
|
use crmeb\basic\BaseController;
|
||||||
use think\facade\Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单处理
|
* 订单处理
|
||||||
*/
|
*/
|
||||||
class StoreProcessing extends BaseController
|
class StoreProcessing extends BaseController
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动向市级供应链创建订单
|
* 自动向市级供应链创建订单
|
||||||
|
* @param $order
|
||||||
|
* @return void
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function AutomaticallyCreateOrders($order)
|
public function AutomaticallyCreateOrders($order)
|
||||||
{
|
{
|
||||||
|
if (!in_array($order['source'], [103, 105])) {
|
||||||
|
return;
|
||||||
$merchant_two = Db::name('merchant')->where('mer_id', $order['mer_id'])->find();
|
}
|
||||||
|
$orderUser = Db::name('merchant')->where('mer_id', $order['mer_id'])->find();
|
||||||
$store_group_order = Db::name('store_group_order')->where('group_order_id', $order['group_order_id'])->find();
|
$store_group_order = Db::name('store_group_order')->where('group_order_id', $order['group_order_id'])->find();
|
||||||
$store_group_order_other = Db::name('store_group_order_other')->where('group_order_sn', $store_group_order['group_order_sn'])->find();
|
$store_group_order_other = Db::name('store_group_order_other')->where('group_order_sn', $store_group_order['group_order_sn'])->find();
|
||||||
if (!$store_group_order_other) {
|
if (!$store_group_order_other) {
|
||||||
unset($store_group_order['group_order_id']);
|
unset($store_group_order['group_order_id']);
|
||||||
$group_order_id = Db::name('store_group_order_other')->strict(false)->insertGetId($store_group_order);
|
$group_order_id = Db::name('store_group_order_other')->strict(false)->insertGetId($store_group_order);
|
||||||
}else{
|
} else {
|
||||||
$group_order_id=$store_group_order_other['group_order_id'];
|
$group_order_id = $store_group_order_other['group_order_id'];
|
||||||
}
|
}
|
||||||
$select = Db::name('store_order_product')->where('order_id', $order['order_id'])->select();
|
$orderProducts = Db::name('store_order_product')->where('order_id', $order['order_id'])->select()->toArray();
|
||||||
if ($order['source'] == 103 ||$order['source'] == 105 && $select) {
|
$merchants = [];
|
||||||
// $financialRecordRepository = app()->make(FinancialRecordRepository::class);
|
foreach ($orderProducts as $item) {
|
||||||
// $financeSn = $financialRecordRepository->getSn();
|
$cartInfo = json_decode($item['cart_info'], true);
|
||||||
$arr = $select->toArray();
|
$payPrice = bcmul($cartInfo['productAttr']['procure_price'], $item['product_num'], 2);
|
||||||
|
if (isset($merchants[$item['product_mer_id']])) {
|
||||||
|
$merchants[$item['product_mer_id']]['total_price'] = bcadd($merchants[$item['product_mer_id']]['procure_price'], $payPrice, 2);
|
||||||
|
$merchants[$item['product_mer_id']]['total_num'] = $merchants[$item['product_mer_id']]['product_num'] + $item['product_num'];
|
||||||
|
} else {
|
||||||
|
$merchants[$item['product_mer_id']]['total_price'] = $payPrice;
|
||||||
|
$merchants[$item['product_mer_id']]['total_num'] = $item['product_num'];
|
||||||
|
}
|
||||||
|
$merchants[$item['product_mer_id']]['product'][] = $item;
|
||||||
|
}
|
||||||
|
$productOther = [];
|
||||||
|
foreach ($merchants as $merId => $merchant) {
|
||||||
$order['group_order_id'] = $group_order_id;
|
$order['group_order_id'] = $group_order_id;
|
||||||
$order['source'] = 104;
|
$order['source'] = 104;
|
||||||
|
$order['mer_id'] = $merId;
|
||||||
$order['mer_id'] = $select[0]['product_mer_id'];
|
$order['uid'] = $orderUser['uid'];
|
||||||
$order['uid'] = $merchant_two['uid'];
|
$order['real_name'] = $orderUser['mer_name'] . '-' . $orderUser['real_name'];
|
||||||
$order['real_name'] = $merchant_two['mer_name'] . '-' . $merchant_two['real_name'];
|
$order['user_phone'] = $orderUser['mer_phone'];
|
||||||
$order['user_phone'] = $merchant_two['mer_phone'];
|
$order['user_address'] = $orderUser['mer_address'];
|
||||||
$order['user_address'] = $merchant_two['mer_address'];
|
|
||||||
$order['order_type'] = 0;
|
$order['order_type'] = 0;
|
||||||
$order['pay_price'] = $order['procure_price'];
|
$order['pay_price'] = $merchant['total_price'];
|
||||||
$order['total_price'] = $order['procure_price'];
|
$order['total_price'] = $merchant['total_price'];
|
||||||
|
$order['procure_price'] = $merchant['total_price'];
|
||||||
|
$order['total_num'] = $merchant['total_num'];
|
||||||
unset($order['order_id'], $order['orderProduct'], $order['user'], $order['supply_chain_rate'], $order['logistics_code'], $order['logistics_phone']);
|
unset($order['order_id'], $order['orderProduct'], $order['user'], $order['supply_chain_rate'], $order['logistics_code'], $order['logistics_phone']);
|
||||||
$order_id = Db::name('store_order_other')->strict(false)->insertGetId($order);
|
$orderId = Db::name('store_order_other')->strict(false)->insertGetId($order);
|
||||||
|
$productOther = array_merge($productOther, $this->setOrderOtherProduct($merchant, $orderUser, $orderId));
|
||||||
|
}
|
||||||
|
Db::name('store_order_product_other')->strict(false)->insertAll($productOther);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($arr as $key => $value) {
|
/**
|
||||||
$arr[$key]['order_id'] = $order_id;
|
* 设置订单商品
|
||||||
$arr[$key]['source'] = 104;
|
* @param $merchant
|
||||||
$cartInfo = json_decode($value['cart_info'], true);
|
* @param $orderUser
|
||||||
$arr[$key]['product_price'] = bcmul($cartInfo['productAttr']['procure_price'], $value['product_num'], 2);
|
* @param $orderId
|
||||||
$arr[$key]['total_price'] = $arr[$key]['product_price'];
|
* @return array
|
||||||
$arr[$key]['pay_price'] = $arr[$key]['product_price'];
|
*/
|
||||||
$arr[$key]['product_id'] = $value['product_source_id'];
|
public function setOrderOtherProduct($merchant, $orderUser, $orderId)
|
||||||
$arr[$key]['uid'] = $merchant_two['uid'];
|
{
|
||||||
$arr[$key]['product_source_id'] = 0;
|
$productOther = [];
|
||||||
$arr[$key]['product_mer_id'] = 0;
|
foreach ($merchant['product'] as $product) {
|
||||||
unset($arr[$key]['order_product_id']);
|
$cartInfo = json_decode($product['cart_info'], true);
|
||||||
Db::name('store_product')->where('product_id',$value['product_source_id'])->dec('stock');
|
$product['order_id'] = $orderId;
|
||||||
}
|
$product['source'] = 104;
|
||||||
// $financialRecordRepository->insertAll($finance);
|
$product['product_price'] = bcmul($cartInfo['productAttr']['procure_price'], $product['product_num'], 2);
|
||||||
Db::name('store_order_product_other')->strict(false)->insertAll($arr);
|
$product['total_price'] = $product['product_price'];
|
||||||
return $order_id;
|
$product['pay_price'] = $product['product_price'];
|
||||||
|
$product['product_id'] = $product['product_source_id'];
|
||||||
|
$product['uid'] = $orderUser['uid'];
|
||||||
|
$product['product_source_id'] = 0;
|
||||||
|
$product['product_mer_id'] = 0;
|
||||||
|
unset($product['order_product_id']);
|
||||||
|
$productOther[] = $product;
|
||||||
|
Db::name('store_product')->where('product_id', $product['product_source_id'])->dec('stock');
|
||||||
}
|
}
|
||||||
|
return $productOther;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user