UpgradeController.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller;
  12. use app\Request;
  13. use app\services\activity\coupon\StoreCouponIssueServices;
  14. use app\services\activity\coupon\StoreCouponProductServices;
  15. use app\services\order\StoreOrderCartInfoServices;
  16. use app\services\order\StoreOrderCreateServices;
  17. use app\services\order\StoreOrderRefundServices;
  18. use app\services\order\StoreOrderServices;
  19. use app\services\system\UpgradeServices;
  20. use app\services\user\UserBillServices;
  21. use app\services\user\UserBrokerageServices;
  22. use app\services\user\UserMoneyServices;
  23. use app\services\user\UserBrokerageFrozenServices;
  24. use think\facade\Db;
  25. use think\facade\Env;
  26. class UpgradeController
  27. {
  28. /**
  29. * @var UpgradeServices
  30. */
  31. private $services;
  32. /**
  33. * UpgradeController constructor.
  34. * @param UpgradeServices $services
  35. */
  36. public function __construct(UpgradeServices $services)
  37. {
  38. $this->services = $services;
  39. }
  40. /**
  41. * 升级程序页面
  42. * @param Request $request
  43. * @return \think\response\View
  44. */
  45. public function index(Request $request)
  46. {
  47. $data = $this->upData();
  48. $Title = "CRMEB升级程序";
  49. $Powered = "Powered by CRMEB";
  50. //获取当前版本号
  51. $version_now = $this->getversion('.version')['version'];
  52. $version_new = $data['new_version'];
  53. $isUpgrade = true;
  54. $executeIng = false;
  55. return view('/upgrade/step1', [
  56. 'title' => $Title,
  57. 'powered' => $Powered,
  58. 'version_now' => $version_now,
  59. 'version_new' => $version_new,
  60. 'isUpgrade' => json_encode($isUpgrade),
  61. 'executeIng' => json_encode($executeIng),
  62. 'next' => 1,
  63. 'action' => 'upgrade'
  64. ]);
  65. }
  66. /**
  67. * 获取当前版本号
  68. * @return array
  69. */
  70. public function getversion($str)
  71. {
  72. $version_arr = [];
  73. $curent_version = @file(app()->getRootPath() . $str);
  74. foreach ($curent_version as $val) {
  75. list($k, $v) = explode('=', $val);
  76. $version_arr[$k] = $v;
  77. }
  78. return $version_arr;
  79. }
  80. /**
  81. * 写入升级过程
  82. * @param string $field
  83. * @param int $n
  84. * @return bool
  85. */
  86. public function setIsUpgrade(string $field, int $n = 0)
  87. {
  88. $upgrade = parse_ini_file(public_path('upgrade') . '.upgrade');
  89. if ($n) {
  90. if (!is_array($upgrade)) {
  91. $upgrade = [];
  92. }
  93. $string = '';
  94. foreach ($upgrade as $key => $item) {
  95. $string .= $key . '=' . $item . "\r\n";
  96. }
  97. $string .= $field . '=' . $n . "\r\n";
  98. file_put_contents(public_path('upgrade') . '.upgrade', $string);
  99. return true;
  100. } else {
  101. if (!is_array($upgrade)) {
  102. return false;
  103. }
  104. return isset($upgrade[$field]);
  105. }
  106. }
  107. public function upgrade(Request $request)
  108. {
  109. list($sleep, $page, $prefix) = $request->getMore([
  110. ['sleep', 0],
  111. ['page', 1],
  112. ['prefix', 'eb_'],
  113. ], true);
  114. $data = $this->upData();
  115. $code_now = $this->getversion('.version')['version_code'];
  116. if ($data['new_code'] == $code_now) {
  117. return app('json')->success(['sleep' => -1]);
  118. }
  119. $sql_arr = [];
  120. foreach ($data['update_sql'] as $items) {
  121. if ($items['code'] > $code_now) {
  122. $sql_arr[] = $items;
  123. }
  124. }
  125. //sql 执行完成,开始执行修改数据
  126. if (!isset($sql_arr[$sleep])) {
  127. // $limit = 100;
  128. // if (!$this->setIsUpgrade('money')) {
  129. // $res = $this->handleMoney((int)$sleep, (int)$page, (int)$limit);
  130. // return app('json')->success($res);
  131. // } elseif (!$this->setIsUpgrade('brokerage')) {
  132. // $res = $this->handleBrokerage((int)$sleep, (int)$page, (int)$limit);
  133. // return app('json')->success($res);
  134. // } elseif (!$this->setIsUpgrade('orderRefund')) {
  135. // $res = $this->handleOrderRefund((int)$sleep, (int)$page, (int)$limit);
  136. // return app('json')->success($res);
  137. // } else {
  138. // file_put_contents(app()->getRootPath() . '.version', "version=" . $data['new_version'] . "\nversion_code=" . $data['new_code']);
  139. // return app('json')->success(['sleep' => -1]);
  140. // }
  141. // $limit = 100;
  142. // if (!$this->setIsUpgrade('cartInfo')) {
  143. // $res = $this->handleCartInfo((int)$sleep, (int)$page, (int)$limit);
  144. // return app('json')->success($res);
  145. // } else {
  146. // file_put_contents(app()->getRootPath() . '.version', "version=" . $data['new_version'] . "\nversion_code=" . $data['new_code'] . "\napp_id=ze7x9rxsv09l6pvsyo" . "\napp_key=fuF7U9zaybLa5gageVQzxtxQMFnvU2OI");
  147. // $this->services->generateSignature();
  148. // return app('json')->success(['sleep' => -1]);
  149. // }
  150. // $limit = 100;
  151. // if (!$this->setIsUpgrade('coupon')) {
  152. // $res = $this->handleCoupon((int)$sleep, (int)$page, (int)$limit);
  153. // return app('json')->success($res);
  154. // } else {
  155. // $this->setEnv();
  156. // file_put_contents(app()->getRootPath() . '.version', "version=" . $data['new_version'] . "\nversion_code=" . $data['new_code'] . "\nplatform=CRMEB\napp_id=ze7x9rxsv09l6pvsyo" . "\napp_key=fuF7U9zaybLa5gageVQzxtxQMFnvU2OI");
  157. // $this->services->generateSignature();
  158. // return app('json')->success(['sleep' => -1]);
  159. // }
  160. file_put_contents(app()->getRootPath() . '.version', "version=" . $data['new_version'] . "\nversion_code=" . $data['new_code'] . "\nplatform=CRMEB\napp_id=ze7x9rxsv09l6pvsyo" . "\napp_key=fuF7U9zaybLa5gageVQzxtxQMFnvU2OI");
  161. $this->services->generateSignature();
  162. return app('json')->success(['sleep' => -1]);
  163. }
  164. $sql = $sql_arr[$sleep];
  165. Db::startTrans();
  166. try {
  167. if ($sql['type'] == 1) {
  168. if (isset($sql['findSql']) && $sql['findSql']) {
  169. $table = $prefix . $sql['table'];
  170. $findSql = str_replace('@table', $table, $sql['findSql']);
  171. if (!empty(Db::query($findSql))) {
  172. $item['table'] = $table;
  173. $item['status'] = 1;
  174. $item['error'] = $table . '表已存在';
  175. $item['sleep'] = $sleep + 1;
  176. $item['add_time'] = date('Y-m-d H:i:s', time());
  177. Db::commit();
  178. return app('json')->success($item);
  179. }
  180. }
  181. if (isset($sql['sql']) && $sql['sql']) {
  182. $upSql = $sql['sql'];
  183. $upSql = str_replace('@table', $table, $upSql);
  184. Db::execute($upSql);
  185. $item['table'] = $table;
  186. $item['status'] = 1;
  187. $item['error'] = $table . '表添加成功';
  188. $item['sleep'] = $sleep + 1;
  189. $item['add_time'] = date('Y-m-d H:i:s', time());
  190. Db::commit();
  191. return app('json')->success($item);
  192. }
  193. } elseif ($sql['type'] == 2) {
  194. if (isset($sql['findSql']) && $sql['findSql']) {
  195. $table = $prefix . $sql['table'];
  196. $findSql = str_replace('@table', $table, $sql['findSql']);
  197. if (empty(Db::query($findSql))) {
  198. $item['table'] = $table;
  199. $item['status'] = 1;
  200. $item['error'] = $table . '表不存在';
  201. $item['sleep'] = $sleep + 1;
  202. $item['add_time'] = date('Y-m-d H:i:s', time());
  203. Db::commit();
  204. return app('json')->success($item);
  205. }
  206. }
  207. if (isset($sql['sql']) && $sql['sql']) {
  208. $upSql = $sql['sql'];
  209. $upSql = str_replace('@table', $table, $upSql);
  210. Db::execute($upSql);
  211. $item['table'] = $table;
  212. $item['status'] = 1;
  213. $item['error'] = $table . '表删除成功';
  214. $item['sleep'] = $sleep + 1;
  215. $item['add_time'] = date('Y-m-d H:i:s', time());
  216. Db::commit();
  217. return app('json')->success($item);
  218. }
  219. } elseif ($sql['type'] == 3) {
  220. if (isset($sql['findSql']) && $sql['findSql']) {
  221. $table = $prefix . $sql['table'];
  222. $findSql = str_replace('@table', $table, $sql['findSql']);
  223. if (!empty(Db::query($findSql))) {
  224. $item['table'] = $table;
  225. $item['status'] = 1;
  226. $item['error'] = $table . '表中' . $sql['field'] . '已存在';
  227. $item['sleep'] = $sleep + 1;
  228. $item['add_time'] = date('Y-m-d H:i:s', time());
  229. Db::commit();
  230. return app('json')->success($item);
  231. }
  232. }
  233. if (isset($sql['sql']) && $sql['sql']) {
  234. $upSql = $sql['sql'];
  235. $upSql = str_replace('@table', $table, $upSql);
  236. Db::execute($upSql);
  237. $item['table'] = $table;
  238. $item['status'] = 1;
  239. $item['error'] = $table . '表中' . $sql['field'] . '字段添加成功';
  240. $item['sleep'] = $sleep + 1;
  241. $item['add_time'] = date('Y-m-d H:i:s', time());
  242. Db::commit();
  243. return app('json')->success($item);
  244. }
  245. } elseif ($sql['type'] == 4) {
  246. if (isset($sql['findSql']) && $sql['findSql']) {
  247. $table = $prefix . $sql['table'];
  248. $findSql = str_replace('@table', $table, $sql['findSql']);
  249. if (empty(Db::query($findSql))) {
  250. $item['table'] = $table;
  251. $item['status'] = 1;
  252. $item['error'] = $table . '表中' . $sql['field'] . '不存在';
  253. $item['sleep'] = $sleep + 1;
  254. $item['add_time'] = date('Y-m-d H:i:s', time());
  255. Db::commit();
  256. return app('json')->success($item);
  257. }
  258. }
  259. if (isset($sql['sql']) && $sql['sql']) {
  260. $upSql = $sql['sql'];
  261. $upSql = str_replace('@table', $table, $upSql);
  262. Db::execute($upSql);
  263. $item['table'] = $table;
  264. $item['status'] = 1;
  265. $item['error'] = $table . '表中' . $sql['field'] . '字段修改成功';
  266. $item['sleep'] = $sleep + 1;
  267. $item['add_time'] = date('Y-m-d H:i:s', time());
  268. Db::commit();
  269. return app('json')->success($item);
  270. }
  271. } elseif ($sql['type'] == 5) {
  272. if (isset($sql['findSql']) && $sql['findSql']) {
  273. $table = $prefix . $sql['table'];
  274. $findSql = str_replace('@table', $table, $sql['findSql']);
  275. if (empty(Db::query($findSql))) {
  276. $item['table'] = $table;
  277. $item['status'] = 1;
  278. $item['error'] = $table . '表中' . $sql['field'] . '不存在';
  279. $item['sleep'] = $sleep + 1;
  280. $item['add_time'] = date('Y-m-d H:i:s', time());
  281. Db::commit();
  282. return app('json')->success($item);
  283. }
  284. }
  285. if (isset($sql['sql']) && $sql['sql']) {
  286. $upSql = $sql['sql'];
  287. $upSql = str_replace('@table', $table, $upSql);
  288. Db::execute($upSql);
  289. $item['table'] = $table;
  290. $item['status'] = 1;
  291. $item['error'] = $table . '表中' . $sql['field'] . '字段删除成功';
  292. $item['sleep'] = $sleep + 1;
  293. $item['add_time'] = date('Y-m-d H:i:s', time());
  294. Db::commit();
  295. return app('json')->success($item);
  296. }
  297. } elseif ($sql['type'] == 6) {
  298. $table = $prefix . $sql['table'] ?? '';
  299. if (isset($sql['findSql']) && $sql['findSql']) {
  300. $findSql = str_replace('@table', $table, $sql['findSql']);
  301. if (!empty(Db::query($findSql))) {
  302. $item['table'] = $prefix . $sql['table'];
  303. $item['status'] = 1;
  304. $item['error'] = $table . '表中此数据已存在';
  305. $item['sleep'] = $sleep + 1;
  306. $item['add_time'] = date('Y-m-d H:i:s', time());
  307. Db::commit();
  308. return app('json')->success($item);
  309. }
  310. }
  311. if (isset($sql['sql']) && $sql['sql']) {
  312. $upSql = $sql['sql'];
  313. $upSql = str_replace('@table', $table, $upSql);
  314. if (isset($sql['whereSql']) && $sql['whereSql']) {
  315. $whereTable = $prefix . $sql['whereTable'] ?? '';
  316. $whereSql = str_replace('@whereTable', $whereTable, $sql['whereSql']);
  317. $tabId = Db::query($whereSql)[0]['tabId'] ?? 0;
  318. if (!$tabId) {
  319. $item['table'] = $whereTable;
  320. $item['status'] = 1;
  321. $item['error'] = '查询父类ID不存在';
  322. $item['sleep'] = $sleep + 1;
  323. $item['add_time'] = date('Y-m-d H:i:s', time());
  324. Db::commit();
  325. return app('json')->success($item);
  326. }
  327. $upSql = str_replace('@tabId', $tabId, $upSql);
  328. }
  329. if (Db::execute($upSql)) {
  330. $item['table'] = $table;
  331. $item['status'] = 1;
  332. $item['error'] = '数据添加成功';
  333. $item['sleep'] = $sleep + 1;
  334. $item['add_time'] = date('Y-m-d H:i:s', time());
  335. Db::commit();
  336. return app('json')->success($item);
  337. }
  338. }
  339. } elseif ($sql['type'] == 7) {
  340. $table = $prefix . $sql['table'] ?? '';
  341. if (isset($sql['findSql']) && $sql['findSql']) {
  342. $findSql = str_replace('@table', $table, $sql['findSql']);
  343. if (empty(Db::query($findSql))) {
  344. $item['table'] = $prefix . $sql['table'];
  345. $item['status'] = 1;
  346. $item['error'] = $table . '表中此数据不存在';
  347. $item['sleep'] = $sleep + 1;
  348. $item['add_time'] = date('Y-m-d H:i:s', time());
  349. Db::commit();
  350. return app('json')->success($item);
  351. }
  352. }
  353. if (isset($sql['sql']) && $sql['sql']) {
  354. $upSql = $sql['sql'];
  355. $upSql = str_replace('@table', $table, $upSql);
  356. if (isset($sql['whereSql']) && $sql['whereSql']) {
  357. $whereTable = $prefix . $sql['whereTable'] ?? '';
  358. $whereSql = str_replace('@whereTable', $whereTable, $sql['whereSql']);
  359. $tabId = Db::query($whereSql)[0]['tabId'] ?? 0;
  360. if (!$tabId) {
  361. $item['table'] = $whereTable;
  362. $item['status'] = 1;
  363. $item['error'] = '查询父类ID不存在';
  364. $item['sleep'] = $sleep + 1;
  365. $item['add_time'] = date('Y-m-d H:i:s', time());
  366. Db::commit();
  367. return app('json')->success($item);
  368. }
  369. $upSql = str_replace('@tabId', $tabId, $upSql);
  370. }
  371. if (Db::execute($upSql)) {
  372. $item['table'] = $table;
  373. $item['status'] = 1;
  374. $item['error'] = '数据修改成功';
  375. $item['sleep'] = $sleep + 1;
  376. $item['add_time'] = date('Y-m-d H:i:s', time());
  377. Db::commit();
  378. return app('json')->success($item);
  379. }
  380. }
  381. } elseif ($sql['type'] == 8) {
  382. } elseif ($sql['type'] == -1) {
  383. $table = $prefix . $sql['table'];
  384. if (isset($sql['sql']) && $sql['sql']) {
  385. $upSql = $sql['sql'];
  386. $upSql = str_replace('@table', $table, $upSql);
  387. if (isset($sql['new_table']) && $sql['new_table']) {
  388. $new_table = $prefix . $sql['new_table'];
  389. $upSql = str_replace('@new_table', $new_table, $upSql);
  390. }
  391. Db::execute($upSql);
  392. $item['table'] = $table;
  393. $item['status'] = 1;
  394. $item['error'] = $table . ' sql执行成功';
  395. $item['sleep'] = $sleep + 1;
  396. $item['add_time'] = date('Y-m-d H:i:s', time());
  397. Db::commit();
  398. return app('json')->success($item);
  399. }
  400. }
  401. } catch (\Throwable $e) {
  402. $item['table'] = $prefix . $sql['table'];
  403. $item['status'] = 0;
  404. $item['sleep'] = $sleep + 1;
  405. $item['add_time'] = date('Y-m-d H:i:s', time());
  406. $item['error'] = $e->getMessage();
  407. Db::rollBack();
  408. return app('json')->success($item);
  409. }
  410. }
  411. /**
  412. * 重写.env文件
  413. * @author 吴汐
  414. * @email 442384644@qq.com
  415. * @date 2023/03/04
  416. */
  417. public function setEnv()
  418. {
  419. $unique = uniqid();
  420. //读取配置文件,并替换真实配置数据1
  421. $strConfig = file_get_contents(root_path() . 'public/install/.env');
  422. $strConfig = str_replace('#DB_HOST#', Env::get('DATABASE.HOSTNAME', ''), $strConfig);
  423. $strConfig = str_replace('#DB_NAME#', Env::get('DATABASE.DATABASE', ''), $strConfig);
  424. $strConfig = str_replace('#DB_USER#', Env::get('DATABASE.USERNAME', ''), $strConfig);
  425. $strConfig = str_replace('#DB_PWD#', Env::get('DATABASE.PASSWORD', ''), $strConfig);
  426. $strConfig = str_replace('#DB_PORT#', Env::get('DATABASE.HOSTPORT', ''), $strConfig);
  427. $strConfig = str_replace('#DB_PREFIX#', Env::get('DATABASE.PREFIX', ''), $strConfig);
  428. $strConfig = str_replace('#DB_CHARSET#', 'utf8', $strConfig);
  429. $strConfig = str_replace('#CACHE_TYPE#', 'redis', $strConfig);
  430. $strConfig = str_replace('#CACHE_PREFIX#', 'cache_' . $unique . ':', $strConfig);
  431. $strConfig = str_replace('#CACHE_TAG_PREFIX#', 'cache_tag_' . $unique . ':', $strConfig);
  432. $strConfig = str_replace('#RB_HOST#', Env::get('REDIS.REDIS_HOSTNAME', ''), $strConfig);
  433. $strConfig = str_replace('#RB_PORT#', Env::get('REDIS.PORT', ''), $strConfig);
  434. $strConfig = str_replace('#RB_PWD#', Env::get('REDIS.REDIS_PASSWORD', ''), $strConfig);
  435. $strConfig = str_replace('#RB_SELECT#', Env::get('REDIS.SELECT', ''), $strConfig);
  436. $strConfig = str_replace('#QUEUE_NAME#', $unique, $strConfig);
  437. @chmod(root_path() . '/.env', 0777); //数据库配置文件的地址
  438. @file_put_contents(root_path() . '/.env', $strConfig); //数据库配置文件的地址
  439. }
  440. /**
  441. * 更新分类券
  442. * @param int $sleep
  443. * @param int $page
  444. * @param int $limit
  445. * @return array
  446. * @author 吴汐
  447. * @email 442384644@qq.com
  448. * @date 2023/03/04
  449. */
  450. public function handleCoupon(int $sleep = 1, int $page = 1, int $limit = 100)
  451. {
  452. $list = app()->make(StoreCouponIssueServices::class)->selectList([['category_id', '>', 0]], 'id,category_id', $page, $limit)->toArray();
  453. if (count($list)) {
  454. $allData = [];
  455. foreach ($list as $item) {
  456. $data = [
  457. 'coupon_id' => $item['id'],
  458. 'product_id' => 0,
  459. 'category_id' => $item['category_id']
  460. ];
  461. $allData[] = $data;
  462. }
  463. if ($allData) {
  464. app()->make(StoreCouponProductServices::class)->saveAll($allData);
  465. }
  466. $info['table'] = 'store_coupon_product';
  467. $info['status'] = 1;
  468. $info['error'] = '分类券数据更新成功';
  469. $info['sleep'] = $sleep + 1;
  470. $info['page'] = $page + 1;
  471. $info['add_time'] = date('Y-m-d H:i:s', time());
  472. return $info;
  473. } else {
  474. $this->setIsUpgrade('coupon', 1);
  475. $info['table'] = 'store_coupon_product';
  476. $info['status'] = 1;
  477. $info['error'] = '分类券数据更新成功';
  478. $info['sleep'] = $sleep + 1;
  479. $info['page'] = 1;
  480. $info['add_time'] = date('Y-m-d H:i:s', time());
  481. return $info;
  482. }
  483. }
  484. /**
  485. * 处理历史余额数据
  486. * @param int $sleep
  487. * @param int $page
  488. * @param int $limit
  489. * @return mixed
  490. */
  491. public function handleMoney(int $sleep = 1, int $page = 1, int $limit = 100)
  492. {
  493. /** @var UserBillServices $userBillServics */
  494. $userBillServics = app()->make(UserBillServices::class);
  495. $where = ['category' => 'now_money', 'type' => ['pay_product', 'pay_product_refund', 'system_add', 'system_sub', 'recharge', 'lottery_use', 'lottery_add']];
  496. $list = $userBillServics->getList($where, '*', $page, $limit, [], 'id asc');
  497. if ($list) {
  498. $allData = $data = [];
  499. foreach ($list as $item) {
  500. $data = [
  501. 'uid' => $item['uid'],
  502. 'link_id' => $item['link_id'],
  503. 'pm' => $item['pm'],
  504. 'title' => $item['title'],
  505. 'type' => $item['type'],
  506. 'number' => $item['number'],
  507. 'balance' => $item['balance'],
  508. 'mark' => $item['mark'],
  509. 'add_time' => strtotime($item['add_time']),
  510. ];
  511. $allData[] = $data;
  512. }
  513. if ($allData) {
  514. /** @var UserMoneyServices $userMoneyServices */
  515. $userMoneyServices = app()->make(UserMoneyServices::class);
  516. $userMoneyServices->saveAll($allData);
  517. }
  518. $info['table'] = 'user_money';
  519. $info['status'] = 1;
  520. $info['error'] = '余额数据更新成功';
  521. $info['sleep'] = $sleep + 1;
  522. $info['page'] = $page + 1;
  523. $info['add_time'] = date('Y-m-d H:i:s', time());
  524. return $info;
  525. } else {
  526. $this->setIsUpgrade('money', 1);
  527. $info['table'] = 'user_money';
  528. $info['status'] = 1;
  529. $info['error'] = '余额数据更新成功';
  530. $info['sleep'] = $sleep + 1;
  531. $info['page'] = 1;
  532. $info['add_time'] = date('Y-m-d H:i:s', time());
  533. return $info;
  534. }
  535. }
  536. /**
  537. * 处理历史佣金数据
  538. * @param int $sleep
  539. * @param int $page
  540. * @param int $limit
  541. * @return mixed
  542. */
  543. public function handleBrokerage(int $sleep = 1, int $page = 1, int $limit = 100)
  544. {
  545. /** @var UserBillServices $userBillServics */
  546. $userBillServics = app()->make(UserBillServices::class);
  547. $where = ['category' => ['', 'now_money'], 'type' => ['brokerage', 'brokerage_user', 'extract', 'refund', 'extract_fail']];
  548. $list = $userBillServics->getList($where, '*', $page, $limit, [], 'id asc');
  549. if ($list) {
  550. $allData = $data = [];
  551. /** @var $brokerageFrozenServices */
  552. $brokerageFrozenServices = app()->make(UserBrokerageFrozenServices::class);
  553. $frozenList = $brokerageFrozenServices->getColumn([['uill_id', 'in', array_column($list, 'id')], ['frozen_time', '>', time()]], 'uill_id,frozen_time', 'uill_id');
  554. foreach ($list as $item) {
  555. if (in_array($item['type'], ['brokerage_user', 'extract', 'refund', 'extract_fail'])) {
  556. $type = $item['type'];
  557. } else {
  558. if (strpos($item['mark'], '二级')) {
  559. $type = 'two_brokerage';
  560. } else {
  561. $type = 'one_brokerage';
  562. }
  563. }
  564. $data = [
  565. 'uid' => $item['uid'],
  566. 'link_id' => $item['link_id'],
  567. 'pm' => $item['pm'],
  568. 'title' => $item['title'],
  569. 'type' => $type,
  570. 'number' => $item['number'],
  571. 'balance' => $item['balance'],
  572. 'mark' => $item['mark'],
  573. 'frozen_time' => $frozenList[$item['id']]['frozen_time'] ?? 0,
  574. 'add_time' => strtotime($item['add_time']),
  575. ];
  576. $allData[] = $data;
  577. }
  578. if ($allData) {
  579. /** @var UserBrokerageServices $userBrokerageServices */
  580. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  581. $userBrokerageServices->saveAll($allData);
  582. }
  583. $info['table'] = 'user_brokerage';
  584. $info['status'] = 1;
  585. $info['error'] = '佣金数据更新成功';
  586. $info['sleep'] = $sleep + 1;
  587. $info['page'] = $page + 1;
  588. $info['add_time'] = date('Y-m-d H:i:s', time());
  589. return $info;
  590. } else {
  591. $this->setIsUpgrade('brokerage', 1);
  592. $info['table'] = 'user_brokerage';
  593. $info['status'] = 1;
  594. $info['error'] = '佣金数据更新成功';
  595. $info['sleep'] = $sleep + 1;
  596. $info['page'] = 1;
  597. $info['add_time'] = date('Y-m-d H:i:s', time());
  598. return $info;
  599. }
  600. }
  601. /**
  602. * 处理历史退款数据
  603. * @param int $sleep
  604. * @param int $page
  605. * @param int $limit
  606. * @return mixed
  607. * @throws \think\db\exception\DataNotFoundException
  608. * @throws \think\db\exception\DbException
  609. * @throws \think\db\exception\ModelNotFoundException
  610. */
  611. public function handleOrderRefund(int $sleep = 1, int $page = 1, int $limit = 100)
  612. {
  613. /** @var StoreOrderServices $storeOrderServices */
  614. $storeOrderServices = app()->make(StoreOrderServices::class);
  615. $list = $storeOrderServices->getSplitOrderList(['refund_status' => [1, 2], ['refund_type' => [1, 2, 4, 5, 6]]], ['*'], [], $page, $limit, 'id asc');
  616. $allData = $refundOrderData = [];
  617. if ($list) {
  618. /** @var StoreOrderCreateServices $storeOrderCreateServices */
  619. $storeOrderCreateServices = app()->make(StoreOrderCreateServices::class);
  620. /** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */
  621. $storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class);
  622. $time = time();
  623. foreach ($list as $order) {
  624. //生成退款订单
  625. $refundOrderData['uid'] = $order['uid'];
  626. $refundOrderData['store_id'] = $order['store_id'];
  627. $refundOrderData['store_order_id'] = $order['id'];
  628. $refundOrderData['order_id'] = $storeOrderCreateServices->getNewOrderId('');
  629. $refundOrderData['refund_num'] = $order['total_num'];
  630. $refundOrderData['refund_type'] = $order['refund_type'];
  631. $refundOrderData['refund_price'] = $order['pay_price'];
  632. $refundOrderData['refunded_price'] = 0;
  633. $refundOrderData['refund_explain'] = $order['refund_reason_wap_explain'];
  634. $refundOrderData['refund_img'] = $order['refund_reason_wap_img'];
  635. $refundOrderData['refund_reason'] = $order['refund_reason_wap'];
  636. $refundOrderData['refund_express'] = $order['refund_express'];
  637. $refundOrderData['refunded_time'] = $order['refund_type'] == 6 ? $order['refund_reason_time'] : 0;
  638. $refundOrderData['add_time'] = $order['refund_reason_time'];
  639. $cartInfos = $storeOrderCartInfoServices->getCartColunm(['oid' => $order['id']], 'id,cart_id,cart_num,cart_info');
  640. foreach ($cartInfos as &$cartInfo) {
  641. $cartInfo['cart_info'] = is_string($cartInfo['cart_info']) ? json_decode($cartInfo['cart_info'], true) : $cartInfo['cart_info'];
  642. }
  643. $refundOrderData['cart_info'] = json_encode(array_column($cartInfos, 'cart_info'));
  644. $allData[] = $refundOrderData;
  645. }
  646. if ($allData) {
  647. /** @var StoreOrderRefundServices $storeOrderRefundServices */
  648. $storeOrderRefundServices = app()->make(StoreOrderRefundServices::class);
  649. $storeOrderRefundServices->saveAll($allData);
  650. }
  651. $info['table'] = 'store_order_refund';
  652. $info['status'] = 1;
  653. $info['error'] = '退款数据更新成功';
  654. $info['sleep'] = $sleep + 1;
  655. $info['page'] = $page + 1;
  656. $info['add_time'] = date('Y-m-d H:i:s', time());
  657. return $info;
  658. } else {
  659. $this->setIsUpgrade('orderRefund', 1);
  660. $info['table'] = 'store_order_refund';
  661. $info['status'] = 1;
  662. $info['error'] = '退款数据更新成功';
  663. $info['sleep'] = $sleep + 1;
  664. $info['page'] = 1;
  665. $info['add_time'] = date('Y-m-d H:i:s', time());
  666. return $info;
  667. }
  668. }
  669. /**
  670. * 更新订单商品表
  671. * @param int $sleep
  672. * @param int $page
  673. * @param int $limit
  674. * @return array
  675. */
  676. public function handleCartInfo(int $sleep = 1, int $page = 1, int $limit = 100)
  677. {
  678. /** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */
  679. $storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class);
  680. $list = $storeOrderCartInfoServices->selectList(['uid' => 0], 'id,oid', $page, $limit)->toArray();
  681. $allData = $cartData = [];
  682. if ($list) {
  683. /** @var StoreOrderServices $storeOrderServices */
  684. $storeOrderServices = app()->make(StoreOrderServices::class);
  685. $uids = $storeOrderServices->getColumn([['id', 'in', array_column($list, 'oid')]], 'uid', 'id');
  686. foreach ($list as $cart) {
  687. $cartData['id'] = $cart['id'];
  688. $cartData['uid'] = $uids[$cart['oid']] ?? 0;
  689. $allData[] = $cartData;
  690. }
  691. if ($allData) {
  692. $storeOrderCartInfoServices->saveAll($allData);
  693. }
  694. $info['table'] = 'store_order_cart_info';
  695. $info['status'] = 1;
  696. $info['error'] = '订单商品数据更新成功';
  697. $info['sleep'] = $sleep + 1;
  698. $info['page'] = $page + 1;
  699. } else {
  700. $this->setIsUpgrade('cartInfo', 1);
  701. $info['table'] = 'store_order_cart_info';
  702. $info['status'] = 1;
  703. $info['error'] = '订单商品数据更新成功';
  704. $info['sleep'] = $sleep + 1;
  705. $info['page'] = 1;
  706. }
  707. $info['add_time'] = date('Y-m-d H:i:s', time());
  708. return $info;
  709. }
  710. /**
  711. * 升级数据
  712. * @return mixed
  713. */
  714. public function upData()
  715. {
  716. $data['new_version'] = 'CRMEB-BZ v5.2.1';
  717. $data['new_code'] = 521;
  718. $data['update_sql'] = [
  719. [
  720. 'code' => 521,
  721. 'type' => 3,
  722. 'table' => "agent_level",
  723. 'field' => "one_brokerage_percent",
  724. 'findSql' => "show columns from `@table` like 'one_brokerage_percent'",
  725. 'sql' => "ALTER TABLE `@table` ADD `one_brokerage_percent` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '一级分佣比例' AFTER `one_brokerage`"
  726. ],
  727. [
  728. 'code' => 521,
  729. 'type' => 3,
  730. 'table' => "agent_level",
  731. 'field' => "two_brokerage_percent",
  732. 'findSql' => "show columns from `@table` like 'two_brokerage_percent'",
  733. 'sql' => "ALTER TABLE `@table` ADD `two_brokerage_percent` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '二级分佣比例' AFTER `two_brokerage`"
  734. ],
  735. [
  736. 'code' => 521,
  737. 'type' => 3,
  738. 'table' => "store_bargain",
  739. 'field' => "is_commission",
  740. 'findSql' => "show columns from `@table` like 'is_commission'",
  741. 'sql' => "ALTER TABLE `@table` ADD `is_commission` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否返佣'"
  742. ],
  743. [
  744. 'code' => 521,
  745. 'type' => 3,
  746. 'table' => "store_seckill",
  747. 'field' => "is_commission",
  748. 'findSql' => "show columns from `@table` like 'is_commission'",
  749. 'sql' => "ALTER TABLE `@table` ADD `is_commission` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否返佣'"
  750. ],
  751. [
  752. 'code' => 521,
  753. 'type' => 6,
  754. 'table' => "system_config_tab",
  755. 'whereTable' => "system_config_tab",
  756. 'findSql' => "select id from @table where `eng_title` = 'wechat_config'",
  757. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat'",
  758. 'sql' => "INSERT INTO `@table` VALUES (NULL, @tabId, '公众号配置', 'wechat_config', 1, 0, '', 3, 0)"
  759. ],
  760. [
  761. 'code' => 521,
  762. 'type' => 6,
  763. 'table' => "system_config_tab",
  764. 'whereTable' => "system_config_tab",
  765. 'findSql' => "select id from @table where `eng_title` = 'wechat_encoding'",
  766. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat'",
  767. 'sql' => "INSERT INTO `@table` VALUES (NULL, @tabId, '服务器域名配置', 'wechat_encoding', 1, 0, '', 3, 0)"
  768. ],
  769. [
  770. 'code' => 521,
  771. 'type' => 6,
  772. 'table' => "system_config_tab",
  773. 'whereTable' => "system_config_tab",
  774. 'findSql' => "select id from @table where `eng_title` = 'routine_config'",
  775. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine'",
  776. 'sql' => "INSERT INTO `@table` VALUES (NULL, @tabId, '小程序配置', 'routine_config', 1, 0, '', 3, 0)"
  777. ],
  778. [
  779. 'code' => 521,
  780. 'type' => 6,
  781. 'table' => "system_config_tab",
  782. 'whereTable' => "system_config_tab",
  783. 'findSql' => "select id from @table where `eng_title` = 'routine_encoding'",
  784. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine'",
  785. 'sql' => "INSERT INTO `@table` VALUES (NULL, @tabId, '消息推送配置', 'routine_encoding', 1, 0, '', 3, 0)"
  786. ],
  787. [
  788. 'code' => 521,
  789. 'type' => 7,
  790. 'table' => "system_config",
  791. 'whereTable' => "system_config_tab",
  792. 'findSql' => "select id from @table where `menu_name` = 'wechat_appid'",
  793. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  794. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_appid'"
  795. ],
  796. [
  797. 'code' => 521,
  798. 'type' => 7,
  799. 'table' => "system_config",
  800. 'whereTable' => "system_config_tab",
  801. 'findSql' => "select id from @table where `menu_name` = 'wechat_appsecret'",
  802. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  803. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_appsecret'"
  804. ],
  805. [
  806. 'code' => 521,
  807. 'type' => 7,
  808. 'table' => "system_config",
  809. 'whereTable' => "system_config_tab",
  810. 'findSql' => "select id from @table where `menu_name` = 'wechat_token'",
  811. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_encoding'",
  812. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_token'"
  813. ],
  814. [
  815. 'code' => 521,
  816. 'type' => 7,
  817. 'table' => "system_config",
  818. 'whereTable' => "system_config_tab",
  819. 'findSql' => "select id from @table where `menu_name` = 'wechat_encode'",
  820. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_encoding'",
  821. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_encode'"
  822. ],
  823. [
  824. 'code' => 521,
  825. 'type' => 7,
  826. 'table' => "system_config",
  827. 'whereTable' => "system_config_tab",
  828. 'findSql' => "select id from @table where `menu_name` = 'wechat_encodingaeskey'",
  829. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_encoding'",
  830. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_encodingaeskey'"
  831. ],
  832. [
  833. 'code' => 521,
  834. 'type' => 7,
  835. 'table' => "system_config",
  836. 'whereTable' => "system_config_tab",
  837. 'findSql' => "select id from @table where `menu_name` = 'wechat_qrcode'",
  838. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  839. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_qrcode'"
  840. ],
  841. [
  842. 'code' => 521,
  843. 'type' => 7,
  844. 'table' => "system_config",
  845. 'whereTable' => "system_config_tab",
  846. 'findSql' => "select id from @table where `menu_name` = 'routine_appId'",
  847. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  848. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'routine_appId'"
  849. ],
  850. [
  851. 'code' => 521,
  852. 'type' => 7,
  853. 'table' => "system_config",
  854. 'whereTable' => "system_config_tab",
  855. 'findSql' => "select id from @table where `menu_name` = 'routine_appsecret'",
  856. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  857. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'routine_appsecret'"
  858. ],
  859. [
  860. 'code' => 521,
  861. 'type' => 7,
  862. 'table' => "system_config",
  863. 'whereTable' => "system_config_tab",
  864. 'findSql' => "select id from @table where `menu_name` = 'api'",
  865. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_encoding'",
  866. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'api'"
  867. ],
  868. [
  869. 'code' => 521,
  870. 'type' => 7,
  871. 'table' => "system_config",
  872. 'whereTable' => "system_config_tab",
  873. 'findSql' => "select id from @table where `menu_name` = 'routine_name'",
  874. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  875. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'routine_name'"
  876. ],
  877. [
  878. 'code' => 521,
  879. 'type' => 7,
  880. 'table' => "system_config",
  881. 'whereTable' => "system_config_tab",
  882. 'findSql' => "select id from @table where `menu_name` = 'routine_contact_type'",
  883. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  884. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'routine_contact_type'"
  885. ],
  886. [
  887. 'code' => 521,
  888. 'type' => 7,
  889. 'table' => "system_config",
  890. 'whereTable' => "system_config_tab",
  891. 'findSql' => "select id from @table where `menu_name` = 'weixin_ckeck_file'",
  892. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  893. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'weixin_ckeck_file'"
  894. ],
  895. [
  896. 'code' => 521,
  897. 'type' => 7,
  898. 'table' => "system_config",
  899. 'whereTable' => "system_config_tab",
  900. 'findSql' => "select id from @table where `menu_name` = 'create_wechat_user'",
  901. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  902. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'create_wechat_user'"
  903. ],
  904. [
  905. 'code' => 521,
  906. 'type' => 7,
  907. 'table' => "system_config",
  908. 'whereTable' => "system_config_tab",
  909. 'findSql' => "select id from @table where `menu_name` = 'get_avatar'",
  910. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  911. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'get_avatar'"
  912. ],
  913. [
  914. 'code' => 521,
  915. 'type' => 7,
  916. 'table' => "system_config",
  917. 'whereTable' => "system_config_tab",
  918. 'findSql' => "select id from @table where `menu_name` = 'share_qrcode'",
  919. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  920. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'share_qrcode'"
  921. ],
  922. [
  923. 'code' => 521,
  924. 'type' => 7,
  925. 'table' => "system_config",
  926. 'whereTable' => "system_config_tab",
  927. 'findSql' => "select id from @table where `menu_name` = 'order_shipping_open'",
  928. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  929. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'order_shipping_open'"
  930. ],
  931. [
  932. 'code' => 521,
  933. 'type' => 7,
  934. 'table' => "system_config",
  935. 'whereTable' => "system_config_tab",
  936. 'findSql' => "select id from @table where `menu_name` = 'routine_auth_type'",
  937. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_config'",
  938. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'routine_auth_type'"
  939. ],
  940. [
  941. 'code' => 521,
  942. 'type' => 7,
  943. 'table' => "system_config",
  944. 'whereTable' => "system_config_tab",
  945. 'findSql' => "select id from @table where `menu_name` = 'wechat_template_to_miniprogram'",
  946. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='wechat_config'",
  947. 'sql' => "UPDATE `@table` SET `config_tab_id` = @tabId WHERE `menu_name` = 'wechat_template_to_miniprogram'"
  948. ],
  949. [
  950. 'code' => 521,
  951. 'type' => 6,
  952. 'table' => "system_config",
  953. 'whereTable' => "system_config_tab",
  954. 'findSql' => "select id from @table where `menu_name` = 'refund_time_available'",
  955. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='refund_config'",
  956. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'refund_time_available', 'text', 'input', @tabId, '', 1, '', 100, 0, '0', '售后期限', '订单收货之后,在多少天内可以进行退款,超出天数前端不显示退款按钮,设置0则永远显示', 0, 1)"
  957. ],
  958. [
  959. 'code' => 521,
  960. 'type' => 6,
  961. 'table' => "system_config",
  962. 'whereTable' => "system_config_tab",
  963. 'findSql' => "select id from @table where `menu_name` = 'routine_api'",
  964. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_encoding'",
  965. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'routine_api', 'text', 'input', @tabId, '', 1, '', 100, 0, '\"\\/api\\/wechat\\/miniServe\"', '接口地址', '配置小程序消息推送使用的接口地址,直接复制输入框内容(此项系统生成,无法修改)', 0, 1)"
  966. ],
  967. [
  968. 'code' => 521,
  969. 'type' => 6,
  970. 'table' => "system_config",
  971. 'whereTable' => "system_config_tab",
  972. 'findSql' => "select id from @table where `menu_name` = 'routine_token'",
  973. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_encoding'",
  974. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'routine_token', 'text', 'input', @tabId, '', 1, '', 100, 0, '\"\"', '小程序验证TOKEN', '小程序验证TOKEN', 0, 1)"
  975. ],
  976. [
  977. 'code' => 521,
  978. 'type' => 6,
  979. 'table' => "system_config",
  980. 'whereTable' => "system_config_tab",
  981. 'findSql' => "select id from @table where `menu_name` = 'routine_encode'",
  982. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_encoding'",
  983. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'routine_encode', 'radio', 'input', @tabId, '0=>明文模式\n1=>兼容模式\n2=>安全模式', 1, '', 0, 0, '0', '消息加解密方式', '小程序消息推送中的消息加密方式,暂时仅支持明文模式', 0, 1)"
  984. ],
  985. [
  986. 'code' => 521,
  987. 'type' => 6,
  988. 'table' => "system_config",
  989. 'whereTable' => "system_config_tab",
  990. 'findSql' => "select id from @table where `menu_name` = 'routine_encodingaeskey'",
  991. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='routine_encoding'",
  992. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'routine_encodingaeskey', 'text', 'input', @tabId, '', 1, '', 0, 0, '\"\"', 'EncodingAESKey', '消息加密密钥由43位字符组成,字符范围为A-Z,a-z,0-9', 0, 1)"
  993. ],
  994. [
  995. 'code' => 521,
  996. 'type' => -1,
  997. 'table' => "system_menus",
  998. 'sql' => "DELETE FROM `@table` WHERE `id` = 657"
  999. ],
  1000. [
  1001. 'code' => 521,
  1002. 'type' => -1,
  1003. 'table' => "system_menus",
  1004. 'sql' => "INSERT INTO `@table` VALUES (657, 656, '', '首页装修', 'admin', '', '', '', '', '[]', 100, 1, 1, 1, '/setting/pages/devise/0', '12/656', 1, '', 0, 'admin-setting-pages-devise', 0, '页面设计')"
  1005. ],
  1006. [
  1007. 'code' => 521,
  1008. 'type' => -1,
  1009. 'table' => "system_menus",
  1010. 'sql' => "INSERT INTO `@table` VALUES (NULL, 656, '', '商品分类', 'admin', '', '', '', '', '[]', 95, 1, 1, 1, '/setting/pages/cate_page/1', '656', 1, '', 0, '', 0, '')"
  1011. ],
  1012. [
  1013. 'code' => 521,
  1014. 'type' => -1,
  1015. 'table' => "system_menus",
  1016. 'sql' => "INSERT INTO `@table` VALUES (NULL, 656, '', '个人中心', 'admin', '', '', '', '', '[]', 90, 1, 1, 1, '/setting/pages/user_page/2', '656', 1, '', 0, '', 0, '')"
  1017. ],
  1018. ];
  1019. return $data;
  1020. }
  1021. /**
  1022. * 升级列表
  1023. * @return mixed
  1024. */
  1025. public function upgradeList()
  1026. {
  1027. return app('json')->success($this->services->getUpgradeList());
  1028. }
  1029. /**
  1030. * 可升级列表
  1031. * @return mixed
  1032. */
  1033. public function upgradeableList()
  1034. {
  1035. return app('json')->success($this->services->getUpgradeableList());
  1036. }
  1037. /**
  1038. * 可升级列表
  1039. * @return mixed
  1040. */
  1041. public function agreement()
  1042. {
  1043. return app('json')->success($this->services->getAgreement());
  1044. }
  1045. /**
  1046. * 下载升级包
  1047. * @param $packageKey
  1048. * @return mixed
  1049. */
  1050. public function download($packageKey)
  1051. {
  1052. if (empty($packageKey)) {
  1053. return app('json')->fail(100100);
  1054. }
  1055. $this->services->packageDownload($packageKey);
  1056. return app('json')->success();
  1057. }
  1058. /**
  1059. * 升级进度
  1060. * @return mixed
  1061. */
  1062. public function progress()
  1063. {
  1064. $result = $this->services->getProgress();
  1065. return app('json')->success($result);
  1066. }
  1067. /**
  1068. * 获取升级状态
  1069. * @return mixed
  1070. */
  1071. public function upgradeStatus()
  1072. {
  1073. $data = $this->services->getUpgradeStatus();
  1074. return app('json')->success($data);
  1075. }
  1076. /**
  1077. * 升级记录
  1078. * @throws \think\db\exception\ModelNotFoundException
  1079. * @throws \think\db\exception\DataNotFoundException
  1080. * @throws \think\db\exception\DbException
  1081. */
  1082. public function upgradeLogList()
  1083. {
  1084. $data = $this->services->getUpgradeLogList();
  1085. return app('json')->success($data);
  1086. }
  1087. /**
  1088. * 导出备份
  1089. * @throws \think\db\exception\ModelNotFoundException
  1090. * @throws \think\db\exception\DataNotFoundException
  1091. * @throws \think\db\exception\DbException
  1092. */
  1093. public function export($id, $type)
  1094. {
  1095. if (!$id || !$type) {
  1096. return app('json')->fail(100026);
  1097. }
  1098. return app('json')->success($this->services->export((int)$id, $type));
  1099. }
  1100. }