| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace addons\Community\backend\controllers;
- use addons\Community\common\models\CommunityGoods;
- use addons\Community\common\models\CommunityGoodsSetting;
- use addons\Community\common\models\CommunityHead;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * 默认控制器
- *
- * Class CommunityGoodsController
- * @package addons\Community\backend\controllers
- */
- class CommunityGoodsController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionGetGoodsSetting()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render($this->action->id);
- }
- if (\Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $goods_id = $params['goods_id'] ?? 0;
- $list = [];
- $enable = 0;
- $enable_refund = 0;
- $data = [];
- $supported_logistics = [1, 2];
- if ($goods_id > 0) {
- $setting = CommunityGoodsSetting::getOne([['mall_id' => $this->mall_id], ['goods_id' => $goods_id], ['status' => StatusEnum::ENABLED]], true, [], false, 'enable, supported_logistics, enable_refund');
- $enable = $setting ? $setting['enable'] : $enable;
- $enable_refund = $setting ? $setting['enable_refund'] : $enable_refund;
- $supported_logistics = $setting ? ($setting['supported_logistics'] ? json_decode($setting['supported_logistics'], true) : $supported_logistics) : $supported_logistics;
- $param = [
- 'where' => [['mall_id' => $this->mall_id], ['goods_id' => $goods_id], ['status' => StatusEnum::ENABLED]],
- 'select' => 'community_id'
- ];
- $community_goods = CommunityGoods::lists($param, true);
- $community_ids = array_column($community_goods, 'community_id');
- $community_list = CommunityHead::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['id' => $community_ids],
- ['status' => StatusEnum::ENABLED]
- ],
- 'select' => 'id, province_id, city_id, district_id'
- ], true);
- // do not give up
- foreach ($community_list as $v) {
- !isset($data[$v['province_id']]) && $data[$v['province_id']] = ['id' => $v['province_id'], 'children' => []];
- !isset($data[$v['province_id']]['children'][$v['city_id']]) && $data[$v['province_id']]['children'][$v['city_id']] = ['id' => $v['city_id'], 'children' => []];
- !isset($data[$v['province_id']]['children'][$v['city_id']]['children'][$v['district_id']]) && $data[$v['province_id']]['children'][$v['city_id']]['children'][$v['district_id']] = ['id' => $v['district_id'], 'children' => []];
- $data[$v['province_id']]['children'][$v['city_id']]['children'][$v['district_id']]['children'][] = ['id' => $v['id']];
- }
- $data = array_values($data);
- foreach ($data as $k => $v) {
- foreach ($v['children'] as $key => $value) {
- isset($data[$k]['children'][$key]['children']) && $data[$k]['children'][$key]['children'] = array_values($data[$k]['children'][$key]['children']);
- }
- isset($data[$k]['children']) && $data[$k]['children'] = array_values($data[$k]['children']);
- }
- }
- $list['enable'] = $enable;
- $list['enable_refund'] = $enable_refund;
- $list['list'] = $data;
- $list['supported_logistics'] = $supported_logistics;
- return $this->success('success', $list);
- }
- }
- }
|