添加入库记录

This commit is contained in:
luofei 2024-06-07 15:43:39 +08:00
parent 454a0ea3ad
commit 5c1f3350cd
3 changed files with 93 additions and 11 deletions

View File

@ -49,16 +49,16 @@ class SystemStoreStorageLists extends BaseAdminDataLists implements ListsSearchI
->field(['id', 'store_id', 'admin_id', 'staff_id', 'product_id', 'nums', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name');
$item['admin_name']=Admin::where('id',$item['admin_id'])->value('name');
$item['admin_name']=Admin::where('id',$item['admin_id'])->value('name');
if($item['staff_id']>0){
$item['staff_name']=SystemStoreStaff::where('id',$item['staff_id'])->value('staff_name');
}else{
$item['staff_name']='无';
->select()->each(function ($item) {
$item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name');
$item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name');
$item['admin_name'] = Admin::where('id', $item['admin_id'])->value('name');
if ($item['staff_id'] > 0) {
$item['staff_name'] = SystemStoreStaff::where('id', $item['staff_id'])->value('staff_name');
} else {
$item['staff_name'] = '无';
}
$item['store_name']=StoreProduct::where('id',$item['product_id'])->value('store_name');
$item['store_name'] = StoreProduct::where('id', $item['product_id'])->value('store_name');
return $item;
})
->toArray();

View File

@ -3,6 +3,8 @@
namespace app\admin\logic\system_store_storage;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
use app\common\model\system_store_storage\SystemStoreStorage;
use app\common\logic\BaseLogic;
use think\facade\Db;
@ -101,4 +103,33 @@ class SystemStoreStorageLogic extends BaseLogic
{
return SystemStoreStorage::findOrEmpty($params['id'])->toArray();
}
public static function confirm($params)
{
$storage = SystemStoreStorage::where('id', $params['id'])->where('store_id', $params['store_id'])->find();
if (empty($storage)) {
throw new \Exception('数据不存在');
}
if ($storage['status'] != 0) {
throw new \Exception('当前状态不能确认入库');
}
$StoreProduct = StoreBranchProduct::where('store_id', $storage['store_id'])->where('product_id', $storage['product_id'])->find();
if (empty($StoreProduct)) {
throw new \Exception('商品不存在');
}
Db::startTrans();
try {
$StoreProduct->stock += $storage['nums'];
$StoreProduct->save();
$storage->status = 1;
$storage->staff_id = $params['staff_id'];
$storage->save();
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
throw new \Exception($e->getMessage());
}
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace app\store\controller\store_product;
use app\common\controller\Definitions;
use app\store\controller\BaseAdminController;
use app\admin\lists\system_store_storage\SystemStoreStorageLists;
use app\admin\logic\system_store_storage\SystemStoreStorageLogic;
use app\admin\validate\system_store_storage\SystemStoreStorageValidate;
use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\title('入库管理')]
class StoreStorageController extends BaseAdminController
{
#[
ApiDoc\Title('入库记录'),
ApiDoc\url('/store/store_product/storeStorage/lists'),
ApiDoc\Method('GET'),
ApiDoc\NotHeaders(),
ApiDoc\Query(name: 'store_id', type: 'int', require: false, desc: '门店id'),
ApiDoc\Query(name: 'staff_id', type: 'int', require: false, desc: '店员id'),
ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态0-待确认1-已确认'),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Query(ref: [Definitions::class, "page"]),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function lists()
{
return $this->dataLists(new SystemStoreStorageLists());
}
#[
ApiDoc\Title('确认入库'),
ApiDoc\url('/store/store_product/storeStorage/confirm'),
ApiDoc\Method('POST'),
ApiDoc\NotHeaders(),
ApiDoc\Header(ref: [Definitions::class, "token"]),
ApiDoc\Param(name: 'id', type: 'int', require: true, desc: 'id'),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function confirm()
{
$params = (new SystemStoreStorageValidate())->post()->goCheck('edit');
$params['store_id'] = $this->request->adminInfo['store_id'];
$params['staff_id'] = $this->request->adminInfo['admin_id'];
SystemStoreStorageLogic::confirm($params);
return $this->success('操作成功', [], 1, 1);
}
}