1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366 |
- <?php
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use think\Exception;
- use think\facade\Cache;use think\facade\Db;
- class Report extends Command
- {
- //相关字段的文字转换
- private $key='Reportexec';
- private $param=[];
- private $qrdType = [1 => '库存品', 2 => '非库存品', 3 => '采购反馈',"4"=>"报备单"];
- private $qrdSource = [1 => '直接下单', 2 => '竞价转单', 3 => '项目转单', 4 => '平台导入', 5 => '有赞平台', 6 => '售后补换货',7=>'报备转单',8=>'支付渠道拆单',9=>"采销补录",10=>"结算补录"];
- private $cgdSource = [0=>"备库单",1 => '直接下单', 2 => '竞价转单', 3 => '项目转单', 4 => '平台导入', 5 => '有赞平台', 6 => '售后补换货',7=>'报备转单',8=>'支付渠道拆单',9=>"采销补录",10=>"结算补录"];
- private $sendType = [1 => '包邮', 2 => '自提'];
- private $pay_status = [1 => '未回', 2 => '部分回款', 3 => '已回'];
- private $inv_status = [1 => '未开', 2 => '部分开票', 3 => '已开'];
- private $cgd_inv_status = [1 => '未回', 2 => '部分回票', 3 => '已回'];
- private $cgd_pay_status = [1 => '未付', 2 => '部分付款', 3 => '已付'];
- private $invoice_pool_status = [1 => '财务审核通过', 2 => '待财务上传发票', 3 => '金税开票中/验票中', 4 => '开票成功', 5 => '开票失败', 6 => '发票退票/废弃', 7 => '取消申请', 8 => '财务驳回', 9 => '验票失败'];
- private $cgdType = [1 => '库存', 2 => '非库存', 3 => '咨询','4'=>'报备单'];
- private $invoice_return_status = [0 => '待财务审核', 1 => '退票中', 2 => '退票成功', 3 => '审核驳回', 4 => '退票失败'];
- private $sendStatus = [1=>'未发货',2=>'部分发货',3=>'全部发货'];
- private $TagName = [1=>'采购单付款',2=>'采购单回票',3=>'销售回款',4=>"销售开票"];
- private $paltType = ['无',"ToB","ToC"];
- protected function configure()
- {
- // 指令配置
- $this->setName('report')
- ->setDescription('the report command');
- }
- protected function execute(Input $input, Output $output)
- {
- // 指令输出
- $Command = Cache::store('redis')->handler()->get('ExecCommand');
- if($Command>=3) return '';
- $info = Cache::store('redis')->handler()->rpop($this->key);
- if($info==false) return '';
- Cache::store('redis')->handler()->incrby('ExecCommand',1);
- Db::startTrans();
- try{
- $info = json_decode($info,true);
- ini_set ('memory_limit', '2048M') ;
- $date=date("Y-m-d H:i:s");
- $param = Db::name("exec_log")->where("id",$info['id'])->findOrEmpty();
- if(isset($param) && !empty($param)){
- if($param['is_del']==1) throw new \Exception("脚本记录已删除");
- switch ($param['action']){
- case 'A':
- $method="A";
- $file ='销售发票申请信息导出';
- break;
- case 'B':
- $method="B";
- $file ='进项发票登记导出';
- break;
- case 'C':
- $method="C";
- $file ='资金认领导出';
- break;
- case 'D':
- $method="D";
- $file = '回款核销明细表';
- break;
- case 'E':
- $method="E";
- $file='回票明细表';
- break;
- case 'F':
- $method="F";
- $file='经营分析报表';
- break;
- case 'G':
- $method="G";
- $file='收入成本明细表';
- break;
- case 'I':
- $method="I";
- $file='应收台账表';
- break;
- case 'J':
- $method="J";
- $file='用友销票表';
- break;
- case 'K':
- $method="K";
- $file='采购单明细表';
- break;
- case 'M':
- $method="M";
- $file='对账单汇总表';
- break;
- case 'N':
- $method="N";
- $file='退货台账';
- break;
- case 'Q':
- $method="Q";
- $file='产品部门销售业绩';
- break;
- case 'R':
- $method="R";
- $file='采购部门销售业绩';
- break;
- case 'L':
- $method="L";
- $file='客服部业绩提成';
- break;
- case 'S':
- $method="S";
- $file='项目部业绩提成';
- break;
- case 'T':
- $method="T";
- $file='新媒体业绩提成';
- break;
- case 'U':
- $method="U";
- $file='项目部2月前业绩提成';
- break;
- case 'V':
- $method="V";
- $file='退货明细';
- break;
- case 'W':
- $method="W";
- $file='对账采购关联对照';
- break;
- case 'X':
- $method='X';
- $file='仓储物流日报';
- break;
- default:
- $file='暂无数据';
- $method="";
- break;
- }
- if ($method == '') throw new Exception('该报表暂无对应的处理方法');
- $data =$this->$method($param);
- $url = excelSaveFile($data, $file . date('_YmdHis_').$param['id']);//加时间戳,防止同名文件覆盖
- Db::name('exec_log')
- ->where(['id' => $param['id'], 'status' => 4])//status==1 待处理
- ->update([
- 'status' => 2, //status==2 处理完成
- 'down_url' => $url,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- $end = date("Y-m-d H:i:s");
- $output->writeln("[$date]【{$param['name']}】[{$param['apply_name']}]预约记录处理完成 end:【{$end}】");
- }
- }catch (\Exception $e){
- Db::name('exec_log')
- ->where(['id' => $info['id'], 'status' =>4])//status==1 待处理
- ->update([
- 'status' => 3, //status==2 处理失败
- 'down_url' => '',
- "remark"=>$e->getMessage(),
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- $output->writeln("[$date]【{$info['name']}】[{$info['apply_name']}]预约记录处理失败 message:【{$e->getMessage()}|{$e->getFile()}|{$e->getCode()}】");
- }
- Cache::store('redis')->handler()->decrby('ExecCommand',1);
- Db::commit();
- }
- //销售发票申请信息导出
- private function A($param=[])
- {
- // $param = $this->request->only(['start' => '', 'end' => '', 'status' => '', 'inv_type' => '', 'inv_out' => '', 'invNo' => '', 'relaComNo' => '', 'inv_number' => '', 'inv_code' => '', 'inv_company' => '', 'buyer_name' => '', 'apply_id' => '', 'apply_name' => '',], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['e.status', 'in', [1, 2]]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
- if (($param['companyNo'] != '') && ($param['companyNo'] != '')) $where[] = ["a.inv_out","=",$param['companyNo']];
- $open_type = [1 => '金税开票', 2 => '金税线下', 3 => '纯线下'];//开票方式
- $inv_type = config('invoiceType.invoiceName');//开票种类(发票类型)
- $list = Db::name('invoice_pool')
- ->alias('a')
- ->field('a.inv_out 卖方公司编码,
- a.inv_company 卖方公司名称,
- a.invNo 申请编号,
- f.department 申请部门,
- a.apply_name 申请人,
- b.buyer_title 发票买方公司名称,
- concat(b.buyer_code," ") 发票买方企业纳税识别号,
- b.buyer_addr 发票买方企业地址,
- b.buyer_mobile 发票买方企业联系方式,
- b.buyer_bank 发票买方企业收款银行,
- concat(b.buyer_bankNo," ") 发票买方企业财务账户,
- d.orderCode 公司订单号,
- b.buyer_title 订单企业客户,
- d.goodName 订单商品名,
- concat(g.inv_cat_code," ") 税收分类编码,
- g.inv_cat_name 税收分类名称,
- d.goodName 发票明细商品名称,
- CONCAT(d.catName,"*",d.goodName) 发票货物或应税劳务、服务名称,
- d.unitName 单位,
- d.goodNum 数量,
- round(d.totalTax/d.goodNum,2) 单价,
- d.tax 税率,
- d.totalTax 总价,
- a.inv_type 开票种类,
- a.open_type 开票方式,
- a.exam_remark 申请备注,
- a.remark 发票备注,
- if(f.cxCode="",f.sequenceNo,f.cxCode) 销售主单号,
- f.goodPrice 商品单价')
- ->leftJoin('invoice_pool_info b', 'a.invNo=b.invNo')
- ->leftJoin('invoice_ticket c', 'a.invNo=c.invNo AND c.type=0 AND c.status=1')
- ->leftJoin('invoice_good d', 'd.invNo=a.invNo')
- ->leftJoin('assoc e', 'e.viceCode=d.invNo AND e.orderCode=d.orderCode AND e.is_del=0')
- ->leftJoin('qrd_info f', 'f.sequenceNo=e.orderCode')
- ->leftJoin('good g', 'g.spuCode=d.goodNo')
- ->where($where)
- ->order('a.addtime desc')
- ->cursor();
- foreach ($list as $value){
- $value["开票方式"] = $open_type[$value["开票方式"]] ?? '';
- $value["开票种类"] = $inv_type[$value["开票种类"]] ?? '';
- yield $value;
- }
- }
- //进项发票登记导出
- private function B($param=[])
- {
- // $param = $this->request->only(['start' => '', 'end' => '', 'invType' => '', 'company' => '', 'relaComNo' => '', 'supplierNo' => '', 'hpNo' => '', 'payNo' => '', 'invoiceType' => '', 'status' => '', 'invoiceNumber' => '', 'checkApi' => '', 'invoiceCode' => '', 'open_start' => '', 'open_end' => '', 'apply_id' => '', 'apply_name' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
- if (($param['companyNo'] != '') && ($param['companyNo'] != '')) $where[] = ["b.companyNo","=",$param['companyNo']];
- $status = [1 => '待系统验证', 2 => '买方公司审核', 3 => '待买方公司认证', 4 => '认证成功', 5 => '验证失败', 6 => '买方审核驳回', 7 => '认证失败', 8 => '回票流程终止', 9 => '验证超次数', 10 => '回票已退'];//认证状态
- $invoiceType = config('invoiceType.invoiceName');//开票种类(发票类型)
- $list = Db::name('pay_invoice')
- ->alias('a')
- ->leftJoin('pay b', 'a.payNo=b.payNo and b.status=2')
- ->leftJoin('invoice_info c', 'c.hpNo=a.hpNo AND c.status=1')
- ->field('"" 序号,
- a.payNo 对账编号,
- a.hpNo 回票申请编号,
- DATE_FORMAT(a.addtime,\'%Y\') 年,
- DATE_FORMAT(a.addtime,\'%m\') 月,
- a.invoiceNumber 发票号,
- c.total 总额,
- c.subtotal_amount 金额,
- c.subtotal_tax 税额,
- a.open_time 开票日期,
- b.supplierName 供应商,
- a.invoiceType 发票类型,
- "" as 业务类型,
- a.status 认证状态,
- a.updatetime 认证时间,
- a.remark 备注')
- ->where($where)
- ->order('a.addtime desc')
- ->cursor();
- $i=1;
- foreach ($list as $item) {
- $item['序号'] = $i;
- $item['业务类型'] = '采购回票';
- $item['认证状态'] = $status[$item['认证状态']]??"";
- $item['发票类型'] = $invoiceType[$item['发票类型']]??"";
- $i++;
- yield $item;
- }
- }
- //资金认领导出
- private function C($param=[])
- {
- // $param = $this->request->only(['start' => '', 'end' => '', 'name' => '', 'bank' => '', 'status' => '', 'tradNo' => '', 'company' => '', 'userd_lower' => '', 'used_upper' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.addtime', 'between', [$param['start'],$param['end']]];
- if (($param['companyNo'] != '') && ($param['companyNo'] != '')) $where[] = ["a.companyNo","=",$param['companyNo']];
- $status = [1 => '未认领', 2 => '部分认领', 3 => '全部认领'];//状态
- $b_status = [1 => '待审批', 2 => '审批通过', 3 => '审批驳回', 4 => '退款', 5 => '解除认领'];//认领审批状态
- $list = Db::name('trade')
- ->alias('a')
- ->field('
- a.companyNo 收款方公司编码,
- a.trade_in 收款单位名称,
- a.trade_account 付款银行单位账号,
- a.trade_out 付款银行单位名称,
- a.trade_used 付款备注,
- a.trade_time 交易时间,
- a.tradNo 资金编号,
- a.status 状态,
- a.total_fee 收入金额,
- a.balance 未认领金额,
- b.total_fee 已认领金额,
- b.logNo 资金认领编号,
- b.customerNo 认领企业,
- c.orderCode 订单编号,
- d.cxCode 销售主单号,
- d.poCode 平台编号,
- d.goodName 产品名称,
- d.ownerName 资金创建人,
- c.apply_name 认领创建人,
- b.status 认领审批状态,
- b.remark 驳回原因')
- ->leftJoin('trade_pool b', 'b.tradNo=a.tradNo and b.is_del=0')
- ->leftJoin('assoc c', 'c.viceCode=b.logNo and c.type=2 and c.status<>3')
- ->leftJoin('qrd_info d', 'd.sequenceNo=c.orderCode')
- ->where($where)
- ->order('a.trade_time desc')
- ->cursor();
- foreach ($list as $value){
- $value['状态'] = $status[$value['状态']] ?? '';
- $value['认领审批状态'] = $b_status[$value['认领审批状态']] ?? '';
- $value["付款银行单位账号"] .=' ';
- $value["认领企业"] =Db::name("customer_info")->where(["companyNo"=>$value["认领企业"]])->value("companyName","");
- yield $value;
- }
- }
- //回款核销明细表
- private function D($param=[])
- {
- // $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0],['b.status',">=",2],["b.type","=",2]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.addtime', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['a.companyNo', '=', $param['companyNo']];
- $data = Db::name('assoc')
- ->alias('b')
- ->field('DATE_FORMAT(b.addtime,\'%Y\') 年,DATE_FORMAT(b.addtime,\'%m\') 月,DATE_FORMAT(b.addtime,\'%d\') 日,a.companyName 业务公司名称,a.companyNo 业务公司编号,b.viceCode 资金认领编号,c.tradNo 资金编号,c.total_fee 本次核销金额,c.addtime 本次核销时间,c.status 资金认领状态,a.sequenceNo 确认单编号,a.department 业务员部门,a.ownerName 业务员,a.platName 平台类型,a.qrdSource 确认单类型,a.qrdType 商品类型,a.poCode 平台订单号,a.customerAttr 客户属性,a.branch 分公司,a.customerName 客户名称,a.firstCat 一级分类,a.goodName 产品名称,round(a.tax/100,2) 税点,(a.goodNum-a.thNum) 下单数量,a.goodPrice 销售单价,(a.totalPrice-a.th_fee) 销售总额')
- ->leftJoin('qrd_info a', 'b.orderCode=a.sequenceNo')
- ->leftJoin('trade_pool c', 'c.logNo=b.viceCode')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- //资金认领状态
- $status = [1 => '待审批', 2 => '审批通过', 3 => '审批驳回', 4 => '已解除认领', 5 => '已取消认领'];
- // $list = [];
- foreach ($data as $value) {
- $value['资金认领状态'] = $status[$value['资金认领状态']] ?? '';
- $value['确认单类型'] = $this->qrdSource[$value['确认单类型']] ?? '';
- $value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
- yield $value;
- }
- }
- //回票明细表
- private function E($param=[])
- {
- // $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0],['a.status', 'in',[3,4]],['b.is_del', '=', 0], ['c.is_del', '=', 0], ['d.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.check_time', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['b.companyNo', '=', $param['companyNo']];
- $data = Db::name('pay_invoice')
- ->alias('a')
- ->field('d.cgdTime 采购单下单日期,
- b.companyName 业务公司名称,
- b.companyNo 业务公司编号,
- a.hpNo 对账回票编号,
- a.payNo 对账单号,
- c.cgdNo 采购单编号,
- a.check_time 本次回票时间,
- a.invoiceNumber 发票号,
- a.inv_amount 本次回票金额,
- d.totalPrice 采购单回票金额,
- "" 不含税采购成本,
- "" 税额,
- d.companyName 公司回票抬头,
- d.goodNo 商品编号,
- d.firstCat 一级分类,
- d.fundCode 核算码,
- d.goodName 商品名称,
- d.goodNum 商品数量,
- d.goodUnit 单位,
- d.cgdSource 采购单类型,
- d.ownerName 采购员,
- d.supplierName 供应商名称,
- d.supplierNo 供应商编号,
- d.goodType 商品类型,
- round(d.tax/100,2) 税率,
- d.packPrice 包装费,
- d.certPrice 证书费,
- d.markPrice 加标费,
- d.openPrice 开模费,
- d.costPrice 成本工艺费,
- d.deliveryPrice 物流费,
- d.barePrice 成本单价,
- d.diff_weight 工差,
- d.diff_fee 工差金额,
- d.goodPrice 单价,
- d.totalPrice 采购总货款,
- d.qrdCode 确认单编号,
- d.bkCode 备库编号,
- d.thNum 退货数量,
- d.th_fee 退货金额,
- a.exam_remark 回票审核备注,
- a.remark 回票申请备注')
- ->leftJoin('pay b', 'a.payNo=b.payNo')
- ->leftJoin('pay_info c', 'c.payNo=a.payNo and c.status=1 and c.is_del=0')
- ->leftJoin('cgd_info d', 'd.sequenceNo=c.cgdNo')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- //采购单类型
- // $cgdSource = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞'];
- //商品类型
- $goodType = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
- // $list = [];
- foreach ($data as $value) {
- $value['采购单类型'] = $this->cgdSource[$value['采购单类型']] ?? '';
- $value['商品类型'] = $goodType[$value['商品类型']] ?? '';
- $value['不含税采购成本'] = round($value['采购总货款']/(1+$value['税率']),2) ;
- $value['税额'] = round($value['不含税采购成本']*$value['税率'],2) ;
- yield $value;
- }
- }
- //经营分析报表
- private function F($param=[])
- {
- // $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createdTime', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['a.companyNo', '=', $param['companyNo']];
- $data = Db::name('qrd_info')
- ->alias('a')
- ->field('
- DATE_FORMAT(a.createdTime,\'%Y\') 年,
- DATE_FORMAT(a.createdTime,\'%m\') 月,
- DATE_FORMAT(a.createdTime,\'%d\') 日,
- a.companyName 业务公司名称,
- a.companyNo 业务公司编号,
- a.department 销售部门,
- a.ownerName 销售员,
- a.qrdSource 订单来源,
- a.pay_source 支付来源,
- "" 活动类型,
- a.sequenceNo 确认单编号,
- if(a.cxCode="",a.sequenceNo,a.cxCode) 销售订单号,
- b.bkCode 备库单编号,
- b.sequenceNo 采购单单号,
- a.platName 平台类型,
- a.poCode 平台订单号,
- a.customerAttr 客户属性,
- a.branch 分公司,
- a.customerName 客户名称,
- a.goodNo 商品编码,
- a.firstCat 一级分类,
- a.secCat 二级分类,
- a.thirdCat 三级分类,
- a.goodName 产品名称,
- a.goodUnit 单位,
- a.goodNum 下单数量,
- a.goodPrice 销售单价,
- (a.totalPrice+a.th_fee) 销售总额,
- round(a.tax/100,2) 税点,
- b.ownerName 采购员,
- b.goodPrice 采购裸价,
- b.markPrice 加标费,
- b.packPrice 包装费,
- b.certPrice 证书费,
- b.openPrice 开模费,
- b.costPrice 工艺费,
- b.deliveryPrice 物流费,
- b.goodPrice 采购单价合计,
- (ifnull(b.totalPrice,a.total_origin_price)+ifnull(b.th_fee,0)) 实际采购总货款,
- 0 毛利润,
- 0 毛利率,
- round(b.tax/100,2) 采购税点,
- 0 不含税采购成本,
- a.qrdType 库存性质,
- b.supplierName 供应商名称,
- b.sendType 发货方式,
- a.thNum 退货数量,
- a.fundCode 财务核算编码,
- a.total_plan_price 预计采购总额')
- ->leftJoin('cgd_info b', 'b.sequenceNo=a.cgdNo and b.is_del=0')
- ->where($where)
- ->order(['a.id' => 'asc'])
- ->cursor();
- $list = [];
- foreach ($data as $value) {
- $value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
- $value['库存性质'] = $this->qrdType[$value['库存性质']] ?? '';
- $value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
- $value['毛利润'] = round(bcsub($value['销售总额'], $value['实际采购总货款'], 3), 2);
- $value['毛利率'] = $value['销售总额'] == 0 ? 0 : round(bcmul(bcsub(1, bcdiv($value['实际采购总货款'], $value['销售总额'], 5),5), 100,2), 2) . '%';
- $value['不含税采购成本'] = round(bcdiv($value['实际采购总货款'], bcadd(1,$value['采购税点'],3), 3), 2);
- yield $value;
- }
- }
- //收入成本明细表
- private function G($param=[])
- {
- // $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0], ['a.status', '>=', 4]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['c.open_date', 'between', [$param['start'],$param['end']]];
- if ($param['companyNo'] != '') $where[] = ['a.inv_out', '=', $param['companyNo']];
- $data = Db::name('invoice_pool')
- ->alias('a')
- ->field('
- a.invNo 发票申请编号,
- m.orderCode 确认单编号,
- if(e.cxCode="",m.orderCode,e.cxCode) 销售主单编号,
- e.qrdSource 销售来源,
- b.seller_title 销售方抬头,
- e.department 业务部门,
- e.ownerName 业务人员,
- m.goodNum 本次开票数量,
- m.totalTax 本次开票金额,
- e.goodPrice 销售单价,
- c.open_date 本次开票时间,
- c.inv_number 发票号,
- m.tax 开票税点,
- a.status 开票状态,
- e.customerName 客户名称,
- e.fundCode 财务核算码,
- e.firstCat 一级分类,
- e.secCat 二级分类,
- e.thirdCat 三级分类,
- e.goodNo 产品编号,
- e.goodName 产品名称,
- f.sequenceNo 采购单编号,
- f.supplierName 卖出方公司,
- f.sendType 发货方式,
- e.qrdType 商品类型,
- f.ownerName 采购员,
- ifnull(f.goodNum,e.goodNum) 采购下单数量,
- f.barePrice 采购裸价,
- f.markPrice 加标费,
- f.packPrice 包装费,
- f.certPrice 证书费,
- f.openPrice 开模费,
- f.costPrice 工艺费,
- f.deliveryPrice 物流费,
- f.goodPrice 成本合计,
- ifnull(f.totalPrice,e.total_origin_price) 采购货款,
- round(f.tax/100,2) 采购单税点,
- g.returnCode 退票编号,
- if(g.returnCode<>"",a.inv_value,"") 退票金额,
- g.status 退票状态,
- g.return_type 退票方式,
- f.thNum 退货数量,
- f.th_fee 退货金额,
- e.total_plan_price 预计采购总额
- ')
- ->leftJoin('invoice_pool_info b', 'b.invNo=a.invNo')
- ->leftJoin('invoice_ticket c', 'c.invNo=a.invNo and c.type=0 and c.status in (0,1,2,3)')
- ->leftJoin("invoice_good m","m.invNo=a.invNo and m.invtype=0 and m.is_del=0")
- // ->leftJoin('assoc d', 'd.viceCode=a.invNo and d.type=1')
- ->leftJoin('qrd_info e', 'e.sequenceNo=m.orderCode')
- ->leftJoin('cgd_info f', 'f.sequenceNo=e.cgdNo')
- ->leftJoin('invoice_return g', 'g.invNo=a.invNo and g.status=2')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- $list = [];
- foreach ($data as $value) {
- $value['开票状态'] = $this->invoice_pool_status[$value['开票状态']] ?? '';
- $value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
- $value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
- $value['退票状态'] = $this->invoice_return_status[$value['退票状态']] ?? '';
- $value['销售来源'] = $this->qrdSource[$value['销售来源']] ?? '';
- yield $value;
- }
- }
- //应收台账表
- private function I($param=[])
- {
- // $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createdTime', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['a.companyNo', '=', $param['companyNo']];
- $data = Db::name('qrd_info')
- ->alias('a')
- ->field('
- a.createdTime 下单时间,
- a.companyName 业务公司名称,
- a.companyNo 业务公司编号,
- a.sequenceNo 业务订单编号,
- if(a.cxCode="",a.sequenceNo,a.cxCode) 销售订单主编号,
- a.department 销售部门,
- a.ownerName 销售员,
- a.qrdSource 订单来源,
- a.platName 平台类型,
- a.poCode 平台订单号,
- a.customerName 客户名称,
- a.customerAttr 客户属性,
- a.branch 客户分公司,
- a.firstCat 一级分类,
- a.goodName 产品名称,
- round(a.tax/100,2) 税点,
- (a.goodNum - a.thNum) 下单数量,
- a.goodPrice 销售单价,
- a.totalPrice 销售总额,
- a.th_fee 退货总额,
- a.pay_status 回款状态,
- a.apay_fee 总已回款,
- a.pay_fee 回款中,
- a.wpay_fee 总未回款,
- a.pay_tag_fee 回款标签金额,
- a.inv_status 开票状态,
- a.ainv_fee 总已开票,
- a.inv_fee 开票中,
- a.winv_fee 总未开票,
- a.inv_tag_fee 开票标签金额,
- a.invtime 最近开票时间,
- "" 业务提票时间,
- a.paytime 最近回款时间,
- 0 账期,
- 0 比率,
- "" 订单是否超期,
- "" 开票是否超期,
- a.sendStatus 发货状态,
- "" 最近一次发货时间
- ')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- // echo Db::name('qrd_info')->getLastSql();die;
- $time = time();
- foreach ($data as $value) {
- // $value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
- // $value['回款状态'] = $this->pay_status[$value['回款状态']] ?? '';
- // $value['开票状态'] = $this->inv_status[$value['开票状态']] ?? '';
- // $value['发货状态'] = $this->sendStatus[$value['发货状态']] ?? '';
- $value['业务提票时间'] =Db::name("assoc")->where(["type"=>1,"status"=>[1,2],"is_del"=>0,'orderCode'=>$value['业务订单编号']])
- ->order("id desc")->value('addtime','');
- //计算账期
- $value['账期'] = bcdiv(bcsub($time,strtotime($value['最近回款时间']==''?$value['下单时间']:$value['最近回款时间']), 3), 86400, 0);
- $value['比率'] = round(bcdiv($value['账期'], 30, 4),3);
- $value['订单是否超期'] = $value['比率'] > 6 ? '是' : '否';
- $value['开票是否超期'] = round(bcdiv(bcsub($time, strtotime($value['最近开票时间']==''?$value['下单时间']:$value['最近开票时间']), 1), 86400, 1)
- ) >
- 15 ? '是' : '否';
- $value['最近一次发货时间'] = Db::table('fh_source')
- ->whereIn('qrdNo', [$value['业务订单编号'], $value['销售订单主编号']])
- ->order(['id' => 'desc'])
- ->value('send_date', '');
- $value['销售回款'] = Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")
- ->where(["a.code"=>$value['业务订单编号'],"a.status"=>1,"b.type"=>3])->value("b.tag_name",'');
- $value['销售开票'] = Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")
- ->where(["a.code"=>$value['业务订单编号'],"a.status"=>1,"b.type"=>4])->value("b.tag_name",'');
- if($value['订单来源']==10)$value['最近一次发货时间']=$value['下单时间'];
- $value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
- $value['回款状态'] = $this->pay_status[$value['回款状态']] ?? '';
- $value['开票状态'] = $this->inv_status[$value['开票状态']] ?? '';
- $value['发货状态'] = $this->sendStatus[$value['发货状态']] ?? '';
- yield $value;
- }
- }
- //用友销票表
- private function J($param=[])
- {
- // $param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
- $where = [['a.is_del', '=', 0],["a.status","in",[3,4]], ['e.is_del','=', 0]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.check_time', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['e.companyNo', '=', $param['companyNo']];
- $data = Db::name('pay_invoice')
- ->alias('a')
- ->field('
- e.companyName 回票业务公司名称,
- a.hpNo 回票编码,
- e.supplierName 供应商名称,
- a.invoiceNumber 发票号,
- b.item_list,
- "" 发票货物或应税劳务、服务名称,
- "" 回票数量,
- "" 本次回票价款,
- "" 本次回票税额,
- "" 回票税率,
- b.issue_date 开票日期,
- b.total 本次回票总金额,
- a.check_time 本次回票时间
- ')
- ->leftJoin('invoice_info b', 'b.hpNo=a.hpNo and b.status=1')
- ->leftJoin('pay e', 'e.payNo=a.payNo')
- ->where($where)
- ->order(['a.id' => 'desc'])
- ->cursor();
- $list = [];
- foreach ($data as $value) {
- $item_list = json_decode($value['item_list'], true);
- unset($value['item_list']);
- foreach ($item_list as $item) {
- yield $list[] = array_merge($value, [
- '发票货物或应税劳务、服务名称' => $item['name'] ?? '',
- '回票数量' => $item['quantity'] ?? '',
- '本次回票价款' => $item['amount'] ?? '',
- '本次回票税额' => $item['tax'] ?? '',
- '回票税率' => $item['tax_rate'] ?? '',
- '规格' => $item['specification'] ?? '',
- '单位' => $item['unit'] ?? '',
- ]);
- }
- }
- // return $list;
- }
- /** 采购单管理数据
- * @throws \PHPExcel_Exception
- * @throws \PHPExcel_Reader_Exception
- * @throws \PHPExcel_Writer_Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function K($param=[])
- {
- // $param = $this->request->only(['companyNo' => '', 'start' => '', 'end' => '', "supplierNo" => ''], 'post', 'trim');
- $where = [];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['createdTime', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
- $data = Db::name("cgd_info")->where($where)
- ->field("
- sequenceNo '采购单编号',
- companyName '业务企业',
- supplierName '供应商名称',
- ownerName '采购员',
- department '采购部门',
- createdTime '采购时间',
- cgdType '采购单类型',
- if(qrdCode='',bkCode,qrdCode) '确认单编号/备库单编号',
- if(cxCode='',if(qrdCode='',bkCode,qrdCode),cxCode) '销售单主单号',
- goodNo '商品编号',
- goodName '商品名称',
- firstCat '一级分类',
- secCat '二级分类',
- thirdCat '三级分类',
- fundCode '核算码',
- round(tax/100,2) '税率',
- barePrice '裸价',
- markPrice '加标费',
- certPrice '证书费',
- openPrice '开模费',
- packPrice '包装费',
- costPrice '工艺费',
- deliveryPrice '物流费',
- goodPrice '单价',
- isStock '是否库存',
- diff_fee '工差金额',
- goodNum '商品数量',
- totalPrice '总价',
- qrdSend '发货状态',
- '' as '对账编号',
- '' as '付款状态',
- '' as '回票状态'
- ")->cursor();
- $list = [];
- foreach ($data as $value) {
- $value['采购单类型'] = $this->cgdType[$value['采购单类型']];
- $payinfo = Db::name("pay_info")->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo and b.status=2")
- ->where(["a.status" => 1, "a.is_del" => 0,'cgdNo'=>$value['采购单编号']])
- ->field("b.payNo,b.inv_status,b.pay_status")->find();
- $value['对账编号'] = $payinfo['payNo'] ?? "";
- $value['付款状态'] = $this->cgd_pay_status[$payinfo['pay_status'] ?? "1"];
- $value['回票状态'] = $this->cgd_inv_status[$payinfo['inv_status'] ?? "1"];
- $value['是否库存'] = $value['是否库存']==1?'是':'否';
- $value['发货状态'] = $this->sendStatus[$value['发货状态']]??"未发货";
- yield $value;
- }
- }
- /**
- * 对账单汇总表
- */
- private function M($param=[])
- {
- $where = [["is_del", "=", 0], ["status", "=", 2]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['addtime', 'between', [$param['start'], $param['end']]];
- if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
- $data = Db::name("pay")->where($where)
- ->field("
- companyName '业务公司',
- apply_name '申请人',
- addtime '申请时间',
- supplierName '供应商名称',
- '' as '付款时间',
- payNo '对账编号',
- total_fee '对账总额',
- apay_fee '已付款',
- pay_fee '付款中',
- wpay_fee '未付款',
- pay_status '付款状态',
- pay_tag_fee '付款加签金额',
- pay_tag as '付款加签时间',
- '' as '付款标签名称',
- ainv_fee '已回票',
- inv_fee '回票中',
- winv_fee '未回票',
- inv_status '回票状态',
- inv_tag_fee '回票加签金额',
- inv_tag as '回票加签时间',
- '' as '回票标签名称',
- remark '备注'
- ")->cursor();
- foreach ($data as $value) {
- $tag = Db::name("tag_log")->alias("a")->leftJoin("order_tag b", "a.tag_id=b.id")->where(["a.code" =>
- $value['对账编号'], "a.status" => 1])->column("a.addtime,b.tag_name", "b.type");
- $value['付款加签时间'] = $tag[1]['addtime'] ?? "";
- $value['回票加签时间'] = $tag[2]['addtime'] ?? "";
- $value['回票标签名称'] = $tag[2]['tag_name'] ?? "";
- $value['付款标签名称'] = $tag[1]['tag_name']?? "";
- $value['付款状态'] = $this->pay_status[$value['付款状态']];
- $value['回票状态'] = $this->inv_status[$value['回票状态']];
- $value['付款时间'] = Db::name("pay_payment")->where(['payNo'=>$value['对账编号'],"is_del"=>0])->order("id desc")
- ->value('return_time','');
- yield $value;
- }
- }
- //退货台账
- private function N($param=[]){
- $where = [];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createtime', 'between', [$param['start'],$param['end']]];
- if ($param['companyNo'] != '') $where[] = ['b.companyNo', '=', $param['companyNo']];
- $list = Db::name("th_source")
- ->alias("a")
- ->leftJoin("qrd_info b","a.th_qrdNo=b.sequenceNo or a.th_qrdNo=b.cxCode")
- ->leftJoin("cgd_info c","b.cgdNo=c.sequenceNo")
- ->where($where)
- ->field("
- DATE_FORMAT( a.createtime, '%Y' ) 年,
- DATE_FORMAT( a.createtime, '%m' ) 月,
- DATE_FORMAT( a.createtime, '%d' ) 日,
- b.companyName 退货公司名称,
- b.companyNo 退货公司编号,
- b.department 销售部门,
- b.ownerName 销售员,
- b.qrdSource 销售来源,
- b.pay_source 支付渠道,
- '' 活动类型,
- b.sequenceNo 订单编号,
- if(b.cxCode='',b.sequenceNo,b.cxCode) 销售订单编号,
- a.thNo 退货单号,
- b.cgdNo 采购单号,
- b.platName 平台类型,
- b.poCode 平台订单号,
- b.customerAttr 客户属性,
- b.area 分公司,
- b.customerName 客户名称,
- b.goodNo 商品编号,
- b.firstCat 一级分类,
- b.secCat 二级分类,
- b.thirdCat 三级分类,
- b.goodName 商品名称,
- b.goodUnit 商品单位,
- a.th_num 退货数量,
- b.goodPrice 销售单价,
- a.th_qrd_fee 退货金额,
- ifnull(b.tax,0)/100 税点,
- c.ownerName 采购员,
- c.barePrice 采购裸价,
- c.markPrice 加标费,
- c.packPrice 包装费,
- c.certPrice 证书费,
- c.openPrice 开模费,
- c.costPrice 工艺费,
- c.deliveryPrice 物流费,
- c.goodPrice 采购单价,
- round(a.th_num * ifnull(c.goodPrice,b.total_origin_price/b.goodNum),2) 退货采购货款,
- ifnull(c.tax,0)/100 采购税点,
- if(b.isStock=1,'是','否') 是否库存,
- c.supplierName 供应商名称,
- c.sendType 发货方式,
- if(a.is_th=1,'是','否') 供应商是否同意退货,
- '' as 付款方式,
- b.fundCode 财务核算码,
- round(a.th_num * (b.total_plan_price/b.goodNum),2) 预计采购总额,
- a.th_remark 退货备注,
- c.bkCode 备库单号
- ")->cursor();
- foreach ($list as $value) {
- $value['销售来源']= $this->qrdSource[$value['销售来源']]??"";
- $value['发货方式']= $this->sendType[$value['发货方式']]??"";
- yield $value;
- }
- }
- //产品部门销售业绩
- private function Q($param=[]){
- $where = [["is_del","=",0],["status","in",[0,1,2]],["apply_id","in",array_merge(getUidByDepartId(52),getUidByDepartId(53))]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['addtime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))]];
- $Db= Db::connect("mysql_wsm");
- $list =$Db->name("sale")->field("orderCode 销售单号,apply_name 业务人员,apply_id 业务部门,cat_id 分类,total_price 产品货款总额,addtime 日期")
- ->where($where)
- ->cursor();
- $depart=[];
- foreach ($list as $value){
- if(!isset($depart[$value['业务部门']])){
- $temp = getDepartByUid($value['业务部门']);
- if(isset($temp['data']) && !empty($temp['data']))
- $depart[$value['业务部门']]=$temp['data'][$value['业务部门']];
- }
- $value['业务部门'] = $depart[$value['业务部门']]??"";
- $value['分类'] = $Db->name("cat")->where(["id"=>$value['分类']])->value("search","");
- yield $value;
- }
- }
- //采购部门销售业绩
- private function R($param=[]){
- $where = [["a.is_del","=",0],["a.status","in",[2,3]]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.sendtime', 'between', [date("Y-m-d 00:00:00",
- strtotime($param['start'])),date("Y-m-d 23:59:59",strtotime($param['end']))]];
- // if ($param['companyNo'] != '') $where[] = ['supplierNo', '=', $param['companyNo']];
- $Db= Db::connect("mysql_wsm");
- $list =$Db->name("order_out_child")->alias("a")
- ->leftjoin("sale b","a.orderCode=b.orderCode")
- ->leftjoin("order_send c","a.outCode=c.outCode")
- ->leftjoin("purchease_order d","c.cgdNo=d.cgdNo")
- ->field("
- a.outChildCode 发货工单号,
- a.outCode 发货单号,
- c.cgdNo 采购单号,
- a.orderCode 销售单号,
- b.platform_id 平台类型,
- b.platform_id 平台名称,
- b.apply_id 业务部门,
- d.cgder 供应商负责人,
- d.cgder 发货操作人,
- b.order_source 订单类型,
- b.order_type 商品类型,
- a.sendtime 发货工单发货时间,
- b.cat_id `一级分类`,
- b.good_name 商品名称,
- b.good_code 商品成本编号,
- b.good_num ,
- a.post_name 物流公司,
- a.post_code 物流单号,
- a.companyNo `业务公司编号`,
- a.companyName `业务公司名称`,
- a.supplierNo `供应商编号`,
- a.supplierName `供应商名称`,
- a.num 本次发货数量,
- a.num*d.good_price 本次发货金额,
- d.good_price 采购单价,
- d.send_num-d.th_num 采购总数,
- d.total_fee-d.th_fee 采购金额,
- d.good_creater`商品创建人`,
- d.addtime`采购单时间`,
- d.cgd_apply_name`源头竞单人`,
- d.cgd_supplier_name`源头供应商`,
- d.supplier_origin_price `源头采购成本`
- ")
- ->where($where)
- ->cursor();
- $depart=[];
- $hasAccount=[];
- $platform=[];
- $is_combind=[];
- foreach ($list as $value){
- if(!isset($depart[$value['业务部门']])){
- $temp = getDepartByUid($value['业务部门']);
- if(isset($temp['data']) && !empty($temp['data']))
- $depart[$value['业务部门']]=$temp['data'][$value['业务部门']];
- }
- if($value['商品类型']==1){
- $value['采购单价'] = $Db->name("purchease_order")->where(["spuCode"=>$value['商品成本编号'],"status"=>3])
- ->order("id desc")->value("good_price",0);
-
- if(!in_array($value['商品成本编号'],$is_combind)){
- $isc = $Db->name('good_basic')->where(['spuCode'=>$value['商品成本编号']])->value('is_combind',0);
- if($isc==1)$is_combind[]=$value['商品成本编号'];
- }
- if(in_array($value['商品成本编号'],$is_combind)){
- $value['采购单价'] = $Db->name("good_nake")
- ->where([["is_del","=",0],["spuCode","=",$value['商品成本编号']],["min_num","<=",$value['good_num']]])
- ->order('min_num desc')->value('nake_total',0);
- }
- $value['本次发货金额']= bcmul($value['本次发货数量'],$value['采购单价'],2);
- }
-
- $value['业务部门'] = $depart[$value['业务部门']]??"";
- $value['发货操作人'] = $Db->name('process_order')->where(['order_code'=>$value['发货工单号'],'order_type'=>'FHGD','action_process'=>2])->value('action_name');
- $value['一级分类'] = $Db->name("cat")->where(["id"=>$value['一级分类']])->value("search","");
- if(!isset($platform[$value['平台类型']])){
- $pal = $Db->name('platform')->where(['id'=>$value['平台类型']])->field('platform_name,use_type')
- ->findOrEmpty();
- $platform[$value['平台类型']] = $pal;
- }
- $value['平台类型'] =$this->paltType[$platform[$value['平台类型']]["use_type"]??0];
- $value['平台名称'] =$platform[$value['平台名称']]["platform_name"]??'';
- $value['订单类型']=$this->qrdSource[$value['订单类型']]??"";
- $value['商品类型']=$this->qrdType[$value['商品类型']]??"";
- $value['物流单号'].='';
- unset($value['good_num']);
- yield $value;
- }
- }
-
- //客服部 52客服部@百辰荣达
- private function L($param=[]){
- $where = [["b.is_del","=",0],["a.is_del","=",0],["b.status","=",2],["b.type","=",2],["a.ownerid","in",getUidByDepartId(52)]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.updatetime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",strtotime($param['end']))]];
- $list = Db::name("qrd_info")->alias("a")
- ->rightJoin("assoc b","a.sequenceNo=b.orderCode")
- ->field(" a.department 部门,
- a.ownerName 销售人员,
- platName 平台类型,
- a.companyName 公司名称,
- if(qrdType=1,'库存',if(qrdType=2,'非库存','咨询')) 订单类型,
- a.sequenceNo 确认单编号,
- a.cgdNo 采购单编号,
- customerAttr 客户属性,
- branch 客户分公司,
- customerName 客户名称,
- a.goodName 产品名称,
- a.goodNo,
- a.firstCat 一级分类,
- a.goodPrice 销售单价,
- if(a.cxCode='',a.sequenceNo,a.cxCode) 原销售单号,
- a.goodNum 下单数量,
- a.totalPrice 销售总额,
- a.createdTime 销售下单时间,
- b.updatetime 回款日期,
- b.cancel_fee 回款金额,
- ceil(DATEDIFF(b.updatetime,a.createdTime)/30) 账期,
- if(a.manager='',a.ownerName,a.manager) 实际销售人员,
- '' 账期回款系数,
- '' 一级类型,
- '' 提成系数,
- '' 明细总提成
- ")
- ->where($where)->cursor();
- $normal=['贵金属','工艺收藏','数码电子','大家电'];
- $huiyi=['会议培训制品','会议培训展会服务'];
- foreach ($list as $value){
- $totalPrice=$value['回款金额'];
- $value['账期回款系数']=getPayRate($value['账期']);
- $value['一级类型']='常规分类';
- $value['提成系数']=0.005;
- if(in_array($value['一级分类'],$normal)) {
- $value['一级类型']='非常规分类';
- $value['提成系数']=0.0002;
- }
- if(in_array($value['一级分类'],$huiyi)){
- $value['一级类型']='会议分类';
- $value['提成系数']=0.0025;
- }
- if($value['订单类型']=='库存'){
- $value['采购单价'] = Db::name('cgd_info')->where(['goodNo'=>$value['goodNo'],'cgdSource'=>0])->order('id desc')->value('goodPrice',0);
- }else{
- $value['采购单价'] = Db::name('cgd_info')->where(['qrdCode'=>$value['原销售单号']])->value('goodPrice',0);
- }
- $value['明细总提成'] = bcmul(bcmul($totalPrice ,$value['账期回款系数']),$value['提成系数'],4);
- unset($value['goodNo']);
- yield $value;
- }
- }
- //项目部业绩 53项目部@普润心堂
- private function S($param=[]){
- $where = [
- ["b.is_del","=",0],
- ["a.is_del","=",0],
- ["b.status","=",2],
- ["b.type","=",2],
- ["a.createdTime",">=",'2023-02-01 00:00:00'], //二月之后订单
- ["a.ownerid","in",getUidByDepartId(53)],
- ["a.ownerid","not in",[143,125]]
- ];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.updatetime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))]];
- $list = Db::name("qrd_info")->alias("a")
- ->rightJoin("assoc b","a.sequenceNo=b.orderCode")
- ->field(" a.department 部门,
- a.ownerName 销售人员,
- platName 平台类型,
- a.companyName 公司名称,
- if(qrdType=1,'库存',if(qrdType=2,'非库存','咨询')) 订单类型,
- a.sequenceNo 确认单编号,
- a.cgdNo 采购单编号,
- customerAttr 客户属性,
- branch 客户分公司,
- customerName 客户名称,
- a.goodName 产品名称,
- a.goodNo,
- a.firstCat 一级分类,
- a.goodPrice 销售单价,
- if(a.cxCode='',a.sequenceNo,a.cxCode) 原销售单号,
- 0 采购单价,
- a.goodNum 下单数量,
- a.totalPrice 销售总额,
- a.createdTime 销售下单时间,
- b.updatetime 回款日期,
- b.cancel_fee 回款金额,
- ceil(DATEDIFF(b.updatetime,a.createdTime)/30) 账期,
- a.manager 项目经理,
- '' 账期回款系数,
- '' 毛利率,
- '' 毛利率区间,
- '' 毛利率提成系数,
- '' 明细总提成,
- '' `明细提成30%`,
- '' `明细提成70%`
- ")->where($where)->cursor();
- $ladder = [
- "0"=>"X<10",
- "0.003"=>"10%≤X≤18%",
- "0.006"=>"18%<X≤20%",
- "0.012"=>"20%<X≤25%",
- "0.02"=>"25%<X≤30%",
- "0.035"=>"X>30%",
- ];
- foreach ($list as $value){
- if($value['订单类型']=='库存'){
- $value['采购单价'] = Db::name("cgd_info")->where(["goodNo"=>$value['goodNo'],"cgdSource"=>0])->order("id desc")->value("goodPrice",0);
- }else{
- $value['采购单价'] = Db::name("cgd_info")->where(["qrdCode"=>$value['原销售单号']])->value("goodPrice",0);
- }
- $value['账期回款系数']=getPayRate($value['账期']);
- $value['毛利率'] = (1-bcdiv($value['采购单价'],$value['销售单价'],4))*100;
- $value['毛利率提成系数'] =getLadderRate($value['毛利率']);
- $value['毛利率区间'] =$ladder[$value['毛利率提成系数'].''];
- $value['明细总提成']= bcmul(bcmul($value['回款金额'] ,$value['账期回款系数']),$value['毛利率提成系数'],4);
- $value['明细提成30%']= bcmul(bcmul(bcmul($value['回款金额'] ,$value['账期回款系数']),$value['毛利率提成系数'],4),0.3,4);
- $value['明细提成70%']= bcmul(bcmul(bcmul($value['回款金额'] ,$value['账期回款系数']),$value['毛利率提成系数'],4),0.7,4);
- unset($value['goodNo']);
- yield $value;
- }
- }
- //新媒体部门 聂亚男&&新媒体业务账户
- private function T($param=[]){
- $where = [
- ["b.is_del","=",0],
- ["a.is_del","=",0],
- ["b.status","=",2],
- ["b.type","=",2],
- ["a.ownerid","in",[143,125]]
- ];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.updatetime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))]];
- $list = Db::name("qrd_info")->alias("a")
- ->rightJoin("assoc b","a.sequenceNo=b.orderCode")
- // ->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
- ->field("
- a.department 部门,
- a.ownerName 销售人员,
- platName 平台类型,
- a.companyName 公司名称,
- if(qrdType=1,'库存',if(qrdType=2,'非库存','咨询')) 订单类型,
- a.sequenceNo 确认单编号,
- a.cgdNo 采购单编号,
- customerAttr 客户属性,
- branch 客户分公司,
- customerName 客户名称,
- a.goodName 产品名称,
- a.goodNo,
- a.firstCat 一级分类,
- a.goodPrice 销售单价,
- if(a.cxCode='',a.sequenceNo,a.cxCode) 原销售单号,
- 0 采购单价,
- a.goodNum 下单数量,
- a.totalPrice 销售总额,
- a.createdTime 销售下单时间,
- b.updatetime 回款日期,
- b.cancel_fee 回款金额,
- ceil(DATEDIFF(b.updatetime,a.createdTime)/30) 账期
- ")->where($where)->cursor();
- foreach ($list as $value){
- if($value['订单类型']=='库存'){
- $value['采购单价'] = Db::name("cgd_info")->where(["goodNo"=>$value['goodNo'],"cgdSource"=>0])->order("id desc")->value("goodPrice",0);
- }else{
- $value['采购单价'] = Db::name("cgd_info")->where(["qrdCode"=>$value['原销售单号']])->value("goodPrice",0);
- }
- unset($value['goodNo']);
- yield $value;
- }
- }
- //项目部2月之前订单
- private function U($param=[]){
- $where = [
- ["b.is_del","=",0],
- ["a.is_del","=",0],
- ["b.status","=",2],
- ["b.type","=",2],
- ["a.createdTime","<=",'2023-02-01 00:00:00'], //二月之前订单
- ["a.ownerid","in",getUidByDepartId(53)],
- ["a.ownerid","not in",[143,125]]
- ];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.updatetime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))]];
- $list = Db::name("qrd_info")->alias("a")
- ->rightJoin("assoc b","a.sequenceNo=b.orderCode")
- // ->leftJoin("cgd_info c","c.sequenceNo = a.cgdNo and c.is_del=0")
- ->field("
- a.department 部门,
- a.ownerName 销售人员,
- platName 平台类型,
- a.companyName 公司名称,
- if(qrdType=1,'库存',if(qrdType=2,'非库存','咨询')) 订单类型,
- a.sequenceNo 确认单编号,
- a.cgdNo 采购单编号,
- customerAttr 客户属性,
- branch 客户分公司,
- customerName 客户名称,
- a.goodName 产品名称,
- a.goodNo,
- a.firstCat 一级分类,
- a.goodPrice 销售单价,
- if(a.cxCode='',a.sequenceNo,a.cxCode) 原销售单号,
- 0 采购单价,
- a.goodNum 下单数量,
- a.totalPrice 销售总额,
- a.createdTime 销售下单时间,
- b.updatetime 回款日期,
- b.cancel_fee 回款金额,
- ceil(DATEDIFF(b.updatetime,a.createdTime)/30) 账期
- ")->where($where)->cursor();
- foreach ($list as $value){
- if($value['订单类型']=='库存'){
- $value['采购单价'] = Db::name("cgd_info")->where(["goodNo"=>$value['goodNo'],"cgdSource"=>0])->order("id desc")->value("goodPrice",0);
- }else{
- $value['采购单价'] = Db::name("cgd_info")->where(["qrdCode"=>$value['原销售单号']])->value("goodPrice",0);
- }
- unset($value['goodNo']);
- // unset($value['companyNo']);
- yield $value;
- }
- }
- //退货明细
- private function V($param=[]){
- $where = [["a.is_del","=",0],["a.apply_id","in",array_merge(getUidByDepartId(52),getUidByDepartId(53))]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))]];
- $Db= Db::connect("mysql_wsm");
- $list =$Db->name("th_data")->alias("a")
- ->leftJoin("sale b","a.orderCode=b.orderCode")
- ->field("a.thCode 退货单号,b.orderCode 销售单号,a.apply_name 业务人员,a.apply_id 业务部门,a.cat_id 分类,a.th_fee 退货金额,a.addtime 日期")
- ->where($where)
- ->cursor();
- $depart=[];
- foreach ($list as $value){
- if(!isset($depart[$value['业务部门']])){
- $temp = getDepartByUid($value['业务部门']);
- if(isset($temp['data']) && !empty($temp['data']))
- $depart[$value['业务部门']]=$temp['data'][$value['业务部门']];
- }
- $value['业务部门'] = $depart[$value['业务部门']]??"";
- $value['分类'] = $Db->name("cat")->where(["id"=>$value['分类']])->value("search","");
- yield $value;
- }
- }
- //对账单采购单明细
- private function W($param=[]){
- $where = [["a.is_del","=",0],["b.is_del","=",0],["a.status","in",[0,1,2]]];
- if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [date("Y-m-d 00:00:00",strtotime($param['start'])),date("Y-m-d 23:59:59",
- strtotime($param['end']))]];
- if ($param['companyNo'] != '') $where[] = ["a.companyNo","=",$param['companyNo']];
- $list =Db::name("pay")->alias("a")
- ->leftJoin("pay_info b","a.payNo=b.payNo and b.status=1")
- ->field("
- a.payNo 对账编号,
- b.cgdNo 采购单编号,
- b.total_fee 采购单对账金额,
- a.total_fee 对账总金额,
- a.apply_name 对账申请人,
- a.supplierName 供应商名称")
- ->where($where)
- ->cursor();
- foreach ($list as $value){
- yield $value;
- }
- }
-
- private function X(){
- $where=[['a.is_stock','=',1],['c.wsm_type','in',[2,5]],['a.is_del','=',0],['b.is_del','=',0],['c.is_del','=',0],];
- $Db= Db::connect('mysql_wsm');
- $list =$Db->name('good_basic')->alias('a')
- ->leftJoin('good_stock b','a.spuCode = b.spuCode')
- ->leftJoin('warehouse_info c','b.wsm_code = c.wsm_code')
- ->field("a.spuCode 产品编码,
- a.good_name 商品名称,
- 0 单日订单发货数量,
- b.wait_in_stock 待入库存数量,
- b.usable_stock 可用库存数量,
- b.wait_out_stock 待出库存数量,
- b.usable_stock + b.wait_out_stock 当前库存数量,
- '' 采购员,
- a.companyName 业务公司名称,
- b.wsm_code,
- c.NAME 仓库名称,
- a.supplierNo ,
- a.supplierName 供应商名称 ")
- ->where($where)->order("a.id desc")
- ->cursor();
- $account =Db::connect("mysql_sys");
- foreach ($list as $item){
- // if($item['备库部门']!=''&& !isset($depart[$item['备库部门']])){
- // $temp = getDepartByUid($item['备库部门']);
- // if(isset($temp['data']) && !empty($temp['data']))$depart[$item['备库部门']]=$temp['data'][$item['备库部门']];
- // }
- // $item['备库部门'] = $depart[$item['备库部门']]??'';
- $item['采购员'] = $account->name("supplier")->where(["code"=>$item['supplierNo']])->value("person",'');
- $item['单日订单发货数量'] = $Db->name('order_out_child')->whereDay('updatetime','today')->where
- (['spuCode'=>$item['产品编码'],'wsm_code'=>$item['wsm_code'],'is_del'=>0,"status"=>2])->sum('num');
- unset($item['wsm_code']);
- unset($item['supplierNo']);
- yield $item;
- }
- }
- }
|