Specvalue.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. {
  27. $spec_id = isset($this->post['spec_id']) && $this->post['spec_id'] !== "" ? intval($this->post['spec_id']) : "";
  28. if ($spec_id == "") {
  29. return error_show(1002, "参数spec_id不能为空");
  30. }
  31. $spec_value = isset($this->post['spec_value']) && $this->post['spec_value'] !== "" ? trim($this->post['spec_value']) : "";
  32. if ($spec_value == "") {
  33. return error_show(1002, "参数spec_value不能为空");
  34. }
  35. $id_is_empty = Db::name('spec_value')
  36. ->field('id')
  37. ->where([
  38. 'spec_id' => $spec_id,
  39. 'spec_value' => $spec_value,
  40. 'is_del' => 0
  41. ])->find();
  42. if ($id_is_empty) return error_show(1005, '数据库已存在该规格值');
  43. else {
  44. $data = [
  45. "spec_id" => $spec_id,
  46. "spec_value" => $spec_value,
  47. "is_del" => 0,
  48. "addtime" => date("Y-m-d H:i:s"),
  49. "updatetime" => date("Y-m-d H:i:s")
  50. ];
  51. $info = Db::name("spec_value")->insert($data);
  52. if ($info) return error_show(0, "新建成功");
  53. else return error_show(1002, "新建失败");
  54. }
  55. }
  56. public function all(){
  57. $spec_id = isset($this->post['spec_id']) && $this->post['spec_id'] !=="" ? intval($this->post['spec_id']):"";
  58. if($spec_id == ""){
  59. return error_show(1002,"参数spec_id不能为空");
  60. }
  61. $info = Db::name('spec_value')->where(['spec_id'=>$spec_id,'is_del'=>0])->select();
  62. if($info==""){
  63. return error_show(1002,"未找到数据");
  64. }
  65. return app_show(0,"获取成功",$info);
  66. }
  67. }