Specvalue.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Specvalue extends BaseController
  7. {
  8. public $post="";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function list(){
  15. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  16. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  17. $where = [['is_del','=',0]];
  18. $count = Db::name('spec_value')->where($where)->count();
  19. $total = ceil($count / $size);
  20. $page = $page >= $total ? $total : $page;
  21. $list = Db::name('spec_value')->where($where)->page($page,$size)->order("addtime desc")->select();
  22. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  23. }
  24. public function create(){
  25. $spec_id = isset($this->post['spec_id']) && $this->post['spec_id'] !=="" ? intval($this->post['spec_id']):"";
  26. if($spec_id==""){
  27. return error_show(1002,"参数spec_id不能为空");
  28. }
  29. $spec_value = isset($this->post['spec_value']) && $this->post['spec_value'] !=="" ? trim($this->post['spec_value']):"";
  30. if($spec_value==""){
  31. return error_show(1002,"参数spec_value不能为空");
  32. }
  33. $data = [
  34. "spec_id"=>$spec_id,
  35. "spec_value"=>$spec_value,
  36. "is_del"=>0,
  37. "addtime"=>date("Y-m-d H:i:s"),
  38. "updatetime"=>date("Y-m-d H:i:s")
  39. ];
  40. $info = Db::name("spec_value")->insert($data);
  41. if($info){
  42. return error_show(0,"新建成功");
  43. }else{
  44. return error_show(1002,"新建失败");
  45. }
  46. }
  47. public function all(){
  48. $spec_id = isset($this->post['spec_id']) && $this->post['spec_id'] !=="" ? intval($this->post['spec_id']):"";
  49. if($spec_id == ""){
  50. return error_show(1002,"参数spec_id不能为空");
  51. }
  52. $info = Db::name('spec_value')->where(['spec_id'=>$spec_id,'is_del'=>0])->select();
  53. if($info==""){
  54. return error_show(1002,"未找到数据");
  55. }
  56. return app_show(0,"获取成功",$info);
  57. }
  58. }