Config.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | EasyAdmin
  4. // +----------------------------------------------------------------------
  5. // | PHP交流群: 763822524
  6. // +----------------------------------------------------------------------
  7. // | 开源协议 https://mit-license.org
  8. // +----------------------------------------------------------------------
  9. // | github开源项目:https://github.com/zhongshaofa/EasyAdmin
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\system;
  12. use app\common\model\SystemConfig;
  13. use app\admin\service\TriggerService;
  14. use app\common\controller\AdminController;
  15. use EasyAdmin\annotation\ControllerAnnotation;
  16. use EasyAdmin\annotation\NodeAnotation;
  17. use services\CacheServices;
  18. use think\App;
  19. use think\facade\Db;
  20. /**
  21. * Class Config
  22. * @package app\admin\controller\system
  23. * @ControllerAnnotation(title="系统配置管理")
  24. */
  25. class Config extends AdminController
  26. {
  27. public function __construct(App $app)
  28. {
  29. parent::__construct($app);
  30. $this->model = new SystemConfig();
  31. }
  32. /**
  33. * @NodeAnotation(title="列表")
  34. */
  35. public function index()
  36. {
  37. $this->assign('total_renwu', 11);
  38. $this->assign('total_shouxu', 22);
  39. return $this->fetch();
  40. }
  41. /**
  42. * @NodeAnotation(title="保存")
  43. */
  44. public function save()
  45. {
  46. $this->checkPostRequest();
  47. $post = $this->request->post();
  48. sr_log(json_encode($post));
  49. // if (isset($post['xz_min_money'])){
  50. // if ($post['xz_min_money'] > $post['xz_max_money']){
  51. // return $this->error('最高级不能小于最低价');
  52. // }
  53. // if (!($post['xz_cur_money'] < $post['xz_max_money'] && $post['xz_cur_money'] > $post['xz_min_money'])){
  54. // return $this->error('当前价必须在区间之间');
  55. // }
  56. // }
  57. try {
  58. // if (isset($post['xz_cur_money'])){
  59. // // 清空所有商品详情缓存
  60. // $list = Db::name('shop_goods')->where('goods_type', 5)->field('goods_id,goods_sn')->select()->toArray();
  61. // foreach ($list as $key=>$val){
  62. // CacheServices::clearToken(md5('goodsDetail_' . $val['goods_sn']));
  63. // }
  64. //
  65. // }
  66. foreach ($post as $key => $val) {
  67. $this->model
  68. ->where('name', $key)
  69. ->update([
  70. 'value' => $val,
  71. ]);
  72. }
  73. TriggerService::updateMenu();
  74. TriggerService::updateSysconfig();
  75. } catch (\Exception $e) {
  76. $this->error('保存失败');
  77. }
  78. $this->success('保存成功');
  79. }
  80. }