IndexController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\integral\controllers\client;
  8. use app\cyy\BaseApiResponse;
  9. use app\models\AccountLog;
  10. use app\models\Coupon;
  11. use app\models\Goods;
  12. use app\models\SaasIntegralCat;
  13. use app\models\User;
  14. use app\plugins\integral\controllers\BaseController;
  15. use app\plugins\integral\models\client\IndexForm;
  16. use app\plugins\integral\models\client\QrcodeForm;
  17. use app\plugins\integral\models\form\GoodsForm;
  18. use app\plugins\integral\models\SaasIntegralGoods;
  19. use yii\base\BaseObject;
  20. use yii\data\Pagination;
  21. class IndexController extends BaseController
  22. {
  23. /**
  24. * 积分商品列表
  25. * @return array
  26. */
  27. public function actionGoodsList() {
  28. $cat_id = get_params('cat_id');
  29. $page = get_params('page', 1);
  30. $limit = get_params('limit', 10);
  31. $query = SaasIntegralGoods::find()->alias('ig')->where(['ig.is_delete' => 0, 'ig.status' => 1, 'ig.store_id' => get_store_id()])->leftJoin(['g' => Goods::tableName()],'g.id=ig.goods_id');;
  32. if ($cat_id > 0) {
  33. $query->andWhere(['ig.cat_id' => $cat_id]);
  34. }
  35. $count = $query->count();
  36. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  37. $list = $query->select(['ig.*'])->limit($pagination->limit)
  38. ->offset($pagination->offset)
  39. ->asArray()->orderBy(['ig.sort' => SORT_ASC, 'ig.created_at' => SORT_DESC])->all();
  40. foreach ($list as &$val) {
  41. $attr = json_decode($val['attr'], true);
  42. $count = count($attr);
  43. $str = '';
  44. foreach ($attr as $key => &$value) {
  45. $attr_group = GoodsForm::getAttrGroupByAttId($value['attr_id']);
  46. $t = $value['attr_name'];
  47. unset($value['attr_name']);
  48. $value['attr_group_name'] = $attr_group ? $attr_group->attr_group_name : null;
  49. $value['attr_name'] = $t;
  50. $str .= $value['attr_group_name'] . ':' . $t;
  51. if ($key < $count - 1) {
  52. $str .= ',';
  53. }
  54. }
  55. $val['attr_str'] = $str;
  56. $val['cat_name'] = SaasIntegralCat::findOne($val['cat_id'])->name;
  57. $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
  58. $val['goods'] = SaasIntegralGoods::getGoods($val['goods_id']);
  59. }
  60. $cat = [];
  61. $store_integral_cat = SaasIntegralCat::find()->where(['store_id' => get_store_id(), 'is_delete' => SaasIntegralCat::DELETE_STATUS_FALSE,
  62. 'is_enable' => SaasIntegralCat::IS_ENABLE_TRUE])->asArray()->all();
  63. if ($store_integral_cat) {
  64. foreach ($store_integral_cat as $c) {
  65. $integral_cat_goods = SaasIntegralGoods::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'status' => 1, 'cat_id' => $c['id']])->asArray()->all();
  66. if (!empty($integral_cat_goods)) {
  67. $cat[] = $c;
  68. }
  69. }
  70. }
  71. return [
  72. 'code' => 0,
  73. 'msg' => 'success',
  74. 'data' => [
  75. 'cat' => $cat,
  76. 'row_count' => $count,
  77. 'page_count' => $pagination->pageCount,
  78. 'list' => $list,
  79. 'coupon' => Coupon::getList(),
  80. 'integral' => get_user()->integral
  81. ]
  82. ];
  83. }
  84. /**
  85. * 商品详情
  86. * @return array
  87. */
  88. public function actionDetail() {
  89. $form = new IndexForm();
  90. $form->id = get_params('id');
  91. $form->store_id = get_store_id();
  92. return $form->getGoodsDetail();
  93. }
  94. /**
  95. * 积分兑换
  96. * @return array
  97. */
  98. public function actionPay() {
  99. $form = new IndexForm();
  100. $form->id = post_params('id');
  101. $form->store_id = get_store_id();
  102. $form->user = get_saas_user();
  103. return $form->pay();
  104. }
  105. /**
  106. * 积分兑换
  107. * @return array
  108. */
  109. public function actionRecord() {
  110. return [
  111. 'code' => 0,
  112. 'msg' => 'success',
  113. 'data' => AccountLog::find()->where(['user_id' => get_user_id(), 'type' => AccountLog::TYPE_INTEGRAL])->orderBy('created_at desc')->asArray()->all()
  114. ];
  115. }
  116. /**
  117. * 积分兑换
  118. * @return array
  119. */
  120. public function actionUserRecord() {
  121. $query = AccountLog::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'type' => AccountLog::TYPE_INTEGRAL])->orderBy('created_at desc');
  122. if (get_params('type') != 0) {
  123. $query->andWhere(['log_type' => get_params('type')])->asArray()->all();
  124. }
  125. $list = $query->asArray()->all();
  126. return [
  127. 'code' => 0,
  128. 'msg' => 'success',
  129. 'data' => $list
  130. ];
  131. }
  132. public function actionGetQrcode()
  133. {
  134. $form = new QrcodeForm();
  135. $user_id = get_user_id();
  136. $form->page = "user/clerk/integralList";
  137. $form->width = 100;
  138. $form->scene = "{$user_id}";
  139. return $form->getQrcode();
  140. }
  141. }