123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- class Sale extends BaseController
- {
- public $post="";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post=$this->request->post();
- }
- public function create(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- $orderCode=makeNo("CX");
- $good_code = $this->post['good_code'] && $this->post['good_code'] !=="" ? trim($this->post['good_code']) :"";
- if($good_code==""){
- return error_show(1002,"商品code不能为空");
- }
- $ct = Db::name('good')->alias('a')->join('good_type b','b.good_code=a.good_code','left')
- ->where(['b.type_code'=>$good_code])->find();
- if($ct==""){
- return error_show(1002,"未找到商品数据");
- }
- $customer_code= $this->post['customer_code'] && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
- if($customer_code==""){
- return error_show(1002,"客户code不能为空");
- }
- $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
- if($customer==false){
- return error_show(1004,"未找到客户数据");
- }
- $supplierNo= $this->post['supplierNo'] && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
- if($supplierNo==""){
- return error_show(1002,"参数supplierNo不能为空");
- }
- $supplier=Db::name("supplier")->where(["code"=>$supplierNo])->find();
- if($supplier==false){
- return error_show(1004,"未找到平台供应商数据");
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- // $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
- //$good_num=isset($this->post['good_num']) && $this->post['good_num'] !=="" ? intval($this->post['good_num']) :"";
- // if($good_num==""){
- // return error_show(1002,"参数good_num不能为空");
- //}
- // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? intval($this->post['origin_price']) :"";
- //$sale_price=isset($this->post['sale_price']) && $this->post['sale_price'] !=="" ? trim($this->post['sale_price']) :"";
- // $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
- $post_fee=isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"";
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- // $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? intval($this->post['send_num']) :"";
- // $wsend_num = isset($this->post['wsend_num']) && $this->post['wsend_num'] !=="" ? intval($this->post['wsend_num']) :"";
- // $send_status = isset($this->post['send_status']) && $this->post['send_status'] !=="" ? intval($this->post['send_status']) :"";
- $va= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
- if($va==""){
- return error_show(1002,"参数order_addr不能为空");
- }
- $vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ? $this->post['good_stock']:"";
- if($vi==""){
- return error_show(1002,"参数good_stock不能为空");
- }
- $good_num = intval(array_sum(array_column($vi,"num")));
- Db::startTrans();
- try {
- $data=[
- "orderCode"=>$orderCode,
- "good_code"=>$good_code,
- "customer_code"=>$customer_code,
- "good_name"=>$ct['good_name'],
- "good_num"=>$good_num,
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "origin_price"=>$ct['original_price'],
- "sale_price"=>$ct['original_price'],
- "post_fee"=>$post_fee,
- "status"=>$status,
- "supplierNo"=>$supplierNo,
- "send_num"=>0,
- "wsend_num"=>$good_num,
- "send_status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'total_price'=>$ct['original_price']*$good_num,
- ];
- $datainfo = Db::name('sale')->insert($data,true);
- $vat=[];
- $inn=[];
- if($datainfo>0){
- foreach ($vi as $ion){
- $iten=[];
- $iten['orderCode']=$orderCode;
- $iten['wsm_code']=$ion['wsm_code'];
- $iten['stock_id']="";
- $iten['num']=$ion['num'];
- $iten['status']=0;
- $iten['sale_price']=$ct['original_price'];
- $iten['addtime'] =date("Y-m-d H:i:s");
- $iten['updatetime'] =date("Y-m-d H:i:s");
- $inn[]=$iten;
- }
- // if($vi['usable_stock']<$iten['num']){
- // Db::rollback();
- // return error_show(1002,"超出库存数量");
- // }
- $vp= Db::name('sale_info')->insertAll($inn);
- if($vp==""){
- Db::rollback();
- return error_show(1002,"添加失败");
- }
- foreach ($va as $value){
- $temp=[];
- $addrs=[];
- if($value['addr_code']!==''&&is_array($value['addr_code'])){
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- }else{
- $addr = isset($value['addr_code'])?$value['addr_code']:'';
- }
- $temp['orderCode']=$orderCode;
- $temp['contactor']=$value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code']=$addr;
- $temp['customer_code'] =$customer_code;
- $temp['receipt_quantity']=$value['receipt_quantity'];
- $temp['post_fee'] =0;
- $temp['is_del'] =0;
- $temp['addtime'] =date("Y-m-d H:i:s");
- $temp['updatetime'] =date("Y-m-d H:i:s");
- $temp['arrive_time']=date("Y-m-d H:i:s");
- $vat[]=$temp;
- }
- $vmp = Db::name('order_addr')->insertAll($vat);
- if($vmp){
- Db::commit();
- return error_show(0,"销售订单创建成功");
- }
- }
- Db::rollback();
- return error_show(1002,"销售订单创建失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- 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];
- $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']):"";
- if($orderCode !==""){
- $where[]=['orderCode',"=",$orderCode];
- }
- $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
- :"";
- if($apply_name !==""){
- $where[]=['apply_name',"like","%$apply_name%"];
- }
- $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
- :"";
- if($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',"like","%$good_code%"];
- }
- $customer_code=isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']):"";
- if($customer_code !==""){
- $where[]=['customer_code',"like","%$customer_code%"];
- }
- $supplierNo=isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
- if($supplierNo !==""){
- $where[]=['supplierNo',"like","%$supplierNo%"];
- }
- $ordertype=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? intval($this->post['order_type'])
- :"";
- if($ordertype !==""){
- $where[]=['order_type',"=",$ordertype];
- }
- $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
- if($status !==""){
- $where[]=['status',"=",$status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
- if($start !=""){
- $where[]= ["addtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
- if($end !=""){
- $where[]= ["addtime",'<=',$end];
- }
- $count = Db::name('sale')->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list= Db::name('sale')->where($where)->order("addtime desc")->page($page,$size)->select();
- $data=[];
- foreach ($list as $value){
- $var = Db::name('good_type')->alias('b')->join("good a","a.good_code=b.good_code","left")
- ->where(['b.type_code'=>$value['good_code'],'a.is_del'=>0])->field('a.good_code,a.good_name,a.cat_id')->find();;
- $value['can']= isset($var['cat_id']) && $var['cat_id'] !=0 ? made($var['cat_id']):[];
- $value['supplierName']='';
- if($value['supplierNo']!=""){
- $supplier=Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
- $value['supplierName']=isset($supplier['name']) ? $supplier['name']:"";
- }
- $value['customerName']='';
- if($value['customer_code']!=""){
- $supplier=Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
- $value['customerName']=isset($supplier['companyName']) ? $supplier['companyName']:"";
- }
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- public function edit(){
- $token = isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $etid = Db::name("sale")->where(["id"=>$id,"is_del"=>0])->find();
- if(empty($etid)){
- return error_show(1002,"未找到数据");
- }
- // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- // if($orderCode==""){
- // return error_show(1002,"销售单code不能为空");
- // }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code']) :"";
- if($good_code==""){
- return error_show(1002,"商品code不能为空");
- }
- $customer_code=isset($this->post['customer_code']) && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']):"";
- if($customer_code==""){
- return error_show(1002,"客户code不能为空");
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']) :"";
- $good_num=isset($this->post['good_num']) && $this->post['good_num'] !=="" ? intval($this->post['good_num']) :"";
- $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? intval($this->post['origin_price']) :"";
- $sale_price=isset($this->post['sale_price']) && $this->post['sale_price'] !=="" ? trim($this->post['sale_price']) :"";
- $total_price=isset($this->post['total_price']) && $this->post['total_price'] !=="" ? trim($this->post['total_price']) :"";
- $post_fee=isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? trim($this->post['post_fee']) :"";
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- $vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
- if($vr=="" ){
- return error_show(1002,"参数order_addr不能为空");
- }
- $vi= isset($this->post['good_stock']) && $this->post['good_stock'] !=="" ? $this->post['good_stock']:"";
- if($vi==""){
- return error_show(1002,"参数good_stock不能为空");
- }
- Db::startTrans();
- try {
- $datn=[
- "id"=>$id,
- "good_code"=>$good_code,
- "customer_code"=>$customer_code,
- "good_name"=>$good_name,
- "good_num"=>$good_num,
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "origin_price"=>$origin_price,
- "sale_price"=>$sale_price,
- "total_price"=>$total_price,
- "post_fee"=>$post_fee,
- "status"=>$status,
- "is_del"=>0,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datninfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($datn);
- if($datninfo>0){
- foreach ($vi as $ion) {
- $iten = [];
- isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
- $iten['orderCode'] = $etid['orderCode'];
- $iten['wsm_code'] = $ion['wsm_code'];
- $iten['stock_id'] =0;
- $iten['num'] = $ion['num'];
- $iten['status'] = 1;
- $iten['sale_price'] = $ion['sale_price'];
- isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
- $iten['updatetime'] = date("Y-m-d H:i:s");
- //$inn[]=$iten;
- $vp = Db::name('sale_info')->save($iten);
- if ($vp == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- foreach ($vr as $value) {
- $temp = [];
- isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
- $temp['orderCode'] = $etid['orderCode'];
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $value['addr_code'];
- $temp['customer_code'] = $customer_code;
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = $value['is_del'];
- isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = date("Y-m-d H:i:s");
- $dat = Db::name('order_addr')->save($temp);
- if ($dat == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- Db::commit();
- return error_show(0,"更新成功");
- }
- Db::rollback();
- return error_show(1002,"更新失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function info(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- //->field('good_code,good_name,good_num,customer_code,orderCode')
- $einfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($einfo)){
- return error_show(1002,"未找到销售订单数据");
- }
- $info = Db::name('sale_diff')->where(['orderCode'=>$einfo['orderCode']])->select();
- $de = Db::name('order_out')->where(['orderCode'=>$einfo['orderCode']])->select();
- $dm = Db::name('order_return')->where(['orderCode'=>$einfo['orderCode']])->select();
- $dk= Db::name('order_back')->where(['orderCode'=>$einfo['orderCode']])->select();
- $sa= Db::name('sale_return')->where(['orderCode'=>$einfo['orderCode']])->select();
- $goon = Db::name('good')->alias('b')->join("good_type a","a.good_code=b.good_code","left")
- ->where(['a.type_code'=> $einfo['good_code']])->find();
- if(empty($goon)){
- return error_show(1003,"未找到商品数据");
- }
- $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
- $in= Db::name('customer_info')->where(['companyNo'=>$einfo['customer_code']])->field('companyName')->find();
- // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
- $einfo['supplierName']='';
- if($einfo['supplierNo']!=""){
- $supplier=Db::name("supplier")->where(["code"=>$einfo['supplierNo']])->find();
- $einfo['supplierName']=isset($supplier['name']) ? $supplier['name']:"";
- }
- $fo = Db::name('order_addr')->where(['orderCode'=>$einfo['orderCode'],'is_del'=>0])->select();
- $bum = Db::name('order_out')->where(['orderCode'=>$einfo['orderCode']])->select();
- $ins=[];
- if(!empty($bum)){
- foreach ($bum as $stn){
- $so = Db::name('order_addr')->where(['id'=>$stn['addrid']])->find();
- $addr = GetAddr($so['addr_code']);
- $stn['addr_info']=$addr;
- $stn['add_code']=json_decode($so['addr_code'],true);
- $stn['addr']=$so['addr'];
- $stn['contact']=$so['contactor'];
- $stn['mobile']=$so['mobile'];
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
- ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
- $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
- $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
- $ins[]=$stn;
- }
- }
- $addrs=[];
- if(!empty($fo)){
- foreach ($fo as $value){
- $value['addr_info']="";
- $value['send_num']=0;
- if($value['addr_code']!=""){
- $addr=GetAddr($value['addr_code']);
- $value['addr_info'] = $addr;
- $value['addr_code'] = json_decode($value['addr_code'],true);
- $send = Db::name("order_out")->where(['addrid'=>$value['id'],'orderCode' => $einfo['orderCode']])->sum("send_num");
- $value['send_num'] = $send ?? 0;
- }
- $value['wsend_num']=$value['receipt_quantity']-$value['send_num'];
- $addrs[]=$value;
- }
- }
- //->field('num,sale_price,wsm_code,stock_id')
- $st = Db::name('sale_info')->where(['orderCode'=>$einfo['orderCode']])->select();
- $data=[];
- if(!empty($fo)) {
- foreach ($st as $value) {
- $value['wsm_name'] = "";
- $value['wsm_supplier'] = "";
- $value['wsm_supplierNo'] = "";
- $value['usable_stock'] = 0;
- $value['send_num'] = 0;
- 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'] : "";
- $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
- $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
- $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
- $value['send_num'] = $send ?? 0;
- }
- $value['wsend_num'] = $value['num'] - $value['send_num'];
- $data[] = $value;
- }
- }
- $einfo['info']=$data;
- $einfo['companyName']=isset($in['companyName']) ? $in['companyName']:"";
- $einfo['addrs']=$addrs;
- $einfo['bum']=$ins;
- $einfo['can']=$int;
- $einfo['item']=$info;
- $einfo['empty']=$de;
- $einfo['str']=$dm;
- $einfo['var']=$dk;
- $einfo['sainfo']=$sa;
- if(empty($einfo)){
- return error_show(1002,"未找到销售订单数据");
- }else{
- return app_show(0,"获取成功",$einfo);
- }
- }
- public function del(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id===""){
- return error_show(1002,"参数id不能为空");
- }
- $ed = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($ed)){
- return error_show(1002,"未找到销售订单数据");
- }
- $str =Db::name('sale')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
- if($str){
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- public function status(){
- $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
- if($status==""){
- return error_show(1002,"订单状态不能为空");
- }
- $dio = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($dio)){
- return error_show(1002,"销售单信息未找到");
- }
- if($status==1 && $dio['order_type']==2) {
- $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
- if ($zxinfo == false) {
- return error_show(1004, "未找到咨询单数据");
- }
- $gold['price']=0;
- if ($zxinfo['zx_type'] == 2) {
- if ($zxinfo['metals'] == "") {
- return error_show(1004, "未找到咨询单贵金属类型数据");
- }
- $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
- $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
- if (empty($gold)) {
- return error_show(1004, "未找到咨询单贵金属类型数据");
- }
- $dio['gold_price']=$gold['price'];
- }
- $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
- if (empty($wsm)) {
- return error_show(1002, "供应商仓库未找到");
- }
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $dio['status']=$status;
- $dio['updatetime']=date("Y-m-d H:i:s");
- $st = Db::name('sale')->save($dio);
- if($st) {
- if($status==3){
- $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
- foreach ($dn as $value) {
- $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
- if($dm==""){
- Db::rollback();
- return error_show(1003,"未找到商品数据");
- }
- if($value['num']>$dm['usable_stock']){
- Db::rollback();
- return error_show(1002,"超出库存数量");
- }
- $dm['usable_stock']-=$value['num'];
- $dm['wait_out_stock']+=$value['num'];
- $send =Db::name("order_out")->where(["wsm_code"=>$value['wsm_code']])->sum("send_num");
- $value['send_num'] = $send??0;
- $value['wsend_num']=$value['num']-$value['send_num'];
- $Db = Db::name('good_stock')->update($dm);
- $Db['updatetime']= date('Y-m-d H:i:s');
- if($Db==false){
- Db::rollback();
- return error_show(1002,"状态更新失败");
- }
- }
- }
- if($status==1 && $dio['order_type']==2){
- $cgd =makeNo("CG");
- $clll=[
- "cgdNo"=>$cgd,
- "bkcode"=>$dio['orderCode'],
- "wsm_code"=>$wsm['wsm_code'],
- "cgder_id"=>"0",
- "cgder"=>$zxinfo['saler'],
- "good_code"=>"GD-".$zxinfo['cpNo'],
- "good_name"=>$zxinfo['cpName'],
- "good_type_code"=>$zxinfo['cpNo'],
- "good_num"=>$dio['good_num'],
- "good_price"=>$zxinfo['total_fee'],
- "total_fee"=>round($zxinfo['total_fee']*$dio['good_num'],2),
- "pakge_fee"=>$zxinfo['package_fee'],
- "cert_fee"=>$zxinfo['cert_fee'],
- "open_fee"=>$zxinfo['open_fee'],
- "delivery_fee"=>$zxinfo['delivery_fee'],
- "mark_fee"=>$zxinfo['mark_fee'],
- "teach_fee"=>$zxinfo['cost_fee'],
- "demo_fee"=>$zxinfo['demo_fee'],
- "nake_fee"=>$zxinfo['bare_fee'],
- "weight"=>isset($zxinfo['weight'])?$zxinfo['weight']:0,
- "supplierNo"=>$zxinfo['gysNo'],
- "supplier_name"=>$zxinfo['gysname'],
- "gold_price"=>$gold['price'],
- "send_num"=>0,
- "wsend_num"=>$dio['good_num'],
- "remark"=>'',
- "lasttime"=>date("Y-m-d H:i:s"),
- "is_del"=>0,
- "status"=>$dio['send_type']==1?1:0,
- "order_type"=>2,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $cgin = Db::name("purchease_order")->insert($clll);
- // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
- if($cgin==false){
- Db::rollback();
- return error_show(1002,"咨询采购单创建商品失败");
- }
- if($dio['send_type']==1){
- $addr = Db::name('order_addr')->where(["orderCode"=>$dio['orderCode'],'is_del'=>0])->select();
- foreach ($addr as $value){
- $outCode=makeNo("CK");
- $data=[
- "wsm_code"=>$wsm['wsm_code'],
- "orderCode"=>$dio['orderCode'],
- "outCode"=>$outCode,
- "order_type"=>$dio['order_type'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "addrid"=>$value['id'],
- "post_name"=>'',
- "post_code"=>'',
- "post_fee"=>'',
- "sendtime"=>date("Y-m-d H:i:s"),
- "send_num"=>$value['receipt_quantity'],
- "check_num"=>0,
- "error_num"=>0,
- "status"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insert($data);
- if(!$datainfo){
- Db::rollback();
- return error_show(1003,"创建失败");
- }
- }
- }
- }
- }
- Db::commit();
- return error_show(0,"订单状态更新成功");
- }catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function fee(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $etid = Db::name("sale")->where(["id"=>$id,"is_del"=>0])->find();
- if(empty($etid)){
- return error_show(1002,"未找到数据");
- }
- $vr= isset($this->post['order_addr']) && $this->post['order_addr'] !=="" ? $this->post['order_addr']:"";
- if($vr==""){
- return error_show(1002,"参数order_addr不能为空");
- }
- Db::startTrans();
- try {
- $data=[
- "id"=>$id,
- "status"=>2,
- "is_del"=>0,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('sale')->where(['id'=>$id,'is_del'=>0])->save($data);
- if($datainfo){
- foreach ($vr as $value){
- $tm=[];
- $tm['id'] = $value['id'];
- $tm['orderCode']=$etid['orderCode'];
- $tm['post_fee']=$value['post_fee'];
- $tm['updatetime']=date("Y-m-d H:i:s");
- $dn = Db::name('order_addr')->save($tm);
- if($dn==false){
- Db::rollback();
- return error_show(1002,"更新失败");
- }
- }
- Db::commit();
- return error_show(0,"更新成功");
- }
- Db::rollback();
- return error_show(1003,"更新失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function out(){
- $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
- $outCode=makeNo("CK");
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- if($orderCode==""){
- return error_show(1002,"参数orderCoder不能为空");
- }
- $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
- if($der==""){
- return error_show(1002,"未找到出库订单单号");
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :"";
- if($wsm_code==""){
- return error_show(1002,"参数wsm_code不能为空");
- }
- $wsm= Db::name('sale_info')->where(['wsm_code'=>$wsm_code,'orderCode'=>$der['orderCode']])->find();
- if($wsm==""){
- return error_show(1002,"未找到仓库编码");
- }
- $post_name= isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
- if($post_name==""){
- return error_show(1002,"物流公司不能为空");
- }
- $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :"";
- if($post_code==""){
- return error_show(1002,"物流单号不能为空");
- }
- $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? intval($this->post['post_fee']) :"";
- if($post_fee==""){
- return error_show(1002,"物流费不能为空");
- }
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !=="" ? $this->post['send_num'] :"";
- if($send_num==""){
- return error_show(1002,"发货数量不能为空");
- }
- if($send_num>$wsm['num']){
- return error_show(1002,"超出可发货数量");
- }
- $apply_id =GetUserInfo($token);
- if(empty($apply_id)||$apply_id['code']!=0){
- return error_show(1002,"申请人数据不存在");
- }
- $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
- $dr = Db::name('order_addr')->where(['id'=>$addrid,'is_del'=>0])->find();
- if(empty($dr)){
- return error_show(1003,"收货人信息未找到");
- }
- if($dr['orderCode']!== $orderCode){
- return error_show(1002,"订单code不存在");
- }
- $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
- // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
- // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
- //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
- //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
- Db::startTrans();
- try {
- $data=[
- "wsm_code"=>$wsm_code,
- "orderCode"=>$orderCode,
- "outCode"=>$outCode,
- "order_type"=>$der['order_type'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "addrid"=>$dr['id'],
- "post_name"=>$post_name,
- "post_code"=>$post_code,
- "post_fee"=>$post_fee,
- "sendtime"=>$sendtime,
- "send_num"=>$send_num,
- "check_num"=>0,
- "error_num"=>0,
- "status"=>$status,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insert($data);
- if($datainfo) {
- if ($status==1) {
- $var = Db::name('sale_info')->where(['orderCode' =>$orderCode,'wsm_code'=>$wsm_code])->find();
- //var_dump(Db::name('sale_info')->getLastSql());
- if($var==""){
- return error_show(1002,"未找到数据");
- }
- $send =Db::name("order_out")->where(["wsm_code"=>$wsm_code,'orderCode'=>$orderCode])->sum("send_num");
- $der['send_num']+= $send;
- $der['wsend_num']-=$send ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
- $der['send_status']=$der['send_num']==0 ? 1 :$der['wsend_num']==0?3:2;
- $der['status']=$der['send_num']==0 ? 3 :$der['wsend_num']==0?5:4;
- $der['updatetime'] = date("Y-m-d H:i:s");
- $si = Db::name('sale')->save($der);
- if($si==false){
- Db::rollback();
- return error_show(1003,"更新失败");
- }
- $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'],'good_type_code'=>$der['good_code']])->find();
- if ($str == false) {
- Db::rollback();
- return error_show(1002, "商品数据未找到");
- }
- if ($var['num'] > $str['wait_out_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $str['wait_out_stock'] -= $var['num'];
- $str['intra_stock'] += $var['num'];
- $str['updatetime'] = date("Y-m-d H:i:s");
- $stre = Db::name('good_stock')->save($str);
- if ($stre == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- }
- Db::commit();
- return error_show(0,"创建成功");
- }else{
- Db::rollback();
- return error_show(1003,"创建失败");
- }
- }catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function customer(){
- $outCode= isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
- if(empty($outCode)){
- return error_show(1002,"销售订单编号不能为空");
- }
- $codeinfo = Db::name('order_out')->where(['outCode'=>$outCode])->find();
- if($codeinfo==""){
- return error_show(1003,"未找到订单数据");
- }
- // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- // if($orderCode==""){
- // return error_show(1002,"参数orderCoder不能为空");
- // }
- $dr = Db::name('sale')->where(['orderCode'=>$codeinfo['orderCode']])->find();
- if($dr==""){
- return error_show(1002,"未找到销售订单");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] :"";
- if($status==""){
- return error_show(10002,"状态不能为空");
- }
- Db::startTrans();
- try {
- $codeinfo['status']=$status;
- $codeinfo['updatetime']=date("Y-m-d H:i:s");
- $cust = Db::name('order_out')->save($codeinfo);
- if($cust){
- if($status==2){
- $ct =Db::name('sale_info')->where(['orderCode' => $dr['orderCode'],'wsm_code'=>$codeinfo['wsm_code']])->find();
- if($ct==false){
- return error_show(1002,"未找到数据");
- }
- $var = Db::name('good_stock')->where(['wsm_code'=>$codeinfo['wsm_code'],'good_type_code'=>$dr['good_code']])->find();
- if($var==false){
- Db::rollback();
- return error_show(1002,"未找到商品数据");
- }
- if($ct['num']>$var['intra_stock']){
- Db::rollback();
- return error_show(1003,"超出库存数量");
- }
- $var['intra_stock']-=$codeinfo['send_num'];
- $var['updatetime']=date("Y-m-d H:i:s");
- $stre = Db::name('good_stock')->save($var);
- if ($stre == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- }
- Db::commit();
- return error_show(0,"出库订单更新成功");
- }else{
- Db::rollback();
- return error_show(1003,"出库订单更新失败");
- }
- }catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $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 = [];
- $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode']):"";
- if($cgdNo!=""){
- $where[]=['a.orderCode',"like", "%$cgdNo%"];
- }
- $diffNo = isset($this->post['diffCode']) && $this->post['diffCode']!="" ? trim($this->post['diffCode']):"";
- if($diffNo!=""){
- $where[]=['a.diffCode',"like", "%$diffNo%"];
- }
- $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%"];
- // }
- $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
- if($supplierNo!=""){
- $supplier = Db::name("supplier")->where([['code',"like","%$supplierNo%"]])->column('code');
- // if(empty($supplier)){
- // return error_show(1004,"未找到供应商信息");
- // }
- $wsmcode = Db::name("sale")->where([
- "is_del"=>0,"supplierNo"=>$supplier])->column("orderCode");
- $where[]=['orderCode',"in",$wsmcode];
- }
- $count = Db::name('sale_diff')->alias('a')->join("good b","b.good_code=a.good_code","left")
- ->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('sale_diff')->alias('a')->join("good b","b.good_code=a.good_kode","left")
- ->where($where)->page($page,$size)->field("a.*,b.cat_id")->order("a.addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
- $wsm = Db::name("sale")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where
- (['a.orderCode'=>$value['orderCode'],"a.is_del"=>0])->field("b.code,b.name")->find();
- $value['code']=isset($wsm['code'])? $wsm['code']:"";
- $value['name']=isset($wsm['name']) ? $wsm['name']:"";
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffcheck(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
- if($id===""){
- return error_show(1004,"参数id不能为空");
- }
- $info = Db::name("sale_diff")->where(["id"=>$id])->find();
- if(empty($info)){
- return error_show(1004,"订单数据未找到");
- }
- $is_act = isset($this->post['is_act']) && $this->post['is_act'] !==""? intval($this->post['is_act']):"";
- if($is_act===''){
- return error_show(1004,"参数is_act不能为空");
- }
- $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !==""? trim($this->post['customer_remark']):"";
- if($customer_remark===''){
- return error_show(1004,"参数customer_remark不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"2";
- $remark = isset($this->post['remark']) && $this->post['remark'] !==""? trim($this->post['remark']):"";
- $info['is_act'] =$is_act;
- $info['customer_remark'] =$customer_remark;
- $info['status'] =$status;
- $info['remark'] =$remark;
- $info['updatetime'] =date("Y-m-d H:i:s");
- $up = Db::name("sale_diff")->save($info);
- if($up){
- return app_show(0,"更新成功");
- }else{
- return error_show(1003,"更新失败");
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffstatus(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
- if($id===""){
- return error_show(1004,"参数id不能为空");
- }
- $info = Db::name("sale_diff")->where(["id"=>$id])->find();
- if(empty($info)){
- return error_show(1004,"订单数据未找到");
- }
- $status = isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']):"3";
- $remark = isset($this->post['remark']) && $this->post['remark'] !==""? trim($this->post['remark']):"";
- $info['status'] =$status;
- $info['remark'] =$remark;
- $info['updatetime'] =date("Y-m-d H:i:s");
- $up = Db::name("sale_diff")->save($info);
- if($up){
- return app_show(0,"更新成功");
- }else{
- return error_show(1003,"更新失败");
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffinfo(){
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
- if($id===""){
- return error_show(1004,"参数id不能为空");
- }
- $info = Db::name('sale_diff')->alias('a')->join("good b","b.good_code=a.good_kode","left")->where
- (["a.id"=>$id])->field("a.*,b.cat_id")->find();
- if(empty($info)){
- return error_show(1004,"订单数据未找到");
- }
- $info['can']= isset($info['cat_id']) && $info['cat_id'] !==0 ? made($info['cat_id']):[];
- return app_show(0,"获取成功",$info);
- }
- public function saleout(){
- $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= [];
- $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
- :"";
- if($orderCode !==""){
- $where[]=['orderCode',"like","%$orderCode%"];
- }
- $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
- :"";
- if($apply_name !==""){
- $where[]=['apply_name',"like","%$apply_name%"];
- }
- $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
- if($status !==""){
- $where[]=['status',"=",$status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
- if($start !=""){
- $where[]= ["addtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
- if($end !=""){
- $where[]= ["addtime",'<=',$end];
- }
- $count = Db::name('order_out')->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list= Db::name('order_out')->where($where)->order("addtime desc")->page($page,$size)->select();
- foreach ($list as $value){
- $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c","k.supplierNo=c.code")
- ->where(["k.wsm_code"=>$value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
- $addr = Db::name("order_addr")->where(["id"=>$value['addrid']])->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']:"";
- $value['addr']=isset($addr['addr']) ? $addr['addr']:"";
- $value['contactor']=isset($addr['contactor']) ? $addr['contactor']:"";
- $value['mobile']=isset($addr['mobile']) ? $addr['mobile']:"";
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- public function outinfo(){
- $outCode = isset($this->post['outCode']) && $this->post['outCode']!==""? trim($this->post['outCode']):"";
- if($outCode==""){
- return error_show(1002,"参数outcode不能为空");
- }
- $codeinfo = Db::name("order_out")->where(['outCode'=>$outCode])->select();
- if(empty($codeinfo)){
- return error_show(1002,"未找到出库数据");
- }
- $data=[];
- foreach ($codeinfo as $value) {
- $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
- ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
- $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
- $item = Db::name("sale")->where(['orderCode'=>$value['orderCode']])->find();
- $value['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
- $value['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
- $value['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
- $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'] : "";
- $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
- $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
- $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
- $data[] = $value;
- }
- return app_show(0,"获取成功",$data);
- }
- }
|