Specvalue.php 2.3 KB

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