diff --git a/app-wx/assets/AppAsset.php b/app-wx/assets/AppAsset.php
new file mode 100644
index 0000000..1f63d02
--- /dev/null
+++ b/app-wx/assets/AppAsset.php
@@ -0,0 +1,25 @@
+ View::POS_HEAD
+ ];
+ public $depends = [
+ ];
+
+}
diff --git a/app-wx/config/.gitignore b/app-wx/config/.gitignore
new file mode 100644
index 0000000..20da318
--- /dev/null
+++ b/app-wx/config/.gitignore
@@ -0,0 +1,2 @@
+main-local.php
+params-local.php
\ No newline at end of file
diff --git a/app-wx/config/bootstrap.php b/app-wx/config/bootstrap.php
new file mode 100644
index 0000000..b3d9bbc
--- /dev/null
+++ b/app-wx/config/bootstrap.php
@@ -0,0 +1 @@
+ 'app-wx',
+ 'basePath' => dirname(__DIR__),
+ 'runtimePath' => Yii::getAlias('@rootRuntime').'/app-wx/',
+ 'bootstrap' => ['log'],
+ 'controllerNamespace' => 'app\wx\controllers',
+ 'defaultRoute' => 'order',
+ 'modules' => [
+
+ 'home' => [
+ 'class' => 'app\wx\modules\home\Module',
+ ]
+ ],
+ 'components' => [
+ 'user' => [
+ 'class'=> 'app\wx\exts\User',
+ 'identityClass' => 'app\wx\models\User',
+ 'enableAutoLogin' => false,//是否启用自动登录
+ ],
+ 'errorHandler' => [
+ 'errorAction' => 'site/error',
+ ],
+ 'assetManager' => [
+ 'forceCopy' => true, //每次都发布文件
+ 'appendTimestamp' => true, //后面加上时间戳,防止缓存。
+ ],
+
+ 'urlManager' => [
+ 'enablePrettyUrl' => true,
+ 'showScriptName' => false,
+ 'rules' => [
+ ],
+ ],
+ ],
+ 'params' => $params,
+];
diff --git a/app-wx/config/params.php b/app-wx/config/params.php
new file mode 100644
index 0000000..9316ece
--- /dev/null
+++ b/app-wx/config/params.php
@@ -0,0 +1,5 @@
+ 'admin@example.com',
+ 'VERSION' => 'v0.1.0 build 1', // 当前发布版本号: v0.1.0 是版本号 | build 1 是编译次数
+];
diff --git a/app-wx/controllers/AppController.php b/app-wx/controllers/AppController.php
new file mode 100644
index 0000000..c7f3dc9
--- /dev/null
+++ b/app-wx/controllers/AppController.php
@@ -0,0 +1,36 @@
+request = Yii::$app->getRequest();
+ $this->response = Yii::$app->getResponse();
+ }
+
+ /**
+ * 渲染 JSON 数据结果
+ * @param $data
+ * @return string
+ */
+ public function renderJson($data)
+ {
+ return json_encode($data, JSON_UNESCAPED_UNICODE);
+ }
+}
\ No newline at end of file
diff --git a/app-wx/controllers/BaseController.php b/app-wx/controllers/BaseController.php
new file mode 100644
index 0000000..c17004c
--- /dev/null
+++ b/app-wx/controllers/BaseController.php
@@ -0,0 +1,281 @@
+
+ * @date 2015/07/01
+ */
+class BaseController extends AppController
+{
+ /**
+ * CSR验证,关闭后可以在不提交CSR验证码的情况下通过POST方式提交数据
+ * @var bool
+ */
+ public $enableCsrfValidation = false;
+ /** @var **/
+ protected $wx;
+ /** @var **/
+ protected $site;
+
+ /**
+ * 初始化应用控制器,确保 mall id 的存在,有效启动程序,否则抛出异常。
+ * @throws yii\web\BadRequestHttpException
+ * @throws yii\web\BadRequestHttpException
+ */
+ public function init()
+ {
+
+ $this->initTempFilePaths();
+
+ parent::init();
+
+ $wxArray = $this->getWxArray();
+
+ //重置应用的名称
+ Yii::$app->name = $wxArray['name'];
+
+ /**
+ * 微信服务号配置
+ */
+ $this->wx = new stdClass();
+ $this->site = new stdClass();
+
+ $this->formatWx($wxArray);
+ $this->formatSite($wxArray);
+
+ $view = Yii::$app->view;
+ $view->params['site']= $this->site;
+ }
+
+ /**
+ * @return array|bool
+ */
+ private function getWxArray()
+ {
+ $wxArray = [
+ 'name' => '配件维修',
+ 'intro' => '报修',
+ 'logo_path' => '',
+ 'subscribe_title' => '报修',
+ 'subscribe_desc' => '报修',
+ 'subscribe_img' => '',
+ 'subscribe_url' => '',
+ 'appid' => 'appid',
+ 'appsecret' => 'appsecret',
+ 'token' => 'token'
+
+ ];
+ return $wxArray;
+ }
+
+ /**
+ * @param $wxArray
+ */
+ private function formatWx($wxArray)
+ {
+ /**
+ * 工程师微信服务号信息
+ */
+ $this->wx->name = $wxArray['name'];//名称
+ $this->wx->intro = $wxArray['intro'];//简介
+ $this->wx->logo_url = $wxArray['logo_path'];//路径
+ $this->wx->subscribe_title = $wxArray['subscribe_title']; // 公众号关注图文标题
+ $this->wx->subscribe_desc = $wxArray['subscribe_desc']; // 公众号关注图文描述
+ $this->wx->subscribe_img = $wxArray['subscribe_img']; // 公众号关注图文消息图片
+ $this->wx->subscribe_url = $wxArray['subscribe_url']; // 公众号关注图文url
+
+ $this->wx->appid = $wxArray['appid'];// APPID
+ $this->wx->appsecret = $wxArray['appsecret'];//APPSECRET
+ $this->wx->token = $wxArray['token'];//微信TOKEN
+ }
+
+ /**
+ * 获取 ID
+ * @return int|string
+ */
+ public function getEngineerId()
+ {
+ return 0;
+ }
+
+ /**
+ * @param $wxArray
+ */
+ private function formatSite($wxArray)
+ {
+ /**
+ * 站点信息
+ */
+ $appUser = Yii::$app->getUser();
+ $url = Yii::$app->request->getHostInfo() . Yii::$app->request->url;
+ $this->site->url = $url;
+ if (YII_ENV_DEV) {
+ $this->site->base_url = Yii::$app->request->getHostInfo() . Yii::$app->request->baseUrl;
+ } else {
+ $this->site->base_url = Yii::$app->request->getHostInfo();
+ }
+
+ $am = Yii::$app->view->getAssetManager();
+ $assets = $am->getBundle('app\wx\assets\AppAsset');
+
+ $this->site->is_android = (int)$this->isAndroid();
+ $this->site->assets_url = $assets->baseUrl;
+ $this->site->is_login = !$appUser->isGuest;
+ $this->site->title = $wxArray['name'];
+ $search = array("\t", "\n", "\r");
+ $this->site->desc = str_replace($search, '
', $wxArray['intro']);
+ $this->site->icon = $wxArray['logo_path'];
+
+ // 携带当前用户的邀请码参数,实现推荐用户功能
+ $sn = '';
+
+ $baseUrl = $this->site->base_url;
+ $this->site->user_bridge_url = $sn ? ($baseUrl . '/wechat/bridging?sn=' . $sn . '&tourl=' . urlencode($this->site->url)) : '';
+ $this->site->sn = $sn;
+
+ $this->site->appid = 'appid';
+ $this->site->timestamp = time();
+ $this->site->noncestr = 'noncestr';
+ $this->site->signature = 'signature';
+ }
+
+ /**
+ * @return yii\web\Response
+ */
+ protected function handleMallAccessCtrl()
+ {
+ //AppLog::DEBUG("BaseController: handleMallAccessCtrl()" );
+ $appUser = Yii::$app->getUser();
+ if(YII_ENV_DEV && $appUser->isGuest){
+ $uid = Yii::$app->params['testUID']; // 请在各自的config/params-local.php里配置
+ $appUser->login(0);
+ $this->goHome();
+ return ;
+ }
+ //test和 prod 环境,进行微信登陆
+ if ($appUser->isGuest){
+ $this->handleOAuthRedirect();
+ } else {
+ $path = $this->request->get('jumppath');
+ $model= $this->request->get('jumpmodel');
+ $paramOne= $this->request->get('paramOne');
+ if (!empty($path) && !empty($model)) {
+ $locationUrl = Yii::$app->params["baseUrl"]."/".$model."#".$path;
+ if (!empty($paramOne)) {
+ $locationUrl .= "/".urldecode($paramOne);
+ }
+ header("Location: $locationUrl");exit;
+ }
+ }
+
+ }
+
+ /**
+ * @return yii\web\Response
+ */
+ private function handleOAuthRedirect()
+ {
+ $sn = Yii::$app->request->get("sn");
+
+ //Yii::$app->response->redirect($OAuthUrl)->send();
+ //Yii::$app->end();
+ }
+
+
+ /**
+ * 是否是IOS端
+ * 是否通过微信客户端来访问
+ * LOG 记录时发现,
+ * 在微信公众号里面第一次访问: $_SERVER ['HTTP_USER_AGENT'] 为 Mozilla/4.0
+ * 第二次访问: $_SERVER ['HTTP_USER_AGENT'] 为
+ * 苹果:
+ * Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 MicroMessenger/6.3.16 NetType/WIFI Language/zh_CN
+ * 安卓(小米NOTE):
+ * Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9b4) Gecko/2008030317 Firefox/3.0b4
+ * @return bool
+ */
+ protected function isAndroid()
+ {
+// if(false !== strpos($_SERVER ['HTTP_USER_AGENT'], 'Android') || !isset($_SERVER ['HTTP_USER_AGENT'])){
+// return true;
+// } else {
+// return false;
+// }
+ return true;
+ }
+
+ //
+ public function setPhoneCode($phone, $code)
+ {
+ Yii::$app->session['v_'.$phone] = array('create_time' => time(),'vCode' => md5($phone.'_'.$code));
+ }
+
+ public function getPhoneCode($phone)
+ {
+ return Yii::$app->session['v_'.$phone];
+ }
+
+ // 默认是300秒
+ public function validatePhoneCode($phone, $code, $vaTime = 300)
+ {
+ $pCode = $this->getPhoneCode($phone);
+ $cTime = time();
+ if (empty($pCode)) {
+ return -3;
+ }
+ if ($cTime > ($pCode['create_time'] + $vaTime)) {
+ $this->unsetPhoneCode($phone);
+ return -1;
+ }
+ if($pCode['vCode'] == md5($phone.'_'.$code)){
+ return 0;
+ }else{
+ return -2;
+ }
+ }
+
+ public function unsetPhoneCode($phone)
+ {
+ unset(Yii::$app->session['v_'.$phone]);
+ }
+
+ /**
+ * 初始化web目录文件夹, 完成自动创建
+ */
+ private function initTempFilePaths()
+ {
+ // 临时文件
+ $webRoot = Yii::getAlias('@webroot');
+ $tmpFilePath = $webRoot . '/tmp';
+ if (!is_dir($tmpFilePath)) {
+ mkdir($tmpFilePath, 0777, true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app-wx/controllers/ErrorController.php b/app-wx/controllers/ErrorController.php
new file mode 100644
index 0000000..7ca90ce
--- /dev/null
+++ b/app-wx/controllers/ErrorController.php
@@ -0,0 +1,60 @@
+name = '系统通知';
+ $this->site = new \stdClass();
+ $this->getSite();
+ $view = \yii::$app->view;
+ $view->params['site'] = $this->site;
+ }
+
+ public function getSite()
+ {
+
+ $url = \yii::$app->request->getHostInfo() . \yii::$app->request->url;
+ $this->site->url = $url;
+ if(YII_ENV_DEV){
+ $this->site->base_url = \yii::$app->request->getHostInfo() . \yii::$app->request->baseUrl;
+ } else {
+ $this->site->base_url = \yii::$app->request->getHostInfo();
+ }
+ $this->site->assets_url = $url;
+ $this->site->title = '通知';
+ $this->site->desc = '';
+ $this->site->icon = '';
+ $this->site->appid = '';
+ $this->site->timestamp = '';
+ $this->site->noncestr = '';
+ $this->site->signature = '';
+ $this->site->user_bridge_url = '';
+ $this->site->sn = '';
+
+ return $this->site;
+ }
+
+ /** 系统暂停
+ * @return string
+ */
+ public function actionStop()
+ {
+ $this->layout = 'site';
+ \yii::$app->name = '系统通知';
+ $viewTpl = '@app/wx/views/site/error/stop.php';
+ $siteInfo = SysSetting::getClientSiteInfo();
+
+ return $this->render($viewTpl,['stop_status'=> $siteInfo['stop'], 'stop_head'=> $siteInfo['stop_head'], 'stop_content'=> $siteInfo['stop_content']]);
+ }
+
+}
diff --git a/app-wx/controllers/SiteController.php b/app-wx/controllers/SiteController.php
new file mode 100644
index 0000000..b35088f
--- /dev/null
+++ b/app-wx/controllers/SiteController.php
@@ -0,0 +1,199 @@
+view;
+ $view->params['site']= $this->site;
+
+ //$this->handleMallAccessCtrl();
+ return parent::beforeAction($action);
+ }
+
+ /**
+ * @return string
+ * @return string HTML
+ */
+ public function actionIndex()
+ {
+ //获取当前用户的模型model
+ $engineerId = $this->getEngineerId();
+ $engineer = new stdClass();
+ /**
+ * 构造user的共用信息
+ */
+ $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'];
+ $engineer->headimgurl = $engineerArray['headimgurl'];
+ $engineer->nickname = $engineerArray['nickname'];
+ return $engineer;
+ }
+
+
+ /**
+ *
+ */
+ public function actionAjaxJweixin()
+ {
+ // 设置微信分享内容
+ $result = new stdClass();
+
+ $engineerId = $this->getEngineerId();
+
+ $baseUrl = $this->site->base_url;
+ if (isset($_GET['from'])) {
+ $url = $_GET['from'];
+ } else {
+ $url = $baseUrl;
+ }
+
+ $sign = WxHelper::getWxJSSDK()->getSignContext($url);
+
+ $result->appid = $sign->appId;
+ $result->timestamp = $sign->timestamp;
+ $result->noncestr = $sign->nonceStr;
+ $result->signature = $sign->signature;
+
+
+ //$sn = $engineer ? urlencode(base64_encode($engineer->id)) : '';
+ // 携带当前用户的邀请码参数,实现推荐用户功能
+ $sn = '';
+ $engineer = Engineer::findOne($engineerId);
+ if ($engineer) {
+ if (empty($engineer->invite_code)) {
+ $engineer->invite_code = Engineer::createInviteCode($engineerId);
+ $engineer->save();
+ }
+ $sn = $engineer->invite_code;
+ }
+ $result->user_bridge_url = $baseUrl . '/wechat/bridging?sn=' . $sn . '&tourl=' . urlencode($url);
+ $result->sn = $sn;
+
+ if ($engineer) {
+ $profile = EngineerProfile::findOne(['engineer_id' => $engineer->id]);
+ $result->title = $this->wx->name;
+ $result->icon = $profile->headimgurl;
+ } else {
+ $result->title = $this->wx->name;
+ $result->icon = '';
+ }
+ $result->desc = $this->wx->intro;
+
+
+ return $this->renderJson($result);
+ }
+
+ /*
+ * 错误页面
+ */
+ public function actionError()
+ {
+ $this->layout = '/error';
+
+ $exception = Yii::$app->errorHandler->exception;
+ if ($exception && isset($exception->statusCode)) {
+ $code = $exception->statusCode;
+ }
+ // $viewTpl = 'error/' . $code . '.php';
+ $viewTpl = 'error/404.php';
+
+ return $this->render($viewTpl);
+ }
+
+ /** 封号提示
+ * @return string
+ */
+ public function actionBlock()
+ {
+ $this->layout = '/error';
+ $viewTpl = 'error/block.php';
+ $service_phone = SysSetting::getServicePhone();
+ return $this->render($viewTpl,['service_phone'=>$service_phone]);
+ }
+
+ /** 关注提示
+ * @return string
+ */
+ public function actionSubscribe()
+ {
+ $this->layout = '/error';
+ $viewTpl = 'error/subscribe.php';
+ $service_phone = SysSetting::getServicePhone();
+ return $this->render($viewTpl,['service_phone'=>$service_phone]);
+ }
+
+ /**
+ * 未授权提示
+ */
+ public function actionNoOauth()
+ {
+ $this->layout = '/error';
+ $viewTpl = 'error/block.php';
+ $id = $this->request->get('id');
+ $service_phone = SysSetting::getServicePhone();
+ $errorMsg = '当前没有权限查看该内容';
+ if ($id == 1) {
+ $errorMsg = '请进行认证以后再来查看该页面';
+ }
+ return $this->render($viewTpl,['service_phone'=>$service_phone, 'errorMsg' => $errorMsg]);
+ }
+
+ public function actionIndex2()
+ {
+
+ return $this->renderPartial('index2');
+ }
+
+ /**
+ * 跳转到接单教程界面
+ */
+ public function actionToTutorialPage()
+ {
+ header("Location: http://mp.weixin.qq.com/mp/homepage?__biz=MzIyNDc5ODMwOA==&hid=1&sn=4f8b8972dc5f471a85618dde0f6a5987&scene=18");
+ exit;
+ }
+}
diff --git a/app-wx/exts/User.php b/app-wx/exts/User.php
new file mode 100644
index 0000000..506d41c
--- /dev/null
+++ b/app-wx/exts/User.php
@@ -0,0 +1,112 @@
+setIdentity($identity);
+
+ if (!$this->enableSession) {
+ return;
+ }
+
+ /* Ensure any existing identity cookies are removed. */
+ if ($this->enableAutoLogin) {
+ Yii::$app->getResponse()->getCookies()->remove(new Cookie($this->identityCookie));
+ }
+
+ $session = Yii::$app->getSession();
+ if (!YII_ENV_TEST) {
+ $session->regenerateID(true);
+ }
+
+ $session->remove($this->idParam);
+ $session->remove($this->authTimeoutParam);
+
+ if ($identity) {
+ $session->set($this->idParam, $identity->getId());
+
+ if ($this->authTimeout !== null) {
+ $session->set($this->authTimeoutParam, time() + $this->authTimeout);
+ }
+ if ($this->absoluteAuthTimeout !== null) {
+ $session->set($this->absoluteAuthTimeoutParam, time() + $this->absoluteAuthTimeout);
+ }
+ if ($duration > 0 && $this->enableAutoLogin) {
+ $this->sendIdentityCookie($identity, $duration);
+ }
+ }
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function renewAuthStatus()
+ {
+ $session = Yii::$app->getSession();
+ $id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($this->idParam) : null;
+
+ if ($id === null) {
+ $identity = null;
+ } else {
+ $class = 'app\wx\models\Engineer';
+ $identity = $class::findIdentity($id);
+ }
+
+ $this->setIdentity($identity);
+
+ if ($identity !== null && ($this->authTimeout !== null || $this->absoluteAuthTimeout !== null)) {
+ $expire = $this->authTimeout !== null ? $session->get($this->authTimeoutParam) : null;
+ $expireAbsolute = $this->absoluteAuthTimeout !== null ? $session->get($this->absoluteAuthTimeoutParam) : null;
+ if ($expire !== null && $expire < time() || $expireAbsolute !== null && $expireAbsolute < time()) {
+ $this->logout(false);
+ } elseif ($this->authTimeout !== null) {
+ $session->set($this->authTimeoutParam, time() + $this->authTimeout);
+ }
+ }
+
+ if ($this->enableAutoLogin) {
+ if ($this->getIsGuest()) {
+ $this->loginByCookie();
+ } elseif ($this->autoRenewCookie) {
+ $this->renewIdentityCookie();
+ }
+ }
+ }
+
+
+ /**
+ * @return int
+ */
+ public function getId()
+ {
+ if(null === $this->_id){
+ $session = Yii::$app->getSession();
+ $this->_id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($this->idParam) : null;
+ }
+ return (int)$this->_id;
+ }
+}
diff --git a/app-wx/helpers/Sort.php b/app-wx/helpers/Sort.php
new file mode 100644
index 0000000..0319f99
--- /dev/null
+++ b/app-wx/helpers/Sort.php
@@ -0,0 +1,37 @@
+attributes() as $attribute) {
+ $this->attributes[$attribute] = [
+ 'asc' => [$attribute => SORT_ASC],
+ 'desc' => [$attribute => SORT_DESC],
+ 'label' => $model->getAttributeLabel($attribute),
+ ];
+ }
+
+ if ($extraAttrbutes) {
+ foreach ($extraAttrbutes as $k => $label) {
+ $this->attributes[$k] = [
+ 'asc' => [$k => SORT_ASC],
+ 'desc' => [$k => SORT_DESC],
+ 'label' => $label,
+ ];
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app-wx/index.html b/app-wx/index.html
new file mode 100644
index 0000000..9015a7a
--- /dev/null
+++ b/app-wx/index.html
@@ -0,0 +1 @@
+index
diff --git a/app-wx/models/User.php b/app-wx/models/User.php
new file mode 100644
index 0000000..dfd29f4
--- /dev/null
+++ b/app-wx/models/User.php
@@ -0,0 +1,37 @@
+getUser();
+ $session = Yii::$app->getSession();
+ $id = $session->getHasSessionId() || $session->getIsActive() ? $session->get($user->idParam) : null;
+ self::$id = $id;
+ }
+
+ return self::$id;
+ }
+}
\ No newline at end of file
diff --git a/app-wx/modules/BaseModule.php b/app-wx/modules/BaseModule.php
new file mode 100644
index 0000000..75bcb26
--- /dev/null
+++ b/app-wx/modules/BaseModule.php
@@ -0,0 +1,13 @@
+render('index');
+ }
+
+
+}
\ No newline at end of file
diff --git a/app-wx/modules/home/views/default/index.php b/app-wx/modules/home/views/default/index.php
new file mode 100644
index 0000000..bc76d38
--- /dev/null
+++ b/app-wx/modules/home/views/default/index.php
@@ -0,0 +1,38 @@
+getAssetManager();
+$asset = $assets->getBundle('app\wx\assets\AppAsset');
+
+function img($file, $path = '/i/')
+{
+ return \Yii::$app->request->baseUrl . $path.$file;
+}
+?>
+
+
在使用系统的过程中,遇到问题或者有好的建议,请一定告诉我们。我们深宅多年练就的功能,就是为了化问题为神奇。
+ +邮箱:tech@jiwork.com (求约)
+在使用系统的过程中,遇到问题或者有好的建议,请一定告诉我们。我们深宅多年练就的功能,就是为了化问题为神奇。
+ +邮箱:tech@jiwork.com (求约)
+在使用系统的过程中,遇到问题或者有好的建议,请一定告诉我们。我们深宅多年练就的功能,就是为了化问题为神奇。
+ +邮箱:tech@jiwork.com (求约)
+