123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- <?php
- namespace app\admin\controller;
- use think\facade\Db;
- use think\facade\Validate;
- use think\App;
- class InterOrder extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function list(){
- $param = $this->request->only(["page"=>1,"size"=>10,'cgdNo'=>"","qrdNo"=>"","khNo"=>"","platform_type"=>"",
- "supplierNo"=>"","companyNo"=>"","starttime"=>"","endtime"=>"","sale_name"=>"","cgd_saler"=>""],"post","trim");
- $where=[["b.is_del","=",0],["c.is_del","=",0],["b.qrdSource","=",10],["c.cgdSource","=",10]];
- $check = checkRole($this->roleid,143);
- if($check){
- $where[]=["a.apply_id","=",$this->uid];
- }
- if($param['cgdNo']!="") $where[]=["a.cgdNo","like","%{$param['cgdNo']}%"];
- if($param['qrdNo']!="") $where[]=["a.orderCode","like","%{$param['qrdNo']}%"];
- if($param['khNo']!="") $where[]=["b.customerNo","like","%{$param['khNo']}%"];
- if($param['companyNo']!="") $where[]=["b.companyNo","like","%{$param['companyNo']}%"];
- if($param['supplierNo']!="") $where[]=["c.supplierNo","like","%{$param['supplierNo']}%"];
- if($param['starttime']!="") $where[]=["a.addtime",">=",date("Y-m-d 00:00:00",strtotime($param['starttime']))];
- if($param['endtime']!="") $where[]=["a.addtime","<=",date("Y-m-d 23:59:59",strtotime($param['endtime']))];
- if($param['sale_name']!="") $where[]=["b.ownerName","like","%{$param['sale_name']}%"];
- if($param['cgd_saler']!="") $where[]=["c.ownerName","like","%{$param['cgd_saler']}%"];
- if($param['platform_type']!=="") $where[]=["b.platform_type","=",$param['platform_type']];
- $count= Db::name("inter_order")
- ->alias("a")
- ->leftJoin("qrd_info b","a.orderCode=b.sequenceNo and b.is_del=0 and b.qrdSource=10")
- ->leftJoin("cgd_info c","b.cgdNo=c.sequenceNo and c.is_del=0 and c.cgdSource=10")
- ->where($where)
- ->count('a.id');
- $total =ceil($count/$param['size']);
- $page =$total>=$param['page'] ? intval($param['page']): intval($total);
- $list= Db::name("inter_order")
- ->alias("a")
- ->leftJoin("qrd_info b","a.orderCode=b.sequenceNo and b.is_del=0 and b.qrdSource=10")
- ->leftJoin("cgd_info c","b.cgdNo=c.sequenceNo and c.is_del=0 and c.cgdSource=10")
- ->field("a.id,
- a.orderCode,
- a.platform_id,
- b.platName,
- b.platform_type,
- b.customerName as khName,
- b.customerNo as khNo,
- b.companyName,
- b.companyNo,
- a.rate*100 as cgd_tax,
- c.supplierName,
- c.supplierNo,
- b.poCode,
- a.addtime as ordertime,
- b.ownerName as sale_name,
- c.ownerName as cgd_saler,
- c.department as cgd_depart,
- b.department as sale_depart,
- b.goodName,
- b.tax,
- b.goodPrice,
- b.goodNum,
- b.totalPrice,
- b.apay_fee,
- b.wpay_fee,
- b.ainv_fee,
- b.winv_fee,
- b.qrdType,
- b.catInfo,
- a.cgdNo,
- b.workCode")
- ->json(["catInfo"])
- ->where($where)->page($page,intval($param['size']))->order("id desc")
- ->select()->toArray();
- // echo Db::name("inter_order")->getLastSql();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function create(){
- $param =$this->request->only([
- "sale_name"=>"","sale_id"=>"","companyNo"=>'',"poCode"=>"","workCode"=>"","khNo"=>"","qrdType"=>"","goodName"=>"",
- "tax"=>"","goodNum"=>"","goodPrice"=>"","mobile"=>"","addr"=>"","contactor"=>"","platform_id"=>"0",
- "buyer"=>"","buyerid"=>"","sendtime"=>"","cat"=>'',"supplierNo"=>"","cgd_tax"=>"","sale_depart"=>"","cgd_depart"=>""
- ],"post");
- $valid =Validate::rule([
- "sale_name|业务员名称"=>"require|max:255|min:1",
- "sale_id|业务员名称"=>"require|number|gt:0",
- "companyNo|业务公司编号"=>"require|max:255|min:1",
- "supplierNo|业务公司编号"=>"require|max:255|min:1",
- "poCode|PO编号"=>"require|max:255|min:1",
- "platform_id|平台id"=>"require|number",
- "workCode|单据编号"=>"require|max:255|min:1",
- "khNo|客户公司编号"=>"require|max:255|min:1",
- "qrdType|订单类型"=>"require|number|in:[1,2,3]",
- "goodName|商品名称"=>"require|max:255|min:1",
- "tax|税率"=>"require|number|gt:0",
- "goodNum|商品数量"=>"require|number|gt:0",
- "goodPrice|商品单价"=>"require|float|gt:0",
- "mobile|联系人电话"=>"require|number|mobile",
- "contactor|联系人"=>"require|max:255|min:1",
- "addr|收货地址"=>"require|max:255|min:1",
- "buyer|销售员"=>"require|max:255|min:1",
- "buyerid|销售员"=>"require|number|gt:0",
- "sendtime|发货时间"=>"require|date",
- "cat|商品分类id"=>"require|number|gt:0",
- "cgd_tax|采购毛利率"=>"require|float|gt:0",
- // "sale_depart|销售员部门"=>"require|max:255|min:1",
- // "cgd_depart|采购员部门"=>"require|max:255|min:1",
- ]);
- if($valid->check($param)==false)return error_show(1004,$valid->getError());
- $qrdcode =makeNo("QRD");
- $cgddcode =makeNo("CGD");
- $goodCode =makeNo("SPU");
- $customer =Db::name("customer_info")->where('companyNo', "=", $param['khNo'])->find();
- $supplierName =Db::name("supplier_info")->where('code', "=", $param['supplierNo'])->value("name","");
- $companyName =Db::name("supplier_info")->where('code', "=", $param['companyNo'])->value("name","");
- $taxinfo = Db::name("order_rate")->where(["id"=>$param["tax"],"status"=>1])->value("rate",0);
- $param["cgd_tax"]=$param["cgd_tax"]/100;
- $platform=[];
- if($param['platform_id']!=0){
- $platform = $this->platform($param['platform_id']);
- if(empty($platform)) return error_show(1004,'平台信息未找到');
- if($platform['is_select_pay_rate']==1) return error_show(1004,'平台带有支付渠道不可选');
- }
- $depart_uid =[$param['sale_id'],$param['buyerid']];
- $depart= UserHandle("get_company_name_by_uid",["uid"=>$depart_uid]);
- if(!isset($depart['code'])||$depart['code']!=0 || empty($depart['data'])){
- return error_show(1004,'采购员或销售员部门未找到!');
- }
- $departByUid =$depart["data"]??[];
- $cat = [];
- $this->cat($param['cat'],$cat);
- if(empty($cat)) return error_show(1004,'分类信息为找到');
- $inter=[
- "cgdNo"=>$cgddcode,
- "orderCode"=>$qrdcode,
- "rate"=>$param["cgd_tax"],
- "platform_id"=>$param["platform_id"],
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "mobile"=>$param['mobile'],
- "contactor"=>$param['contactor'],
- "sendtime"=>$param['sendtime'],
- "addr"=>$param['addr'],
- ];
- $qrd =[
- 'name' => $param['sale_depart']."销售单",//确认单名称,
- 'sequenceNo' => $qrdcode,//确认单编号,
- 'ownerName' => $param['sale_name'],//销售员,
- 'ownerid' => $param['sale_id'],//销售员id,
- 'department' => $departByUid[$param['sale_id']]??'',//部门,
- 'createdTime' => date("Y-m-d H:i:s"),//销售单创建时间,
- 'qrdType' => $param['qrdType'],//销售单类型,
- 'qrdSource' => 10,//销售单来源,
- 'companyNo' => $param['companyNo'],//业务企业编号,
- 'companyName' => $companyName,//业务企业名称,
- 'customerNo' => $param['khNo'],//客户编号,
- 'customerName' =>$customer['companyName']??"",//客户名称,
- 'poCode' => $param['poCode'],//po编号,
- 'platName' => $platform['platform_name']??"",//平台名称,
- 'platform_type' => $platform['use_type']??"0",//平台类型,
- 'workCode' =>$param['workCode'],//业务编号,
- 'zxCode' => '',//咨询单编号,
- 'goodNo' => $goodCode,//商品编号,
- 'goodName' => $param['goodName'],//商品名称,
- 'goodBrand' =>'',//商品品牌,
- 'firstCat' => $cat[0]['cat_name']??"",//一级分类,
- 'secCat' => $cat[1]['cat_name']??"",//二级分类,
- 'thirdCat' => $cat[2]['cat_name']??"",//三级分类,
- 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类详情,
- 'fundCode' => $cat[2]['fund_code']??"",//核算编码,
- 'goodMaterial' => '',//商品材质,
- 'goodUnit' => '',//商品单位,
- 'goodDesc' => '',//工艺说明,
- 'goodType' =>1,//商品类型,
- 'goodModel' => '',//商品型号,
- 'isStock' => 0,//是否库存品,
- 'metalsType' =>'',//贵金属种类,
- 'weight' => 0,//商品重量,
- 'goldPrice' => 0,//贵金属单价,
- 'deliveryDay' =>'',//物流天数,
- 'workDay' => '',//工期,
- 'tax' => $taxinfo,//税率,
- 'goodNum' => $param['goodNum'],//销售数量,
- 'goodPrice' => $param['goodPrice'],//产品单价,
- 'totalPrice' =>round( $param['goodPrice']*$param['goodNum'],2),//货款总额,
- 'sendNum' => $param['goodNum'],//已发货数量,
- 'wsendNum' => 0,//未发货数量,
- 'apay_fee' => 0,//已付款,
- 'pay_fee' => 0,//付款中
- 'wpay_fee' => round( $param['goodPrice']*$param['goodNum'],2),
- 'inv_fee' => 0,//回票中
- 'ainv_fee' => 0,//已开票,
- 'winv_fee' =>round( $param['goodPrice']*$param['goodNum'],2),
- 'is_diff' =>0,//是否有工差,
- 'sendType' => 1,//发货方式,
- 'sendStatus' =>3,//发货状态,
- 'pay_status' =>1,//收款状态,1未付,2部分,3完结
- 'inv_status' => 1,//开票状态,,1未付,2部分,3完结
- 'remark' => '',//备注,
- 'diff_weight' =>0,//工差重量,
- 'diff_fee' =>0,//工差金额,
- 'area' =>$customer['companyName']??"",//公司,
- 'customerAttr' => $customer['parent']??"",//客户属性,
- 'branch' => $customer['branch']??"",//分公司,从客户表中查
- 'cgdNo' => $cgddcode,//采购单号,
- 'thNum' => 0,//退货数量,
- 'th_fee' => 0,//退货金额,
- 'is_del' => 0,//是否删除,
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' =>date("Y-m-d H:i:s"),
- 'inv_tag' => 0,//开票标签,
- 'pay_tag' => 0,//回款标签,
- 'inv_tag_fee' => 0,//开票票标签金额,
- 'pay_tag_fee' => 0,//回款标签金额,
- ];
- $cgd=[
- 'name' => $param['cgd_depart']."采购单",//采购单名称',
- 'sequenceNo' => $cgddcode,//采购单编号',
- 'ownerName' => $param['buyer'],//采购员名称',
- 'ownerid' => $param['buyerid'],//采购员id',
- 'department' => $departByUid[$param['buyerid']]??'',//部门名称',
- 'createdTime' => date("Y-m-d H:i:s"),//订单创建时间',
- 'cgdType' =>$param['qrdType'],//采购单类型',
- 'cgdSource' =>10,//采购单来源',
- 'companyNo' => $param['companyNo'],//业务公司编号',
- 'companyName' => $companyName,//业务公司',
- 'cgdTime' => date("Y-m-d H:i:s"),//采购下单时间',
- 'bkCode' => '',//备库单编号',
- 'qrdCode' => $qrdcode,//确认单编号',
- 'goodNo' => $goodCode,//商品编号',
- 'goodName' => $param['goodName'],//商品名称',
- 'goodType' => 1,//商品类型',
- 'goodBrand' =>'',//商品品牌',
- 'goodModel' => '',//商品型号',
- 'firstCat' => $cat[0]['cat_name']??"",//商品一级分类',
- 'secCat' => $cat[1]['cat_name']??"",//二级分类',
- 'thirdCat' => $cat[2]['cat_name']??"",//三级分类',
- 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类明细',
- 'fundCode' => $cat[2]['fund_code']??"",//NOT NULL,
- 'goodMaterial' => '',//商品材质',
- 'goodUnit' => '',//商品单位',
- 'goodDesc' => '',//工艺说明',
- 'metalsType' => '',//贵金属种类',
- 'weight' => 0,//商品重量',
- 'goldPrice' => 0,//贵金属实时金价',
- 'is_diff' =>0,//是否有工差',
- 'deliveryDay' =>'',//物流天数',
- 'workDay' =>'',//产品工期',
- 'tax' => $taxinfo,//税点',
- 'barePrice' => 0,//裸价',
- 'markPrice' => 0,//加标费',
- 'packPrice' => 0,//包装费',
- 'certPrice' => 0,//证书费',
- 'openPrice' => 0,//开模费',
- 'costPrice' => 0,//工艺费',
- 'deliveryPrice' =>0,//物流费',
- 'goodPrice' => round( $param['goodPrice']*(1-$param['cgd_tax']),2),//成本合计/单价',
- 'isStock' =>0,//是否库存品',
- 'goodNum' => $param['goodNum'],//下单数量',
- 'totalPrice' => round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
- 'supplierNo' => $param['supplierNo'],//供应商编号',
- 'supplierName' => $supplierName,//供应商名称',
- 'apay_fee' => 0,//已付款金额',
- 'wpay_fee' =>round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
- 'ainv_fee' => 0,//已开票金额',
- 'winv_fee' =>round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
- 'sendType' => 1,//发货方式',
- 'bkCreater' => '',//备库申请人',
- 'sendStatus' => 3,//发货状态',
- 'wsendNum' =>0,//未发货数量',
- 'sendNum' => $param['goodNum'],//已发货数量',
- 'wareHouse' => '',//仓库名称',
- 'wsmCode' =>'',//仓库编号',
- 'remark' => '',//备注',
- 'pay_status' =>1,//付款情况',
- 'inv_status' => 1,//开票情况',
- 'diff_weight' => 0,//工差重量',
- 'diff_fee' => 0,//工差金额',
- 'thNum' => 0,//退货数量',
- 'th_fee' => 0,//退货金额',
- 'check_rate' => '',//修正后的税率',
- 'is_del' => 0,
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' => date("Y-m-d H:i:s"),
- ];
- $good=[
- "spuCode"=>$goodCode,
- "good_name"=>$param['goodName'],
- "companyNo"=>$param['companyNo'],
- "supplierNo"=>$param['supplierNo'],
- "is_stock"=>0,
- "craft_desc"=>'',
- "after_sales"=>'',
- "good_img"=>'',
- "good_thumb_img"=>'',
- "good_info_img"=>'',
- "creater"=>$this->uname,
- "createrid"=>$this->uid,
- "cat_name"=>$cat[2]['cat_name'],
- "unit_name"=>'',
- "isZx"=>0,
- "status"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- try {
- $a = Db::name("qrd_info")->insert($qrd);
- $d = Db::name("inter_order")->insert($inter);
- $b = Db::name('cgd_info')->insert($cgd);
- $c = Db::name('good')->insert($good);
- if ($a && $b && $c&&$d) {
- Db::commit();
- return app_show(0,'新建成功');
- } else {
- Db::rollback();
- return error_show(1004,'新建失败');
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- public function save(){
- $param =$this->request->only([
- "sale_name"=>"","sale_id"=>"","companyNo"=>'',"poCode"=>"","workCode"=>"","khNo"=>"","qrdType"=>"","goodName"=>"",
- "tax"=>"","goodNum"=>"","goodPrice"=>"","good_total"=>"","mobile"=>"","addr"=>"","contactor"=>"","id"=>"","platform_id"=>0,
- "buyer"=>"","buyerid"=>"","sendtime"=>"","cat"=>'',"supplierNo"=>"","cgd_tax"=>"","sale_depart"=>"","cgd_depart"=>""
- ],"post");
- $valid =Validate::rule([
- "id|主键ID"=>"require|number|gt:0",
- "sale_name|业务员名称"=>"require|max:255|min:1",
- "sale_id|业务员名称"=>"require|number|gt:0",
- "companyNo|业务公司编号"=>"require|max:255|min:1",
- "supplierNo|业务公司编号"=>"require|max:255|min:1",
- "platform_id|平台id"=>"require|number",
- "poCode|PO编号"=>"require|max:255|min:1",
- "workCode|单据编号"=>"require|max:255|min:1",
- "khNo|客户公司编号"=>"require|max:255|min:1",
- "qrdType|订单类型"=>"require|number|in:[1,2,3]",
- "goodName|商品名称"=>"require|max:255|min:1",
- "tax|税率"=>"require|number|gt:0",
- "goodNum|商品数量"=>"require|number|gt:0",
- "goodPrice|商品单价"=>"require|float|gt:0",
- "mobile|联系人电话"=>"require|number|mobile",
- "contactor|联系人"=>"require|max:255|min:1",
- "addr|收货地址"=>"require|max:255|min:1",
- "buyer|销售员"=>"require|max:255|min:1",
- "buyerid|销售员"=>"require|number|gt:0",
- "sendtime|发货时间"=>"require|date",
- "cat|商品分类"=>"require|number|gt:0",
- "cgd_tax|采购毛利率"=>"require|float|gt:0",
- // "sale_depart|销售员部门"=>"require|max:255|min:1",
- // "cgd_depart|采购员部门"=>"require|max:255|min:1",
- ]);
- if($valid->check($param)==false)return error_show(1004,$valid->getError());
- $inter_order=Db::name("inter_order")->where(["id"=>$param['id']])->findOrEmpty();
- if(empty($inter_order)) return error_show(1004,"未找到订单数据");
- $qrd_order=Db::name("qrd_info")->where(["sequenceNo"=>$inter_order['orderCode']])->findOrEmpty();
- if(empty($qrd_order)) return error_show(1004,"未找到销售单数据");
- $cgd_order=Db::name("cgd_info")->where(["sequenceNo"=>$inter_order['cgdNo']])->findOrEmpty();
- if(empty($cgd_order)) return error_show(1004,"未找到采购单数据");
- $goodinfo=Db::name("good")->where(["spuCode"=>$qrd_order['goodNo']])->findOrEmpty();
- if(empty($goodinfo)) return error_show(1004,"未找到商品数据");
- $param["cgd_tax"]=$param["cgd_tax"]/100;
- $customer =Db::name("customer_info")->where('companyNo', "=", $param['khNo'])->find();
- $supplierName =Db::name("supplier_info")->where('code', "=", $param['supplierNo'])->value("name","");
- $companyName =Db::name("supplier_info")->where('code', "=", $param['companyNo'])->value("name","");
- $taxinfo = Db::name("order_rate")->where(["id"=>$param["tax"],"status"=>1])->value("rate",0);
- $platform=[];
- if($param['platform_id']!=0){
- $platform = $this->platform($param['platform_id']);
- if(empty($platform)) return error_show(1004,'平台信息未找到');
- if($platform['is_select_pay_rate']==1) return error_show(1004,'平台带有支付渠道不可选');
- }
- $depart_uid =[$param['sale_id'],$param['buyerid']];
- $depart= UserHandle("get_company_name_by_uid",["id"=>$depart_uid]);
- if(!isset($depart['code'])||$depart['code']!=0 || empty($depart['data'])){
- return error_show(1004,'采购员或销售员部门未找到!');
- }
- $departByUid =$depart["data"]??[];
- $cat = [];
- if($qrd_order['status']!=0) return error_show(1004,"销售单已对账,无法修改");
- if($cgd_order['status']!=0) return error_show(1004,"采购单已对账,无法修改");
- $this->cat($param['cat'],$cat);
- if(empty($cat)) return error_show(1004,'分类信息为找到');
- $inter=[
- "id"=>$inter_order['id'],
- "rate"=>$param["cgd_tax"],
- "mobile"=>$param['mobile'],
- "contactor"=>$param['contactor'],
- "platform_id"=>$param["platform_id"],
- "addr"=>$param['addr'],
- "sendtime"=>$param['sendtime'],
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $qrd =["id"=>$qrd_order['id'],
- 'name' => $param['sale_depart']."销售单",//确认单名称,
- 'ownerName' => $param['sale_name'],//销售员,
- 'ownerid' => $param['sale_id'],//销售员id,
- 'department' => $departByUid[$param['sale_id']]??'',//部门,
- 'qrdType' => $param['qrdType'],//销售单类型,
- 'companyNo' => $param['companyNo'],//业务企业编号,
- 'companyName' => $companyName,//业务企业名称,
- 'customerNo' => $param['khNo'],//客户编号,
- 'customerName' =>$customer['companyName']??"",//客户名称,
- 'poCode' => $param['poCode'],//po编号,
- 'workCode' =>$param['workCode'],//业务编号,
- 'platName' => $platform['platform_name']??"",//平台名称,
- 'platform_type' => $platform['use_type']??"0",//平台类型,
- 'goodName' => $param['goodName'],//商品名称,
- 'firstCat' => $cat[0]['cat_name']??"",//一级分类,
- 'secCat' => $cat[1]['cat_name']??"",//二级分类,
- 'thirdCat' => $cat[2]['cat_name']??"",//三级分类,
- 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类详情,
- 'fundCode' => $cat[2]['fund_code']??"",//核算编码,
- 'tax' => $taxinfo,//税率,
- 'goodNum' => $param['goodNum'],//销售数量,
- 'goodPrice' => $param['goodPrice'],//产品单价,
- 'totalPrice' =>round( $param['goodPrice']*$param['goodNum'],2),//货款总额,
- 'sendNum' => $param['goodNum'],//已发货数量,
- 'wpay_fee' => round( $param['goodPrice']*$param['goodNum'],2),
- 'winv_fee' =>round( $param['goodPrice']*$param['goodNum'],2),
- 'area' =>$customer['companyName']??"",//公司,
- 'customerAttr' => $customer['parent']??"",//客户属性,
- 'branch' => $customer['branch']??"",//分公司,从客户表中查
- 'updatetime' =>date("Y-m-d H:i:s"),
- ];
- $cgd=["id"=>$cgd_order['id'],
- 'name' => $param['cgd_depart']."采购单",//采购单名称',
- 'ownerName' => $param['buyer'],//采购员名称',
- 'ownerid' => $param['buyerid'],//采购员id',
- 'department' => $departByUid[$param['buyerid']]??'',//部门名称',
- 'cgdType' =>$param['qrdType'],//采购单类型',
- 'companyNo' => $param['companyNo'],//业务公司编号',
- 'companyName' => $companyName,//业务公司',
- 'goodName' => $param['goodName'],//商品名称',
- 'firstCat' => $cat[0]['cat_name']??"",//商品一级分类',
- 'secCat' => $cat[1]['cat_name']??"",//二级分类',
- 'thirdCat' => $cat[2]['cat_name']??"",//三级分类',
- 'catInfo' => json_encode($cat,JSON_UNESCAPED_UNICODE),//分类明细',
- 'fundCode' => $cat[2]['fund_code']??"",//NOT NULL,
- 'tax' => $taxinfo,//税点',
- 'goodPrice' => round( $param['goodPrice']*(1-$param['cgd_tax']),2),//成本合计/单价',
- 'goodNum' => $param['goodNum'],//下单数量',
- 'totalPrice' => round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
- 'supplierNo' => $param['supplierNo'],//供应商编号',
- 'supplierName' => $supplierName,//供应商名称',
- 'wpay_fee' =>round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
- 'winv_fee' =>round( $param['goodNum']*$param['goodPrice']*(1-$param['cgd_tax']),2),//采购总货款',
- 'sendNum' => $param['goodNum'],//已发货数量',
- 'updatetime' => date("Y-m-d H:i:s"),
- ];
- $good=[
- "id"=>$goodinfo['id'],
- "good_name"=>$param['goodName'],
- "companyNo"=>$param['companyNo'],
- "supplierNo"=>$param['supplierNo'],
- "cat_name"=>$cat[2]['cat_name'],
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- try {
- $a = Db::name("qrd_info")->save($qrd);
- $d = Db::name("inter_order")->save($inter);
- $b = Db::name('cgd_info')->save($cgd);
- $c = Db::name('good')->save($good);
- if ($a && $b && $d &&$c) {
- Db::commit();
- return app_show(0,'更新成功');
- } else {
- Db::rollback();
- return error_show(1004,'更新失败');
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- // "id|主键ID"=>"require|number|gt:0",
- // "sale_name|业务员名称"=>"require|max:255|min:1",
- // "sale_id|业务员名称"=>"require|number|gt:0",
- // "companyNo|业务公司编号"=>"require|max:255|min:1",
- // "supplierNo|业务公司编号"=>"require|max:255|min:1",
- // "poNo|PO编号"=>"require|max:255|min:1",
- // "sequenceNo|单据编号"=>"require|max:255|min:1",
- // "khNo|客户公司编号"=>"require|max:255|min:1",
- // "qrdType|订单类型"=>"require|number|in:[1,2,3]",
- // "goodName|商品名称"=>"require|max:255|min:1",
- // "tax|税率"=>"require|number|gt:0",
- // "goodNum|商品数量"=>"require|number|gt:0",
- // "goodPrice|商品单价"=>"require|number|gt:0",
- // "mobile|联系人电话"=>"require|number|mobile",
- // "contactor|联系人"=>"require|max:255|min:1",
- // "addr|收货地址"=>"require|max:255|min:1",
- // "buyer|销售员"=>"require|max:255|min:1",
- // "buyerid|销售员"=>"require|number|gt:0",
- // "sendtime|发货时间"=>"require|date",
- // "cat|商品分类"=>"require|array",
- // "cgd_tax|采购毛利率"=>"require|number|gt:0",
- // "sale_depart|销售员部门"=>"require|max:255|min:1",
- // "cgd_depart|采购员部门"=>"require|max:255|min:1",
- public function info(){
- $post=$this->request->post();
- $id = isset($post['id'])&&$post['id']!='' ? $post['id'] :"";
- $condition = [['a.id',"=",$id],["b.is_del","=",0],["c.is_del","=",0],["b.qrdSource","=",10],["c.cgdSource","=",10]];
- $list=Db::name('inter_order')->alias('a')->join('qrd_info b',"a.orderCode=b.sequenceNo and b.is_del=0 and b.qrdSource=10",'left')
- ->join('cgd_info c',"a.cgdNo=c.sequenceNo and c.is_del=0 and c.cgdSource=10",'left')->json
- (["cat"])->where($condition)
- ->order("a.addtime desc")->field('a.id,
- b.goodNo ,
- a.orderCode,
- a.platform_id,
- b.platName,
- b.platform_type,
- b.customerNo as khNo,
- b.customerName as khName,
- b.companyName,
- b.companyNo,
- b.poCode,
- b.workCode,
- a.addtime as ordertime,
- b.ownerName as sale_name,
- b.ownerid as sale_id,
- b.department as sale_depart,
- b.goodName,
- b.goodNo,
- b.tax,
- b.catInfo as cat,
- b.goodPrice,
- b.goodNum,
- b.totalPrice,
- b.qrdType,
- c.supplierName,
- c.supplierNo,
- a.cgdNo,
- c.ownerName as buyer,
- c.ownerid as buyerid,
- c.department as cgd_depart,
- a.sendtime ,
- a.rate*100 as cgd_tax,
- a.contactor,
- a.mobile,
- a.addr
- ')->findOrEmpty();
- if(empty($list)){
- return error_show(1004,'未找到数据');
- }
- $list['rateid'] = Db::name("order_rate")->where('rate',"=",$list['tax'])->value("id",'');
- return app_show(0,"获取成功",$list);
- }
- public function getCat(){
- $post=$this->request->post();
- $condition = [['status',"=",1],["is_del","=",0],['level',"=",3]];
- $cat_name=isset($post['cat_name']) && $post['cat_name'] !==""? trim($post['cat_name']) :"";
- if($cat_name!==""){
- $condition[]=['cat_name',"like","%$cat_name%"];
- }
- $search=isset($post['search']) && $post['search'] !==""? trim($post['search']) :"";
- if($search!==""){
- $condition[]=['search',"like","%$search%"];
- }
- $cat = Db::connect("mysql_wsm")->name("cat")->where($condition)->field("id,cat_name,fund_code,search")->order
- ("weight desc ,addtime desc")->select()->toArray();
- return app_show(0,"获取成功",$cat);
- }
- /**
- * @param $id
- * @param array $cat
- * @return array|mixed
- */
- private function cat($id,&$cat=[]){
- $condition[]=["id","=",$id];
- $data= Db::connect("mysql_wsm")->name("cat")->where($condition)->field("id,cat_name,fund_code,pid")->findOrEmpty();
- array_unshift($cat,$data);
- if($data['pid']==0||empty($data)) return $cat;
- else $this->cat($data['pid'],$cat);
- }
- /**
- * @param $id
- * @return array|\think\Model
- */
- private function platform($id){
- $condition[]=["id","=",$id];
- $data= Db::connect("mysql_wsm")->name("platform")
- ->where($condition)->field("id,platform_name,is_select_pay_rate,use_type,desc")->findOrEmpty();
- return $data;
- }
- public function getPlatform(){
- $post=$this->request->post();
- $platform =Db::connect("mysql_wsm")->name("user_platform")->where(["uid"=>$this->uid,"is_del"=>0])->value("platform",'');
- $condition = [['status',"=",1],["is_del","=",0],["platform_type","=",0]];
- $condition[]=['id',"in",explode(",",$platform)];
- $is_pay=isset($post['is_pay']) && $post['is_pay'] !==""? intval($post['is_pay']) :"";
- if($is_pay!==""){
- $condition[]=['is_select_pay_rate',"=",$is_pay];
- }
- $use_type=isset($post['use_type']) && $post['use_type'] !==""? intval($post['use_type']) :"";
- if($use_type!==""){
- $condition[]=['use_type',"=",$use_type];
- }
- $platform_name=isset($post['platform_name']) && $post['platform_name'] !==""? trim($post['platform_name']) :"";
- if($platform_name!==""){
- $condition[]=['platform_name',"like","%$platform_name%"];
- }
- $cat = Db::connect("mysql_wsm")->name("platform")->where($condition)->field("id,platform_name,is_select_pay_rate,use_type,desc")
- ->order("addtime desc")->select()->toArray();
- return app_show(0,"获取成功",$cat);
- }
- }
|