diff --git a/app/admin/controller/warehouse_product/WarehouseProductController.php b/app/admin/controller/warehouse_product/WarehouseProductController.php index 4f1fdeb3..a552f941 100644 --- a/app/admin/controller/warehouse_product/WarehouseProductController.php +++ b/app/admin/controller/warehouse_product/WarehouseProductController.php @@ -38,10 +38,22 @@ class WarehouseProductController extends BaseAdminController */ public function add() { - $params = (new WarehouseProductValidate())->post()->goCheck('add'); - $params['admin_id']=$this->adminId; - $params['store_id']=0; - $result = WarehouseProductLogic::add($params); + $params = $this->request->post(); + + foreach($params['product_arr'] as $k=>$v){ + $data['admin_id']=$this->adminId; + $data['store_id']=0; + $data['supplier_id']=$params['supplier_id']; + $data['warehouse_id']=$params['warehouse_id']; + $data['code']=$params['code']; + $data['product_id']=$v['product_id']; + $data['nums']=$v['nums']; + $data['purchase']=$v['purchase']; + $data['total_price']=$v['total_price']; + $data['financial_pm']=1; + WarehouseProductLogic::add($data); + } + if (WarehouseProductLogic::hasError()) { return $this->fail(WarehouseProductLogic::getError()); }else{ diff --git a/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php index e668a823..b5f7646c 100644 --- a/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php +++ b/app/admin/lists/warehouse_product_storege/WarehouseProductStoregeLists.php @@ -11,13 +11,14 @@ use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\warehouse\Warehouse; use app\common\lists\ListsSortInterface; +use app\common\lists\ListsExcelInterface; /** * 仓库商品存储列表 * Class WarehouseProductStoregeLists * @package app\admin\listswarehouse_product_storege */ -class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsSortInterface +class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExcelInterface { public $ids; public $store_name; @@ -31,7 +32,7 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe public function setSearch(): array { return [ - '=' => ['warehouse_id','product_id'], + '=' => ['warehouse_id', 'product_id'], ]; } /** @@ -49,7 +50,7 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe */ public function setDefaultOrder(): array { - return [ 'id' => 'desc','nums' => 'desc',]; + return ['id' => 'desc', 'nums' => 'desc',]; } /** @@ -101,6 +102,11 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe $item->rose = $find->rose; $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name'); + }else{ + $item->store_name = ''; + $item->cate_name = ''; + $item->unit_name = ''; + $item->store_info = ''; } $item['stock'] = $item['nums']; return $item; @@ -127,4 +133,37 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe return WarehouseProductStorege::where($this->searchWhere)->count(); } } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + + return '仓库商品列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + + $data = [ + 'store_name' => '商品名称', + 'cate_name' => '分类', + 'unit_name' => '单位', + 'store_info' => '规格', + 'nums' => '数量', + ]; + + return $data; + } } diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 1ae90f04..0dd50725 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -34,7 +34,7 @@ class WarehouseProductLogic extends BaseLogic public static function add(array $params) { // Db::startTrans(); - // try { + try { $before_nums = 0; $after_nums = 0; $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); @@ -51,6 +51,7 @@ class WarehouseProductLogic extends BaseLogic } $before_nums = $storege['nums']; } else { + $after_nums=$params['nums']; WarehouseProductStorege::create([ 'warehouse_id' => $params['warehouse_id'], 'product_id' => $params['product_id'], @@ -91,12 +92,13 @@ class WarehouseProductLogic extends BaseLogic // self::enter($res['id'], $params['financial_pm']); // Db::commit(); return $res; - // } catch (\Exception $e) { - // Db::rollback(); - // Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine()); - // self::setError($e->getMessage()); - // return false; - // } + } catch (\Throwable $e) { + throw new BusinessException($e->getMessage()); + // Db::rollback(); + // Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine()); + // self::setError($e->getMessage()); + // return false; + } }