Kirin 4 rokov pred
rodič
commit
afadc1a726

+ 101 - 0
app/api/controller/activity/StoreExchangeController.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace app\api\controller\activity;
+
+use app\admin\model\store\StoreDescription;
+use app\admin\model\store\StoreProductAttrValue;
+use app\models\store\StoreExchange;
+use app\models\store\StoreIntegral;
+use app\models\store\StoreProductAttr;
+use app\models\store\StoreProductRelation;
+use app\models\store\StoreProductReply;
+
+//use app\models\store\StoreSeckill;
+use app\models\store\StoreVisit;
+use app\Request;
+use crmeb\services\GroupDataService;
+use crmeb\services\QrcodeService;
+use crmeb\services\UtilService;
+
+/**
+ * 秒杀产品类
+ * Class StoreSeckillController
+ * @package app\api\controller\activity
+ */
+class StoreExchangeController
+{
+    /**
+     * 积分产品列表
+     * @param Request $request
+     * @param $time
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function lst(Request $request)
+    {
+        list($page, $limit) = UtilService::getMore([
+            ['page', 0],
+            ['limit', 0],
+        ], $request, true);
+//        var_dump(111);
+        $seckillInfo = StoreExchange::seckillList($page, $limit);
+        if (count($seckillInfo)) {
+            foreach ($seckillInfo as $key => &$item) {
+                if ($item['quota'] > 0) {
+                    $quota = StoreProductAttrValue::where('product_id', $item['id'])->where('type', 5)->value('SUM(quota)');
+                    $percent = (int)bcmul(bcdiv(bcsub($item['quota'], $quota), $item['quota'], 2), 100, 0);
+                    $item['percent'] = $percent;
+                    $item['stock'] = $quota;
+                } else {
+                    $item['percent'] = 100;
+                    $item['stock'] = 0;
+                }
+
+            }
+        }
+        return app('json')->successful($seckillInfo);
+    }
+
+    /**
+     * 秒杀产品详情
+     * @param Request $request
+     * @param $id
+     * @return mixed
+     */
+    public function detail(Request $request, $id, $time = 0)
+    {
+        if (!$id || !($storeInfo = StoreExchange::getValidProduct($id))) return app('json')->fail('商品不存在或已下架!');
+        $storeInfo = $storeInfo->hidden(['cost', 'add_time', 'is_del'])->toArray();
+        $siteUrl = sys_config('site_url');
+        $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
+        $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
+        $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_seckill_detail_wap.jpg', '/activity/seckill_detail/' . $id . '/' . $time);
+        $uid = $request->uid();
+        $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like', 'product_seckill');
+        $storeInfo['like_num'] = StoreProductRelation::productRelationNum($id, 'like', 'product_seckill');
+        $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($storeInfo['product_id'], $uid, 'collect');
+        $storeInfo['uid'] = $uid;
+        $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id, 5));
+        $data['storeInfo'] = $storeInfo;
+        StoreVisit::setView($uid, $id, $storeInfo['product_id'], 'viwe');
+        $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['product_id']);
+        $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['product_id'])->count();
+        if ($data['replyCount']) {
+            $goodReply = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['product_id'])->where('product_score', 5)->count();
+            $data['replyChance'] = $goodReply;
+            if ($goodReply) {
+                $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2);
+                $data['replyChance'] = bcmul($data['replyChance'], 100, 3);
+            }
+        } else $data['replyChance'] = 0;
+        list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, 0, 5);
+        foreach ($productValue as $k => $v) {
+            $productValue[$k]['product_stock'] = StoreProductAttrValue::where('product_id', $storeInfo['product_id'])->where('suk', $v['suk'])->where('type', 0)->value('stock');
+        }
+        $data['productAttr'] = $productAttr;
+        $data['productValue'] = $productValue;
+        return app('json')->successful($data);
+    }
+}