Procuremenmenu.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 协助采购子菜单安装(仅超级管理员访问一次)
  7. */
  8. class Procuremenmenu extends Backend
  9. {
  10. protected $noNeedRight = ['install'];
  11. public function install()
  12. {
  13. if (!$this->auth->isSuperAdmin()) {
  14. $this->error('仅超级管理员可执行');
  15. }
  16. $t = time();
  17. $listRule = Db::name('auth_rule')->where('name', 'procuremen/pick')->find();
  18. if (!$listRule) {
  19. $listRule = Db::name('auth_rule')->where('name', 'procuremen/index')->find();
  20. }
  21. if (!$listRule) {
  22. $this->error('未找到协助下发菜单,请先在权限规则中配置 procuremen/pick 或 procuremen/index');
  23. }
  24. $pid = (int)($listRule['pid'] ?? 0);
  25. if ($pid <= 0) {
  26. $existsRoot = Db::name('auth_rule')->where('name', 'procuremenroot')->find();
  27. if ($existsRoot) {
  28. $pid = (int)$existsRoot['id'];
  29. } else {
  30. $pid = Db::name('auth_rule')->insertGetId([
  31. 'type' => 'file',
  32. 'pid' => 0,
  33. 'name' => 'procuremenroot',
  34. 'title' => '协助采购',
  35. 'icon' => 'fa fa-share-alt',
  36. 'url' => '',
  37. 'ismenu' => 1,
  38. 'menutype' => 'addtabs',
  39. 'weigh' => 88,
  40. 'status' => 'normal',
  41. 'createtime' => $t,
  42. 'updatetime' => $t,
  43. ]);
  44. }
  45. Db::name('auth_rule')->where('id', (int)$listRule['id'])->update([
  46. 'pid' => $pid,
  47. 'title' => '协助下发',
  48. 'name' => 'procuremen/pick',
  49. 'updatetime' => $t,
  50. ]);
  51. }
  52. $added = 0;
  53. $workflowMenus = [
  54. ['name' => 'procuremen/pick', 'title' => '协助下发', 'icon' => 'fa fa-paper-plane', 'weigh' => 90],
  55. ['name' => 'procuremen/audit', 'title' => '确认供应商', 'icon' => 'fa fa-check-square-o', 'weigh' => 89],
  56. ['name' => 'procuremen/confirm', 'title' => '采购确认', 'icon' => 'fa fa-shopping-cart', 'weigh' => 88],
  57. ];
  58. foreach ($workflowMenus as $wm) {
  59. if (Db::name('auth_rule')->where('name', $wm['name'])->find()) {
  60. Db::name('auth_rule')->where('name', $wm['name'])->update([
  61. 'title' => $wm['title'],
  62. 'icon' => $wm['icon'],
  63. 'weigh' => $wm['weigh'],
  64. 'updatetime' => $t,
  65. ]);
  66. continue;
  67. }
  68. Db::name('auth_rule')->insertGetId([
  69. 'type' => 'file',
  70. 'pid' => $pid,
  71. 'name' => $wm['name'],
  72. 'title' => $wm['title'],
  73. 'icon' => $wm['icon'],
  74. 'url' => '',
  75. 'ismenu' => 1,
  76. 'menutype' => 'addtabs',
  77. 'weigh' => $wm['weigh'],
  78. 'status' => 'normal',
  79. 'createtime' => $t,
  80. 'updatetime' => $t,
  81. ]);
  82. $added++;
  83. }
  84. $menus = [
  85. ['name' => 'procuremensms/index', 'title' => '短信模版维护', 'icon' => 'fa fa-commenting-o', 'weigh' => 87],
  86. ['name' => 'procuremenarchive/index', 'title' => '历史存证档案查询', 'icon' => 'fa fa-archive', 'weigh' => 86],
  87. ['name' => 'procuremenexport/index', 'title' => '月度报表导出列表', 'icon' => 'fa fa-file-excel-o', 'weigh' => 85],
  88. ['name' => 'supplierscorerule/index', 'title' => '供应商评分规则', 'icon' => 'fa fa-sliders', 'weigh' => 84],
  89. ['name' => 'supplierservicescore/index', 'title' => '供应商服务评分', 'icon' => 'fa fa-trophy', 'weigh' => 83],
  90. ];
  91. foreach ($menus as $m) {
  92. if (Db::name('auth_rule')->where('name', $m['name'])->find()) {
  93. continue;
  94. }
  95. $menuId = Db::name('auth_rule')->insertGetId([
  96. 'type' => 'file',
  97. 'pid' => $pid,
  98. 'name' => $m['name'],
  99. 'title' => $m['title'],
  100. 'icon' => $m['icon'],
  101. 'url' => '',
  102. 'ismenu' => 1,
  103. 'menutype' => 'addtabs',
  104. 'weigh' => $m['weigh'],
  105. 'status' => 'normal',
  106. 'createtime' => $t,
  107. 'updatetime' => $t,
  108. ]);
  109. $added++;
  110. if ($m['name'] === 'procuremensms/index') {
  111. Db::name('auth_rule')->insert([
  112. 'type' => 'file',
  113. 'pid' => $menuId,
  114. 'name' => 'procuremensms/edit',
  115. 'title' => '编辑',
  116. 'icon' => 'fa fa-circle-o',
  117. 'ismenu' => 0,
  118. 'status' => 'normal',
  119. 'createtime' => $t,
  120. 'updatetime' => $t,
  121. ]);
  122. $added++;
  123. }
  124. if ($m['name'] === 'procuremenexport/index') {
  125. $exportChildren = [
  126. ['name' => 'procuremen/export_month_outward', 'title' => '导出'],
  127. ['name' => 'procuremen/details', 'title' => '详情'],
  128. ];
  129. foreach ($exportChildren as $cr) {
  130. $exists = Db::name('auth_rule')->where('name', $cr['name'])->find();
  131. if ($exists) {
  132. Db::name('auth_rule')->where('name', $cr['name'])->update([
  133. 'pid' => $menuId,
  134. 'title' => $cr['title'],
  135. 'status' => 'normal',
  136. 'ismenu' => 0,
  137. 'updatetime' => $t,
  138. ]);
  139. continue;
  140. }
  141. Db::name('auth_rule')->insert([
  142. 'type' => 'file',
  143. 'pid' => $menuId,
  144. 'name' => $cr['name'],
  145. 'title' => $cr['title'],
  146. 'icon' => 'fa fa-circle-o',
  147. 'ismenu' => 0,
  148. 'status' => 'normal',
  149. 'createtime' => $t,
  150. 'updatetime' => $t,
  151. ]);
  152. $added++;
  153. }
  154. }
  155. if ($m['name'] === 'procuremenarchive/index') {
  156. $archiveChildren = [
  157. ['name' => 'procuremen/archiveabandon', 'title' => '重新下发'],
  158. ['name' => 'procuremen/details', 'title' => '详情'],
  159. ];
  160. foreach ($archiveChildren as $cr) {
  161. $exists = Db::name('auth_rule')->where('name', $cr['name'])->find();
  162. if ($exists) {
  163. Db::name('auth_rule')->where('name', $cr['name'])->update([
  164. 'pid' => $menuId,
  165. 'title' => $cr['title'],
  166. 'status' => 'normal',
  167. 'ismenu' => 0,
  168. 'updatetime' => $t,
  169. ]);
  170. continue;
  171. }
  172. Db::name('auth_rule')->insert([
  173. 'type' => 'file',
  174. 'pid' => $menuId,
  175. 'name' => $cr['name'],
  176. 'title' => $cr['title'],
  177. 'icon' => 'fa fa-circle-o',
  178. 'ismenu' => 0,
  179. 'status' => 'normal',
  180. 'createtime' => $t,
  181. 'updatetime' => $t,
  182. ]);
  183. $added++;
  184. }
  185. }
  186. if ($m['name'] === 'supplierscorerule/index') {
  187. foreach ([
  188. ['name' => 'supplierscorerule/add', 'title' => '添加'],
  189. ['name' => 'supplierscorerule/edit', 'title' => '编辑'],
  190. ['name' => 'supplierscorerule/del', 'title' => '删除'],
  191. ['name' => 'supplierscorerule/setdefault', 'title' => '设为默认'],
  192. ] as $cr) {
  193. if (Db::name('auth_rule')->where('name', $cr['name'])->find()) {
  194. continue;
  195. }
  196. Db::name('auth_rule')->insert([
  197. 'type' => 'file',
  198. 'pid' => $menuId,
  199. 'name' => $cr['name'],
  200. 'title' => $cr['title'],
  201. 'icon' => 'fa fa-circle-o',
  202. 'ismenu' => 0,
  203. 'status' => 'normal',
  204. 'createtime' => $t,
  205. 'updatetime' => $t,
  206. ]);
  207. $added++;
  208. }
  209. }
  210. if ($m['name'] === 'supplierservicescore/index') {
  211. foreach ([
  212. ['name' => 'supplierservicescore/export', 'title' => '导出供应商评审表'],
  213. ] as $cr) {
  214. if (Db::name('auth_rule')->where('name', $cr['name'])->find()) {
  215. continue;
  216. }
  217. Db::name('auth_rule')->insert([
  218. 'type' => 'file',
  219. 'pid' => $menuId,
  220. 'name' => $cr['name'],
  221. 'title' => $cr['title'],
  222. 'icon' => 'fa fa-circle-o',
  223. 'ismenu' => 0,
  224. 'status' => 'normal',
  225. 'createtime' => $t,
  226. 'updatetime' => $t,
  227. ]);
  228. $added++;
  229. }
  230. }
  231. }
  232. \think\Cache::rm('__menu__');
  233. $this->success('菜单安装完成,新增节点 ' . $added . ' 个。请刷新后台并到「权限管理」为角色勾选新菜单。');
  234. }
  235. }