Blame view

app-wx/controllers/SiteController.php 5.26 KB
62d73041   xu   app-wx
1
2
3
4
<?php
namespace app\wx\controllers;

use Yii;
62d73041   xu   app-wx
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
use app\wx\models\Engineer;
use common\models\EngineerProfile;
use common\helpers\WxHelper;
use common\models\SysSetting;

use stdClass;

/**
 * Site-控制器
 * Class SiteController
 * @package app\wx\controllers
 */
class SiteController extends BaseController
{
    public $layout = 'site';

    /**
     * @param yii\base\Action $action
     * @return bool
     * @throws yii\web\BadRequestHttpException
     */
    public function beforeAction($action)
    {
        $view = Yii::$app->view;
        $view->params['site']= $this->site;

        //$this->handleMallAccessCtrl();
        return parent::beforeAction($action);
    }

    /**
     * @return string
     * @return string HTML
7d60e23d   xu   app-wx(v0.1.0 bui...
38
     */
62d73041   xu   app-wx
39
40
41
    public function actionIndex()
    {
        //获取当前用户的模型model
7d60e23d   xu   app-wx(v0.1.0 bui...
42
        $engineerId = $this->getEngineerId();
62d73041   xu   app-wx
43
44
45
        $engineer = new stdClass();
        /**
         * 构造user的共用信息
62d73041   xu   app-wx
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
         */
        $engineer = $this->buildEngineerResult($engineerId);

        return $this->render('index',
            [
                'engineer' => $engineer,
            ]
        );
    }

    private function buildEngineerResult($engineerId)
    {
        $query  = Engineer::find()
            ->select(['engineer.id', 'engineer_profile.headimgurl','engineer_profile.nickname'])
            ->leftJoin('engineer_profile', "engineer.id = engineer_profile.engineer_id")
            ->where(['engineer.id' => $engineerId]);
        $query->asArray();
        $engineerArray = $query->one();

        if(empty($engineerArray)){
            return false;
        }

        $engineer = new stdClass();
        $engineer->id = (int)$engineerArray['id'];
7d60e23d   xu   app-wx(v0.1.0 bui...
71
72
        $engineer->headimgurl = $engineerArray['headimgurl'];
        $engineer->nickname = $engineerArray['nickname'];
62d73041   xu   app-wx
73
74
75
76
77
78
79
80
81
        return $engineer;
    }


    /**
     *
     */
    public function actionAjaxJweixin()
    {
7d60e23d   xu   app-wx(v0.1.0 bui...
82
        // 设置微信分享内容
62d73041   xu   app-wx
83
84
85
86
87
88
89
90
91
92
93
        $result = new stdClass();

        $engineerId = $this->getEngineerId();

        $baseUrl = $this->site->base_url;
        if (isset($_GET['from'])) {
            $url = $_GET['from'];
        } else {
            $url = $baseUrl;
        }

7d60e23d   xu   app-wx(v0.1.0 bui...
94
        $sign  = WxHelper::getWxJSSDK()->getSignContext($url);
62d73041   xu   app-wx
95
96
97
98
99
100
101
102
103

        $result->appid = $sign->appId;
        $result->timestamp = $sign->timestamp;
        $result->noncestr = $sign->nonceStr;
        $result->signature = $sign->signature;


        //$sn = $engineer ?  urlencode(base64_encode($engineer->id)) : '';
        // 携带当前用户的邀请码参数,实现推荐用户功能
62d73041   xu   app-wx
104
105
106
107
        $sn = '';
        $engineer = Engineer::findOne($engineerId);
        if ($engineer) {
            if (empty($engineer->invite_code)) {
7d60e23d   xu   app-wx(v0.1.0 bui...
108
109
                $engineer->invite_code = Engineer::createInviteCode($engineerId);
                $engineer->save();
62d73041   xu   app-wx
110
            }
7d60e23d   xu   app-wx(v0.1.0 bui...
111
            $sn = $engineer->invite_code;
62d73041   xu   app-wx
112
        }
7d60e23d   xu   app-wx(v0.1.0 bui...
113
114
115
        $result->user_bridge_url = $baseUrl . '/wechat/bridging?sn=' . $sn . '&tourl=' . urlencode($url);
        $result->sn = $sn;

62d73041   xu   app-wx
116
        if ($engineer) {
7d60e23d   xu   app-wx(v0.1.0 bui...
117
            $profile = EngineerProfile::findOne(['engineer_id' => $engineer->id]);
62d73041   xu   app-wx
118
            $result->title = $this->wx->name;