123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- <?php
- namespace app\Admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\ProcessOrder;
- use think\App;
- use think\facade\Db;
- //退货单
- class Orderback extends \app\BaseController
- {
- public $post=[];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post =$this->request->post();
- }
- 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]];
- $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
- if($thNo!=""){
- $where[]=['thNo',"like", "%{$thNo}%"];
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status!==""){
- // $where['status'] = $status;
- $where[]=['status',"=", $status];
- }
- $post_code= isset($this->post['post_code']) && $this->post['post_code']!="" ? trim($this->post['post_code']):"";
- if($post_code!=""){
- $where[]=['post_code',"like", "%{$post_code}%"];
- }
- $post_compay = isset($this->post['post_compay']) && $this->post['post_compay']!="" ? trim($this->post['post_compay']):"";
- if($post_compay!=""){
- $where[]=['post_company',"=", $post_compay];
- }
- $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}%"];
- }
- $order_code = isset($this->post['order_code']) && $this->post['order_code']!="" ? trim($this->post['order_code']):"";
- if($order_code!=""){
- $where[]=['orderCode',"like", "%{$order_code}%"];
- }
- $out_code = isset($this->post['out_code']) && $this->post['out_code']!="" ? trim($this->post['out_code']):"";
- if($out_code!=""){
- $where[]=['outCode',"like", "%{$out_code}%"];
- }
- $return_code = isset($this->post['return_code']) && $this->post['return_code']!="" ? trim($this->post['return_code']):"";
- if($return_code!=""){
- $where[]=['returnCode',"like", "%{$return_code}%"];
- }
- $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_back")->where($where)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name("order_back")->where($where)->page($page,$size)->order("addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $value['wsm_name']="";
- $value['wsm_supplier']='';
- $value['wsm_supplierNo']='';
- if($value['return_wsm']!=""){
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
- ->where(["a.wsm_code"=>$value['return_wsm']])->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']:"";
- }
- $value['customer_name']='';
- if($value['customer_code']!=''){
- $customer = Db::name("customer_info")->where(['companyNo'=>$value['customer_code']])->find();
- $value['customer_name']=isset($customer['companyName'])?$customer['companyName']:'';
- }
- $inorder= Db::name("order_backinfo")->where(['thNo'=>$value['thNo'],"is_del"=>0])->select();
- $value['child']=empty($inorder)? [] : $inorder;
- $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 info(){
- $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
- if($thNo==""){
- return error_show(1004,"参数thNo不能为空");
- }
- $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
- $info['origin_price']=$orderinfo['origin_price'];
- $info['sale_price']=$orderinfo['sale_price'];
- $info['order_type']=$orderinfo['order_type'];
- $info['total_price']=$orderinfo['total_price'];
- $info['addr_cn']=GetAddr($info['addr_code']);
- if($orderinfo['order_type']==3|| $orderinfo['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
- }else {
- $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
- }
- if (empty($goon)) {
- return error_show(1003, "未找到商品数据");
- }
- if (empty($goon)) {
- return error_show(1003, "未找到商品数据");
- }
- $retutninfo = Db::name("order_return")->where(['returnCode'=>$info['returnCode']])->find();
- $info['apply_id'] = $retutninfo['apply_id'];
- $info['apply_name'] = $retutninfo['apply_name'];
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $info['wsm_name']="";
- $info['wsm_supplier']='';
- $info['wsm_supplierNo']='';
- if($info['return_wsm']!=""){
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
- ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
- $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
- $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
- $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
- }
- $inorder= Db::name("order_backinfo")->alias("a")->leftJoin("result_info b","a.error_code=b.result_code")
- ->where(['a.thNo'=>$info['thNo'],"a.is_del"=>0])->field("a.*,b.result as error_msg")->select();
- $info['child']=empty($inorder)? [] : $inorder;
- $info['can']=$int;
- return app_show(0,"获取成功",$info);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function check(){
- $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
- if($thNo==""){
- return error_show(1004,"参数thNo不能为空");
- }
- $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $normal = isset($this->post['normal']) && $this->post['normal']!=="" ? intval($this->post['normal']):"";
- if($normal===""){
- return error_show(1004,"参数normal不能为空");
- }
- $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
- if($info['status']== 2){
- return error_show(1002,"退货单已验货");
- }
- $receive=$normal+array_sum(array_column($errorlist,'error_num'));
- $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
- $info['received_num'] = $receive;
- $info['normal_num'] = $normal;
- $info['remark'] = $remark;
- $str = $info['status'];
- $info['status'] =empty($errorlist)?3: 2;
- $info['updatetime'] = date("Y-m-d H:i:s");
- Db::startTrans();
- try{
- $up=Db::name("order_back")->save($info);
- if($up){
- $stn = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",2,$info);
- $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>2,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- if(empty($errorlist)){
- Db::commit();
- return app_show(0,'更新成功');
- }
- foreach($errorlist as $value){
- $data=[];
- isset($value['id'])&&$value['id']!=''?$data['id']=$value['id']:"";
- $data['thNo']=$thNo;
- $data['error_num']=$value['error_num'];
- $data['error_code']=$value['error_code'];
- $data['error_remark']=$value['error_remark'];
- $data['is_del']=isset($value['is_del'])?$value['is_del']:0;
- isset($value['id'])&&$value['id']!=''? "" : $data['addtime']=date("Y-m-d H:i:s");
- $data['updatetime']=date("Y-m-d H:i:s");
- $in = Db::name("order_backinfo")->save($data);
- if(!$in){
- Db::rollback();
- return error_show(1005,'更新失败');
- }
- }
- Db::commit();
- return app_show(0,'更新成功');
- }
- Db::rollback();
- return error_show(1005,'更新失败');
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function CheckExam(){
- $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
- if($thNo==""){
- return error_show(1004,"参数thNo不能为空");
- }
- $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
- Db::startTrans();
- try{
- $temp=$info['status'];
- $info['status'] =3;
- $info['updatetime'] = date("Y-m-d H:i:s");
- $up=Db::name("order_back")->save($info);
- if($up){
- $stn = ["order_code"=>$thNo,"status"=>$temp,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
- $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>3,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- if(empty($errorlist)){
- $up =Db::name("order_backinfo")->where(["thNo"=>$thNo,"is_del"=>0])->save(["status"=>1,
- "updatetime"=>date("Y-m-d H:i:s")]);
- if($up){
- Db::commit();
- return app_show(0,'更新成功');
- }else{
- Db::rollback();
- return error_show(1005,'异常记录数据更新失败');
- }
- }else{
- foreach($errorlist as $value){
- $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
- if(empty($temp)){
- Db::rollback();
- return error_show(1005,'异常记录数据未找到');
- }
- $temp['status']=$value['status'];
- $temp['exam_remark']=$value['remark'];
- $temp['updatetime']=date("Y-m-d H:i:s");
- $com = Db::name("order_backinfo")->save($temp);
- if($com==false){
- Db::rollback();
- return error_show(1005,'异常记录数据更新失败');
- }
- }
- Db::commit();
- return app_show(0,'更新成功');
- }
- }
- Db::rollback();
- return error_show(1005,'更新失败');
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function Exam(){
- $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
- if($thNo==""){
- return error_show(1004,"参数thNo不能为空");
- }
- $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
- if($status===""){
- return error_show(1004,"参数status不能为空");
- }
- $return_wsm=isset($this->post["return_wsm"])&&$this->post["return_wsm"]!=""?trim($this->post["return_wsm"]):"";
- $normal_num=isset($this->post["normal_num"])&&$this->post["normal_num"]!=""?intval($this->post["normal_num"])
- :"";
- $defective_wsm=isset($this->post["defective_wsm"])&&$this->post["defective_wsm"]!=""?trim($this->post["defective_wsm"]):"";
- $defective_num=isset($this->post["defective_num"])&&$this->post["defective_num"]!==""?intval($this->post["defective_num"]):"";
- $loss_num=isset($this->post["loss_num"])&&$this->post["loss_num"]!=""?intval($this->post["loss_num"]):"";
- if($status==4){
- if($defective_num===""){
- return error_show(1004,"参数defective_num不能为空");
- }
- if($loss_num===""){
- return error_show(1004,"参数loss_num不能为空");
- }
- if($normal_num===""){
- return error_show(1004,"参数normal_num不能为空");
- }
- if($defective_wsm===""){
- return error_show(1004,"参数defective_wsm不能为空");
- }
- if($return_wsm===""){
- return error_show(1004,"参数return_wsm不能为空");
- }
- $info['return_wsm']=$return_wsm;
- $info['loss_num']=$loss_num;
- $info['normal_num']=$normal_num;
- $info['defective_wsm']=$defective_wsm;
- $info['defective_num']=$defective_num;
- }
- $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
- Db::startTrans();
- try{
- $var = $info['status'];
- $info['status'] =$status;
- $info['remark'] =$remark;
- $info['updatetime'] = date("Y-m-d H:i:s");
- $up=Db::name("order_back")->save($info);
- if($up){
- $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
- $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
- ProcessOrder::AddProcess($this->post['token'],$process);
- Db::commit();
- return app_show(0,'更新成功');
- }
- Db::rollback();
- return error_show(1005,'更新失败');
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- }
|