post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1; $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10; $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : ""; $where = ["is_del"=>0]; if ($status !== "") { $where['status'] = $status; } $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : ""; if ($good_name !== "") { $where['good_name'] = array("like","%$good_name%"); } $group_id = isset($this->post['group_id']) && $this->post['group_id'] !== "" ? intval($this->post['group_id']) : ""; if ($group_id !== "") { $where['group_id'] =$group_id; } $start = isset($this->post['start']) &&$this->post['start']!=""? $this->post['start'] :""; if($start!==""){ $where['addtime'] =array(">=",date("Y-m-d H:i:s",strtotime($start))); } $end = isset($this->post['end']) &&$this->post['end']!=""? $this->post['end'] :""; if($end!==""){ $where['addtime'] =array("<=",date("Y-m-d H:i:s",strtotime($end)+24*3600)); } $count =Db::name("good")->where($where)->count(); $total = ceil($count/$size); $page = $page>$total?$total:$page; $list = Db::name("good")->where($where)->page($page,$size)->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } public function create(){ $good_name = isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):""; if($good_name==""){ return error_show(1004,"参数good_name不能为空"); } $good_desc = isset($this->post['good_desc'])&&$this->post['good_desc']!=""?trim($this->post['good_desc']):""; $good_unit = isset($this->post['good_unit'])&&$this->post['good_unit']!=""?trim($this->post['good_unit']):""; if($good_unit==""){ return error_show(1004,"参数good_unit不能为空"); } $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):""; if($good_img==""){ return error_show(1004,"参数good_img不能为空"); } $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""?trim($this->post['origin_place']):""; $group_id = isset($this->post['group_id'])&&$this->post['group_id']!==""?intval($this->post['group_id']):""; if($group_id===""){ return error_show(1004,"参数group_id不能为空"); } $isT = Db::name("good")->where(["good_name"=>$good_name,"is_del"=>0,"group_id"=>$group_id])->find(); if($isT){ return error_show(1004,"商品名称已存在"); } $data=[ "good_name"=>$good_name, "good_desc"=>$good_desc, "good_unit"=>$good_unit, "good_img"=>$good_img, "origin_place"=>$origin_place, "group_id"=>$group_id, "createrid"=>$this->userinfo['id'], "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $in = Db::name("good")->insert($data); if($in){ return app_show(0,"新建成功"); }else{ return app_show(1004,"新建失败"); } } public function edit(){ $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):""; if($id===""){ return error_show(1004,"参数id不能为空"); } $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $good_name = isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):""; if($good_name==""){ return error_show(1004,"参数good_name不能为空"); } $group_id = isset($this->post['group_id'])&&$this->post['group_id']!=""?intval($this->post['group_id']):""; if($group_id==""){ return error_show(1004,"参数group_id不能为空"); } $isT = Db::name("good")->where(["good_name"=>$good_name,"is_del"=>0,"group_id"=>$group_id])->find(); if($isT && $isT['id']!=$data['id']){ return error_show(1004,"商品名称已存在"); } $good_desc = isset($this->post['good_desc'])&&$this->post['good_desc']!=""?trim($this->post['good_desc']):""; $good_unit = isset($this->post['good_unit'])&&$this->post['good_unit']!=""?trim($this->post['good_unit']):""; if($good_unit==""){ return error_show(1004,"参数good_unit不能为空"); } $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):""; if($good_img==""){ return error_show(1004,"参数good_img不能为空"); } $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""?trim($this->post['origin_place']):""; $datas=[ "good_name"=>$good_name, "good_desc"=>$good_desc, "good_unit"=>$good_unit, "good_img"=>$good_img, "origin_place"=>$origin_place, "group_id"=>$group_id, "updatetime"=>date("Y-m-d H:i:s") ]; $in = Db::name("good")->where($data)->save($datas); if($in){ return app_show(0,"编辑成功"); }else{ return error_show(1004,"编辑失败"); } } public function delete(){ $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):""; if($id===""){ return error_show(1004,"参数id不能为空"); } $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $data['is_del']=1; $data['updatetime']=date("Y-m-d H:i:s"); $del = Db::name("good")->save($data); if($del){ return app_show(0,"删除成功"); }else{ return error_show(1004,"删除失败"); } } public function status(){ $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):""; if($id===""){ return error_show(1004,"参数id不能为空"); } $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $status = isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):""; if($status===""){ return error_show(1004,"参数status不能为空"); } $msg = $status==1?"启用":"禁用"; $data['status']=$status; $data['updatetime']=date("Y-m-d H:i:s"); $del = Db::name("good")->save($data); if($del){ return app_show(0,"{$msg}成功"); }else{ return error_show(1004,"{$msg}失败"); } } public function info(){ $id = isset($this->post['id'])&&$this->post['id']!=""? intval($this->post['id']):""; if($id===""){ return error_show(1004,"参数id不能为空"); } $data = Db::name("good")->where(["id"=>$id,"is_del"=>0])->find(); if($data==false){ return error_show(1004,"未找到商品数据"); } $creater = Db::name("admin")->where(["id"=>$data['createrid']])->find(); $data['creater'] = isset($creater['username']) ? $creater['username']:""; return app_show(0,"获取成功",$data); } }