diff --git a/app/admin/controller/store_category/StoreCategoryController.php b/app/admin/controller/store_category/StoreCategoryController.php new file mode 100644 index 0000000..381ab13 --- /dev/null +++ b/app/admin/controller/store_category/StoreCategoryController.php @@ -0,0 +1,95 @@ +dataLists(new StoreCategoryLists()); + } + + + /** + * @notes 添加商品分类 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function add() + { + $params = (new StoreCategoryValidate())->post()->goCheck('add'); + $result = StoreCategoryLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreCategoryLogic::getError()); + } + + + /** + * @notes 编辑商品分类 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function edit() + { + $params = (new StoreCategoryValidate())->post()->goCheck('edit'); + $result = StoreCategoryLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreCategoryLogic::getError()); + } + + + /** + * @notes 删除商品分类 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function delete() + { + $params = (new StoreCategoryValidate())->post()->goCheck('delete'); + StoreCategoryLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品分类详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 11:33 + */ + public function detail() + { + $params = (new StoreCategoryValidate())->goCheck('detail'); + $result = StoreCategoryLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/store_product/StoreProductController.php b/app/admin/controller/store_product/StoreProductController.php new file mode 100644 index 0000000..f494ea8 --- /dev/null +++ b/app/admin/controller/store_product/StoreProductController.php @@ -0,0 +1,142 @@ +dataLists(new StoreProductLists()); + } + + + /** + * @notes 添加商品列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function add() + { + $params = (new StoreProductValidate())->post()->goCheck('add'); + $result = StoreProductLogic::add($params); + return $this->success('添加成功', [], 1, 1); + } + + + /** + * @notes 编辑商品列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function edit() + { + $params = (new StoreProductValidate())->post()->goCheck('edit'); + $result = StoreProductLogic::edit($params); + return $this->success('编辑成功', [], 1, 1); + + } + + /** + * @notes 修改商品状态 + * @return \think\response\Json + * @date 2024/05/31 10:53 + */ + public function status(){ + $params=$this->request->post(); + $admin_info=$this->adminInfo; + if($admin_info['job_ids']){ + foreach ($admin_info['job_ids'] as $key => $job_id) { + if($job_id==2){ + return $this->fail('无权限操作'); + } + } + } + StoreProduct::where('id',$params['id'])->update(['is_show'=>$params['is_show']]); + return $this->success('操作成功',[],1,1); + } + + /** + * @notes 删除商品列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function delete() + { + $params = (new StoreProductValidate())->post()->goCheck('delete'); + StoreProductLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品列表详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function detail() + { + $params = (new StoreProductValidate())->goCheck('detail'); + $result = StoreProductLogic::detail($params); + return $this->data($result); + } + + /** + * @notes 复制商品 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function copy() + { + $params = $this->request->post(); + $find = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray(); + foreach ($params['store_arr'] as $key => $store_id) { + StoreProductLogic::ordinary($find, $store_id, $this->adminId, $find); + } + return $this->success('复制成功', [], 1, 1); + } + + /** + * 商品导入到门店 + */ + public function import() + { + return $this->fail('接口已关闭'); + } + + public function restore() + { + $params = (new StoreProductValidate())->post()->goCheck('delete'); + StoreProductLogic::restore($params); + return $this->success('删除成功', [], 1, 1); + } + +} diff --git a/app/admin/controller/store_product_unit/StoreProductUnitController.php b/app/admin/controller/store_product_unit/StoreProductUnitController.php new file mode 100644 index 0000000..bbfb693 --- /dev/null +++ b/app/admin/controller/store_product_unit/StoreProductUnitController.php @@ -0,0 +1,95 @@ +dataLists(new StoreProductUnitLists()); + } + + + /** + * @notes 添加计量单位 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 15:50 + */ + public function add() + { + $params = (new StoreProductUnitValidate())->post()->goCheck('add'); + $result = StoreProductUnitLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(StoreProductUnitLogic::getError()); + } + + + /** + * @notes 编辑计量单位 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 15:50 + */ + public function edit() + { + $params = (new StoreProductUnitValidate())->post()->goCheck('edit'); + $result = StoreProductUnitLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(StoreProductUnitLogic::getError()); + } + + + /** + * @notes 删除计量单位 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 15:50 + */ + public function delete() + { + $params = (new StoreProductUnitValidate())->post()->goCheck('delete'); + StoreProductUnitLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取计量单位详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 15:50 + */ + public function detail() + { + $params = (new StoreProductUnitValidate())->goCheck('detail'); + $result = StoreProductUnitLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/system_store/SystemStoreController.php b/app/admin/controller/system_store/SystemStoreController.php new file mode 100644 index 0000000..748652d --- /dev/null +++ b/app/admin/controller/system_store/SystemStoreController.php @@ -0,0 +1,106 @@ +dataLists(new SystemStoreLists()); + } + /** + * @notes 根据商品源获取门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function source_product_store_lists() + { + return $this->dataLists(new SystemStoreSourceLists()); + } + + /** + * @notes 添加门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function add() + { + $params = (new SystemStoreValidate())->post()->goCheck('add'); + $result = SystemStoreLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SystemStoreLogic::getError()); + } + + + /** + * @notes 编辑门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function edit() + { + $params = (new SystemStoreValidate())->post()->goCheck('edit'); + $result = SystemStoreLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SystemStoreLogic::getError()); + } + + + /** + * @notes 删除门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function delete() + { + $params = (new SystemStoreValidate())->post()->goCheck('delete'); + SystemStoreLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取门店列表详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function detail() + { + $params = (new SystemStoreValidate())->goCheck('detail'); + $result = SystemStoreLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/store_category/StoreCategoryLists.php b/app/admin/lists/store_category/StoreCategoryLists.php new file mode 100644 index 0000000..459f3e5 --- /dev/null +++ b/app/admin/lists/store_category/StoreCategoryLists.php @@ -0,0 +1,94 @@ + ['pid'], + '%like%' => ['name'], + ]; + } + + + /** + * @notes 获取商品分类列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 11:33 + */ + public function lists(): array + { + $userGroups = UserShip::field('id,title')->select()->toArray(); + return StoreCategory::where($this->searchWhere) + ->field(['id', 'pid', 'name', 'data', 'pic', 'sort', 'price_rate']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) use ($userGroups) { + if (empty($item['price_rate'])) { + $item['price_rate'] = $userGroups; + } else { + $priceRate = reset_index($item['price_rate'], 'id'); + unset($priceRate[100003], $priceRate[100004]); + $temp = []; + foreach ($userGroups as $userGroup) { + if (!isset($priceRate[$userGroup['id']])) { + continue; + } + if ($userGroup['id'] == 21 && !empty($priceRate[100001]) && empty($userGroup['rate'])) { + $userGroup['rate'] = $priceRate[100001]['rate']; + unset($priceRate[100001]); + } elseif ($userGroup['id'] == 22 && !empty($priceRate[100002]) && empty($userGroup['rate'])) { + $userGroup['rate'] = $priceRate[100002]['rate']; + unset($priceRate[100002]); + } else { + $userGroup['rate'] = $priceRate[$userGroup['id']]['rate'] ?? 0; + } + $temp[] = $userGroup; + } + $item['price_rate'] = $temp; + } + $item['is_children'] = StoreCategory::where('pid', $item->id)->count(); // 判断是否有子分类 + return $item->toArray(); + }) + ->toArray(); + } + + + /** + * @notes 获取商品分类数量 + * @return int + * @author admin + * @date 2024/05/31 11:33 + */ + public function count(): int + { + return StoreCategory::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php new file mode 100644 index 0000000..d1201c4 --- /dev/null +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -0,0 +1,247 @@ + ['cate_id', 'is_show', 'bar_code', 'id'], + 'in' => ['product_type'], + '<=' => ['stock'], + '%like%' => ['store_name'], + ]; + } + + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function lists(): array + { + $class_all = $this->request->get('class_all'); + if ($class_all) { + //查3级别的 + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; + } else { + $this->searchWhere[] = ['cate_id', '=', $class_all]; + } + } + $is_warehouse = $this->request->get('is_warehouse', 0); + $order_type = $this->request->get('order_type', 0); + $userShip = 0; + if (!empty($this->params['user_id'])) { + $userShip = User::where('id', $this->params['user_id'])->value('user_ship'); + } + $query = StoreProduct::where($this->searchWhere); + if (isset($this->params['type_filter'])) { + $query->where('product_type', '<>', 5); + if ($this->params['type_filter'] == 0) { + $query->where(function ($query) { + $query->where('product_type', 6)->whereOr('is_show', 0); + }); + } else { + $query->where('is_show', 1); + } + } + if (!empty($this->params['activity_zone_form_id'])) { + $exceptIds = ActivityZone::where('form_id', $this->params['activity_zone_form_id'])->column('product_id'); + $query->where('is_show', 1)->where('product_type', '<>', 5)->whereNotIn('id', $exceptIds); + } + $storeId = $this->params['store_id'] ?? 0; + $is_true = true; + if ($storeId > 0) { + $is_true = SystemStore::isSelfOperate($storeId); + } + if (!empty($this->params['product_status'])) { + $query->onlyTrashed(); + } + $list = $query->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) use ($is_warehouse, $userShip, $order_type, $is_true) { + $item['product_id'] = $item['id']; + $item['bar_code_two'] = ''; + if (in_array($item['unit'], [2, 21])) { + $item['bar_code_two'] = $item['bar_code']; + if ($item['bar_code'] == 0) { + $item['bar_code_two'] = ''; + } + $item['bar_code'] = ''; + } else { + if (strlen($item['bar_code']) < 10) { + $item['bar_code_two'] = $item['bar_code']; + if ($item['bar_code'] == 0) { + $item['bar_code_two'] = ''; + } + $item['bar_code'] = ''; + } + } + switch ($item['product_type']) { + case 2: + $item['product_type_name'] = '兑换产品'; + break; + case 3: + $item['product_type_name'] = '赠品'; + break; + case 4: + $item['product_type_name'] = '活动产品'; + break; + case 5: + $item['product_type_name'] = '批发产品'; + break; + case 6: + $item['product_type_name'] = '零采商品'; + break; + default: + $item['product_type_name'] = '普通商品'; + } + $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); + $stock = StoreBranchProduct::where('store_id', '<>', '4')->where('product_id', $item['id'])->sum('stock'); + $category = StoreCategory::where('id', 'in', [$item['top_cate_id'], $item['two_cate_id'], $item['cate_id']])->column('name'); + $item['cate_name'] = implode('/', $category); + if ($is_warehouse == 1) { + $item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); + } else { + $nums = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); + $item['stock'] = bcadd($nums, $stock); + } + if ($userShip == 4) { + $item['price'] = $item['cost']; + } + if ($item['is_show'] == 1) { + $item['status_msg'] = '上架|常用'; + } else { + $item['status_msg'] = '下架|不常用|是否有替换'; + } + if ($order_type == 2) { + $price = StoreProductGroupPrice::where('group_id', 42)->where('product_id', $item['product_id'])->value('price'); + if ($price > 0) { + $item['price'] = $price; + $item['store_name'] = $item['store_name'] . '|活动价'; + } + }elseif($is_true == true && $userShip>0){ + $item['price'] = $item['vip_price']; + $item['store_name'] = $item['store_name'] . '|会员价'; + } + return $item; + })?->toArray(); + // if ($userShip > 0 && $userShip != 4) { + // $list = StoreProductGroupPrice::resetStoreProductsPrice($list, $userShip, $this->params['store_id'] ?? 0); + // } + return $list; + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function count(): int + { + $export = $this->request->get('export'); + if ($export == 1) { + $class_all = $this->request->get('class_all'); + if ($class_all) { + //查3级别的 + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; + } else { + $this->searchWhere[] = ['cate_id', '=', $class_all]; + } + } + } + $query = StoreProduct::where($this->searchWhere); + if (isset($this->params['type_filter'])) { + if ($this->params['type_filter'] == 0) { + $query->where(function ($query) { + $query->where('product_type', 6)->whereOr('is_show', 0); + }); + } else { + $query->where('is_show', 1); + } + } + if (!empty($this->params['product_status'])) { + $query->onlyTrashed(); + } + return $query->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 = [ + 'id' => '商品id', + 'store_name' => '商品名称', + 'product_type_name' => '商品类型', + 'cate_name' => '分类', + 'unit_name' => '单位', + 'store_info' => '规格', + 'stock' => '库存', + 'purchase' => '采购价', + 'cost' => '商户', + 'price' => '零售', + 'rose' => '毛利率', + 'bar_code' => '条码', + ]; + return $data; + } +} diff --git a/app/admin/lists/store_product_unit/StoreProductUnitLists.php b/app/admin/lists/store_product_unit/StoreProductUnitLists.php new file mode 100644 index 0000000..a26acc0 --- /dev/null +++ b/app/admin/lists/store_product_unit/StoreProductUnitLists.php @@ -0,0 +1,65 @@ + ['name'], + ]; + } + + + /** + * @notes 获取计量单位列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 15:50 + */ + public function lists(): array + { + return StoreProductUnit::where($this->searchWhere) + ->field(['id', 'name', 'is_bulk', 'py', 'number', 'data']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取计量单位数量 + * @return int + * @author admin + * @date 2024/05/31 15:50 + */ + public function count(): int + { + return StoreProductUnit::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/system_store/SystemStoreLists.php b/app/admin/lists/system_store/SystemStoreLists.php new file mode 100644 index 0000000..600967f --- /dev/null +++ b/app/admin/lists/system_store/SystemStoreLists.php @@ -0,0 +1,68 @@ + ['phone'], + '%like%'=>['name'] + ]; + } + + + /** + * @notes 获取门店列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 17:45 + */ + public function lists(): array + { + return SystemStore::where($this->searchWhere) + ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show','day_start','day_end' + ,'bank','bank_code','bank_address','realname,paid_deposit,security_deposit' + ]) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取门店列表数量 + * @return int + * @author admin + * @date 2024/05/31 17:45 + */ + public function count(): int + { + return SystemStore::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/store_category/StoreCategoryLogic.php b/app/admin/logic/store_category/StoreCategoryLogic.php new file mode 100644 index 0000000..0dcd944 --- /dev/null +++ b/app/admin/logic/store_category/StoreCategoryLogic.php @@ -0,0 +1,111 @@ + $params['pid'], + 'name' => $params['name'], + 'data' => $params['data'], + 'pic' => $params['pic'], + 'sort' => $params['sort'], + 'price_rate' => array_values($priceRate) + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑商品分类 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 11:33 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $priceRate = []; + foreach ($params['price_rate'] as $v) { + $priceRate[$v['id']] = $v; + } + StoreCategory::where('id', $params['id'])->update([ + 'pid' => $params['pid'], + 'name' => $params['name'], + 'data' => $params['data'], + 'pic' => $params['pic'], + 'sort' => $params['sort'], + 'price_rate' => array_values($priceRate) + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除商品分类 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 11:33 + */ + public static function delete(array $params): bool + { + return StoreCategory::destroy($params['id']); + } + + + /** + * @notes 获取商品分类详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 11:33 + */ + public static function detail($params): array + { + return StoreCategory::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php new file mode 100644 index 0000000..003b94b --- /dev/null +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -0,0 +1,469 @@ + $params['store_name'], + 'image' => $params['image'], + 'store_info' => $params['store_info'] ?? '', + 'bar_code' => $params['bar_code'] ?? '', + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, + 'cate_id' => $params['cate_id'], + 'unit' => $params['unit'], + 'stock' => 0, + 'price' => $params['price'], + 'vip_price' => $params['vip_price'], + 'cost' => $params['cost'], + 'purchase' => $params['purchase'], + 'is_return' => $params['is_return'], + 'manufacturer_information' => $params['manufacturer_information'] ?? '', + 'swap' => $params['swap'] ?? 0, + 'batch' => $params['batch'] ?? 0, + 'store_batch' => $params['store_batch'] ?? 1, + 'product_type' => $params['product_type'] ?? 0, + 'is_show' => $params['is_show'] ?? 0, + 'made_place' => $params['made_place'] ?? '', + ]; + $rose = 0; + //零售-供货 + $rose_price = bcsub($params['price'], $params['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $params['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $data['rose']=$rose; + $res = StoreProduct::create($data); + // 添加商品到活动专区 + (new ActivityZoneLogic())->addProduct($res); + StoreProductAttrValue::create([ + "bar_code" => $params["bar_code"] ?? '', + "image" => $params["image"] ?? '', + "price" => $params['price'], + 'vip_price' => $params['vip_price'], + "cost" => $params['cost'], + "purchase" => $params['purchase'], + "unit" => $params["unit"], + "stock" => 0, + "product_id" => $res['id'], + 'sales' => 0, + ]); + Db::commit(); + if ($data['product_type'] == 5) { + return true; + } + if ($params['is_store_all'] == 1) { + $store_arr = SystemStore::where('is_show', 1)->column('id'); + foreach ($store_arr as $store_id) { + if ($store_id != 5) { + Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]); + } + } + } else { + if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { + foreach ($params['store_arr'] as $key => $store_id) { + if ($store_id != 5) { + Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]); + } + } + } + } + if (getenv('STORE_ID')) { + Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => getenv('STORE_ID'), 'stock_type' => 1, 'admin_id' => Request()->adminId]); + } + + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException('添加商品失败' . $e->getMessage()); + } + } + + public static function deleteRelatedData($cate_id) + { + $data_to_delete = StoreProductCate::where('cate_id', $cate_id)->select(); + foreach ($data_to_delete as $item) { + + if ($item['pid'] != 0) { + self::deleteRelatedData($item['pid']); + StoreProductCate::where('id', $item['id'])->update(['delete_time' => time()]); + } + + if ($item['pid'] == 0 && in_array($item['count'], [0, 1])) { + StoreProductCate::where('id', $item['id'])->update(['delete_time' => time()]); + } + } + } + + // 递归减少分类数据的count值 + public static function decreaseCount($cate_id) + { + $data_to_decrease = StoreProductCate::where('cate_id', $cate_id)->select(); + foreach ($data_to_decrease as $item) { + if ($item['pid'] != 0) { + self::decreaseCount($item['pid']); + } + StoreProductCate::where('id', $item['id'])->update(['count' => $item['count'] - 1]); + } + } + + /* + * 传入三级或者二级分类返还上级分类 一级那全是相同 + */ + public static function dealChangeCate($cate_id) + { + $value = []; + $last_cate = Db::name('store_category')->where('id', $cate_id)->value('pid'); + if (!empty($last_cate)) { + //2 + $value['two_cate_id'] = $last_cate; + //1 + $first_cate = Db::name('store_category')->where('id', $value['two_cate_id'])->value('pid'); + if (empty($first_cate)) { //顶级了 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $last_cate; + } else { + $value['top_cate_id'] = $first_cate; + } + } else { + //1-2 选的1级目录 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $cate_id; + } + return $value; + } + + /** + * @notes 编辑商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + $count = count($params['cate_arr']); + $top_cate_id = 0; + $two_cate_id = 0; + if ($count == 3) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][1]; + } elseif ($count == 2) { + $top_cate_id = $params['cate_arr'][0]; + $two_cate_id = $params['cate_arr'][0]; + } + $data = [ + 'store_name' => $params['store_name'], + 'image' => $params['image'], + 'bar_code' => $params['bar_code'] ?? '', + 'store_info' => $params['store_info'] ?? '', + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, + 'cate_id' => $params['cate_id'], + 'unit' => $params['unit'], + 'stock' => $params['stock'], + 'cost' => $params['cost'], + 'purchase' => $params['purchase'], + 'is_return' => $params['is_return'], + 'price' => $params['price'], + 'vip_price' => $params['vip_price'], + 'batch' => $params['batch'], + 'store_batch' => $params['store_batch'] ?? 1, + 'manufacturer_information' => $params['manufacturer_information'] ?? '', + 'swap' => $params['swap'] ?? 0, + 'is_show' => $params['is_show'] ?? 0, + 'made_place' => $params['made_place'] ?? '', + ]; + $rose = 0; + //零售-供货 + $rose_price = bcsub($params['price'], $params['purchase'], 2); + if ($rose_price > 0) { + //利润除于零售 + $price_div = bcdiv($rose_price, $params['price'], 2); + $rose=bcmul($price_div, 100, 2); + } + $data['rose']=$rose; + $find=StoreProduct::where(['id' => $params['id']])->find(); + if($find['purchase']!=$params['purchase']){ + SqlChannelPriceLog($params['id'],21,$find['purchase'],$params['purchase'],); + } + if($find['cost']!=$params['cost']){ + SqlChannelPriceLog($params['id'],4,$find['cost'],$params['cost'],); + } + if($find['price']!=$params['price']){ + SqlChannelPriceLog($params['id'],22,$find['price'],$params['price'],); + } + $find->save($data); + // 修改活动专区商品 + (new ActivityZoneLogic())->updateProduct($params['id'], $data); + // $dealCate = self::dealChangeCate($params['cate_id']); + //修改 + StoreBranchProduct::where('product_id', $params['id'])->whereNotIn('store_id', [17, 18])->update([ + 'price' => $params['price'], + 'vip_price' => $params['vip_price'], + 'cost' => $params['cost'], + 'unit' => $params['unit'], + 'batch' => $params['batch'], + 'store_name' => $params['store_name'], + 'manufacturer_information' => $params['manufacturer_information'] ?? '', + 'store_info' => $params['store_info'] ?? '', + 'cate_id' => $params['cate_id'], + 'top_cate_id' => $top_cate_id, + 'two_cate_id' => $two_cate_id, + 'bar_code' => $params['bar_code'], + 'purchase' => $params['purchase'], + 'rose' => $rose, + 'status' => $params['is_show'] ?? 0, + 'image' => $params['image'], + 'store_batch' => $params['store_batch'] ?? 1, + + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + d($e); + throw new BusinessException('编辑商品失败' . $e->getMessage()); + } + } + + + /** + * @notes 删除商品列表 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function delete(array $params): bool + { + $res = StoreProduct::destroy($params['id']); + // 删除活动专区商品 + (new ActivityZoneLogic())->deleteProduct($params['id']); + StoreBranchProduct::where('product_id', $params['id'])->update(['delete_time' => time()]); + return $res; + } + + public static function restore(array $params): bool + { + $data = StoreProduct::where('id', $params['id'])->onlyTrashed()->find(); + if (empty($data)) { + throw new BusinessException('数据不存在'); + } + $res = $data->restore(); + StoreBranchProduct::where('product_id', $params['id'])->update(['delete_time' => null]); + return $res; + } + + + /** + * @notes 获取商品详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public static function detail($params): array + { + $query = StoreProduct::where('id', $params['id']); + if (isset($params['is_show'])) { + $query->where('is_show', $params['is_show']); + } + $data = $query->findOrEmpty()->toArray(); + if(empty($data)){ + throw new BusinessException('商品不存在'); + } + $data['cate_arr']=[$data['top_cate_id']]; + if($data['two_cate_id'] == $data['top_cate_id']){ + $data['cate_arr'][]=$data['cate_id']; + }else{ + $data['cate_arr'][]=$data['two_cate_id']; + $data['cate_arr'][]=$data['cate_id']; + } + $data['unit_name']=StoreProductUnit::where('id', $data['unit'])->value('name'); + if (!empty($params['user_id'])) { + $userShip = User::where('id', $params['user_id'])->value('user_ship'); + if ($userShip == 4) { + $data['price'] = $data['cost']; + } else { + $data = StoreProductGroupPrice::resetStoreProductPrice($data, $userShip, $params['store_id'] ?? 0); + } + } + if($data['is_show']==1){ + $data['status_msg']='上架|常用'; + }else{ + $data['status_msg']='下架|不常用|是否有替换'; + } + $data['stock']=WarehouseProductStorege::where('product_id', $params['id'])->where('warehouse_id',1)->value('nums')??0; + + return $data; + } + + /** + * 删除门店商品 + */ + public static function store_del($id, $store_id) + { + + Db::startTrans(); + try { + StoreBranchProduct::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]); + StoreBranchProductAttrValue::where(['product_id' => $id, 'store_id' => $store_id])->update(['delete_time' => time()]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException('删除失败' . $e->getMessage()); + } + } + + + /**普通 */ + public static function ordinary($product_arr, $store_id, $admin_id, $find) + { + $res = StoreBranchProduct::where('store_id', $store_id)->where('product_id', $find['id'])->find(); + if ($res) { + return $res; + } + $dealCate = self::dealChangeCate($find['cate_id']); + $product = [ + 'product_id' => $find['id'], + 'image' => $find['image'], + 'store_name' => $find['store_name'], + 'store_info' => $find['store_info'], + 'keyword' => $find['keyword'], + 'bar_code' => $find['bar_code'], + 'cate_id' => $find['cate_id'], + 'top_cate_id' => $dealCate['top_cate_id'], + 'two_cate_id' => $dealCate['two_cate_id'], + 'price' => $find['price'], + // 'cost' => $find['cost'], //v1.0 + 'cost' => $find['cost'], + 'purchase' => $find['purchase'], + 'vip_price' => $find['vip_price'], + 'manufacturer_information' => $find['manufacturer_information'] ?? '', + 'unit' => $find['unit'], + 'batch' => $find['batch'], + 'store_batch' => $find['store_batch'], + 'store_id' => $store_id, + 'sales' => 0, + 'product_type' => $find['product_type'], + 'stock' => 0, + 'rose' => $find['rose'], + ]; + $branch = StoreBranchProduct::create($product); + $arr = [ + 'product_id' => $product_arr['id'], + 'store_id' => $store_id, + 'sales' => 0, + 'type' => 0, + 'bar_code' => $find['bar_code'] + ]; + StoreBranchProductAttrValue::create($arr); + return $branch; + } + + /**兑换 */ + public static function exchange($product_arr, $store_id, $admin_id, $find, $warehouse_id) + { + $store_find = StoreBranchProductExchange::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray(); + if ($find && !$store_find) { + Db::startTrans(); + try { + $product = [ + 'product_id' => $find['id'], + 'image' => $find['image'], + 'store_name' => $find['store_name'], + 'store_info' => $find['store_info'], + 'keyword' => $find['keyword'], + 'bar_code' => $find['bar_code'], + 'cate_id' => $find['cate_id'], + 'price' => $find['price'], + 'cost' => $find['cost'], + 'purchase' => $find['purchase'], + 'vip_price' => $find['vip_price'], + 'unit' => $find['unit'], + 'store_id' => $store_id, + 'sales' => 0, + 'stock' => 0, + ]; + StoreBranchProductExchange::create($product); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException('添加兑换商品失败' . $e->getMessage()); + } + } + // else { + // Db::startTrans(); + // try { + // // if ($product_arr['stock'] > 0) { + // // self::storage($find, $store_id, $admin_id, $product_arr,2,$warehouse_id); + // // } + // Db::commit(); + // return true; + // } catch (\Exception $e) { + // Db::rollback(); + // Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); + // return false; + // } + // } + } +} diff --git a/app/admin/logic/store_product_unit/StoreProductUnitLogic.php b/app/admin/logic/store_product_unit/StoreProductUnitLogic.php new file mode 100644 index 0000000..caa9bb9 --- /dev/null +++ b/app/admin/logic/store_product_unit/StoreProductUnitLogic.php @@ -0,0 +1,101 @@ + $params['name'], + 'is_bulk' => $params['is_bulk'], + 'py' => $params['py'], + 'number' => $params['number'], + 'data' => $params['data'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑计量单位 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 15:50 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + StoreProductUnit::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'is_bulk' => $params['is_bulk'], + 'py' => $params['py'], + 'number' => $params['number'], + 'data' => $params['data'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除计量单位 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 15:50 + */ + public static function delete(array $params): bool + { + return StoreProductUnit::destroy($params['id']); + } + + + /** + * @notes 获取计量单位详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 15:50 + */ + public static function detail($params): array + { + return StoreProductUnit::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/store_category/StoreCategoryValidate.php b/app/admin/validate/store_category/StoreCategoryValidate.php new file mode 100644 index 0000000..036e341 --- /dev/null +++ b/app/admin/validate/store_category/StoreCategoryValidate.php @@ -0,0 +1,86 @@ + 'require', + 'pid' => 'require', + 'name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'pid' => '所属ID', + 'name' => '分类名称', + ]; + + + /** + * @notes 添加场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneAdd() + { + return $this->only(['pid','name']); + } + + + /** + * @notes 编辑场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneEdit() + { + return $this->only(['id','pid','name']); + } + + + /** + * @notes 删除场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreCategoryValidate + * @author admin + * @date 2024/05/31 11:33 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/store_product/StoreProductValidate.php b/app/admin/validate/store_product/StoreProductValidate.php new file mode 100644 index 0000000..4f941af --- /dev/null +++ b/app/admin/validate/store_product/StoreProductValidate.php @@ -0,0 +1,86 @@ + 'require', + 'store_name' => 'require', + 'rose' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'store_name' => '商品名称', + 'rose'=>'上浮比率' + ]; + + + /** + * @notes 添加场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneAdd() + { + return $this->only(['store_name','rose']); + } + + + /** + * @notes 编辑场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneEdit() + { + return $this->only(['id','store_name','rose']); + } + + + /** + * @notes 删除场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductValidate + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/store_product_unit/StoreProductUnitValidate.php b/app/admin/validate/store_product_unit/StoreProductUnitValidate.php new file mode 100644 index 0000000..a1d11c4 --- /dev/null +++ b/app/admin/validate/store_product_unit/StoreProductUnitValidate.php @@ -0,0 +1,84 @@ + 'require', + 'name' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '单位名称', + ]; + + + /** + * @notes 添加场景 + * @return StoreProductUnitValidate + * @author admin + * @date 2024/05/31 15:50 + */ + public function sceneAdd() + { + return $this->only(['name']); + } + + + /** + * @notes 编辑场景 + * @return StoreProductUnitValidate + * @author admin + * @date 2024/05/31 15:50 + */ + public function sceneEdit() + { + return $this->only(['id','name']); + } + + + /** + * @notes 删除场景 + * @return StoreProductUnitValidate + * @author admin + * @date 2024/05/31 15:50 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return StoreProductUnitValidate + * @author admin + * @date 2024/05/31 15:50 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/store_category/StoreCategory.php b/app/common/model/store_category/StoreCategory.php new file mode 100644 index 0000000..c1d0379 --- /dev/null +++ b/app/common/model/store_category/StoreCategory.php @@ -0,0 +1,26 @@ +hasOne(StoreProductUnit::class,'id','unit')->bind(['unit_name'=>'name','is_bulk']); + } + + + public function className() + { + return $this->hasOne(StoreCategory::class,'id','cate_id')->bind(['class_name'=>'name']); + + } + public static function onBeforeWrite($data) + { + try { + $where = $data->getWhere(); + if($data){ + $find = self::where($where)->field(array_keys($data->toArray()))->find(); + if ($find) { + channelLog(array_merge($find->toArray(), $where), 'product', '更新前'); + } + } + } catch (Throwable $e) { + Log::error('product:' . $e->getMessage()); + } + } + public static function onAfterWrite($data){ + try{ + channelLog($data->toArray(),'product','更新后'); + }catch(Throwable $e){ + Log::error('product:'.$e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/common/model/store_product_unit/StoreProductUnit.php b/app/common/model/store_product_unit/StoreProductUnit.php new file mode 100644 index 0000000..25ae541 --- /dev/null +++ b/app/common/model/store_product_unit/StoreProductUnit.php @@ -0,0 +1,23 @@ +dataLists(new PsiProductLists()); + } + + + /** + * @notes 添加商品出入库信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function add() + { + return $this->fail('当前接口废弃'); + } + + + /** + * @notes 编辑商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function edit() + { + $params = $this->request->post(); + $params['admin_id'] = $this->adminId; + $result = WarehouseProductLogic::edit($params,$this->adminId); + return $this->success('编辑成功', [], 1, 1); + } + + + /** + * @notes 删除商品仓储信息 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function delete() + { + $params = (new WarehouseProductValidate())->post()->goCheck('delete'); + WarehouseProductLogic::delete($params,$this->adminId); + return $this->success('删除成功', [], 1, 1); + + } + + + /** + * @notes 获取商品仓储信息详情 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function detail() + { + $params = (new WarehouseProductValidate())->goCheck('detail'); + $result = WarehouseProductLogic::detail($params); + return $this->data($result); + } + + /** + * @notes 结算 + * @return \think\response\Json + * @author admin + * @date 2024/07/31 16:55 + */ + public function settlement(){ + $id=$this->request->post('id'); + $result = WarehouseProductLogic::settlement($id); + return $this->success('结算成功', [], 1, 1); + } + /** + * 确认操作 + */ + public function enter() + { + // $id=$this->request->post('id'); + // $result = WarehouseProductLogic::enter($id); + // if (true === $result) { + // return $this->success('编辑成功', [], 1, 1); + // } + // return $this->fail(WarehouseProductLogic::getError()); + return $this->success(''); + } + + /** + * 仓库重置出入库数量 + */ + public function set_nums() + { + $params=$this->request->post(); + $result = WarehouseProductLogic::settNums($params,$this->adminId); + return $this->success(''); + } +} diff --git a/app/psi/lists/psi_product/PsiProductLists.php b/app/psi/lists/psi_product/PsiProductLists.php new file mode 100644 index 0000000..1a1f5d4 --- /dev/null +++ b/app/psi/lists/psi_product/PsiProductLists.php @@ -0,0 +1,228 @@ + ['warehouse_id', 'financial_pm', 'product_id','store_id','oid','supplier_id','is_pay','code'], + 'between_time' => 'create_time' + ]; + } + + + /** + * @notes 获取商品仓储信息列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/07/31 16:55 + */ + public function lists(): array + { + if ($this->request->get('product_name')) { + $product_name = $this->request->get('product_name'); + $ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + $this->ids = $ids; + } else { + return []; + } + } + if ($this->request->get('bar_code')) { + $bar_code = $this->request->get('bar_code'); + $ids = StoreProduct::where('bar_code', 'like', '%' . $bar_code . '%')->withTrashed()->column('id'); + if ($ids) { + $this->searchWhere[] = ['product_id', 'in', $ids]; + $this->ids = $ids; + } else { + return []; + } + } + $query = PsiProduct::where($this->searchWhere); + if (isset($this->params['is_group']) && $this->params['is_group'] == 1) { + $query->group('product_id')->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'sum(nums) nums', 'price', 'purchase', 'cost', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']); + } else { + $query->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']); + } + return $query + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + // ->withTrashed() + ->select()->each(function ($item) { + $item->store_name = ''; + $item->image = ''; + $item->price = $item['price']??0; + $item->purchase = $item['purchase']??0; + $item->unit_name = ''; + $item->store_info = ''; + $item->top_cate_name = ''; + if ($item->financial_pm == 0) { + $item->financial_pm_name = '出库'; + } else { + $item->financial_pm_name = '入库'; + } + if ($item->store_id > 0) { + $item->system_store_name = SystemStore::where('id', $item->store_id)->value('name'); + } else { + $item->system_store_name = ''; + } + if ($item->status == 0) { + $item->status_name = '未确认'; + } elseif ($item->status == 1) { + $item->status_name = '已确认'; + } else { + $item->status_name = '库存不足'; + } + if ($item->admin_id) { + $item->admin_name = Admin::where('id', $item->admin_id)->value('name'); + } else { + $item->admin_name = ''; + } + if ($item->product_id) { + $find = StoreProduct::where('id', $item->product_id)->field('price,purchase,image,store_name,unit,store_info,top_cate_id')->withTrashed()->find(); + if($find){ + $item->store_name = $find->store_name . '|' . $item->product_id; + $item->image = $find->image; + $item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name'); + $item->store_info =$find->store_info; + $item->top_cate_name =StoreCategory::where('id', $find->top_cate_id)->value('name'); + } + } + if ($item->warehouse_id) { + $item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name'); + } else { + $item->warehouse_name = ''; + } + if ($item->supplier_id) { + $item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name'); + }else{ + $item->supplier_name = ''; + } + $item->expiration_date = $item->expiration_date ? date('Y-m-d', $item->expiration_date) : ''; + $item->manufacture = $item->manufacture ? date('Y-m-d', $item->manufacture) : ''; + + if (!empty($item['order_type'])) { + $item->order_type_name = getOrderTypeName($item->order_type); + } + if ($item->order_type == 5) { + $item->outbound = '无须出库'; + } + }) + ->toArray(); + } + + + /** + * @notes 获取商品仓储信息数量 + * @return int + * @author admin + * @date 2024/07/31 16:55 + */ + public function count(): int + { + if ($this->ids) { + return PsiProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count(); + } else { + return PsiProduct::where($this->searchWhere)->count(); + } + } + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + $financial_pm = $this->request->get('financial_pm'); + if ($financial_pm == 1) { + return '入库列表'; + } + return '出库列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $financial_pm = $this->request->get('financial_pm'); + if ($financial_pm == 1) { + $data = [ + 'admin_name' => '操作人员', + 'warehouse_name' => '仓库', + 'supplier_name' => '供应商', + 'store_name' => '商品名称', + 'financial_pm_name' => '出入库', + 'code' => '入库单', + 'batch' => '批次', + 'nums' => '数量', + 'manufacture' => '生产日期', + 'expiration_date' => '保质期', + 'purchase' => '采购价', + 'price' => '零售', + 'total_price' => '总价', + 'create_time' => '操作时间', + ]; + } else { + $data = [ + 'id' => 'id', + 'admin_name' => '操作人员', + 'warehouse_name' => '仓库', + 'store_name' => '商品名称', + 'top_cate_name' => '分类', + 'store_info' => '规格', + 'unit_name' => '单位', + 'financial_pm_name' => '出入库', + 'code' => '出库单', + 'system_store_name' => '门店', + 'nums' => '数量', + 'purchase' => '供货价', + 'vip_price' => '会员价', + 'price' => '零售价', + 'total_price' => '供货总价', + 'create_time' => '操作时间', + ]; + } + + return $data; + } +}