| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- <?php
- namespace backend\modules\mall\controllers;
- use backend\controllers\MallController;
- use backend\models\AdminRole;
- use backend\modules\mall\services\TopAddonsService;
- use common\enums\addons\MallAddonsEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\RedisKeyEnum;
- use common\enums\SettingEnum;
- use common\enums\StatusEnum;
- use common\events\mall\AddonsInstallEvent;
- use common\helpers\Auth;
- use common\models\addons\AddonsOrder;
- use common\models\addons\AiTool;
- use common\models\backend\Admin;
- use common\models\common\Addons;
- use common\models\common\PlatformSetting;
- use common\models\common\PosterCode;
- use common\models\mall\MallAddons;
- use common\models\platform\PlatformOrder;
- use common\models\platform\PlatformOrderStatisticsDay;
- use common\models\rbac\AuthItem;
- use common\models\rbac\AuthItemChild;
- use Yii;
- use yii\helpers\Json;
- class AddonsController extends MallController
- {
- // 我的应用
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [[['keyword'], 'string']]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $cate = Yii::$app->params['addonsGroup'];// 获取应用分类
- // 搜索
- if (!empty($params['keyword'])) {
- $addons_names = Addons::getAddonsByTitle($params['keyword'], 'name');
- }
- // 获取用户拥有的应用列表
- $where = ['mall_id' => $this->mall_id,'addons_status' => MallAddonsEnum::INSTALL,'status' => StatusEnum::ENABLED];
- $childWhere = [];
- !empty($addons_names) && $where['addons_name'] = $addons_names;
- $is_compliance = Yii::$app->services->mall->isOpenComplianceMode($this->mall_id);
- $is_compliance && $childWhere = ['<>', 'group', 'business'];
- $list = MallAddons::getMallAddons([$where], ['addons' => function ($query) use ($childWhere) {
- $query->where($childWhere)
- ->select('id,title,name,cover,group,brief_introduction,course_url');
- }], true, 'id,addons_name,expire_time,status');// 获取已上架的应用列表
- // 获取用户有权限的插件
- $valid_addons = self::getUserAuth($list);
- $valid_addons_menu_arr = self::getUserAuthAddonsDefaultMenu($list);
- // 应用重组到分类中
- $data = [];// 返回值初始化
- $time = time();
- $cache = Yii::$app->cache;
- // 获取所有置顶插件
- $top_addons = Yii::$app->services->setting->mall->get($this->mall_id, 'top_addons.addons_name');
- $top_addons = empty($top_addons) ? [] : Json::decode($top_addons);
- foreach ($list as $value) {
- // 已过期的应用则跳过循环
- if ($value['expire_time'] != MallAddonsEnum::EXPIRE && $time >= $value['expire_time']) continue;
- if (is_array($valid_addons) && !in_array($value['addons_name'], $valid_addons)) continue;
- $addons = $value['addons'];
- if (!empty($addons)) {
- // 获取首页链接
- $cache_key = RedisKeyEnum::suffix(RedisKeyEnum::BACKEND_MENU,$addons['name'],true);
- $cacheData = $cache->get($cache_key);
- $url = '';
- if(!empty($cacheData[0]['url'])){
- $url = $cacheData[0]['url'];
- }
- if(!empty($valid_addons_menu_arr[$addons['name']])){
- $url = $valid_addons_menu_arr[$addons['name']];
- }
- $k = $addons['group'];
- $data[$k]['title'] = $cate[$k]['title'];
- $data[$k]['list'][] = [
- 'id' => $value['id'],
- 'title' => $addons['title'],
- 'name' => $addons['name'],
- 'cover' => $addons['cover'],
- 'brief_introduction' => $addons['brief_introduction'],
- 'status' => $time > $value['expire_time'] && $value['expire_time'] != -1 ? 2 : $value['status'],
- 'url' =>$url,
- 'course_url' => $addons['course_url'],
- 'is_top' => in_array($addons['name'], $top_addons) ? 1 : 0, // 是否已置顶
- ];
- }
- }
- $data = $this->getAiToolList($cate,$data);
- $this->success('获取成功', $data);
- }
- }
- $is_compliance = Yii::$app->services->mall->isOpenComplianceMode($this->mall_id);
- return $this->render($this->action->id, ['is_compliance', $is_compliance]);
- }
- public function getAiToolList($cate,$data){
- $static_url = \Yii::$app->services->setting->platform->get('system.static_url');
- $ai_tool_list = AiTool::lists(['where' => [['status' => StatusEnum::ENABLED], ['is_docking' => 0]], 'order' => 'sort asc,id asc']);
- foreach ($ai_tool_list as &$value){
- $value['cover'] = $static_url.$value['cover'];
- }
- $data['aiTool']['title'] = $cate['aiTool']['title'];
- if(isset($data['aiTool']['list'])){
- foreach ($data['aiTool']['list'] as &$val){
- $val['is_docking'] = 1;
- }
- $data['aiTool']['list']= array_merge($data['aiTool']['list'],$ai_tool_list);
- }else{
- $data['aiTool']['list'] = $ai_tool_list;
- }
- return $data;
- }
- // 插件详情
- public function actionDetail()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->get()) {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [[['name'], 'required'], [['name'], 'string']]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $detail = Addons::getOne([['name' => $params['name']], ['is_online' => StatusEnum::ENABLED, 'status' => StatusEnum::ENABLED]], true, ['mallAddons' => function($query){
- $query->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]);
- }]);
- $mallAddons = $detail['mallAddons'] ?? [];
- $time = time();
- // 判断是否已安装该应用[0=否,1=是]
- $isIntall = 1;
- if (empty($mallAddons)) {
- $isIntall = 0;
- } else {
- if ($mallAddons['addons_status'] == MallAddonsEnum::TO_BE_INSTALL) $isIntall = 0;
- }
- $is_renew = $allow_uninstall = $allow_install = 0;
- // 判断是否需要续费
- if ($mallAddons) {
- $expire_time = $mallAddons['expire_time'];
- $is_renew = $expire_time == MallAddonsEnum::EXPIRE ? 0 : 1;
- if ($mallAddons['addons_status'] != MallAddonsEnum::UNINSTALL) {// 非卸载状态下才可以卸载
- $allow_uninstall = $expire_time != MallAddonsEnum::EXPIRE && $expire_time <= $time ? 0 : 1;
- }
- if (in_array($mallAddons['addons_status'], [MallAddonsEnum::UNINSTALL, MallAddonsEnum::TO_BE_INSTALL])) $allow_install = 1;
- }
- $data = [
- 'title' => $detail['title'],
- 'name' => $detail['name'],
- 'cover' => $detail['cover'],
- 'brief_introduction' => $detail['brief_introduction'],
- 'description' => $detail['description'],
- 'payment_type' => $detail['payment_type'],
- 'price_setting' => Json::decode($detail['price_setting'], true),
- 'is_install' => $isIntall,
- 'version' => $mallAddons ? $mallAddons['version'] : $detail['version'],// 商城应用版本号
- 'allow_install' => $allow_install,// 是否允许安装,0=否,1=是
- 'is_renew' => $is_renew,// 续费
- 'expire_time' => $mallAddons['expire_time'] ?? 0,// 过期时间
- 'now_time' => time(),// 当前时间
- 'allow_uninstall' => $allow_uninstall,// 是否允许卸载,0=否,1=是
- ];
- // 插件已过期并且状态不是已过期则将其状态改为已过期
- if (!empty($mallAddons) && $mallAddons['addons_status'] != MallAddonsEnum::EXPIRE) {
- if ($mallAddons['expire_time'] > 0 && $mallAddons['expire_time'] < $time) {
- MallAddons::setData(['mall_id' => $this->mall_id, 'addons_name' => $mallAddons['addons_name'], 'addons_status' => MallAddonsEnum::EXPIRE]);
- }
- }
- $this->success('获取成功', $data);
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 已购应用
- * @Author: lun
- * @DateTime: 2022/2/28 0028 16:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionPurchased()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- $cate = Yii::$app->params['addonsGroup'];// 获取应用分类
- $childWhere = [];
- $is_compliance = Yii::$app->services->mall->isOpenComplianceMode($this->mall_id);
- $is_compliance && $childWhere = ['<>', 'group', 'business'];
- $list = MallAddons::getMallAddons([['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]], ['addons' => function ($query) use ($childWhere) {
- $query->where($childWhere)
- ->select('id,title,name,cover,group,brief_introduction,course_url');
- }], true, 'id,addons_name,expire_time,addons_status,status');// 获取已上架的应用列表
- $data = $addons_list = [];// 返回值初始化
- $time = time();// 当前时间
- $soon_expire_time = 3 * 24 * 60 * 60;// 即将过期时间
- // 获取用户有权限的插件
- $valid_addons = self::getUserAuth($list);
- foreach ($list as $value) {
- // 判断已安装的应用中是否存在已过期的应用,移除此代码可暂时全部应用
- if ($value['addons_status'] == MallAddonsEnum::INSTALL && $value['expire_time'] == MallAddonsEnum::EXPIRE) continue;// 永久有效应用跳过
- if (is_array($valid_addons) && !in_array($value['addons_name'], $valid_addons)) continue;
- $addons = $value['addons'];
- if (!empty($addons)) {
- $k = $addons['group'];
- $addons_list[$k]['title'] = $cate[$k]['title'];
- $addons_list[$k]['list'][] = [
- 'id' => $value['id'],
- 'title' => $addons['title'],
- 'name' => $addons['name'],
- 'cover' => $addons['cover'],
- 'brief_introduction' => $addons['brief_introduction'],
- 'addons_status' => $value['expire_time'] != MallAddonsEnum::EXPIRE && $value['expire_time'] <= $time ? MallAddonsEnum::EXPIRE : $value['addons_status'],
- 'is_renew' => $value['expire_time'] == MallAddonsEnum::EXPIRE ? 0 : 1,// 是否需要续费,0=否,1=是
- 'soon_expire' => $value['expire_time'] > 0 && ($time + $soon_expire_time) > $value['expire_time'] ? 1 : 0,// 即将过期,0=否,1=是
- 'expire_time' => $value['expire_time'],
- 'course_url' => $addons['course_url'],
- ];
- }
- }
- $data['now_time'] = $time;
- $data['addons_list'] = $addons_list;
- $this->success('获取成功', $data);
- } else {
- return $this->render($this->action->id);
- }
- }
- // 应用市场
- public function actionMarket()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [[['keyword'], 'string']]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $cate = Yii::$app->params['addonsGroup'];// 获取应用分类
- // 搜索
- if (!empty($params['keyword'])) {
- $addons_names = Addons::getAddonsByTitle($params['keyword'], 'name');
- }
- $Where = [['is_online' => 1]];
- $is_compliance = Yii::$app->services->mall->isOpenComplianceMode($this->mall_id);
- $is_compliance && $Where[] = ['<>', 'group', 'business'];
- // 获取用户拥有的应用列表
- !empty($addons_names) && $Where[] = ['in', 'name', $addons_names];
- $field = 'id,title,name,cover,group,brief_introduction';
- $list = Addons::getAddons($Where, ['mallAddons' => function($query){
- $query->where(['mall_id' => $this->mall_id]);
- }], true, $field, $this->mall_id);// 获取已上架的应用列表
- // 获取用户有权限的插件
- $valid_addons = self::getUserAuth($list, 'name');
- // 应用重组到分类中
- $data = [];// 返回值初始化
- foreach ($list as $value) {
- // if ($value['mallAddons'] && $value['mallAddons']['status'] == StatusEnum::ENABLED) continue;
- if (is_array($valid_addons) && !in_array($value['name'], $valid_addons)) continue;
- $k = $value['group'];
- $data[$k]['title'] = $cate[$k]['title'];
- $data[$k]['list'][] = [
- 'title' => $value['title'],
- 'name' => $value['name'],
- 'cover' => $value['cover'],
- 'brief_introduction' => $value['brief_introduction'],
- 'is_install' => $value['is_install'],
- ];
- }
- $this->success('获取成功', $data);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- // 安装插件
- public function actionInstall()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [[['name'], 'required'], [['name'], 'string']]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- // 判断商城是否已安装此插件
- $market_addons = Addons::getOne([['name' => $params['name'],'is_online' => 1]], true,['mallAddons' => function($query){
- $query->where(['mall_id' => $this->mall_id,'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- }]);
- if (empty($market_addons['mallAddons'])) return $this->error('您并未购买此应用,请前往购买');
- if ($market_addons['mallAddons']['status'] != StatusEnum::ENABLED) return $this->error('应用已下架,暂不可安装');
- // 安装插入数据
- $params['mall_id'] = $this->mall_id;
- $params['addons_name'] = $params['name'];
- $params['addons_status'] = MallAddonsEnum::INSTALL;
- $res = MallAddons::setData($params);
- if ($res == false) throw new \Exception(MallAddons::getStaticError());
- // 初始化安装插件
- $install_key = "addons\\" . $params['name'] . "\Install";
- $install = new $install_key();
- $install->runApp($this->mall_id, $params['name']);
- // 初始化商城事件
- //Yii::$app->services->events->mallEventBind($params['name'],$this->mall_id);
- // 异步初始化商城
- $event = new AddonsInstallEvent($this->mall_id);
- $install_addons_data = [];
- $install_addons_data['mall_id'] = $this->mall_id;
- $install_addons_data['addons_name'] = $params['addons_name'];
- Yii::$app->services->events->dispatch($event,$install_addons_data,$event->listeners);
- $this->success('安装成功');
- } catch (\Exception $e) {
- $this->error('安装失败,原因:'.$e->getMessage());
- }
- }
- }
- }
- // 卸载插件
- public function actionUninstall()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [[['name'], 'required'], [['name'], 'string']]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- // 判断商城是否已安装此插件
- $market_addons = Addons::getOne([['is_online' => 1]], true,['mallAddons' => function($query){
- $query->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]);
- }]);
- if (empty($market_addons)) return $this->error('暂无插件可卸载');
- // 卸载数据
- $res = MallAddons::Uninstall($this->mall_id, $params['name']);
- if ($res == false) throw new \Exception(MallAddons::getStaticError());
- if ($params['name'] == 'StoreSteward') {
- // 如果卸载插件为门店管家。这删除该商城下所有二维码链接
- PosterCode::updateAll(['applet_code' => ''], ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]);
- }
- $this->success('卸载成功');
- } catch (\Exception $e) {
- $this->error('卸载失败,原因:' . $e->getMessage());
- }
- }
- }
- }
- /**
- * 生成扫码订单
- * @Author: lun
- * @DateTime: 2022/2/25 0025 14:41
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionCreateOrder()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- $params = $request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['name','setting_index'], 'required'],
- [['name'], 'string'],
- [['setting_index'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- // 判断应用是否可购买
- $addons = Addons::getOne([['name' => $params['name'],'is_online' => StatusEnum::ENABLED, 'status' => StatusEnum::ENABLED]], true);
- if (empty($addons)) return $this->error('该应用已下架');
- if (empty($addons['price_setting'][$params['setting_index']])) return $this->error('支付价格有误');
- $price_setting = Json::decode($addons['price_setting'],true);
- // 创建订单
- $addons['consumer_name'] = $this->mall['name'];
- $order = AddonsOrder::createOrder($this->mall_id, $addons, $price_setting[$params['setting_index']]);
- if ($order == false) throw new \Exception(AddonsOrder::getStaticError());
- $data['order'] = $order['order'];
- if ($order['order']['pay_money'] > 0) {
- // 获取交易订单信息
- $trade = Yii::$app->services->pay->getByTradeNo($order['trade']['trade_no']);
- // 获取支付方式
- if (!empty($trade)) {
- $payment_arr = AddonsOrder::getPaymentArr($addons['payment_type'], $trade);
- $data['payment_arr'] = $payment_arr;
- }
- }
- // 修改订单
- $res = AddonsOrder::setData([
- 'id' => $order['order']['order_id'],
- 'out_trade_no' => $order['trade']['trade_no'],
- 'operator_id' => $this->admin->id,
- 'operator_username' => $this->admin->account,
- 'extra_info' => Json::encode(['payment_arr' => $payment_arr ?? []]),
- ]);
- if ($res == false) throw new \Exception(AddonsOrder::getStaticError());
- $this->success('获取成功', $data);
- } catch (\Exception $e) {
- $this->error('文件:' . $e->getFile() . ',第'. $e->getLine() .'行,原因:'. $e->getMessage());
- }
- }
- }
- /**
- * 确认订单
- * @Author: ltm
- * @DateTime: 2022/3/2 0002 9:27
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public function actionConfirmOrder(){
- $request = Yii::$app->request;
- $params = $request->get();
- if ($request->isAjax && $request->isGet) {
- $res = Yii::$app->services->validate->validate($params, [
- [['name','setting_index'], 'required'],
- [['name'], 'string'],
- [['setting_index'], 'integer'],
- [['order_id'],'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 查询插件信息
- $addons = Addons::getOne([['name' => $params['name'],'is_online' => 1]], true);
- $addons['mall_name'] = $this->mall['name'];
- $addons['setting_index'] = $params['setting_index'];
- if (empty($addons)) return $this->error('该应用已下架');
- if (empty($addons['price_setting'][$params['setting_index']])) return $this->error('该应用未开放购买');
- $addons['price_setting'] = Json::decode($addons['price_setting'],true);
- //订单信息
- if($params['order_id']){
- $order = AddonsOrder::getOne([['id'=>$params['order_id'],'status' => StatusEnum::ENABLED]],true);
- $order['mall_name'] = $this->mall['name'];
- if (empty($addons)) return $this->error('订单不存在或已经删除');
- $order['extra_info'] = Json::decode($addons['extra_info'],true);
- $addons['order'] = $order;
- }
- //获取应用服务协议
- $payagreement = PlatformSetting::getConfByGroup(['addons'], true);
- $addons['payagreement'] = $payagreement['addons']['payagreement']['value'];
- $this->success('获取成功', $addons);
- }
- return $this->render($this->action->id);
- }
- /**
- * 关闭订单
- * @Author: lun
- * @DateTime: 2022/3/3 0003 19:48
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- * @throws \Exception
- */
- public function actionOrderClose(){
- $request = Yii::$app->request;
- $params = $request->get();
- if ($request->isAjax && $request->isGet) {
- $res = Yii::$app->services->validate->validate($params, [
- [['id'], 'required'],
- [['id'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 查询插件信息
- try {
- $params['order_status'] = OrderStatusEnum::REPEAL;
- $params['mall_id'] = $this->mall_id;
- $params['close_time'] = time();
- $order = AddonsOrder::setData($params);
- $platformOrder = PlatformOrder::findOne(['order_id' => $params['id']]);
- $platformOrder -> order_status = OrderStatusEnum::REPEAL;
- $platformOrder -> updated_at = time();
- if($platformOrder) $platformOrder->save();
- if ($order == false) throw new \Exception(AddonsOrder::getStaticError());
- // 统计订单数据
- $res = PlatformOrderStatisticsDay::setData([
- 'cancel_order_num' => 1,
- 'cancel_order_money' => $order['order_price'],
- 'cancel_goods_num' => 1,
- ]);
- if ($res == false) throw new \Exception(PlatformOrderStatisticsDay::getStaticError());
- $this->success('操作成功');
- } catch (\Exception $e) {
- $this->error('文件:' . $e->getFile() . ',第'. $e->getLine() .'行,原因:'. $e->getMessage());
- }
- }
- }
- /**
- * @Author: ltm 订单详情
- * @DateTime: 2022/3/3 0003 9:57
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public function actionOrderDetail(){
- $request = Yii::$app->request;
- $params = $request->get();
- if ($request->isAjax && $request->isGet) {
- $res = Yii::$app->services->validate->validate($params, [
- [['order_id'], 'required'],
- [['order_id'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 查询插件信息
- $with = ['addons' => function($query){
- $query->select('title,id,brief_introduction,cover');
- }];
- $addons = AddonsOrder::getOne([['id'=>$params['order_id'],'status' => StatusEnum::ENABLED]],true,$with);
- $addons['mall_name'] = $this->mall['name'];
- if (empty($addons)) return $this->error('订单不存在或已经删除');
- $addons['extra_info'] = Json::decode($addons['extra_info'],true);
- $this->success('获取成功', $addons);
- }
- return $this->render($this->action->id);
- }
- /**
- * @Author: ltm 订单支付
- * @DateTime: 2022/3/2 0002 16:37
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public function actionConfirmPay(){
- $request = Yii::$app->request;
- $params = $request->get();
- if ($request->isAjax && $request->isGet) {
- $res = Yii::$app->services->validate->validate($params, [
- [['order_id'], 'required'],
- [['order_id'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 查询插件信息
- $with = ['addons' => function($query){
- $query->select('title,id,brief_introduction,cover');
- }];
- $addons = AddonsOrder::getOne([['id'=>$params['order_id'],'status' => StatusEnum::ENABLED]],true,$with);
- $addons['mall_name'] = $this->mall['name'];
- if (empty($addons)) return $this->error('订单不存在或已经删除');
- $addons['extra_info'] = Json::decode($addons['extra_info'],true);
- $this->success('获取成功', $addons);
- }
- return $this->render($this->action->id);
- }
- /**
- * 支付成功页面
- * @Author: ltm
- * @DateTime: 2022/3/4 0004 14:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionConfirmSuccess(){
- $request = Yii::$app->request;
- $params = $request->get();
- if ($request->isAjax && $request->isGet) {
- $res = Yii::$app->services->validate->validate($params, [
- [['order_id'], 'required'],
- [['order_id'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 查询插件信息
- $addons = AddonsOrder::getOne([['id'=>$params['order_id'],'status' => StatusEnum::ENABLED]],true);
- $addons['mall_name'] = $this->mall['name'];
- if (empty($addons)) return $this->error('订单不存在或已经删除');
- $addons['extra_info'] = Json::decode($addons['extra_info'],true);
- $this->success('获取成功', $addons);
- }
- return $this->render($this->action->id);
- }
- /**
- * 获取订单列表
- * @Author: lun
- * @DateTime: 2022/3/2 0002 15:21
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionOrderList()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- $params = $request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['datetime'], 'each', 'rule' => ['string']],
- [['order_status'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params = AddonsOrder::exceptNullVal($params);
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- isset($params['order_status']) && $where[] = ['=', 'order_status', $params['order_status']];
- if (!empty($params['datetime'])) {
- $start_time = strtotime($params['datetime'][0]);
- $end_time = strtotime($params['datetime'][1]);
- $where[] = ['between', 'created_at', $start_time, $end_time];
- }
- $with = ['addons' => function($query){
- $query->select("title,name,cover,brief_introduction");
- }];
- $order = 'id desc,created_at desc';
- $select = "id,order_no,addons_name,unit,duration,pay_money,order_price,order_status,pay_status,payment_type,operator_username,expire_time,created_at";
- $params = compact('where','order','select','with');
- $list = AddonsOrder::listPage($params, false, true);
- $this->success('获取成功', $list);
- } else {
- return $this->render($this->action->id);
- }
- }
- // 获取用户有效的插件
- private function getUserAuth($list, $column = 'addons_name')
- {
- // 获取用户权限
- $admin = Yii::$app->user->identity;
- // 超级管理员,管理员无需校验
- if (in_array($admin->admin_type, [Admin::ADMIN_TYPE_SUPER])) 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();
- return $valid_addons;
- }
- private function getUserAuthAddonsDefaultMenu($list, $column = 'addons_name')
- {
- // 获取用户权限
- $admin = Yii::$app->user->identity;
- // 超级管理员,管理员无需校验
- if (in_array($admin->admin_type, [Admin::ADMIN_TYPE_SUPER, Admin::ADMIN_TYPE_AGENT])) return true;
- // 获取角色id
- $role_id = AdminRole::find()->select('role_id')->where(['admin_id' => $admin->id])->scalar();
- // 获取插件名称
- $addons_names = array_column($list, $column);
- $item_id_arr = AuthItem::find()->select('id')->where(['addons_name' => $addons_names ,'is_addon' => 1, 'level' => 2, 'status' => StatusEnum::ENABLED])->column();
- // 获取有效插件
- $valid_addons_list = AuthItemChild::find()->select('*')->where(['role_id' => $role_id, 'item_id' => $item_id_arr])
- ->orderBy('item_id asc')
- ->asArray()->all();
- $valid_addons_menu_arr = [];
- foreach ($valid_addons_list as $val){
- if(!isset($valid_addons_menu_arr[$val['addons_name']])&&strpos($val['name'],'default')!==false){
- $valid_addons_menu_arr[$val['addons_name']] = $val['name'];
- }
- }
- return $valid_addons_menu_arr;
- }
- /**
- * 设置应用置顶
- *
- * @return void
- */
- public function actionToTop()
- {
- if ($this->request->isAjax) {
- $name = $this->request->post('name');
- $service = new TopAddonsService(['mall_id' => $this->mall_id]);
- return $service->setTopAddons($name)
- ? $this->success('ok')
- : $this->error($service->error);
- }
- }
- /**
- * 取消应用置顶
- *
- * @return void
- */
- public function actionToBottom()
- {
- if ($this->request->isAjax) {
- $name = $this->request->post('name');
- $service = new TopAddonsService(['mall_id' => $this->mall_id]);
- return $service->setBottomAddons($name)
- ? $this->success('ok')
- : $this->error($service->error);
- }
- }
- }
|