| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\integral\controllers\client;
- use app\cyy\BaseApiResponse;
- use app\models\AccountLog;
- use app\models\Coupon;
- use app\models\Goods;
- use app\models\SaasIntegralCat;
- use app\models\User;
- use app\plugins\integral\controllers\BaseController;
- use app\plugins\integral\models\client\IndexForm;
- use app\plugins\integral\models\client\QrcodeForm;
- use app\plugins\integral\models\form\GoodsForm;
- use app\plugins\integral\models\SaasIntegralGoods;
- use yii\base\BaseObject;
- use yii\data\Pagination;
- class IndexController extends BaseController
- {
- /**
- * 积分商品列表
- * @return array
- */
- public function actionGoodsList() {
- $cat_id = get_params('cat_id');
- $page = get_params('page', 1);
- $limit = get_params('limit', 10);
- $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');;
- if ($cat_id > 0) {
- $query->andWhere(['ig.cat_id' => $cat_id]);
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select(['ig.*'])->limit($pagination->limit)
- ->offset($pagination->offset)
- ->asArray()->orderBy(['ig.sort' => SORT_ASC, 'ig.created_at' => SORT_DESC])->all();
- foreach ($list as &$val) {
- $attr = json_decode($val['attr'], true);
- $count = count($attr);
- $str = '';
- foreach ($attr as $key => &$value) {
- $attr_group = GoodsForm::getAttrGroupByAttId($value['attr_id']);
- $t = $value['attr_name'];
- unset($value['attr_name']);
- $value['attr_group_name'] = $attr_group ? $attr_group->attr_group_name : null;
- $value['attr_name'] = $t;
- $str .= $value['attr_group_name'] . ':' . $t;
- if ($key < $count - 1) {
- $str .= ',';
- }
- }
- $val['attr_str'] = $str;
- $val['cat_name'] = SaasIntegralCat::findOne($val['cat_id'])->name;
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- $val['goods'] = SaasIntegralGoods::getGoods($val['goods_id']);
- }
- $cat = [];
- $store_integral_cat = SaasIntegralCat::find()->where(['store_id' => get_store_id(), 'is_delete' => SaasIntegralCat::DELETE_STATUS_FALSE,
- 'is_enable' => SaasIntegralCat::IS_ENABLE_TRUE])->asArray()->all();
- if ($store_integral_cat) {
- foreach ($store_integral_cat as $c) {
- $integral_cat_goods = SaasIntegralGoods::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'status' => 1, 'cat_id' => $c['id']])->asArray()->all();
- if (!empty($integral_cat_goods)) {
- $cat[] = $c;
- }
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'cat' => $cat,
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list,
- 'coupon' => Coupon::getList(),
- 'integral' => get_user()->integral
- ]
- ];
- }
- /**
- * 商品详情
- * @return array
- */
- public function actionDetail() {
- $form = new IndexForm();
- $form->id = get_params('id');
- $form->store_id = get_store_id();
- return $form->getGoodsDetail();
- }
- /**
- * 积分兑换
- * @return array
- */
- public function actionPay() {
- $form = new IndexForm();
- $form->id = post_params('id');
- $form->store_id = get_store_id();
- $form->user = get_saas_user();
- return $form->pay();
- }
- /**
- * 积分兑换
- * @return array
- */
- public function actionRecord() {
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => AccountLog::find()->where(['user_id' => get_user_id(), 'type' => AccountLog::TYPE_INTEGRAL])->orderBy('created_at desc')->asArray()->all()
- ];
- }
- /**
- * 积分兑换
- * @return array
- */
- public function actionUserRecord() {
- $query = AccountLog::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'type' => AccountLog::TYPE_INTEGRAL])->orderBy('created_at desc');
- if (get_params('type') != 0) {
- $query->andWhere(['log_type' => get_params('type')])->asArray()->all();
- }
- $list = $query->asArray()->all();
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list
- ];
- }
- public function actionGetQrcode()
- {
- $form = new QrcodeForm();
- $user_id = get_user_id();
- $form->page = "user/clerk/integralList";
- $form->width = 100;
- $form->scene = "{$user_id}";
- return $form->getQrcode();
- }
- }
|