request->get();
$id = $get['id'] ?? 0;
$num = $get['num'] ?? 1;
$info = GoodsClass::getById($id, true);
if (empty($info)) {
util::fail('没有找到商品');
}
$shopId = $this->shopId;
$ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
$printLabelSn = $ext->printLabelSn ?? '';
if (empty($printLabelSn)) {
util::fail('请设置标签打印机');
}
$p = new printUtil($printLabelSn);
$name = $info->name ?? '';
$goodsSn = $info->sn ?? '';
$flower = $info->flower ?? 0;
$price = floatval($info->price) ?? 0;
$content = '' . $name . '';
$content .= '' . $goodsSn . '';
if ($flower == 0 && $price > 0) {
$content .= '' . $price . '';
}
$p->times = $num;
$p->printLabelMsg($content);
util::complete();
}
//添加商品 ssh 2019.12.7
public function actionAdd()
{
$data = Yii::$app->request->post();
$data['sjId'] = $this->sjId;
$data['mainId'] = $this->mainId;
$data['shopId'] = $this->shopId ?? 0;
$data['property'] = 0;
$data['flower'] = 1;
$staff = $this->shopAdmin;
$data['staffName'] = $staff->name ?? '';
$return = GoodsClass::addGoods($data);
util::success($return);
}
//根据sn获取商品详情 ssh 20220505
public function actionGetBySn()
{
$sn = Yii::$app->request->get('sn');
$goods = GoodsClass::getByCondition(['sn' => $sn], true);
GoodsClass::valid($goods, $this->mainId);
util::success($goods);
}
//绿植盆栽采购 ssh 20220405
public function actionCgPlant()
{
$post = Yii::$app->request->post();
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
$post['mainId'] = $this->mainId ?? 0;
$post['sjId'] = $this->sjId ?? 0;
$post['shopId'] = $this->shopId ?? 0;
$staff = $this->shopAdmin ?? [];
$staffName = $staff->name ?? '';
$post['staffName'] = $staffName;
$post['staffId'] = $staff->id ?? 0;
$respond = GoodsClass::cgPlant($post, $this->shop);
$transaction->commit();
util::success($respond);
} catch (\Exception $e) {
$transaction->rollBack();
util::fail();
}
}
//商品列表 ssh 2019.12.7
public function actionList()
{
$get = Yii::$app->request->get();
$status = isset($get['status']) && is_numeric($get['status']) ? $get['status'] : -1;
$cId = isset($get['cId']) && !empty($get['cId']) ? $get['cId'] : 0;
$name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
$flowerNum = isset($get['flowerNum']) && $get['flowerNum'] > 0 ? $get['flowerNum'] : 0;
$flower = isset($get['flower']) ? $get['flower'] : '';
$hasStock = isset($get['hasStock']) ? $get['hasStock'] : 0;
$where = [];
if ($status != -1) {
$where['status'] = $status;
}
if (!empty($name)) {
$where['name'] = ['like', $name];
}
if (!empty($cId)) {
$where['cId'] = $cId;
}
$where['mainId'] = $this->mainId;
$where['delStatus'] = 0;
if ($flowerNum > 0) {
$where['flowerNum'] = $flowerNum;
}
if (is_numeric($flower)) {
$where['flower'] = $flower;
}
if ($hasStock == 1) {
$where['stock>'] = 0;
}
$data = GoodsService::getGoodsList($where);
util::success($data);
}
public function actionGetGoodsInfoList()
{
$get = Yii::$app->request->get();
$cId = isset($get['cId']) ? $get['cId'] : 0;
$flowerNum = isset($get['flowerNum']) ? $get['flowerNum'] : 0;
if(empty($cId)){
util::fail('分类不能为空');
}
$where = ['cId' => $cId];
$params = [];
if(!empty($flowerNum)){
$params['flowerNum'] = $flowerNum;
}
$data = GoodsClass::getGoodsData($where,$params);
util::success($data);
}
//获取商品详情 ssh 2019.12.7
public function actionDetail()
{
$id = Yii::$app->request->get('id');
$goods = GoodsClass::getGoodsInfo($id);
GoodsClass::valid($goods, $this->mainId);
util::success($goods);
}
//更新商品 ssh 2019.12.7
public function actionUpdate()
{
$data = Yii::$app->request->post();
$id = isset($data['id']) ? $data['id'] : 0;
$info = GoodsService::getById($id);
GoodsService::valid($info, $this->mainId);
$data['sjId'] = $this->sjId;
$data['mainId'] = $this->mainId;
$data['shopId'] = $this->shopId ?? 0;
$data['flower'] = $info['flower'] ?? 0;
if (isset($info['spu']) && !empty($info['spu'])) {
util::fail('美团商品暂时不能修改');
}
$staff = $this->shopAdmin;
$connection = Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
GoodsClass::updateGoods($info, $data, $staff);
$transaction->commit();
util::complete();
} catch (\Exception $e) {
$transaction->rollBack();
util::fail();
}
}
//商品排序 ssh 2020.3.11
public function actionSort()
{
$id = Yii::$app->request->get('id', 0);
$cId = Yii::$app->request->get('cId', 0);
$inTurn = Yii::$app->request->get('inTurn', 0);
//验证商品
$info = GoodsService::getById($id);
GoodsService::valid($info, $this->mainId);
if ($cId != 0) {
//验证分类
$category = CategoryService::getById($cId);
CategoryService::valid($category, $this->mainId);
GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
} else {
GoodsService::updateById($id, ['inTurn' => $inTurn]);
GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
}
util::complete('操作成功');
}
//删除商品 ssh 2019.12.7
public function actionDelete()
{
$id = Yii::$app->request->get('id', 0);
$goods = GoodsService::getById($id);
GoodsService::valid($goods, $this->mainId);
GoodsService::deleteGoods($goods);
util::complete();
}
//上下架 ssh 2019.12.8
public function actionChangeStatus()
{
$get = Yii::$app->request->get();
$id = isset($get['id']) ? $get['id'] : 0;
$status = isset($get['status']) ? $get['status'] : 1;
$info = GoodsService::getById($id);
GoodsService::valid($info, $this->mainId);
GoodsService::changeStatus($id, $status);
util::complete();
}
//商品说明 ssh 2019.12.8
public function actionIntroduce()
{
$set = GoodsSettingService::getByCondition(['mainId' => $this->mainId]);
$introduce = $set['goodsIntroduce'];
util::success(['introduce' => $introduce]);
}
//修改商品说明 ssh 2019.12.8
public function actionUpdateIntroduce()
{
$introduce = Yii::$app->request->post('introduce', '');
GoodsSettingService::updateByCondition(['mainId' => $this->mainId], ['goodsIntroduce' => $introduce]);
util::complete('提交成功');
}
//设置 ssh 2019.12.8
public function actionSetting()
{
$return = GoodsSettingService::getSetting($this->mainId);
util::success($return);
}
//更新涨价 ssh 2019.12.9
public function actionUpdateRise()
{
$post = Yii::$app->request->post();
$festIdList = isset($post['festIdList']) && !empty($post['festIdList']) ? $post['festIdList'] : [];
unset($post['festIdList']);
$riseSwitch = isset($post['riseSwitch']) && is_numeric($post['riseSwitch']) ? $post['riseSwitch'] : 1;
if ($riseSwitch == 1) {
if (empty($festIdList)) {
util::fail('请选择节日');
}
FestRiseService::deleteByCondition(['mainId' => $this->mainId]);
$add = [];
foreach ($festIdList as $festId) {
$add[] = ['mainId' => $this->mainId, 'festId' => $festId];
}
FestRiseService::batchAdd($add);
}
GoodsSettingService::updateByCondition(['mainId' => $this->mainId], $post);
util::complete('提交成功');
}
//获取商品详情 ssh 2019.12.3
public function actionMallDetail()
{
$id = Yii::$app->request->get('id', 0);
$info = GoodsClass::getGoodsInfo($id);
GoodsService::valid($info, $this->mainId);
$setting = GoodsSettingService::getByCondition(['mainId' => $this->mainId]);
$commonIntro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
$info['commonIntro'] = $commonIntro;
util::success($info);
}
public function actionIndex()
{
$catWhere = ['mainId' => $this->mainId];
$goodsWhere['mainId'] = $this->mainId;
$goodsWhere['delStatus'] = 0;
$classIds = CategoryService::getCategoryClassAll($catWhere);
$goodsData = GoodsCategoryService::getGoodsAll($goodsWhere);
$goodsCateData = GoodsCategoryService::getEnableGoodsCategory($this->mainId);
//组装数据 [{classId:'','className:'',child:[{itemInfoData}]}]
$data = GoodsCategoryService::assembleData($classIds, $goodsCateData, $goodsData);
util::success($data);
}
//保存花材组合 ssh 2021.4.10
public function actionSaveItemGroup()
{
$orderSn = Yii::$app->request->post('orderSn', '');
$name = Yii::$app->request->post('name', '');
$classId = Yii::$app->request->post('categoryId', 0);
if (empty($name)) {
util::fail("名称不能为空");
}
$cateExists = CategoryService::exists(['id' => $classId, 'mainId' => $this->mainId]);
if (!$cateExists) {
util::fail("分类不存在");
}
$itemInfo = OrderItemclass::getAllByCondition(['orderSn' => $orderSn], null, "*");
if (empty($itemInfo)) {
util::fail("订单不存在");
}
$order = OrderService::getOrderBySn($orderSn);
OrderService::valid($order, $this->shopId);
$save = GoodsService::saveItemGroup($order, $itemInfo, $classId, $name, $this->adminId);
if ($save) {
util::complete();
}
util::fail("保存失败");
}
}