| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- namespace backend\controllers;
- use biz\order\services\OrderService;
- use biz\stat\services\StatIncomeService;
- use biz\stat\services\StatUserByDayService;
- use biz\stat\services\VisitByDayService;
- use biz\user\classes\UserClass;
- use biz\user\services\UserService;
- use common\components\weixinUtil;
- use common\models\xhStatIncome;
- use common\models\xhUser;
- use common\services\ImageService;
- use common\services\xhMerchantAssetService;
- use Yii;
- use yii\web\Controller;
- use common\services\xhAdminService;
- use yii\helpers\Json;
- use common\services\xhMerchantExtendService;
- use common\services\xhMerchantService;
- use common\services\xhStatIncomeService;
- use common\services\xhStatIncomeMonthService;
- use common\components\util;
- use common\components\configDict;
- use common\components\stringUtil;
- use common\services\xhVisitByDayService;
- use common\services\xhWxOpenService;
- use common\services\xhWxMenuService;
- use yii\web\Cookie;
- /**
- * main controller
- */
- class MainController extends BackendController
- {
-
- public $enableCsrfValidation = false;
-
- public $withoutLogin = ['login', 'logout', 'check-login', 'test', 'rabbitmq'];
-
- //消息队列 shish 2019.9.8
- //CMD中执行 yii rabbitmq/consume consumers
- public function actionRabbitmq()
- {
- $producer = \Yii::$app->rabbitmq->getProducer('producers');
- $msg = serialize(['dataset_id' => rand(1, 100), 'linked_datasets' => []]);
- $producer->publish($msg, 'ex1', 'route1');
- echo 'ok';
- }
-
- public function actionBindOpen()
- {
- $merchant = $this->merchant;
- $wxAppId = $merchant['wxAppId'];
- $miniAppId = $merchant['miniAppId'];
- $open_appid = $merchant['openAppId'];
-
- echo "<pre>";
-
- $id = Yii::$app->request->get('id', 0);
- //创建平台,并将公众号绑定到平台
- if ($id == 1) {
- weixinUtil::createOpenAccount($wxAppId, $this->merchant);
- $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
- print_r($return);
- if ($return['errcode'] == 0) {
- $openAppId = $return['open_appid'];
- xhMerchantService::updateById($this->merchantId, ['openAppId' => $openAppId]);
- }
- }
- //将小程序绑定到平台
- if ($id == 2) {
- $openAppId = $merchant['openAppId'];
- $r = weixinUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
- print_r($r);
- }
- //查询公众号 小程序的绑定情况
- if ($id == 3) {
- $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
- print_r($return);
- $return = weixinUtil::getOpenAccount($miniAppId, $this->merchant, true);
- print_r($return);
- }
-
- //设置小程序服务器域名
- if ($id == 4) {
- weixinUtil::setDomain($this->merchant);
- weixinUtil::setWebViewDomain($this->merchant);
- }
-
- //为授权的小程序帐号上传小程序代码
- if ($id == 5) {
- $tId = $_GET['tId'];
- weixinUtil::miniCommit($this->merchant, $tId);
- }
-
- //获取小程序体验码
- if ($id == 6) {
- weixinUtil::getExperienceQrCode($this->merchant);
- }
-
- //获取授权小程序帐号已设置的类目
- if ($id == 7) {
- weixinUtil::getMiniCategory($this->merchant);
- }
-
- //获取小程序的第三方提交代码的页面配置
- if ($id == 8) {
- weixinUtil::getMiniPage($this->merchant);
- }
-
- //将第三方提交的代码包提交审核
- if ($id == 9) {
- weixinUtil::miniSubmitAudit($this->merchant);
- }
-
- //查询最新一次提交的审核状态
- if ($id == 10) {
- weixinUtil::miniGetLatestAuditStatus($this->merchant);
- }
-
- //发布已通过审核的小程序
- if ($id == 11) {
- weixinUtil::miniRelease($this->merchant);
- }
-
- //撤回审核
- if ($id == 12) {
- weixinUtil::rollbackCheck($this->merchant);
- }
- //生成 申请会员页 的小程序码
- if ($id == 13) {
- weixinUtil::generateMemberCode($this->merchant);
- }
- //解绑小程序和公众号绑定的平台
- if ($id == 14) {
- weixinUtil::unbindAccount($this->merchant);
- weixinUtil::unbindMiniProgram($this->merchant);
- }
- Yii::$app->end();
- $r = weixinUtil::bindOpenAccount($miniAppId, $open_appid, $merchant, true);
- print_r($r);
- echo $miniAppId . ' ' . $open_appid . ' ';
-
- $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
- print_r($return);
- die;
-
- $return = weixinUtil::createOpenAccount($wxAppId, $this->merchant);
- print_r($return);
- die;
-
- $r = weixinUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
- print_r($r);
- echo $miniAppId . ' ' . $open_appid . ' ';
-
- $return = weixinUtil::getOpenAccount($wxAppId, $this->merchant);
- print_r($return);
- $return = weixinUtil::getOpenAccount($miniAppId, $this->merchant);
- print_r($return);
- die;
-
- if ($return['errcode'] == 0) {
- $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
- } else {
- $return = weixinUtil::createOpenAccount($wxAppId, $this->merchant);
- if ($return['errcode'] == 0) {
- $open_appid = isset($return['open_appid']) ? $return['open_appid'] : '';
- }
- }
- echo "<br />open_appid:" . $open_appid . "<br />";
- if (!empty($open_appid)) {
- xhMerchantService::updateById($this->merchantId, ['openAppId' => $open_appid]);
- $r = weixinUtil::bindOpenAccount($miniAppId, $open_appid, $merchant);
- echo "绑定小程序结果:<br />";
- print_r($r);
- }
- echo "<br /><br />";
- $return = weixinUtil::getOpenAccount($wxAppId, $merchant);
- echo "微信appId:{$wxAppId}<br />";
- print_r($return);
- $return = weixinUtil::getOpenAccount($miniAppId, $merchant);
- echo "<br />小程序appId:{$miniAppId}<br />";
- print_r($return);
- }
-
- public function actionCs()
- {
- // 忽略获取的header数据
- $ignore = ['host', 'accept', 'content-length', 'content-type'];
- $headers = [];
- foreach ($_SERVER as $key => $value) {
- if (substr($key, 0, 5) === 'HTTP_') {
- $key = substr($key, 5);
- $key = str_replace('_', ' ', $key);
- $key = str_replace(' ', '-', $key);
- $key = strtolower($key);
- if (!in_array($key, $ignore)) {
- $headers[$key] = $value;
- }
- }
- }
- $token = isset($headers['token']) ? $headers['token'] : '';
- }
-
- public function actionIndex()
- {
- echo 'aaa';die;
- $time = strtotime(date("Y-m-d"));
- $todayIncome = xhStatIncomeService::getTodayIncome($this->merchantId, $time);
- $year = date("Y");
- $month = date("n");
- $monthIncome = xhStatIncomeMonthService::getMonthIncome($this->merchantId, $year, $month);
- $statUser = StatUserByDayService::getTodayNum();
-
- $todayVisit = VisitByDayService::getTodayNum($this->merchantId);
- $totalVisit = VisitByDayService::getTotalVisit($this->merchantId);
- $latestIncome = xhStatIncomeService::getLatestIncome($this->merchantId);//取最近10天的收入
-
- $dayIncome = xhStatIncome::find()->where(['merchantId' => $this->merchantId])->asArray()->orderBy('time desc')->limit(3)->all();
-
- $income = StatIncomeService::getTodayNum();
-
- //获取最近的订单 shish 2019.8.19
- $orderList = OrderService::getLatestOrder();
- //今日访问量
- $todayVisitNum = VisitByDayService::getTodayNum($this->merchantId);
- return $this->render('index', [
- 'merchant' => $this->merchant,
- 'merchantExtend' => $this->merchantExtend,
- 'merchantAsset' => $this->merchantAsset,
- 'todayIncome' => $todayIncome,
- 'monthIncome' => $monthIncome,
- 'statUser' => $statUser,
- 'todayVisit' => $todayVisit,
- 'totalVisit' => $totalVisit,
- 'latestIncome' => $latestIncome,
- 'dayIncome' => $dayIncome,
- 'orderList' => $orderList,
- 'income' => $income,
- 'todayVisitNum' => $todayVisitNum,
- ]);
-
- }
-
- public function actionTest()
- {
-
- }
-
- public function actionLogin()
- {
- $merchant = xhMerchantService::getById(12358);
- $data = ["touser" => 'oTFbYvsjwgVwXggwtlM2ESAKwuN8', "template_id" => 'rxcSb6up1IgKJQY2XcTodJdFweigTu6UPXVZ7wsdWcI',
- "url" => 'http://m.huaml.com/order/detail?id=1', "data" => [
- "first" => ["value" => '石头付款', "color" => "#173177"],
- "keyword1" => ["value" => '10元', "color" => "#173177"],
- "keyword2" => ["value" => '客户付款', "color" => "#173177"],
- "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
- "remark" => ["value" => "点击查看明细", "color" => "#173177"]]];
-
- $accessToken = weixinUtil::getAuthorizerAccessToken($merchant);
- $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$accessToken}";
- //$data = urldecode(json_encode($data, JSON_UNESCAPED_UNICODE));
- //$curl = new curl\Curl();
- //$response = $curl->setOption(CURLOPT_POSTFIELDS, $data)->post($url);
- //self::asyncRequest('https://api.weixin.qq.com','/cgi-bin/message/template/send?access_token='.$accessToken,json_encode($data, JSON_UNESCAPED_UNICODE));
- //echo 'ok';
- //die;
-
-
- $params = json_encode($data,JSON_UNESCAPED_UNICODE);
- $start_time = microtime(true);
-
- $fp = fsockopen('ssl://api.weixin.qq.com', 443, $error, $errstr, 3);
- $http = "POST /cgi-bin/message/template/send?access_token={$accessToken} HTTP/1.1\r\nHost: api.weixin.qq.com\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($params) . "\r\nConnection:close\r\n\r\n$params\r\n\r\n";
- fwrite($fp, $http);
- fclose($fp);
-
- die;
-
-
-
- sleep(3);
- Yii::info('id:'.$_POST['name']);
- util::ok();
- if ($this->isLogin) {
- $this->redirect(['main/index']);
- }
- return $this->renderPartial('login');
- }
-
- private static function asyncRequest($host, $path, $param = []){
-
- $query = isset($param) ? http_build_query($param) : '';
-
- $port = 80;
- $errno = 0;
- $errstr = '';
- $timeout = 30; //连接超时时间(S)
-
- $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
- //$fp = stream_socket_client("tcp://".$host.":".$port, $errno, $errstr, $timeout);
-
- if (!$fp) {
-
- return '连接失败';
- }
- if ($errno || !$fp) {
-
-
- return $errstr;
- }
-
- stream_set_blocking($fp,0); //非阻塞
- stream_set_timeout($fp, 1);//响应超时时间(S)
- $out = "POST " . $path . " HTTP/1.1\r\n";
- $out .= "host:" . $host . "\r\n";
- $out .= "content-length:" . strlen($query) . "\r\n";
- $out .= "content-type:application/x-www-form-urlencoded\r\n";
- $out .= "connection:close\r\n\r\n";
- $out .= $query;
-
- $result = @fputs($fp, $out);
-
- @fclose($fp);
- return $result;
-
- }
-
- /**
- * 重复登陆,记录登陆名
- * @return string
- */
- public function actionRelogin()
- {
- return $this->renderPartial('relogin');
- }
-
- public function actionLogout()
- {
- xhAdminService::logout();
- $this->redirect(['main/login']);
- }
-
- public function actionCheckLogin()
- {
- $request = Yii::$app->request;
- $mobile = $request->post('mobile');
- $password = $request->post('password');
- $return = xhAdminService::loginByMobile($mobile, $password, true);//true 自动登陆
- util::encode($return);
- }
-
- public function actionSetLoginPassword()
- {
- $id = $this->adminId;
- $admin = xhAdminService::getById($id);
- return $this->render('setLoginPassword', ['admin' => $admin]);
- }
-
- public function actionModifyLoginPassword()
- {
- $post = Yii::$app->request->post();
- $prePassword = isset($post['prePassword']) ? $post['prePassword'] : '';
- $id = $this->adminId;
- $admin = xhAdminService::getById($id);
- $savePwd = $admin['password'];
- if (empty($savePwd)) {
- util::failInfo('请填写密码');
- }
- if (md5($prePassword) == $savePwd) {
- util::failInfo('原密码不正确');
- }
- xhAdminService::updateById($id, ['password' => md5($post['password'])]);
- util::successInfo('修改成功');
- }
-
- /**
- * 扫码枪扫码
- */
- public function actionSearch()
- {
- $get = Yii::$app->request->get();
- $content = isset($get['content']) ? $get['content'] : '';
- $id = preg_replace('/\D/s', '', $content);
- if (strpos($content, configDict::getQrKey('user')) === 0) {
- $this->redirect(['/user/detail', 'id' => $id]);
- Yii::$app->end();
- }
- if (strpos($content, configDict::getQrKey('coupon')) === 0) {
- $this->redirect(['/coupon/detail', 'id' => $id]);
- Yii::$app->end();
- }
- }
-
- /**
- * 审核通过
- */
- public function actionApprove()
- {
- $openMerchant = xhWxOpenService::getMerchant();
- return $this->render('approve', ['admin' => $this->admin, 'openMerchant' => $openMerchant]);
- }
-
- public function actionQuickOrder()
- {
- $this->redirect(Yii::$app->params['frontUrl'] . '/payment/quick-order?account=' . $this->merchant['id']);
- }
-
- public function actionPub()
- {
- $channelName = 'redis_shi';
- $time = time();
- Yii::$app->redis->executeCommand('PUBLISH', [$channelName, $time]);
- }
-
- public function actionSub()
- {
- $channelName = 'redis_shi';
- print_r(Yii::$app->redis->executeCommand('SUBSCRIBE', [$channelName]));
- }
-
- public function actionError()
- {
- $msg = Yii::$app->request->get('msg');
- return $this->render('error', ['msg' => $msg]);
- }
-
- }
|