| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * Created by PhpStorm
- * Author: 向往那片天空
- * Date: 2020/6/11
- * Time: 10:32
- * 微信/QQ: 250023777
- * 格言: 抓住中心,宁精勿杂,宁专勿多
- */
- namespace app\api\controller\activity;
- use app\admin\model\store\StoreDescription;
- use app\admin\model\store\StoreProductAttrValue;
- use app\models\store\StoreActivity;
- use app\models\store\StoreOrder;
- use app\models\store\StoreProductAttr;
- use app\models\store\StoreProductRelation;
- use app\Request;
- use crmeb\services\QrcodeService;
- use crmeb\services\UtilService;
- use app\models\store\StoreActivityProduct as StoreActivityProductModel;
- use app\models\store\StoreLiveProduct as StoreLiveProductModel;
- /**
- * 直播商品控制器
- * Class StoreActivityProduct
- * @package app\api\controller\activity
- */
- class StoreLiveProduct
- {
- /**
- * 活动商品列表
- * @param Request $request
- * @return mixed
- */
- public function lst(Request $request)
- {
- list($title, $page, $limit) = UtilService::getMore([
- ['title', ''],
- ['page', 1],
- ['limit', 10],
- ], $request, true);
- $combinationList = StoreLiveProductModel::getAll($title, $page, $limit);
- if (!count($combinationList)) return app('json')->successful([]);
- return app('json')->successful($combinationList->hidden(['info', 'product_id', 'start_time', 'stop_time', 'effective_time', 'images', 'mer_id', 'attr', 'sort', 'stock', 'add_time', 'is_del', 'is_show', 'browse', 'cost', 'is_show', 'postage', 'is_postage', 'is_host', 'mer_use', 'combination'])->toArray());
- }
- /**
- * 活动商品详情
- * @param Request $request
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function detail(Request $request, $id)
- {
- if (!$id || !($combinationOne = StoreLiveProductModel::getLiveOne($id))) return app('json')->fail('活动商品不存在或已下架');
- // echo 'ok';die;
- $combinationOne = $combinationOne->hidden(['mer_id', 'attr', 'sort', 'start_time', 'stop_time', 'effective_time', 'add_time', 'is_host', 'is_show', 'is_del', 'mer_use', 'cost', 'combination'])->toArray();
- $combinationOne['images'] = json_decode($combinationOne['images'], true);
- $siteUrl = sys_config('site_url');
- $combinationOne['image'] = set_file_url($combinationOne['image'], $siteUrl);
- $combinationOne['image_base'] = set_file_url($combinationOne['image'], $siteUrl);
- $combinationOne['code_base'] = QrcodeService::getWechatQrcodePath($id . '_activity_detail_wap.jpg', '/activity/group_detail/' . $id);
- $combinationOne['sale_stock'] = 0;
- if ($combinationOne['stock'] > 0) $combinationOne['sale_stock'] = 1;
- if (!strlen(trim($combinationOne['unit_name']))) $combinationOne['unit_name'] = '个';
- $uid = $request->uid();
- $combinationOne['userCollect'] = StoreProductRelation::isProductRelation($combinationOne['id'], $uid, 'collect', 'activity');
- $combinationOne['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id, 5));
- $data['storeInfo'] = $combinationOne;
- // $data['reply'] = StoreProductReply::getRecProductReply($combinationOne['product_id']);
- // $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $combinationOne['product_id'])->count();
- // if ($data['replyCount']) {
- // $goodReply = StoreProductReply::productValidWhere()->where('product_id', $combinationOne['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', $combinationOne['product_id'])->where('type', 5)->where('suk', $v['suk'])->value('stock');
- }
- $data['productAttr'] = $productAttr;
- $data['productValue'] = $productValue;
- return app('json')->successful($data);
- }
- }
|