| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557 |
- <?php
- namespace backend\modules\mall\controllers;
- use backend\controllers\MallController;
- use backend\modules\mall\services\TopAddonsService;
- use common\enums\RedisKeyEnum;
- use common\helpers\ArrayHelper;
- use common\helpers\CurlHelper;
- use common\models\census\CensusMall;
- use common\models\census\CensusMallGoods;
- use common\models\census\CensusMallPurchasingPower;
- use common\models\census\CensusMallRegion;
- use common\models\census\CensusMallSingleDay;
- use common\models\census\CensusMallUserLevel;
- use common\models\census\CensusMallUserLevelSingleDay;
- use common\models\census\CensusMallUserSource;
- use common\models\notice\Notice;
- use common\models\user\User;
- use Yii;
- use yii\db\Query;
- use common\models\user\UserLevel;
- use common\enums\StatusEnum;
- use common\models\statistics\RegionStatistics;
- use common\models\statistics\GlobalStatistics;
- use common\models\backend\VideoTutorialsLog;
- use common\models\common\PlatformSetting;
- use common\models\backend\Admin;
- use backend\models\AdminRole;
- use common\models\rbac\AuthItem;
- use common\models\rbac\AuthItemChild;
- use common\models\mall\MallHost;
- /**
- * 商城首页
- *
- * @Author bing
- * @DateTime 2021-08-16 13:12:44
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- class OverviewController extends MallController
- {
- /**
- * 数据概况
- * @Author bing
- * @DateTime 2021-08-19 11:33:51
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- public function actionIndexOld()
- {
- if (\Yii::$app->request->isAjax) {
- $statistics = Yii::$app->services->setting->mall->get($this->mall_id, 'index_data');
- if (empty($statistics) || $statistics['status'] == 0) {
- $orderStatistics = Yii::$app->services->statistics->user->get($this->mall_id);
- $globalStatistics = Yii::$app->services->statistics->global->get($this->mall_id);
- $regionStatistics = Yii::$app->services->statistics->region->get($this->mall_id);
- } else {
- RegionStatistics::getDefaultRegion($this->mall_id);
- $regionStatistics = RegionStatistics::setProvinceName(json_decode($statistics['region_data'], true));
- $levels = UserLevel::getListIndexByLevelColumn($this->mall_id);
- //处理生成缓存后新增或删除等级
- $yesterday_upgrade_level = GlobalStatistics::removeLevel(json_decode($statistics['yesterday_upgrade_level'], true), $levels);
- $today_upgrade_level = GlobalStatistics::removeLevel(json_decode($statistics['today_upgrade_level'], true), $levels);
- $globalStatistics = GlobalStatistics::getShowData(['yesterday_upgrade_level' => $yesterday_upgrade_level, 'today_upgrade_level' => $today_upgrade_level], $levels);
- $globalStatistics['today_visitor_num'] = $statistics['today_visitor_num'];
- $globalStatistics['yesterday_visitor_num'] = $statistics['yesterday_visitor_num'];
- $globalStatistics['today_browse_num'] = $statistics['today_browse_num'];
- $globalStatistics['yesterday_browse_num'] = $statistics['yesterday_browse_num'];
- $globalStatistics['today_register_num'] = $statistics['today_register_num'];
- $globalStatistics['total_follow_num'] = $statistics['total_follow_num'];
- $globalStatistics['total_browse_num'] = $statistics['total_browse_num'];
- $globalStatistics['total_visitor_num'] = $statistics['total_visitor_num'];
- $globalStatistics['user_num'] = $statistics['user_num'];
- $orderStatistics['pay_money'] = $statistics['total_money'];
- $orderStatistics['order_num'] = $statistics['order_num'];
- $orderStatistics['pay_num'] = $statistics['pay_num'];
- $orderStatistics['total_money'] = $statistics['total_money'];
- $orderStatistics['today_money'] = $statistics['today_money'];
- }
- $goodsStatistics = Yii::$app->services->statistics->goods->get($this->mall_id, 'desc', 'sales_num');
- $level_list = $globalStatistics['level_list'];
- array_walk($regionStatistics, function (&$region) {
- $region['parent_id'] = 1;
- $region['level'] = 'province';
- });
- //会员来源数据整理
- $usersource = User::$sources;
- $soure = (array)$orderStatistics['source'];
- $soure_data = [];
- if($soure){
- foreach ($soure as $k => $v){
- $soure_item = [];
- $soure_item['name'] = $usersource[$k];
- $soure_item['num'] = $v;
- $soure_data[] = $soure_item;
- }
- }
- $min_num_source = count($soure_data);
- if($min_num_source<3){ //因为是平面图,最低要求三条数据
- $num_source = 3 - $min_num_source;
- $array_source_key = array_keys($soure);
- foreach ($usersource as $k => $v){
- if(!in_array($k,$array_source_key)){
- $soure_item['name'] = $v;
- $soure_item['num'] = 0;
- $soure_data[] = $soure_item;
- $num_source --;
- if($num_source<=0){
- break;
- }
- }
- }
- }
- //系统通知
- $notice_where[] = ['=','status',StatusEnum::ENABLED];
- $notice = Notice::lists(['where' => $notice_where,'order' => 'id desc','limit' => 8],true);
- $list = [
- "today_visitor_num" => $globalStatistics['today_visitor_num'],
- "yesterday_visitor_num" => $globalStatistics['yesterday_visitor_num'],
- "visitor_proportion" => $this->conversion($globalStatistics['today_visitor_num'], $globalStatistics['yesterday_visitor_num']),
- "today_browse_num" => $globalStatistics['today_browse_num'],
- "yesterday_browse_num" => $globalStatistics['yesterday_browse_num'],
- "browse_proportion" => $this->conversion($globalStatistics['today_browse_num'], $globalStatistics['yesterday_browse_num']),
- "level_list" => $level_list,
- "total_transactions" => (int)$orderStatistics['total_money'] ?? 0, //总交易额
- "update_time" => time(), //截止时间
- "today_earnings" => $orderStatistics['today_money'] ? round($orderStatistics['today_money'], 2) : 0, //今日收益, 支付统计
- "add_user" => (int)$globalStatistics['today_register_num'], //今日新增用户
- "user_sum" => (int)$globalStatistics['user_num'], //总用户数
- "province_list" => $regionStatistics,
- "conversion_browse_num" => $globalStatistics['total_browse_num'] ? round($globalStatistics['total_browse_num'], 2) : 0, //转化率-浏览量(总)
- "conversion_visitor_num" => $globalStatistics['total_visitor_num'] ? round($globalStatistics['total_visitor_num'], 2) : 0, //转化率-访问量(总)
- "follow_num" => $globalStatistics['total_follow_num'] ? round($globalStatistics['total_follow_num'], 2) : 0, //转化率-关注数(总)
- // "browse_visitor_proportion" => 5050,
- // "visitor_follow_proportion" => 100,
- // "browse_follow_proportion" => 100,
- "purchasing_power" => (array)$orderStatistics['buy'],
- "user_source" => $soure_data,
- "order_visit_num" => $globalStatistics['total_visitor_num'] ?? 0, //下单统计-访问量(总)
- "order_num" => $orderStatistics['order_num'], //下单统计-下单量(总)
- "pay_num" => $orderStatistics['pay_num'], //下单统计-支付数(总)
- // "visit_order_proportion" => 100,
- // "order_pay_proportion" => 100,
- // "visit_pay_proportion" => 100,
- "goods_list" => $goodsStatistics,
- "notice" => $notice,
- "forum" => []
- ];
- return $this->success('操作成功', $list);
- }
- return $this->render($this->action->id);
- }
- //2022-4-23,取数据统计缓存
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- $statistics = Yii::$app->services->setting->mall->get($this->mall_id, 'index_data');
- if (empty($statistics) || $statistics['status'] == 0) {
- $regionStatistics = CensusMallRegion::getMallRegion($this->mall_id);
- $data_cache = $this->getCensusMallCache($this->mall_id);
- if(!isset($data_cache['total_users'])) $data_cache = $this->getCensusMall($this->mall_id);
- $total_users = $data_cache['total_users']??0;
- if(!isset($data_cache['total_pay_money'])) $data_cache = $this->getCensusMall($this->mall_id);
- $total_pay_money = $data_cache['total_pay_money']??0;
- if(!isset($data_cache['total_orders'])) $data_cache = $this->getCensusMall($this->mall_id);
- $order_num = $data_cache['total_orders']??0;
- if(!isset($data_cache['total_pay_orders'])) $data_cache = $this->getCensusMall($this->mall_id);
- $pay_num = $data_cache['total_pay_orders']??0;
- if(!isset($data_cache['total_visitors'])) $data_cache = $this->getCensusMall($this->mall_id);
- $total_visitor_num = $data_cache['total_visitors']??0;
- if(!isset($data_cache['total_views'])) $data_cache = $this->getCensusMall($this->mall_id);
- $total_browse_num = $data_cache['total_views']??0;
- if(!isset($data_cache['total_follow_num'])) $data_cache = $this->getCensusMall($this->mall_id);
- $total_follow_num = $data_cache['total_follow_num']??0;
- //当天数据
- $date = date('Y-m-d');
- // $today_data_cache = $this->getCensusMallSingleDayCache($this->mall_id,$date);
- // if(!isset($today_data_cache['total_pay_money']))
- $today_data_cache = $this->getCensusMallSingleDay($this->mall_id,$date);
- $today_total_pay_money = $today_data_cache['total_pay_money']??0;
- if(!isset($today_data_cache['add_users'])) $today_data_cache = $this->getCensusMallSingleDay($this->mall_id,$date);
- $today_add_users = $today_data_cache['add_users']??0;
- if(!isset($today_data_cache['total_visitors'])) $today_data_cache = $this->getCensusMallSingleDay($this->mall_id,$date);
- $today_visitor_num = $today_data_cache['total_visitors']??0;
- if(!isset($today_data_cache['total_views'])) $today_data_cache = $this->getCensusMallSingleDay($this->mall_id,$date);
- $today_browse_num = $today_data_cache['total_views']??0; //今日浏览量
- //昨天数据
- $date = date('Y-m-d',strtotime('-1 day'));
- $yesterday_data_cache = $this->getCensusMallSingleDayCache($this->mall_id,$date);
- if(!isset($yesterday_data_cache['total_visitors'])) $yesterday_data_cache = $this->getCensusMallSingleDay($this->mall_id,$date);
- $yesterday_visitor_num = $yesterday_data_cache['total_visitors']??0;
- if(!isset($yesterday_data_cache['total_views'])) $yesterday_data_cache = $this->getCensusMallSingleDay($this->mall_id,$date);
- $yesterday_browse_num = $yesterday_data_cache['total_views']??0;
- $levels = UserLevel::getListIndexByLevelColumn($this->mall_id);
- $level_list = [];
- $today = CensusMallUserLevelSingleDay::lists(['where'=>[['mall_id'=>$this->mall_id],['date'=>date('Y-m-d',time())]],'index'=>'level']);
- $yesterday = CensusMallUserLevelSingleDay::lists(['where'=>[['mall_id'=>$this->mall_id],['date'=>date('Y-m-d',strtotime('-1 days'))]],'index'=>'level']);
- foreach ($levels as $level=>$name){
- $today_num = 0;
- $yesterday_num = 0;
- if(isset($today[$level])) $today_num = $today[$level]['numbers'];
- if(isset($yesterday[$level])) $yesterday_num = $yesterday[$level]['numbers'];
- $proportion = 100;
- if(!empty($yesterday_num)){
- $proportion = ($today_num - $yesterday_num)/$yesterday_num * 100;
- }else{
- if(empty($today_num)) $proportion = 0;
- }
- $row =[
- 'id'=>$level,
- 'name'=>$name,
- 'proportion'=>$proportion,
- 'today_num'=>$today_num,
- 'yesterday_num'=>$yesterday_num,
- ];
- $level_list[]=$row;
- }
- $goods_list = CensusMallGoods::getMallGoodsList($this->mall_id);
- } else {
- RegionStatistics::getDefaultRegion($this->mall_id);
- $levels = UserLevel::getListIndexByLevelColumn($this->mall_id);
- //处理生成缓存后新增或删除等级
- $yesterday_upgrade_level = GlobalStatistics::removeLevel(json_decode($statistics['yesterday_upgrade_level'], true), $levels);
- $today_upgrade_level = GlobalStatistics::removeLevel(json_decode($statistics['today_upgrade_level'], true), $levels);
- $globalStatistics = GlobalStatistics::getShowData(['yesterday_upgrade_level' => $yesterday_upgrade_level, 'today_upgrade_level' => $today_upgrade_level], $levels);
- $regionStatistics = RegionStatistics::setProvinceName(json_decode($statistics['region_data'], true));
- $total_users = $statistics['user_num'];
- $total_pay_money = $statistics['total_money'];
- $order_num = $statistics['order_num'];
- $pay_num = $statistics['pay_num'];
- $today_total_pay_money = $statistics['today_money'];
- $today_add_users = $statistics['today_register_num'];
- $today_visitor_num = $statistics['today_visitor_num'];
- $yesterday_visitor_num = $statistics['yesterday_visitor_num'];
- $today_browse_num = $statistics['today_browse_num'];
- $yesterday_browse_num = $statistics['yesterday_browse_num'];
- $total_follow_num = $statistics['total_follow_num'];
- $total_browse_num = $statistics['total_browse_num'];
- $total_visitor_num = $statistics['total_visitor_num'];
- $level_list = $globalStatistics['level_list'];
- $goods_list = [];
- if(isset($statistics['goods_list'])){
- $goods_rows = json_decode($statistics['goods_list'],true);
- if(!empty($goods_rows) && is_array($goods_rows)){
- $goods_list = ArrayHelper::arraySorts($goods_rows,'sales_num','desc');
- }
- }
- }
- //不受虚拟数据影响
- $purchasing_power = CensusMallPurchasingPower::getMallUserPower($this->mall_id);
- $user_source = CensusMallUserSource::getMallUserSource($this->mall_id);
- array_walk($regionStatistics, function (&$region) {
- $region['parent_id'] = 1;
- $region['level'] = 'province';
- });
- //系统通知
- $notice_where[] = ['=','status',StatusEnum::ENABLED];
- $notice = Notice::lists(['where' => $notice_where,'order' => 'id desc','limit' => 8],true);
- $list = [
- "today_visitor_num" => $today_visitor_num,
- "yesterday_visitor_num" => $yesterday_visitor_num,
- "visitor_proportion" => $this->conversion($today_visitor_num, $yesterday_visitor_num),
- "today_browse_num" => $today_browse_num,
- "yesterday_browse_num" => $yesterday_browse_num,
- "browse_proportion" => $this->conversion($today_browse_num, $yesterday_browse_num),
- "level_list" => $level_list,
- "total_transactions" => (int)$total_pay_money, //总交易额
- "update_time" => time(), //截止时间
- "today_earnings" =>$today_total_pay_money, //今日收益, 支付统计
- "add_user" => (int)$today_add_users, //今日新增用户
- "user_sum" => (int)$total_users, //总用户数
- "province_list" => $regionStatistics,
- "conversion_browse_num" => $total_browse_num, //转化率-浏览量(总)
- "conversion_visitor_num" => $total_visitor_num, //转化率-访问量(总)
- "follow_num" => $total_follow_num, //
- "purchasing_power" =>$purchasing_power,
- "user_source" => $user_source,
- "order_visit_num" => $total_visitor_num, //下单统计-访问量(总)
- "order_num" => $order_num, //下单统计-下单量(总)
- "pay_num" => $pay_num, //下单统计-支付数(总)
- "goods_list" => $goods_list,
- "notice" => $notice,
- "forum" => []
- ];
- $video_tutorials_map = PlatformSetting::getConfByGroup('video_tutorial', true);
- $video_tutorials=\Yii::$app->params['video_tutorial'];
- foreach ($video_tutorials as &$item){
- if(isset($video_tutorials_map['type'.$item['id']])){
- $value = json_decode($video_tutorials_map['type'.$item['id']]['value'],true);
- $item['name'] = $value['name'];
- $item['url'] = $value['url'];
- }
- }
- $list['video_tutorials'] = $video_tutorials;
- $res = VideoTutorialsLog::findOne(['admin_id'=>$this->admin['id'],'video_tutorials_id'=>1,'is_complete'=>1]);
- $is_watch_first_video_tutorial =0;
- if(!empty($res)){
- $is_watch_first_video_tutorial = 1;
- }
- $list['is_watch_first_video_tutorial'] =$is_watch_first_video_tutorial;
- $contact_tel = \Yii::$app->services->setting->platform->get('system.contact_tel');
- $is_show_video_tutorials = \Yii::$app->services->setting->platform->get('system.is_show_video_tutorials');
- if(!empty($this->mall['contact_tel'])) $contact_tel =$this->mall['contact_tel'];
- $list['contact_tel']=$contact_tel;
- $list['is_show_video_tutorials'] = empty($is_show_video_tutorials) ? 0 : $is_show_video_tutorials;
- return $this->success('操作成功', $list);
- }
- return $this->render($this->action->id);
- }
- protected function getCensusMallCache($mall_id){
- $key = RedisKeyEnum::CENSUS_MALL;
- $redis_key = RedisKeyEnum::suffix($key, '', true) . ':' . $mall_id;
- $data_cache = Yii::$app->redis->hgetall($redis_key);
- $data = [];
- if($data_cache){
- foreach ($data_cache as $k=>$v){
- if($k%2==0)$data[$v] = $data_cache[$k+1];
- }
- }
- return $data;
- }
- protected function getCensusMall($mall_id){
- return CensusMall::getOne([['mall_id'=>$mall_id], ['status' => StatusEnum::ENABLED]],true);
- }
- protected function getCensusMallSingleDayCache($mall_id,$date){
- $key = RedisKeyEnum::CENSUS_MALL_SINGLE_DATE;
- $redis_key = RedisKeyEnum::suffix($key, '', true) . ':' . $mall_id.':' . $date;
- $data_cache = Yii::$app->redis->hgetall($redis_key);
- $data = [];
- if($data_cache){
- foreach ($data_cache as $k=>$v){
- if($k%2==0)$data[$v] = $data_cache[$k+1];
- }
- }
- return $data;
- }
- protected function getCensusMallSingleDay($mall_id,$date){
- return CensusMallSingleDay::getOne([['mall_id'=>$mall_id],['date'=>$date]],true);
- }
- /**
- * 商城基本数据
- * @Author bing
- * @DateTime 2021-08-19 18:30:28
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- public function actionMallHeader()
- {
- $admin = Yii::$app->user->identity;
-
- $user = array(
- 'id' => $admin->id,
- 'mch_id' => $admin->mch_id,
- 'username' => $admin->username,
- 'admin_type' => $admin->admin_type,
- 'source' => $admin->source,
- );
- $mall = array(
- 'id' => $this->mall['id'],
- 'name' => $this->mall['name'],
- 'sign' => $this->mall['mall_sign'],
- );
- $services = Yii::$app->services->setting->platform->get('system');
- //获取商城设置的域名
- $mall_host = MallHost::findOne(['mall_id' => $this->mall_id]);
- if (!empty($mall_host)) {
- //h5链接不为空,覆盖总站点h5链接
- if (!empty($mall_host['h5_url']) && $mall_host['is_custom_host'] == 1) {
- if (strpos($mall_host['h5_url'], 'https') !== false || strpos($mall_host['h5_url'], 'http') !== false) {
- $services['h5_url'] = $mall_host['h5_url'];
- } else {
- $services['h5_url'] = 'https://' . $mall_host['h5_url'];
- }
- }
- }
- $update_password_status = Yii::$app->services->setting->mall->get('basic.update_password_status');
- $navs = [];
- // 置顶应用
- $service = new TopAddonsService(['mall_id' => $this->mall_id]);
- $navs = $service->getAddonsNavs();
- // print_r($navs);exit;
- //不显示没有权限的置顶应用
- $valid_addons = self::getUserAuth($navs); //获取有权限的置顶应用名
- if (!empty($navs)) {
- foreach ($navs as $key => $value) {
- if (is_array($valid_addons) && !in_array($value['name'], $valid_addons)) unset($navs[$key]);//对比全部置顶应用,删除没有权限的应用数据
- }
- }
- // print_r($navs);exit;
- // print_r($valid_addons);exit;
- return $this->success('操作成功', compact('user', 'mall', 'services', 'update_password_status', 'navs'));
- }
- public function actionTest()
- {
- return $this->render('test');
- }
- /**
- * 求2个值直接的百分比差距
- */
- public function conversion($num1, $num2)
- {
- $res = 100;
- if(!empty($num2)) {
- $res = ($num1 - $num2)/$num2 * 100;
- }else{
- if(empty($num1)) $res = 0;
- }
- return $res;
- }
- // 概况首页
- public function actionDirveWindow()
- {
- return $this->render($this->action->id);
- }
- // 用户数据
- public function actionUserData()
- {
- return $this->render($this->action->id);
- }
- // 用户数据
- public function actionSalesData()
- {
- return $this->render($this->action->id);
- }
- // 价值分析
- public function actionAnalysis()
- {
- return $this->render($this->action->id);
- }
- // 流量分析
- public function actionFlowAnalysis()
- {
- return $this->render($this->action->id);
- }
- // 交易数据
- public function actionTransactionData()
- {
- return $this->render($this->action->id);
- }
- // 商品数据
- public function actionCommodityData()
- {
- return $this->render($this->action->id);
- }
- //修改密码
- public function actionUpdatePassword(){
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['old_pass','new_pass','check_pass'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if($params['new_pass']!=$params['check_pass']) return $this->error('新密码和确认密码不一致');
- if(!$this->admin->validatePassword($params['old_pass'])){
- return $this->error('旧密码不正确');
- }
- $this->admin->password = Yii::$app->security->generatePasswordHash($params['new_pass']);
- $res = $this->admin->save();
- if ($res === false) return $this->error('修改密码失败');
- return $this->success('操作成功');
- }
- public function actionAddVideoTutorialsLog(){
- try {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['video_tutorials_id','is_complete','view_times'], 'required'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['admin_id'] = $this->admin['id']??0;
- VideoTutorialsLog::addVideoTutorialsLog($params);
- return $this->success('操作成功');
- }catch (\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- /**
- * 获取智能客服地址
- * @Author: lun
- * @DateTime: 2023/8/17 0017 10:56
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionGetAiService()
- {
- try {
- $params['id'] = str_replace('.','',$_SERVER['SERVER_ADDR']) . '_'. $this->mall_id;
- $params['name'] = $this->mall['name'] ?? '';
- $default_avatar = Yii::$app->services->setting->platform->get('system.backend_url') . '/resources/img/admin/mall-logo.png';
- $mall_avatar = Yii::$app->services->setting->mall->get($this->mall_id, 'basic.logo');
- $params['avatar'] = empty($mall_avatar) ? $default_avatar : $mall_avatar;
- $header['Content-Type'] = 'application/x-www-form-urlencoded';
- $url = 'http://middle-api.qijianshigw.com/ai-customer-service/chat/get-url';
- $data[] = CurlHelper::postJson($url, $params);
- $data = current($data);
- $data = $data['data'];
- $url = $data['base'] .'?service='. $data['service'] .'&token='. $data['token'];
- return $this->success('操作成功', $url);
- }catch (\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- // 获取用户有效的插件
- private function getUserAuth($list, $column = 'name')
- {
- // 获取用户权限
- $admin = Yii::$app->user->identity;
- // 超级管理员,管理员无需校验
- if (in_array($admin->admin_type, [Admin::ADMIN_TYPE_SUPER, Admin::ADMIN_TYPE_AGENT])) return true;
- // 商场管理员无需校验
- if (Yii::$app->services->rbacAuthRole->isMallAdmin()) return true;
- // 获取角色id
- $role_id = AdminRole::find()->select('role_id')->where(['admin_id' => $admin->id])->scalar();
- // 获取插件名称
- $addons_names = array_column($list, $column);
- $item_ids = AuthItem::getAddonsItemIds($addons_names);// 获取插件对应的权限路径item_id
- // 获取有效插件
- $valid_addons = AuthItemChild::find()->select('addons_name')->where(['role_id' => $role_id, 'item_id' => $item_ids])->column();
- // print_r($valid_addons);exit;
- return $valid_addons;
- }
- }
|