123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\ProcessOrder;
- use think\App;
- use think\facade\Db;
- class Purch extends Base
- {
- public $noble=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->noble=\think\facade\Config::get("noble");
- }
- public function list(){
- $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']):"10";
- $where =[['is_del',"=",0]];
- $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
- if($bkcode!=""){
- $where[]=['bkcode',"like", "%{$bkcode}%"];
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status!==""){
- // $where['status'] = $status;
- $where[]=['status',"=", $status];
- }
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo'])
- :"";
- if($cgdNo!=""){
- //$where['cgdNo'] = Db::Raw("like '%{$cgdNo}%'");
- $where[]=['cgdNo',"like", "%{$cgdNo}%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
- if($apply_name!=""){
- // $where['cgder'] =Db::Raw("like '%{$apply_name}%'");
- $where[]=['cgder',"like", "%{$apply_name}%"];
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
- if($wsm_code!=""){
- // $where['wsm_code'] = $wsm_code;
- $where[]=['wsm_code',"=", $wsm_code];
- }
- $wsm_in_code = isset($this->post['wsm_in_code']) && $this->post['wsm_in_code']!="" ? trim($this->post['wsm_in_code']):"";
- if($wsm_in_code!=""){
- $incode = Db::name("purchease_in")->where(["wsm_in_code"=>Db::raw(" like %{$wsm_in_code}%"),"is_del"=>0])->column("cgdNo");
- if(empty($incode)){
- return error_show(1004,"未找到有关入库单信息");
- }
- $where[]=['cgdNo',"in", $incode];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
- if($good_name!=""){
- //$where['good_name'] = Db::raw(" like %{$good_name}%");
- $where[]=['good_name',"like", "%{$good_name}%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
- :"";
- if($good_code!=""){
- // $where['good_code'] = Db::raw(" like %{$good_code}%");
- $where[]=['spuCode',"like", "%{$good_code}%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo']!="" ? trim($this->post['supplierNo'])
- :"";
- if($supplierNo!=""){
- // $where['good_code'] = Db::raw(" like %{$good_code}%");
- $where[]=['supplierNo',"like", "%{$supplierNo}%"];
- }
- $wsm_supplierNo = isset($this->post['wsm_supplierNo']) && $this->post['wsm_supplierNo']!="" ? trim($this->post['wsm_supplierNo'])
- :"";
- if($wsm_supplierNo!=""){
- $supplier = Db::name("supplier")->where(["code"=>$wsm_supplierNo])->find();
- if(empty($supplier)){
- return error_show(1004,"未找到供应商信息");
- }
- $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$wsm_supplierNo])->column("wsm_code");
- $where[]=['wsm_code',"in", $wsmcode];
- }
- $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
- if($start!=""){
- // $where['addtime'] = Db::raw(" >= '{$start}'");
- $where[]=['addtime',">=", $start];
- }
- $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
- if($end!=""){
- $where[]=['addtime',"<=", $end];
- }
- $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
- if($last_start!=""){
- //$where['lasttime'] = Db::raw(" >= '{$last_start}'");
- $where[]=['lasttime',">=", $last_start];
- }
- $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
- if($last_end!=""){
- //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
- $where[]=['lasttime',"<=", $last_end];
- }
- $count=Db::name("purchease_order")->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name("purchease_order")->where($where)->page($page,$size)->order("addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $value['wsm_name']="";
- if($value['wsm_code']!=""){
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
- ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
- $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
- $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
- $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
- }
- if($value['order_type']==3|| $value['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
- $value["speclist"]=isset($goon['specinfo'])&&$goon['specinfo']!=""? json_decode($goon['specinfo'],true):"";
- }else {
- $goon =Db::name('good_basic')->where(['spuCode'=>$value['spuCode']])->find();
- $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
- $speclist=[];
- if(!empty($spec)){
- foreach ($spec as $val){
- $temp=[];
- $temp['id']=$val['id'];
- $temp['spuCode']=$val['spuCode'];
- $temp['spec_id']=$val['spec_id'];
- $temp['spec_value_id']=$val['spec_value_id'];
- $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
- $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
- $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
- $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
- $speclist[]=$temp;
- }
- }
- $value["speclist"]=empty($speclist)?[]:$speclist;
- }
-
- //采购单详情字段order_type 为1或者2时,取线上商品库 商品创建人 order_type 为3或者4时 取采购反馈的商品库 商品反馈人
- $value['cgder_id'] = $goon['createrid'];
- $value['cgder'] = $goon['creater'];
- $inorder= Db::name("purchease_in")->where(['cgdNo'=>$value['cgdNo'],"is_del"=>0])->select();
- $value['child']=empty($inorder)? [] : $inorder;
- $data[]=$value;
- }
- return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
- }
- public function info(){
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
- if($cgdNo==""){
- return error_show(1004,"参数cgdNo 不能为空");
- }
- $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
- if(empty($data)){
- return error_show(1004,"未找到数据");
- }
- $im = Db::name('purchease_back')->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->select();
- $var=[];
- foreach ($im as $value){
- $goon = Db::name('good_basic')->where(['spuCode'=>$value['good_code']])->field("cat_id")->find();
- if(empty($goon)){
- return error_show(1002,"未找到商品数据");
- }
- $cat= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
- $value['cant']=$cat;
- $var[]=$value;
- }
- $dom = Db::name("purchease_diff")->where(['cgdNo'=>$data['cgdNo'],'is_del'=>0])->find();
- if($data['order_type']==3|| $data['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
- }else {
- $goon =Db::name('good_basic')->where(['spuCode'=>$data['spuCode']])->find();
- }
- if(empty($goon)){
- return error_show(1002,"未找到商品数据");
- }else{
- $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
- $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
- $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
- $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
- $speclist=[];
- if(!empty($spec)){
- foreach ($spec as $value){
- $temp=[];
- $temp['id']=$value['id'];
- $temp['spuCode']=$value['spuCode'];
- $temp['spec_id']=$value['spec_id'];
- $temp['spec_value_id']=$value['spec_value_id'];
- $temp['is_del']=$value['is_del'];
- $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
- $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
- $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
- $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
- $speclist[]=$temp;
- }
- }
- $goon["speclist"]=empty($speclist)?[]:$speclist;
- $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
- $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
- $goon['origin_place_cn']="";
- $goon['delivery_place_cn']="";
- if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
- $goon['delivery_place_cn']=GetAddr(json_encode($place));
- }
- if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
- $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
- list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
- $goon['origin_place_cn']=GetAddr(json_encode($place));
- }
- if($goon['brand_id']!=0){
- $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
- $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
- }else{
- $goon["brand_name"]="";
- $goon["brand_id"]="";
- }
- $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
- $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
- $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
- if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
- $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
- }
- $goon['company'] = isset($company['company'])?$company['company']:"";
- }
- $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
- $data['wsm_name']="";
- if($data['wsm_code']!=""){
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
- ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
- ->where(["a.wsm_code"=>$data['wsm_code']])->field("a.name as wsm_name,b.name,b.code,c.wsm_name as wsm_contactor,c.wsm_mobile,c.wsm_addr,c.addr_code")->find();
- $data['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
- $data['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
- $data['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
- $data['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
- $data['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
- // $data['wsm_addr'] =isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
- $data['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
- $data['wsm_addr'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
- $data['wsm_addr'].=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
- $inorder= Db::name("purchease_in")->where(['cgdNo'=>$data['cgdNo'],"is_del"=>0])->select();
- $data['child']=empty($inorder)? [] : $inorder;
- }
- $data['can'] = $int;
- $data['goodinfo'] = $goon;
- $data['purcheasediff'] = $dom;
- if(isset($data['companyNo'])&&$data['companyNo']!=""){
- $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
- }
- $data['company'] = isset($company['company'])?$company['company']:"";
- //$data['info'] = $var;
- $data['purcheaseback'] = $var;
- return app_show(0,"获取成功",$data);
- }
- public function edit(){
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
- if($cgdNo==""){
- return error_show(1004,"参数cgdNo 不能为空");
- }
- $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
- if(empty($data)){
- return error_show(1004,"未找到数据");
- }
- $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$this->post['remark'],"action_type"=>"edit"];
- $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!=""? trim($this->post['wsm_code']):"";
- if($wsm_code!=""){
- $ware = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
- if(empty($ware)){
- return error_show(1004,"未找到仓库信息");
- }
- // $good = Db::name("good_stock")->where(["wsm_code"=>$wsm_code,"good_type_code"=>$data['good_type_code'],"is_del"=>0])->find();
- // if(empty($good)){
- // return error_show(1004,"未找到仓库下商品信息");
- // }
- $data['wsm_code'] = $wsm_code;
- }
- $cgdid = isset($this->post['cgder_id'])&&$this->post['cgder_id']!=""?intval($this->post['cgder_id']):"";
- if($cgdid!=''){
- $cgduser = GetInfoById($this->post['token'],["id"=>$cgdid]);
- if((!empty($cgduser) && $cgduser['code']!=0) ||empty($cgduser) ){
- return error_show($cgduser['code'],$cgduser['message']);
- }
- $userinfo = $cgduser['data'];
- $data['cgder_id'] = $cgdid;
- $data['cgder'] = $userinfo['nickname'];
- }
- $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=""?intval($this->post['good_num']):"";
- if($good_num!=""){
- $data['good_num'] = $good_num;
- }
- $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=""?$this->post['good_price']:"";
- if($good_price!=""){
- $data['good_price'] = $good_price;
- }
- // $total_fee = isset($this->post['total_fee'])&&$this->post['total_fee']!=""?$this->post['total_fee']:"";
- // if($total_fee!=""){
- // $data['total_fee'] = $total_fee;
- // }
- $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""?$this->post['pakge_fee']:"";
- if($pakge_fee!=""){
- $data['pakge_fee'] = $pakge_fee;
- }
- $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""?$this->post['cert_fee']:"";
- if($cert_fee!=""){
- $data['cert_fee'] = $cert_fee;
- }
- $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""?$this->post['open_fee']:"";
- if($open_fee!=""){
- $data['open_fee'] = $open_fee;
- }
- $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""?$this->post['delivery_fee']:"";
- if($delivery_fee!=""){
- $data['delivery_fee'] = $delivery_fee;
- }
- $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""?$this->post['mark_fee']:"";
- if($mark_fee!=""){
- $data['mark_fee'] = $mark_fee;
- }
- $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=""?$this->post['teach_fee']:"";
- if($teach_fee!=""){
- $data['teach_fee'] = $teach_fee;
- }
- $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=""?$this->post['nake_fee']:"";
- if($nake_fee!=""){
- $data['nake_fee'] = $nake_fee;
- }
- $weight = isset($this->post['weight'])&&$this->post['weight']!=""?$this->post['weight']:"";
- if($weight!=""){
- $data['weight'] = $weight;
- }
- $diff_weight = isset($this->post['diff_weight'])&&$this->post['diff_weight']!=""?$this->post['diff_weight']:"";
- if($diff_weight!=""){
- $data['diff_weight'] = $diff_weight;
- }
- $diff_fee = isset($this->post['diff_fee'])&&$this->post['diff_fee']!=""?$this->post['diff_fee']:"";
- if($diff_fee!=""){
- $data['diff_fee'] = $diff_fee;
- }
- $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""?trim($this->post['supplierNo'])
- :"";
- if($supplierNo!=""){
- $supplier =Db::name("supplier")->where(['code'=>$supplierNo])->find();
- if(empty($supplier)){
- return error_show(1004,"未找到供应商信息");
- }
- $data['supplierNo'] = $supplierNo;
- $data['supplier_name'] = $supplier['name'];
- }
- $remark = isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
- if($remark!=""){
- $data['remark'] = $remark;
- }
- $data['good_price'] = round(($data['pakge_fee']+$data['weight']*$data['gold_price']+$data['nake_fee']+$data['mark_fee']+$data['cert_fee']+$data['open_fee']/$data['good_num']
- +$data['teach_fee']*$data['weight']+$data['delivery_fee']),2);
- $data['total_fee'] = round($data['good_price']*$data['good_num'],2);
- $data['updatetime'] =date("Y-m-d H:i:s");
- $upd=Db::name("purchease_order")->save($data);
- if($upd){
- ActionLog::logAdd($this->post['token'],$order,'cgd',$data['status'],$this->post);
- return app_show(0,"更新成功");
- }else{
- return error_show(1004,'更新失败');
- }
- }
- public function status(){
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
- if($cgdNo==""){
- return error_show(1004,"参数cgdNo 不能为空");
- }
- $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
- if(empty($data)){
- return error_show(1004,"未找到数据");
- }
- $remark= isset($this->post['remark']) && $this->post['remark']!="" ?trim($this->post['remark']):"";
- $status = isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
- if($status===""){
- return error_show(1004,"参数status 不能为空");
- }
- if($data['send_status']>1 && $status==0){
- return error_show(1004,"采购单发货中无法取消");
- }
- $order = ["order_code"=>$cgdNo,"status"=> $data['status'] ,"action_remark"=>$remark,"action_type"=>"status"];
- $data['status'] = $status;
- $data['remark'] = $remark;
- $data['updatetime'] =date("Y-m-d H:i:s");
- $upd=Db::name("purchease_order")->save($data);
- if($upd){
- $process=["order_code"=>$cgdNo,"order_id"=>$data['id'],"order_status"=>$status,"order_type"=>'CGD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- ActionLog::logAdd($this->post['token'],$order,'cgd',$status,$this->post);
- return app_show(0,"更新成功");
- }else{
- return error_show(1004,'更新失败');
- }
- }
- public function diffcreat(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- //$cgdNo=makeNo("CG");
- $cgdNo = $this->post['cgdNo'] && $this->post['cgdNo'] !=="" ? trim($this->post['cgdNo']) :"";
- if($cgdNo==""){
- return error_show(1002,"参数good_code不能为空");
- }
- $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
- if($cg==""){
- return error_show(1002,"未找到采购单数据");
- }
- $gd= Db::name('good')->where(['spuCode'=>$cg['spuCode']])->find();
- if($gd==""){
- return error_show(1002,"未找到商品数据");
- }
- $diff_weight = isset($this->post['diff_weight']) && $this->post['diff_weight'] !=="" ? floatval($this->post['diff_weight']) :"";
- if($diff_weight===""){
- return error_show(1002,"参数diff_weight不能为空");
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $diff_price = $diff_weight*$cg['gold_price'];
- $data=[
- "cgdNo"=>$cgdNo,
- "good_code"=>$cg['spuCode'],
- "good_name"=>$cg['good_name'],
- "sale_price"=>$cg['good_price'],
- "good_weight"=>$cg['weight'],
- "good_num"=>$cg['good_num'],
- "apply_id"=>$rid,
- "apply_name"=>$rname,
- "diff_weight"=>$diff_weight,
- "diff_price"=>$diff_price,
- "gold_price"=>$cg['good_price'],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- try{
- $item = Db::name("purchease_diff")->insert($data,true);
- if($item>0){
- $stm = ["order_code"=>$cgdNo,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stm,"CGGCD",1,$stm);
- $process=["order_code"=>$cgdNo,"order_id"=>$item,"order_status"=>1,"order_type"=>'CGGCD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- $orderCode = Db::name("order_num")->where([["cgdNo","=",$cg['cgdNo']],["status","=",1]])->column("orderCode");
- if(!empty($orderCode)){
- $order = Db::name("sale")->where(["orderCode"=>$orderCode])->select()->toArray();
- if(empty($order)){
- Db::rollback();
- return error_show(1002,"未找到确认单信息");
- }
- foreach ($orderCode as $value){
- $data=[
- "orderCode"=>$value['orderCode'],
- "good_code"=>$value['spuCode'],
- "good_name"=>$value['good_name'],
- "diff_weight"=>$diff_weight,
- "diff_price"=>$diff_weight*$value['good_price'],
- "gold_price"=>$value['good_price'],
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $cgd = Db::name('sale_diff')->insert($data,true);
- if($cgd==0){
- // $sto = ["order_code"=>$cg['bkcode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
- // ActionLog::logAdd($this->post['token'],$sto,"ZXGCD",1,$sto);
- // $process=["order_code"=>$cg['bkcode'],"order_id"=>$cgd,"order_status"=>1,"order_type"=>'ZXGCD'];
- // ProcessOrder::AddProcess($this->post['token'],$process);
- // Db::commit();
- // return error_show(0,"新建成功");
- // }else{
- Db::rollback();
- return error_show(1002,"新建失败");
- }
- }
- }
- Db::commit();
- return error_show(0,"新建成功");
- }else{
- Db::rollback();
- return error_show(1002,"新建失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1002,$e->getMessage());
- }
- }
- public function difflist(){
- $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']):"10";
- $where = [['a.is_del',"=",0]];
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
- if($cgdNo!=""){
- $where[]=['a.cgdNo',"like", "%$cgdNo%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"";
- if($status!==""){
- $where[]=['a.status',"=",$status];
- }
- $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
- if ($start !="") {
- $where[]= ["a.addtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
- if($end !=""){
- $where[]= ["a.addtime",'<=',$end];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
- if($apply_name!==""){
- $where[]=['a.apply_name',"like","%$apply_name%"];
- }
- $count = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
- ->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('purchease_diff')->alias('a')->join("good b","b.spuCode=a.good_code","left")
- ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.cat_id")->select();
- $data=[];
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- public function diffinfo(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id 不能为空");
- }
- $idinf = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
- if($idinf==false){
- return error_show(1002,"未找到采购工差单数据");
- }
- $dn = Db::name('purchease_order')->where(['cgdNo'=>$idinf['cgdNo'],'is_del'=>0])->field('order_type')->find();
- $goon = Db::name('good')->where(['spuCode'=>$idinf['good_code']])->find();
- if(empty($goon)){
- return error_show(1002,"未找到商品数据");
- }
- $idinf['wsm_name'] ="";
- $idinf['wsm_supplier'] ="";
- $idinf['wsm_supplierNo'] ="";
- $idinf['wsm_contactor'] ="";
- $idinf['wsm_mobile'] ="";
- $idinf['addr_code'] ="";
- $idinf['wsm_addr'] ="";
- if($dn['wsm_code']!=""){
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
- ->leftJoin("warehouse_addr c","a.wsm_code=c.wsm_code and c.is_del=0")
- ->where(["a.wsm_code"=>$dn['wsm_code']])->field("a.name as wsm_name,b.name,b.code,c.wsm_name as wsm_contactor,c.wsm_mobile,c.wsm_addr,c.addr_code")->find();
- $idinf['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
- $idinf['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
- $idinf['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
- $idinf['wsm_contactor'] =isset($wsmcode['wsm_contactor']) ? $wsmcode['wsm_contactor']:"";
- $idinf['wsm_mobile'] =isset($wsmcode['wsm_mobile']) ? $wsmcode['wsm_mobile']:"";
- // $data['wsm_addr'] =isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
- $idinf['addr_code'] =isset($wsmcode['addr_code']) ? $wsmcode['addr_code']:"";
- $idinf['addr_cn'] =isset($wsmcode['addr_code']) ? GetAddr($wsmcode['addr_code']):"";
- $idinf['wsm_addr']=isset($wsmcode['wsm_addr']) ? $wsmcode['wsm_addr']:"";
- }
- $idinf['info'] =$dn;
- $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
- $idinf['can']=$int;
- $idinf['order_type']=$dn['order_type'];
- return app_show(0,"获取成功",$idinf);
- }
- public function diffstatu(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $dio = Db::name('purchease_diff')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($dio)){
- return error_show(1002,"退货订单未找到");
- }
- $cgd = Db::name("purchease_order")->where(['cgdNo'=>$dio['cgdNo']])->find();
- if(empty($cgd)){
- return error_show(1002,"采购单未找到");
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- if($status===""){
- return error_show(1002,"参数status不能为空");
- }
- $temp = $dio['status'];
- $dio['status']=$status;
- $dio['updatetime']=date("Y-m-d H:i:s");
- $item = Db::name("purchease_diff")->update($dio);
- if ($item){
- $sto = ["order_code"=>$dio['cgdNo'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$sto,"CGGCD",$dio['status'],$sto);
- $process=["order_code"=>$dio['cgdNo'],"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGGCD'];
- ProcessOrder::AddProcess($this->post['token'],$process);
- return error_show(0,"更新成功");
- }else{
- return error_show(1002,"更新失败");
- }
- }
- // public function create(){
- // $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
- // if($customer==""){
- // return error_show(1004,"参数customer_code不能为空");
- // }
- // $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
- // if($supplier==""){
- // return error_show(1004,"参数supplier_code不能为空");
- // }
- // $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
- // if($good_code==""){
- // return error_show(1004,"参数good_code不能为空");
- // }
- // $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
- // if($good_num===""){
- // return error_show(1004,"参数good_code不能为空");
- // }
- // $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
- // if($file_url===""){
- // return error_show(1004,"参数file_url不能为空");
- // }
- // $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
- // if($mark==""){
- // return error_show(1004,"参数remark不能为空");
- // }
- //
- // $data=[
- // ""
- // ];
- // }
- }
|