wufeng 2 rokov pred
rodič
commit
88bf26492c

+ 26 - 26
app/admin/controller/Export.php

@@ -43,7 +43,7 @@ class Export extends BaseController
 
         $list = Db::name('invoice_pool')
             ->alias('a')
-            ->field('a.inv_out 卖方公司编码,a.inv_company 卖方公司名称,a.invNo 申请编号,f.department 申请部门,a.apply_name 申请人,b.buyer_title 发票买方公司名称,b.buyer_code 发票买方企业纳税识别号,b.buyer_addr 发票买方企业地址,b.buyer_mobile 发票买方企业联系方式,b.buyer_bank 发票买方企业收款银行,b.buyer_bankNo 发票买方企业财务账户,d.orderCode 公司订单号,b.buyer_title 订单企业客户,d.goodName 订单商品名,g.inv_cat_code 税收分类编码,g.inv_cat_name 税收分类名称,d.goodName 发票明细商品名称,CONCAT(d.catName,"*",d.goodName) 发票货物或应税劳务、服务名称,d.unitName 单位,d.goodNum 数量,d.goodPrice 单价,d.tax 税率,d.totalPrice 总价,a.inv_type 开票种类,a.open_type 开票方式,a.remark 申请备注,c.remark 发票备注')
+            ->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 数量,d.goodPrice 单价,round(d.tax/100,2) 税率,d.totalPrice 总价,a.inv_type 开票种类,a.open_type 开票方式,a.remark 申请备注,c.remark 发票备注')
             ->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')
@@ -204,7 +204,7 @@ class Export extends BaseController
 
         $data = Db::name('qrd_info')
             ->alias('a')
-            ->field('DATE_FORMAT(a.addtime,\'%Y\') 年,DATE_FORMAT(a.addtime,\'%m\') 月,DATE_FORMAT(a.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 PO编号,a.customerAttr 客户属性,a.branch 分公司,a.customerName 客户名称,a.firstCat 一级分类,a.goodName 产品名称,a.tax 税点,(a.goodNum-a.thNum) 下单数量,a.goodPrice 销售单价,(a.totalPrice-a.th_fee) 销售总额')
+            ->field('DATE_FORMAT(a.addtime,\'%Y\') 年,DATE_FORMAT(a.addtime,\'%m\') 月,DATE_FORMAT(a.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 PO编号,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('assoc b', 'b.orderCode=a.sequenceNo')
             ->leftJoin('trade_pool c', 'c.logNo=b.viceCode')
             ->where($where)
@@ -244,7 +244,7 @@ class Export extends BaseController
             ->field('d.cgdTime 采购单下单日期,b.companyName 业务公司名称,b.companyNo 业务公司编号,a.hpNo 对账回票编号,a.payNo 对账单号,c.cgdNo 采购单编号,a.check_time 本次回票时间,a.invoiceNumber 发票号,a.inv_amount 本次回票金额,a.inv_subtotal_amount 不含税采购成本,
             "" 税额,
             "" 票面税率,
-            d.companyName 公司回票抬头,d.goodNo 商品编号,d.firstCat 一级分类,d.fundCode 核算码,d.goodName 商品名称,d.goodNum 商品数量,d.goodUnit 单位,d.cgdSource 采购单类型,d.ownerName 采购员,d.supplierName 供应商名称,d.supplierNo 供应商编号,d.goodType 商品类型,d.tax 税率,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 退货金额,e.item_list')
+            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 退货金额,e.item_list')
             ->leftJoin('pay b', 'a.payNo=b.payNo')
             ->leftJoin('pay_info c', 'c.payNo=a.payNo')
             ->leftJoin('cgd_info d', 'd.sequenceNo=c.cgdNo')
@@ -320,7 +320,7 @@ class Export extends BaseController
             a.goodNum 下单数量,
             a.goodPrice 销售单价,
             a.totalPrice 销售总额,
-            a.tax 税点,
+            round(a.tax/100,2) 税点,
             a.inv_status 开票状态,
             a.pay_status 回款状态,
             b.ownerName 采购员,
@@ -332,11 +332,11 @@ class Export extends BaseController
             b.costPrice 工艺费,
             b.deliveryPrice 物流费,
             b.goodPrice 采购单价合计,
-            b.totalPrice 采购总货款,
-            0 毛利润,
-            0 毛利率,
-            b.tax 采购税点,
-            0 不含税采购成本,
+            ifnull(b.totalPrice,a.total_origin_price) 采购总货款,
+            (a.totalPrice -ifnull(b.totalPrice,a.total_origin_price))  毛利润,
+            round((a.totalPrice -ifnull(b.totalPrice,a.total_origin_price))/a.totalPrice,2) 毛利率,
+            round(b.tax/100,2) 采购税点,
+            round(b.totalPrice/(1+ round(b.tax/100,2)),2) 不含税采购成本,
             a.qrdType 库存性质,
             b.supplierName 供应商名称,
             b.sendType 发货方式,
@@ -374,7 +374,7 @@ class Export extends BaseController
     {
         $param = $this->request->only(['companyNo' => '', 'start' => '', 'end' => ''], 'post', 'trim');
 
-        $where = [['a.is_del', '=', 0], ['d.is_del', '=', 0]];
+        $where = [['a.is_del', '=', 0], ['d.is_del', '=', 0], ['a.status', '=', 4]];
 
         if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
         if ($param['companyNo'] != '') $where[] = ['a.inv_out', '=', $param['companyNo']];
@@ -387,14 +387,14 @@ class Export extends BaseController
             b.seller_title 销售方抬头,
             e.department 业务部门,
             e.ownerName 业务人员,
-            e.goodNum 本次开票数量,
+           ifnull((SELECT goodNum from cfp_invoice_good w where w.invNo =a.invNo and w.orderCode=e.sequenceNo),"") 本次开票数量,
             d.cancel_fee 本次开票金额,
-            a.addtime 本次开票时间,
+            c.open_date 本次开票时间,
             c.inv_number 发票号,
-            e.tax 开票税点,
+            round(e.tax/100,2) 开票税点,
             a.status 开票状态,
             e.customerName 客户名称,
-            f.fundCode 财务核算码,
+            e.fundCode 财务核算码,
             e.firstCat 一级分类,
             e.secCat 二级分类,
             e.thirdCat 三级分类,
@@ -402,19 +402,19 @@ class Export extends BaseController
             f.qrdCode 采购单编号,
             f.supplierName 卖出方公司,
             f.sendType 发货方式,
-            f.cgdType 商品类型,
+            e.qrdType 商品类型,
             f.ownerName 采购员,
-            e.goodNum 采购下单数量,
-            e.goodPrice 采购裸价,            
+            ifnull(f.goodNum,e.goodNum) 采购下单数量,
+            f.barePrice 采购裸价,            
             f.markPrice 加标费,
             f.packPrice 包装费,
             f.certPrice 证书费,
             f.openPrice 开模费,
             f.costPrice 工艺费,
             f.deliveryPrice 物流费,
-            e.goodPrice 成本合计,
-            e.totalPrice 采购货款,
-            e.tax 采购单税点,
+            f.goodPrice 成本合计,
+            ifnull(f.totalPrice,e.total_origin_price) 采购货款,
+            round(f.tax/100,2) 采购单税点,
             g.returnCode 退票编号,
             a.inv_value 退票金额,
             g.status 退票状态,
@@ -423,11 +423,11 @@ class Export extends BaseController
             f.th_fee 退货金额            
             ')
             ->leftJoin('invoice_pool_info b', 'b.invNo=a.invNo')
-            ->leftJoin('invoice_ticket c', 'c.invNo=a.invNo and c.type=0')
-            ->leftJoin('assoc d', 'd.viceCode=a.invNo')
+            ->leftJoin('invoice_ticket c', 'c.invNo=a.invNo and c.type=0 and c.status=1')
+            ->leftJoin('assoc d', 'd.viceCode=a.invNo and d.status=2 and d.type=1')
             ->leftJoin('qrd_info e', 'e.sequenceNo=d.orderCode')
             ->leftJoin('cgd_info f', 'f.qrdCode=d.orderCode')
-            ->leftJoin('invoice_return g', 'g.invNo=a.invNo')
+            ->leftJoin('invoice_return g', 'g.invNo=a.invNo and g.status=2')
             ->where($where)
             ->order(['a.id' => 'desc'])
             ->cursor();
@@ -437,7 +437,7 @@ class Export extends BaseController
         foreach ($data as $value) {
             $value['开票状态'] = $this->invoice_pool_status[$value['开票状态']] ?? '';
             $value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
-            $value['商品类型'] = $this->cgdType[$value['商品类型']] ?? '';
+            $value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
             $value['退票状态'] = $this->invoice_return_status[$value['退票状态']] ?? '';
             $list[] = $value;
         }
@@ -478,7 +478,7 @@ class Export extends BaseController
             a.branch 客户分公司,
             a.firstCat 一级分类,
             a.goodName 产品名称,
-            a.tax 税点,
+            round(a.tax/100,2) 税点,
             (a.goodNum - a.thNum) 下单数量,
             a.goodPrice 销售单价,
             (a.totalPrice - a.th_fee) 销售总额,
@@ -633,7 +633,7 @@ class Export extends BaseController
         secCat '二级分类',
         thirdCat '三级分类',
         fundCode '核算码',
-        tax '税率',
+       round(tax/100,2) '税率',
         barePrice '裸价',
         markPrice '加标费',
         certPrice '证书费',

+ 105 - 0
app/command/good.php

@@ -0,0 +1,105 @@
+<?php
+declare (strict_types = 1);
+
+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\facade\Cache;
+use think\facade\Db;
+
+class good extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('good')
+            ->setDescription('the good command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        // 指令输出
+	    $this->date=date("Y-m-d 00:00:00",time());
+	    $goodset =Cache::store("redis")->get("goodSet");
+	    if($goodset ==1) return;
+	    Cache::store("redis")->set("goodSet",1,1800);
+//	    $this->date="2022-06-01 00:00:00";
+	    try{
+		    $this->goodBasic();
+		    $this->goodZx();
+		    Cache::store("redis")->set("goodSet",0);
+	    }catch (\Exception $e){
+		    Cache::store("redis")->set("goodSet",0);
+		    $output->writeln("【".date("Y-m-d H:i:s")."】".$e->getMessage());
+	    }
+
+    }
+
+    public function addGood($data){
+    	if(empty($data)) return;
+    	foreach ($data as $v){
+			$is=Db::name("good")->where("spuCode",$v['spuCode'])->findOrEmpty();
+			if(empty($is)){
+				$array=[
+					"spuCode"=>$v['spuCode'],
+					"good_name"=>$v['good_name'],
+					"companyNo"=>$v['companyNo'],
+					"supplierNo"=>$v['supplierNo'],
+					"is_stock"=>$v['is_stock'],
+					"craft_desc"=>$v['craft_desc'],
+					"after_sales"=>$v['after_sales'],
+					"good_img"=>$v['good_img'],
+					"good_thumb_img"=>$v['good_thumb_img'],
+					"good_info_img"=>$v['good_info_img'],
+					"creater"=>$v['creater'],
+					"createrid"=>$v['createrid'],
+					"cat_name"=>$v['cat_id'],
+					"unit_name"=>$v['good_unit'],
+					"isZx"=>$v['isZx'],
+					"status"=>0,
+					"addtime"=>date("Y-m-d H:i:s"),
+					"updatetime"=>date("Y-m-d H:i:s")
+				];
+				Db::name("good")->insert($array);
+				echo "【".date("Y-m-d H:i:s")."】 添加商品{$v['spuCode']}进入类目表\r\n";
+			}
+        }
+    }
+	/**
+	* @throws \think\db\exception\DataNotFoundException
+	* @throws \think\db\exception\DbException
+	* @throws \think\db\exception\ModelNotFoundException
+	 */
+    public function goodBasic(){
+    	$list =Db::connect('mysql_wsm')
+            ->name('good_basic')
+            ->withAttr("cat_id",function ($v){
+            	return Db::connect('mysql_wsm')->name('cat')->where("id",$v)->value("cat_name","");
+            })
+            ->withAttr("good_unit",function ($m){
+            	return Db::connect('mysql_wsm')->name('unit')->where("id",$m)->value("unit","");
+            })->field("spuCode,good_name,cat_id,good_unit,craft_desc,after_sales,supplierNo,companyNo,good_img,good_info_img,good_thumb_img,creater,createrid,is_stock,0 isZx")
+            ->where("addtime",">=", $this->date)
+            ->select()->toArray();
+    	    return $this->addGood($list);
+    }
+
+    public function goodZx(){
+    	$list =Db::connect('mysql_wsm')
+            ->name('good_zixun')
+            ->withAttr("cat_id",function ($v){
+            	return Db::connect('mysql_wsm')->name('cat')->where("id",$v)->value("cat_name","");
+            })
+            ->withAttr("good_nuit",function ($v){
+            	return Db::connect('mysql_wsm')->name('unit')->where("id",$v)->value("unit","");
+            })
+            ->field("spuCode,good_name,craft_desc,'' after_sales,cat_id,good_unit,supplierNo,companyNo,good_img,good_info_img,good_thumb_img,creater,createrid,0 is_stock,1 isZx")
+            ->where("addtime",">=", $this->date)
+            ->select()->toArray();
+    	     return $this->addGood($list);
+    }
+}

+ 5 - 3
app/command/handleCxData.php

@@ -27,10 +27,11 @@ class handleCxData extends command
 
         $date = date('Y-m-d H:i:s');
 
-        //cfp_caixiao_data
+		Db::startTrans();
         $result = Db::name('caixiao_data')
             ->json(["data"])
             ->where("status",1)
+            ->lock(true)
             ->findOrEmpty();
 
         if ($result) {
@@ -421,15 +422,16 @@ class handleCxData extends command
                 if ($cgd_insert_data) Db::name('cgd_info')->insertAll($cgd_insert_data);
                 if ($wait_insert_data) Db::name('caixiao_wait')->insert($wait_insert_data);
                 Db::name("caixiao_data")->where('uniqkey',$result['uniqkey'])->update(['status'=>0]);
-
+				Db::commit();
                 $output->writeln('处理成功');
 
             } catch (Exception $exception) {
+            	Db::rollback();
                 $output->writeln($exception->getMessage());
             }
 
         }
-
+		Db::rollback();
     }
 
 }

+ 2 - 0
config/console.php

@@ -10,5 +10,7 @@ return [
 
 		'copyCxData'=>app\command\copyCxData::class,//复制采销数据到中间表
         'handleCxData'=>app\command\handleCxData::class,//处理中间表的采销数据
+
+        'Good'=>app\command\good::class,//处理中间表的采销数据
     ],
 ];

+ 2 - 3
config/database.php

@@ -34,7 +34,7 @@ return [
             // 端口
             'hostport'        => env('database.hostport', '3306'),
             // 数据库连接参数
-            'params'          => [],
+            'params'          => [PDO::ATTR_STRINGIFY_FETCHES=>true],
             // 数据库编码默认采用utf8
             'charset'         => env('database.charset', 'utf8'),
             // 数据库表前缀
@@ -72,8 +72,7 @@ return [
             // 密码
             'password'        => env('database.password1', 'root'),
             // 数据库表前缀
-            'prefix'          => env('database.prefix1
-            ', 'wsm_'),
+            'prefix'          => env('database.prefix1', 'wsm_'),
 
         ],
     ],