UpgradeController.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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.3.0';
  717. $data['new_code'] = 530;
  718. $data['update_sql'] = [
  719. [
  720. 'code' => 530,
  721. 'type' => -1,
  722. 'table' => "system_config_tab",
  723. 'sql' => "truncate table `@table`"
  724. ],
  725. [
  726. 'code' => 530,
  727. 'type' => 3,
  728. 'table' => "system_config_tab",
  729. 'field' => "menus_id",
  730. 'findSql' => "show columns from `@table` like 'menus_id'",
  731. 'sql' => "ALTER TABLE `@table` ADD `menus_id` int(11) NOT NULL DEFAULT '0' COMMENT '菜单ID'"
  732. ],
  733. [
  734. 'code' => 530,
  735. 'type' => -1,
  736. 'table' => "system_config_tab",
  737. 'sql' => <<<SQL
  738. INSERT INTO `@table` (`id`, `pid`, `title`, `eng_title`, `status`, `info`, `icon`, `type`, `sort`, `menus_id`) VALUES
  739. (1, 129, '基础配置', 'basics', 1, 0, 'ios-settings', 0, 0, 23),
  740. (2, 78, '公众号配置(H5)', 'wechat', 1, 0, 'ios-chatbubbles', 3, 0, 1006),
  741. (4, 23, '微信支付配置', 'pay', 1, 0, 'ios-chatbubbles', 3, 0, 1063),
  742. (7, 78, '小程序配置', 'routine', 1, 0, 'logo-android', 3, 0, 1007),
  743. (9, 0, '分销配置', 'fenxiao', 1, 0, 'md-contacts', 3, 0, 28),
  744. (11, 100, '用户积分配置', 'point', 0, 0, 'logo-euro', 3, 0, 3423),
  745. (18, 65, '一号通', 'system_sms', 1, 0, 'ios-chatboxes', 3, 99, 3418),
  746. (21, 65, '小票打印配置', 'printing_deploy', 1, 0, 'logo-buffer', 3, 0, 1057),
  747. (23, 65, '商城支付配置', 'pay_config', 1, 0, 'logo-usd', 3, 70, 1063),
  748. (28, 100, '用户充值配置', 'recharge_site', 0, 0, '', 3, 2, 3423),
  749. (31, 79, '基础配置', 'base_config', 0, 0, '', 0, 0, 1012),
  750. (41, 65, '采集商品配置', 'copy_product', 1, 0, '', 3, 0, 1058),
  751. (45, 100, '用户等级配置', 'store_member', 1, 0, '', 3, 3, 3423),
  752. (50, 113, '发票功能配置', 'store_invoice', 1, 0, '', 3, 0, 3424),
  753. (63, 23, '支付宝支付配置', 'ali_pay', 1, 0, '', 3, 0, 1063),
  754. (64, 65, '物流查询配置', 'logistics_select', 1, 0, '', 3, 0, 1059),
  755. (65, 0, '接口设置', 'system_serve', 1, 0, 'md-briefcase', 3, 0, 1056),
  756. (66, 65, '电子面单配置', 'electronic_sheet', 1, 0, '', 3, 0, 1060),
  757. (67, 100, '付费会员配置', 'member_card', 0, 0, '', 3, 2, 3423),
  758. (69, 0, '客服配置', 'kefu_config', 1, 0, '', 3, 0, 3421),
  759. (70, 129, '分享配置', 'share_index_config', 1, 0, '', 0, 0, 23),
  760. (71, 113, '售后退款配置', 'refund_config', 1, 0, '', 3, 0, 3424),
  761. (72, 9, '分销模式', 'brokerage_type', 1, 0, '', 3, 0, 28),
  762. (73, 9, '返佣设置', 'brokerage_set', 1, 0, '', 3, 0, 28),
  763. (74, 9, '提现设置', 'extract_set', 1, 0, '', 3, 0, 28),
  764. (75, 78, 'PC站点配置', 'system_pc', 1, 0, '', 3, 0, 1010),
  765. (77, 78, 'APP配置', 'app', 1, 0, '', 3, 0, 1011),
  766. (78, 0, '应用配置', 'sys_app', 1, 0, '', 3, 0, 135),
  767. (79, 65, '系统存储配置', 'storage_config', 1, 0, '', 3, 0, 1012),
  768. (80, 79, '七牛云配置', 'qiniu_config', 0, 0, '', 0, 0, 1012),
  769. (81, 79, '阿里云配置', 'oss_config', 0, 0, '', 0, 0, 1012),
  770. (82, 79, '腾讯云配置', 'cos_config', 0, 0, '', 0, 0, 1012),
  771. (86, 21, '基础配置', 'print_basic', 1, 0, '', 3, 0, 1057),
  772. (87, 21, '易联云配置', 'yly_config', 1, 0, '', 3, 0, 1057),
  773. (89, 41, '基础配置', 'copy_basic', 1, 0, '', 3, 0, 1058),
  774. (90, 41, '99api配置', '99api_config', 1, 0, '', 3, 0, 1058),
  775. (91, 64, '基础配置', 'logistics_basic', 1, 0, '', 3, 0, 1059),
  776. (92, 64, '阿里云配置', 'logistics_aliyun', 1, 0, '', 3, 0, 1059),
  777. (93, 66, '基础配置', 'electronic_basic', 1, 0, '', 3, 0, 1060),
  778. (94, 66, '一号通配置', 'system_electronic_config', 1, 0, '', 3, 0, 1060),
  779. (96, 65, '短信接口配置', 'sms_config', 1, 0, '', 3, 0, 1062),
  780. (97, 96, '基础配置', 'sms_config_basic', 1, 0, '', 3, 0, 1062),
  781. (98, 96, '阿里云配置', 'sms_aliyun', 1, 0, '', 3, 0, 1062),
  782. (99, 96, '腾讯云配置', 'tencent_sms', 1, 0, '', 3, 0, 1062),
  783. (100, 0, '用户配置', 'system_user_config', 1, 0, 'md-contact', 3, 0, 3423),
  784. (102, 65, '对外接口配置', 'out_config', 1, 0, '', 3, 0, 0),
  785. (103, 102, '基础配置', 'out_basic', 1, 0, '', 3, 0, 0),
  786. (104, 102, '推送配置', 'out_push', 1, 0, '', 3, 0, 0),
  787. (105, 100, '新用户设置', 'new_user_setting', 1, 0, '', 3, 0, 3423),
  788. (106, 129, '翻译配置', 'online_translation', 0, 0, '', 3, 0, 23),
  789. (107, 21, '飞鹅云配置', 'fey_config', 1, 0, '', 3, 0, 1057),
  790. (108, 23, '通联支付', 'allinpay', 1, 0, '', 3, 0, 1063),
  791. (109, 23, '基础配置', 'pay_basic', 1, 0, '', 3, 100, 1063),
  792. (110, 79, '京东云配置', 'jd_oss_config', 0, 0, '', 0, 0, 1012),
  793. (111, 79, '华为云配置', 'obs_config', 0, 0, '', 0, 0, 1012),
  794. (112, 79, '天翼云配置', 'ty_oss_config', 0, 0, '', 0, 0, 1012),
  795. (113, 0, '订单配置', 'order_config', 1, 0, '', 3, 0, 3424),
  796. (114, 113, '包邮设置', 'free_shipping_config', 1, 0, '', 3, 10, 3424),
  797. (115, 113, '订单取消配置', 'order_cancel_config', 1, 0, '', 3, 0, 3424),
  798. (116, 113, '自动收货配置', 'auto_take_config', 1, 0, '', 3, 0, 3424),
  799. (117, 113, '自动评价配置', 'auto_reviews_config', 1, 0, '', 3, 0, 3424),
  800. (119, 113, '到店自提配置', 'self_mention_config', 1, 0, '', 3, 0, 3424),
  801. (120, 113, '警戒库存配置', 'store_stock_config', 1, 0, '', 3, 0, 3424),
  802. (122, 129, 'LOGO配置', 'site_logo_config', 1, 0, '', 0, 0, 23),
  803. (123, 129, '统计配置', 'statistics_config', 1, 0, '', 0, 0, 23),
  804. (124, 129, '地图配置', 'map_config', 1, 0, '', 0, 0, 23),
  805. (125, 129, '备案配置', 'beian_config', 1, 0, '', 0, 0, 23),
  806. (126, 100, '用户签到配置', 'user_sign_config', 0, 0, '', 3, 0, 3423),
  807. (129, 0, '系统配置', 'system_config', 1, 0, '', 0, 0, 23),
  808. (130, 2, '公众号配置', 'wechat_config', 1, 0, '', 3, 0, 1006),
  809. (131, 2, '服务器域名配置', 'wechat_encoding', 1, 0, '', 3, 0, 1006),
  810. (132, 7, '小程序配置', 'routine_config', 1, 0, '', 3, 0, 1007),
  811. (133, 7, '消息推送配置', 'routine_encoding', 1, 0, '', 3, 0, 1007),
  812. (134, 129, '模块配置', 'model_config', 1, 0, '', 0, 0, 23);
  813. SQL
  814. ],
  815. [
  816. 'code' => 530,
  817. 'type' => -1,
  818. 'table' => "system_config",
  819. 'sql' => "UPDATE `@table` SET `parameter` = '0=>银行卡\n1=>微信\n2=>支付宝\n3=>余额' WHERE `menu_name` = 'store_free_postage'"
  820. ],
  821. [
  822. 'code' => 530,
  823. 'type' => -1,
  824. 'table' => "system_config",
  825. 'sql' => "DELETE FROM `@table` WHERE `id` = 459"
  826. ],
  827. [
  828. 'code' => 530,
  829. 'type' => 6,
  830. 'table' => "system_config",
  831. 'whereTable' => "system_config_tab",
  832. 'findSql' => "select id from @table where `menu_name` = 'model_checkbox'",
  833. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='model_config'",
  834. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'model_checkbox', 'checkbox', 'input', @tabId, 'seckill=>秒杀\nbargain=>砍价\ncombination=>拼团', 1, '', 0, 0, '[\"seckill\",\"bargain\",\"combination\"]', '模块配置', '模块配置,选中展示对应的模块,取消选中则前后端不展示模块相关内容', 0, 1)"
  835. ],
  836. [
  837. 'code' => 530,
  838. 'type' => 6,
  839. 'table' => "system_config",
  840. 'whereTable' => "system_config_tab",
  841. 'findSql' => "select id from @table where `menu_name` = 'sp_appid'",
  842. 'whereSql' => "SELECT id as tabId FROM `@whereTable` WHERE `eng_title`='pay'",
  843. 'sql' => "INSERT INTO `@table` VALUES (NULL, 'sp_appid', 'text', 'input', @tabId, '', 1, '', 100, 0, '\"\"', '主商户APPID', '开启服务商支付,需要配置主商户申请的时候开通的公众号服务号的APPID', 0, 1)"
  844. ],
  845. [
  846. 'code' => 530,
  847. 'type' => 3,
  848. 'table' => "system_notification",
  849. 'field' => "wechat_data",
  850. 'findSql' => "show columns from `@table` like 'wechat_data'",
  851. 'sql' => "ALTER TABLE `@table` ADD `wechat_data` varchar(255) NOT NULL DEFAULT '' COMMENT '模版消息参数' AFTER `wechat_tempid`"
  852. ],
  853. [
  854. 'code' => 530,
  855. 'type' => 3,
  856. 'table' => "system_notification",
  857. 'field' => "wechat_link",
  858. 'findSql' => "show columns from `@table` like 'wechat_link'",
  859. 'sql' => "ALTER TABLE `@table` ADD `wechat_link` varchar(255) NOT NULL DEFAULT '' COMMENT '模版消息链接' AFTER `wechat_data`"
  860. ],
  861. [
  862. 'code' => 530,
  863. 'type' => 3,
  864. 'table' => "system_notification",
  865. 'field' => "wechat_to_routine",
  866. 'findSql' => "show columns from `@table` like 'wechat_to_routine'",
  867. 'sql' => "ALTER TABLE `@table` ADD `wechat_to_routine` int(1) NOT NULL DEFAULT '0' COMMENT '模版消息跳转小程序' AFTER `wechat_link`"
  868. ],
  869. [
  870. 'code' => 530,
  871. 'type' => 3,
  872. 'table' => "system_notification",
  873. 'field' => "routine_data",
  874. 'findSql' => "show columns from `@table` like 'routine_data'",
  875. 'sql' => "ALTER TABLE `@table` ADD `routine_data` varchar(255) NOT NULL DEFAULT '' COMMENT '订阅消息参数' AFTER `routine_tempid`"
  876. ],
  877. [
  878. 'code' => 530,
  879. 'type' => 3,
  880. 'table' => "system_notification",
  881. 'field' => "routine_link",
  882. 'findSql' => "show columns from `@table` like 'routine_link'",
  883. 'sql' => "ALTER TABLE `@table` ADD `routine_link` varchar(255) NOT NULL DEFAULT '' COMMENT '订阅消息链接' AFTER `routine_data`"
  884. ],
  885. [
  886. 'code' => 530,
  887. 'type' => 3,
  888. 'table' => "system_notification",
  889. 'field' => "custom_trigger",
  890. 'findSql' => "show columns from `@table` like 'custom_trigger'",
  891. 'sql' => "ALTER TABLE `@table` ADD `custom_trigger` varchar(255) NOT NULL DEFAULT '' COMMENT '自定义消息触发位置' AFTER `add_time`"
  892. ],
  893. [
  894. 'code' => 530,
  895. 'type' => 3,
  896. 'table' => "system_notification",
  897. 'field' => "custom_variable",
  898. 'findSql' => "show columns from `@table` like 'custom_variable'",
  899. 'sql' => "ALTER TABLE `@table` ADD `custom_variable` varchar(1000) NOT NULL DEFAULT '' COMMENT '自定义消息变量' AFTER `custom_trigger`"
  900. ],
  901. [
  902. 'code' => 530,
  903. 'type' => -1,
  904. 'table' => "system_menus",
  905. 'sql' => "INSERT INTO `@table` VALUES (NULL, 993, '', '小程序链接', 'admin', '', '', '', '', '[]', 0, 1, 1, 1, '/app/routine/link', '135/993', 1, '', 0, '', 0, '')"
  906. ],
  907. [
  908. 'code' => 530,
  909. 'type' => -1,
  910. 'table' => "system_menus",
  911. 'sql' => "INSERT INTO `@table` VALUES (NULL, 56, '', '模块配置', 'admin', '', '', '', '', '[]', 0, 1, 1, 1, '/marketing/integral/system_config/2/134', '25/56', 1, '', 0, 'system-model-system_config', 0, '')"
  912. ],
  913. [
  914. 'code' => 530,
  915. 'type' => 1,
  916. 'table' => "routine_scheme",
  917. 'findSql' => "select * from information_schema.tables where table_name ='@table'",
  918. 'sql' => "CREATE TABLE IF NOT EXISTS `@table` (
  919. `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
  920. `title` varchar(255) NOT NULL DEFAULT '' COMMENT '名称',
  921. `path` varchar(255) NOT NULL DEFAULT '' COMMENT '小程序页面地址',
  922. `url` varchar(255) NOT NULL DEFAULT '' COMMENT '生成链接地址',
  923. `add_time` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
  924. `expire_type` int(11) NOT NULL DEFAULT '-1' COMMENT '到期类型',
  925. `expire_interval` int(11) NOT NULL DEFAULT '0' COMMENT '到期天数',
  926. `expire_time` int(11) NOT NULL DEFAULT '0' COMMENT '到期时间',
  927. `is_del` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除',
  928. PRIMARY KEY (`id`)
  929. ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='小程序外链'"
  930. ],
  931. ];
  932. return $data;
  933. }
  934. /**
  935. * 升级列表
  936. * @return mixed
  937. */
  938. public function upgradeList()
  939. {
  940. return app('json')->success([]);
  941. return app('json')->success($this->services->getUpgradeList());
  942. }
  943. /**
  944. * 可升级列表
  945. * @return mixed
  946. */
  947. public function upgradeableList()
  948. {
  949. return app('json')->success([]);
  950. return app('json')->success($this->services->getUpgradeableList());
  951. }
  952. /**
  953. * 可升级列表
  954. * @return mixed
  955. */
  956. public function agreement()
  957. {
  958. return app('json')->success($this->services->getAgreement());
  959. }
  960. /**
  961. * 下载升级包
  962. * @param $packageKey
  963. * @return mixed
  964. */
  965. public function download($packageKey)
  966. {
  967. if (empty($packageKey)) {
  968. return app('json')->fail(100100);
  969. }
  970. $this->services->packageDownload($packageKey);
  971. return app('json')->success();
  972. }
  973. /**
  974. * 升级进度
  975. * @return mixed
  976. */
  977. public function progress()
  978. {
  979. $result = $this->services->getProgress();
  980. return app('json')->success($result);
  981. }
  982. /**
  983. * 获取升级状态
  984. * @return mixed
  985. */
  986. public function upgradeStatus()
  987. {
  988. return app('json')->success([]);
  989. $data = $this->services->getUpgradeStatus();
  990. return app('json')->success($data);
  991. }
  992. /**
  993. * 升级记录
  994. * @throws \think\db\exception\ModelNotFoundException
  995. * @throws \think\db\exception\DataNotFoundException
  996. * @throws \think\db\exception\DbException
  997. */
  998. public function upgradeLogList()
  999. {
  1000. return app('json')->success([]);
  1001. $data = $this->services->getUpgradeLogList();
  1002. return app('json')->success($data);
  1003. }
  1004. /**
  1005. * 导出备份
  1006. * @throws \think\db\exception\ModelNotFoundException
  1007. * @throws \think\db\exception\DataNotFoundException
  1008. * @throws \think\db\exception\DbException
  1009. */
  1010. public function export($id, $type)
  1011. {
  1012. if (!$id || !$type) {
  1013. return app('json')->fail(100026);
  1014. }
  1015. return app('json')->success($this->services->export((int)$id, $type));
  1016. }
  1017. }