新增订单转预定单功能并优化入库操作
- 在 BeforehandOrderController 中添加 orderTransferAdvanceOrder 方法,实现订单转预定单功能 - 在 BeforehandOrderLogic 中实现 orderTransferAdvanceOrder 逻辑,包括创建预定单和保存预定单商品信息 - 优化 SystemStoreStorageController 和 SystemStoreStorageLogic 的入库操作,简化代码并提高效率 - 在 API 和 Store 控制器中调用 SystemStoreStorageLogic 的 edit 方法完成入库操作
This commit is contained in:
parent
c328e9a809
commit
ae38c2e571
@ -64,6 +64,18 @@ class BeforehandOrderController extends BaseAdminController
|
|||||||
return $this->success('出库成功', [], 1, 1);
|
return $this->success('出库成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 订单转预定单
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function orderTransferAdvanceOrder(){
|
||||||
|
$params=$this->request->post();
|
||||||
|
$params['admin_id']=$this->adminId;
|
||||||
|
$params['mark']='订单转预定单';
|
||||||
|
$result = BeforehandOrderLogic::orderTransferAdvanceOrder($params);
|
||||||
|
return $this->success('转单成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 编辑预订单表
|
* @notes 编辑预订单表
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
|
@ -58,37 +58,12 @@ class SystemStoreStorageController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
{
|
{
|
||||||
// return $this->fail('暂不支持入库操作');
|
|
||||||
|
|
||||||
// $params = (new SystemStoreStorageValidate())->post()->goCheck('edit');
|
|
||||||
// $params['admin_id']=$this->adminId;
|
|
||||||
// $result = SystemStoreStorageLogic::edit($params);
|
|
||||||
// if (true === $result) {
|
|
||||||
// return $this->success('编辑成功', [], 1, 1);
|
|
||||||
// }
|
|
||||||
// return $this->fail(SystemStoreStorageLogic::getError());
|
|
||||||
$id = $this->request->post('id',0);
|
$id = $this->request->post('id',0);
|
||||||
if($id==0){
|
if($id==0){
|
||||||
return $this->fail('参数错误');
|
return $this->fail('参数错误');
|
||||||
}
|
}
|
||||||
$find=SystemStoreStorage::where(['id' => $id])->find();
|
SystemStoreStorageLogic::edit(['id'=>$id,'admin_id'=>$this->adminId]);
|
||||||
|
return $this->success('操作成功',[]);
|
||||||
if($find){
|
|
||||||
$find->save(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
|
||||||
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
|
||||||
if($branch_product){
|
|
||||||
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
|
|
||||||
}else{
|
|
||||||
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();
|
|
||||||
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], $this->adminId, $storeProduct);
|
|
||||||
$storeBranchProduct->stock = $find['nums'];
|
|
||||||
$storeBranchProduct->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $this->success('操作成功',[]);
|
|
||||||
}
|
|
||||||
return $this->fail('操作失败');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
|||||||
use app\common\model\beforehand_order\BeforehandOrder;
|
use app\common\model\beforehand_order\BeforehandOrder;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||||
|
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\StoreProduct;
|
||||||
use app\common\model\warehouse_order\WarehouseOrder;
|
use app\common\model\warehouse_order\WarehouseOrder;
|
||||||
use app\common\model\warehouse_product\WarehouseProduct;
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
@ -174,7 +176,58 @@ class BeforehandOrderLogic extends BaseLogic
|
|||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @notes 订单转预定单
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/09/30 11:26
|
||||||
|
*/
|
||||||
|
public static function orderTransferAdvanceOrder(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$datas = [];
|
||||||
|
|
||||||
|
$order=StoreOrder::where('id', $params['id'])->find();
|
||||||
|
$info=StoreOrderCartInfo::where('oid', $params['id'])->select();
|
||||||
|
$total_num = $order['total_num'];
|
||||||
|
$total_price = $order['total_price'];
|
||||||
|
$uid = $order['uid'];
|
||||||
|
foreach ($info as $k => $v) {
|
||||||
|
$datas[$k]['product_id'] = $v['product_id'];
|
||||||
|
$datas[$k]['uid'] = $uid;
|
||||||
|
$datas[$k]['cart_num'] = $v['cart_num'];
|
||||||
|
$datas[$k]['purchase'] = $v['purchase'];
|
||||||
|
$datas[$k]['price'] = $v['price'];
|
||||||
|
$datas[$k]['total_price'] = $v['total_price'];
|
||||||
|
$datas[$k]['create_time'] = time();
|
||||||
|
$datas[$k]['update_time'] = time();
|
||||||
|
$total_num += $v['nums'];
|
||||||
|
}
|
||||||
|
$order = BeforehandOrder::create([
|
||||||
|
'order_id' => getNewOrderId('YG'),
|
||||||
|
'admin_id' => $params['admin_id'] ?? 0,
|
||||||
|
'uid' => $uid,
|
||||||
|
'total_num' => $total_num,
|
||||||
|
'total_price' => $total_price,
|
||||||
|
'pay_price' => 0,
|
||||||
|
'pay_type' => 0,
|
||||||
|
'deduction_price' => 0,
|
||||||
|
'paid' => 0,
|
||||||
|
'mark' => $params['mark'] ?? ''
|
||||||
|
]);
|
||||||
|
foreach ($datas as $k => $v) {
|
||||||
|
$datas[$k]['bhoid'] = $order['id'];
|
||||||
|
}
|
||||||
|
(new BeforehandOrderCartInfo())->saveAll($datas);
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @notes 删除预订单表
|
* @notes 删除预订单表
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace app\admin\logic\system_store_storage;
|
namespace app\admin\logic\system_store_storage;
|
||||||
|
|
||||||
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
|
||||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||||
@ -61,18 +61,25 @@ class SystemStoreStorageLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
return true;
|
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
SystemStoreStorage::where('id', $params['id'])->update([
|
$find=SystemStoreStorage::where(['id' => $params['id']])->find();
|
||||||
'nums' => $params['nums'],
|
|
||||||
'admin_id' => $params['admin_id'],
|
if($find){
|
||||||
'status' => 0,
|
$find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
||||||
'mark' => '',
|
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
||||||
]);
|
if($branch_product){
|
||||||
|
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
|
||||||
|
}else{
|
||||||
|
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();
|
||||||
|
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct);
|
||||||
|
$storeBranchProduct->stock = $find['nums'];
|
||||||
|
$storeBranchProduct->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace app\api\controller\system_store_storage;
|
namespace app\api\controller\system_store_storage;
|
||||||
|
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
|
use app\admin\logic\system_store_storage\SystemStoreStorageLogic;
|
||||||
use app\api\controller\BaseApiController;
|
use app\api\controller\BaseApiController;
|
||||||
use app\api\lists\system_store_storage\SystemStoreStorageLists;
|
use app\api\lists\system_store_storage\SystemStoreStorageLists;
|
||||||
use app\api\lists\system_store_storage\SystemStoreStorageGroupLists;
|
use app\api\lists\system_store_storage\SystemStoreStorageGroupLists;
|
||||||
@ -55,25 +56,8 @@ class SystemStoreStorageController extends BaseApiController
|
|||||||
public function warehousing_add()
|
public function warehousing_add()
|
||||||
{
|
{
|
||||||
$params = $this->request->post();
|
$params = $this->request->post();
|
||||||
$find = SystemStoreStorage::where('id', $params['id'])->find();
|
$id = SystemStoreStaff::where('uid', $this->userId)->value('id');
|
||||||
if ($find) {
|
SystemStoreStorageLogic::edit(['id'=>$params['id'],'staff_id'=>$id,'admin_id'=>0]);
|
||||||
$id = SystemStoreStaff::where('uid', $this->userId)->value('id');
|
return $this->success('操作成功');
|
||||||
$find->staff_id = $id;
|
|
||||||
$find->mark = '入库时间:' . date('Y-m-d H:i:s');
|
|
||||||
$find->status = 1;
|
|
||||||
$find->save();
|
|
||||||
|
|
||||||
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
|
||||||
if($branch_product){
|
|
||||||
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
|
|
||||||
}else{
|
|
||||||
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();
|
|
||||||
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct);
|
|
||||||
$storeBranchProduct->stock = $find['nums'];
|
|
||||||
$storeBranchProduct->save();
|
|
||||||
}
|
|
||||||
return $this->success('操作成功');
|
|
||||||
}
|
|
||||||
return $this->fail('操作失败');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,8 @@ class SystemStoreStorageController extends BaseAdminController
|
|||||||
if($id==0){
|
if($id==0){
|
||||||
return $this->fail('参数错误');
|
return $this->fail('参数错误');
|
||||||
}
|
}
|
||||||
$res=SystemStoreStorage::where(['id' => $id,'store_id'=>$this->adminInfo['store_id']])->update(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
SystemStoreStorageLogic::edit(['id'=>$id,'staff_id'=>$this->adminId,'admin_id'=>0]);
|
||||||
if($res){
|
return $this->success('操作成功');
|
||||||
$find=SystemStoreStorage::where(['id' => $id])->find();
|
|
||||||
StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update();
|
|
||||||
return $this->success('操作成功',[]);
|
|
||||||
}
|
|
||||||
return $this->fail('操作失败');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user