|
|
@@ -15,20 +15,21 @@ use bizGhs\product\services\ProductService;
|
|
|
use bizGhs\item\services\ItemService;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
+
|
|
|
class ProductController extends BaseController
|
|
|
{
|
|
|
|
|
|
- public $guestAccessAction = ['index'];
|
|
|
+ public $guestAccessAction = ['index'];
|
|
|
|
|
|
//开单时获取所有的分类花材信息
|
|
|
//库存预警
|
|
|
public function actionIndex()
|
|
|
{
|
|
|
- $py = Yii::$app->request->get('py','');
|
|
|
- $type = Yii::$app->request->get('type','');
|
|
|
+ $py = Yii::$app->request->get('py', '');
|
|
|
+ $type = Yii::$app->request->get('type', '');
|
|
|
|
|
|
//访问店铺时用户增加最近访问的店铺 ssh 2021.3.1
|
|
|
- AdminClass::addRecentShop($this->lookShopId,$this->admin);
|
|
|
+ AdminClass::addRecentShop($this->lookShopId, $this->admin);
|
|
|
|
|
|
//获取所有当前供应商的分类 (全部、常用)
|
|
|
//根据分类组装分类下的花材信息
|
|
|
@@ -37,109 +38,117 @@ class ProductController extends BaseController
|
|
|
//获取供应商下所有花材ID (itemIds)
|
|
|
$itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
|
|
|
|
|
|
- $itemIds = array_column($itemIdsInfo,'itemId');
|
|
|
+ $itemIds = array_column($itemIdsInfo, 'itemId');
|
|
|
|
|
|
- if($py){
|
|
|
+ if ($py) {
|
|
|
$pyNameItemIds = ItemClass::getItemIdsByPyName($py);
|
|
|
- $itemIds = array_intersect($itemIds,$pyNameItemIds);
|
|
|
+ $itemIds = array_intersect($itemIds, $pyNameItemIds);
|
|
|
}
|
|
|
$shopId = $this->shopId;
|
|
|
//兼容客户根据门店下单
|
|
|
- if($this->lookShopId){
|
|
|
+ if ($this->lookShopId) {
|
|
|
$shopId = $this->lookShopId;
|
|
|
}
|
|
|
//库存预警
|
|
|
- if($type=='waring'){
|
|
|
+ if ($type == 'waring') {
|
|
|
//shopId 改为可以前端传,默认是当前shopId linqh 2021.1.26
|
|
|
- $shopId = Yii::$app->request->get('shopId',0);
|
|
|
- if(!$shopId){
|
|
|
+ $shopId = Yii::$app->request->get('shopId', 0);
|
|
|
+ if (!$shopId) {
|
|
|
$shopId = $this->shopId;
|
|
|
}
|
|
|
|
|
|
- $waringItemIds = ProductClass::getItemIdsWarning($this->sjId,$shopId);
|
|
|
- $itemIds = array_intersect($itemIds,$waringItemIds);
|
|
|
+ $waringItemIds = ProductClass::getItemIdsWarning($this->sjId, $shopId);
|
|
|
+ $itemIds = array_intersect($itemIds, $waringItemIds);
|
|
|
}
|
|
|
|
|
|
|
|
|
- $itemInfoData = ProductClass::getProductInfoByItemIds($itemIds,$shopId);
|
|
|
+ $itemInfoData = ProductClass::getProductInfoByItemIds($itemIds, $shopId);
|
|
|
|
|
|
//常用的itemIds
|
|
|
$oftenItemIds = ProductClass::getOftenItemIds($shopId);
|
|
|
|
|
|
//组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
|
|
|
- $data = ProductService::assembleData($classIds,$itemIdsInfo,$itemInfoData,$oftenItemIds,$type);
|
|
|
+ $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
|
|
|
|
|
|
util::success($data);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//弃用
|
|
|
public function actionList()
|
|
|
{
|
|
|
//$classId = Yii::$app->request->get('classId',0);
|
|
|
- $pyName = Yii::$app->request->get('py','');
|
|
|
+ $pyName = Yii::$app->request->get('py', '');
|
|
|
$itemInfo = ItemClass::getGhsItemAll($this->sjId);
|
|
|
- $itemIds = array_column($itemInfo,'itemId');
|
|
|
- if($pyName){
|
|
|
+ $itemIds = array_column($itemInfo, 'itemId');
|
|
|
+ if ($pyName) {
|
|
|
$pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
|
|
|
- $itemIds = array_intersect($itemIds,$pyNameItemIds);
|
|
|
+ $itemIds = array_intersect($itemIds, $pyNameItemIds);
|
|
|
}
|
|
|
- $shopId = Yii::$app->request->get('shopId',0);
|
|
|
- if(!$shopId){
|
|
|
+ $shopId = Yii::$app->request->get('shopId', 0);
|
|
|
+ if (!$shopId) {
|
|
|
$shopId = $this->shopId;
|
|
|
}
|
|
|
- $type = Yii::$app->request->get('type','');
|
|
|
- if($type=='waring'){
|
|
|
+ $type = Yii::$app->request->get('type', '');
|
|
|
+ if ($type == 'waring') {
|
|
|
//库存预警
|
|
|
- $waringItemIds = ProductClass::getItemIdsWarning($this->sjId,$shopId);
|
|
|
- $itemIds = array_intersect($itemIds,$waringItemIds);
|
|
|
+ $waringItemIds = ProductClass::getItemIdsWarning($this->sjId, $shopId);
|
|
|
+ $itemIds = array_intersect($itemIds, $waringItemIds);
|
|
|
}
|
|
|
- $data = ProductClass::getProductInfoByItemIds($itemIds,$shopId);
|
|
|
- util::success(['list'=>$data]);
|
|
|
+ $data = ProductClass::getProductInfoByItemIds($itemIds, $shopId);
|
|
|
+ util::success(['list' => $data]);
|
|
|
}
|
|
|
|
|
|
//改价
|
|
|
public function actionChangePrice()
|
|
|
{
|
|
|
-
|
|
|
- $productId = Yii::$app->request->post('productId',0);
|
|
|
- $price = Yii::$app->request->post('price');
|
|
|
-
|
|
|
- if(!is_numeric($price)){
|
|
|
- util::fail("请输入正确价格");
|
|
|
- }
|
|
|
- if($price <= 0 ){
|
|
|
- util::fail("价格不能小于0");
|
|
|
- }
|
|
|
-
|
|
|
- //判断是否有效
|
|
|
- $productData = ProductClass::getProductData($productId,$this->shopId);
|
|
|
- if(!$productData){
|
|
|
- util::fail("花材不存在");
|
|
|
+ $productId = Yii::$app->request->post('productId', 0);
|
|
|
+ $price = Yii::$app->request->post('price', '');
|
|
|
+ if (is_numeric($price) && $price > 0) {
|
|
|
+ //改价
|
|
|
+
|
|
|
+ //判断是否有效
|
|
|
+ $productData = ProductClass::getProductData($productId, $this->shopId);
|
|
|
+ if (!$productData) {
|
|
|
+ util::fail("花材不存在");
|
|
|
+ }
|
|
|
+ ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_CHANGE);
|
|
|
+ } else {
|
|
|
+ //自动调价
|
|
|
+ $productData = ProductClass::getById($productId);
|
|
|
+ if (!$productData) {
|
|
|
+ util::fail("花材不存在");
|
|
|
+ }
|
|
|
+ $itemId = $productData['itemId'];
|
|
|
+ //获取该花材的每扎成本价和每扎加价
|
|
|
+ //自动调价=每扎成本价+每扎加价
|
|
|
+ $itemData = ItemClass::getItemData($itemId, $this->sjId);
|
|
|
+ if (!$itemData) {
|
|
|
+ util::fail("出错拉");
|
|
|
+ }
|
|
|
+ $price = bcadd($itemData['unitCost'], $itemData['unitAddPrice'], 2);
|
|
|
+ ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
|
|
|
}
|
|
|
- ProductClass::changePrice($productId,$this->shopId,$price, ProductClass::PRICE_LABEL_CHANGE);
|
|
|
- util::complete("改价成功");
|
|
|
+ util::success(['price'=>$price]);
|
|
|
}
|
|
|
|
|
|
//恢复自动调价
|
|
|
public function actionAutoPrice()
|
|
|
{
|
|
|
- $productId = Yii::$app->request->post('productId',0);
|
|
|
+ $productId = Yii::$app->request->post('productId', 0);
|
|
|
$productData = ProductClass::getById($productId);
|
|
|
- if(!$productData){
|
|
|
+ if (!$productData) {
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
$itemId = $productData['itemId'];
|
|
|
//获取该花材的每扎成本价和每扎加价
|
|
|
//自动调价=每扎成本价+每扎加价
|
|
|
- $itemData = ItemClass::getItemData($itemId,$this->sjId);
|
|
|
- if(!$itemData){
|
|
|
+ $itemData = ItemClass::getItemData($itemId, $this->sjId);
|
|
|
+ if (!$itemData) {
|
|
|
util::fail("出错拉");
|
|
|
}
|
|
|
- $price = bcadd($itemData['unitCost'],$itemData['unitAddPrice'],2);
|
|
|
- ProductClass::changePrice($productId,$this->shopId,$price, ProductClass::PRICE_LABEL_AUTO);
|
|
|
+ $price = bcadd($itemData['unitCost'], $itemData['unitAddPrice'], 2);
|
|
|
+ ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
|
|
|
util::complete("操作成功");
|
|
|
}
|
|
|
|