|
@@ -7,6 +7,7 @@
|
|
|
namespace bizGhs\item\services;
|
|
namespace bizGhs\item\services;
|
|
|
|
|
|
|
|
use biz\item\classes\PtItemClass;
|
|
use biz\item\classes\PtItemClass;
|
|
|
|
|
+use biz\item\classes\PtItemClassClass;
|
|
|
use bizGhs\base\services\BaseService;
|
|
use bizGhs\base\services\BaseService;
|
|
|
use bizGhs\item\classes\ItemClass;
|
|
use bizGhs\item\classes\ItemClass;
|
|
|
use bizGhs\item\classes\ItemClassClass;
|
|
use bizGhs\item\classes\ItemClassClass;
|
|
@@ -21,48 +22,49 @@ class ItemService extends BaseService
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
public static $baseFile = '\bizGhs\item\classes\ItemClass';
|
|
public static $baseFile = '\bizGhs\item\classes\ItemClass';
|
|
|
|
|
+
|
|
|
//新增花材
|
|
//新增花材
|
|
|
public static function addGhsItem($data)
|
|
public static function addGhsItem($data)
|
|
|
{
|
|
{
|
|
|
- $merchantId = $data['merchantId']??0;
|
|
|
|
|
- $classId = $data['classId']??0;
|
|
|
|
|
- $itemId = $data['itemId']??0;
|
|
|
|
|
- $cost = $data['cost']??false;
|
|
|
|
|
- $addPrice = $data['addPrice']??false;
|
|
|
|
|
- $stockWarning = $data['stockWarning']??false;
|
|
|
|
|
|
|
+ $merchantId = $data['merchantId'] ?? 0;
|
|
|
|
|
+ $classId = $data['classId'] ?? 0;
|
|
|
|
|
+ $itemId = $data['itemId'] ?? 0;
|
|
|
|
|
+ $cost = $data['cost'] ?? false;
|
|
|
|
|
+ $addPrice = $data['addPrice'] ?? false;
|
|
|
|
|
+ $stockWarning = $data['stockWarning'] ?? false;
|
|
|
//$shopId = $data['shopId']??0;
|
|
//$shopId = $data['shopId']??0;
|
|
|
- if(!$merchantId ){
|
|
|
|
|
|
|
+ if (!$merchantId) {
|
|
|
util::fail("请选择供应商");
|
|
util::fail("请选择供应商");
|
|
|
}
|
|
}
|
|
|
- if(!$classId){
|
|
|
|
|
|
|
+ if (!$classId) {
|
|
|
util::fail("请选择分类");
|
|
util::fail("请选择分类");
|
|
|
}
|
|
}
|
|
|
- if(!$itemId){
|
|
|
|
|
|
|
+ if (!$itemId) {
|
|
|
util::fail("请选择花材");
|
|
util::fail("请选择花材");
|
|
|
}
|
|
}
|
|
|
- if($cost===false){
|
|
|
|
|
|
|
+ if ($cost === false) {
|
|
|
util::fail("请输入花材的成本价");
|
|
util::fail("请输入花材的成本价");
|
|
|
}
|
|
}
|
|
|
- if($addPrice===false){
|
|
|
|
|
|
|
+ if ($addPrice === false) {
|
|
|
util::fail("请输入花材的加价");
|
|
util::fail("请输入花材的加价");
|
|
|
}
|
|
}
|
|
|
- if($stockWarning===false){
|
|
|
|
|
|
|
+ if ($stockWarning === false) {
|
|
|
util::fail("请输入库存预警值");
|
|
util::fail("请输入库存预警值");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//判断花材是否存在 调用平台花材的方法
|
|
//判断花材是否存在 调用平台花材的方法
|
|
|
$checkItem = PtItemClass::getById($itemId);
|
|
$checkItem = PtItemClass::getById($itemId);
|
|
|
- if(!$checkItem){
|
|
|
|
|
|
|
+ if (!$checkItem) {
|
|
|
util::fail("花材不存在");
|
|
util::fail("花材不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $existItemClass = ItemClassClass::exists(['id'=>$classId,'merchantId'=>$merchantId]);
|
|
|
|
|
- if(!$existItemClass){
|
|
|
|
|
|
|
+ $existItemClass = ItemClassClass::exists(['id' => $classId, 'merchantId' => $merchantId]);
|
|
|
|
|
+ if (!$existItemClass) {
|
|
|
util::fail("花材分类不存在");
|
|
util::fail("花材分类不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $existItem = ItemClass::exists(['itemId'=>$itemId,'merchantId'=>$merchantId]);
|
|
|
|
|
- if($existItem){
|
|
|
|
|
|
|
+ $existItem = ItemClass::exists(['itemId' => $itemId, 'merchantId' => $merchantId]);
|
|
|
|
|
+ if ($existItem) {
|
|
|
util::fail("花材已添加");
|
|
util::fail("花材已添加");
|
|
|
}
|
|
}
|
|
|
//补全花材信息
|
|
//补全花材信息
|
|
@@ -78,26 +80,26 @@ class ItemService extends BaseService
|
|
|
|
|
|
|
|
$connection = Yii::$app->db;
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
$transaction = $connection->beginTransaction();
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
//写入一条item,同时写入一条itemInfo(初始化库存)
|
|
//写入一条item,同时写入一条itemInfo(初始化库存)
|
|
|
ItemClass::add($data);
|
|
ItemClass::add($data);
|
|
|
//根据sjId ,获取所有的shopId, 循环写入product
|
|
//根据sjId ,获取所有的shopId, 循环写入product
|
|
|
$shopIds = ShopService::getShopIds($merchantId);
|
|
$shopIds = ShopService::getShopIds($merchantId);
|
|
|
- if(empty($shopIds)){
|
|
|
|
|
|
|
+ if (empty($shopIds)) {
|
|
|
$transaction->rollBack();
|
|
$transaction->rollBack();
|
|
|
util::fail("无门店");
|
|
util::fail("无门店");
|
|
|
}
|
|
}
|
|
|
- foreach ($shopIds as $shopId){
|
|
|
|
|
|
|
+ foreach ($shopIds as $shopId) {
|
|
|
$data['shopId'] = $shopId;
|
|
$data['shopId'] = $shopId;
|
|
|
//判断product 是否存在,若存在,则不再处理
|
|
//判断product 是否存在,若存在,则不再处理
|
|
|
- $existItem = ProductClass::exists(['itemId'=>$itemId,'merchantId'=>$merchantId,'shopId'=>$shopId]);
|
|
|
|
|
- if($existItem){
|
|
|
|
|
|
|
+ $existItem = ProductClass::exists(['itemId' => $itemId, 'merchantId' => $merchantId, 'shopId' => $shopId]);
|
|
|
|
|
+ if ($existItem) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
ProductClass::add($data);
|
|
ProductClass::add($data);
|
|
|
}
|
|
}
|
|
|
$transaction->commit();
|
|
$transaction->commit();
|
|
|
- }catch (Exception $exception){
|
|
|
|
|
|
|
+ } catch (Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
$transaction->rollBack();
|
|
|
util::fail("新增失败");
|
|
util::fail("新增失败");
|
|
|
}
|
|
}
|
|
@@ -109,11 +111,11 @@ class ItemService extends BaseService
|
|
|
{
|
|
{
|
|
|
$connection = Yii::$app->db;
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
$transaction = $connection->beginTransaction();
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
ItemClass::batchAdd($data);
|
|
ItemClass::batchAdd($data);
|
|
|
ProductClass::batchAdd($data);
|
|
ProductClass::batchAdd($data);
|
|
|
$transaction->commit();
|
|
$transaction->commit();
|
|
|
- }catch (\Exception $exception){
|
|
|
|
|
|
|
+ } catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
$transaction->rollBack();
|
|
|
util::fail("初始化失败");
|
|
util::fail("初始化失败");
|
|
|
}
|
|
}
|
|
@@ -122,56 +124,56 @@ class ItemService extends BaseService
|
|
|
//修改花材信息
|
|
//修改花材信息
|
|
|
public static function updateGshItem($data)
|
|
public static function updateGshItem($data)
|
|
|
{
|
|
{
|
|
|
- $id = $data['id']??0;
|
|
|
|
|
- $stockWarning = $data['stockWarning']??0;
|
|
|
|
|
- $addPrice = $data['addPrice']??0;
|
|
|
|
|
- $weight = $data['weight']??0;
|
|
|
|
|
- $cost = $data['cost']??0; //成本价
|
|
|
|
|
- if($stockWarning < 0 ){
|
|
|
|
|
|
|
+ $id = $data['id'] ?? 0;
|
|
|
|
|
+ $stockWarning = $data['stockWarning'] ?? 0;
|
|
|
|
|
+ $addPrice = $data['addPrice'] ?? 0;
|
|
|
|
|
+ $weight = $data['weight'] ?? 0;
|
|
|
|
|
+ $cost = $data['cost'] ?? 0; //成本价
|
|
|
|
|
+ if ($stockWarning < 0) {
|
|
|
util::fail("库存预警不能小于0");
|
|
util::fail("库存预警不能小于0");
|
|
|
}
|
|
}
|
|
|
- if($addPrice < 0 ){
|
|
|
|
|
|
|
+ if ($addPrice < 0) {
|
|
|
util::fail("每扎加价不能小于0");
|
|
util::fail("每扎加价不能小于0");
|
|
|
}
|
|
}
|
|
|
- if($weight < 0 ){
|
|
|
|
|
|
|
+ if ($weight < 0) {
|
|
|
// util::fail("每扎重量不能小于0");
|
|
// util::fail("每扎重量不能小于0");
|
|
|
}
|
|
}
|
|
|
- if($cost < 0 ){
|
|
|
|
|
|
|
+ if ($cost < 0) {
|
|
|
util::fail("成本价不能小于0");
|
|
util::fail("成本价不能小于0");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$model = self::getById($id);
|
|
$model = self::getById($id);
|
|
|
- if(!$model){
|
|
|
|
|
|
|
+ if (!$model) {
|
|
|
util::fail("该花材不存在");
|
|
util::fail("该花材不存在");
|
|
|
}
|
|
}
|
|
|
- if($model['merchantId'] !== $data['merchantId']){
|
|
|
|
|
|
|
+ if ($model['merchantId'] !== $data['merchantId']) {
|
|
|
util::fail("参数错误");
|
|
util::fail("参数错误");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ItemClass::updateGshItem($id,$stockWarning,$addPrice,$weight,$cost);
|
|
|
|
|
|
|
+ ItemClass::updateGshItem($id, $stockWarning, $addPrice, $weight, $cost);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//删除花材,同时修改itemInfo 的状态值 delStatus = 1
|
|
//删除花材,同时修改itemInfo 的状态值 delStatus = 1
|
|
|
- public static function deleteGhsItem($id,$shopId,$sjId,$adminId)
|
|
|
|
|
|
|
+ public static function deleteGhsItem($id, $shopId, $sjId, $adminId)
|
|
|
{
|
|
{
|
|
|
$model = ItemClass::getById($id);
|
|
$model = ItemClass::getById($id);
|
|
|
- if(!$model){
|
|
|
|
|
|
|
+ if (!$model) {
|
|
|
util::fail("该花材不存在");
|
|
util::fail("该花材不存在");
|
|
|
}
|
|
}
|
|
|
- if($model['merchantId'] !== $sjId){
|
|
|
|
|
|
|
+ if ($model['merchantId'] !== $sjId) {
|
|
|
util::fail("参数错误");
|
|
util::fail("参数错误");
|
|
|
}
|
|
}
|
|
|
$connection = Yii::$app->db;
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
$transaction = $connection->beginTransaction();
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
ItemClass::deleteGhsItem($id);
|
|
ItemClass::deleteGhsItem($id);
|
|
|
$condition = [
|
|
$condition = [
|
|
|
- 'itemId'=>$model['itemId'],
|
|
|
|
|
- 'shopId'=>$shopId,
|
|
|
|
|
|
|
+ 'itemId' => $model['itemId'],
|
|
|
|
|
+ 'shopId' => $shopId,
|
|
|
];
|
|
];
|
|
|
- ProductClass::updateByCondition($condition,['delStatus'=>1,'adminId'=>$adminId]);
|
|
|
|
|
|
|
+ ProductClass::updateByCondition($condition, ['delStatus' => 1, 'adminId' => $adminId]);
|
|
|
$transaction->commit();
|
|
$transaction->commit();
|
|
|
- }catch (\Exception $exception){
|
|
|
|
|
|
|
+ } catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
$transaction->rollBack();
|
|
|
util::fail("操作失败");
|
|
util::fail("操作失败");
|
|
|
}
|
|
}
|
|
@@ -180,7 +182,41 @@ class ItemService extends BaseService
|
|
|
//获取所有的花材ID
|
|
//获取所有的花材ID
|
|
|
public static function getGhsItemIds($merchantId)
|
|
public static function getGhsItemIds($merchantId)
|
|
|
{
|
|
{
|
|
|
- $data = ItemClass::getGhsItemAll($merchantId,'classId,itemId');
|
|
|
|
|
|
|
+ $data = ItemClass::getGhsItemAll($merchantId, 'classId,itemId');
|
|
|
return $data;
|
|
return $data;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //初始化 花材 ghsItemClass, ghsItem ghsProduct linqh 2021.4.12
|
|
|
|
|
+ public static function initItem($sjId,$shopId)
|
|
|
|
|
+ {
|
|
|
|
|
+ //获取pt 的花材分类
|
|
|
|
|
+ $ptClass = PtItemClassClass::getAllList("*","");
|
|
|
|
|
+ foreach ($ptClass as $v){
|
|
|
|
|
+ $classId = $v['id'];
|
|
|
|
|
+ $className = $v['name'];
|
|
|
|
|
+ $inTurn = $v['inTurn'];
|
|
|
|
|
+ //根据classId 获取所有 ptItem
|
|
|
|
|
+ $ptItem = PtItemClass::getAllList("*",['classId'=>$classId]);
|
|
|
|
|
+ if($ptItem){
|
|
|
|
|
+ //写入ghsItemClass
|
|
|
|
|
+ $classData = [
|
|
|
|
|
+ 'merchantId'=>$sjId,
|
|
|
|
|
+ 'name'=>$className,
|
|
|
|
|
+ 'inTurn'=>$inTurn,
|
|
|
|
|
+ ];
|
|
|
|
|
+ $ghsItemClass = ItemClassClass::add($classData);
|
|
|
|
|
+ $ghsClassId = $ghsItemClass['id'];
|
|
|
|
|
+ foreach ($ptItem as $v){
|
|
|
|
|
+ unset($v['addTime']);
|
|
|
|
|
+ unset($v['updateTime']);
|
|
|
|
|
+ $itemData = $v;
|
|
|
|
|
+ $itemData['classId'] = $ghsClassId;
|
|
|
|
|
+ $itemData['merchantId'] = $sjId;
|
|
|
|
|
+ ItemClassClass::add($itemData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|