| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace hd\controllers;
- use bizHd\goods\classes\GoodsClass;
- use bizHd\goods\services\CategoryService;
- use bizHd\goods\services\GoodsCategoryService;
- use bizHd\goods\services\GoodsSettingService;
- use biz\sj\services\MerchantAssetService;
- use bizHd\saas\services\FestRiseService;
- use Yii;
- use common\components\util;
- use bizHd\goods\services\GoodsService;
- use yii\web\Controller;
- class GoodsController extends BaseController
- {
- public $guestAccessAction = ['detail'];
- //商品列表 shish 2019.12.7
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $status = isset($get['status']) ? $get['status'] : -1;
- $goodsName = isset($get['goodsName']) && !empty($get['goodsName']) ? $get['goodsName'] : '';
- $where = [];
- if ($status != -1) {
- $where['status'] = $status;
- }
- if (!empty($goodsName)) {
- $where['goodsName'] = ['like', $goodsName];
- }
- if (isset($get['cId']) && $get['cId'] != -1) {
- $where['cId'] = $get['cId'];
- }
- $where['merchantId'] = $this->sjId;
- $where['delStatus'] = 0;
- $data = GoodsService::getGoodsList($where);
- $asset = MerchantAssetService::getByMerchantId($this->sjId);
- $data['MerchantAsset'] = $asset;
- util::success($data);
- }
- //添加商品 shish 2019.12.7
- public function actionAdd()
- {
- $data = Yii::$app->request->post();
- $data['merchantId'] = $this->sjId;
- $return = GoodsService::addGoods($data);
- $id = $return['id'];
- $info = GoodsService::getById($id);
- util::success($info);
- }
- //获取商品详情 shish 2019.12.7
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id');
- $goods = GoodsService::getGoodsInfo($id);
- GoodsClass::valid($goods, $this->sjId);
- util::success($goods);
- }
- //更新商品 shish 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->sjId);
- $data['merchantId'] = $this->sjId;
- GoodsService::updateGoods($id, $data);
- util::complete();
- }
- //商品排序 shish 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->sjId);
- if ($cId != 0) {
- //验证分类
- $category = CategoryService::getById($cId);
- CategoryService::valid($category, $this->sjId);
- GoodsCategoryService::updateByCondition(['cId' => $cId, 'gId' => $id], ['inTurn' => $inTurn]);
- } else {
- GoodsService::updateById($id, ['inTurn' => $inTurn]);
- GoodsCategoryService::updateByCondition(['gId' => $id], ['inTurn' => $inTurn]);
- }
- util::complete('操作成功');
- }
- //删除商品 shish 2019.12.7
- public function actionDelete()
- {
- $id = Yii::$app->request->get('id', 0);
- $goods = GoodsService::getById($id);
- GoodsService::valid($goods, $this->sjId);
- GoodsService::deleteGoods($goods);
- util::complete();
- }
- //上下架 shish 2019.12.8
- public function actionChangeStatus()
- {
- $post = Yii::$app->request->post();
- $id = isset($post['id']) ? $post['id'] : 0;
- $status = isset($post['status']) ? $post['status'] : 1;
- $info = GoodsService::getById($id);
- GoodsService::valid($info, $this->sjId);
- GoodsService::changeStatus($id, $status);
- util::complete();
- }
- //发送短链接到手机上 shish 2019.12.8
- public function actionSendShortUrl()
- {
- $id = Yii::$app->request->get('id');
- util::complete();
- }
- //查看商品短链接 shish 2019.12.8
- public function actionShortUrl()
- {
- $id = Yii::$app->request->get('id');
- util::success(['shortUrl' => 'https://w.url.cn/s/A8iQl2r']);
- }
- //商品说明 shish 2019.12.8
- public function actionIntroduce()
- {
- $set = GoodsSettingService::getByCondition(['merchantId' => $this->sjId]);
- $introduce = $set['goodsIntroduce'];
- util::success(['introduce' => $introduce]);
- }
- //修改商品说明 shish 2019.12.8
- public function actionUpdateIntroduce()
- {
- $introduce = Yii::$app->request->post('introduce', '');
- GoodsSettingService::updateByCondition(['merchantId' => $this->sjId], ['goodsIntroduce' => $introduce]);
- util::complete('提交成功');
- }
- //设置 shish 2019.12.8
- public function actionSetting()
- {
- $return = GoodsSettingService::getSetting($this->sjId);
- util::success($return);
- }
- //更新涨价 shish 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(['merchantId' => $this->sjId]);
- $add = [];
- foreach ($festIdList as $festId) {
- $add[] = ['merchantId' => $this->sjId, 'festId' => $festId];
- }
- FestRiseService::batchAdd($add);
- }
- GoodsSettingService::updateByCondition(['merchantId' => $this->sjId], $post);
- util::complete('提交成功');
- }
- //获取商品详情 shish 2019.12.3
- public function actionMallDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $info = GoodsService::getGoodsInfo($id);
- GoodsService::valid($info, $this->sjId);
- $setting = GoodsSettingService::getByCondition(['merchantId' => $this->sjId]);
- $commonIntro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
- $info['commonIntro'] = $commonIntro;
- util::success($info);
- }
- }
|