123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- 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\models\user\User;
- use app\Request;
- use crmeb\services\QrcodeService;
- use crmeb\services\UtilService;
- use app\models\store\StoreTryProduct as StoreTryProductModel;
- use think\facade\Db;
- use app\models\store\StoreTryRecord as StoreTryRecordModel;
- class StoreTryProduct
- {
-
- public function lst(Request $request)
- {
- list($page, $limit) = UtilService::getMore([
- ['page', 1],
- ['limit', 10],
- ], $request, true);
- $combinationList = StoreTryProductModel::getAll($page, $limit);
- if (!count($combinationList)) return app('json')->successful([]);
- return app('json')->successful($combinationList->toArray());
- }
-
- public function detail(Request $request, $id)
- {
- if (!$id || !($combinationOne = StoreTryProductModel::getTryOne($id))) return app('json')->fail('试用商品不存在或已下架');
- $combinationOne = $combinationOne->toArray();
- $combinationOne['images'] = json_decode($combinationOne['slider_image'], 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 . '_try_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', 'try');
- $combinationOne['description'] = htmlspecialchars_decode(StoreDescription::getDescription($combinationOne['product_id'], 0));
- $data['storeInfo'] = $combinationOne;
- list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($combinationOne['product_id'], $uid, 0, 0);
- foreach ($productValue as $k => $v) {
- $productValue[$k]['product_stock'] = StoreProductAttrValue::where('product_id', $combinationOne['product_id'])->where('type', 0)->where('suk', $v['suk'])->value('stock');
- }
- $data['productAttr'] = $productAttr;
- $data['productValue'] = $productValue;
- $data['people_count'] = Db::name('store_try_record')->where("tid={$id} and is_del=0")->count();
- $data['is_apply'] = StoreTryRecordModel::be(['tid' => $id, 'uid' => $request->uid(), 'is_del' => 0]) ? 1 : 0;
- if ($combinationOne['is_finish']) {
- $users = StoreTryRecordModel::where("r.tid={$id} and r.is_check=1")->alias('r')->field('r.phone,u.avatar')->join('user u', 'u.uid=r.uid')->select()->toArray();
- foreach ($users as $k => &$v) {
- $v['phone'] = substr_replace($v['phone'], '****', 3, 4);
- }
- $data['win_people'] = $users;
- } else {
- $data['win_people'] = [];
- }
- return app('json')->successful($data);
- }
- }
|