asJson([ 'code' => 0, 'data' => [ 'list' => NavbarLink::getLink() ] ]); } /** * 获取商品信息 */ public function actionGoods() { $store_id = post_params('store_id', -1); $limit = post_params('limit', 20); $page = post_params('page', 1); $cat_id = post_params('cat_id', 0); $goods_id = post_params('goods_id'); $product_type = post_params('product_type', 0); $this->asJson(NewDiyForm::getGoods([ 'store_id' => $store_id, 'limit' => $limit, 'page' => $page, 'cat_id' => $cat_id, 'goods_id' => $goods_id, 'product_type' => $product_type, ])); } /** * 获取服务商品信息 */ public function actionGetWorkerGoods() { $ids = get_params('goods_id', ''); $product_type = get_params('product_type', 6); $query = Goods::find() ->where(['status' => 1, 'is_delete' => 0, 'store_id' => get_store_id()]); if (!empty($ids)) { $ids = json_decode($ids, true); $query->andWhere(['id' => $ids]); } $query->select('id, name, cover_pic, price, original_price, virtual_sales'); $list = $query->asArray()->all(); foreach ($list as &$item) { $item['order_num'] = OrderDetail::find()->where(['goods_id' => $item['id']])->groupBy('order_id')->count() ?? 0; $item['sales'] = OrderDetail::find()->alias('od')->where(['od.goods_id' => $item['id'], 'o.is_pay' => 1]) ->leftJoin(['o' => Order::tableName()], 'o.id = od.order_id')->select('od.num')->sum('od.num') ?? 0; $item['sales'] += $item['virtual_sales']; $item['sales'] += $item['virtual_sales']; } return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => [ 'list' => $list ] ]); } /** * 获取店铺AppId */ public function actionGetAppid(){ $store_id = post_params('new_store_id',0); if(!is_numeric($store_id)){ return $this->asJson([ 'code' => 1, 'msg' => '店铺信息有误' ]); } if ($store_id <= 0) { return $this->asJson([ 'code' => 0, 'data' => [ "wechat_app_id" => "", "gh_wechat_app_id" => "", "alipay_app_id" => "", "id" => 0, "name" => "平台自营", "business_model" => 2 ] ]); } $storeInfo = Store::find()->where(['id'=>$store_id,'is_delete'=>0])->asArray()->one(); if(!$storeInfo){ return $this->asJson([ 'code' => 1, 'msg' => '店铺信息有误' ]); } $wechatInfo = WechatConfig::find()->where(['store_id'=>$store_id,'is_delete'=>0,'type'=>1])->asArray()->one(); if($wechatInfo){ $storeInfo['wechat_app_id'] = $wechatInfo['app_id']; $storeInfo['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id']; } $alipayInfo = Option::get('alipay_config',$store_id,'alipay'); if($alipayInfo && $alipayInfo['value']){ $alipayInfo = json_decode($alipayInfo['value'],true); $storeInfo['alipay_app_id'] = $alipayInfo['app_id']; } return $this->asJson([ 'code' => 0, 'data' => $storeInfo ]); } /** * 获取diy店铺信息 */ public function actionStoreInfo(){ $latitude = (float)post_params('latitude', 0); $longitude = (float)post_params('longitude', 0); $shop_ids = post_params('shop_ids'); $cat_id = post_params('cat_id'); $page = post_params('page',1); $pageSize = post_params('pageSize',10); if($latitude && $longitude && !$shop_ids && !$cat_id){ //$storeInfo = $this->getStoreInfoByDistance($latitude,$longitude,$page,$pageSize); $storeInfo = []; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $storeInfo ]); } if(!empty($shop_ids)){ // $sql = 'UPDATE cyy_store,(SELECT id d,REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(`coordinate`, ",", 2)), ",", 1)) c from cyy_store) b SET cyy_store.latitude=b.c where cyy_store.id =b.d; //UPDATE cyy_store,(SELECT id, SUBSTRING_INDEX(`coordinate`, ",", 1) c from cyy_store) b SET cyy_store.longitude=b.c where cyy_store.id =b.id;'; $query = Store::find(); $shop_ids = implode(',', $shop_ids); $sql = "select id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model,longitude, latitude,acos(cos({$latitude}*pi()/180 )*cos(latitude*pi()/180)*cos({$longitude}*pi()/180 -longitude*pi()/180)+sin({$latitude}*pi()/180 )*sin(latitude*pi()/180))*6370996.81 as distance from cyy_store where is_delete = 0 and open_status = 1 and id in ({$shop_ids}) ORDER BY distance ASC"; $storeInfo = \Yii::$app->db->createCommand($sql)->queryAll(); // $storeInfo = $query->where(['in','id',$shop_ids])->andWhere(['is_delete'=>0,'open_status'=>1])->select("id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model")->asArray()->all(); if(count($storeInfo) > 0 ){ foreach($storeInfo as $k=>$v){ if($v['distance']){ $storeInfo[$k]['distance'] = $this->distance($v['distance']); }else{ $storeInfo[$k]['distance'] = '0m'; } if($v['category_id']){ // $categoryInfo = Cat::find()->where(['id'=>$v['category_id'],'is_delete'=>0])->asArray()->one(); // if($categoryInfo){ // $storeInfo[$k]['category_name'] = $categoryInfo['name']; // }else{ // $storeInfo[$k]['category_name'] = ''; // } $cat = SaasCategory::findOne($v['category_id']); if ($cat) { $storeInfo[$k]['category_name'] = $cat->name; }else{ $storeInfo[$k]['category_name'] = ''; } }else{ $storeInfo[$k]['category_name'] = ''; } if($v['business_model']==3){ $goodsInfo = []; }elseif($v['business_model']==4){ $goodsInfo = Goods::find()->alias('g') ->leftJoin(['fc' => FoodCat::tableName()], 'fc.id=g.cat_id') ->where(['g.store_id' => $v['id'], 'g.is_delete' => 0]) ->andWhere(['g.md_food_id' => -1])->select("g.id,g.name,g.price,g.original_price,g.cover_pic")->limit($this->store_goods_limit)->asArray() ->orderBy('g.sort DESC')->all(); }else{ //获取6条商品记录 $goodsInfo = Goods::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'status'=>1])->andWhere(['md_food_id' => 0])->select("id,name,price,original_price,cover_pic") ->limit($this->store_goods_limit)->orderBy('sort DESC')->asArray()->all(); } if(count($goodsInfo) > 0){ $storeInfo[$k]['goodsInfo'] = $goodsInfo; }else{ $storeInfo[$k]['goodsInfo'] = []; } $wechatInfo = WechatConfig::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'type'=>1])->asArray()->one(); if($wechatInfo){ $storeInfo[$k]['wechat_app_id'] = $wechatInfo['app_id']; $storeInfo[$k]['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id']; } $alipayInfo = Option::get('alipay_config',$v['id'],'alipay'); if($alipayInfo && $alipayInfo['value']){ $alipayInfo = json_decode($alipayInfo['value'],true); $storeInfo[$k]['alipay_app_id'] = $alipayInfo['app_id']; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $storeInfo ] ]); } if(!empty($cat_id)){ // $query = Store::find(); $sql = "select id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model, longitude, latitude,acos(cos({$latitude}*pi()/180 )*cos(latitude*pi()/180)*cos({$longitude}*pi()/180 -longitude*pi()/180)+sin({$latitude}*pi()/180 )*sin(latitude*pi()/180))*6370996.81 as distance from cyy_store where is_delete = 0 and open_status = 1 AND category_id={$cat_id} AND business_model!=1"; // $storeInfo = $query->where(['is_delete'=>0,'open_status'=>1,'category_id'=>$cat_id])->select("id,name,logo,address,category_id,sales,rank,per_spend,coordinate,business_model"); // $countQuery = clone $query; $count = \Yii::$app->db->createCommand($sql)->queryScalar(); $offset = ($page - 1) * $pageSize; $sql .= " ORDER BY distance ASC LIMIT {$pageSize} OFFSET {$offset}"; $list['list'] = \Yii::$app->db->createCommand($sql)->queryAll(); // $query->offset(($page - 1) * $pageSize)->limit($pageSize); // $list['list'] = $query->asArray()->all(); if(count($list['list']) > 0 ){ foreach($list['list'] as $k=>$v){ if($v['distance']){ $list['list'][$k]['distance'] = $this->distance($v['distance']); }else{ $list['list'][$k]['distance'] = '0m'; } if($v['category_id']){ $categoryInfo = SaasCategory::find()->where(['id'=>$v['category_id'],'is_delete'=>0])->asArray()->one(); if($categoryInfo){ $list['list'][$k]['category_name'] = $categoryInfo['name']; }else{ $list['list'][$k]['category_name'] = ''; } }else{ $list['list'][$k]['category_name'] = ''; } if($v['business_model']==3){ $goodsInfo = []; }elseif($v['business_model']==4){ $goodsInfo = Goods::find()->alias('g') ->leftJoin(['fc' => FoodCat::tableName()], 'fc.id=g.cat_id') ->where(['g.store_id' => $v['id'], 'g.is_delete' => 0]) ->andWhere(['g.md_food_id' => -1])->select("g.id,g.name,g.price,g.original_price,g.cover_pic") ->limit($this->store_goods_limit)->asArray()->orderBy('g.sort DESC')->all(); }else{ //获取6条商品记录 $goodsInfo = Goods::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'status'=>1])->andWhere(['md_food_id' => 0]) ->select("id,name,price,original_price,cover_pic")->limit($this->store_goods_limit) ->orderBy('sort DESC')->asArray()->all(); } if(count($goodsInfo) > 0){ $list['list'][$k]['goodsInfo'] = $goodsInfo; }else{ $list['list'][$k]['goodsInfo'] = []; } $wechatInfo = WechatConfig::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'type'=>1])->asArray()->one(); if($wechatInfo){ $list['list'][$k]['wechat_app_id'] = $wechatInfo['app_id']; $list['list'][$k]['gh_wechat_app_id'] = $wechatInfo['gh_wechat_app_id']; } $alipayInfo = Option::get('alipay_config',$v['id'],'alipay'); if($alipayInfo && $alipayInfo['value']){ $alipayInfo = json_decode($alipayInfo['value'],true); $list['list'][$k]['alipay_app_id'] = $alipayInfo['app_id']; } } } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'page' => $page, 'totalCount' => $count ] ]); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [] ]); } public static function distance($distance) { if ($distance == -1) { return -1; } if ($distance > 1000) { $distance = round($distance / 1000, 2) . 'km'; } else { $distance = round($distance, 2); $distance .= 'm'; } return $distance; } private function getStoreInfoByDistance($latitude,$longitude,$page=1,$pageSize=10){ $connection = \Yii::$app->db; $num = ($page - 1 ) * $pageSize; $sql = "SELECT *, 6378.138 * 2 * ASIN( SQRT( POW( SIN( ( $latitude * PI() / 180 - lat * PI() / 180 ) / 2 ), 2 ) + COS( $latitude * PI() / 180) * COS(lat * PI() / 180) * POW( SIN( ( $longitude * PI() / 180 - lng * PI() / 180 ) / 2 ), 2 ) ) ) * 1000 AS distance FROM ( SELECT id,`name`,logo,address,category_id,sales,rank,per_spend,coordinate,business_model,substring_index(coordinate, ',',1) AS lat,substring_index(coordinate, ',',-1) AS lng FROM cyy_store WHERE is_delete = 0 and open_status = 1 ) store ORDER BY distance ASC Limit $num , $pageSize"; $command = $connection->createCommand($sql); $res = $command->queryAll(); foreach($res as $k=>$v){ if($v['distance']){ if ($v['distance'] < 1000) { $res[$k]['distance'] = round($v['distance'], 2) . "m"; } else { $res[$k]['distance'] = round($v['distance'] / 1000 , 2) . "km"; } } if($v['category_id']){ $categoryInfo = Cat::find()->where(['id'=>$v['category_id'],'is_delete'=>0])->asArray()->one(); if($categoryInfo){ $res[$k]['category_name'] = $categoryInfo['name']; }else{ $res[$k]['category_name'] = ''; } } //获取6条商品记录 $goodsInfo = Goods::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'status'=>1])->select("id,name,price,original_price,cover_pic")->limit($this->store_goods_limit)->orderBy('sort')->asArray()->all(); if(count($goodsInfo) > 0){ $res[$k]['goodsInfo'] = $goodsInfo; }else{ $res[$k]['goodsInfo'] = []; } $wechatInfo = WechatConfig::find()->where(['store_id'=>$v['id'],'is_delete'=>0,'type'=>1])->asArray()->all(); if($wechatInfo){ $res[$k]['wechat_app_id'] = $wechatInfo['app_id']; } $alipayInfo = Option::get('alipay_config',$v['id'],'alipay'); if($alipayInfo && $alipayInfo['value']){ $alipayInfo = json_decode($alipayInfo['value'],true); $res[$k]['alipay_app_id'] = $alipayInfo['app_id']; } } $count = Store::find()->where(['is_delete'=>0,'open_status'=>1])->count(); $data = [ 'data'=>$res, 'page'=>$page, 'count'=>$count ]; return $data; } /** * 获取首页模板 */ public function actionNewIndex() { $store_id = get_params('store_id',-1); $params = [ 'is_delete' => 0, 'is_index' => 1, 'store_id' =>$store_id //'store_id' => $this->alliance_store_id ]; $id = get_params('id'); if (!empty($id)) { unset($params['is_index'], $params['store_id']); $params['id'] = $id; } $template = NewDiyTemplate::findOne($params); $controls = NewDiyTemplate::find() ->where([ 'store_id' => $store_id, //'store_id' => $this->alliance_store_id, 'is_delete' => 0, 'type' => 100 ])->asArray()->one()['template'];//商城控件 $platform_controls = NewDiyTemplate::find() ->where([ 'store_id' => -1, //'store_id' => $this->alliance_store_id, 'is_delete' => 0, 'type' => 100 ])->asArray()->one()['template']; $controls_arr = json_decode($controls, true); $platform_controls_arr = json_decode($platform_controls, true); if (!empty($controls_arr) && !empty($platform_controls_arr)) { $open = true; foreach ($controls_arr as &$controls_item) { if ($controls_item['controlComName'] === 'widgetNavControl') { $open = false; foreach ($platform_controls_arr as $platform_controls_item) { if ($platform_controls_item['controlComName'] === 'widgetNavControl') { $controls_item = $platform_controls_item; } } } if ($controls_item['controlComName'] === 'widgetWxControl') { $store = Store::findOne($store_id); $kefu_id = ''; if ($store && $store->kefu_id) { $kefu_id = $store->kefu_id; } else { $controls_item['kefuType'] = 0; } $controls_item['kefu_id'] = $kefu_id; } } if ($open) { $platformWidgetNavControl = []; foreach ($platform_controls_arr as $platform_controls_item) { if ($platform_controls_item['controlComName'] === 'widgetNavControl') { $platformWidgetNavControl = $platform_controls_item; } } array_unshift($controls_arr, $platformWidgetNavControl); } } $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE); return $this->asJson([ 'code' => 0, 'data' => [ 'template' => $template, 'controls' => $controls, ] ]); } /** * 系统页面列表 * @return \yii\web\Response */ public function actionSystemTemplateList() { $store_id = get_params('store_id',0); if(!is_numeric($store_id)){ return $this->asJson([ 'code' => 1, 'msg' => '店铺信息为必传', ]); } $list = NewDiyTemplate::find() ->where([ 'store_id' => $this->store_id, 'is_delete' => 0, 'name' => 'system' ])->orderBy(['id' => SORT_ASC])->asArray()->all(); foreach ($list as $index => &$item) { $template = json_decode($item['template'], true); if ($template['system_type'] === 'my') { foreach ($template['templates'] as &$tem) { if ($tem['comName'] === 'userWallet') { $open = false; foreach ($tem['params']['list'] as $i) { if ($i['controlComName'] === 'walletItemControl' && !isset($i['walletItemType'])){ $open = true; break; } } if ($open) { if ($open) { $tem['params']['list'] = [ [ "name" => "店铺积分", "subName" => "积分换好物", "controlComName" => "walletItemControl", "walletItemType" => "walletSaasStoreIntegral", "color" => "#262626", "subColor" => "#bbbbbb" ], [ "name" => "优惠券", "subName" => "下单立省", "controlComName" => "walletItemControl", "walletItemType" => "walletSaasCoupon", "color" => "#262626", "subColor" => "#bbbbbb" ], [ "name" => "联盟券", "subName" => "联盟券", "controlComName" => "walletItemControl", "walletItemType" => "walletSaasLeaguePrice", "color" => "#262626", "subColor" => "#bbbbbb" ], [ "name" => "联盟积分", "subName" => "积分换好物", "controlComName" => "walletItemControl", "walletItemType" => "walletSaasIntegral", "color" => "#262626", "subColor" => "#bbbbbb" ] ]; } } } } } if ($template['system_type'] === 'goodsDetail' && intval($this->store_id) > 0) { $_open = true; } $item['template'] = json_encode($template, JSON_UNESCAPED_UNICODE); } $list = array_values($list); if (empty($_open)) { $order_detail_template = [ 'name' => 'system', 'store_id' => 0, 'template' => '{"page_name":"商品详情","is_index":"0","page_type":1,"system_type":"goodsDetail","page_link":"","theme":{"color":""},"pageCss":{"margin":0,"padding":0,"vSpave":0,"hSpace":0,"borderRadius":0,"borderRaNum":0,"backgroundColor":"","backgroundImage":"","bgImg":"","bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"},"templates":[{"name":"商品详情页面-头部商品轮播图","type":"","comName":"goodsSwiperImgs","icon":"","controlComName":"","params":{}},{"name":"商品详情页面-商品介绍","type":"","comName":"goodsIntroduce","icon":"","controlComName":"goodsIntroduceControl","params":{"showMemberPrice":false,"showOriginPrice":false},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品优惠活动","type":"","comName":"goodsDiscount","icon":"","controlComName":"goodsDiscountControl","params":{"showGoodsDiscount":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品sku属性选择","type":"","comName":"goodsAttribute","icon":"","controlComName":"goodsAttributeControl","params":{"showAddress":true,"showNearbyShop":true,"showFreight":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品评价","type":"","comName":"goodsEvaluate","icon":"","controlComName":"goodsEvaluateControl","params":{"showEvaluate":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-商品评价","type":"","comName":"goodsShopEntry","icon":"","controlComName":"goodsShopEntryControl","params":{"showGoodsShopEntry":true},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","margin":12,"padding":0,"borderRadius":0}},{"name":"商品详情页面-底部导航","type":"","comName":"goodsFootNav","icon":"","controlComName":"goodsFootNavControl","params":{"styleType":"1","tabList":[{"text":"店铺","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/857370f6a7a788ff0674b4255dabc91974b402a0.png","link":{},"fontColor":"#262626"},{"text":"客服","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/aa7a96931ae57b070af3bd38f9553a40b7d9bd4f.png","link":{},"fontColor":"#262626"},{"text":"购物车","icon":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-11-02/5d156040e27daf1da32d3a4241355684f4708f7e.png","link":{},"fontColor":"#262626"}],"buyBtn":{"text":"立即购买","color":"#FFFFFF","bgColor":"#FBBA10"},"cartBtn":{"text":"加入购物车","color":"#FFFFFF","bgColor":"#F0250E"}},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"bgOpacity":100,"opacity":"100","backgroundSize":"100% 100%","backgroundRepeat":"no-repeat","borderRadius":0}}],"controlComName":"pageControl","id":""}', 'type' => 1, 'id' => 1 ]; $list = array_merge($list, [$order_detail_template]); } $controls = NewDiyTemplate::find() ->where([ 'store_id' => $this->store_id, 'is_delete' => 0, 'type' => 100 ])->asArray()->one()['template']; $controls_arr = json_decode($controls, true); foreach ($controls_arr as &$controls_item) { if ($controls_item['controlComName'] === 'widgetWxControl') { $store = Store::findOne($store_id); $kefu_id = ''; if ($store && $store->kefu_id) { $kefu_id = $store->kefu_id; } else { $controls_item['kefuType'] = 0; } $controls_item['kefu_id'] = $kefu_id; } } $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE); return $this->asJson([ 'code' => 0, 'msg' => '加载成功', 'data' => [ 'list' => $list, 'controls' => $controls, ] ]); } /** * 获取商品优惠详情 */ public function actionAddress() { $form = new GoodsForm(); $form->attributes = get_params(); return $this->asJson($form->getAddress()); } /** * 获取DIY模板 */ public function actionTemplateUnit() { $type = get_params('type', 'goods'); $template = DiyTemplate::findOne([ 'is_delete' => 0, 'type' => $type, 'store_id' => get_store_id() ]); if (is_platform() && $type == 'controls') { $tabbar = Option::get('tabbar', 0, 'saas', json_encode([])); $tabbar = json_decode($tabbar['value'], true); $temp = json_decode($template->template, true); foreach ($temp as $key => $value) { if ($value['name'] == '底部导航') { $temp[$key]['param']['list'] = $tabbar; } } $template->template = json_encode($temp, JSON_UNESCAPED_UNICODE); } return $this->asJson([ 'code' => 0, 'data' => [ 'template' => $template ] ]); } /** * 获取秒杀商品信息 */ public function actionSeckillActivity() { try { $id = get_params('activeId', 20); $seckill_activity = SeckillActivity::find()->where([ 'AND', ['store_id' => get_store_id(), 'is_delete' => 0, 'id' => $id, 'is_platform' => 0], ['>', 'end_time', time()] ])->select('id, start_time, end_time, name, store_id')->asArray()->all(); $pagination = [ 'list' => [], 'pageNo' => 0, 'totalCount' => 0 ]; if ($seckill_activity) { foreach ($seckill_activity as &$item) { $query = SeckillActivityGoods::find()->alias('sag')->where([ 'sag.is_delete' => 0, 'sag.activity_id' => $item['id'] ])->leftJoin(['g' => Goods::tableName()], 'sag.goods_id = g.id') ->andWhere([ 'g.status' => 1, 'g.is_delete' => 0 ])->select("g.id, g.cover_pic, g.delivery_rules_id, g.name, sag.seckill_num, sag.seckill_price price, g.price original_price, sag.sale_num, sag.attr, sag.use_attr, sag.virtual_sales, sag.virtual_num"); $pagination = pagination_make($query); $item['seckill_activity_goods'] = $pagination['list']; foreach ($item['seckill_activity_goods'] as &$activity_good) { if ((int)$activity_good['use_attr'] === 1) { $attr = json_decode($activity_good['attr'], true); $activity_good['price'] = sprintf('%.2f', $attr[0]['seckill_price']); } $activity_good['delivery_rules'] = DeliveryRules::find()->where([ 'id' => $activity_good['delivery_rules_id'], 'status' => 1, 'is_delete' => 0 ])->select('type, times, days, name')->one(); if ($activity_good['delivery_rules']) { $days = "下单" . $activity_good['delivery_rules']['days'] . "天后"; $activity_good['delivery_rules']['times'] = (int)$activity_good['delivery_rules']['type'] === 1 ? $days : date("m月d日 H:i:s", $activity_good['delivery_rules']['times']); $activity_good['delivery_rules']['type'] .= ''; } if (((int)$activity_good['seckill_num'] + $activity_good['virtual_sales']) === 0 || ((int)$activity_good['sale_num'] + $activity_good['virtual_sales']) === 0) { $activity_good['progress'] = 0; } else { $activity_good['progress'] = sprintf('%.2f', (($activity_good['sale_num'] * 1) / ($activity_good['seckill_num'] + $activity_good['sale_num'])) * 100); $activity_good['seckill_num'] <= 0 && $activity_good['progress'] = 100; if ($item['start_time'] > time()) { $activity_good['progress'] = 0; $activity_good['virtual_sales'] = 0; } } // $activity_good['seckill_num'] -= $activity_good['sale_num']; } } } return $this->asJson([ 'code' => 0, 'data' => [ 'list' => $seckill_activity, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'] ], ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 0, 'data' => [] ]); } } }