InitController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. namespace console\controllers;
  3. use biz\user\services\UserOldDataService;
  4. use biz\user\services\UserService;
  5. use common\services\xhAdminService;
  6. use common\services\xhMerchantAssetService;
  7. use common\services\xhMerchantExtendService;
  8. use common\services\xhWxMenuService;
  9. use Yii;
  10. use yii\console\Controller;
  11. use common\models\xhDistrict;
  12. use linslin\yii2\curl;
  13. use common\components\util;
  14. use common\services\xhTMessageService;
  15. use common\services\xhMerchantService;
  16. use back\controllers\WeixinAdminbaseController;
  17. use common\models\xhMerchant;
  18. use common\services\xhInitService;
  19. /**
  20. * 脚本
  21. */
  22. class InitController extends Controller
  23. {
  24. //首次开店初始化 shish 2020.1.19
  25. public function actionFirstInit()
  26. {
  27. }
  28. //二次初始化 shish 2020.1.19
  29. public function actionSecondInit()
  30. {
  31. $id = Yii::$app->request->get('id');
  32. if (empty($id)) {
  33. echo "商家ID无效\n";
  34. }
  35. $merchant = xhMerchantService::getById($id);
  36. if (empty($merchant)) {
  37. echo "商家无效\n";
  38. }
  39. //初始化微信菜单
  40. xhWxMenuService::applyInit($merchant);
  41. }
  42. public function actionChangeDb()
  43. {
  44. echo 'ok';
  45. }
  46. //接入一个商家需要的操作 shish 2019.9.7 yii init/join-one
  47. public function actionJoinOne()
  48. {
  49. $id = 12360;
  50. //初始化微信菜单
  51. $merchant = xhMerchantService::getById($id);
  52. //xhWxMenuService::applyInit($merchant);
  53. //模板消息
  54. $r = xhTMessageService::supplement($merchant);
  55. print_r($r);
  56. }
  57. //yii init/sub
  58. public function actionSub()
  59. {
  60. $name = 'redis_shi';
  61. $redisPubSub = \Yii::$app->redisPubSub;
  62. $redisPubSub->setOptReadTimeout(-1);
  63. $redisPubSub->subscribe($name, function ($instance, $channelName, $message) {
  64. $a = 123;
  65. });
  66. }
  67. public function actionPub()
  68. {
  69. $name = 'redis_shi';
  70. $time = 'nihao1123';
  71. $redisPubSub = \Yii::$app->redisPubSub;
  72. $redisPubSub->publish($name, $time);
  73. }
  74. public function actionBegin()
  75. {
  76. //先清除公众号里的模板消息!!!!!!!
  77. $num = 0;
  78. //清空数据
  79. $this->actionFlushAll();
  80. //国兰花尚
  81. if ($num == 0) {
  82. xhAdminService::updateById(1, ['mobile' => '18030142050', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => 'c80fd29375a3a91d3681d8445822248a', 'adminName' => '姜祖岚']);
  83. xhMerchantService::updateById(12358, [
  84. 'merchantName' => '国兰花尚',
  85. 'miniAppId' => 'wxe994a9f5fd036f69',
  86. 'miniAppSecret' => '53b646675251e940f56bd304c2dba480',
  87. 'wxAppId' => 'wx193341a4a80f6ea3',
  88. 'wxUserName' => 'gh_090c30df22e6',
  89. 'wxAliasName' => 'glhs520',
  90. 'openAppId' => 'wxe9211595a1d5a39f',
  91. 'wxToken' => 'wt01467284437',
  92. 'status' => 1,
  93. ]);
  94. xhMerchantExtendService::updateByMerchantId(12358, [
  95. 'wxAppId' => 'wx193341a4a80f6ea3',
  96. 'miniAppId' => 'wxe994a9f5fd036f69',
  97. 'wxPayMerchantId' => '1244548702',
  98. 'wxPayKey' => 'eez23jf739jsmm4309j10jnza3qw8dwm',
  99. 'webTitle' => '国兰花尚',
  100. 'webKeyword' => '国兰花尚',
  101. 'webDescription' => '国兰花尚',
  102. 'alipayAccount' => '18030142050',
  103. 'alipayAccountName' => '游俊涛',
  104. ]);
  105. }
  106. //花美灵
  107. if ($num == 1) {
  108. xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
  109. xhMerchantService::updateById(12358, [
  110. 'merchantName' => '花美灵',
  111. 'miniAppId' => 'wxe4675bab299a52f7',
  112. 'miniAppSecret' => '03dd4000a26af5c17fb86321b7d1ebf3',
  113. 'wxAppId' => 'wx84d95afcb7b594eb',
  114. 'wxUserName' => 'gh_090c30df22e6',
  115. 'wxAliasName' => 'glhs520',
  116. 'wxToken' => 'wt01467284437',
  117. 'openAppId' => 'wxb46e972ab18f27bb',
  118. 'status' => 1,
  119. ]);
  120. xhMerchantExtendService::updateByMerchantId(12358, [
  121. 'wxAppId' => 'wx84d95afcb7b594eb',
  122. 'miniAppId' => 'wxe4675bab299a52f7',
  123. 'wxPayMerchantId' => '1371367002',
  124. 'wxPayKey' => 'eoz23aG739jscv4309275jnza32wvdwm',
  125. 'webTitle' => '花美灵',
  126. 'webKeyword' => '花美灵',
  127. 'webDescription' => '花美灵',
  128. 'alipayAccount' => 'shishaohua8879@sina.com',
  129. 'alipayAccountName' => '石少华',
  130. ]);
  131. }
  132. //花卉宝
  133. if ($num == 2) {
  134. xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
  135. xhMerchantService::updateById(12358, [
  136. 'merchantName' => '花卉宝',
  137. 'miniAppId' => '',
  138. 'miniAppSecret' => '',
  139. 'wxAppId' => 'wx66dd83ff8744f7a8',
  140. 'wxUserName' => 'gh_a9105e0f02b9',
  141. 'wxAliasName' => 'ihuahuibao',
  142. 'wxToken' => 'wt01467284437',
  143. 'status' => 1,
  144. ]);
  145. xhMerchantExtendService::updateByMerchantId(12358, [
  146. 'wxAppId' => 'wx66dd83ff8744f7a8',
  147. 'miniAppId' => '',
  148. 'wxPayMerchantId' => '1442448402',
  149. 'wxPayKey' => 'xxe29ax639jvcv4m082a1jnza32svdd0',
  150. 'webTitle' => '花卉宝',
  151. 'webKeyword' => '花卉宝',
  152. 'webDescription' => '花卉宝',
  153. 'alipayAccount' => 'shishaohua8879@sina.com',
  154. 'alipayAccountName' => '石少华',
  155. ]);
  156. }
  157. }
  158. public function actionLast()
  159. {
  160. //拉取用户
  161. $this->actionPullUser();
  162. //生成模板消息
  163. //$this->actionTMSupplement();
  164. }
  165. public function actionFlushAll()
  166. {
  167. $sql = "TRUNCATE xhDrawCash;
  168. TRUNCATE xhInvite;
  169. TRUNCATE xhLuckyDrawActivity;
  170. TRUNCATE xhLuckyDrawAward;
  171. TRUNCATE xhLuckyDrawAwardCustomer;
  172. TRUNCATE xhLuckyDrawAwardParticipant;
  173. TRUNCATE xhMerchantCapital;
  174. TRUNCATE xhOrder;
  175. TRUNCATE xhOrderDayNum;
  176. TRUNCATE xhOrderGoods;
  177. TRUNCATE xhOrderMonthNum;
  178. TRUNCATE xhRecharge;
  179. TRUNCATE xhStatDealByDay;
  180. TRUNCATE xhStatInDay;
  181. TRUNCATE xhStatInMonth;
  182. TRUNCATE xhStatOutDay;
  183. TRUNCATE xhStatOutMonth;
  184. TRUNCATE xhStatUserByDay;
  185. TRUNCATE xhStatVisitByDay;
  186. TRUNCATE xhUnionUser;
  187. TRUNCATE xhUser;
  188. TRUNCATE xhUserAlipay;
  189. TRUNCATE xhUserAsset;
  190. TRUNCATE xhUserByDay;
  191. TRUNCATE xhUserByMonth;
  192. TRUNCATE xhUserCapital;
  193. TRUNCATE xhUserIntegral;
  194. TRUNCATE xhUserOldData;
  195. TRUNCATE xhUserByDay;";
  196. //清空用户
  197. $sql .= "TRUNCATE xhUser;TRUNCATE xhUserAsset;TRUNCATE xhUserCapital;TRUNCATE xhUserIntegral;";
  198. $sql .= "TRUNCATE xhUserIntegral;TRUNCATE xhUserAlipay;ALTER TABLE xhUser AUTO_INCREMENT=12536580;";
  199. //清空提现申请记录
  200. $sql .= "TRUNCATE xhDrawCash;";
  201. Yii::$app->db->createCommand($sql)->execute();
  202. //清空订单
  203. $sql = "TRUNCATE xhOrder;TRUNCATE xhOrderDayNum;TRUNCATE xhOrderGoods;TRUNCATE xhOrderMonthNum;";
  204. Yii::$app->db->createCommand($sql)->execute();
  205. //清空缓存
  206. Yii::$app->redis->executeCommand('FLUSHDB');
  207. }
  208. /**
  209. * 拉取微信用户 shish 2019.9.9
  210. */
  211. public function actionPullUser()
  212. {
  213. $merchantId = 12359;
  214. $return = UserService::syncWeixinUser($merchantId);
  215. $total = isset($return['data']['total']) ? $return['data']['total'] : 0;
  216. xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans' => $total]);
  217. }
  218. /**
  219. * 开放平台初始化
  220. * yii init/open hhb
  221. */
  222. public function actionOpen($myOption = 'hhb')
  223. {
  224. $hostname = isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME'] : '';
  225. if ($hostname == 'iZ23b0wy8awZ') {
  226. util::stop("线上服务器不允许初始化\n");
  227. }
  228. echo "开始初始化…\n";
  229. xhInitService::clear($myOption);
  230. echo "初始化完成!\n";
  231. }
  232. /**
  233. * 模板消息补充增加
  234. * ./yii init/t-m-supplement
  235. */
  236. public function actionTMSupplement()
  237. {
  238. //服务号
  239. $allMerchant = xhMerchant::getAllByCondition(['status' => 1]);
  240. if (empty($allMerchant)) {
  241. echo "没有商家需要初始化模板消息";
  242. Yii::$app->end();
  243. }
  244. foreach ($allMerchant as $val) {
  245. $merchantId = $val['id'];
  246. $merchant = xhMerchantService::getById($merchantId);
  247. xhTMessageService::supplement($merchant);
  248. }
  249. }
  250. /**
  251. * 初始化 花卉宝 的行政区划
  252. */
  253. public function actionDistrict()
  254. {
  255. set_time_limit(0);
  256. $connection = Yii::$app->db;
  257. $sql = 'truncate xhDistrict';
  258. $connection->createCommand($sql)->execute();
  259. $url = 'http://apis.map.qq.com/ws/district/v1/list?key=OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  260. $curl = new curl\Curl();
  261. $result = $curl->get($url);
  262. $r = json_decode($result, true);
  263. if (!empty($r)) {
  264. $onelist = $r['result'][0];
  265. $twolist = $r['result'][1];
  266. $threelist = $r['result'][2];
  267. foreach ($onelist as $oneKey => $oneVal) {
  268. $topId = $oneVal['id'];
  269. $name = isset($oneVal['name']) ? $oneVal['name'] : '';
  270. $fullname = $oneVal['fullname'];
  271. $lat = (string)$oneVal['location']['lat'];
  272. $lng = (string)$oneVal['location']['lng'];
  273. $oneData = ['districtId' => $topId, 'shortName' => $name, 'fullName' => $fullname, 'locationLat' => $lat, 'locationLng' => $lng, 'parentId' => 0];
  274. echo "<p>1级菜单:</p>\n";
  275. print_r($oneData);
  276. echo "\n";
  277. $oneObj = xhDistrict::add($oneData);
  278. if (isset($oneVal['cidx'])) {
  279. $onecidx = $oneVal['cidx'];
  280. if (isset($onecidx[0]) && isset($onecidx[1])) {
  281. echo "<p>2级菜单序号: | {$onecidx[0]} {$onecidx[1]}</p>\n";
  282. for ($xx = $onecidx[0]; $xx <= $onecidx[1]; $xx++) {
  283. $twoVal = $twolist[$xx];
  284. $id = $twoVal['id'];
  285. $name = isset($twoVal['name']) ? $twoVal['name'] : '';
  286. $fullname = $twoVal['fullname'];
  287. $lat = (string)$twoVal['location']['lat'];
  288. $lng = (string)$twoVal['location']['lng'];
  289. $twoData = ['districtId' => $id, 'shortName' => $name, 'fullName' => $fullname, 'locationLat' => $lat, 'locationLng' => $lng, 'parentId' => $oneObj['id']];
  290. echo $xx;
  291. print_r($twoData);
  292. echo "\n";
  293. $twoObj = xhDistrict::add($twoData);
  294. if (isset($twoVal['cidx'])) {
  295. $twocidx = $twoVal['cidx'];
  296. if (isset($twocidx[0]) && isset($twocidx[1])) {
  297. echo "<p>3级菜单序号: | {$twocidx[0]} {$twocidx[1]}</p>\n";
  298. for ($incr = $twocidx[0]; $incr <= $twocidx[1]; $incr++) {
  299. $threeVal = $threelist[$incr];
  300. $id = $threeVal['id'];
  301. $name = isset($threeVal['name']) ? $threeVal['name'] : '';
  302. $fullname = $threeVal['fullname'];
  303. $lat = (string)$threeVal['location']['lat'];
  304. $lng = (string)$threeVal['location']['lng'];
  305. $threeData = ['districtId' => $id, 'shortName' => $name, 'fullName' => $fullname, 'locationLat' => $lat, 'locationLng' => $lng, 'parentId' => $twoObj['id']];
  306. $threeObj = xhDistrict::add($threeData);
  307. echo $incr;
  308. print_r($threeData);
  309. echo "\n";
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }