forked from qmpaas/leadshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWechatController.php
91 lines (82 loc) · 3.41 KB
/
WechatController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace app\controllers;
use app\forms\ImageTools;
use fitment\models\Fitment;
use framework\common\AppAsset;
use Yii;
use yii\web\Controller;
class WechatController extends Controller
{
use ImageTools;
public $layout = false;
/**
* Displays homepage.
* @return string
*/
public function actionIndex()
{
$industry = "wechat";
$alias = 'wechat';
$AppAsset = $this->compiling($industry, $alias, 'uni');
$param = ["AppAsset" => $AppAsset, 'industry' => $industry, 'alias' => $alias];
$cacheKey = 'WECHAT_TABBAR_98c08c25f8136d590c';
$list = \Yii::$app->cache->get($cacheKey);
if ($list) {
return $this->render('index', $list);
}
$data = Fitment::find()->where(['AppID' => '98c08c25f8136d590c', 'keyword' => 'tabbar'])->select('keyword,content')->asArray()->one();
if ($data) {
$tabBar = str2url(to_array($data['content']));
$newBar = [
"color" => $tabBar["inactive_color"],
"selectedColor" => $tabBar["active_color"],
"backgroundColor" => $tabBar["background_color"],
"list" => [
],
];
$temp = Yii::$app->basePath . '/web/static/images/icon';
if (!is_dir($temp)) {
make_dir($temp);
}
foreach ($tabBar["data"] as $k => $item) {
if ($tabBar['tabbarStyle'] == 2) {
$icon = 'icon_' . md5($k) . '.' . $this->getImageExtension($item["iconPath"]);
$iconPath = $temp . $icon;
$this->downloadFile($item["iconPath"], $iconPath);
$this->zoomImage($iconPath, $iconPath);
copy($iconPath, Yii::$app->basePath . '/web/static/images/icon/' . $icon);
$selectIcon = 'select_icon_' . md5($k) . '.' . $this->getImageExtension($item["selectedIconPath"]);
$selectIconPath = $temp . $selectIcon;
$this->downloadFile($item["selectedIconPath"], $selectIconPath);
$this->zoomImage($selectIconPath, $selectIconPath);
copy($selectIconPath, Yii::$app->basePath . '/web/static/images/icon/' . $selectIcon);
$newItem["iconPath"] = '/static/images/icon/' . $icon;
$newItem["selectedIconPath"] = '/static/images/icon/' . $selectIcon;
}
$newItem["pagePath"] = $item["link"]["path"];
$newItem["text"] = $item["text"];
$newBar["list"][] = $newItem;
}
$param['tabBar'] = $newBar;
}
$param['title'] = "Leadshop";
\Yii::$app->cache->set($cacheKey, $param, 60 * 60 * 2);
return $this->render('index', $param);
}
/**
* 处理编译
* @param string $name [description]
* @param string $alias [description]
* @return [type] [description]
*/
public function compiling($name = '', $alias = '', $type = 'uni')
{
$view = \Yii::$app->view;
$config = array('industry' => $name, 'alias' => $alias, 'type' => $type);
$AppAsset = new AppAsset($config);
$am = $AppAsset->getAssetManager();
$AppAsset->publish($am);
$AppAsset->registerAssetFiles($view);
return $AppAsset;
}
}