IndexController.php 5.5 KB

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