| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace backend\controllers;
- use common\models\xhUnionUser;
- use common\services\xhGoodsService;
- use common\components\util;
- use Yii;
- use yii\web\Controller;
- use yii\filters\AccessControl;
- use common\models\xhGoods;
- use common\models\xhRecommend;
- use common\services\xhRecommendService;
- use yii\helpers\Json;
- class RecommendController extends BackendController
- {
- public function actionGoods()
- {
- $recommendGoods = xhRecommendService::getGoodsList($this->merchantId);
- return $this->render('goods',['recommend' => $recommendGoods]);
- }
- /**
- * 将商品推荐到首页
- */
- public function actionPutGoodsToIndex()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $goods = xhGoodsService::getById($id);
- if($goods['merchantId'] != $this->merchantId){
- util::failInfo();
- }
- $recommend = xhRecommendService::getByMerchantId($this->merchantId);
- $goods = $recommend['goods'];
- $arr = explode(',',$goods);
- $goodsUnique = array_filter($arr);
- if(count($goodsUnique) > 4){
- util::failInfo('最多只能推荐5个');
- }
- $goodsUnique[] = $id;
- $unique = array_unique($goodsUnique);
- xhRecommendService::updateByMerchantId($this->merchantId, ['goods' =>implode(',',$unique)]);
- util::successInfo('推荐成功');
- }
- public function actionDelIndexGoods()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $goods = xhGoodsService::getById($id);
- if($goods['merchantId'] != $this->merchantId){
- util::failInfo();
- }
- xhRecommendService::wipeGoodsId($id, $this->merchantId);
- util::successInfo('删除成功');
- }
- }
|