| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- namespace console\controllers;
- use biz\user\services\UserOldDataService;
- use biz\user\services\UserService;
- use common\services\xhAdminService;
- use common\services\xhMerchantAssetService;
- use common\services\xhMerchantExtendService;
- use common\services\xhWxMenuService;
- use Yii;
- use yii\console\Controller;
- use common\models\xhDistrict;
- use linslin\yii2\curl;
- use common\components\util;
- use common\services\xhTMessageService;
- use common\services\xhMerchantService;
- use back\controllers\WeixinAdminbaseController;
- use common\models\xhMerchant;
- use common\services\xhInitService;
- /**
- * 脚本
- */
- class InitController extends Controller
- {
-
- //首次开店初始化 shish 2020.1.19
- public function actionFirstInit()
- {
-
- }
-
- //二次初始化 shish 2020.1.19
- public function actionSecondInit()
- {
- $id = Yii::$app->request->get('id');
- if (empty($id)) {
- echo "商家ID无效\n";
- }
- $merchant = xhMerchantService::getById($id);
- if (empty($merchant)) {
- echo "商家无效\n";
- }
- //初始化微信菜单
- xhWxMenuService::applyInit($merchant);
- }
-
- public function actionChangeDb()
- {
- echo 'ok';
- }
-
- //接入一个商家需要的操作 shish 2019.9.7 yii init/join-one
- public function actionJoinOne()
- {
- $id = 12360;
- //初始化微信菜单
- $merchant = xhMerchantService::getById($id);
- //xhWxMenuService::applyInit($merchant);
- //模板消息
- $r = xhTMessageService::supplement($merchant);
- print_r($r);
- }
-
- //yii init/sub
- public function actionSub()
- {
- $name = 'redis_shi';
- $redisPubSub = \Yii::$app->redisPubSub;
- $redisPubSub->setOptReadTimeout(-1);
- $redisPubSub->subscribe($name, function ($instance, $channelName, $message) {
- $a = 123;
- });
- }
-
- public function actionPub()
- {
- $name = 'redis_shi';
- $time = 'nihao1123';
- $redisPubSub = \Yii::$app->redisPubSub;
- $redisPubSub->publish($name, $time);
- }
-
- public function actionBegin()
- {
-
- //先清除公众号里的模板消息!!!!!!!
-
- $num = 0;
-
- //清空数据
- $this->actionFlushAll();
-
- //国兰花尚
- if ($num == 0) {
- xhAdminService::updateById(1, ['mobile' => '18030142050', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => 'c80fd29375a3a91d3681d8445822248a', 'adminName' => '姜祖岚']);
- xhMerchantService::updateById(12358, [
- 'merchantName' => '国兰花尚',
- 'miniAppId' => 'wxe994a9f5fd036f69',
- 'miniAppSecret' => '53b646675251e940f56bd304c2dba480',
- 'wxAppId' => 'wx193341a4a80f6ea3',
- 'wxUserName' => 'gh_090c30df22e6',
- 'wxAliasName' => 'glhs520',
- 'openAppId' => 'wxe9211595a1d5a39f',
- 'wxToken' => 'wt01467284437',
- 'status' => 1,
- ]);
- xhMerchantExtendService::updateByMerchantId(12358, [
- 'wxAppId' => 'wx193341a4a80f6ea3',
- 'miniAppId' => 'wxe994a9f5fd036f69',
- 'wxPayMerchantId' => '1244548702',
- 'wxPayKey' => 'eez23jf739jsmm4309j10jnza3qw8dwm',
- 'webTitle' => '国兰花尚',
- 'webKeyword' => '国兰花尚',
- 'webDescription' => '国兰花尚',
- 'alipayAccount' => '18030142050',
- 'alipayAccountName' => '游俊涛',
- ]);
- }
- //花美灵
- if ($num == 1) {
- xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
- xhMerchantService::updateById(12358, [
- 'merchantName' => '花美灵',
- 'miniAppId' => 'wxe4675bab299a52f7',
- 'miniAppSecret' => '03dd4000a26af5c17fb86321b7d1ebf3',
- 'wxAppId' => 'wx84d95afcb7b594eb',
- 'wxUserName' => 'gh_090c30df22e6',
- 'wxAliasName' => 'glhs520',
- 'wxToken' => 'wt01467284437',
- 'openAppId' => 'wxb46e972ab18f27bb',
- 'status' => 1,
- ]);
- xhMerchantExtendService::updateByMerchantId(12358, [
- 'wxAppId' => 'wx84d95afcb7b594eb',
- 'miniAppId' => 'wxe4675bab299a52f7',
- 'wxPayMerchantId' => '1371367002',
- 'wxPayKey' => 'eoz23aG739jscv4309275jnza32wvdwm',
- 'webTitle' => '花美灵',
- 'webKeyword' => '花美灵',
- 'webDescription' => '花美灵',
- 'alipayAccount' => 'shishaohua8879@sina.com',
- 'alipayAccountName' => '石少华',
- ]);
- }
- //花卉宝
- if ($num == 2) {
- xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
- xhMerchantService::updateById(12358, [
- 'merchantName' => '花卉宝',
- 'miniAppId' => '',
- 'miniAppSecret' => '',
- 'wxAppId' => 'wx66dd83ff8744f7a8',
- 'wxUserName' => 'gh_a9105e0f02b9',
- 'wxAliasName' => 'ihuahuibao',
- 'wxToken' => 'wt01467284437',
- 'status' => 1,
- ]);
- xhMerchantExtendService::updateByMerchantId(12358, [
- 'wxAppId' => 'wx66dd83ff8744f7a8',
- 'miniAppId' => '',
- 'wxPayMerchantId' => '1442448402',
- 'wxPayKey' => 'xxe29ax639jvcv4m082a1jnza32svdd0',
- 'webTitle' => '花卉宝',
- 'webKeyword' => '花卉宝',
- 'webDescription' => '花卉宝',
- 'alipayAccount' => 'shishaohua8879@sina.com',
- 'alipayAccountName' => '石少华',
- ]);
- }
-
- }
-
- public function actionLast()
- {
- //拉取用户
- $this->actionPullUser();
- //生成模板消息
- //$this->actionTMSupplement();
- }
-
- public function actionFlushAll()
- {
- $sql = "TRUNCATE xhDrawCash;
- TRUNCATE xhInvite;
- TRUNCATE xhLuckyDrawActivity;
- TRUNCATE xhLuckyDrawAward;
- TRUNCATE xhLuckyDrawAwardCustomer;
- TRUNCATE xhLuckyDrawAwardParticipant;
- TRUNCATE xhMerchantCapital;
- TRUNCATE xhOrder;
- TRUNCATE xhOrderDayNum;
- TRUNCATE xhOrderGoods;
- TRUNCATE xhOrderMonthNum;
- TRUNCATE xhRecharge;
- TRUNCATE xhStatDealByDay;
- TRUNCATE xhStatInDay;
- TRUNCATE xhStatInMonth;
- TRUNCATE xhStatOutDay;
- TRUNCATE xhStatOutMonth;
- TRUNCATE xhStatUserByDay;
- TRUNCATE xhStatVisitByDay;
- TRUNCATE xhUnionUser;
- TRUNCATE xhUser;
- TRUNCATE xhUserAlipay;
- TRUNCATE xhUserAsset;
- TRUNCATE xhUserByDay;
- TRUNCATE xhUserByMonth;
- TRUNCATE xhUserCapital;
- TRUNCATE xhUserIntegral;
- TRUNCATE xhUserOldData;
- TRUNCATE xhUserByDay;";
- //清空用户
- $sql .= "TRUNCATE xhUser;TRUNCATE xhUserAsset;TRUNCATE xhUserCapital;TRUNCATE xhUserIntegral;";
- $sql .= "TRUNCATE xhUserIntegral;TRUNCATE xhUserAlipay;ALTER TABLE xhUser AUTO_INCREMENT=12536580;";
- //清空提现申请记录
- $sql .= "TRUNCATE xhDrawCash;";
- Yii::$app->db->createCommand($sql)->execute();
- //清空订单
- $sql = "TRUNCATE xhOrder;TRUNCATE xhOrderDayNum;TRUNCATE xhOrderGoods;TRUNCATE xhOrderMonthNum;";
- Yii::$app->db->createCommand($sql)->execute();
- //清空缓存
- Yii::$app->redis->executeCommand('FLUSHDB');
- }
-
- /**
- * 拉取微信用户 shish 2019.9.9
- */
- public function actionPullUser()
- {
- $merchantId = 12359;
- $return = UserService::syncWeixinUser($merchantId);
- $total = isset($return['data']['total']) ? $return['data']['total'] : 0;
- xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans' => $total]);
- }
-
- /**
- * 开放平台初始化
- * yii init/open hhb
- */
- public function actionOpen($myOption = 'hhb')
- {
- $hostname = isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME'] : '';
- if ($hostname == 'iZ23b0wy8awZ') {
- util::stop("线上服务器不允许初始化\n");
- }
- echo "开始初始化…\n";
- xhInitService::clear($myOption);
- echo "初始化完成!\n";
- }
-
- /**
- * 模板消息补充增加
- * ./yii init/t-m-supplement
- */
- public function actionTMSupplement()
- {
- //服务号
- $allMerchant = xhMerchant::getAllByCondition(['status' => 1]);
- if (empty($allMerchant)) {
- echo "没有商家需要初始化模板消息";
- Yii::$app->end();
- }
- foreach ($allMerchant as $val) {
- $merchantId = $val['id'];
- $merchant = xhMerchantService::getById($merchantId);
- xhTMessageService::supplement($merchant);
- }
- }
-
- /**
- * 初始化 花卉宝 的行政区划
- * ./yii init/district
- */
- public function actionDistrict()
- {
- set_time_limit(0);
- $connection = Yii::$app->db;
- $sql = 'truncate xhDistrict';
- $connection->createCommand($sql)->execute();
- $url = 'http://apis.map.qq.com/ws/district/v1/list?key=OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
- $curl = new curl\Curl();
- $result = $curl->get($url);
- $r = json_decode($result, true);
- if (!empty($r)) {
- $onelist = $r['result'][0];
- $twolist = $r['result'][1];
- $threelist = $r['result'][2];
- foreach ($onelist as $oneKey => $oneVal) {
- $topId = $oneVal['id'];
- $name = isset($oneVal['name']) ? $oneVal['name'] : '';
- $fullname = $oneVal['fullname'];
- $lat = (string)$oneVal['location']['lat'];
- $lng = (string)$oneVal['location']['lng'];
- $oneData = ['districtId' => $topId, 'name' => $name, 'fullName' => $fullname, 'locationLat' => $lat, 'locationLng' => $lng, 'parentId' => 0];
- echo "<p>1级菜单:</p>\n";
- print_r($oneData);
- echo "\n";
- $oneObj = xhDistrict::add($oneData);
- if (isset($oneVal['cidx'])) {
- $onecidx = $oneVal['cidx'];
- if (isset($onecidx[0]) && isset($onecidx[1])) {
- echo "<p>2级菜单序号: | {$onecidx[0]} {$onecidx[1]}</p>\n";
- for ($xx = $onecidx[0]; $xx <= $onecidx[1]; $xx++) {
- $twoVal = $twolist[$xx];
- $id = $twoVal['id'];
- $name = isset($twoVal['name']) ? $twoVal['name'] : '';
- $fullname = $twoVal['fullname'];
- $lat = (string)$twoVal['location']['lat'];
- $lng = (string)$twoVal['location']['lng'];
- $twoData = ['districtId' => $id, 'name' => $name, 'fullName' => $fullname, 'locationLat' => $lat, 'locationLng' => $lng, 'parentId' => $oneObj['id']];
- echo $xx;
- print_r($twoData);
- echo "\n";
- $twoObj = xhDistrict::add($twoData);
- if (isset($twoVal['cidx'])) {
- $twocidx = $twoVal['cidx'];
- if (isset($twocidx[0]) && isset($twocidx[1])) {
- echo "<p>3级菜单序号: | {$twocidx[0]} {$twocidx[1]}</p>\n";
- for ($incr = $twocidx[0]; $incr <= $twocidx[1]; $incr++) {
- $threeVal = $threelist[$incr];
- $id = $threeVal['id'];
- $name = isset($threeVal['name']) ? $threeVal['name'] : '';
- $fullname = $threeVal['fullname'];
- $lat = (string)$threeVal['location']['lat'];
- $lng = (string)$threeVal['location']['lng'];
- $threeData = ['districtId' => $id, 'name' => $name, 'fullName' => $fullname, 'locationLat' => $lat, 'locationLng' => $lng, 'parentId' => $twoObj['id']];
- $threeObj = xhDistrict::add($threeData);
- echo $incr;
- print_r($threeData);
- echo "\n";
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- }
|