RecommendController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace backend\controllers;
  3. use common\models\xhUnionUser;
  4. use common\services\xhGoodsService;
  5. use common\components\util;
  6. use Yii;
  7. use yii\web\Controller;
  8. use yii\filters\AccessControl;
  9. use common\models\xhGoods;
  10. use common\models\xhRecommend;
  11. use common\services\xhRecommendService;
  12. use yii\helpers\Json;
  13. class RecommendController extends BackendController
  14. {
  15. public function actionGoods()
  16. {
  17. $recommendGoods = xhRecommendService::getGoodsList($this->merchantId);
  18. return $this->render('goods',['recommend' => $recommendGoods]);
  19. }
  20. /**
  21. * 将商品推荐到首页
  22. */
  23. public function actionPutGoodsToIndex()
  24. {
  25. $get = Yii::$app->request->get();
  26. $id = isset($get['id']) ? $get['id'] : 0;
  27. $goods = xhGoodsService::getById($id);
  28. if($goods['merchantId'] != $this->merchantId){
  29. util::failInfo();
  30. }
  31. $recommend = xhRecommendService::getByMerchantId($this->merchantId);
  32. $goods = $recommend['goods'];
  33. $arr = explode(',',$goods);
  34. $goodsUnique = array_filter($arr);
  35. if(count($goodsUnique) > 4){
  36. util::failInfo('最多只能推荐5个');
  37. }
  38. $goodsUnique[] = $id;
  39. $unique = array_unique($goodsUnique);
  40. xhRecommendService::updateByMerchantId($this->merchantId, ['goods' =>implode(',',$unique)]);
  41. util::successInfo('推荐成功');
  42. }
  43. public function actionDelIndexGoods()
  44. {
  45. $get = Yii::$app->request->get();
  46. $id = isset($get['id']) ? $get['id'] : 0;
  47. $goods = xhGoodsService::getById($id);
  48. if($goods['merchantId'] != $this->merchantId){
  49. util::failInfo();
  50. }
  51. xhRecommendService::wipeGoodsId($id, $this->merchantId);
  52. util::successInfo('删除成功');
  53. }
  54. }