| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- <?php
- /**
- * Created by PhpStorm.
- * User: blank
- * Date: 2018/11/28
- * Time: 13:56
- */
- namespace app\backend\modules\member\controllers;
- use app\backend\modules\income\Income;
- use app\common\components\BaseController;
- use app\common\exceptions\ShopException;
- use app\common\facades\Setting;
- use app\common\helpers\Url;
- use app\common\models\Menu;
- use app\common\services\popularize\PopularizePageShowFactory;
- class PopularizePageShowController extends BaseController
- {
- /**
- * 加载模板
- * @return string
- * @throws \Throwable
- */
- public function index()
- {
- return view('member.popularize.index', [])->render();
- }
- //微信
- public function wechatSet()
- {
- $info = Setting::get("popularize.wechat");
- $set = request()->input('set');
- if (!empty($set)) {
- foreach ($set['plugin'] as $key => $value) {
- $set[$key] = $value;
- }
- unset($set['plugin']);
- if (Setting::set("popularize.wechat", $set)) {
- return $this->successJson('保存成功', ['data' => true]);
- } else {
- throw new ShopException('保存失败');
- }
- }
- return $this->successJson('ok', $this->getResult($info));
- }
- //微信小程序
- public function miniSet()
- {
- $info = Setting::get("popularize.mini");
- $set = request()->input('set');
- if (!empty($set)) {
- foreach ($set['plugin'] as $key => $value) {
- $set[$key] = $value;
- }
- unset($set['plugin']);
- if (Setting::set("popularize.mini", $set)) {
- return $this->successJson('保存成功', ['data' => true]);
- } else {
- throw new ShopException('保存失败');
- }
- }
- $info['min-app'] = 1;
- return $this->successJson('ok', $this->getResult($info, 1));
- }
- //手机浏览器 pc
- public function wapSet()
- {
- $info = Setting::get("popularize.wap");
- $set = request()->input('set');
- if (!empty($set)) {
- foreach ($set['plugin'] as $key => $value) {
- $set[$key] = $value;
- }
- unset($set['plugin']);
- if (Setting::set("popularize.wap", $set)) {
- return $this->successJson('保存成功', ['data' => true]);
- } else {
- throw new ShopException('保存失败');
- }
- }
- return $this->successJson('ok', $this->getResult($info));
- }
- //app
- public function appSet()
- {
- $info = Setting::get("popularize.app");
- $set = request()->input('set');
- if (!empty($set)) {
- foreach ($set['plugin'] as $key => $value) {
- $set[$key] = $value;
- }
- unset($set['plugin']);
- if (Setting::set("popularize.app", $set)) {
- return $this->successJson('保存成功', ['data' => true]);
- } else {
- throw new ShopException('保存失败');
- }
- }
- return $this->successJson('ok', $this->getResult($info));
- }
- //支付宝
- public function alipaySet()
- {
- $info = Setting::get("popularize.alipay");
- $set = request()->input('set');
- if (!empty($set)) {
- foreach ($set['plugin'] as $key => $value) {
- $set[$key] = $value;
- }
- unset($set['plugin']);
- if (Setting::set("popularize.alipay", $set)) {
- return $this->successJson('保存成功', ['data' => true]);
- } else {
- throw new ShopException('保存失败');
- }
- }
- return $this->successJson('ok', $this->getResult($info));
- }
- /**
- * 获取商城开启的插件
- * @return array 开启的插件页面路由与名称
- */
- protected function getData()
- {
- $lang_set = $this->getLangSet();
- $config = $this->getIncomePageConfig();
- $plugins = $this->getPlugins();
- foreach ($config as $key => $item) {
- $incomeFactory = new PopularizePageShowFactory(new $item['class'], $lang_set);
- if ($plugins[$incomeFactory->getMark()]) {
- $array[] = [
- 'url' => $plugins[$incomeFactory->getMark()],
- 'title' => $incomeFactory->getTitle(),
- 'mark' => $incomeFactory->getMark(),
- 'status' => is_array($plugins[$incomeFactory->getMark()]) ? 1 : 0,
- 'type' => $item['type']
- ];
- } else {
- $array[] = [
- 'url' => $incomeFactory->getAppUrl(),
- 'title' => $incomeFactory->getTitle(),
- 'mark' => $incomeFactory->getMark(),
- 'status' => 0,
- 'type' => $item['type']
- ];
- }
- }
- return $array;
- }
- //当收入页面显示的前端路由有两个时,需要在把俩个路由都添加进来
- // \Config::set(['popularize_page_show.收入页面类的getMark()方法返回的值' => 路由数组);
- protected function getPlugins()
- {
- $popularize_page_show = [
- 'area_dividend' => 'regionalAgencyCenter',
- 'store_cashier' => 'cashier',
- 'store_withdraw' => 'storeManage',
- 'hotel_cashier' => 'HotelCashier',
- 'hotel_withdraw' => 'HotelManage',
- 'merchant' => 'enterprise_index',
- 'micro' => 'microShop_ShopKeeperCenter',
- ];
- $plugin = \app\common\modules\shop\ShopConfig::current()->get('popularize_page_show') ?: [];
- return array_merge($popularize_page_show, $plugin);
- }
- /**
- * 生成js文件给前端用
- */
- protected function toJson()
- {
- //放弃使用这个方法,原因无法匹配多个公众号
- return;
- $all_set = Setting::getByGroup("popularize");
- $data = [
- 'wechat' => [
- 'vue_route' => !empty($all_set['wechat']['vue_route']) ? $all_set['wechat']['vue_route'] : [],
- 'url' => !empty($all_set['wechat']['callback_url']) ? $all_set['wechat']['callback_url'] : '',
- ],
- 'mini' => [
- 'vue_route' => !empty($all_set['mini']['vue_route']) ? $all_set['mini']['vue_route'] : [],
- 'url' => !empty($all_set['mini']['callback_url']) ? $all_set['mini']['callback_url'] : '',
- ],
- 'wap' => [
- 'vue_route' => !empty($all_set['wap']['vue_route']) ? $all_set['wap']['vue_route'] : [],
- 'url' => !empty($all_set['wap']['callback_url']) ? $all_set['wap']['callback_url'] : '',
- ],
- 'app' => [
- 'vue_route' => !empty($all_set['app']['vue_route']) ? $all_set['app']['vue_route'] : [],
- 'url' => !empty($all_set['app']['callback_url']) ? $all_set['app']['callback_url'] : '',
- ],
- 'alipay' => [
- 'vue_route' => !empty($all_set['alipay']['vue_route']) ? $all_set['alipay']['vue_route'] : [],
- 'url' => !empty($all_set['alipay']['callback_url']) ? $all_set['alipay']['callback_url'] : '',
- ],
- ];
- $string = json_encode($data);
- $sj = date('Y-m-d H:i:s', time());
- $json_str = <<<json
- //update $sj
- let popularize = {$string};
- if (typeof define === "function") {
- define(popularize)
- } else {
- window.\$popularize = popularize;
- }
- json;
- $path = 'static' . DIRECTORY_SEPARATOR . 'yunshop' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'popularize' . DIRECTORY_SEPARATOR;
- $absolute_file = $path . 'popularize_' . \YunShop::app()->uniacid . '.js';
- // 生成目录
- if (!is_dir(base_path($path))) {
- mkdir(base_path($path), 0777);
- }
- return file_put_contents(base_path($absolute_file), $json_str);
- }
- /**
- * 收入页面配置 config
- *
- * @return mixed
- */
- private function getIncomePageConfig()
- {
- return Income::current()->getPageItems();
- }
- /**
- * 获取商城中的插件名称自定义设置
- *
- * @return mixed
- */
- private function getLangSet()
- {
- $lang = \Setting::get('shop.lang', ['lang' => 'zh_cn']);
- return $lang[$lang['lang']];
- }
- private function getItems()//获取所有插件
- {
- $config = \app\backend\modules\income\Income::current()->getPageItems();//获取所有插件
- $data = [];
- foreach ($config as $key => $item) {
- $incomeFactory = new $item['class'];
- $data[$key]['value'] = $incomeFactory->getMark();//获取收类型的名称
- $data[$key]['name'] = $incomeFactory->getTitle();
- }
- return $data;
- }
- public function getPluginType()
- {
- return [
- 'dividend' => '入口类',
- 'industry' => '行业类',
- 'marketing' => '营销类',
- 'business_management' => '企业管理类',
- 'tool' => '工具类',
- 'recharge' => '生活充值',
- 'api' => '接口类',
- 'store' => '门店应用类',
- 'blockchain' => '区块链类',
- ];
- }
- public function setArray($info)
- {
- $array = $this->getData();
- foreach ($array as $value) {
- if ($value['type'] == 'dividend') {
- $dividend[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'industry') {
- $industry[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'marketing') {
- $marketing[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'business_management') {
- $business_management[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'tool') {
- $tool[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'recharge') {
- $recharge[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'api') {
- $api[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'store') {
- $store[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- if ($value['type'] == 'blockchain') {
- $blockchain[] = [
- 'url' => $value['url'],
- 'name' => $value['title'],
- 'type' => $value['type'],
- 'status' => in_array($value['url'], $info['vue_route']) ? 1 : 0,
- 'mark' => $value['mark']
- ];
- }
- }
- $not_plugin = [
- 'dividend' => $dividend,
- 'industry' => $industry,
- 'marketing' => $marketing,
- 'business_management' => $business_management,
- 'tool' => $tool,
- 'recharge' => $recharge,
- 'api' => $api,
- 'store' => $store,
- 'blockchain' => $blockchain
- ];
- return $not_plugin;
- }
- public function getResult($info, $item = 0)
- {
- $not_plugin = $this->setArray($info);
- $array1 = $this->getItems();
- foreach ($array1 as $v) {
- $plugin[] = [
- 'status' => !empty($info[$v['value']]) ? $info[$v['value']] : 0,
- 'name' => $v['name'],
- 'value' => $v['value'],
- ];
- }
- $basics = [
- 'background_color' => $info['background_color'],
- 'callback_url' => $info['callback_url'],
- 'is_show_unable' => $info['is_show_unable'],
- 'show_member_id' => $info['show_member_id'],
- 'extension' => in_array('extension', $info['vue_route']) ? 1 : 0,
- 'not_plugin' => $not_plugin,
- 'plugin_type' => $this->getPluginType()
- ];
- if ($item == 1) {
- $basics['small_extension_link'] = $info['small_extension_link'];
- }
- return [
- 'plugin' => $plugin,
- 'basics' => $basics,
- ];
- }
- }
|