|
@@ -0,0 +1,139 @@
|
|
|
+<?php
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\command;
|
|
|
+
|
|
|
+use app\admin\model\GoodBasic;
|
|
|
+use app\admin\model\GoodZixun;
|
|
|
+use app\user\model\TaxRelation;
|
|
|
+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;
|
|
|
+
|
|
|
+class sysGood extends Command
|
|
|
+{
|
|
|
+ protected $date;
|
|
|
+
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ // 指令配置
|
|
|
+ $this->setName('sysgood')
|
|
|
+ ->setDescription('the sysgood command');
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function execute(Input $input, Output $output)
|
|
|
+ {
|
|
|
+ $this->date = date('Y-m-d H:i:s', time() - 3600);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $this->processGoods('goodBasic');
|
|
|
+ $this->processGoods('goodZx');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $output->writeln('【' . date('Y-m-d H:i:s') . '】' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function processGoods($method)
|
|
|
+ {
|
|
|
+ $goods = call_user_func([$this, $method]);
|
|
|
+
|
|
|
+ if (empty($goods)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->addGood($goods);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function goodBasic()
|
|
|
+ {
|
|
|
+ return $this->processGood(GoodBasic::class, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function goodZx()
|
|
|
+ {
|
|
|
+ return $this->processGood(GoodZixun::class, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function processGood($modelClass, $isZx)
|
|
|
+ {
|
|
|
+ $with = ["unit", "cat", "goodTax"=>["outCategory", "inCategory"]];
|
|
|
+
|
|
|
+ $fields = "spuCode,good_name,craft_desc,supplierNo,companyNo,supplierName,companyName,good_img,
|
|
|
+ good_info_img,good_thumb_img,creater,createrid,{$isZx} as isZx,is_combind,cgd_supplier_code cgd_supplierNo,
|
|
|
+ cgd_supplier_name cgd_supplierName,isChild,addtime,updatetime";
|
|
|
+ if ($isZx == 0) {
|
|
|
+ $fields .=",after_sales,is_stock";
|
|
|
+ }else{
|
|
|
+ $fields .=",'' after_sales, 0 is_stock";
|
|
|
+ }
|
|
|
+
|
|
|
+ return $modelClass::with($with)
|
|
|
+ ->field($fields)
|
|
|
+ ->where('updatetime', '>=', $this->date)
|
|
|
+ ->where('status', '=', 1)
|
|
|
+ ->where('is_del', 0)
|
|
|
+ ->select()
|
|
|
+ ->each(function (&$item){
|
|
|
+ $this->populateItem($item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function populateItem(&$item)
|
|
|
+ {
|
|
|
+ $item['tax_id'] = $item['tax_id'] ?? 0;
|
|
|
+ $item['cgd_inv_good_name'] = $item['cgd_inv_good_name'] ?? '';
|
|
|
+ $item['inv_cat_name'] = '';
|
|
|
+ $item['inv_cat_code'] = '';
|
|
|
+ $item['inv_tax'] = '';
|
|
|
+ $item['inv_good_name'] = $item['cgd_inv_good_name'] ?? '';
|
|
|
+ $item['cgd_inv_cat_code'] = '';
|
|
|
+ $item['cgd_inv_cat_name'] = '';
|
|
|
+ $item['cgd_inv_tax'] = isset($item['cgd_inv_tax'])?(str_replace('%','',$item['cgd_inv_tax'])/100):"";
|
|
|
+ $item['cat_diff'] = 0;
|
|
|
+ $item['tax_diff'] = 0;
|
|
|
+
|
|
|
+ if (!is_null($item['tax_id']) && $item['tax_id'] != 0) {
|
|
|
+ $taxInfo = TaxRelation::with(["incomeTax", "outputTax"])
|
|
|
+ ->where(['income_tax_id' => $item['tax_id'], "companyNo" => $item['companyNo']])
|
|
|
+ ->findOrEmpty();
|
|
|
+
|
|
|
+ if (!$taxInfo->isEmpty()) {
|
|
|
+ $item['inv_cat_name'] = $taxInfo['output_short_name'];
|
|
|
+ $item['inv_cat_code'] = $taxInfo['output_merge_code'];
|
|
|
+ $item['inv_tax'] = str_replace("%",'',$taxInfo['output_bind_tax'])/100;
|
|
|
+ $item['cgd_inv_cat_code'] = $taxInfo['income_merge_code'];
|
|
|
+ $item['cgd_inv_cat_name']= $taxInfo['income_short_name'];
|
|
|
+ $item['cat_diff'] = $taxInfo['output_merge_code']===$taxInfo['income_merge_code']?1:2;
|
|
|
+ $item['tax_diff'] = $taxInfo['output_bind_tax']===$item['cgd_inv_tax']?1:2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $item['status'] = ($item['inv_cat_code'] != '' && $item['cgd_inv_cat_code'] != '') ? 2 : (($item['inv_cat_code'] != '' || $item['cgd_inv_cat_code'] != '') ? 1 : 0);
|
|
|
+ }
|
|
|
+ protected function addGood($goods)
|
|
|
+ {
|
|
|
+ $spuCode = array_column($goods->toArray(), 'spuCode');
|
|
|
+ $idsArr = (new \app\cxinv\model\Good())
|
|
|
+ ->whereIn('spuCode', $spuCode)
|
|
|
+ ->column('id,status,updatetime', 'spuCode');
|
|
|
+ $saveAll = [];
|
|
|
+ foreach ($goods as $item) {
|
|
|
+ if (!isset($idsArr[$item['spuCode']]) ||
|
|
|
+ ($idsArr[$item['spuCode']]['updatetime'] != $item['updatetime'])) {
|
|
|
+ $item['id'] = $idsArr[$item['spuCode']]['id'] ?? null;
|
|
|
+ $saveAll[] = $item->toArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($saveAll)) {
|
|
|
+ try {
|
|
|
+ (new \app\cxinv\model\Good())->saveAll($saveAll);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|