Level.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\user\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 会员等级管理
  7. * Class Level
  8. * @package app\store\controller
  9. */
  10. class Level extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'UserLevel';
  17. /**
  18. * 等级管理
  19. * @auth true
  20. * @menu true
  21. * @throws \think\Exception
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. * @throws \think\exception\PDOException
  26. */
  27. public function index()
  28. {
  29. $this->title = '等级管理';
  30. $query = $this->_query($this->table)->order('id asc')->page();
  31. }
  32. /**
  33. * 数据列表处理
  34. * @auth true
  35. * @menu true
  36. * @param array $data
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @throws \think\exception\DbException
  40. */
  41. protected function _index_page_filter(&$data)
  42. {
  43. }
  44. /**
  45. * 添加等级
  46. * @auth true
  47. * @menu true
  48. * @throws \think\Exception
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. * @throws \think\exception\PDOException
  53. */
  54. public function add()
  55. {
  56. $this->title = '添加等级';
  57. $this->_form($this->table, 'form');
  58. }
  59. /**
  60. * 编辑等级
  61. * @auth true
  62. * @menu true
  63. * @throws \think\Exception
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. * @throws \think\exception\PDOException
  68. */
  69. public function edit()
  70. {
  71. $this->title = '编辑等级';
  72. $this->_form($this->table, 'form');
  73. }
  74. /**
  75. * 删除
  76. * @auth true
  77. * @menu true
  78. * @throws \think\Exception
  79. * @throws \think\exception\PDOException
  80. */
  81. public function del()
  82. {
  83. $this->_save($this->table, ['is_deleted' => 1]);
  84. }
  85. /**
  86. * 表单数据处理
  87. * @auth true
  88. * @menu true
  89. * @param array $data
  90. */
  91. protected function _form_filter(&$data)
  92. {
  93. if($this->request->isGet()) {
  94. $this->price = !empty($data['price']) ? json_decode($data['price'],true):[];
  95. }
  96. if($this->request->isPost())
  97. {
  98. // 会员价格设置
  99. $title_arr= input('post.title');
  100. $time_arr= input('post.time');
  101. $price_arr= input('post.price');
  102. $price_param = [];
  103. foreach ($title_arr as $k=>$t){
  104. $price_param[] = ['title'=>$t,'time'=>intval($time_arr[$k]),'price'=>bcadd($price_arr[$k],0,2),'level_key'=>$k];
  105. }
  106. $data['price'] = json_encode($price_param);
  107. }
  108. }
  109. }