InitController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. //哪些东西开店时需要初始化
  25. public function actionFirstInit()
  26. {
  27. //CouponAsset优惠券资产
  28. //初始化微信菜单
  29. //模板消息
  30. }
  31. //二次初始化 shish 2020.1.19
  32. public function actionSecondInit()
  33. {
  34. $id = Yii::$app->request->get('id');
  35. if (empty($id)) {
  36. echo "商家ID无效\n";
  37. }
  38. $merchant = xhMerchantService::getById($id);
  39. if (empty($merchant)) {
  40. echo "商家无效\n";
  41. }
  42. //初始化微信菜单
  43. xhWxMenuService::applyInit($merchant);
  44. }
  45. public function actionChangeDb()
  46. {
  47. echo 'ok';
  48. }
  49. //接入一个商家需要的操作 shish 2019.9.7 yii init/join-one
  50. public function actionJoinOne()
  51. {
  52. $id = 12360;
  53. //初始化微信菜单
  54. $merchant = xhMerchantService::getById($id);
  55. //xhWxMenuService::applyInit($merchant);
  56. //模板消息
  57. $r = xhTMessageService::supplement($merchant);
  58. print_r($r);
  59. }
  60. //yii init/sub
  61. public function actionSub()
  62. {
  63. $name = 'redis_shi';
  64. $redisPubSub = \Yii::$app->redisPubSub;
  65. $redisPubSub->setOptReadTimeout(-1);
  66. $redisPubSub->subscribe($name, function ($instance, $channelName, $message) {
  67. $a = 123;
  68. });
  69. }
  70. public function actionPub()
  71. {
  72. $name = 'redis_shi';
  73. $time = 'nihao1123';
  74. $redisPubSub = \Yii::$app->redisPubSub;
  75. $redisPubSub->publish($name, $time);
  76. }
  77. public function actionBegin()
  78. {
  79. //先清除公众号里的模板消息!!!!!!!
  80. $num = 0;
  81. //清空数据
  82. $this->actionFlushAll();
  83. //国兰花尚
  84. if ($num == 0) {
  85. xhAdminService::updateById(1, ['mobile' => '18030142050', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => 'c80fd29375a3a91d3681d8445822248a', 'adminName' => '姜祖岚']);
  86. xhMerchantService::updateById(12358, [
  87. 'merchantName' => '国兰花尚',
  88. 'miniAppId' => 'wxe994a9f5fd036f69',
  89. 'miniAppSecret' => '53b646675251e940f56bd304c2dba480',
  90. 'wxAppId' => 'wx193341a4a80f6ea3',
  91. 'wxUserName' => 'gh_090c30df22e6',
  92. 'wxAliasName' => 'glhs520',
  93. 'openAppId' => 'wxe9211595a1d5a39f',
  94. 'wxToken' => 'wt01467284437',
  95. 'status' => 1,
  96. ]);
  97. xhMerchantExtendService::updateByMerchantId(12358, [
  98. 'wxAppId' => 'wx193341a4a80f6ea3',
  99. 'miniAppId' => 'wxe994a9f5fd036f69',
  100. 'wxPayMerchantId' => '1244548702',
  101. 'wxPayKey' => 'eez23jf739jsmm4309j10jnza3qw8dwm',
  102. 'webTitle' => '国兰花尚',
  103. 'webKeyword' => '国兰花尚',
  104. 'webDescription' => '国兰花尚',
  105. 'alipayAccount' => '18030142050',
  106. 'alipayAccountName' => '游俊涛',
  107. ]);
  108. }
  109. //花美灵
  110. if ($num == 1) {
  111. xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
  112. xhMerchantService::updateById(12358, [
  113. 'merchantName' => '花美灵',
  114. 'miniAppId' => 'wxe4675bab299a52f7',
  115. 'miniAppSecret' => '03dd4000a26af5c17fb86321b7d1ebf3',
  116. 'wxAppId' => 'wx84d95afcb7b594eb',
  117. 'wxUserName' => 'gh_090c30df22e6',
  118. 'wxAliasName' => 'glhs520',
  119. 'wxToken' => 'wt01467284437',
  120. 'openAppId' => 'wxb46e972ab18f27bb',
  121. 'status' => 1,
  122. ]);
  123. xhMerchantExtendService::updateByMerchantId(12358, [
  124. 'wxAppId' => 'wx84d95afcb7b594eb',
  125. 'miniAppId' => 'wxe4675bab299a52f7',
  126. 'wxPayMerchantId' => '1371367002',
  127. 'wxPayKey' => 'eoz23aG739jscv4309275jnza32wvdwm',
  128. 'webTitle' => '花美灵',
  129. 'webKeyword' => '花美灵',
  130. 'webDescription' => '花美灵',
  131. 'alipayAccount' => 'shishaohua8879@sina.com',
  132. 'alipayAccountName' => '石少华',
  133. ]);
  134. }
  135. //花卉宝
  136. if ($num == 2) {
  137. xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
  138. xhMerchantService::updateById(12358, [
  139. 'merchantName' => '花卉宝',
  140. 'miniAppId' => '',
  141. 'miniAppSecret' => '',
  142. 'wxAppId' => 'wx66dd83ff8744f7a8',
  143. 'wxUserName' => 'gh_a9105e0f02b9',
  144. 'wxAliasName' => 'ihuahuibao',
  145. 'wxToken' => 'wt01467284437',
  146. 'status' => 1,
  147. ]);
  148. xhMerchantExtendService::updateByMerchantId(12358, [
  149. 'wxAppId' => 'wx66dd83ff8744f7a8',
  150. 'miniAppId' => '',
  151. 'wxPayMerchantId' => '1442448402',
  152. 'wxPayKey' => 'xxe29ax639jvcv4m082a1jnza32svdd0',
  153. 'webTitle' => '花卉宝',
  154. 'webKeyword' => '花卉宝',
  155. 'webDescription' => '花卉宝',
  156. 'alipayAccount' => 'shishaohua8879@sina.com',
  157. 'alipayAccountName' => '石少华',
  158. ]);
  159. }
  160. }
  161. public function actionLast()
  162. {
  163. //拉取用户
  164. $this->actionPullUser();
  165. //生成模板消息
  166. //$this->actionTMSupplement();
  167. }
  168. public function actionFlushAll()
  169. {
  170. $sql = "TRUNCATE xhDrawCash;
  171. TRUNCATE xhInvite;
  172. TRUNCATE xhLuckyDrawActivity;
  173. TRUNCATE xhLuckyDrawAward;
  174. TRUNCATE xhLuckyDrawAwardCustomer;
  175. TRUNCATE xhLuckyDrawAwardParticipant;
  176. TRUNCATE xhMerchantCapital;
  177. TRUNCATE xhOrder;
  178. TRUNCATE xhOrderDayNum;
  179. TRUNCATE xhOrderGoods;
  180. TRUNCATE xhOrderMonthNum;
  181. TRUNCATE xhRecharge;
  182. TRUNCATE xhStatDealByDay;
  183. TRUNCATE xhStatInDay;
  184. TRUNCATE xhStatInMonth;
  185. TRUNCATE xhStatOutDay;
  186. TRUNCATE xhStatOutMonth;
  187. TRUNCATE xhStatUserByDay;
  188. TRUNCATE xhStatVisitByDay;
  189. TRUNCATE xhUnionUser;
  190. TRUNCATE xhUser;
  191. TRUNCATE xhUserAlipay;
  192. TRUNCATE xhUserAsset;
  193. TRUNCATE xhUserByDay;
  194. TRUNCATE xhUserByMonth;
  195. TRUNCATE xhUserCapital;
  196. TRUNCATE xhUserIntegral;
  197. TRUNCATE xhUserOldData;
  198. TRUNCATE xhUserByDay;";
  199. //清空用户
  200. $sql .= "TRUNCATE xhUser;TRUNCATE xhUserAsset;TRUNCATE xhUserCapital;TRUNCATE xhUserIntegral;";
  201. $sql .= "TRUNCATE xhUserIntegral;TRUNCATE xhUserAlipay;ALTER TABLE xhUser AUTO_INCREMENT=12536580;";
  202. //清空提现申请记录
  203. $sql .= "TRUNCATE xhDrawCash;";
  204. Yii::$app->db->createCommand($sql)->execute();
  205. //清空订单
  206. $sql = "TRUNCATE xhOrder;TRUNCATE xhOrderDayNum;TRUNCATE xhOrderGoods;TRUNCATE xhOrderMonthNum;";
  207. Yii::$app->db->createCommand($sql)->execute();
  208. //清空缓存
  209. Yii::$app->redis->executeCommand('FLUSHDB');
  210. }
  211. /**
  212. * 拉取微信用户 shish 2019.9.9
  213. */
  214. public function actionPullUser()
  215. {
  216. $merchantId = 12359;
  217. $return = UserService::syncWeixinUser($merchantId);
  218. $total = isset($return['data']['total']) ? $return['data']['total'] : 0;
  219. xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans' => $total]);
  220. }
  221. /**
  222. * 开放平台初始化
  223. * yii init/open hhb
  224. */
  225. public function actionOpen($myOption = 'hhb')
  226. {
  227. $hostname = isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME'] : '';
  228. if ($hostname == 'iZ23b0wy8awZ') {
  229. util::stop("线上服务器不允许初始化\n");
  230. }
  231. echo "开始初始化…\n";
  232. xhInitService::clear($myOption);
  233. echo "初始化完成!\n";
  234. }
  235. /**
  236. * 模板消息补充增加
  237. * ./yii init/t-m-supplement
  238. */
  239. public function actionTMSupplement()
  240. {
  241. //服务号
  242. $allMerchant = xhMerchant::getAllByCondition(['status' => 1]);
  243. if (empty($allMerchant)) {
  244. echo "没有商家需要初始化模板消息";
  245. Yii::$app->end();
  246. }
  247. foreach ($allMerchant as $val) {
  248. $merchantId = $val['id'];
  249. $merchant = xhMerchantService::getById($merchantId);
  250. xhTMessageService::supplement($merchant);
  251. }
  252. }
  253. }