IntegralController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\models\NewIntegralCat;
  9. use app\models\NewIntegralSetting;
  10. use app\models\Goods;
  11. use app\models\GoodsCat;
  12. use app\modules\client\controllers\BaseController;
  13. class IntegralController extends BaseController
  14. {
  15. //积分商城信息
  16. public function actionIndex(){
  17. $store_id = get_store_id();
  18. $settingInfo = NewIntegralSetting::find()->where(['store_id'=>$store_id])->asArray()->one();
  19. $catInfo = NewIntegralCat::find()->where(['store_id'=>$store_id,'is_enable'=>1,'is_delete'=>0])->select('id,name')->orderBy('sort')->asArray()->all();
  20. $data = [];
  21. $data['polling'] = (isset($settingInfo['polling_img']) && $settingInfo['polling_img']) ? json_decode($settingInfo['polling_img'],true) : null;
  22. $data['explain'] = (isset($settingInfo['explain']) && $settingInfo['explain']) ? $settingInfo['explain'] : null;
  23. $data['catInfo'] = $catInfo;
  24. $data['integral'] = get_user()->integral;
  25. return $this->asJson([
  26. 'code' => 0,
  27. 'msg' => 'success',
  28. 'data' => $data
  29. ]);
  30. }
  31. //商品列表
  32. public function actionGoodsInfo(){
  33. $store_id = get_store_id();
  34. $level = get_params('level',0);
  35. $catId = get_params('cat_id',0);
  36. $query = Goods::find()->alias('g')->where(['g.store_id'=>$store_id,'g.product_type'=>Goods::GOODS_TYPE_INTEGRAL, 'g.status' => 1, 'g.is_delete' => 0]);
  37. if($level == 1){
  38. $query->andWhere(['<=','g.integral_price',100]);
  39. }
  40. if($level == 2){
  41. $query->andWhere(['>','g.integral_price',100]);
  42. $query->andWhere(['<=','g.integral_price',500]);
  43. }
  44. if($level == 3){
  45. $query->andWhere(['>','g.integral_price',500]);
  46. $query->andWhere(['<=','g.integral_price',1000]);
  47. }
  48. if($level == 4){
  49. $query->andWhere(['>','g.integral_price',1000]);
  50. }
  51. if($catId){
  52. $query->leftJoin(['gc' => GoodsCat::tableName()], 'gc.goods_id=g.id')->andWhere(['gc.cat_id' => $catId]);
  53. }
  54. $query->select('g.id,g.name,g.price,g.original_price,g.integral_price,g.cover_pic,g.virtual_sales')->orderBy('g.sort DESC');
  55. $list = pagination_make($query);
  56. return $this->asJson([
  57. 'code' => 0,
  58. 'msg' => 'success',
  59. 'data' => [
  60. 'data' => $list['list'],
  61. 'pageNo' => $list['pageNo'],
  62. 'totalCount' => $list['totalCount'],
  63. ]
  64. ]);
  65. }
  66. }