| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\constants\OptionSetting;
- use app\models\Admin;
- use app\models\Cat;
- use app\models\DeliveryRules;
- use app\models\District;
- use app\models\DiyTemplate;
- use app\models\FoodCat;
- use app\models\Goods;
- use app\models\FoodExtGoods;
- use app\models\GoodsCat;
- use app\models\Mch;
- use app\models\MdGroupActivitiesGoods;
- use app\models\NewDiyTemplate;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\SeckillActivity;
- use app\models\SeckillActivityGoods;
- use app\models\WorkerGoodsExt;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\DiyForm;
- use app\modules\client\models\v1\OrderCommentForm;
- use app\modules\client\models\v1\OrderListForm;
- use app\modules\client\models\v1\StoreListForm;
- use yii\helpers\Json;
- use app\models\Option;
- use app\models\Store;
- use app\models\User;
- /**
- * 测试
- */
- class DiyController extends BaseController
- {
- /**
- * 获取首页模板
- */
- public function actionIndex()
- {
- $template = DiyTemplate::findOne([
- 'is_delete' => 0,
- 'is_index' => 1,
- 'store_id' => get_store_id()
- ]);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'template' => $template
- ]
- ]);
- }
- /**
- * 获取DIY模板
- */
- public function actionTemplate()
- {
- $template = DiyTemplate::findOne([
- 'is_delete' => 0,
- 'id' => get_params('id', 0),
- 'store_id' => get_store_id()
- ]);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'template' => $template
- ]
- ]);
- }
- /**
- * 获取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 actionGoods()
- {
- $limit = get_params('limit', 20);
- $page = get_params('page', 1);
- $cat_id = get_params('cat_id', 0);
- $activities_id = get_params('activities_id', 0);
- $goods_id = get_params('goods_id', Json::encode([]));
- $product_type = get_params('product_type');
- $this->asJson(DiyForm::getGoods([
- 'limit' => $limit,
- 'page' => $page,
- 'cat_id' => $cat_id,
- 'goods_id' => $goods_id,
- 'product_type' => $product_type,
- 'activities_id' => $activities_id,
- ]));
- }
- /**
- * 获取分类
- */
- public function actionGetCat() {
- $store_id = get_store_id();
- $data = Cat::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'is_show' => 1, 'parent_id' => 0])
- ->select('id, name')->orderBy('sort asc')->asArray()->all();
- foreach ($data as &$item) {
- $item['title'] = $item['name'];
- $item['subTitle'] = $item['name'];
- $item['link'] = null;
- unset($item['name']);
- // $arr2 = array_column($arr, 'name');
- $goods = [];
- $cat_arr = Cat::find()->where(['parent_id' => $item['id'], 'is_delete' => 0])->select('id')->column();
- $cat_arr = array_merge($cat_arr, [$item['id']]);
- if (!empty($cat_arr)) {
- $cat_arr2 = Cat::find()->where(['parent_id' => $cat_arr, 'is_delete' => 0])->select('id')->column();
- $cat_arr = array_merge($cat_arr, $cat_arr2);
- }
- $goods_cat_arr = GoodsCat::find()->where(['cat_id' => $cat_arr, 'is_delete' => 0])->select('goods_id')->column();
- $item['data'] = Goods::find()->where(['id' => $goods_cat_arr, 'is_delete' => 0, 'status' => 1])
- ->select('id, name, cover_pic, original_price, price, is_negotiable, virtual_sales')->asArray()->all();
- foreach ($item['data'] as $key => &$value) {
- $goods = Goods::findOne($value['id']);
- $value['virtual_sales'] = $goods->getSalesVolume() + $value['virtual_sales'];
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $data
- ]
- ]);
- }
- /**
- * 获取服务商品信息
- */
- public function actionGetWorkerGoods() {
- $ids = get_params('goods_id', '');
- $product_type = get_params('product_type', 6);
- if (intval($product_type) === 6) {
- $cat_id = get_params('cat_id');
- $query = WorkerGoodsExt::find()->alias('wge')->where(['wge.store_id' => get_store_id(), 'g.status' => 1, 'g.is_delete' => 0])
- ->leftJoin(['g' => Goods::tableName()], 'g.id = wge.goods_id');
- if (!empty($ids)) {
- $ids_ = json_decode($ids, true);
- if (empty($ids_)) {
- $ids = explode(',', $ids);
- } else {
- $ids = $ids_;
- }
- $query->andWhere(['g.id' => $ids]);
- }
- if ($cat_id) {
- $query->andWhere(['wge.cat_id' => $cat_id]);
- }
- $query->select('g.id, g.name, g.cover_pic, wge.desc, g.price, g.original_price, g.virtual_sales');
- } else {
- $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'];
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'list' => $list
- ]
- ]);
- }
- /**
- * 获取秒杀商品信息
- */
- 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],
- ['>', 'end_time', time()]
- ])->select('id, start_time, end_time, name')->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")->groupBy('g.id');
- $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' => []
- ]);
- }
- }
- /**
- * 获取自提点信息
- */
- public function actionShop()
- {
- $limit = get_params('limit', 20);
- $page = get_params('page', 1);
- $shop_id = get_params('shop_id', Json::encode([]));
- $longitude = get_params('longitude', 0);
- $latitude = get_params('latitude', 0);
- if ($latitude) {
- $res = DiyForm::getNearbyShop([
- 'limit' => $limit,
- 'page' => $page,
- 'shop_id' => $shop_id,
- 'longitude' => $longitude,
- 'latitude' => $latitude
- ]);
- } else {
- $res = DiyForm::getShop([
- 'limit' => $limit,
- 'page' => $page,
- 'shop_id' => $shop_id
- ]);
- }
- $this->asJson($res);
- }
- /**
- * 获取自提点信息
- */
- public function actionMch()
- {
- $limit = get_params('limit', 20);
- $page = get_params('page', 1);
- $mch_id = get_params('mch_id', Json::encode([]));
- $longitude = get_params('longitude', 0);
- $latitude = get_params('latitude', 0);
- if ($latitude) {
- $res = DiyForm::getNearbyMch([
- 'limit' => $limit,
- 'page' => $page,
- 'mch_id' => $mch_id,
- 'longitude' => $longitude,
- 'latitude' => $latitude
- ]);
- } else {
- $res = DiyForm::getMch([
- 'limit' => $limit,
- 'page' => $page,
- 'mch_id' => $mch_id
- ]);
- }
- $this->asJson($res);
- }
- /**
- * 获取首页模板
- */
- public function actionNewIndex()
- {
- $params = [
- 'is_delete' => 0,
- 'is_index' => 1,
- 'store_id' => get_store_id()
- ];
- $id = get_params('id');
- if (!empty($id)) {
- unset($params['is_index']);
- $params['id'] = $id;
- }
- $template = NewDiyTemplate::findOne($params);
- $controls = NewDiyTemplate::find()
- ->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- 'type' => 100,
- 'name' => 'controls'
- ])->asArray()->one()['template'];
- if (is_platform()) {
- $controls = '[{"name":"导航","is_show":true,"controlComName":"widgetNavControl","show_type":"nav","params":{"defaultColor":"#2e2d2d","activeColor":"#FCBE40","navList":[{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/a94065d9bc45172db3df618616fa174e6908ad97.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0e337d2c6c92e2bbac7b0e57dc022af250bd574e.png","nav_text":"首页","link":{"name":"首页","link":"/pages/union/home/index","open_type":"switchtab","params":[]}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0f7048ecd1c7d0d30278ca9665beca219ff3e778.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/865006703b674a416be49169c691333ae210d055.png","nav_text":"我的","link":{"name":"用户中心","link":"/pages/my/my","id":375,"open_type":"switchtab","params":[]}}]},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"}},{"name":"弹窗","is_show":false,"show_type":"window","controlComName":"widgetPopupControl","params":{"list":[],"rule":1}},{"name":"电话","is_show":true,"show_type":"list","controlComName":"widgetPhoneControl","params":{"phone":"","picUrl":""}},{"name":"微信客服","is_show":true,"show_type":"list","controlComName":"widgetWxControl","params":{"picUrl":""}}]';
- }
- $data = [
- 'template' => $template,
- 'controls' => $controls
- ];
- $data['show'] = true;
- // 已指定会员等级 && (用户未登陆 || 用户的会员等级 != 页面设置的会员等级)
- if($template['level'] != 0 && (!get_user() || get_user()->level != $template['level'])){
- $data['show'] = false;
- }
- if (\Yii::$app->prod_is_dandianpu()) {
- $store = Store::findOne(get_store_id());
- if ($store) {
- $data['store_name'] = $store->name;
- $data['store_logo'] = $store->logo;
- }
- $self_mini = Option::get('self_mini', $store->id, 'store', 0)['value'];
- $is_store_traffic_sharing = Option::get('is_store_traffic_sharing', $store->id, 'store', 1)['value'];
- $switch_store = intval(Option::get('one_store_switch_store', 0, 'saas', 0)['value']);
- $is_store_traffic_sharing_switch = false;
- if (intval($is_store_traffic_sharing) && !intval($self_mini) && $switch_store) {
- $is_store_traffic_sharing_switch = true;
- }
- $controls = json_decode($data['controls'], true);
- foreach ($controls as &$control_item) {
- if ($control_item['controlComName'] == 'widgetNavControl') {
- $tab_open = true;
- foreach ($control_item['params']['navList'] as $nav_index => &$nav_item) {
- if (isset($nav_item['tab_type']) && $nav_item['tab_type'] == 'store_sharing') {
- $nav_item['link']['link'] = '/allianceStore/index/index';
- $nav_item['link']['open_type'] = 'navigate';
- if (!$is_store_traffic_sharing_switch) {
- unset($control_item['params']['navList'][$nav_index]);
- }
- $tab_open = false;
- }
- }
- $control_item['params']['navList'] = array_values($control_item['params']['navList']);
- if ($tab_open && $is_store_traffic_sharing_switch) {
- array_push($control_item['params']['navList'], [
- "pic_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/store.png',
- "active_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/storeActive.png',
- "nav_text" => "联盟商家",
- "tab_type" => "store_sharing",
- "link" => [
- "name" => "联盟商家",
- "link" => "/allianceStore/index/index",
- "open_type" => "navigate",
- "params" => [],
- "id" => "9421"
- ]
- ]);
- }
- }
- }
- $data['controls'] = json_encode($controls, JSON_UNESCAPED_UNICODE);
- }
- if(show_shenhe()){
- $this->newIndexShowShenhe($data);
- }
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- ]);
- }
- public function newIndexShowShenhe(&$data) {
- $temp = '{"page_name": "首页","is_index": "1","page_type": 0,"page_link": "","theme": {"color": "","time": 1633765304209},"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": "pageHeader","comName": "pageHeader","controlComName": "pageHeaderControl","moduleCss": {"backgroundColor": "#FFF","backgroundImage": "","bgImg": "","useBackground": true,"bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat"},"params": {"text": "首页","showText": 1,"capsuleType": "0","styleType": "1","mdStyle": "1","css": {"color": "#333","fontNum": "18","fontSize": "","fontStyle": "normal","fontWeight": "bold","textDecoration": "inherit","textAlign": "center"}}},{"name": "产品展示","type": "productShow","comName": "productShow","icon": "icon-chanpinzhanshi","controlComName": "productShowControl","moduleCss": {"backgroundColor": "#FFFFFF","backgroundImage": "","bgImg": "","useBackground": true,"bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat","margin": 0,"padding": 0,"borderRadius": 0},"params": {"moduleNameCss": {"color": "#262626","fontNum": "16","fontSize": "","fontStyle": "normal","fontWeight": "bold","textDecoration": "inherit"},"moduleMoreCss": {"color": "#888888","fontNum": "12","fontSize": "","fontStyle": "normal","fontWeight": "normal","textDecoration": "inherit"},"headerBg": {"backgroundColor": "","backgroundImage": "","bgImg": "","useBackground": true,"bgOpacity": 100,"opacity": "100","backgroundSize": "100% 100%","backgroundRepeat": "no-repeat"},"styleType": "1","moduleName": "","moreText": "更多","showMoreText": false,"showModuleName": true,"showPrice": true,"showSales": true,"showBuyBtn": false,"productDataFrom": "select","selectData": [],"classifyData": "","classifyArr": [],"buyBtnType": "1","producNameColor": "#1D1D1D","priceColor": "#FA2C1B","originPriceColor": "#9B9B9B","saleColor": "#9B9B9B","buyStyle": "add","buyBtnText": "购买","goodsItemOutSpace": 0,"goodsItemInnerSpace": 0,"link": {}}}],"controlComName": "pageControl","id": "1"}';
- $data['template']['template'] = $temp;
- $tempArr = json_decode($temp, true);
- $miniAuditGoodsIds = Option::get(OptionSetting::ACTIVITY_MINI_AUDIT_GOODS, get_store_id(), '', '')['value'];
- if(empty($miniAuditGoodsIds)){
- return;
- }
- $goodsIds = explode(',', $miniAuditGoodsIds);
- foreach($goodsIds as $id){
- $item = [
- 'id' => $id,
- ];
- $tempArr['templates'][1]['params']['selectData'][] = $item;
- }
- $data['template']['template'] = json_encode($tempArr, JSON_UNESCAPED_UNICODE);
- }
- /**
- * 获取DIY模板
- */
- public function actionNewTemplateUnit()
- {
- $id = get_params('id');
- $template = NewDiyTemplate::findOne($id);
- // if (is_platform() && $template->type = 100) {
- // $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,
- 'controls' => NewDiyTemplate::find()
- ->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- 'type' => 100
- ])->asArray()->one()['template']
- ]
- ]);
- }
- public function actionGetFoodsCatList() {
- $data = FoodCat::find()->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- 'is_show' => 1,
- 'md_id' => get_md_id() < 1 ? [0, -1] : get_md_id()
- ])->select('id, name')->asArray()->all();
- foreach ($data as &$item) {
- $item['title'] = $item['name'];
- $item['subTitle'] = $item['name'];
- $item['link'] = null;
- $item['dataFrom'] = "classify";
- $item['classifyId'] = $item['id'];
- unset($item['name']);
- $where['cat_id'] = $item['id'];
- $item['data'] = Goods::find()->where(['cat_id' => $item['id'], 'is_delete' => 0, 'status' => 1])
- ->select('id, name, cover_pic, original_price, price, is_negotiable, virtual_sales, attr, use_attr')->asArray()->all();
- foreach ($item['data'] as &$goods) {
- $once_goods = Goods::findOne($goods['id']);
- $goods['attr'] = json_decode($goods['attr'], true);
- $goods['use_attr'] *= 1;
- $attr_group_list = null;
- if ($once_goods) {
- $attr_group_list = $once_goods->getAttrGroupList();
- }
- $goods['attr_group_list'] = $attr_group_list;
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'list' => $data,
- ]
- ]);
- }
- public function actionGetFoodsList() {
- try {
- $params = get_params();
- $where = [
- 'store_id' => get_store_id(),
- 'md_food_id' => get_md_id() < 1 ? -1 : get_md_id(),
- 'is_delete' => 0,
- 'status' => 1
- ];
- if ($params['goods_id']) {
- if (is_string($params['goods_id'])) {
- $params['goods_id'] = explode(',', $params['goods_id']);
- } else {
- try {
- $params['goods_id'] = json_decode($params['goods_id'], true);
- } catch (\Exception $e) {
- }
- }
- $where['id'] = $params['goods_id'];
- }
- if ($params['cat_id']) {
- $where['cat_id'] = $params['cat_id'];
- }
- $goods = Goods::find()->where($where)->select('id, food_ext_goods_id, md_food_id, store_id, name, cover_pic, price, original_price, virtual_sales, product_type, attr, use_attr')->asArray()->all();
- foreach ($goods as &$good) {
- $good['attr'] = json_decode($good['attr'], true);
- $good['use_attr'] *= 1;
- $once_goods = Goods::findOne($good['id']);
- $attr_group_list = null;
- if ($once_goods) {
- $attr_group_list = $once_goods->getAttrGroupList();
- }
- $good['attr_group_list'] = $attr_group_list;
- $feg = [];
- $good['food_ext_goods'] = FoodExtGoods::getAttr($good['food_ext_goods_id'], $good['store_id'], $good['md_food_id'], $feg);
- $good['food_ext_goods_model'] = $feg;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '获取成功',
- 'data' => [
- 'goods' => $goods,
- ]
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'data' => $e->getMessage()
- ]);
- }
- }
- /**
- * 系统页面列表
- * @return \yii\web\Response
- */
- public function actionSystemTemplateList() {
- $store_id = get_store_id();
- $list = NewDiyTemplate::find()
- ->where([
- 'store_id' => $store_id,
- 'is_delete' => 0,
- 'name' => 'system'
- ])->orderBy(['id' => SORT_ASC])->asArray()->all();
- $form = new OrderListForm();
- $form->store_id = $store_id;
- $form->user_id = get_user_id();
- foreach ($list as &$item) {
- if ($item['template']) {
- $template = json_decode($item['template'], true);
- if ($template['system_type'] === 'my') {
- foreach ($template['templates'] as &$tem_) {
- if ($tem_['comName'] === 'userMember' && $tem_['params']['showMemberCode'] === null) {
- $tem_['params'] = array_merge($tem_['params'], ['showMemberCode' => true]);
- }
- /* begin 2024/03/28 16:09:20 新增分销商条件为后台指定的判断 WPing丶 */
- $setting = Option::get('share_basic_setting', $store_id);
- $setting = $setting ? Json::decode($setting['value']) : [];
- $share_condition = $setting['share_condition']['value'];
- if($share_condition == 3 && $tem_['comName'] === 'userTools') {
- foreach($tem_['params']['list'] as $ut_key => $ut_item) {
- $user = User::findOne(get_user_id());
- if(($ut_item['link']['link'] == "/user/share/index" || $ut_item['link']['link'] == "\/user\/share\/index") && $user->is_distributor != 1) {
- unset($tem_['params']['list'][$ut_key]);
- }
- }
- }
- /* end */
- if($tem_['comName'] === 'userOrder'){
- $hostInfo = \Yii::$app->request->hostName;
- $default_tab_list = [
- [
- "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitPay.png",
- "tabText" => "待付款",
- "link" => [],
- "controlComName" => "userOrderTabItemControl",
- "controlComKey" => "userOrderTabWaitPay",
- "checked" => true
- ],
- [
- "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitSendOrder.png",
- "tabText" => "待发货",
- "link" => [],
- "controlComName" => "userOrderTabItemControl",
- "controlComKey" => "userOrderTabWaitSendOrder",
- "checked" => true
- ],
- [
- "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitIncome.png",
- "tabText" => "待收货",
- "link" => [],
- "controlComName" => "userOrderTabItemControl",
- "controlComKey" => "userOrderTabWaitIncome",
- "checked" => true
- ],
- [
- "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabComplete.png",
- "tabText" => "已完成",
- "link" => [],
- "controlComName" => "userOrderTabItemControl",
- "controlComKey" => "userOrderTabComplete",
- "checked" => true
- ],
- // [
- // "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabWaitComment.png",
- // "tabText" => "待评价",
- // "link" => [],
- // "controlComName" => "userOrderTabItemControl",
- // "controlComKey" => "userOrderTabWaitComment",
- // "checked" => false
- // ],
- [
- "tabImg" => "https://{$hostInfo}/web/v1/statics/clientImg/order/userOrderTabHandleRefund.png",
- "tabText" => "退换售后",
- "link" => [],
- "controlComName" => "userOrderTabItemControl",
- "controlComKey" => "userOrderTabHandleRefund",
- "checked" => true
- ]
- ];
- //如果没有controlComKey 则认为是使用的老版本
- if (!isset($tem_['params']['tabsList'][0]['controlComKey'])) {
- $tem_['params']['tabsList'] = $default_tab_list;
- }
- foreach ($tem_['params']['tabsList'] as &$tab_item) {
- switch ($tab_item['controlComKey']) {
- case 'userOrderTabWaitPay'://待付款
- $form->status = 0;
- $tab_item['order_count'] = $form->searchOrderCount();
- break;
- case 'userOrderTabWaitSendOrder'://待发货
- $form->status = 1;
- $tab_item['order_count'] = $form->searchOrderCount();
- break;
- case 'userOrderTabWaitIncome'://待收货
- $form->status = 2;
- $tab_item['order_count'] = $form->searchOrderCount();
- break;
- case 'userOrderTabComplete'://已完成
- $form->status = 3;
- $tab_item['order_count'] = $form->searchOrderCount();
- break;
- case 'userOrderTabWaitComment'://已完成
- $tab_item['order_count'] = OrderCommentForm::commonComment(get_user_id())->count();
- break;
- default:
- $form->status = 0;
- $tab_item['order_count'] = 0;
- break;
- }
- }
- }
- if ($tem_['comName'] === 'userWallet') {
- $open = false;
- foreach ($tem_['params']['list'] as $i) {
- if ($i['controlComName'] === 'walletItemControl' && !isset($i['walletItemType'])){
- $open = true;
- break;
- }
- }
- //优化我的钱包字段 增加类型 方便判断
- if ($open) {
- $tem_['params']['list'] = [
- [
- "name" => "积分",
- "subName" => "",
- "controlComName" => "walletItemControl",
- "walletItemType" => "walletIntegral",
- "color" => "#262626",
- "subColor" => "#bbbbbb"
- ],
- // [
- // "name" => "优惠券",
- // "subName" => "",
- // "controlComName" => "walletItemControl",
- // "walletItemType" => "walletCoupon",
- // "color" => "#262626",
- // "subColor" => "#bbbbbb"
- // ],
- [
- "name" => "余额",
- "subName" => "",
- "controlComName" => "walletItemControl",
- "walletItemType" => "walletBalance",
- "color" => "#262626",
- "subColor" => "#bbbbbb"
- ],
- [
- "name" => "联盟券",
- "subName" => "",
- "controlComName" => "walletItemControl",
- "walletItemType" => "walletLeaguePrice",
- "color" => "#262626",
- "subColor" => "#bbbbbb"
- ]
- ];
- }
- //判断如果是数字门店 || 独立部署版本 || 装修开关关闭状态就需要不展示联盟券
- if (\Yii::$app->prod_is_saas() || !is_open_platform() || (isset($tem_['showCoupon']) && !intval($tem_['showCoupon']))) {
- foreach ($tem_['params']['list'] as $params_index => $params_item) {
- if ($params_item['walletItemType'] === 'walletLeaguePrice') {
- unset($tem_['params']['list'][$params_index]);
- }
- }
- $tem_['params']['list'] = array_values($tem_['params']['list']);
- }
- }
- }
- }
- $item['template'] = json_encode($template);
- }
- }
- $controls = NewDiyTemplate::find()
- ->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- 'type' => 100,
- 'name' => 'controls'
- ])->asArray()->one()['template'];
- if (is_platform()) {
- $controls = '[{"name":"导航","is_show":true,"controlComName":"widgetNavControl","show_type":"nav","params":{"defaultColor":"#2e2d2d","activeColor":"#FCBE40","navList":[{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/a94065d9bc45172db3df618616fa174e6908ad97.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0e337d2c6c92e2bbac7b0e57dc022af250bd574e.png","nav_text":"首页","link":{"name":"首页","link":"/pages/union/home/index","open_type":"switchtab","params":[]}},{"pic_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/0f7048ecd1c7d0d30278ca9665beca219ff3e778.png","active_url":"https://chidian.cyyvip.com/web/uploads/images/store_1/2021-10-27/865006703b674a416be49169c691333ae210d055.png","nav_text":"我的","link":{"name":"用户中心","link":"/pages/my/my","id":375,"open_type":"switchtab","params":[]}}]},"moduleCss":{"backgroundColor":"#ffffff","backgroundImage":"","bgImg":"","useBackground":true,"backgroundSize":"100% 100%","backgroundRepeat":"no-repeat"}},{"name":"弹窗","is_show":false,"show_type":"window","controlComName":"widgetPopupControl","params":{"list":[],"rule":1}},{"name":"电话","is_show":true,"show_type":"list","controlComName":"widgetPhoneControl","params":{"phone":"","picUrl":""}},{"name":"微信客服","is_show":true,"show_type":"list","controlComName":"widgetWxControl","params":{"picUrl":""}}]';
- }
- if (\Yii::$app->prod_is_dandianpu()) {
- $self_mini = Option::get('self_mini', get_store_id(), 'store', 0)['value'];
- $is_store_traffic_sharing = Option::get('is_store_traffic_sharing', get_store_id(), 'store', 1)['value'];
- $switch_store = intval(Option::get('one_store_switch_store', 0, 'saas', 0)['value']);
- $is_store_traffic_sharing_switch = false;
- if (intval($is_store_traffic_sharing) && !intval($self_mini) && $switch_store) {
- $is_store_traffic_sharing_switch = true;
- }
- $controls_arr = json_decode($controls, true);
- foreach ($controls_arr as &$control_item) {
- if ($control_item['controlComName'] == 'widgetNavControl') {
- $tab_open = true;
- foreach ($control_item['params']['navList'] as $nav_index => &$nav_item) {
- if (isset($nav_item['tab_type']) && $nav_item['tab_type'] == 'store_sharing') {
- $nav_item['link']['link'] = '/allianceStore/index/index';
- $nav_item['link']['open_type'] = 'navigate';
- if (!$is_store_traffic_sharing_switch) {
- unset($control_item['params']['navList'][$nav_index]);
- }
- $tab_open = false;
- }
- }
- $control_item['params']['navList'] = array_values($control_item['params']['navList']);
- if ($tab_open && $is_store_traffic_sharing_switch) {
- array_push($control_item['params']['navList'], [
- "pic_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/store.png',
- "active_url" => 'https://' . \Yii::$app->request->hostName . '/web/v1/statics/clientImg/shop/storeActive.png',
- "nav_text" => "联盟商家",
- "tab_type" => "store_sharing",
- "link" => [
- "name" => "联盟商家",
- "link" => "/allianceStore/index/index",
- "open_type" => "navigate",
- "params" => [],
- "id" => "9421"
- ]
- ]);
- }
- }
- }
- $controls = json_encode($controls_arr, JSON_UNESCAPED_UNICODE);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '加载成功',
- 'data' => [
- 'list' => $list,
- 'controls' => $controls,
- ]
- ]);
- }
- //获取商城信息
- public function actionGetStore() {
- $longitude = input_params('longitude', '');
- $latitude = input_params('latitude', '');
- $store = Store::find()->alias('s')->where(['s.id' => get_store_id()])
- ->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id')
- ->select('s.id, s.name, s.logo, s.province_id, s.district_id, s.city_id, s.contact_tel mobile, s.address
- , s.shop_time_type, s.s_time, s.e_time, s.open_status, s.coordinate')->asArray()->one();
- $arr = [$store['province_id'], $store['city_id'], $store['district_id']];
- $District = District::find()->where(['id' => $arr])->select('name')->asArray()->column();
- [$store['province'], $store['city'], $store['district']] = $District;
- $store['distance'] = '';
- if (!empty($store['coordinate']) && !empty($longitude) && !empty($latitude)) {
- $coordinate = explode(',', $store['coordinate']);
- $from = [$longitude, $latitude];
- $store['distance'] = $this->distance((new StoreListForm())->get_distance($from, $coordinate, false, 2));
- }
- // $arr = [
- // "id" => 'id',
- // 'name' => '商城名称',
- // 'logo' => 'logo',
- // 'province_id' => '省',
- // 'city_id' => '市',
- // 'district_id' => '区',
- // 'address' => '详细地址',
- // 'mobile' => '电话号码',
- // 'shop_time_type' => '0:默认全天,1:时间段',
- // 's_time' => '开始时间',
- // 'e_time' => '结束时间',
- // 'open_status' => '营业状态,0:打烊,1:营业'
- // ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $store
- ]);
- }
- private static function distance($distance)
- {
- if ($distance == -1) {
- return -1;
- }
- if ($distance > 1000) {
- $distance = round($distance / 1000, 2) . 'km';
- } else {
- $distance .= 'm';
- }
- return $distance;
- }
- public function actionGetMchList(){
- $mchIds = \Yii::$app->request->post('shop_ids');
- $catId = \Yii::$app->request->post('cat_id');
- $lat = \Yii::$app->request->post('latitude');
- $lng = \Yii::$app->request->post('longitude');
- $query = Mch::find()->where(['is_delete' => 0,'store_id' => get_store_id(),'is_open' => Mch::IS_OPEN_TRUE])->select('id,name,logo,address');
- if(!empty($mchIds)){
- $query->andWhere(['id' => explode(',', $mchIds)]);
- }
- if(!empty($catId)){
- $query->andWhere(['mch_common_cat_id' => $catId]);
- }
- if($lat && $lng){
- $queryDis = 'ROUND(st_distance_sphere(point('. $lng .', '. $lat .'), point(longitude, latitude)), 2)';
- $query->addSelect([$queryDis . ' dis']);
- $query->orderBy('dis ASC, sort DESC');
- }
- $list = $query->asArray()->all();
- foreach($list as &$item){
- $item['goodsInfo'] = Goods::find()->where(['mch_id' => $item['id'], 'is_delete' => 0, 'status' => 1])->limit(6)->select('id,name,cover_pic,price,original_price')->asArray()->all();
- if(!isset($item['dis'])){
- $item['dis'] = '未知';
- }else{
- if($item['dis'] > 1000){
- $item['dis'] = round($item['dis'] / 1000, 2) . 'km';
- }else{
- $item['dis'] .= 'm';
- }
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '加载成功',
- 'data' => [
- 'list' => $list
- ]
- ]);
- }
- }
|