瀏覽代碼

Merge branch 'master-new-wgg' of wugg/phpstock into master-new

wugg 1 年之前
父節點
當前提交
d80ab19cc3

+ 0 - 2
app/admin/controller/Consult.php

@@ -535,8 +535,6 @@ class Consult extends Base
                 "brand_id"=>$brand_id,
                 "arrival_time"=>$arrival_time,
                 "specinfo"=>json_encode($specinfo),
-//                "color"=>$color,
-//                "material"=>$material,
                 "cost_desc"=>$cost_desc,
                 "is_addrs"=>$is_addrs,
                 "is_custom"=>$is_custom,

+ 3 - 4
app/admin/controller/Good.php

@@ -5,7 +5,7 @@ namespace app\admin\controller;
 
 use app\admin\model\DataGroup as DataGroupModel;
 use app\admin\model\GoodCombind;use app\admin\model\GoodLog;
-use app\admin\model\GoodStock;use app\txx\model\YzGood;
+use app\admin\model\GoodStock;use app\txx\model\ActGoodurl;use app\txx\model\YzGood;
 use think\App;
 use think\db\Raw;
 use think\facade\Db;
@@ -317,13 +317,12 @@ class Good extends Base
             $value["brand_name"] = $brand[$value['brand_id']]??'';//isset($brand['brand_name']) ? $brand['brand_name'] : "";
 //            $unit = Db::name("unit")->field('id,unit')->where(["id" => $value['good_unit']])->find();
             $value['unit'] = $unit[$value['good_unit']]??'';//isset($unit['unit']) ? $unit['unit'] : "";
-//            $company = Db::name("business")->field('id,company')->where(["companyNo" => $value['companyNo']])->find();
+
             $value['company'] = $names['data'][$value['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
             $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
             $value['status'] = $value['exam_status'];
             $value['exclusive'] = makeExcluse($value['is_exclusive']);
-//            $value['good_info_img']=$value['good_info_img'];
-//            $value['good_img']=$value['good_img'];
+            $value['is_act_url'] =ActGoodurl::where(["act_good_id"=>$value["platform_youzan_id"],"is_del"=>0])->value("act_good_url",'');
             $spec = Db::name("good_spec")
                 ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
                 ->select()

+ 1 - 0
app/admin/controller/Purch.php

@@ -401,6 +401,7 @@ class Purch extends Base
 //            $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
             $goon['supplier_cgderid'] = $supplier['data']['personid'] ?? '';
             $goon['supplier_cgder'] = $supplier['data']['person'] ?? '';
+            $data['pay_type'] = $supplier['data']['pay_type'] ?? '';
             $goon['supplierName'] = isset($supplier['data']['name']) ? $supplier['data']['name'] : "";
             $goon['noble_name'] = isset($goon['noble_metal']) && $goon['noble_metal'] != 0 ? $this->noble[$goon['noble_metal']] : "";
 

+ 23 - 10
app/admin/controller/Sale.php

@@ -9,7 +9,7 @@ use app\admin\model\GoodLog;
 use app\admin\model\GoodStockInfo;
 use app\admin\model\OrderOutChild;use app\admin\model\ProcessOrder;
 use app\admin\model\SaleInfo;
-use Exception;
+use app\bbc\model\BbcFill;use Exception;
 use think\App;
 use think\facade\Cache;
 use think\facade\Config;
@@ -514,7 +514,8 @@ class Sale extends Base
         //判断该供应商是否开通了供应商账号
         $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
 
-        $cg = ["cgdNo" => $cgdCode,
+        $cg = [
+        	"cgdNo" => $cgdCode,
             "bkcode" => "",
             "wsm_code" => $wsm_code,
             "cgder" => $data['creater'],
@@ -5201,7 +5202,7 @@ class Sale extends Base
             ->alias('a')
             ->field('a.id sale_id,a.good_code,a.platform_order,a.good_name,a.wsend_num,a.total_price,a.order_type,
             a.status sale_status,a.orderCode,a.cat_id,a.good_createrid,c.id cgd_id,c.status cgd_status,c.cgdNo,c.cgder_id,
-            a.addtime,c.wsm_code')
+            a.addtime,c.wsm_code,a.order_source,a.other_orderNo')
             ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
             ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
             ->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
@@ -5292,7 +5293,7 @@ class Sale extends Base
                 }else{
                 	$good = Db::name('good_stock')->where(['spuCode' => $sale['good_code'],'wsm_code'=>$sale['wsm_code']])
                 		->findOrEmpty();
-	                    if (empty($good)) throw new Exception('未找到商品信息');
+	                if (empty($good)) throw new Exception('未找到商品信息');
                 	if($sale['cgd_status']==1){
 	                    $stock = Db::name('good_stock')->where($good)
 	                    ->inc('wait_in_stock',$sale['wsend_num'])
@@ -5302,13 +5303,15 @@ class Sale extends Base
                 	
                 	if($sale['cgd_status']==3){
                 		$wait_out= Db::name('order_out_child')
-		                ->where(['is_del' => 0, 'orderCode' => $sale['orderCode'],"status"=>[1,2,3]])
+		                ->where(['is_del' => 0, 'orderCode' => $sale['orderCode'],"status"=>1])
 		                ->sum('num');
                 		$usable = $sale['wsend_num'] - intval($wait_out);
-                		$stock = Db::name('good_stock')->where($good)
-	                    ->inc('usable_stock',$usable)
-	                    ->update();
-	                    if ($stock == false) throw new Exception('商品库存更新失败');
+                		if($usable>0){
+			                $stock = Db::name('good_stock')->where($good)
+			                           ->inc('usable_stock',$usable)
+			                           ->update();
+			                if ($stock == false) throw new Exception('商品库存更新失败');
+		                }
                 	}
                 }
                 if($sale['order_type'] == 4){
@@ -5337,6 +5340,16 @@ class Sale extends Base
                                             'wait_name'=>0,
                                         ]);
                 }
+                
+                 if($sale['order_source'] == 11){
+                    $fill =(new BbcFill())->where(['fillCode'=>$sale['other_orderNo']])->findOrEmpty();
+                    if($fill->isEmpty()) throw new Exception($sale['orderCode'] . '未找到对应得业务报备单');
+                    if($fill->transfer_num <$sale['wsend_num'])throw new Exception($sale['orderCode'] . '对应得业务报备单已转单数量不足');
+		            $fill->transfer_num -=$sale['wsend_num'];
+		            $fill->status=$fill->transfer_num >0?2:1;
+		            $upd=$fill->save();
+		            if($upd==false)throw new \Exception('业务报备单更新失败');
+                }
 				 $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$sale['orderCode'], "isCgd"=>1]);
 				if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
 					throw new Exception($fininfo['message']??"结算校验失败");
@@ -5397,8 +5410,8 @@ class Sale extends Base
                 	'status' => 3,
                 	'th_num' => Db::raw("wsend_num"),
                 	'th_fee' =>Db::raw("total_price"),
-                	'wsend_num' =>0,
                 	'send_num' =>Db::raw("wsend_num"),
+                	'wsend_num' =>0,
                 	'send_status' =>3,
                 	'updatetime' => $date
                 	]);

+ 2 - 2
app/admin/controller/SaleReport.php

@@ -3249,7 +3249,7 @@ class SaleReport extends Base
 		foreach ($list as $value){
 			$value['stock_num'] = Db::name("good_stock")->where("spuCode",$value['good_code'])->sum("usable_stock");
 			if($value['is_stock']==1){
-				$value['good_price'] = Db::name("purchease_order")->where(["spuCode"=>$value['good_code'],"order_source"=>0])->value("good_price",0);
+				$value['good_price'] = Db::name("purchease_order")->where(["spuCode"=>$value['good_code'],"order_source"=>0])->order('id desc')->value("good_price",0);
 				$value['total_fee'] = bcmul($value['good_price'],$value['good_num'],2);
 			}
 			$data[]= $value;
@@ -3287,7 +3287,7 @@ class SaleReport extends Base
 		foreach ($list as $value){
 			$value['当日剩余可用库存'] = Db::name("good_stock")->where("spuCode",$value['商品编号'])->sum("usable_stock");
 			if($value['is_stock']==1){
-				$value['库存采购单价'] = Db::name("purchease_order")->where(["spuCode"=>$value['商品编号'],"order_source"=>0])->value("good_price",0);
+				$value['库存采购单价'] = Db::name("purchease_order")->where(["spuCode"=>$value['商品编号'],"order_source"=>0])->order('id desc')->value("good_price",0);
 				$value['当日库存消耗金额'] = bcmul($value['库存采购单价'],$value['当日库存销售'],2);
 			}
 			unset($value['is_stock']);

+ 163 - 0
app/admin/listener/Cgdmake.php

@@ -0,0 +1,163 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\listener;
+
+use app\admin\model\Good;
+use app\admin\model\GoodLog;use app\admin\model\GoodNake;
+use app\admin\model\GoodStock;use app\admin\model\OrderOut;use app\admin\model\OrderSend;use app\admin\model\PurcheaseOrder;
+use app\admin\model\Sale;
+use app\admin\model\WarehouseInfo;
+use app\bbc\model\BbcFill;
+use app\admin\model\OrderNum;use app\model\AccountCompany;
+class Cgdmake
+{
+    /**
+     * 非库存品生成cgd
+     *
+     * @return mixed
+     */
+    public function handle($event)
+    {
+        $orderinfo = (new Sale())->where(["orderCode"=>$event])->findOrEmpty();
+        if($orderinfo->isEmpty()==false&& $orderinfo->order_type!=1){
+            $cgdCode = makeNo('CG');
+            $wsm =(new WarehouseInfo())->where(['supplierNo' => $orderinfo->supNo, 'companyNo' =>$orderinfo->supplierNo, 'wsm_type' => 2,
+          'is_del' => 0])->findOrEmpty();
+         if($wsm->isEmpty()){
+         	 $wsm_code = makeNo('WSM');
+            $inwsm = [
+                'wsm_code' => $wsm_code,
+                'name' => $orderinfo->supName,
+                'wsm_type' => 2,
+                'supplierNo' => $orderinfo->supNo,
+                'supplierName' => $orderinfo->supName,
+                'addr' => '',
+                'addrs_code' => '',
+                'contactor' => $orderinfo->cgderid ,
+                'contactor_name' => $orderinfo->cgder ,
+                'mobile' => '',
+                'position' => '',
+                'companyNo' => $orderinfo->supplierNo,
+                'companyName' => $orderinfo->supplierName,
+                'status' => 1,
+                'is_del' => 0,
+                'addtime' => date('Y-m-d H:i:s'),
+                'updatetime' => date('Y-m-d H:i:s'),
+                'createrid' => $orderinfo->apply_id,
+                'creater' => $orderinfo->apply_name,
+                'updaterid' => $orderinfo->apply_id,
+                'updater' => $orderinfo->apply_name,
+            ];
+            WarehouseInfo::create($inwsm);
+	         }else {
+	            $wsm_code = $wsm['wsm_code'];
+	        }
+         //判断该供应商是否开通了供应商账号
+        $from_tag=AccountCompany::IsOpenAccount($orderinfo->supNo);
+         $info = (new BbcFill())->where(["fillCode"=>$orderinfo->other_orderNo])->findOrEmpty();
+         if($info->isEmpty())return;
+		 if($info->fill_type==2){
+        	 $origins=(new GoodNake())->where([['spuCode', '=', $orderinfo->good_code], ['min_num', '<=',
+        	 $info->good_num], ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
+        	 $good = (new Good())->where(['spuCode'=>$orderinfo->good_code])->findOrEmpty();
+        	 $origin =array_merge($good->toArray(),$origins->toArray());
+        }
+        if($info->fill_type==3){
+        	 $origin =(new \app\admin\model\ConsultBids())->where([['spuCode', '=', $orderinfo->good_code] ,['is_del', '=',
+        	 0]])->findOrEmpty()->toArray();
+        }
+        $cg = [
+        	'cgdNo' => $cgdCode,
+            'bkcode' => '',
+            'wsm_code' => $wsm_code,
+            'cgder' => $orderinfo->cgder,
+            'cgder_id' => $orderinfo->cgderid,
+            'spuCode' => $orderinfo->good_code,
+            'skuCode' => $orderinfo->skuCode,
+            'good_name' => $orderinfo->good_name,
+            'good_num' => $orderinfo->good_num,
+            'good_price' => $orderinfo->origin_price,
+            'total_fee' => round(bcmul($orderinfo->origin_price , $orderinfo->good_num,4),2),
+            'pakge_fee' => $origin['pakge_fee']??"0",
+            'cert_fee' => $origin['cert_fee']??'0',
+            'open_fee' => $origin['open_fee']??'0',
+            'teach_fee' => $origin['cost_fee']??'0',
+            'mark_fee' => $origin['mark_fee']??'0',
+            'demo_fee' => $origin['demo_fee']??'0',
+            'nake_fee' => $origin['nake_fee']??'0',
+            'weight' => $origin['weight'],
+            'delivery_fee' => $origin['delivery_fee']??0,
+            'gold_price' =>0,
+            'diff_weight' => '0',
+            'diff_fee' => '0',
+            'supplierNo' => $orderinfo->supNo ,
+            'supplier_name' => $orderinfo->supName,
+            'companyNo' => $orderinfo->supplierNo,
+            'companyName' => $orderinfo->supplierName,
+            'send_status' => 1,
+            'send_num' => 0,
+            'wsend_num' => $orderinfo->good_num,
+            'remark' => '',
+            'status' => 0,//0初始化
+            'lasttime' => date('Y-m-d H:i:s'),
+            'is_del' => 0,
+            'order_type' => $orderinfo->order_type,
+            'order_source' =>11,
+            'good_type' =>  $orderinfo->good_type,
+            'addtime' => date('Y-m-d H:i:s'),
+            'updatetime' => date('Y-m-d H:i:s'),
+            'good_createrid' => $origin['createrid'],
+            'good_creater' => $origin['creater'],//商品创建人
+            'from_tag' => $from_tag==false ? 2 : 1,//来源标签:1采销(默认),2供应商端
+        ];
+        $cgd=PurcheaseOrder::create($cg);
+                $events=['order_type' => 'CGD',
+                        'order_code' =>$cgdCode,//咨询单详情编号
+                        'order_id' =>  $cgd->id,
+                        'order_status' => 2,
+                        'action_process' =>0,
+                        'action_status' => 0,
+                        'action_uid' => $orderinfo->apply_id,
+                        'action_name' => $orderinfo->apply_name,
+             ];
+        event('ProcessOrder',$events);
+        $orderOut= (new OrderOut())->where(["orderCode"=>$orderinfo->orderCode])
+        ->field("outCode,'{$cgdCode}' cgdNo,send_num")->select();
+        if($orderOut->isEmpty()==false) (new OrderSend())->saveAll($orderOut->toArray());
+         $rela = [
+                'orderCode' => $event,
+                'cgdNo' => $cgdCode,
+                'spuCode' => $orderinfo->good_code,
+                'good_num' => $orderinfo->good_num,
+                'wsend_num' =>$orderinfo->good_num,
+                'send_num' => 0,
+                'wait_num' => 0,
+                'status' => 1,
+                'source' => 2
+            ];
+         OrderNum::create($rela);
+         $goodstock =new GoodStock();
+         $stockinfo = $goodstock->where(['spuCode' =>$orderinfo->good_code, 'wsm_code' => $wsm_code, 'is_del' => 0])->findOrEmpty();
+         if($stockinfo->isEmpty()){
+             $stokc = [
+                        'spuCode' => $orderinfo->good_code,
+                        'wsm_code' => $wsm_code,
+                        'wait_in_stock' => $orderinfo->good_num,
+                        'wait_out_stock' => 0,
+                        'usable_stock' => 0,
+                        'intra_stock' => 0,
+                        'total_stock' => 0,
+                        'status' => 1,
+                        'addtime' => date('Y-m-d H:i:s'),
+                        'updatetime' => date('Y-m-d H:i:s')
+                    ];
+           $stockinfo=  GoodStock::create($stokc);
+         }else{
+           $stockinfo->inc( 'wait_in_stock' ,$orderinfo->good_num)->update();
+         }
+          $good_data[] = ['good_log_code' => $cgdCode, 'stock_id' =>$stockinfo->id, 'type' => 1,'stock' => $orderinfo->good_num, 'stock_name' => 'wait_in_stock'];
+          GoodLog::LogAdd(['id'=>$orderinfo->apply_id,'nickname'=>$orderinfo->apply_name], $good_data, 'CGD');
+      }
+    }
+}

+ 14 - 0
app/admin/model/BargainOrder.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class BargainOrder extends Model
+{
+    protected $updateTime="updatetime";
+}

+ 14 - 0
app/admin/model/ConsultBids.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ConsultBids extends Model
+{
+   protected $updateTime="updatetime";
+}

+ 19 - 0
app/admin/model/ConsultInfo.php

@@ -0,0 +1,19 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ConsultInfo extends Model
+{
+ 
+	public function consultOrder(){
+		return $this->belongsTo(ConsultOrder::class,"zxNo","zxNo")
+		->bind(["creater","createrid","is_project","projectNo","khNo","khName","companyNo","companyName","endtime","area",
+		"platform_id"=>"platform_code","saleid","salesman"]);
+	}
+}

+ 14 - 0
app/admin/model/ConsultOrder.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ConsultOrder extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/GoodZixun.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodZixun extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/OrderAddr.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderAddr extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/OrderNum.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderNum extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/OrderOut.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderOut extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/OrderSend.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class OrderSend extends Model
+{
+    //
+}

+ 6 - 1
app/admin/model/Sale.php

@@ -10,5 +10,10 @@ use think\Model;
  */
 class Sale extends Model
 {
-    //
+	protected static $order_source=[1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞', 6 => '售后补换货', 7 => '报备转单',
+	 8 => '支付渠道', 9 => '采销录单',10 => '结算录单', 11 => '业务报备单',];
+	protected static $order_type=[1=>"库存商品",2=>"非库存商品",3=>"咨询商品",4=>"报备商品"];
+	protected static $order_status=["未发货","部分发货","全部发货","取消订单"];
+	protected static $send_status=["","未发货","部分发货","全部发货"];
+	protected static $good_type=["","正常商品","赠品","样品"];
 }

+ 3 - 1
app/bbc/controller/Base.php

@@ -9,7 +9,9 @@ use think\Response;
 
 class Base extends \app\admin\controller\Base
 {
-  public function __construct(App $app) {parent::__construct($app);}
+  public function __construct(App $app) {
+  	parent::__construct($app);
+  }
   
    /**
 	* @param string $message

+ 479 - 0
app/bbc/controller/Fill.php

@@ -0,0 +1,479 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\bbc\controller;
+
+use app\admin\model\BargainOrder;
+use app\admin\model\ConsultBids;
+use app\admin\model\ConsultInfo;
+use app\admin\model\GoodNake;
+use app\admin\model\GoodPlatform;
+use app\admin\model\GoodZixun;
+use app\admin\model\OrderAddr;
+use app\admin\model\OrderOut;
+use app\admin\model\OrderOutChild;
+use app\admin\model\Sale;
+use app\bbc\model\BbcFill;
+use app\model\Headquarters;
+use app\model\Supplier;
+use think\App;
+use think\facade\Validate;
+use think\Request;
+
+class Fill extends Base
+{
+	protected $model=null;
+	public function __construct(App $app) {
+		parent::__construct($app);
+		$this->model=new BbcFill();
+	}
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function list()
+    {
+        $param=$this->request->param(["cat_id"=>"","start"=>"",'end'=>'',"fillCode"=>"","status"=>"","good_name"=>"",
+        "spuCode"=>"","companyNo"=>"","customerCode"=>"","is_compliance"=>"","page"=>1,"size"=>15],"post","trim");
+        $where=[];
+        $param['companyNo']==""?:$where[]=["companyNo","like","%{$param['companyNo']}%"];
+        $param['customerCode']==""?:$where[]=["customerCode","like","%{$param['customerCode']}%"];
+        $param['fillCode']==""?:$where[]=["fillCode","like","%{$param['fillCode']}%"];
+        $param['good_name']==""?:$where[]=["good_name","like","%{$param['good_name']}%"];
+        $param['spuCode']==""?:$where[]=["spuCode","like","%{$param['spuCode']}%"];
+        $param['is_compliance']===""?:$where[]=["is_compliance","=",$param['is_compliance']];
+        $param['cat_id']===""?:$where[]=["cat_id","=",$param['cat_id']];
+        $param['status']===""?:$where[]=["status","=",$param['status']];
+        
+        $list=$this->model->with(["unitT","cat","brand","platform"])
+        ->where($where)
+        ->order("id desc")
+        ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
+   
+    }
+
+    /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function create()
+    {
+        $param = $this->request->param([
+        	"companyNo"=>"",
+        	"customerCode"=>"",
+        	"platform_id"=>"",
+        	"good_num"=>"",
+        	"good_price"=>"",
+        	"skuCode"=>"",
+        	"manager"=>"",
+        	"managerid"=>"",
+        	"fill_remark"=>""
+        	],"post","trim");
+        $valid=Validate::rule([
+        	"companyNo|业务公司"=>"require|max:255",
+        	"customerCode|客户公司"=>'require|max:255',
+        	"platform_id|平台"=>'require|number',
+        	"good_num|商品数量"=>'require|number|gt:0',
+        	"good_price|商品单价"=>'require|float|gt:0',
+        	"skuCode|商品编号"=>'require|max:255',
+        	'manager|业务经理'=>'require',
+        	'managerid|业务经理id'=>'require',
+        	'fill_remark|订单备注'=>'require'
+        	]);
+        if($valid->check($param)==false) $this->error($valid->getError());
+        $head=new Headquarters();
+        $company = $head->where(["code"=>[$param['companyNo'],$param['customerCode']]])->column("name","code");
+        if(empty($company))$this->error("未找到相关业务公司/客户名称信息");
+        $goodinfo = (new GoodPlatform())->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")
+        ->where("skuCode",$param['skuCode'])
+        ->field("skuCode,b.spuCode,platform_code platform_id,plat_code,good_name,
+        cat_id,exam_status,brand_id,good_unit unit_id,supplierNo,supplierName,if(is_stock=1,1,2) fill_type")
+        ->findOrEmpty();
+        if($goodinfo->isEmpty()) $this->error("商品信息未找到");
+        if($goodinfo->exam_status!=3) $this->error("商品未上线");
+        $origin_price=0;
+		if($goodinfo->fill_type==2){
+        	 $origin =(new GoodNake())->where([['spuCode', '=', $goodinfo->spuCode], ['min_num', '<=', $param['good_num']],
+        	 ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
+                if ($origin->isEmpty()) $this->error('未找到商品相关阶梯成本价格');
+                $origin_price = $origin->nake_total;
+        }
+        $data=[
+        	"fillCode"=>makeNo("BF"),
+        	"total_price"=>bcmul($param['good_num'],$param['good_price'],4),
+        	"origin_price"=>$origin_price,
+        	"apply_id"=>$this->uid,
+        	"apply_name"=>$this->uname,
+        	"status"=>1,
+        	"is_compliance"=>1,
+        	"companyName"=>$company[$param['companyNo']]?:"",
+        	"customerName"=>$company[$param['customerCode']]?:"",
+        ];
+        $create= array_merge($data,$param,$goodinfo->toArray());
+        BbcFill::create($create);
+        $this->success("业务报备信息创建成功");
+    }
+
+    /**
+     * 是否合规审核
+     *
+     * @param  \think\Request  $request
+     * @return \think\Response
+     */
+    public function compliance()
+    {
+        $param=$this->request->param(["id"=>"","is_compliance"=>"","plat_code"=>"","compliance_remark"=>""],"post","trim");
+        $valid =Validate::rule([
+        	"id|主键id"=>"require|number|gt:0",
+            "is_compliance|是否合规"=>"require|number|in:1,2",
+            "compliance_remark|合规备注"=>"requireIf:is_compliance,2",
+            "plat_code|BBC平台商品编号"=>"requireIf:is_compliance,1"
+            ]);
+        if($valid->check($param)==false) $this->error($valid->getError());
+        $info= $this->model->findOrEmpty($param['id']);
+        if($info->isEmpty())$this->error("未找到报备单数据");
+        $info->is_compliance = $param['is_compliance'];
+        $info->compliance_remark = $param['compliance_remark'];
+        $info->plat_code = $param['plat_code'];
+        $up =$info->save();
+        $up?$this->success("报备单更新成功"):$this->error("报备单更新失败");
+    }
+
+    /**
+        报备转单
+     */
+    public function transfer()
+    {
+        
+        $param = $this->request->only([
+        'id'=>"",
+        'addr_list'=>[],
+        'customerCode'=>'',
+        "poCode"=>""
+        ], 'post',"trim");
+          $val = Validate::rule([
+            'id|报备的主键id' => 'require|number|gt:0',
+            'customerCode|客户编号'=>'require|max:255',
+            'addr_list|收货地址' => 'require|array|max:100',
+            'poCode|平台订单号' => 'require|max:255',
+        ]);
+        if ($val->check($param)==false)$this->error( $val->getError());
+
+        $val2 = Validate::rule([
+            'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
+            'contactor|联系人' => 'require|max:255',
+            'mobile|联系电话' => 'require|mobile',
+            'addr_code|收货省市区编码' => 'array|length:3',
+            'addr|详细地址' => 'require|max:255',
+        ]);
+        $info = $this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()) $this->error("未找到报备单数据");
+        if($info->status==3 ||$info->status==4 )$this->error('报备单数据'.BbcFill::$status_cn[$info->status]);
+        $head=new Headquarters();
+        $company = $head->where(['code'=>$param['customerCode']])->findOrEmpty();
+        if($company->isEmpty())$this->error('未找到相关客户名称信息');
+        if($info->fill_type!=3) $good =(new \app\admin\model\Good())->where(["spuCode"=>$info->spuCode])->findOrEmpty();
+        else $good=(new ConsultBids())->where(['spuCode'=>$info->spuCode])->findOrEmpty();
+        if($good->isEmpty())$this->error('未找到商品信息');
+        $supplier = (new Supplier())->where(["code"=>$info->supplierNo])->findOrEmpty();
+        if($supplier->isEmpty())$this->error('未找到供应商信息');
+        $orderCode= makeNo("QR");
+        $orderArr=[];
+        $transNum=0;
+        foreach ($param["addr_list"] as $item){
+        	if ($val2->check($item)==false)$this->error( $val2->getError());
+        	$temp=['orderCode' => $orderCode,
+                    'addr' => $item['addr'],
+                    'addr_code' =>empty( $item['addr_code'])?'': implode(',', $item['addr_code']),
+                    'contactor' => $item['contactor'],
+                    'mobile' => $item['mobile'],
+                    'customer_code' => $param['customerCode'],
+                    'post_fee' => 0,
+                    'receipt_quantity' => $item['receipt_quantity'],
+                    'is_del' => 0,
+                    'addtime' => date("Y-m-d H:i:s"),
+                    'updatetime' => date('Y-m-d H:i:s')
+                    ];
+        	$transNum+=$item['receipt_quantity'];
+        	$orderArr[]=$temp;
+        }
+        if($info->fill_type==1 && $good->usable_stock< $transNum) $this->error('商品可用库存不足');
+        $orderInfo=[
+        	    'orderCode' => $orderCode,
+                'apply_id' => $this->uid,
+                'apply_name' => $this->uname,
+                'order_type' => $info->fill_type,//报备商品
+                'order_source' => 11,//业务报备转单
+                'platform_id' => $info->platform_id,
+                'good_code' =>  $info->spuCode,
+                'skuCode' =>  $info->skuCode,
+                'cat_id' => $info->cat_id,
+                'good_name' =>  $info->good_name,
+                'good_num' => $transNum,
+                'good_type' => 1,
+                'origin_price' => $info->origin_price,
+                'sale_price' => round($info->good_price,2),
+                'total_price' => round(bcmul($info->good_price, strval($transNum), 4), 2),
+                'post_fee' => 0,
+                'is_diff' => $good->is_diff,
+                'is_activity' => 0,
+                'activity_code' => '',
+                'is_stock' => 0,
+                'customer_code' => $param['customerCode'],
+                'customerName' => $company['name'],
+                'supplierNo' => $info->companyNo,
+                'supplierName' => $info->companyName,
+                'supNo' =>$info->supplierNo,
+                'supName' => $info->supplierName,
+                'zxNo' =>$good->bidNo?: '',
+                'platform_order' =>$param['poCode'],
+                'send_num' => 0,
+                'wsend_num' =>$transNum,
+                'th_num' => 0,
+                'th_fee' => 0,
+                'send_status' => 1,
+                'send_type' => 1,//直接发货
+                'remark' => '',
+                'status' => 0,
+                'is_del' => 0,
+                'proof_id' => 0,
+                'other_orderNo' => $info->fillCode,
+                'workNo' => '',
+                'poNo' => '',
+                'use_order' => 0,
+                'good_weight' => 0,
+                'gold_price' => 0,
+                'cost_price' => $good->cost_fee,
+                'diff_weight' => 0,
+                'diff_fee' => 0,
+                'returnCode' => '',
+                'addtime' => date("Y-m-d H:i:s"),
+                'updatetime' =>date('Y-m-d H:i:s'),
+                'cgderid' => $supplier->personid,
+                'cgder' => $supplier->person,
+                'good_createrid' => $good['createrid'],
+                'good_creater' =>$good['createrid'],
+                'manager'=>$info->manager,
+                'managerid'=>$info->managerid
+                ];
+        $this->model->startTrans();
+        try{
+        	$ist =$this->model->lock(true)->findOrEmpty($param['id']);
+        	if($ist->wtrans_num< $transNum)throw new \Exception('报备单可转单数量不足!');
+        	$order=Sale::create($orderInfo);
+        	if($order->id==false) throw new \Exception("订单创建失败");
+        	 $Addr=(new OrderAddr())->saveAll($orderArr);
+        	 //库存品转单直接生成数据
+        	if($info->fill_type==1){
+        		$up = (new \app\admin\model\Good())->where(["spuCode"=>$info->spuCode])->lock(true)->findOrEmpty();
+        		 if($up->isEmpty())throw new \Exception('未找到商品信息');
+        		 if($up->usable_stock< $transNum)throw new \Exception('商品可用库存不足');
+        		 $up->usable_stock= $up->usable_stock-$transNum;
+        		 $up->updatetime=date('Y-m-d H:i:s');
+        		 $goodUp=$up->save();
+        		 if($goodUp==false)throw new \Exception('商品库存修改失败');
+        	}
+        	$i=0;
+        	foreach ($Addr as $item){
+        		 	$outCode = substr(makeNo('DF'), 0, -2) . str_pad(strval($i), 2, '0', STR_PAD_LEFT);
+                     $i++;
+        		 	$out=[
+        		 	       'orderCode' => $orderCode,
+                           'outCode' => $outCode,
+                           'apply_id' => $this->uid,
+                           'apply_name' => $this->uname,
+                           'addrid' => $item->id,
+                           'post_name' => '',
+                           'post_code' => '',
+                           'post_fee' => 0,
+                           'sendtime' => date('Y-m-d H:i:s'),
+                           'send_num' => $item->receipt_quantity,
+                           'check_num' => 0,
+                           'error_num' => 0,
+                           'wsm_code' => '',
+                           'order_type' =>$info->fill_type,
+                           'status' => 0,
+                           'send_status' => $info->fill_type==1?1:0,
+                           'addtime' => date('Y-m-d H:i:s'),
+                           'updatetime' => date('Y-m-d H:i:s')
+                          ];
+        		 	    $outinfo=OrderOut::create($out);
+        		 	    if($outinfo->isEmpty())throw new \Exception('发货单创建失败');
+        		 	    if($info->fill_type==1)OrderOutChild::makeChild($outCode);
+        		 }
+        	$ist->transfer_num +=$transNum;
+        	$ist->status=$ist->transfer_num >= $ist->good_num?3:2;
+        	$upd=$ist->save();
+        	if($upd==false)throw new \Exception('报备单更新失败');
+             $this->model->commit();
+		   	//非库存数据需要生成采购单 异步监听事件处理 需要注意采购单生成失败无法回滚
+            if($info->fill_type!==1){
+            	event("CgdCreate",$orderCode);
+            }
+            $event=[ 'order_type' => 'CKD',
+		                        'order_code' =>$outCode,//咨询单详情编号
+		                        'order_id' => $outinfo->id,
+		                        'order_status' => 2,
+		                        'action_process' =>1,
+		                        'action_status' => $info->fill_type!==1?0:1,
+		                        'action_uid' => $this->uid,
+		                        'action_name' => $this->uname,
+                        ];
+        	event('ProcessOrder',$event);
+            $event=[    'order_type' => 'XSQRD',
+                        'order_code' =>$orderCode,//咨询单详情编号
+                        'order_id' => $order->id,
+                        'order_status' => 2,
+                        'action_process' =>0,
+                        'action_status' => 0,
+                        'action_uid' => $this->uid,
+                        'action_name' => $this->uname,
+                  ];
+            event('ProcessOrder',$event);
+        }catch (\Exception $exception){
+        	$this->model->rollback();
+        	$this->error($exception->getMessage());
+         
+        }
+        $this->success("转单成功",["orderCode"=>$orderCode]);
+    }
+
+    /**
+	 * 咨询订单转业务报备
+     */
+    public function ZixunCreate()
+    {
+      $param=$this->request->param(["bidNo"=>"","sale_price"=>"","manager"=>"","managerid"=>"","good_num"=>"",
+      "proof_type"=>"",'proof_url'=>'',"remark"=>""],"post","trim");
+      $valid = Validate::rule([
+      	"bidNo|咨询竞价单号"=>"require",
+      	"sale_price|商品单价"=>"require|float|gt:0",
+      	"manager|业务经理"=>"require|max:255",
+      	"managerid|业务经理id"=>"require|number|gt:0",
+      	"good_num|商品数量"=>"require|number|gt:0",
+      	"proof_type|凭证类型"=>"require|number|in:0,1,2,3",
+      	"proof_url|凭证地址"=>"require"
+      	]);
+      if($valid->check($param)==false)$this->error($valid->getError());
+      $bids=new ConsultBids();
+      $info = $bids->where(["bidNo"=>$param["bidNo"],"is_del"=>0])->findOrEmpty();
+      if($info->isEmpty()) $this->error("竞价单信息未找到");
+      if( $param['sale_price'] < $info['sale_price']) $this->error('修改的销售单价不能低于原来的销售单价');
+        $coninfo= new ConsultInfo();
+        $this->model->startTrans();
+        try{
+            $zxinfo = $coninfo->with('consult_order')->where(['infoNo' => $info['infoNo'], 'is_del' => 0])->lock(true)->findOrEmpty();
+            if($zxinfo->isEmpty()) throw new \Exception("未找到咨询单信息");
+            if($zxinfo->is_project!=2) throw new \Exception("咨询单类型有误");
+	        $data=[
+	            'fillCode'=>makeNo('BF'),
+	            'fill_type'=>3,
+	            'skuCode'=>'',
+	            'spuCode'=>$info->spuCode,
+	            'good_name'=>$info->good_name,
+	            'unit_id'=>$info->unit_id,
+	            'brand_id'=>$info->brand_id,
+	            'cat_id'=>$info->cat_id,
+	            'good_num'=>$param['good_num'],
+	            'good_price'=>$param['sale_price'],
+	            'platform_id'=>$zxinfo->platform_id,
+	            'total_price'=>bcmul($param['good_num'],$param['sale_price'],4),
+	            'origin_price'=>$info->total_fee,
+	            'apply_id'=>$this->uid,
+	            'apply_name'=>$this->uname,
+	            'status'=>1,
+	            'companyNo'=>$zxinfo->companyNo,
+	            'companyName'=>$zxinfo->companyName,
+	            'customerCode'=>$zxinfo->khNo,
+	            'customerName'=>$zxinfo->khName,
+	            'supplierNo'=>$info->supplierNo,
+	            'supplierName'=>$info->supplierName,
+	            'is_compliance'=>0,
+	            'plat_code'=>'',
+	            'fill_remark'=>$param['remark'],
+	            'manager'=>$param['manager'],
+	            'managerid'=>$param['managerid'],
+	        ];
+	        $bbcCre=BbcFill::create($data);
+            if($bbcCre->id==false) throw new \Exception('报备单创建失败');
+            BargainOrder::update(["status"=>4],['bidsNo' =>$param['bidNo'],'is_del'=>0,'status'=>0]);
+            $info->status=6;
+            $up =$info->save();
+            if($up==false) throw new \Exception('竞价单状态更新失败');
+            $zxinfo->status=5;
+            $zxup=$zxinfo->save();
+            if($zxup==false) throw new \Exception('咨询单状态更新失败');
+              $limt = [
+                    'spuCode' => $info['spuCode'],
+                    'good_name' => $info['good_name'],
+                    'brand_id' => $info['brand_id'],
+                    'good_unit' => $info['unit_id'],
+                    'cat_id' => $info['cat_id'],
+                    'good_type' => 0,
+                    'moq' => 1,
+                    'customized' => $info['work_day'],
+                    'tax' => $info['tax'],
+                    'supplierNo' => $info['supplierNo'],
+                    'supplierName' =>$info['supplierName'],
+                    'is_auth' => 0,
+                    'craft_desc' => $info['good_name'],
+                    'good_remark' => '',
+                    'platform_id' => $zxinfo['platform_id'],
+                    'good_img' => $info['good_img'],
+                    'good_thumb_img' => '',
+                    'good_info_img' => '',
+                    'specinfo' => $info['specinfo'],
+                    'work_day' => $info['work_day'],
+                    'noble_metal' => $info['metal_id'],
+                    'is_gold_price' => $info['is_gold_price'],
+                    'config' => $info['config'],
+                    'other_config' => $info['other_config'],
+                    'weight' => $info['weight'],
+                    'good_weight' => $info['good_weight'],
+                    'is_diff' => $info['is_diff'],
+                    'supply_area' => $info['supply_area'],
+                    'pay_way' => $info['pay_way'],
+                    'send_way' => $info['send_way'],
+                    'companyNo' => $zxinfo['companyNo'],
+                    'companyName' =>$zxinfo['companyName'],
+                    'status' => 1,
+                    'is_del' => 0,
+                    'order_type' => 3,
+                    'order_source' => 11,
+                    'createrid' => $zxinfo['createrid'],
+                    'creater' => $zxinfo['creater'],
+                    'order_createrid' => $this->uid,
+                    'order_creater' =>  $this->uname,
+                    'addtime' => date('Y-m-d H:i:s'),
+                    'updatetime' => date('Y-m-d H:i:s'),
+                    'proof_type' => $param['proof_type'],//凭证类型
+                    'proof_url' => $param['proof_url'],//凭证文件
+                ];
+               GoodZixun::create($limt);
+            $this->model->commit();
+        }catch (\Exception $exception){
+            $this->model->rollback();
+            $this->error($exception->getMessage().$exception->getLine());
+        }
+        $this->success("报备单生成成功",["fillCode"=>$data['fillCode']]);
+    }
+
+    /**
+     * 保存更新的资源
+     *
+     * @param  \think\Request  $request
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function info()
+    {
+    	$id = $this->request->post("id");
+    	$info =$this->model->with(['unitT','cat','brand',"platform"])->findOrEmpty($id);
+    	if($info->isEmpty()) $this->error("未找到数据");
+    	$this->success("获取成功",$info);
+    }
+    
+}

+ 10 - 3
app/bbc/controller/Good.php

@@ -3,7 +3,16 @@ declare (strict_types = 1);
 
 namespace app\bbc\controller;
 
-use app\admin\model\GoodBasic;use app\admin\model\GoodExam;use app\admin\model\GoodLadder;use app\admin\model\GoodNake;use app\admin\model\GoodPlatform;use app\admin\model\GoodProof;use app\admin\model\Platform;use app\admin\model\PlatformYouzan;use app\model\AccountItem;use app\youzan\model\Account;use think\App;use think\Exception;use thinkException;use think\facade\Validate;
+use app\admin\model\GoodBasic;
+use app\admin\model\GoodExam;
+use app\admin\model\GoodLadder;
+use app\admin\model\GoodNake;
+use app\admin\model\GoodPlatform;
+use app\admin\model\GoodProof;
+use app\admin\model\Platform;
+use app\model\AccountItem;use think\App;
+use think\Exception;
+use think\facade\Validate;
 
 class Good extends Base
 {
@@ -80,9 +89,7 @@ class Good extends Base
          	$catinfo= $cat->where(['id'=>$item['cat_id']])->value('search','');
             $item['cat_info'] =explode('_',$catinfo);
             $item['brand_name'] =$Brand->where(['id'=>$item['brand_id']])->value('brand_name','');
-//            $item['unit'] =$unit->where(['id'=>$item['good_unit']])->value('unit','');
             $item['platform_name'] =$platfrom->where(['id'=>$item['platform_code']])->value('platform_name','');
-//            $item['exclusive'] = makeExcluse($item['is_exclusive']);
             $item['company_name'] =$account->alias('a')->leftJoin('company_item b','a.itemid=b.id')
             ->where('a.account_id',$item['createrid'])->value('b.name');
          }

+ 52 - 0
app/bbc/model/BbcFill.php

@@ -0,0 +1,52 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\bbc\model;
+
+use app\admin\model\Brand;
+use app\admin\model\Cat;
+use app\admin\model\GoodBasic;use app\admin\model\GoodZixun;use app\admin\model\Platform;use app\admin\model\Unit;
+use think\Model;
+use think\model\concern\SoftDelete;
+
+/**
+ * @mixin \think\Model
+ */
+class BbcFill extends Model
+{
+	use SoftDelete;
+   protected $createTime="addtime";
+   protected $updateTime="updatetime";
+   protected $deleteTime = 'delete_time';
+   protected $hidden = ['delete_time'];
+   static $status_cn=['待提交','待转单','部分转单','转单成功','取消转单'];
+   protected $append=["status_cn","wtrans_num","good_img"];
+   public function unitT(){
+   	return $this->belongsTo(Unit::class,"unit_id","id")->bind(["unit"]);
+   }
+   
+   public function brand(){
+   	return $this->belongsTo(Brand::class,'brand_id','id')->bind(['brand_name']);
+   }
+   
+   public function cat(){
+   	return $this->belongsTo(Cat::class,'cat_id','id')->bind(["cat_name"=>'search']);
+   }
+   
+   public function platform(){
+   	return $this->belongsTo(Platform::class,'platform_id','id')->bind(['platform_name']);
+   }
+   
+   public function GetStatusCnAttr($v,$row){
+   	    return self::$status_cn[$row['status']]??"";
+   }
+   
+   public function GetGoodImgAttr($v,$row){
+   	if($row['fill_type']==3)$img=(new GoodZixun())->where(["spuCode"=>$row['spuCode']])->value("good_img",'');
+   	else $img=(new GoodBasic())->where(['spuCode'=>$row['spuCode']])->value('good_thumb_img','');
+   	    return $img;
+   }
+   public function GetWtransNumAttr($v,$row){
+   	    return  bcsub($row['good_num'],$row['transfer_num']);
+   }
+}

+ 1 - 1
app/command/SplitSale.php

@@ -130,7 +130,7 @@ class SplitSale extends Command
 							$orderCode = substr($orderCode, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
 							$supplier = ['No' => $sale['supplierNo'], 'name' => $sale['supplierName'],"pay_name"=>$pay_rate['pay_name']];
 							if(!isset($cgd['cgdNo']) && $sale['is_stock']==1 ){
-								$sale['origin_price'] = Db::name("purchease_order")->where(["spuCode"=>$sale['good_code'],"is_del"=>0,"status"=>[2,3]])->value("good_price",0);
+								$sale['origin_price'] = Db::name("purchease_order")->where(["spuCode"=>$sale['good_code'],"is_del"=>0,"status"=>[2,3]])->order("id desc")->value("good_price",0);
 							}else{
 								$sale['origin_price'] = $cgd['good_price'];
 							}

+ 1 - 0
app/event.php

@@ -15,6 +15,7 @@ return [
         'ProcessOrder' => [\app\bbc\listener\ProcessOrder::class],
         'GoodOff' => [\app\bbc\listener\GoodOffine::class],
         'thdata' => [\app\admin\listener\ThData::class],
+        'CgdCreate' => [\app\admin\listener\Cgdmake::class],
      
     ],
 

+ 19 - 0
app/model/AccountCompany.php

@@ -0,0 +1,19 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class AccountCompany extends Base
+{
+    public static function IsOpenAccount($supplierNo){
+      return    self::alias("a")->leftJoin("account b" ,"b.id=a.account_id")
+         ->where([ ['a.is_del', '=', 0],
+            ['a.status', '=', 1],
+            ['b.level', '=', 3]])->where(["companyCode"=>$supplierNo])->findOrEmpty()->isEmpty();
+    }
+}

+ 14 - 0
app/model/Base.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Base extends Model
+{
+    protected $connection='mysql_sys';
+}

+ 17 - 0
app/model/Headquarters.php

@@ -0,0 +1,17 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Headquarters extends Base
+{
+	protected $globalScope=["is_del"];
+	public function scopeIsDel($query){
+		$query->where("is_del",0);
+	}
+}

+ 17 - 0
app/model/Supplier.php

@@ -0,0 +1,17 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Supplier extends Base
+{
+    protected $globalScope=['is_del'];
+	public function scopeIsDel($query){
+		$query->where('is_del',0);
+	}
+}

+ 58 - 0
app/txx/controller/Base.php

@@ -0,0 +1,58 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\controller;
+
+use think\App;
+use think\exception\HttpResponseException;
+use think\Response;
+
+class Base extends \app\admin\controller\Base
+{
+	public function __construct(App $app) {
+  	parent::__construct($app);
+  }
+  
+   /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+    public function error($message='',$code=1003,$data=null){
+        $this->result($message,$data,$code);
+    }
+    /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+     public function success($message='',$data=null,$code=0){
+        $this->result($message,$data,$code);
+    }
+    
+     /**
+	* @param string $msg
+	* @param null $data
+	* @param int $code
+	* @param string|null $type
+	* @param array $header
+	* @param array $options
+	 */
+    private function result(string $msg, $data = null, int $code = 0, string $type = 'json', array $header = [], array
+    $options = [])
+    {
+        $result = [
+            'code' => $code,
+            'message'  => $msg,
+            'data' => $data,
+        ];
+        $code = 200;
+        if (isset($header['statuscode'])) {
+            $code = $header['statuscode'];
+            unset($header['statuscode']);
+        }
+
+        $response = Response::create($result, $type, $code)->header($header)->options($options);
+         throw new HttpResponseException($response);
+    }
+}

+ 131 - 0
app/txx/controller/TxGood.php

@@ -0,0 +1,131 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\controller;
+
+use app\admin\model\Brand;
+use app\admin\model\Cat;
+use app\admin\model\PlatformYouzan;
+use app\admin\model\Unit;
+use app\report\model\GoodSpec;
+use app\txx\model\ActGoodurl;
+use app\txx\model\YzGood;
+use think\App;
+use think\facade\Validate;
+
+class TxGood extends Base
+{
+	private $platform_id=37;
+	public  $origin_img_host ='http://stock.api.wanyuhengtong.com';
+    public  $ssl_img_host ='https://image.wanyuhengtong.com';
+	public function __construct(App $app) {
+		parent::__construct($app);
+	}
+	/**
+	* 1. 十万订单每秒热点数据架构如何优化
+	* 2. Redis集群崩溃时如何保证秒杀系统高可用
+	* 3. Redis主从切换导致库存同步异常以及超卖问题
+	* 4. 秒杀链路中Redis与MQ如何保证事务一致性
+	* 5. 线上MQ百万秒杀订单积压如何优化
+	* 6. 如何用Redis高效实现12306的复杂售票业务
+	* 7. 新浪微博突发事件如何做好Redis缓存的高可用
+	* 8. 高并发场景缓存穿透&失效&雪崩如何解决
+	* 9. Redis集群架构如何抗住12306与双11的洪峰流量
+	* 10. Redis缓存与数据库双写不一致如何解决
+	* 11. 双十一亿级用户日活统计如何用Redis快速计算
+	* 12. 双十一电商推荐系统如何用Redis实现
+	* 13. 日均百亿级微信红包系统如何架构
+	* 14. 类似微信的社交App朋友圈关注模型如何设计实现
+	* 15. 美团单车如何基于Redis快速找到附近的车
+	* 16. Redis分布式锁主从架构锁失效问题如何解决
+	* 17. 超大并发的分布式锁架构该如何设计
+	* 18. Redis底层ZSet跳表是如何设计与实现的
+	* 19. Redis底层ZSet实现压缩列表和跳表如何选择
+	* 20. Redis6.0多线程模型比单线程优化在哪里了
+    */
+	public function AddCouponUrl(){
+		$param = $this->request->param(["skuCode"=>"","coupon_url"=>""],"post","trim");
+		$valid =Validate::rule(["skuCode|商品上线编号"=>"require","coupon_url|商品优惠券链接"=>"require"]);
+		if($valid->check($param)==false)$this->error($valid->getError());
+		$youzan = new PlatformYouzan();
+		$info = $youzan->where(["skuCode"=>$param['skuCode'],"is_del"=>0])->findOrEmpty();
+		if($info->isEmpty())$this->error("未找到商品信息");
+		if($info->exam_status!=6)$this->error("商品未上线");
+		$actUrl= new ActGoodurl();
+		$isT = $actUrl->where(["act_good_id"=>$info->id,"is_del"=>0])->findOrEmpty();
+		if($isT->isEmpty()){
+			$data=[
+				"act_good_url"=>$param['coupon_url'],
+				"act_good_id"=>$info->id,
+				"apply_id"=>$this->uid,
+				"apply_name"=>$this->uname,
+				];
+		}else{
+			$data=[
+				'act_good_url'=>$param['coupon_url'],
+				'apply_id'=>$this->uid,
+				'apply_name'=>$this->uname,
+				];
+		}
+		$up=$isT->save($data);
+		$up?$this->success("链接上传成功"):$this->error("链接上传失败");
+	}
+	
+	public function list(){
+		$param = $this->request->param(["page"=>1,"size"=>15,"good_name"=>""],'post','trim');
+		$where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','=',$this->platform_id],['b.exam_status',
+		'=',6]];
+		$param['good_name']!=''??$where[]=["c.good_name","like","%{$param['good_name']}%"];
+		$actUrl= new ActGoodurl();
+		$list = $actUrl->alias("a")
+		->leftJoin("platform_youzan b","a.act_good_id=b.id")
+		->leftJoin('good_basic c', 'c.spuCode=b.spuCode')
+		->where($where)
+		->field("b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,
+		            c.good_name,c.good_img,c.good_info_img,c.good_thumb_img,c.brand_id,c.cat_id,
+		            c.good_unit,a.addtime,a.updatetime,b.spuCode,b.sale_price,b.final_price")
+		->order("a.id desc")
+		->paginate(["list_rows"=>$param['size'],"page"=>$param["page"]]);
+		foreach ($list->items() as $item){
+			$item['brand_name'] =Brand::where("id",$item['brand_id'])->value("brand_name",'');
+			$item['good_unit'] =Unit::where("id",$item['good_unit'])->value("unit",'');
+			$item['cat_name'] =Cat::where("id",$item['cat_id'])->value("search",'');
+			$item['good_url'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('detail_url','');
+			$item['origin_price'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('origin','');
+			$item['spec_info'] =GoodSpec::where(["spuCode" => $item['spuCode'], "is_del" => 0])->with(["spec",
+			"Spec_info"])->field("spec_id,spec_value_id")->select();
+		}
+		$this->success('获取成功',["list"=>$list->items(),"count"=>$list->total()]);
+	}
+	
+	public function GoodInfo(){
+	    $param =$this->request->only(['skuCode'=>''],'post','trim');
+	    $valid =Validate::rule(['skuCode|商品上线编号'=>'require']);
+		if($valid->check($param)==false)$this->error($valid->getError());
+		$field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,
+            a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
+            a.good_unit,b.addtime,b.updatetime,a.spuCode, b.sale_price,b.final_price';
+		$youzan = new PlatformYouzan();
+	    $info = $youzan
+	              ->alias('b')
+	              ->field($field)
+		    //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
+		          ->leftJoin('good_basic a', 'a.spuCode=b.spuCode')
+	              ->where(['b.skuCode'=>$param['skuCode'],'b.is_del'=>0])->findOrEmpty();
+
+	    if($info->isEmpty())  $this->error('商品数据未找到');
+	   
+	        $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
+			$info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
+			$info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
+			$info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');;
+	        $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
+	        $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
+	        $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
+	    
+	    $info->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_img);
+	    $info->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_info_img);
+	    $info->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_thumb_img);
+	    $this->success('获取成功',$info);
+    }
+}

+ 1 - 1
app/txx/middleware/CheckAuth.php

@@ -4,7 +4,7 @@ declare (strict_types = 1);
 namespace app\txx\middleware;
 
 use app\txx\common\Sign;
-use think\facade\Db;
+use think\facade\Db;use think\Response;
 class CheckAuth
 {
     /**

+ 14 - 0
app/txx/model/ActGoodurl.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ActGoodurl extends Model
+{
+    //
+}