123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?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\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\db\exception\DbException
- */
- public function lst(Request $request)
- {
- list($page, $limit, $money_type) = UtilService::getMore([
- ['page', 0],
- ['limit', 0],
- ['money_type', ''],
- ], $request, true);
- $seckillInfo = StoreExchange::exchangeList($money_type, $page, $limit);
- if (count($seckillInfo)) {
- foreach ($seckillInfo as $key => &$item) {
- if ($item['quota'] > 0) {
- $quota = StoreProductAttrValue::where('product_id', $item['id'])->where('type', 4)->value('SUM(quota)');
- $percent = (int)bcmul(bcdiv(bcsub($item['quota'], $quota), $item['quota'], 2), 100, 0);
- $item['percent'] = $percent;
- $item['stock'] = $quota;
- $item['money_type'] = get_money_name($item['money_type']);
- } else {
- $item['percent'] = 100;
- $item['stock'] = 0;
- $item['money_type'] = get_money_name($item['money_type']);
- }
- }
- }
- return app('json')->successful($seckillInfo);
- }
- /**
- * 秒杀产品详情
- * @param Request $request
- * @param $id
- * @return mixed
- */
- public function detail(Request $request, $id)
- {
- 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 . '_exchange_detail_wap.jpg', '/activity/exchange_detail/' . $id);
- $uid = $request->uid();
- $storeInfo['uid'] = $uid;
- $storeInfo['money_type'] = get_money_name($storeInfo['money_type']);
- $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id, 4));
- $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, 4);
- 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');
- $productValue[$k]['money_type_name'] = get_money_name($productValue[$k]['money_type']);
- }
- $data['productAttr'] = $productAttr;
- $data['productValue'] = $productValue;
- return app('json')->successful($data);
- }
- }
|