model=new \app\admin\model\GoodZixun(); } public function list(){ $param = $this->request->param(["spuCode"=>"","status"=>"","tax_status"=>"","order_source"=>"","orderCode"=>"", "start"=>"","end"=>"","relaComNo"=>"","good_name"=>"","supplierNo"=>"","name"=>"","page"=>"1","size"=>"10","creater"=>""], "post","trim"); $where =[['is_del','=',0]] ; if($param['spuCode']!="") $where[]=['good_zixun.spuCode','like',"%".$param['spuCode']."%"]; if($param['status']!="") $where[]=['good_zixun.status','=',$param['status']]; if($param['tax_status']!="") $where[]=['good_tax.status','=',$param['tax_status']==0?null:$param['tax_status']]; if($param['order_source']!="") $where[]=['order_source','in',$param['order_source']]; if($param['orderCode']!="") $where[]=['good_zixun.spuCode','in',\app\admin\model\Sale::where("orderCode","=",$param['orderCode'])->column("good_code")]; if($param['relaComNo']!="") $where[]=['good_zixun.companyNo|supplierNo','=',$param['relaComNo']]; if($param['good_name']!="") $where[]=['good_name','like',"%".$param['good_name']."%"]; if($param['supplierNo']!="") $where[]=['supplierNo','like',$param['supplierNo']]; if($param['name']!="") $where[]=['supplierName','like',"%".$param['name']."%"]; if($param['start']!="") $where[]=['good_zixun.addtime','>=',startTime($param['start'])]; if($param['end']!="") $where[]=['good_zixun.addtime','<=',endTime($param['end'])]; if($param['creater']!="") $where[]=['good_zixun.creater','like',"%{$param['creater']}%"]; $list = $this->model->with(["brand","unit","cat","Platform","GoodTax"=>["outCategory","inCategory","cgdCategory"]])->withJoin("good_tax","left") ->where($where)->order('id desc') ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]) ->each(function(&$item){ $item['cat_info'] = explode("_",$item->search); $item['is_basic'] =GoodBasic::where("spuCode","=",$item['spuCode'])->value("status"); $item['is_online'] = GoodPlatform::where("spuCode","=",$item['spuCode'])->findOrEmpty()->isEmpty()?0:1; $item["orderCode"] = \app\admin\model\Sale::where("good_code","=",$item['spuCode'])->value("orderCode"); $account = AccountItem::with(["ItemName"])->where("account_id","=",$item['order_createrid'])->findOrEmpty(); $item["order_creater_depart"] = $account["depart_name"]??""; }); $list->hidden(["brand","unit","cat","good_tax","GoodTax","Platform"]); return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } //添加或修改商品税目 public function changeTax(){ $param = $this->request->param([ "spuCode"=>"", "isToSale"=>0, //是否同步结算销售单 "isToCgd"=>0, //是否同步结算采购单 "isToGood"=>0, //是否同步结算商品库 "tax_id"=>"", "tax"=>"", "inv_good_name"=>"", "out_tax_id"=>"", "out_tax"=>"", "cgd_tax_id"=>"", "cgd_tax"=>"", ],"post","trim"); $validate = $this->validate($param,[ "spuCode|商品编码"=>"require", "isToSale|是否同步结算销售单"=>"number|in:0,1", "isToCgd|是否同步结算采购单"=>"number|in:0,1", "isToGood|是否同步结算商品库"=>"number|in:0,1", "tax_id|进项税目"=>"require", "tax|进项税率"=>"number", "inv_good_name|开票商品名称"=>"require", "out_tax_id|销项税目"=>"require", "out_tax|销项税率"=>"number", "cgd_tax_id|源头税目"=>"require", "cgd_tax|源头税率"=>"number", ]); if($validate!==true) return error($validate); $good= $this->model->where("spuCode","=",$param['spuCode'])->findOrEmpty(); if($good->isEmpty()) return error("咨询商品不存在"); $good_tax = GoodTax::where("spuCode","=",$param['spuCode'])->findOrEmpty(); $good_tax->open_type=$good->open_type; $good_tax->spuCode=$param['spuCode']; $good_tax->companyNo = $good->companyNo; $good_tax->tax_id = $param['tax_id']; $good_tax->tax = $param['tax']; $good_tax->inv_good_name = $param['inv_good_name']; $good_tax->out_tax_id = $param['out_tax_id']; $good_tax->out_tax = $param['out_tax']; $good_tax->cgd_tax_id = $param['cgd_tax_id']; $good_tax->cgd_tax = $param['cgd_tax']; $good_tax->status=($param['tax_id']>0 && $param['out_tax_id']>0)?2:1; $good_tax->createrid=$good_tax->createrid??$this->uid; $good_tax->creater=$good_tax->creater??$this->uname; $this->model->startTrans(); try{ $save=$good_tax->save(); if($save==false) throw new \Exception("添加失败"); if($param['isToSale']==1){ $sale = \app\admin\model\Sale::where("good_code","=",$param['spuCode'])->findOrEmpty(); if(!$sale->isEmpty()){ $sale->updatetime=date('Y-m-d H:i:s'); if($sale->save()==false) throw new \Exception('同步销售单失败'); } OrderTax::where(["spuCode"=>$param['spuCode'],"code"=>$sale->orderCode])->delete(); OrderCategory::where(["spuCode"=>$param['spuCode']])->whereNotLike("code","CG%") ->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]); } if($param['isToCgd']==1){ $cgd = \app\admin\model\PurcheaseOrder::where("spuCode","=",$param['spuCode'])->findOrEmpty(); if(!$cgd->isEmpty()) { $cgd->updatetime=date('Y-m-d H:i:s'); if($cgd->save()==false) throw new \Exception('同步采购单失败'); OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete(); OrderCategory::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']); }else{ OrderTax::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->delete(); OrderCategory::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']); } } if($param['isToGood']==1){ $good->updatetime=date('Y-m-d H:i:s'); $sa=$good->save(); if($sa==false) throw new \Exception("同步商品库失败"); } $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } return success("更新成功"); } public function info(){ $id = $this->request->post("id","", "int"); $info = $this->model->with(["brand","unit","cat","Platform","GoodTax"=>["outCategory","inCategory","cgdCategory"]]) ->where("id","=",$id)->findOrEmpty(); if($info->isEmpty()) return error("咨询商品不存在"); $info['cat_info'] = explode("_",$info->search); $info['is_basic'] =GoodBasic::where("spuCode","=",$info['spuCode'])->value("status"); $info['is_online'] = GoodPlatform::where("spuCode","=",$info['spuCode'])->findOrEmpty()->isEmpty()?0:1; $info["orderCode"] = \app\admin\model\Sale::where("good_code","=",$info['spuCode'])->value("orderCode"); $account = AccountItem::with(["ItemName"])->where("account_id","=",$info['order_createrid'])->findOrEmpty(); $info["order_creater_depart"] = $account["depart_name"]??""; return success("获取成功",$info); } }