IntegralController.php 3.2 KB

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