123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\ProcessOrder;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- //采购单退货
- class Purchback extends Base
- {
- //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']):"";
- $returnCode=makeNo("CT");
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !==""? trim($this->post['cgdNo']) :"";
- if($cgdNo==""){
- return error_show(1002,"参数cgdNo不能为空");
- }
- $cg = Db::name('purchease_order')->where(['cgdNo'=>$cgdNo,'is_del'=>0])->find();
- if($cg==""){
- return error_show(1002,"未找到采购单数据");
- }
- $gd= Db::name('good_basic')->where(['spuCode'=>$cg['good_code']])->find();
- if($gd==""){
- return error_show(1002,"未找到商品数据");
- }
- // $int= isset($gd['cat_id']) && $gd['cat_id'] !=0 ? made($gd['cat_id']):[];
- $return_num = isset($this->post['return_num']) && $this->post['return_num'] !=="" ? trim($this->post['return_num']):"";
- if($return_num==""){
- return error_show(1002,"参数return_num不能为空");
- }
- $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'] : "";
- $good_total = $return_num*$cg['good_price'];
- // $post_company = isset($this->post['post_company']) && $this->post['post_company'] !==""? trim($this->post['post_company']) :"";
- // $post_code =isset($this->post['post_code']) && $this->post['post_code'] !==""? trim($this->post['post_code']) :"";
- // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !==""? intval($this->post['post_fee']):"";
- // $status= isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']) :"";
- $remark =isset($this->post['remark']) && $this->post['remark'] !==""? trim($this->post['remark']) :"";
- $data = [
- "returnCode"=>$returnCode,
- "cgdNo"=>$cgdNo,
- "good_code"=>$cg['good_code'],
- "return_num"=>$return_num,
- "good_name"=>$cg['good_name'],
- "good_price"=>$cg['good_price'],
- "good_catid"=>$gd['cat_id'],
- "apply_name"=>$rname,
- "apply_id"=>$rid,
- "good_total"=>$good_total,
- "post_company"=>"",
- "post_code"=>"",
- "post_fee"=>"",
- "status"=>1,
- "remark"=>$remark,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- //$data['can'] = $int;
- $pd = Db::name('purchease_back')->insert($data,true);
- if($pd>0){
- $sto = ["order_code"=>$returnCode,"status"=>1,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$sto,"CGTHD",1,$sto);
- $process=["order_code"=>$returnCode,"order_id"=>$pd,"order_status"=>1,"order_type"=>'CGTHD',"before_status"=>1];
- ProcessOrder::AddProcess($this->post['token'],$process);
- return error_show(0,"新建成功");
- }else{
- return error_show(1002,"新建失败");
- }
- }
- 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 = [['a.is_del',"=",0],['b.is_del',"=",0]];
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo']):"";
- if($cgdNo!=""){
- $where[]=['a.cgdNo',"like", "%$cgdNo%"];
- }
- $returnCode= isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($returnCode!=""){
- $where[]=['a.returnCode',"like", "%$returnCode%"];
- }
- $good_type_code=isset($this->post['good_type_code']) && $this->post['good_type_code']!==""? trim($this->post['good_type_code']):"";
- if($good_type_code !=""){
- $where[]= ["b.spuCode",'like',"%$good_type_code%"];
- }
- $good_name=isset($this->post['good_name']) && $this->post['good_name']!==""? trim($this->post['good_name']):"";
- if($good_name !=""){
- $where[]= ["b.good_name",'like',"%$good_name%"];
- }
- $status=isset($this->post['status']) && $this->post['status']!==""? trim($this->post['status']):"";
- if($status!=""){
- $where[]= ["a.status",'=',$status];
- }
- $count = Db::name('purchease_back')->alias('a')->join("purchease_order b","b.cgdNo=a.cgdNo","left")
- ->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('purchease_back')->alias('a')->join("purchease_order b","b.cgdNo=a.cgdNo","left")
- ->where($where)->page($page,$size)
- ->field("a.returnCode,b.spuCode,a.good_catid,a.return_num,a.good_price,a.good_total,
- a.post_company,a.post_fee,a.status,a.cgdNo,b.good_name,b.order_type")->order("a.addtime desc")->select();
- $data=[];
- foreach ($list as $value){
- $value['can']= isset($value['good_catid']) && $value['good_catid'] !=0 ? made($value['good_catid']):[];
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
- }
- public function status(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $dio = Db::name('purchease_back')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($dio)){
- return error_show(1002,"退货订单未找到");
- }
- $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
- if($returnCode==""){
- return error_show(1002,"参数returnCode不能为空");
- }
- $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
- if($status===""){
- return error_show(1001,'status不能为空');
- }
- $temp= $dio['status'];
- $dio['status']=$status;
- $dio['updatetime']=date("Y-m-d H:i:s");
- $str = Db::name("purchease_back")->update($dio);
- if($str){
- $sto = ["order_code"=>$id,"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$sto,"CGTHD",$dio['status'],$sto);
- $process=["order_code"=>$returnCode,"order_id"=>$dio['id'],"order_status"=>$status,"order_type"=>'CGTHD',"before_status"=>1];
- ProcessOrder::AddProcess($this->post['token'],$process);
- return error_show(0,"更新成功");
- }else{
- return error_show(1002,"更新失败");
- }
- }
- public function backfe(){
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
- if($id==""){
- return error_show(1002,"参数id不能为空");
- }
- $dio = Db::name('purchease_back')->where(['id'=>$id,'is_del'=>0])->find();
- if(empty($dio)){
- return error_show(1002,"退货订单未找到");
- }
- $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
- if($returnCode==""){
- return error_show(1002,"参数returnCode不能为空");
- }
- $post_company = isset($this->post['post_company']) && $this->post['post_company'] !==""? trim($this->post['post_company']) :"";
- if($post_company==""){
- return error_show(1002,"参数post_company 不能为空");
- }
- $post_code = isset($this->post['post_code']) && $this->post['post_code'] !==""? trim($this->post['post_code']) :"";
- if($post_code==""){
- return error_show(1002,"参数post_code不能为空");
- }
- $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !==""? trim($this->post['post_fee']) :"";
- if($post_fee==""){
- return error_show(1002,"参数post_fee不能为空");
- }
- $data=[
- "id"=>$id,
- "returnCode"=>$returnCode,
- "post_company"=>$post_company,
- "post_code"=>$post_code,
- "post_fee"=>$post_fee,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $datainfo=Db::name('purchease_back')->save($data);
- if($datainfo){
- $sto = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$sto,"BKD",0,$sto);
- $process=["order_code"=>$returnCode,"order_id"=>$dio['id'],"order_status"=>$dio['status'],"order_type"=>'CGTHD',"before_status"=>1];
- ProcessOrder::AddProcess($this->post['token'],$process);
- return error_show(0,"更新成功");
- }else{
- return error_show(1002,"更新失败");
- }
- //return $datainfo ? error_show(0,"更新成功") : error_show(1002,"更新失败");
- }
- public function info(){
- $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
- if($returnCode==""){
- return error_show(1002,"参数returnCode不能为空");
- }
- $info= Db::name("purchease_return")->where(['returnCode'=>$returnCode])->find();
- if(empty($info)){
- return error_show(1002,"未找到数据");
- }
- $dom = Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],'is_del'=>0])->find();
- if($dom['order_type']==3 ||$dom['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$dom['spuCode'],"is_del"=>0])->find();
- }else {
- $goon =Db::name('good_basic')->where(['spuCode'=>$dom['spuCode']])->find();
- }
- if(empty($goon)){
- return error_show(1002,"未找到商品数据");
- }
- $userCommon=\app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>$dom['supplierNo']]);
- // $supplier=Db::name("supplier")->where(["code"=>$dom['supplierNo']])->find();
- $int= isset($goon['cat_id']) && $goon['cat_id'] !=0 ? made($goon['cat_id']):[];
- //$info['good'] = isset($wsmcode['good_name']) ? $wsmcode['good_name'] : "";
- $info['good_num'] = isset($dom['good_num']) ? $dom['good_num'] : "";
- $info['spuCode'] = isset($dom['spuCode']) ? $dom['spuCode'] : "";
- $info['good_name'] = isset($dom['good_name']) ? $dom['good_name'] : "";
- $info['good_price'] = isset($dom['good_price']) ? $dom['good_price'] : "";
- $info['return_price'] = round($info['good_price']*$info['return_num'],2);
- $info['wsm_supplier'] = $names['data'][$dom['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
- $info['wsm_supplierNo'] = $dom['supplierNo'];
- $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 delete(){
- $returnCode = isset($this->post['returnCode']) && $this->post['returnCode'] !==""? trim($this->post['returnCode']) :"";
- if($returnCode==""){
- return error_show(1002,"参数returnCode不能为空");
- }
- $info= Db::name("purchease_back")->where(['returnCode'=>$returnCode,"is_del"=>0])->find();
- if(empty($info)){
- return error_show(1002,"未找到数据");
- }
- $del = Db::name("purchease_back")->where(['returnCode'=>$returnCode])->save(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($del){
- $sto = ["order_code"=>$returnCode,"status"=>$info['status'],"action_remark"=>'',"action_type"=>"delete"];
- ActionLog::logAdd($this->post['token'],$sto,"CGTHD",0,["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- $process=["order_code"=>$returnCode,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'CGTHD'];
- ProcessOrder::workdel($process);
- return error_show(0,"删除成功");
- }else{
- return error_show(1002,"删除失败");
- }
- }
- }
|