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;
|
||||
|
||||
/**
|
||||
* 订单列表控制器
|
||||
@ -155,25 +161,90 @@ class StoreOrderController extends BaseAdminController
|
||||
$id = $this->request->post('id');
|
||||
$system_store = $this->request->post('system_store');
|
||||
$xlsx = new OrderDetail();
|
||||
$order=StoreOrder::where('id',$id)->findOrEmpty();
|
||||
$time= strtotime('+1 day', $order['pay_time']);
|
||||
$order['pay_time']=date('Y-m-d H:i:s',$order['pay_time']);
|
||||
$order['delivery_time']=date('Y-m-d', $time);
|
||||
$order = StoreOrder::where('id', $id)->findOrEmpty();
|
||||
$time = strtotime('+1 day', $order['pay_time']);
|
||||
$order['pay_time'] = date('Y-m-d H:i:s', $order['pay_time']);
|
||||
$order['delivery_time'] = date('Y-m-d', $time);
|
||||
$data = StoreOrderCartInfo::where('oid', $id)->select();
|
||||
foreach ($data as $key => &$value) {
|
||||
$find=StoreProduct::where('id',$value->product_id)->find();
|
||||
$value->store_name=$find['store_name']??'';
|
||||
$value->store_info=$find['store_info']??'';
|
||||
$value->total_price=bcmul($value['price'],$value['cart_num'],2);
|
||||
if(!empty($find['unit'])){
|
||||
$value->unit_name=StoreProductUnit::where('id',$find['unit'])->value('name');
|
||||
}else{
|
||||
$value->unit_name='';
|
||||
$find = StoreProduct::where('id', $value->product_id)->find();
|
||||
$value->store_name = $find['store_name'] ?? '';
|
||||
$value->store_info = $find['store_info'] ?? '';
|
||||
$value->total_price = bcmul($value['price'], $value['cart_num'], 2);
|
||||
if (!empty($find['unit'])) {
|
||||
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
} else {
|
||||
$value->unit_name = '';
|
||||
}
|
||||
}
|
||||
$order['total_price']=$order['pay_price'];
|
||||
$file_path = $xlsx->export($data,$system_store,$order);
|
||||
$order['total_price'] = $order['pay_price'];
|
||||
$file_path = $xlsx->export($data, $system_store, $order);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -63,13 +63,13 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
if ($this->request->get('start_time') == '') {
|
||||
$this->searchWhere[] = ['create_time', 'between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
|
||||
}
|
||||
$this->searchWhere[]=['is_pay','=',1];
|
||||
$this->searchWhere[]=['status','>=',0];
|
||||
$this->searchWhere[] = ['is_pay', '=', 1];
|
||||
$this->searchWhere[] = ['status', '>=', 0];
|
||||
$query = StoreOrderCartInfo::where($this->searchWhere);
|
||||
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) {
|
||||
@ -78,16 +78,16 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
$item['image'] = $find['image']; //商品图片
|
||||
$item['store_name'] = $find['store_name']; //商品名称
|
||||
$item['store_info'] = $find['store_info']; //商品规格
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??'';
|
||||
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name')??'';
|
||||
$item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name')??'';
|
||||
}else{
|
||||
$item['image']='';//商品图片
|
||||
$item['store_name']='';//商品名称
|
||||
$item['store_info']='';//商品规格-(数据库叫商品简介)
|
||||
$item['unit_name']='';//
|
||||
$item['cate_name']='';//
|
||||
$item['system_store']='';//
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name') ?? '';
|
||||
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name') ?? '';
|
||||
$item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name') ?? '';
|
||||
} else {
|
||||
$item['image'] = ''; //商品图片
|
||||
$item['store_name'] = ''; //商品名称
|
||||
$item['store_info'] = ''; //商品规格-(数据库叫商品简介)
|
||||
$item['unit_name'] = ''; //
|
||||
$item['cate_name'] = ''; //
|
||||
$item['system_store'] = ''; //
|
||||
}
|
||||
return $item; //返回处理后的数据。
|
||||
})
|
||||
@ -130,16 +130,31 @@ class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSear
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$data = [
|
||||
'system_store' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'cate_name' => '分类',
|
||||
'cart_num' => '数量',
|
||||
'price' => '单价',
|
||||
'total_price' => '总价',
|
||||
];
|
||||
if ($this->request->get('is_group') == 1) {
|
||||
$data = [
|
||||
'system_store' => '门店',
|
||||
'store_name' => '商品名称',
|
||||
'store_info' => '规格',
|
||||
'unit_name' => '单位',
|
||||
'cate_name' => '分类',
|
||||
'cart_num' => '数量',
|
||||
'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();
|
||||
|
||||
@ -56,8 +74,8 @@ class WarehouseLogic extends BaseLogic
|
||||
$topData[] = [
|
||||
'title' => '总商品库存',
|
||||
'desc' => '平台统计商品总库存、含门店仓库',
|
||||
'total_money' => bcadd($warehouseProductStorege['nums'],$storeBranchProduct['stock'],2),
|
||||
'cash_title' => bcadd($warehouseProductStorege['total_price'],$storeBranchProduct['total_price'],2),
|
||||
'total_money' => bcadd($warehouseProductStorege['nums'], $storeBranchProduct['stock'], 2),
|
||||
'cash_title' => bcadd($warehouseProductStorege['total_price'], $storeBranchProduct['total_price'], 2),
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
@ -193,14 +211,14 @@ class WarehouseLogic extends BaseLogic
|
||||
$list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray();
|
||||
$count = StoreProduct::where('stock', '<', 0)->count();
|
||||
} elseif ($parmas['type'] == 2) {
|
||||
$where[]=['stock','<',0];
|
||||
if(isset($parmas['store_id']) && $parmas['store_id'] > 0){
|
||||
$where[]=['store_id','=',$parmas['store_id']];
|
||||
$where[] = ['stock', '<', 0];
|
||||
if (isset($parmas['store_id']) && $parmas['store_id'] > 0) {
|
||||
$where[] = ['store_id', '=', $parmas['store_id']];
|
||||
}
|
||||
$store_arr=getenv('NO_STORE_STATISTICS');
|
||||
if($store_arr){
|
||||
$store_arr=explode(',',$store_arr);
|
||||
$where[]=['store_id','not in',$store_arr];
|
||||
$store_arr = getenv('NO_STORE_STATISTICS');
|
||||
if ($store_arr) {
|
||||
$store_arr = explode(',', $store_arr);
|
||||
$where[] = ['store_id', 'not in', $store_arr];
|
||||
}
|
||||
$list = StoreBranchProduct::where($where)->page($parmas['page_no'], 15)->select()
|
||||
->each(function ($item) {
|
||||
@ -220,61 +238,55 @@ class WarehouseLogic extends BaseLogic
|
||||
$count = WarehouseProductStorege::where('nums', '<', 0)->count();
|
||||
}
|
||||
return ['lists' => $list, 'count' => $count];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 负库存更新归0
|
||||
*/
|
||||
public static function updateNegativeZero($parmas)
|
||||
{
|
||||
if ($parmas['type'] == 1) {
|
||||
$res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]);
|
||||
$res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]);
|
||||
} elseif ($parmas['type'] == 2) {
|
||||
$res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]);
|
||||
$res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]);
|
||||
} elseif ($parmas['type'] == 3) {
|
||||
$res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]);
|
||||
$res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function stockProductPrice($parmas){
|
||||
$arr1=WarehouseProductStorege::where('nums','>',0)->select();
|
||||
foreach ($arr1 as $k=>$v){
|
||||
$find=StoreProduct::where('id',$v['product_id'])->find();
|
||||
if($find&& $find['price']>0){
|
||||
$total_price=bcmul($find['price'],$v['nums'],2);
|
||||
$price=$find['price'];
|
||||
}else{
|
||||
$total_price=0;
|
||||
$price=0;
|
||||
public static function stockProductPrice($parmas)
|
||||
{
|
||||
$arr1 = WarehouseProductStorege::where('nums', '>', 0)->select();
|
||||
foreach ($arr1 as $k => $v) {
|
||||
$find = StoreProduct::where('id', $v['product_id'])->find();
|
||||
if ($find && $find['price'] > 0) {
|
||||
$total_price = bcmul($find['price'], $v['nums'], 2);
|
||||
$price = $find['price'];
|
||||
} else {
|
||||
$total_price = 0;
|
||||
$price = 0;
|
||||
}
|
||||
WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]);
|
||||
|
||||
WarehouseProductStorege::where('id', $v['id'])->update(['price' => $price, 'total_price' => $total_price]);
|
||||
}
|
||||
|
||||
$arr2=StoreBranchProduct::where('stock','>',0)->select();
|
||||
foreach ($arr2 as $k=>$v){
|
||||
if($v['price']>0){
|
||||
$total_price=bcmul($v['price'],$v['stock'],2);
|
||||
}else{
|
||||
$total_price=0;
|
||||
$arr2 = StoreBranchProduct::where('stock', '>', 0)->select();
|
||||
foreach ($arr2 as $k => $v) {
|
||||
if ($v['price'] > 0) {
|
||||
$total_price = bcmul($v['price'], $v['stock'], 2);
|
||||
} else {
|
||||
$total_price = 0;
|
||||
}
|
||||
StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]);
|
||||
StoreBranchProduct::where('id', $v['id'])->update(['total_price' => $total_price]);
|
||||
}
|
||||
$arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->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();
|
||||
}
|
||||
$arr3 = StoreProduct::where('stock', '>=', 0)->select();
|
||||
foreach ($arr3 as $k => $v) {
|
||||
$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