wugg 8 months ago
parent
commit
71a6879a6c

+ 1 - 23
app/admin/controller/Cat.php

@@ -518,29 +518,7 @@ class Cat extends Base
         if ($status === '') {
             return error_show(1002, '参数status不能为空');
         }
-//        if ($status == 1) {
-//            if ($stn['rate'] === '') {
-//                return error_show(1003, '单品修改下限未设置');
-//            }
-//            if ($stn['order_rate'] === '') {
-//                return error_show(1003, '预算成本利率未设置');
-//            }
-//            if ($stn['sale_rate'] === '') {
-//                return error_show(1003, '分类成本售价利率未设置');
-//            }
-//            if ($stn['lower_rate'] === '') {
-//                return error_show(1003, '分类最低毛利率未设置');
-//            }
-//        if($stn['money_rate']==''){
-//            return error_show(1003,'分类财务利率未设置');
-//        }
-//        if($stn['low_rate']==''){
-//            return error_show(1003,'分类最低毛利未设置');
-//        }
-//        if($stn['fund_code']==''){
-//            return error_show(1003,'分类核算码未设置');
-//        }
-//        }
+
         if ($stn['level'] == 3) {
             if ($status == 1) {
                 $can = made($stn['id']);

+ 2 - 22
app/admin/controller/Suppler.php

@@ -20,12 +20,6 @@ class Suppler extends Base
         if ($name == "") {
             return error_show(1002, "参数name不能为空");
         }
-//        $rename = Db::name('supplier')->field('id')->where(['is_del' => 0, 'name' => $name])->find();
-//        if (!empty($rename)) {
-//            return error_show(1002, "公司名称已存在");
-//        }
-
-
         $tr = makeNo("QS");
         $source = isset($this->post['source']) && $this->post['source'] !== "" ? intval($this->post['source']) : "";
         if ($source === "") {
@@ -208,21 +202,7 @@ class Suppler extends Base
 
         return json_show($rs['code'], $rs['message'], $rs['data']);
 
-//                if ($vp == "") {
-//                    Db::rollback();
-//                    return error_show(1002, "添加失败");
-//                }
-
-//                Db::commit();
-//                return app_show(0, "添加成功", ["id" => $join]);
-//            } else {
-//                Db::rollback();
-//                return error_show(1002, "添加失败");
-//            }
-//        } catch (\Exception $e) {
-//            Db::rollback();
-//            return error_show(1003, $e->getMessage());
-//        }
+
     }
 
     public function list()
@@ -557,7 +537,7 @@ class Suppler extends Base
         return json_show($rs['code'], $rs['message'], $rs['data']);
     }
 
-    //供应商升级成业务公司
+    //供应商升级成业务公司IIV2407051106408353
     public function upgrade(){
 
         $param = $this->request->filter('trim')->post();

+ 0 - 71
app/admin/controller/User.php

@@ -142,77 +142,6 @@ class User extends Base
     //详情
     public function userInfo()
     {
-        /**
-         * $post = $this->request->post();
-         * $token = isset($post['token']) ? trim($post['token']) : "";
-         * if ($token == "") {
-         * return app_show(101, 'token不能为空');
-         * }
-         * $effetc = VerifyTokens($token);
-         * if (!empty($effetc) && $effetc['code'] != 0) {
-         * return app_show($effetc['code'], $effetc['message']);
-         * }
-         * $userinfo = GetUserInfo($token);
-         * if (empty($userinfo) || $userinfo['code'] != 0) {
-         * return app_show(102, "员工信息不存在");
-         * }
-         * $id = isset($post['id']) && $post['id'] !== "" ? trim($post['id']) : "";
-         * if ($id == "") {
-         * return error_show(1004, "id不能为空");
-         * }
-         * $to = GetInfoById($token, ['id' => $id]);
-         * if (empty($to) || $to['code'] != 0) {
-         * return app_show(1002, "员工信息不存在");
-         * }
-         * // $nickname = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
-         * $data = $to['data'];
-         * $role = Db::name("user_role")->alias('a')->leftJoin('role b', "a.roleid = b.id")->where("a.uid", "=", $data['id'])
-         * ->field("roleid,role_name,business_all,uid,a.status")->find();
-         * $data['role_name'] = isset($role['role_name']) ? $role['role_name'] : "";
-         * $data['roleid'] = isset($role['roleid']) ? $role['roleid'] : "";
-         * $data['status'] = isset($role['status']) ? $role['status'] : '0';
-         * $st = Db::name('user_business')->where(['userid' => $role['uid'], "is_del" => 0])->field('businessid,is_main')->select()->toArray();
-         * $val = [];
-         * if (!empty($st)) {
-         * foreach ($st as $itom) {
-         * $tep = [];
-         * $business = Db::name('business')->where(['id' => $itom['businessid'], "is_del" => 0])->field("company,companyNo")->find();
-         * $tep['company'] = isset($business['company']) ? $business['company'] : "";
-         * $tep['companyNo'] = isset($business['companyNo']) ? $business['companyNo'] : "";
-         * $tep['businessid'] = $itom['businessid'];
-         * $tep['is_main'] = $itom['is_main'];
-         * $val[] = $tep;
-         * }
-         * }
-         * $data['business'] = $val;
-         * $info = [];
-         * $stn = Db::name('user_platform')->where(['uid' => $role['uid']])->find();
-         * if ($stn != false) {
-         * $plat = isset($stn['platform']) ? explode(",", $stn['platform']) : "";
-         * if ($plat != "") {
-         * $platform = Db::name('platform')->where(['id' => $plat, 'is_del' => 0])->column("id,platform_name,platform_code");
-         * $info = $platform;
-         * }
-         *
-         * }
-         * $depart = Db::name("depart_user")->where([["uid", "=", $data['id']], ["is_del", "=", 0]])->column("itemid");
-         * $data['depart'] = "";
-         *
-         * if (!empty($depart)) {
-         * $deparname = Db::name("company_item")->where(["id" => $depart, "is_del" => 0])->field("id,name,depart_link")->select()->toArray();
-         * if (!empty($deparname)) {
-         * foreach ($deparname as $ky => $item) {
-         * $deparname[$ky]['depart_code'] = array_filter(explode("-", $item['depart_link']));
-         * }
-         * }
-         * $data['depart'] = $deparname;
-         * }
-         * $data['platform'] = $info;
-         *
-         * return app_show(0, "获取成功", $data);
-         * **/
-
-//        $id = $this->request->post('id/d', 0, "trim");
 
         $userCommon = CommonUser::getIns();
         $rs = json_decode($userCommon->GetUserInfo(['id' => $this->uid]), true);

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

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

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

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

+ 11 - 1
app/admin/model/GoodBasic.php

@@ -10,5 +10,15 @@ use think\Model;
  */
 class GoodBasic extends Model
 {
-    //
+    public function brand(){
+        return $this->belongsTo(Brand::class,"brand_id","id")->bind(["brand_name"]);
+    }
+
+    public function category(){
+        return $this->belongsTo(Cat::class,"cat_id","id")->bind(["cat_name","cat_search"=>"search"]);
+    }
+
+    public function Unit(){
+        return $this->belongsTo(Unit::class,"good_unit","id")->bind(["unit_name"=>"unit"]);
+    }
 }

+ 6 - 4
app/admin/route/app.php

@@ -11,8 +11,8 @@
 use think\facade\Route;
 
 Route::rule('menu', 'admin/Menu/list');
-Route::rule('menusave', 'admin/Menu/MenuEdit');
-Route::rule('menudel', 'admin/Menu/MenuDel');
+Route::rule('menusave', 'admin/Menu/create');
+Route::rule('menudel', 'admin/Menu/delete');
 Route::rule('menustatus', 'admin/Menu/MenuStatus');
 Route::rule("menulist", "admin/Menu/MenuAllList");
 Route::rule('menuaction', 'admin/Action/ActionList');
@@ -21,8 +21,6 @@ Route::rule('menuactionstatus', 'admin/Action/ActionStatus');
 Route::rule('menuactionadd', 'admin/Action/ActionAdd');
 Route::rule("menuactionlist", "admin/Action/index");
 Route::rule("menuactiondel", "admin/Menu/MenuActionDel");
-Route::rule("actiondata", "admin/Action/DataAction");
-Route::rule("actionsave", "admin/Action/ActionSave");
 Route::rule("actionstatus", "admin/Action/ActionStatus");
 Route::rule("actioninfo", "admin/Action/ActionInfo");
 Route::rule("actionlist", "admin/Action/ActionList");
@@ -52,11 +50,13 @@ Route::rule('query', 'admin/Newfill/query');
 Route::rule('itemdel', 'admin/Newfill/itemdel');
 Route::rule('stat', 'admin/Newfill/stat');
 Route::rule('userp', 'admin/Newfill/userp');
+
 Route::rule('clist', 'admin/Departuser/list');
 Route::rule('attend', 'admin/Departuser/attend');
 Route::rule('useredit', 'admin/Departuser/useredit');
 Route::rule('ifound', 'admin/Departuser/found');
 Route::rule('iuserdel', 'admin/Departuser/userdel');
+
 Route::rule('customerlist', 'admin/Customer/list');
 Route::rule('customercreate', 'admin/Customer/create');
 Route::rule('customerupdate', 'admin/Customer/update');
@@ -69,12 +69,14 @@ Route::rule('supplieredit', 'admin/Supplier/edit');
 Route::rule('supplierselec', 'admin/Supplier/selec');
 Route::rule('supplierdelect', 'admin/Supplier/del');
 Route::rule('comprehensiveList', 'admin/Supplier/comprehensiveList');//供应商和业务企业合并列表
+
 Route::rule('resultlist', 'admin/Result/list');
 Route::rule('resultcreate', 'admin/Result/create');
 Route::rule('resultselect', 'admin/Result/selec');
 Route::rule('resultedit', 'admin/Result/edit');
 Route::rule('resultdel', 'admin/Result/del');
 Route::rule('resultstatu', 'admin/Result/statu');
+
 Route::rule('Resigninfolist', 'admin/Resigninfo/list');//离职交接单列表
 Route::rule('Resigninfocreate', 'admin/Resigninfo/create');//离职交接单创建
 Route::rule('Resigninfoselect', 'admin/Resigninfo/selec');

+ 70 - 0
app/command/roleAction.php

@@ -0,0 +1,70 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use app\admin\model\Action;use app\admin\model\Role;use app\admin\model\UserRole;use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;use think\facade\Db;
+
+class roleAction extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('roleaction')
+            ->setDescription('the roleaction command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+    	$list= Db::name("user_role")->alias("a")
+    	->leftJoin("role_action b"," a.roleid = b.role_id ")
+    	->where(["a.is_del"=>0])
+    	->cursor();
+    	$data=[];
+    	$db = Db::connect('mysql_sys');
+    	foreach ($list as $item){
+    	   $ti= $db->name('account_company')->where(["companyCode"=>$item['companyNo'],"is_del"=>0,
+    	   "account_id"=>$item['uid']])->findOrEmpty();
+    	   if(empty($ti)) continue;
+    	    $temp=[];
+    	    $temp[] = $db->name("user")->where("account_id",$item['uid'])->value("nickname");
+    	    $temp[]= Db::name('role')->where("id",$item['roleid'])->value("role_name");
+    	    $temp[] =$db->name("headquarters")->where("code",$item['companyNo'])->value("name","所有");
+    	    $temp[] =$item['companyNo'];
+    	    $menu=[];
+            if($item['action_conllect']!=''){
+            	 $menu = Db::name('action')->alias('a')
+    	    ->leftJoin('admin_menu c','a.menuid=c.id')
+    	    ->leftJoin('action_list d','a.action_code=d.action_code')
+    	    ->whereIn('a.id',explode(',',$item['action_conllect']))
+    	    ->field("CONCAT(menu_name,'-',action_name) as menu")->select()->toArray();
+            }
+    	   
+    	    $data[]= array_merge($temp,array_column($menu,"menu"));
+    	}
+    	excelSaveFile($data,"权限采销");
+    }
+
+
+    public function RoleProcess(){
+        $list = Db::name("role_process")->where(["is_del"=>0])->cursor();
+        $data=[];
+        $db = Db::connect('mysql_sys');
+        foreach ($list as $item){
+           $temp=[];
+           $roleinfo = Db::name('role')->where('id',$item['role_id'])->findOrEmpty();
+           $temp[] = $roleinfo['role_name']??"";
+           $temp[] =$db->name('headquarters')->where('code',$roleinfo['companyNo'])->value('name','所有');;
+           if($item['action_data']!=""){
+               $prceos = Db::name("action_process")->whereIn('id',explode(',',$item['action_data']))
+                ->field("CONCAT(order_name,'-',status_name) as proce")->select()->toArray();
+                $data[]= array_merge($temp,array_column($prceos,'proce'));
+           }
+        }
+        excelSaveFile($data,'权限流程采销');
+    }
+}

+ 3 - 4
app/common.php

@@ -858,11 +858,10 @@ function GoodPrice($data,$cost_rate=0){
 }
 
 function checkRole($roleid,$menu){
-    $roleinfo = Db::name("role_action")->where([['role_id',"=",$roleid],["status","=",1]])->find();
-    if($roleinfo['private_data']!=""){
+    $roleinfo = \think\facade\Db::name('role_action')->where([['role_id','in',$roleid],['status','=',1]])->json(['private_data'])->find();
+    if(!empty($roleinfo['private_data'])){
 
-        $private = explode(",",$roleinfo['private_data']);
-        if(in_array($menu,$private)){
+        if(in_array($menu,$roleinfo['private_data'])){
             return true;
         }
     }

+ 49 - 0
app/txx/command/updateAct.php

@@ -0,0 +1,49 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\txx\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+
+class updateAct extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('updateact')
+            ->setDescription('the updateact command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        // 指令输出
+        $actGood=new \app\txx\model\ActGood();//同步券码
+        $actGood->startTrans();
+        try{
+        $info = $actGood->with(['act','promocode'])
+        ->where(['version'=>'2.0','status'=>2,'is_del'=>0])->findOrEmpty();
+        if(!$info->isEmpty()){
+            if($info->promocode_status==1){
+                $info->status=3;
+                $info->save();
+            }else{
+                $info->status=5;
+                $info->remark=$info->promocode_remark;
+                $info->save();
+                $info->act->status=6;
+                $info->act->save();
+            }
+        }
+        $actGood->commit();
+        }catch (\Exception $e){
+            $actGood->rollback();
+            $output->writeln('<error>'.$e->getMessage().'</error>');
+        }
+
+        $output->writeln('updateact');
+    }
+}

+ 47 - 27
app/txx/controller/Act.php

@@ -8,17 +8,18 @@ use think\facade\Validate;
 use app\txx\model\Act as Actm;
 use think\App;
 
-class Act extends BaseController
+class Act extends Base
 {
 	protected $uid=0;
 	protected $uname='';
-		public function __construct(App $app) {
+	protected $model;
+    public function __construct(App $app) {
 		parent::__construct($app);
 		if($this->request->isCx==1){
 		    $this->uid=$this->request->uid;
 	        $this->uname=$this->request->uname;
 		}
-
+        $this->model=new Actm();
 	}
     /**
      * 显示资源列表
@@ -38,6 +39,7 @@ class Act extends BaseController
         "start"=>'',
         "end"=>'',
         "status"=>'',
+        'act_status'=>'',
       	],"post",'trim');
       $condition=[["is_del","=",0]];
       if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
@@ -48,12 +50,23 @@ class Act extends BaseController
       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]);
+      if($param['act_status']!='') {
+          if($param['act_status']==1){
+              $condition[]=["startTime",">",date("Y-m-d H:i:s")];
+          }elseif($param['act_status']==2){
+             $condition[]=['startTime','<',date('Y-m-d H:i:s')];
+             $condition[]=['endTime','>',date('Y-m-d H:i:s')];
+          }elseif($param['act_status']==3){
+             $condition[]=['endTime','<',date('Y-m-d H:i:s')];
+          }
+      }
+
+      $list=$this->model->where($condition)
+      ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']])
+      ->each(function(&$item){
+        $item['act_status']=time()< strtotime($item['startTime'])?1:(time()> strtotime($item['endTime'])?3:2);
+      });
+      $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
     }
 
     /**
@@ -80,7 +93,7 @@ class Act extends BaseController
             'contactor|联系人' => 'require|max:255',
             'mobile|联系电话' => 'require',
         ]);
-        if($validate->check($param)==false)return  json_show(1004,$validate->getError());
+        if($validate->check($param)==false)$this->error($validate->getError());
         $actCode=makeNo("ACE");
         $data=[
         	"actCode"=>$actCode,
@@ -93,14 +106,15 @@ class Act extends BaseController
         	"endTime"=>$param['end']==''?null : $param['end'],
         	"web_url"=>$param['web_url']??"",
         	"status"=>0,
+        	"version"=>"2.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,"活动新建失败");
-
+        $add =$this->model->create($data);
+        if($add->isEmpty())$this->error("活动添加失败");
+        $this->success("添加成功",["actCode"=>$actCode]);
     }
 
     /**
@@ -133,7 +147,9 @@ class Act extends BaseController
         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,"活动不存在");
+        if($info->isEmpty()) return json_show(1005,"活动不存在");
+        if($info->status==1) return json_show(1005,"活动已发布,不能编辑");
+
         $data=[
         	"act_name"=>$param['act_name'],
         	"company_name"=>$param['company_name'],
@@ -145,8 +161,9 @@ class Act extends BaseController
         	"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,"活动编辑失败");
+        $add =$info->save($data);
+        if($add==false)$this->error('活动修改失败');
+        $this->success('活动修改成功');
     }
 
     /**
@@ -160,10 +177,10 @@ class Act extends BaseController
     $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);
+      if($validate->check($param)==false)$this->error($validate->getError());
+
+      $info = $this->model->with(["goodInfo"])->where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+      $this->success("获取成功",$info);
     }
 
       /**
@@ -174,14 +191,17 @@ class Act extends BaseController
      */
     public function delete()
     {
-		$param = $this->request->only(["actCode"=>''],"post","trim");
+	    $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,"活动删除失败");
+      if($validate->check($param)==false)$this->error($validate->getError());
+      ;
+        $info = $this->model->where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+      if($info==false) $this->error("活动不存在");
+      $info->is_del=1;
+      $info->save();
+      $info->goodInfo()->update(["is_del"=>1]);
+      $this->success("删除成功");
+
     }
 }

+ 180 - 0
app/txx/controller/Activity.php

@@ -0,0 +1,180 @@
+<?php
+
+
+namespace app\txx\controller;
+
+
+use app\txx\model\ActGood;
+use app\txx\model\PlatformYouzan;
+use think\App;
+use think\facade\Validate;
+class Activity extends Base{
+    private $platform_id=[37,79];
+    private $model;
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        $this->model = new ActGood();
+    }
+    public function goodList(){
+        $param = $this->request->param(["good_name"=>"","skuCode"=>'',"plat_code"=>'',"exam_status"=>"","page"=>1,"size"=>15],"post","trim");
+        $where=[["is_del","=",0],["platform_id",'in',$this->platform_id]];
+        if($param['good_name']!=="")$where[]=["good_name","like","%".$param['good_name']."%"];
+        if($param['skuCode']!=="")$where[]=["skuCode","like","%".$param['skuCode']."%"];
+        if($param['plat_code']!=="")$where[]=["plat_code","like","%".$param['plat_code']."%"];
+        if($param['exam_status']!==''){
+            $where[]=["exam_status","=",$param['exam_status']];
+        }
+        $list=PlatformYouzan::with(["good"=>["unit","category","brand"],"platform","yzGood"])
+        ->where($where)->order("id desc")
+        ->field("plat_code,spuCode,skuCode,sale_price,final_price,exam_status,online_time,creater")
+        ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
+    }
+
+    public function create(){
+        $param = $this->request->param(["snArr"=>"","actCode"=>""],"post","trim");
+        $valid = Validate::rule([
+            "snArr|选中的商品集合"=>"require|array",
+            "actCode|活动编码"=>"require|max:20"
+        ]);
+        if(!$valid->check($param)){
+            $this->error($valid->getError());
+        }
+        $skuCodeArr= array_column($param['snArr'],"skuCode");
+        $goodArr= PlatformYouzan::with(["yzGood"])->where(["skuCode"=>$skuCodeArr,"is_del"=>0])->select()->toArray();
+
+        if(count($goodArr)!==count($param['snArr'])){
+            $this->error("商品信息有误");
+        }
+        $yzGood = array_column($goodArr,"yzGood","skuCode");
+        $Act = \app\txx\model\Act::where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
+        if($Act->isEmpty()){
+            $this->error("活动信息有误");
+        }
+        if($Act->status!==4){
+            $this->error("活动状态有误");
+        }
+        if(strtotime($Act->end_time)<time()){
+            $this->error("活动已结束");
+        }
+         if(strtotime($Act->start_time)<time()){
+            $this->error('活动已开始');
+        }
+         $valids= Validate::rule([
+            "skuCode|商品编码"=>"require|max:20",
+            "stock_num|库存数量"=>"require|integer",
+            "roundId|轮次"=>"integer",
+        ]);
+       $actArr=[];
+        foreach ($param['snArr'] as $k=>$v){
+                if(!$valids->check($v)){
+                    $this->error($valids->getError());
+                }
+                 if(!isset($yzGood[$v['skuCode']])|| isset($yzGood[$v['skuCode']]['status']))throw new \Exception('商品信息有误');
+                 if($yzGood[$v['skuCode']]['status']!==6)throw new \Exception($v['skuCode'].'有赞商品未上线');
+                 $temp=[
+					'actCode'=>$param['actCode'],
+					'yz_good_code'=>$v['skuCode'],
+					'stock_num'=>$v['stock_num'],
+					'used_num'=>0,
+					'balance_num'=>$v['stock_num'],
+					'roundId'=>$v['roundId']??'',
+					'good_url'=>$yzGood[$v['skuCode']]['detail_url']??'',
+					'origin_price'=>$yzGood[$v['skuCode']]['origin']??'',
+					'status'=>1,
+					];
+                 $actArr[]=$temp;
+             }
+        $this->model->startTrans();
+         try{
+             $add= $this->model->saveAll($actArr);
+             if($add->isEmpty()) throw new \Exception('添加失败');
+             $Act->save(["status"=>1]);
+             $this->model->commit();
+        }catch (\Exception $e){
+             $this->model->rollback();
+             $this->error($e->getMessage());
+        }
+      $this->success('添加成功');
+    }
+
+    public function list(){
+        $param=$this->request->param(["actCode"=>"","status"=>"","skuCode"=>"","roundId"=>"","page"=>1,"size"=>15],"post","trim");
+        $where=[["is_del","=",0]];
+        if($param['actCode']!==""){
+            $where[]=["actCode","like","%".$param['actCode']."%"];
+        }
+        if($param['status']!==""){
+            $where[]=["status","=",$param['status']];
+        }
+        if($param['skuCode']!==""){
+            $where[]=["yz_good_code","like","%".$param['skuCode']."%"];
+        }
+        if($param['roundId']!==""){
+            $where[]=["roundId","=",$param['roundId']];
+        }
+        $list= $this->model->with(["act","platformYz"=>["platform","good"],"promocode"])->where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+        $list->each(function($item,$key){
+            $item['status_cn']=ActGood::$statusCn[$item['status']]??"";
+            $item['act_status_cn']=\app\txx\model\Act::$statusCn[$item['act_status']]??"";
+            return $item;
+        });
+        $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
+    }
+    public function info(){
+        $param=$this->request->param(["id"=>""],"post","trim");
+        $info= $this->model->with(["act","platformYz"=>["platform","good"],"promocode"])->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+        $info['status_cn']=ActGood::$statusCn[$info['status']]??"";
+        $info['act_status_cn']=\app\txx\model\Act::$statusCn[$info['act_status']];
+        $this->success("获取成功",$info);
+    }
+    public function resetPromocode(){
+        $param=$this->request->param(["id"=>""],"post","trim");
+        $info= $this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+        if(!in_array($info->status,[4,5]))throw new \Exception("状态有误");
+        $info->status=1;
+        try{
+           if($info->promocode_id!==0){
+            $promocode= \app\youzan\model\YzActivityPromoCode::findOrEmpty($info->promocode_id);
+            if($promocode->isEmpty())throw new \Exception('优惠券信息有误');
+            $promocode->save(['status'=>0]);
+
+        }else{
+            $info->promocode_id=0;
+        }
+        $save= $info->save();
+        if(!$save)throw new \Exception('重置失败');
+        }catch (\Exception $e){
+            $this->error($e->getMessage());
+        }
+        $this->success("重置成功");
+    }
+
+    public function delete(){
+        $param=$this->request->param(["id"=>""],"post","trim");
+        $info= $this->model->findOrEmpty($param['id']);
+        if($info->isEmpty()){
+            $this->error("信息有误");
+        }
+        $info->is_del=1;
+        try{
+            $save= $info->save();
+            if(!$save)throw new \Exception('删除失败');
+            if($info->promocode_id!==0){
+                $promocode= \app\youzan\model\YzActivityPromoCode::findOrEmpty($info->promocode_id);
+                if($promocode->isEmpty())throw new \Exception('优惠券信息有误');
+                $promocode->save(['is_del'=>1]);
+            }
+        }catch (\Exception $e){
+            $this->error($e->getMessage());
+        }
+        $this->success("删除成功");
+    }
+}

+ 3 - 2
app/txx/controller/Base.php

@@ -3,11 +3,12 @@ declare (strict_types = 1);
 
 namespace app\txx\controller;
 
-use think\App;
+use app\BaseController;use think\App;
 use think\exception\HttpResponseException;
 use think\Response;
 
-class Base extends \app\admin\controller\Base
+
+class Base extends BaseController
 {
 	public $white=[];
 	public function __construct(App $app) {

+ 1 - 1
app/txx/middleware.php

@@ -2,7 +2,7 @@
 // 全局中间件定义文件
 return [
     // 全局请求缓存
-    app\txx\middleware\CheckAuth::class
+//    app\txx\middleware\CheckAuth::class
     // 多语言加载
     // \think\middleware\LoadLangPack::class,
     // Session初始化

+ 5 - 1
app/txx/model/Act.php

@@ -10,5 +10,9 @@ use think\Model;
  */
 class Act extends Model
 {
-    //
+    public static $statusCn=["待选择商品","待同步创建优惠券码","待同步优惠券码","待确认上传至活动主办方","已确认上传至活动主办方","券码创建失败","券码同步失败"];
+
+    public function goodInfo(){
+        return $this->hasMany(ActGood::class,"actCode","actCode")->where(["is_del"=>0])->with(["Promocode"]);
+    }
 }

+ 35 - 11
app/txx/model/ActGood.php

@@ -3,24 +3,48 @@ declare (strict_types = 1);
 
 namespace app\txx\model;
 
-use think\Exception;use think\Model;
+use app\youzan\model\YzActivityPromoCode;
+use think\Exception;
+use think\Model;
 
 /**
  * @mixin \think\Model
  */
 class ActGood extends Model
 {
+    public static $statusCn=["待审核","待生成券码信息","待同步券码信息","已同步券码信息","券码生成失败","券码同步失败"];
     //
-    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'],
+    public function act(){
+        return $this->belongsTo(Act::class,"actCode","actCode")->bind(["act_anme","startTime","endTime","company_name","contactor","mobile","act_status"=>"status"]);
+    }
 
-			];
-    	}
+    public function Promocode(){
+        return $this->belongsTo(YzActivityPromoCode::class,"id","act_good_id")->bind(["title","code","fetch_url","promocode_status"=>"status","promocode_remark"=>"remark"]);
+    }
+    public function yzGood(){
+        return $this->belongsTo(YzGood::class,'yz_good_code','item_no')->bind(['good_name'=>'title','detail_url']);
     }
+
+    public function platformYz(){
+        return $this->belongsTo(PlatformYouzan::class,'yz_good_code','skuCode')->bind(['plat_code','spuCode','sale_price','final_price','platform_name',"good_name"]);
+    }
+    public static function onAfterUpdate(Model $model) : void{
+        if($model->version=="2.0" && $model->is_del==0){
+            self::sysncAct($model->actCode,$model->status,$model->version);
+         }
+     }
+
+    // 0 '待审核',1 '待生成券码信息',2 '待同步券码信息',3 '已同步券码信息',4 '券码生成失败',5'券码同步失败'
+    //'待选择商品','待同步创建优惠券码','待同步优惠券码','待确认上传至活动主办方','已确认上传至活动主办方','券码创建失败','券码同步失败'
+    public static function sysncAct($actCode,$goodStatus,$version){
+                $actStatus=["1"=>"1","2"=>"2","3"=>"3","4"=>"5","5"=>"6"];//0 '待审核',1 '待生成券码信息',2 '待同步券码信息',3 '已同步券码信息',4 '券码生成失败',5'券码同步失败'
+                $num = self::where(['version'=>$version,'actCode'=>$actCode,'is_del'=>0])->where('status','<>',$goodStatus)->count();
+               if($num==0){
+                    $act = \app\txx\model\Act::where(['actCode'=>$actCode])->findOrEmpty();
+                    if(!$act->isEmpty()){
+                        $act->status=$actStatus[$goodStatus];
+                        $act->save();
+                    }
+               }
+     }
 }

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

@@ -3,6 +3,8 @@ declare (strict_types = 1);
 
 namespace app\txx\model;
 
+use app\admin\model\GoodBasic;
+use app\admin\model\Platform;
 use think\model;
 
 /**
@@ -11,4 +13,16 @@ use think\model;
 class PlatformYouzan extends Model
 {
 
+    public function good(){
+        return $this->belongsTo(GoodBasic::class,"spuCode","spuCode")
+        ->bind(["good_name","cat_id","is_exclusive","brand_id","good_img","good_unit","unit_name","brand_name","cat_name",'cat_search']);
+    }
+
+    public function platform(){
+        return $this->belongsTo(Platform::class,"platform_id","id")->bind(["platform_name"]);
+    }
+
+    public function yzGood(){
+        return $this->belongsTo(YzGood::class,"skuCode","item_no")->bind(["origin_price"=>"origin","deatil_url","yz_status"=>"status"]);
+    }
 }

+ 11 - 11
app/txx/route/app.php

@@ -6,14 +6,14 @@ 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');
+//
+//
+//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');

+ 93 - 0
app/youzan/command/ActGood.php

@@ -0,0 +1,93 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\youzan\command;
+
+use app\admin\model\Act;use app\youzan\model\YzGood;use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+
+class ActGood extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('actgood')
+            ->setDescription('the actgood command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $output->writeln('<info>actgood</info>');
+        $actgood = \app\admin\model\ActGood::with(["act"])->where(["version"=>"2.0","status"=>1,"is_del"=>0,"promocode_id"=>0])->findOrEmpty();
+        if($actgood->isEmpty())$this->createPromocode($actgood);
+    }
+    /**id
+    act_good_id
+    skuCode
+    item_id
+    title
+    is_at_least
+    code
+    is_forbid_preference
+    specify_item_ids
+    is_share
+    start_at
+    end_at
+    total
+    expire_notice
+    quota
+    cent_value
+    code_type
+    range_type
+    at_least
+    status
+    group_id
+    is_expired
+    fetch_url
+    createTime
+    updateTime
+
+* @param $actgood
+ */
+    //
+    public function createPromocode($actgood){
+        $promocode = \app\youzan\model\YzActivityPromoCode::where(["act_good_id"=>$actgood->id,"skuCoode"=>$actgood->yz_good_code,"status"=>0])->findOrEmpty();
+        if($promocode->isEmpty()){
+            $promocode = \app\youzan\model\YzActivityPromoCode::create([
+                "act_good_id"=>$actgood->id,
+                "skuCoode"=>$actgood->yz_good_code,
+                "item_id"=>0,
+                "title"=>$actgood->name,
+                "is_at_least"=>0,
+                "code"=>"",
+                "is_forbid_preference"=>1,
+                "specify_item_ids"=>"",
+                "is_share"=>0,
+                "start_at"=>startTime($actgood->endTime),
+                "end_at"=>endTime(date("Y-m-d H:i:s",strtotime($actgood->endTime)+3600*24*7)),
+                "total"=>$actgood->balance_num,
+                "expire_notice"=>1,
+                "quota"=>1,
+                "cent_value"=>0,
+                "code_type"=>'GENERAL',
+                "range_type"=>"PART",
+                "at_least"=>0,
+                "status"=>0,
+                "addtime"=>date("Y-m-d H:i:s"),
+                "updatetime"=>date("Y-m-d H:i:s")
+            ]);
+            if(!$promocode->isEmpty()){
+                $actgood->promocode_id = $promocode->id;
+                $actgood->status = 2; //生成券码
+                $actgood->save();
+            }else {
+               $actgood->remark = "优惠券信息创建失败";
+               $actgood->status = 4;
+               $actgood->save();
+            }
+         }
+    }
+}

+ 19 - 0
app/youzan/model/YzActivityPromoCode.php

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

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

@@ -0,0 +1,17 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\youzan\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;
+}