|
|
@@ -56,7 +56,7 @@ class ProductController extends BaseController
|
|
|
}
|
|
|
$where['shopId'] = $shopId;
|
|
|
|
|
|
- $itemInfoData = ProductClass::getAllByCondition($where,null,"*");
|
|
|
+ $itemInfoData = ProductClass::getAllByCondition($where, null, "*");
|
|
|
$itemInfoData = ProductClass::groupProductInfo($itemInfoData);
|
|
|
//常用的itemIds
|
|
|
$oftenItemIds = ProductClass::getOftenItemIds($shopId);
|
|
|
@@ -65,7 +65,7 @@ class ProductController extends BaseController
|
|
|
|
|
|
//dd($itemInfoData);
|
|
|
//组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
|
|
|
- $data = ProductService::assembleData($classIds, $itemIdsInfo,$itemInfoData, $oftenItemIds, $type);
|
|
|
+ $data = ProductService::assembleData($classIds, $itemIdsInfo, $itemInfoData, $oftenItemIds, $type);
|
|
|
|
|
|
util::success($data);
|
|
|
}
|
|
|
@@ -93,38 +93,28 @@ class ProductController extends BaseController
|
|
|
$where['shopId'] = $shopId;
|
|
|
|
|
|
$type = Yii::$app->request->get('type', '');
|
|
|
- $showPage = Yii::$app->request->get('showPage',0);
|
|
|
- if($showPage){
|
|
|
- $res = ProductClass::getList("*",$where,"inTurn desc");
|
|
|
- $data = $res['list'];
|
|
|
- }else{
|
|
|
- $data = ProductClass::getAllByCondition($where,"inTurn desc","*");
|
|
|
+ $showPage = Yii::$app->request->get('showPage', 0);
|
|
|
+ if ($showPage) {
|
|
|
+ $respond = ProductClass::getList("*", $where, "inTurn desc");
|
|
|
+ util::success($respond);
|
|
|
}
|
|
|
+ $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
|
|
|
|
|
|
$data = ProductClass::groupProductInfo($data);
|
|
|
if ($type == 'waring') {
|
|
|
//库存预警
|
|
|
$newData = [];
|
|
|
- foreach ($data as $v){
|
|
|
- if($v['stock'] <= $v['stockWarning']) {
|
|
|
+ foreach ($data as $v) {
|
|
|
+ if ($v['stock'] <= $v['stockWarning']) {
|
|
|
$newData[] = $v;
|
|
|
}
|
|
|
}
|
|
|
util::success(['list' => $newData]);
|
|
|
}
|
|
|
- if($showPage){
|
|
|
- $res['list'] = $data;
|
|
|
- util::success(['list' => $res]);
|
|
|
- }else{
|
|
|
- util::success(['list' => $data]);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ util::success(['list' => $data]);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//改价
|
|
|
public function actionChangePrice()
|
|
|
{
|
|
|
@@ -156,7 +146,7 @@ class ProductController extends BaseController
|
|
|
$price = bcadd($productData['cost'], $productData['addPrice'], 2);
|
|
|
ProductClass::changePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
|
|
|
}
|
|
|
- util::success(['price'=>$price]);
|
|
|
+ util::success(['price' => $price]);
|
|
|
}
|
|
|
|
|
|
//恢复自动调价
|
|
|
@@ -186,41 +176,41 @@ class ProductController extends BaseController
|
|
|
{
|
|
|
$productId = Yii::$app->request->post('productId', 0);
|
|
|
$addPrice = Yii::$app->request->post('addPrice', '');
|
|
|
- if($addPrice < 0 ){
|
|
|
+ if ($addPrice < 0) {
|
|
|
util::fail("加价不能小于0");
|
|
|
}
|
|
|
$productData = ProductClass::getProductData($productId, $this->shopId);
|
|
|
if (!$productData) {
|
|
|
util::fail("花材不存在");
|
|
|
}
|
|
|
- ProductClass::changeAddPrice($productId,$addPrice);
|
|
|
+ ProductClass::changeAddPrice($productId, $addPrice);
|
|
|
util::complete();
|
|
|
}
|
|
|
|
|
|
//批量修改product 排序,成本价,加价
|
|
|
public function actionBatchUpdate()
|
|
|
{
|
|
|
- $data = Yii::$app->request->post('data',''); //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
|
|
|
- $type = Yii::$app->request->post('type','');
|
|
|
- if(empty($data) || empty($type)){
|
|
|
+ $data = Yii::$app->request->post('data', ''); //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
|
|
|
+ $type = Yii::$app->request->post('type', '');
|
|
|
+ if (empty($data) || empty($type)) {
|
|
|
util::fail("参数错误");
|
|
|
}
|
|
|
- if(in_array($type,['inTurn','addPrice','cost','weight','ratio']))
|
|
|
- $data = json_decode($data,true);
|
|
|
- foreach ($data as $v){
|
|
|
+ if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
|
|
|
+ $data = json_decode($data, true);
|
|
|
+ foreach ($data as $v) {
|
|
|
$id = $v['id'];
|
|
|
- $val = $v[$type]??'';
|
|
|
+ $val = $v[$type] ?? '';
|
|
|
$where = [];
|
|
|
$where['id'] = $id;
|
|
|
$where['shopId'] = $this->shopId;
|
|
|
$where['merchantId'] = $this->sjId;
|
|
|
- if(empty($val)){
|
|
|
+ if (empty($val)) {
|
|
|
util::fail("参数错误1");
|
|
|
}
|
|
|
- $data =[
|
|
|
- $type=>$val
|
|
|
+ $data = [
|
|
|
+ $type => $val
|
|
|
];
|
|
|
- ProductClass::updateByCondition($where,$data);
|
|
|
+ ProductClass::updateByCondition($where, $data);
|
|
|
}
|
|
|
util::complete();
|
|
|
}
|