wugg hace 2 años
padre
commit
5817f2fb59

+ 77 - 0
app/txx/common/Sign.php

@@ -0,0 +1,77 @@
+<?php
+
+
+namespace app\txx\common;
+
+
+class Sign {
+	private $appId = "";
+    private $appKey = "";
+	public function __construct(string $appId,string $appKey) {
+		$this->appId=$appId;
+		$this->appKey=$appKey;
+	}
+    //创建sign
+    public function makeSign($data) {
+        ksort($data);
+        $string = $this->toUrlParams($data);
+        $string = $string . "&key=" . $this->appKey;
+        $string = md5($string);
+        $result = strtolower($string);
+        return $result;
+    }
+
+    //检验sign是否正确
+    public function verifySign($data) {
+        //check sign
+       if (!isset($data['sign']) || !$data['sign']) {
+          return ['code'=>1,'msg'=>'发送的数据签名不存在'];
+       }
+
+        //check sign
+        if (!isset($data['appid']) || !$data['appid']) {
+            return ['code'=>1,'msg'=>'发送的应用参数不存在'];
+        }
+        if ($data['appid'] != $this->appId) {
+            return ['code'=>1,'msg'=>'发送的应用参数错误'];
+        }
+
+        //check sign
+        if (!isset($data['noce']) || !$data['noce']) {
+            return ['code'=>1,'msg'=>'发送的应用参数不存在'];
+        }
+
+       //check timestamp
+       if (!isset($data['timestamp']) || !$data['timestamp']) {
+          return ['code'=>1,'msg'=>'发送的数据参数不合法'];
+       }
+
+       // 验证请求, 10分钟失效
+       if (time() - $data['timestamp'] > 600) {
+          return ['code'=>1,'msg'=>'验证超时, 请重新发送请求'];
+       }
+
+       $clientSign = $data['sign'];
+        unset($data['sign']);
+       $serverSign = $this->makeSign($data);
+       if ($clientSign == $serverSign) {
+         return ['code'=>0,'msg'=>'验证通过'];
+       } else {
+         return ['code'=>1,'msg'=>'请求不合法'];
+       }
+    }
+
+    //生成url字符串
+    private function toUrlParams($values){
+        $buff = "";
+        foreach ($values as $k => $v)
+        {
+            //&& $v != ""
+            if($k != "sign" && !is_array($v)&& $v != ""){
+                $buff .= $k . "=" .$v . "&";
+            }
+        }
+        $buff = trim($buff, "&");
+        return $buff;
+    }
+}

+ 187 - 0
app/txx/controller/Act.php

@@ -0,0 +1,187 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\controller;
+
+use app\BaseController;
+use think\facade\Validate;
+use app\txx\model\Act as Actm;
+use think\App;
+
+class Act extends BaseController
+{
+	protected $uid=0;
+	protected $uname='';
+		public function __construct(App $app) {
+		parent::__construct($app);
+		if($this->request->isCx==1){
+		    $this->uid=$this->request->uid;
+	        $this->uname=$this->request->uname;
+		}
+
+	}
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function list()
+    {
+      $param = $this->request->only([
+      	"page"=>1,
+      	"size"=>15,
+      	"act_name"=>'',
+      	"actCode"=>'',
+      	"company_name"=>'',
+       	"contactor"=>'',
+        "act_type"=>'',
+        "start"=>'',
+        "end"=>'',
+        "status"=>'',
+      	],"post",'trim');
+      $condition=[["is_del","=",0]];
+      if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
+      if($param['actCode']!='') $condition[]=["actCode","like","%{$param['actCode']}%"];
+      if($param['company_name']!='') $condition[]=["company_name","like","%{$param['company_name']}%"];
+      if($param['contactor']!='') $condition[]=["contactor","like","%{$param['contactor']}%"];
+      if($param['act_type']!='') $condition[]=["act_type","=",$param["act_type"]];
+      if($param['start']!='') $condition[]=["addtime",">=",$param["start"]." 00:00:00"];
+      if($param['end']!='') $condition[]=["addtime","<=",$param["end"]." 23:59:59"];
+      if($param['status']!='') $condition[]=["status","=",$param["status"]];
+      $actm=new Actm();
+      $count =$actm->where($condition)->count();
+      $total =ceil($count/$param['size']);
+      $page = $param['page']>= $total ?intval($total):intval($param['page']);
+      $list=$actm->where($condition)->page($page,intval($param['size']))->order("addtime desc")->select()->toArray();
+      return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function create()
+    {
+       $param = $this->request->only([
+       	"act_name"=>"",
+       	"company_name"=>'',
+       	"contactor"=>'',
+       	"mobile"=>'',
+       	"web_url"=>'',
+       	"start"=>'',
+       	"end"=>'',
+       	"act_type"=>1,
+       	],"post","trim");
+
+        $validate = Validate::rule([
+            'act_name|活动名称' => 'require',
+            'company_name|活动公司名称' => 'require',
+            'contactor|联系人' => 'require|max:255',
+            'mobile|联系电话' => 'require',
+        ]);
+        if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+        $actCode=makeNo("ACE");
+        $data=[
+        	"actCode"=>$actCode,
+        	"act_name"=>$param['act_name'],
+        	"company_name"=>$param['company_name'],
+        	"contactor"=>$param['contactor'],
+        	"mobile"=>$param['mobile'],
+        	"act_type"=>$param['act_type'],
+        	"startTime"=>$param['start']==''?null : $param['start'],
+        	"endTime"=>$param['end']==''?null : $param['end'],
+        	"web_url"=>$param['web_url']??"",
+        	"status"=>0,
+        	"apply_id"=>$this->uid,
+        	"apply_name"=>$this->uname,
+        	"addtime"=>date("Y-m-d H:i:s"),
+        	"updatetime"=>date("Y-m-d H:i:s"),
+        ];
+        $add =Actm::create($data);
+        return $add ?json_show(0,"活动新建成功",["actCode"=>$actCode]): json_show(1006,"活动新建失败");
+
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param  \think\Request  $request
+     * @return \think\Response
+     */
+    public function save()
+    {
+       $param = $this->request->only([
+       	"act_name"=>"",
+       	"company_name"=>'',
+       	"contactor"=>'',
+       	"mobile"=>'',
+       	"web_url"=>'',
+       	"start"=>'',
+       	"end"=>'',
+       	"actCode"=>'',
+       	"act_type"=>1,
+       	],"post","trim");
+
+        $validate = Validate::rule([
+            'act_name|活动名称' => 'require',
+            'actCode|活动编号' => 'require',
+            'company_name|活动公司名称' => 'require',
+            'contactor|联系人' => 'require|max:255',
+            'mobile|联系电话' => 'require',
+        ]);
+        if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+         $actm=new Actm();
+        $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
+        if($info==false) return json_show(1005,"活动不存在");
+        $data=[
+        	"act_name"=>$param['act_name'],
+        	"company_name"=>$param['company_name'],
+        	"contactor"=>$param['contactor'],
+        	"mobile"=>$param['mobile'],
+        	"act_type"=>$param['act_type'],
+        	"startTime"=>$param['start']==''?null : $param['start'],
+        	"endTime"=>$param['end']==''?null : $param['end'],
+        	"web_url"=>$param['web_url']??"",
+        	"updatetime"=>date("Y-m-d H:i:s"),
+        ];
+        $add =$actm->update($data,["actCode"=>$param['actCode'],"is_del"=>0]);
+        return $add ?json_show(0,"活动编辑成功"): json_show(1006,"活动编辑失败");
+    }
+
+    /**
+     * 显示指定的资源
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function info()
+    {
+    $param = $this->request->only(["actCode"=>''],"post","trim");
+     $validate = Validate::rule([
+            'actCode|活动编号' => 'require',]);
+      if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+     $actm=new Actm();
+        $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find()->toArray();
+      return json_show(0,"获取成功",$info);
+    }
+
+      /**
+     * 删除指定资源
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function delete()
+    {
+		$param = $this->request->only(["actCode"=>''],"post","trim");
+     $validate = Validate::rule([
+            'actCode|活动编号' => 'require',]);
+      if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+       $actm=new Actm();
+        $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
+      if($info==false) return json_show(1005,"活动不存在");
+      $isDel =$actm->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")],["actCode"=>$param['actCode'],"is_del"=>0]);
+       return $isDel?json_show(0,"活动删除成功"): json_show(1006,"活动删除失败");
+    }
+}

+ 624 - 0
app/txx/controller/Good.php

@@ -0,0 +1,624 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\controller;
+
+use app\BaseController;
+use app\txx\model\Act;
+use app\txx\model\ActGood;
+use app\txx\model\YzGood;
+use app\txx\model\PlatformYouzan;
+use think\App;
+use think\Exception;
+use think\facade\Db;
+use think\facade\Validate;
+use think\Request;
+
+class Good extends BaseController
+{
+	protected $uid=0;
+	protected $uname='';
+	protected $platformid=37;
+	/**@param array snArr 商品编号sn数组
+     * @param string actCode 活动编号
+	* @return \think\response\Json
+	* @throws \think\exception\DbException
+	 */
+    private $acton=[];
+    public $noble=[];
+    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);
+		if($this->request->isCx==1){
+			$this->uid=$this->request->uid;
+			$this->uname=$this->request->uname;
+		}
+
+	}
+
+    public function AddGood()
+    {
+    	$post = $this->request->only(["snArr"=>[],"actCode"=>''],"post");
+    	$snArr= $post['snArr'];
+    	if(empty($snArr)) return  json_show(1004,"参数错误 snArr 不能为空");
+    	$platformYouzan =new PlatformYouzan();
+    	$skuCodes = array_column($snArr,"skuCode");
+		$goodArr = $platformYouzan->where(["skuCode"=>$skuCodes,"is_del"=>0])->select()->toArray();
+		if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
+		$actCode= $post['actCode']!=''? trim($post['actCode']):"";
+		if($actCode=='') return json_show(1004,"参数错误 actCode 不能为空");
+//	    $roundId= $post['roundId']!=''? trim($post['roundId']):"";
+//	    if($roundId=='') return json_show(1004,"参数错误 roundId 不能为空");
+		$act =new Act();
+		$isActExit=$act->where(['actCode'=>$actCode,"is_del"=>0])->find();
+		if($isActExit==false) return json_show(1005,"未找到活动有效数据");
+
+		$actGood=new ActGood();
+		Db::startTrans();
+		try{
+			$data=[];
+			foreach ($snArr as $item){
+				$isExit = $actGood->find(["actCode"=>$actCode,"yz_good_code"=>$item['skuCode'],"is_del"=>0]);
+				if($isExit) throw new Exception("活动商品已添加",1006);
+				$temp=[
+					"actCode"=>$actCode,
+					"yz_good_code"=>$item['skuCode'],
+					"stock_num"=>$item['stock_num'],
+					"used_num"=>0,
+					"balance_num"=>$item['stock_num'],
+					"apply_id"=>$this->uid,
+					"apply_name"=>$this->uname,
+					"roundId"=>$item['roundId']??"",
+					"status"=>0,
+					"addtime"=>date("Y-m-d H:i:s"),
+					"updatetime"=>date("Y-m-d H:i:s")
+					];
+				$data[]=$temp;
+			}
+			if (empty($data)){
+					throw new Exception("活动商品不能为空",1006);
+			}
+			$isAdd=ActGood::insertAll($data);
+			if ($isAdd==false){
+					throw new Exception("活动商品添加失败",1006);
+			}
+			$up =$act->where($isActExit->toArray())->update(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+			if ($up==false){
+				throw new Exception("活动商品添加失败",1006);
+			}
+			Db::commit();
+			return json_show(0,"活动商品添加成功");
+		}catch (\Exception $e){
+			Db::rollback();
+			return json_show(1008,$e->getMessage());
+		}
+    }
+
+    /**活动商品列表
+      * @param int page 页数
+      * @param int size 每页显示数量
+      * @param string act_name  活动名称
+      * @param string actCode 活动编号
+      * @param string company_name 活动公司名称
+      * @param string contactor 活动联系人
+      * @param int act_type 活动类型 暂无
+      * @param int cat_id  采销分类
+      * @param string spuCode 商品成本编号
+      * @param string skuCode 商品上线编号
+      * @param int exam_status 商品上线审核状态
+     */
+    public function list()
+    {
+       $param = $this->request->only([
+      	"page"=>1,
+      	"size"=>15,
+      	"act_name"=>'',
+      	"actCode"=>'',
+      	"company_name"=>'',
+       	"contactor"=>'',
+        "act_type"=>'',
+        "good_name"=>'',
+        "cat_id"=>'',
+        "spuCode"=>'',
+        "skuCode"=>'',
+        "status"=>"",
+        "roundId"=>"",
+        "exam_status"=>'',
+      	],"post",'trim');
+      $condition=[["a.is_del","=",0],["b.is_del","=",0]];
+      if($param['act_name']!='') $condition[]=["b.act_name","like","%{$param['act_name']}%"];
+      if($param['actCode']!='') $condition[]=["a.actCode","like","%{$param['actCode']}%"];
+      if($param['company_name']!='') $condition[]=["b.company_name","like","%{$param['company_name']}%"];
+      if($param['contactor']!='') $condition[]=["b.contactor","like","%{$param['contactor']}%"];
+      if($param['good_name']!='') $condition[]=["d.good_name","like","%{$param['good_name']}%"];
+      if($param['skuCode']!='') $condition[]=["c.skuCode","like","%{$param['skuCode']}%"];
+      if($param['act_type']!='') $condition[]=["b.act_type","=",$param["act_type"]];
+      if($param['roundId']!=='') $condition[]=["a.roundId","=",$param["roundId"]];
+      if($param['status']!=='') $condition[]=["a.status","=",$param["status"]];
+       if ($param['exam_status'] !== '') {
+        	if($param['exam_status']==1){
+        		$where[] = ['c.exam_status', "=", 6];
+        	}else{
+        		$where[] = ['c.exam_status', "<>", 6];
+        	}
+        }
+      $actm=new ActGood();
+       if($this->request->isCx==1){
+       	$field="a.id,a.actCode,a.yz_good_code,a.apply_id,a.apply_name,a.stock_num,a.used_num,a.balance_num,a.status,
+      a.addtime,a.updatetime,c.plat_code,b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,
+     c.final_price,c.desc,d.good_name,d.good_unit,c.yz_cat_id,d.cat_id,a.roundId,d.brand_id";
+       }else{
+		$field="a.id,a.actCode,a.yz_good_code,a.stock_num,a.used_num,a.balance_num,a.status,a.addtime,a.updatetime,
+		b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,c.final_price,c.desc,d.good_name,
+		d.good_unit,d.cat_id,d.brand_id,a.roundId";
+       }
+      $count =$actm->alias("a")
+      ->leftJoin("act b","a.actCode=b.actCode")
+      ->leftJoin("platform_youzan c","a.yz_good_code=c.skuCode")
+      ->leftJoin("good d","c.spuCode=d.spuCode")
+      ->where($condition)->count();
+      $total =ceil($count/$param['size']);
+      $page = $param['page']>= $total ?intval($total):intval($param['page']);
+      $list=$actm->alias("a")
+      ->leftJoin("act b","a.actCode=b.actCode")
+      ->leftJoin("platform_youzan c","a.yz_good_code=c.skuCode")
+      ->leftJoin("good d","c.spuCode=d.spuCode")
+	   ->field($field)->where($condition)->page($page,intval($param['size']))
+	   ->order("addtime desc")->select()->toArray();
+       //6.补充数据,照搬list方法
+        $all_brand = Db::name('brand')
+            ->where('is_del', 0)
+            ->whereIn('id', array_column($list, 'brand_id'))
+            ->column('brand_name', 'id');
+         $unit = Db::name("unit")->where(["id" => array_column($list, 'good_unit')])->column('unit', 'id');
+            $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
+	 $yzgood =new YzGood();
+      foreach ($list as &$item){
+		$item['unit'] =$unit[$item['good_unit']] ?? "";
+		$item['brand_name'] = $all_brand[$item['brand_id']]?? "";
+		$item['web_url_num'] = Db::name("act_goodurl")->where(["act_good_id"=>$item['id'],"is_del"=>0])->count();
+	 $item['origin_price'] =$yzgood->where(["item_no"=>$item['yz_good_code'],"is_del"=>0])->value("origin",'');
+		if($this->request->isCx==1){
+			$item['cat_info'] = made($item['cat_id'], []);
+		}else{
+			unset($item['cat_id']);
+			unset($item['good_unit']);
+			unset($item['brand_id']);
+		}
+
+      }
+      return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param  \think\Request  $request
+     * @return \think\Response
+     */
+    public function EditGood()
+    {
+    	$post = $this->request->only(["goodArr"=>[]],"post");
+    	$snArr= $post['goodArr'];
+    	if(empty($snArr)) return  json_show(1004,"参数 goodArr 不能为空");
+    	$platformYouzan =new PlatformYouzan();
+    	$goodCode = array_column($snArr,"yz_good_code");
+		$goodArr = $platformYouzan->where(["skuCode"=>$goodCode,"is_del"=>0])->select()->toArray();
+		if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
+//	    $roundId= $post['roundId']!=''? trim($post['roundId']):"";
+//	    if($roundId=='') return json_show(1004,"参数错误 roundId 不能为空");
+		$actGood=new ActGood();
+		Db::startTrans();
+		try{
+			$data=[];
+			foreach ($snArr as $item){
+				$isExit = $actGood->where(["actCode"=>$item['actCode'],"yz_good_code"=>$item['yz_good_code'],
+				"is_del"=>0])->find();
+				if($isExit==false) throw new Exception("活动商品不存在",1006);
+				$temp=[
+					"id"=>$isExit['id'],
+					"stock_num"=>$item['stock_num'],
+					"balance_num"=>$item['stock_num'],
+					"roundId"=>$item['roundId']??"",
+					"is_del"=>$item['is_del']??0,
+					"updatetime"=>date("Y-m-d H:i:s")
+					];
+				$data[]=$temp;
+
+			}
+			$isAdd=$actGood->saveAll($data);
+			if ($isAdd==false){
+					throw new Exception("活动商品更新失败",1006);
+			}
+			Db::commit();
+			return json_show(0,"活动商品更新成功");
+		}catch (\Exception $e){
+			Db::rollback();
+			return json_show(1008,$e->getMessage());
+		}
+
+    }
+
+    /**
+     * 显示指定的资源
+     *
+     * @param  int  $id 参数详情id
+     * @return \think\Response
+     */
+    public function GoodInfo()
+    {
+    	$param =$this->request->only(["id"=>''],"post","trim");
+    	if($param['id']=='') return json_show(1004,"参数 id 不能为空");
+    	 if($this->request->isCx==1){
+       	    $field="a.id,a.actCode,a.yz_good_code,a.apply_id,a.apply_name,a.stock_num,a.used_num,a.balance_num,a.status,
+            a.addtime,a.updatetime,c.plat_code,b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,
+            c.final_price,c.desc,d.good_name,d.good_unit,c.yz_cat_id,d.cat_id,d.brand_id,a.roundId";
+	       }else{
+			$field="a.id,a.actCode,a.yz_good_code,a.stock_num,a.used_num,a.balance_num,a.status,a.addtime,a.updatetime,
+			b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,c.final_price,c.desc,d.good_name,
+			d.good_unit,d.cat_id,d.brand_id,a.roundId";
+            }
+    	$actm=new ActGood();
+    	$info=$actm->alias("a")
+      ->leftJoin("act b","a.actCode=b.actCode")
+      ->leftJoin("platform_youzan c","a.yz_good_code=c.skuCode")
+      ->leftJoin("good d","c.spuCode=d.spuCode")
+      ->field($field)
+      ->find($param);
+    	if($info==false){
+    	    return json_show(1005,"未找到数据");
+    	}
+    	$info['brand_name'] = Db::name('brand')
+            ->where('is_del', 0)
+            ->where('id',$info['brand_id'])
+            ->value('brand_name', '');
+         $info['unit'] = Db::name("unit")->where("id" ,$info['good_unit'])->value('unit', '');
+          if($this->request->isCx==1){
+          	 $info['cat_info'] =made($info['cat_id']);
+          }else{
+          	unset($info['good_unit']);
+            unset($info['brand_id']);
+          }
+        return json_show(0,"获取成功",$info->toArray());
+    }
+
+    /** 商品链接导入
+     * @param  int  act_good_id 商品活动id
+     * @param  array  web_url 商品链接url
+     * @return \think\Response
+     */
+    public function GoodUrlImport()
+    {
+    	$param = $this->request->only(["web_url"=>[]],"post");
+    	$validate=Validate::rule([
+    		'web_url|商品链接' => 'require|array'
+            ]);
+    	if($validate->check($param)==false) return json_show(1004,$validate->getError());
+    	$actm=new ActGood();
+
+    	$web=[];
+    	foreach ($param['web_url'] as $item){
+    		$actGood =$actm->where(["id"=>$item['act_good_id'],"is_del"=>0])->find();
+    	    if($actGood==false) return json_show(1005,'未找到商品数据');
+				$temp=[
+					"act_good_url"=>$item['act_good_url'],
+					"act_good_id"=>$item['act_good_id'],
+					"status"=>1,
+					"is_del"=>0,
+					"apply_id"=>$this->uid,
+					"apply_name"=>$this->uname,
+					"addtime"=>date("Y-m-d H:i:s"),
+					"updatetime"=>date("Y-m-d H:i:s")
+					];
+				$web[]=$temp;
+    	}
+
+    	Db::startTrans();
+    	try{
+    	$isAdd=Db::name("act_goodurl")->insertAll($web);
+    	if( $isAdd<=0 ){
+    		Db::rollback();
+    		return json_show(1006,"商品链接导入失败");
+    	}
+    	$ids = array_unique(array_column($param['web_url'],"act_good_id"));
+		foreach ($ids as $item){
+			$actGood =$actm->where(["id"=>$item,"is_del"=>0])->find();
+    	    if($actGood==false) return json_show(1005,'未找到商品数据');
+    	    $num =Db::name("act_goodurl")->where(["act_good_id"=>$item,"is_del"=>0])->count();
+    	    if($num>=$actGood['stock_num']){
+    	    	$up =$actm->where(["id"=>$item,"is_del"=>0])->update(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+    	    	if($up==false) return json_show(1005,'商品数据更新失败');
+    	    	$upunum = $actm->where(["actCode"=>$actGood["actCode"],"is_del"=>0,"status"=>0])->count();
+    	    	if($upunum==0){
+    	    		$up1 =Db::name("Act")->where(["actCode"=>$actGood["actCode"],"is_del"=>0])->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
+			        if ($up1==false){
+				        throw new Exception("活动数据更新失败",1006);
+			        }
+    	    	}
+    	    }
+		}
+    	Db::commit();
+    	return json_show(0,'商品链接导入成功');
+    	}catch (\Exception $e){
+    		Db::rollback();
+    		return json_show(1008,$e->getMessage());
+    	}
+    }
+
+    /**
+     * 保存更新的资源
+     * @param  int  $page
+     * @param  int  $size
+     * @param  string  $act_name
+     * @param  string  $actCode
+     * @param  int  $act_good_id
+     * @return \think\Response
+     */
+    public function GoodUrlList()
+    {
+    	  $param = $this->request->only([
+      	"page"=>1,
+      	"size"=>15,
+      	"act_name"=>'',
+      	"actCode"=>'',
+      	"act_good_id"=>'',
+      	"good_code"=>'',
+      	"roundId"=>'',
+      	],"post","trim");
+		$condition=[["a.is_del","=",0],["b.is_del","=",0],["c.is_del","=",0]];
+		if($param['act_name']!='')$condition[]=["c.act_name","like","%{$param['act_name']}%"];
+		if($param['actCode']!='')$condition[]=["c.actCode","like","%{$param['actCode']}%"];
+		if($param['act_good_id']!='')$condition[]=["a.act_good_id","=",$param['act_good_id']];
+		if($param['good_code']!='')$condition[]=["b.yz_good_code","=",$param['good_code']];
+	    if($param['roundId']!=='') $condition[]=["b.roundId","=",$param["roundId"]];
+		$count = Db::name("act_goodurl")->alias("a")
+		->leftJoin("act_good b","a.act_good_id=b.id  and b.is_del=0")
+		->leftJoin("act c","b.actCode=c.actCode and c.is_del=0")
+		->where($condition)
+		->count();
+		$total =ceil($count/$param['size']);
+		$page =$param['page']>=$total ? intval($total) : intval($param['page']);
+		$list = Db::name("act_goodurl")->alias("a")
+		->leftJoin("act_good b","a.act_good_id=b.id  and b.is_del=0")
+		->leftJoin("act c","b.actCode=c.actCode and c.is_del=0")
+		->where($condition)->page($page,intval($param['size']))
+		->field("a.id,a.act_good_url,b.roundId,a.act_good_id,a.apply_id,a.apply_name,a.addtime,a.updatetime,b.stock_num")
+		->select()->toArray();
+		foreach ($list as &$item){
+			$item['web_url_num'] = Db::name("act_goodurl")->where(["act_good_id"=>$item['act_good_id'],"is_del"=>0])->count();
+		}
+		return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param  int  $id
+     * @return \think\Response
+     */
+    public function GoodUrlDel()
+    {
+     $param = $this->request->only(["web_url_ids"=>[]],"post");
+     if(empty($param['web_url_ids'])|| $param["web_url_ids"]=="") return json_show(1004,"参数 web_url_ids 不能为空");
+     $actm=new ActGood();
+     $web=[];
+    	foreach ($param['web_url_ids'] as $item){
+    		$actGood =Db::name("act_goodurl")->where(["id"=>$item,"is_del"=>0])->find();
+    	    if($actGood==false) return json_show(1005,'未找到商品链接数据');
+    	    $web[]=$actGood['act_good_id'];
+    	}
+	    $web =array_unique($web);
+    	Db::startTrans();
+    	try{
+		 $isDel=Db::name("act_goodurl")->where(["id"=>$param['web_url_ids']])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+		 if($isDel==false){
+		 	 throw new Exception("活动商品链接删除失败",1006);
+		 }
+		foreach ($web as $item){
+			$actGood =$actm->where(["id"=>$item,"is_del"=>0])->find();
+    	    if($actGood==false) return json_show(1005,'未找到商品数据');
+    	    $num =Db::name("act_goodurl")->where(["act_good_id"=>$item,"is_del"=>0])->count();
+    	    if($num<$actGood['stock_num']){
+    	    	$up =$actm->where(["id"=>$item,"is_del"=>0])->update(["status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
+    	    	if($up==false) return json_show(1005,'商品数据更新失败');
+    	    	$upunum = $actm->where(["actCode"=>$actGood["actCode"],"is_del"=>0,"status"=>0])->count();
+    	    	if($upunum!=0){
+    	    		$up1 =Db::name("Act")->where(["actCode"=>$actGood["actCode"],"is_del"=>0])->update(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+			        if ($up1==false){
+				        throw new Exception("活动数据更新失败",1006);
+			        }
+    	    	}
+
+    	    }
+		}
+    	Db::commit();
+    	return json_show(0,'商品链接导入成功');
+    	}catch (\Exception $e){
+    		Db::rollback();
+    		return json_show(1008,$e->getMessage());
+    	}
+    }
+
+     //获取跟有赞对接的平台所属的商品上线信息
+    public function listByYz()
+    {
+    	 $this->noble=\think\facade\Config::get("noble");
+        $order=\think\facade\Config::get("order");
+        $this->acton=$order['order_type'];
+        $param = $this->request->only([
+            'page' => 1,
+            'size' => 15,
+            'good_name' => '',
+            'skucode' => '',
+            'plat_code' => '',
+            'exam_status' => '',
+        ], 'post', 'trim');
+        $where = [["b.is_del", "=", 0],["b.platform_id","=",$this->platformid]];
+        if ($param['good_name'] !== "") $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
+        if ($param['skucode'] !== '') $where [] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
+        if ($param['plat_code'] !== '') $where[] = ["b.plat_code", "like", '%' . $param['plat_code'] . '%'];
+        if ($param['exam_status'] !== '') {
+        	if($param['exam_status']==1){
+        		$where[] = ['b.exam_status', "=", 6];
+        	}else{
+        		$where[] = ['b.exam_status', "<>", 6];
+        	}
+        }
+		if($this->request->isCx==1){
+			$field="b.skuCode,b.platform_id platform_code,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,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,
+			a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,b.exam_status,a.createrid purchase_id,
+			a.creater purchase";
+		}else{
+			$field="b.skuCode,b.plat_code,b.id as platform_youzan_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,b.exam_status,a.spuCode,
+            b.sale_price,b.final_price";
+		}
+
+        $count = Db::name('platform_youzan')
+            ->alias("b")
+            ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
+            ->where($where)
+            ->count();
+
+        $total = ceil($count / $param['size']);
+        $param['page'] = $param['page'] >= $total ? $total : $param['page'];
+        $list = Db::name('platform_youzan')
+            ->alias("b")
+            ->field($field)
+            //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
+            ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
+            ->where($where)
+            ->page(intval($param['page']),intval($param['size']))
+            ->order("b.addtime desc")
+            ->cursor();
+        $data = [];
+        $yzgood = new YzGood();
+        foreach ($list as $value) {
+            $brand = Db::name("brand")->field('id,brand_name')->where(["id" => $value['brand_id']])->find();
+            $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
+
+            $unit = Db::name("unit")->field('id,unit')->where(["id" => $value['good_unit']])->find();
+            $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
+		    $value['exam_status'] = $value['exam_status']==6?1:0;
+            $value['origin_price'] =$yzgood->where(["item_no"=>$value['skuCode'],"is_del"=>0])->value("origin",'');
+
+            $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
+            $speclist = [];
+            if (!empty($spec)) {
+                foreach ($spec as $val) {
+                    $temp = [];
+                    $temp['spec_id'] = $val['spec_id'];
+                    $temp['spec_value_id'] = $val['spec_value_id'];
+                    $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+                    $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+                    $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+                    $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+                    $speclist[] = $temp;
+                }
+            }
+            $value['good_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$value['good_img']);
+            $value['good_info_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$value['good_img']);
+            $value['good_thumb_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$value['good_img']);
+            if($this->request->isCx==1){
+        	$value['cat_info'] = made($value['cat_id'], []);
+            $platform = Db::name("platform")->field('id,platform_name')->where(["id" => $value['platform_code']])->find();
+            $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
+            $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
+            $supplier = Db::name("supplier")->field('id,name')->where(["code" => $value['supplierNo']])->find();
+            $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
+            $value['company'] = isset($company['company']) ? $company['company'] : "";
+            $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
+            $value['exclusive'] = makeExcluse($value['is_exclusive']);
+            $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
+            $itemid =Db::name("depart_user")->where(["uid"=>$value["purchase_id"],"is_del"=>0])->value("itemid",'');
+            $value['company_name'] = implode('/', array_column(GetPart($itemid), 'name'));
+        	}else{
+            	unset($value['brand_id']);
+			unset($value['good_unit']);
+			unset($value['spuCode']);
+        	}
+
+            $value['specinfo'] = $speclist;
+            $data[] = $value;
+        }
+        return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
+    }
+
+	/**
+	 * @return \think\response\Json
+	 * @throws \think\db\exception\DataNotFoundException
+	 * @throws \think\db\exception\DbException
+	 * @throws \think\db\exception\ModelNotFoundException
+	 */
+    public function YzGoodInfo(){
+	    $param =$this->request->only(["skuCode"=>''],"post","trim");
+	    if($param['skuCode']=='') return json_show(1004,"参数 skuCode 不能为空");
+	    if($this->request->isCx==1){
+			$field="b.skuCode,b.platform_id platform_code,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,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,
+			a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,b.exam_status,a.createrid purchase_id,
+			a.creater purchase";
+		}else{
+			$field="b.skuCode,b.plat_code,b.id as platform_youzan_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,b.exam_status,a.spuCode,
+            b.sale_price,b.final_price";
+		}
+	    $info = Db::name('platform_youzan')
+	              ->alias("b")
+	              ->field($field)
+		    //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
+		          ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
+	              ->where(["b.skuCode"=>$param['skuCode'],"b.is_del"=>0])->find();
+
+	    if($info==false)  return json_show(1005,"商品数据未找到");
+	    $yzgood = new YzGood();
+	    $brand = Db::name("brand")->field('id,brand_name')->where(["id" => $info['brand_id']])->find();
+	    $info["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
+	    $unit = Db::name("unit")->field('id,unit')->where(["id" => $info['good_unit']])->find();
+	    $info['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
+	    $info['exam_status'] = $info['exam_status']==6?1:0;
+	    $info['origin_price'] =$yzgood->where(["item_no"=>$info['skuCode'],"is_del"=>0])->value("origin",'');
+	    $spec = Db::name("good_spec")->where(["spuCode" => $info['spuCode'], "is_del" => 0])->select()->toArray();
+	    $speclist = [];
+	    if (!empty($spec)) {
+		    foreach ($spec as $val) {
+			    $temp = [];
+			    $temp['spec_id'] = $val['spec_id'];
+			    $temp['spec_value_id'] = $val['spec_value_id'];
+			    $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
+			    $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
+			    $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
+			    $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
+			    $speclist[] = $temp;
+		    }
+	    }
+	    $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_img']);
+	    $info['good_thumb_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$info['good_img']);
+	    if($this->request->isCx==1){
+        	$info['cat_info'] = made($info['cat_id'], []);
+            $platform = Db::name("platform")->field('id,platform_name')->where(["id" => $info['platform_code']])->find();
+            $info['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
+            $info['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
+            $supplier = Db::name("supplier")->field('id,name')->where(["code" => $info['supplierNo']])->find();
+            $info['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
+            $info['company'] = isset($company['company']) ? $company['company'] : "";
+            $info['stock_total'] = Db::name("good_stock")->where(['spuCode' => $info['spuCode'], "is_del" => 0])->sum("usable_stock");
+            $info['exclusive'] = makeExcluse($info['is_exclusive']);
+            $info['noble_name'] = isset($info['noble_metal']) && $info['noble_metal'] != 0 ? $this->noble[$info['noble_metal']] : "";
+            $itemid =Db::name("depart_user")->where(["uid"=>$info["purchase_id"],"is_del"=>0])->value("itemid",'');
+            $info['company_name'] = implode('/', array_column(GetPart($itemid), 'name'));
+        	}else{
+	    	unset($info['brand_id']);
+		    unset($info['good_unit']);
+		    unset($info['spuCode']);
+        	}
+
+	    $info['specinfo'] = $speclist;
+	    return json_show(0,"获取成功",$info);
+    }
+}

+ 10 - 0
app/txx/middleware.php

@@ -0,0 +1,10 @@
+<?php
+// 全局中间件定义文件
+return [
+    // 全局请求缓存
+    app\txx\middleware\CheckAuth::class
+    // 多语言加载
+    // \think\middleware\LoadLangPack::class,
+    // Session初始化
+    // \think\middleware\SessionInit::class
+];

+ 63 - 0
app/txx/middleware/CheckAuth.php

@@ -0,0 +1,63 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\middleware;
+
+use app\txx\common\Sign;
+use think\facade\Db;
+class CheckAuth
+{
+    /**
+     * 处理请求
+     *
+     * @param \think\Request $request
+     * @param \Closure       $next
+     * @return Response
+     */
+    public function handle($request, \Closure $next)
+    {
+    	$request->isCx=0;
+    	$request->uid=0;
+    	$request->uname='';
+        $param = $request->post();
+	    if(!isset($param['token'])||$param['token']==''){
+		    $header = $request->header();
+		    $check =$this->check($header,$param);
+		    if($check['code']==1){
+			    return json_show(104,$check['msg']);
+		    }
+	    }else{
+			$acct =VerifyTokens($param['token']);
+	    	if(!isset($acct['code']) || $acct['code']!=0){
+			    return  json_show(102,$acct['message']);
+		    }
+	        $request->uid=isset($acct['data']['user']['id']) ?$acct['data']['user']['id']:"";
+            $request->uname=isset($acct['data']['user']['nickname']) ?$acct['data']['user']['nickname']:"";
+	    	$request->isCx=1;
+	    }
+		$response = $next($request);
+	    return $response;
+
+
+    }
+	/**数据接口签名验证
+	* @param $data
+	* @param $param
+	 * @return array
+	 */
+    private  function check($data,$param){
+        //check sign
+        if (!isset($data['appid']) || !$data['appid']) {
+            return ['code'=>1,'msg'=>'发送的应用参数不存在'];
+        }
+        $appinf =Db::name("act_company")->where(["app_id"=>$data['appid'],"is_del"=>0,"status"=>1])->findOrEmpty();
+        if(empty($appinf)){
+        	  return ['code'=>1,'msg'=>'发送的应用参数错误'];
+        }
+		$mege=["appid"=>$data['appid'],"nonce"=>$data['noce']??'',"sign"=>$data['sign']??'',"timestamp"=>$data['timestamp']??''];
+        $value =array_merge($mege,$param);
+        $Sign=new Sign($appinf['app_id'],$appinf['app_key']);
+        $result =$Sign->verifySign($value);
+        return $result;
+    }
+}

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

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

+ 26 - 0
app/txx/model/ActGood.php

@@ -0,0 +1,26 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\model;
+
+use think\Exception;use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ActGood extends Model
+{
+    //
+    static function ActAdd(array $Good, string $actCode,array $userinfo=[]){
+    	if (empty($Good)) throw new Exception("参与活动商品不能为空",1006);
+    	self::startTrans();
+    	$data=[];
+    	foreach ($Good as $item ){
+			$temp=[
+				"actCode"=>$actCode,
+				"yz_good_id"=>$item['id'],
+
+			];
+    	}
+    }
+}

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

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

+ 17 - 0
app/txx/model/YzGood.php

@@ -0,0 +1,17 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class YzGood extends Model
+{
+    protected $connection = 'mysql_yz';//切换连接参数
+    protected $table = 'yz_good';
+    protected $pk = 'id';
+    protected $autoWriteTimestamp = false;
+}

+ 19 - 0
app/txx/route/app.php

@@ -0,0 +1,19 @@
+<?php
+use think\facade\Route;
+
+Route::rule('ActAdd', 'txx/Act/create');
+Route::rule('Actlist', 'txx/Act/list');
+Route::rule('ActEdit', 'txx/Act/save');
+Route::rule('ActInfo', 'txx/Act/info');
+Route::rule('ActDel', 'txx/Act/delete');
+
+
+Route::rule('ActGoodAdd', 'txx/Good/AddGood');
+Route::rule('ActGoodList', 'txx/Good/list');
+Route::rule('ActGoodEdit', 'txx/Good/EditGood');
+Route::rule('ActGoodInfo', 'txx/Good/GoodInfo');
+Route::rule('ActGoodUrlImport', 'txx/Good/GoodUrlImport');
+Route::rule('ActGoodUrlList', 'txx/Good/GoodUrlList');
+Route::rule('ActGoodUrlDel', 'txx/Good/GoodUrlDel');
+Route::rule('yzgoodlist', 'txx/Good/listByYz');
+Route::rule('yzgoodinfo', 'txx/Good/YzGoodInfo');