feat(purchase_order): 修改采购订单逻辑,优化查询和合并订单流程
This commit is contained in:
parent
c462958325
commit
d5a716c2bd
@ -20,13 +20,6 @@ class PurchaseOrderController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
return $this->dataLists(new PurchaseOrderInfoLists());
|
return $this->dataLists(new PurchaseOrderInfoLists());
|
||||||
}
|
}
|
||||||
public function order_lists()
|
|
||||||
{
|
|
||||||
$id = $this->request->get('id');
|
|
||||||
$order_arr = PurchaseOrder::where('id', $id)->value('order_arr');
|
|
||||||
$this->request->__set('order_arr', $order_arr);
|
|
||||||
return $this->dataLists(new StoreOrderLists);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 合并今日商户订单
|
* 合并今日商户订单
|
||||||
*/
|
*/
|
||||||
|
@ -50,9 +50,6 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
if($this->request->get('is_delivery')>=1){
|
if($this->request->get('is_delivery')>=1){
|
||||||
$this->searchWhere[]=['delivery_uid','>',0];
|
$this->searchWhere[]=['delivery_uid','>',0];
|
||||||
}
|
}
|
||||||
if($this->request->__get('order_arr')){
|
|
||||||
$this->searchWhere[]=['id','in',$this->request->__get('order_arr')];
|
|
||||||
}
|
|
||||||
return StoreOrder::with(['staff','store'])->where($this->searchWhere)
|
return StoreOrder::with(['staff','store'])->where($this->searchWhere)
|
||||||
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
->when(!empty($this->request->adminInfo['store_id']), function ($query) {
|
||||||
$query->where('store_id', $this->request->adminInfo['store_id']);
|
$query->where('store_id', $this->request->adminInfo['store_id']);
|
||||||
|
@ -26,30 +26,93 @@ class PurchaseOrderLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
$oid_arr = [];
|
$oid_arr = [];
|
||||||
$store_arr = [];
|
$store_arr = [];
|
||||||
|
$purchaseOrderInfo = new PurchaseOrderInfo();
|
||||||
|
|
||||||
foreach ($params as $k => $v) {
|
foreach ($params as $k => $v) {
|
||||||
$oid_arr[] = $v['oid'];
|
$oid_arr[] = $v['oid'];
|
||||||
$store_arr[] = $v['store_id'];
|
$store_arr[] = $v['store_id'];
|
||||||
}
|
}
|
||||||
$store_arr = array_unique($store_arr);
|
$store_arr = array_unique($store_arr);
|
||||||
Db::startTrans();
|
|
||||||
try {
|
// Db::startTrans();
|
||||||
$price = StoreOrder::whereIn('id', $oid_arr)->field('SUM(pay_price) as pay_price,SUM(total_price) as total_price')->find();
|
// try {
|
||||||
|
$price = StoreOrder::whereIn('id', $oid_arr)->whereIn('store_id', $store_arr)->group('store_id')->field('store_id,SUM(pay_price) as pay_price,SUM(total_price) as total_price')->select()->toArray();
|
||||||
|
$purchase_arr = [];
|
||||||
|
$order_arr = [];
|
||||||
|
$total_price = 0;
|
||||||
|
$pay_price = 0;
|
||||||
|
foreach ($price as $k => $v) {
|
||||||
|
foreach($params as $key => $value){
|
||||||
|
if($value['store_id']==$v['store_id']){
|
||||||
|
$order_arr[] = $value['oid'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$total_price += $v['total_price'];
|
||||||
|
$pay_price += $v['pay_price'];
|
||||||
|
$data = [
|
||||||
|
'store_id' => $v['store_id'],
|
||||||
|
'order_arr' => json_encode($order_arr),
|
||||||
|
'order_id' => getNewOrderId('CG'),
|
||||||
|
'total' => $v['total_price'],
|
||||||
|
'actual' => $v['pay_price'],
|
||||||
|
'money' => $v['pay_price'],
|
||||||
|
'paid' => 1,
|
||||||
|
'is_mer' => 1,
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time(),
|
||||||
|
];
|
||||||
|
//创建门店合计订单
|
||||||
|
$res = PurchaseOrder::create($data);
|
||||||
|
$purchase_arr[] = ['id'=>$res['id'],'store_id'=>$v['store_id']];
|
||||||
|
$purchase_id[] =$res['id'];
|
||||||
|
}
|
||||||
|
$info = StoreOrderCartInfo::where('oid', 'in', $order_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select()->toArray();
|
||||||
|
//创建门店合计商品
|
||||||
|
foreach($purchase_arr as $k=>$v){
|
||||||
|
foreach ($info as $item) {
|
||||||
|
if($v['store_id']==$item['store_id']){
|
||||||
|
$arr['oid'] = $v['id'];
|
||||||
|
$arr['store_id'] = $item['store_id'];
|
||||||
|
$arr['product_id'] = $item['product_id'];
|
||||||
|
$arr['price'] = $item['price'];
|
||||||
|
$arr['total_price'] = $item['total_price'];
|
||||||
|
$arr['cart_num'] = $item['cart_num'];
|
||||||
|
$arr['status'] = 1;
|
||||||
|
$purchase_order_info[] = $arr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$purchaseOrderInfo->saveAll($purchase_order_info);
|
||||||
|
//---------------生成平台订单-----------------
|
||||||
$data = [
|
$data = [
|
||||||
'store_id' => 0,
|
'store_id' => 0,
|
||||||
'store_arr' => json_encode($store_arr),
|
'store_arr' => json_encode($store_arr),
|
||||||
'order_arr' => json_encode($oid_arr),
|
'order_arr' => json_encode($purchase_id),
|
||||||
'order_id' => getNewOrderId('PT'),
|
'order_id' => getNewOrderId('PT'),
|
||||||
'total' => $price['total_price'],
|
'total' => $total_price,
|
||||||
'actual' => $price['pay_price'],
|
'actual' => $pay_price,
|
||||||
'money' => $price['pay_price'],
|
'money' => $pay_price,
|
||||||
'paid' => 1,
|
'paid' => 1,
|
||||||
'is_mer' => 2,
|
'is_mer' => 2,
|
||||||
'create_time' => time(),
|
'create_time' => time(),
|
||||||
'update_time' => time(),
|
'update_time' => time(),
|
||||||
];
|
];
|
||||||
$res = PurchaseOrder::create($data);
|
$res = PurchaseOrder::create($data);
|
||||||
$info = StoreOrderCartInfo::where('oid', 'in', $oid_arr)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('product_id')->select();
|
$info = PurchaseOrderInfo::where('oid', 'in', $purchase_id)->field('store_id, product_id,price,SUM(total_price) as total_price, SUM(cart_num) as cart_num')->group('store_id, product_id')->select();
|
||||||
$purchase_order_info = [];
|
$purchase_order_info_two=[];
|
||||||
|
foreach ($info as $item) {
|
||||||
|
$arr['oid'] = $res['id'];
|
||||||
|
$arr['store_id'] = $item['store_id'];
|
||||||
|
$arr['product_id'] = $item['product_id'];
|
||||||
|
$arr['price'] = $item['price'];
|
||||||
|
$arr['total_price'] = $item['total_price'];
|
||||||
|
$arr['cart_num'] = $item['cart_num'];
|
||||||
|
$arr['status'] = 1;
|
||||||
|
$purchase_order_info_two[] = $arr;
|
||||||
|
}
|
||||||
|
$purchaseOrderInfo->saveAll($purchase_order_info_two);
|
||||||
|
$productOffer = [];
|
||||||
foreach ($info as $item) {
|
foreach ($info as $item) {
|
||||||
$arr['order_id'] = $res['id'];
|
$arr['order_id'] = $res['id'];
|
||||||
$arr['product_id'] = $item['product_id'];
|
$arr['product_id'] = $item['product_id'];
|
||||||
@ -57,18 +120,18 @@ class PurchaseOrderLogic extends BaseLogic
|
|||||||
$arr['total_price'] = $item['total_price'];
|
$arr['total_price'] = $item['total_price'];
|
||||||
$arr['need_num'] = $item['cart_num'];
|
$arr['need_num'] = $item['cart_num'];
|
||||||
$arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
|
$arr['unit'] = StoreProduct::where('id', $item['product_id'])->value('unit');
|
||||||
$purchase_order_info[] = $arr;
|
$productOffer[] = $arr;
|
||||||
}
|
|
||||||
$purchaseOrderInfo = new PurchaseProductOffer();
|
|
||||||
$purchaseOrderInfo->saveAll($purchase_order_info);
|
|
||||||
StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]);
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Db::rollback();
|
|
||||||
self::setError($e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
$purchaseProductOffer = new PurchaseProductOffer();
|
||||||
|
$purchaseProductOffer->saveAll($productOffer);
|
||||||
|
// StoreOrder::whereIn('id', $oid_arr)->update(['is_merge' => 1]);
|
||||||
|
// Db::commit();
|
||||||
|
// return true;
|
||||||
|
// } catch (\Throwable $e) {
|
||||||
|
// Db::rollback();
|
||||||
|
// self::setError($e->getMessage());
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user