Merge pull request 'dev' (#181) from dev into main
Reviewed-on: https://gitea.lihaink.cn/mkm/multi-store/pulls/181
This commit is contained in:
commit
f44698d8f2
@ -7,6 +7,8 @@ use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\store_order\StoreOrderLists;
|
||||
use app\admin\lists\store_order\StoreRefundOrderLists;
|
||||
use app\admin\logic\store_order\StoreOrderLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\admin\validate\store_order\StoreOrderValidate;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
@ -15,7 +17,11 @@ use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\service\xlsx\OrderDetail;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 订单列表控制器
|
||||
@ -176,4 +182,69 @@ class StoreOrderController extends BaseAdminController
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出库单
|
||||
*/
|
||||
public function createOutboundOrder()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$store_id = $this->request->post('store_id');
|
||||
$warehouse_id = $this->request->post('warehouse_id');
|
||||
$delivery_time = $this->request->post('delivery_time');
|
||||
$mark = $this->request->post('mark');
|
||||
$find = WarehouseOrder::where('oid',$id)->find();
|
||||
if($find){
|
||||
return $this->fail('该订单已创建出库单');
|
||||
}
|
||||
$product_arr=StoreOrderCartInfo::where('oid',$id)->field('oid,product_id id,price,total_price,cart_num stock')->select();
|
||||
if(!$product_arr){
|
||||
return $this->fail('无商品');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$arr = [
|
||||
'oid' => $id,
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => $store_id,
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
'admin_id' => $this->adminId,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
WarehouseProductLogic::add($data);
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
if ($this->request->get('is_group') == 1) {
|
||||
$query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']);
|
||||
} else {
|
||||
$query->field('store_id,product_id,price,total_price,cart_num');
|
||||
$query->field('store_id,product_id,price,total_price,cart_num,create_time');
|
||||
}
|
||||
return $query->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->each(function ($item) {
|
||||
@ -130,6 +130,7 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
if ($this->request->get('is_group') == 1) {
|
||||
$data = [
|
||||
'system_store' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
@ -140,6 +141,20 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'system_store' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'cate_name' => '分类',
|
||||
'cart_num' => '数量',
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
'create_time' => '时间',
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace app\admin\logic\statistic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
@ -48,6 +49,23 @@ class WarehouseLogic extends BaseLogic
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$pay_price=StoreOrder::where('paid',1)->where('refund_status',0)->sum('pay_price');
|
||||
// $refund_price=StoreOrder::where('paid',1)->sum('refund_price');
|
||||
$topData[] = [
|
||||
'title' => '交易金额',
|
||||
'desc' => '平台发生交易的金额',
|
||||
'total_money' =>$pay_price,
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$number=StoreFinanceFlow::where('financial_type',3)->where('financial_pm',1)->sum('number');
|
||||
$topData[] = [
|
||||
'title' => '获得利润',
|
||||
'desc' => '平台订单产生的手续费',
|
||||
'total_money' =>$number,
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
// $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('nums', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
|
||||
@ -236,7 +254,8 @@ class WarehouseLogic extends BaseLogic
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function stockProductPrice($parmas){
|
||||
public static function stockProductPrice($parmas)
|
||||
{
|
||||
$arr1 = WarehouseProductStorege::where('nums', '>', 0)->select();
|
||||
foreach ($arr1 as $k => $v) {
|
||||
$find = StoreProduct::where('id', $v['product_id'])->find();
|
||||
@ -248,7 +267,6 @@ class WarehouseLogic extends BaseLogic
|
||||
$price = 0;
|
||||
}
|
||||
WarehouseProductStorege::where('id', $v['id'])->update(['price' => $price, 'total_price' => $total_price]);
|
||||
|
||||
}
|
||||
|
||||
$arr2 = StoreBranchProduct::where('stock', '>', 0)->select();
|
||||
@ -260,21 +278,15 @@ class WarehouseLogic extends BaseLogic
|
||||
}
|
||||
StoreBranchProduct::where('id', $v['id'])->update(['total_price' => $total_price]);
|
||||
}
|
||||
$arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->select();
|
||||
$arr3 = StoreProduct::where('stock', '>=', 0)->select();
|
||||
foreach ($arr3 as $k => $v) {
|
||||
StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]);
|
||||
}
|
||||
$arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->group('product_id')->order('stock desc')->select();
|
||||
foreach ($arr4 as $k=>$v){
|
||||
$find=StoreProduct::where('id',$v['product_id'])->find();
|
||||
if($find){
|
||||
$stock=bcadd($find['stock'],$v['stock'],2);
|
||||
$find->total_price=bcmul($find['purchase'],$v['stock'],2);
|
||||
$find->stock=$stock;
|
||||
$find->save();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
$stock = StoreBranchProduct::where('product_id', $v['id'])->where('stock', '>', 0)->sum('stock');
|
||||
$nums = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $v['id'])->sum('nums');
|
||||
$stock2 = bcadd($stock, $nums, 2);
|
||||
bcmul($v['purchase'], $stock2, 2);
|
||||
StoreProduct::where('id', $v['id'])->update(['stock' => $stock2, 'total_price' => $v]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user