|
@@ -8,15 +8,48 @@ use think\facade\Db;
|
|
|
|
|
|
class InvCat extends BaseController{
|
|
|
public function __construct(App $app) {parent::__construct($app);}
|
|
|
-
|
|
|
+ //商品关联开票类目
|
|
|
public function AddGood(){
|
|
|
+ $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
|
|
|
+ if($spuCode==''){
|
|
|
+ return error_show(1004,"参数 spuCode 不能为空");
|
|
|
+ }
|
|
|
+ $goodinfo =Db::name("good")->where(["spuCode"=>$spuCode])->findOrEmpty();
|
|
|
+ if(empty($goodinfo)) return error_show(1004,"商品数据未找到");
|
|
|
+ $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!=''?trim($this->post['inv_good_name']):"";
|
|
|
+ if($inv_good_name==''){
|
|
|
+ return error_show(1004,"参数 inv_good_name 不能为空");
|
|
|
+ }
|
|
|
+ $tax = isset($this->post['tax'])&&$this->post['tax']!=''?trim($this->post['tax']):"";
|
|
|
+ if($tax=="") return error_show(1004,"参数 tax 不能为空");
|
|
|
+ $cat_code = isset($this->post['cat_code'])&&$this->post['cat_code']!=''?trim($this->post['cat_code']):"";
|
|
|
+ if($cat_code==''){
|
|
|
+ return error_show(1004,"参数 cat_code 不能为空");
|
|
|
+ }
|
|
|
+ $catinfo=Db::name("inv_cat")->where(["cat_code"=>$cat_code])->findOrEmpty();
|
|
|
+ if(empty($catinfo)) return error_show(1004,"未找到对应的开票类目");
|
|
|
+ $taxArr=$catinfo['tax']!=''? explode("、",$catinfo['tax']):[];
|
|
|
+ if(!in_array($tax,$taxArr))return error_show(1004,"未找到对应的开票类目税率");
|
|
|
+ $data=[
|
|
|
+ "inv_cat_name"=>$catinfo['short_name'],
|
|
|
+ "inv_cat_code"=>$catinfo['merge_code'],
|
|
|
+ "inv_tax"=>$tax,
|
|
|
+ "inv_good_name"=>$inv_good_name,
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $up =Db::name("good")->where($goodinfo)->update($data);
|
|
|
+ return $up? app_show(0,"添加成功"):error_show(1004,"添加失败");
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ //商品列表
|
|
|
public function GoodList(){
|
|
|
$page =isset($this->post['page'])&& $this->post['page']!="" ? intval($this->post['page']) :1;
|
|
|
$size =isset($this->post['size'])&& $this->post['size']!="" ? intval($this->post['size']) :15;
|
|
|
$condition =[];
|
|
|
+ $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
|
|
|
+ if($status!==''){
|
|
|
+ $condition[]=["status","=",$status];
|
|
|
+ }
|
|
|
$spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
|
|
|
if($spuCode!="") $condition[]=["spuCode","like","%$spuCode%"];
|
|
|
$good_name=isset($this->post['good_name'])&&$this->post['good_name']!=''?trim($this->post['good_name']):"";
|
|
@@ -39,4 +72,47 @@ class InvCat extends BaseController{
|
|
|
}
|
|
|
return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
|
|
|
}
|
|
|
+ //发票类目列表
|
|
|
+ public function catlist(){
|
|
|
+ $page =isset($this->post['page'])&& $this->post['page']!="" ? intval($this->post['page']) :1;
|
|
|
+ $size =isset($this->post['size'])&& $this->post['size']!="" ? intval($this->post['size']) :15;
|
|
|
+ $condition =[];
|
|
|
+ $cat_name = isset($this->post['cat_name'])&&$this->post['cat_name']!=''?trim($this->post['cat_name']):"";
|
|
|
+ if($cat_name!=''){
|
|
|
+ $condition[]=["cat_name|short_name","like","%$cat_name%"];
|
|
|
+ }
|
|
|
+ $cat_code = isset($this->post['cat_code'])&&$this->post['cat_code']!=''?trim($this->post['cat_code']):"";
|
|
|
+ if($cat_code!=''){
|
|
|
+ $condition[]=["cat_code|merge_code","like","%$cat_code%"];
|
|
|
+ }
|
|
|
+ $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
|
|
|
+ if($status!==''){
|
|
|
+ $condition[]=["status","=",$status];
|
|
|
+ }
|
|
|
+ $count =Db::name("inv_cat")->where($condition)->count();
|
|
|
+ $total=ceil($count/$size);
|
|
|
+ $page = $page>=$total? intval($total):$page;
|
|
|
+ $list =Db::name("inv_cat")->where($condition)->order("addtime desc")->page($page,$size)->select()->toArray();
|
|
|
+ foreach ($list as &$value){
|
|
|
+ $value['tax'] = $value['tax']==''?[]:explode("、",$value['tax']);
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
|
|
|
+ }
|
|
|
+ //类目查询
|
|
|
+ public function query(){
|
|
|
+ $condition =[];
|
|
|
+ $cat_name = isset($this->post['cat_name'])&&$this->post['cat_name']!=''?trim($this->post['cat_name']):"";
|
|
|
+ if($cat_name!=''){
|
|
|
+ $condition[]=["cat_name|short_name","like","%$cat_name%"];
|
|
|
+ }
|
|
|
+ $cat_code = isset($this->post['cat_code'])&&$this->post['cat_code']!=''?trim($this->post['cat_code']):"";
|
|
|
+ if($cat_code!=''){
|
|
|
+ $condition[]=["cat_code|merge_code","like","%$cat_code%"];
|
|
|
+ }
|
|
|
+ $list =Db::name("inv_cat")->where($condition)->order("addtime desc")->limit(30)->select()->toArray();
|
|
|
+ foreach ($list as &$value){
|
|
|
+ $value['tax'] = $value['tax']==''?[]:explode("、",$value['tax']);
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",$list);
|
|
|
+ }
|
|
|
}
|