|
@@ -3,22 +3,22 @@ declare (strict_types = 1);
|
|
|
|
|
|
namespace app\txx\controller;
|
|
namespace app\txx\controller;
|
|
|
|
|
|
-use app\BaseController;
|
|
|
|
|
|
+use app\txx\model\ActGood;
|
|
use think\facade\Validate;
|
|
use think\facade\Validate;
|
|
use app\txx\model\Act as Actm;
|
|
use app\txx\model\Act as Actm;
|
|
use think\App;
|
|
use think\App;
|
|
|
|
|
|
-class Act extends BaseController
|
|
|
|
|
|
+class Act extends Base
|
|
{
|
|
{
|
|
- protected $uid=0;
|
|
|
|
- protected $uname='';
|
|
|
|
- public function __construct(App $app) {
|
|
|
|
|
|
+ protected $model;
|
|
|
|
+ protected static $ActStatusCn=["无状态",'活动未开始','活动进行中',"活动已结束"];
|
|
|
|
+ public function __construct(App $app) {
|
|
parent::__construct($app);
|
|
parent::__construct($app);
|
|
if($this->request->isCx==1){
|
|
if($this->request->isCx==1){
|
|
$this->uid=$this->request->uid;
|
|
$this->uid=$this->request->uid;
|
|
$this->uname=$this->request->uname;
|
|
$this->uname=$this->request->uname;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ $this->model=new Actm();
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* 显示资源列表
|
|
* 显示资源列表
|
|
@@ -38,8 +38,9 @@ class Act extends BaseController
|
|
"start"=>'',
|
|
"start"=>'',
|
|
"end"=>'',
|
|
"end"=>'',
|
|
"status"=>'',
|
|
"status"=>'',
|
|
|
|
+ 'act_status'=>'',
|
|
],"post",'trim');
|
|
],"post",'trim');
|
|
- $condition=[["is_del","=",0]];
|
|
|
|
|
|
+ $condition=[["is_del","=",0],["version","=","2.0"]];
|
|
if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
|
|
if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
|
|
if($param['actCode']!='') $condition[]=["actCode","like","%{$param['actCode']}%"];
|
|
if($param['actCode']!='') $condition[]=["actCode","like","%{$param['actCode']}%"];
|
|
if($param['company_name']!='') $condition[]=["company_name","like","%{$param['company_name']}%"];
|
|
if($param['company_name']!='') $condition[]=["company_name","like","%{$param['company_name']}%"];
|
|
@@ -48,12 +49,24 @@ class Act extends BaseController
|
|
if($param['start']!='') $condition[]=["addtime",">=",$param["start"]." 00:00:00"];
|
|
if($param['start']!='') $condition[]=["addtime",">=",$param["start"]." 00:00:00"];
|
|
if($param['end']!='') $condition[]=["addtime","<=",$param["end"]." 23:59:59"];
|
|
if($param['end']!='') $condition[]=["addtime","<=",$param["end"]." 23:59:59"];
|
|
if($param['status']!='') $condition[]=["status","=",$param["status"]];
|
|
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)->order("id desc")
|
|
|
|
+ ->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);
|
|
|
|
+ $item['act_status_cn'] = self::$ActStatusCn[$item['act_status']];
|
|
|
|
+ });
|
|
|
|
+ $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -66,11 +79,13 @@ class Act extends BaseController
|
|
$param = $this->request->only([
|
|
$param = $this->request->only([
|
|
"act_name"=>"",
|
|
"act_name"=>"",
|
|
"company_name"=>'',
|
|
"company_name"=>'',
|
|
|
|
+ "depart"=>"",
|
|
"contactor"=>'',
|
|
"contactor"=>'',
|
|
"mobile"=>'',
|
|
"mobile"=>'',
|
|
"web_url"=>'',
|
|
"web_url"=>'',
|
|
"start"=>'',
|
|
"start"=>'',
|
|
"end"=>'',
|
|
"end"=>'',
|
|
|
|
+ "settle_time"=>"",
|
|
"act_type"=>1,
|
|
"act_type"=>1,
|
|
],"post","trim");
|
|
],"post","trim");
|
|
|
|
|
|
@@ -79,8 +94,10 @@ class Act extends BaseController
|
|
'company_name|活动公司名称' => 'require',
|
|
'company_name|活动公司名称' => 'require',
|
|
'contactor|联系人' => 'require|max:255',
|
|
'contactor|联系人' => 'require|max:255',
|
|
'mobile|联系电话' => 'require',
|
|
'mobile|联系电话' => 'require',
|
|
|
|
+ "depart|部门"=>"require",
|
|
|
|
+ "settle_time|结算时间"=>"require",
|
|
]);
|
|
]);
|
|
- if($validate->check($param)==false)return json_show(1004,$validate->getError());
|
|
|
|
|
|
+ if($validate->check($param)==false)$this->error($validate->getError());
|
|
$actCode=makeNo("ACE");
|
|
$actCode=makeNo("ACE");
|
|
$data=[
|
|
$data=[
|
|
"actCode"=>$actCode,
|
|
"actCode"=>$actCode,
|
|
@@ -88,19 +105,22 @@ class Act extends BaseController
|
|
"company_name"=>$param['company_name'],
|
|
"company_name"=>$param['company_name'],
|
|
"contactor"=>$param['contactor'],
|
|
"contactor"=>$param['contactor'],
|
|
"mobile"=>$param['mobile'],
|
|
"mobile"=>$param['mobile'],
|
|
|
|
+ "depart"=>$param['depart'],
|
|
"act_type"=>$param['act_type'],
|
|
"act_type"=>$param['act_type'],
|
|
"startTime"=>$param['start']==''?null : $param['start'],
|
|
"startTime"=>$param['start']==''?null : $param['start'],
|
|
"endTime"=>$param['end']==''?null : $param['end'],
|
|
"endTime"=>$param['end']==''?null : $param['end'],
|
|
"web_url"=>$param['web_url']??"",
|
|
"web_url"=>$param['web_url']??"",
|
|
|
|
+ "settle_time"=>date("Y-m-d H:i:s",strtotime($param['settle_time'])),
|
|
"status"=>0,
|
|
"status"=>0,
|
|
|
|
+ "version"=>"2.0",
|
|
"apply_id"=>$this->uid,
|
|
"apply_id"=>$this->uid,
|
|
"apply_name"=>$this->uname,
|
|
"apply_name"=>$this->uname,
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
"updatetime"=>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]);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -116,10 +136,12 @@ class Act extends BaseController
|
|
"company_name"=>'',
|
|
"company_name"=>'',
|
|
"contactor"=>'',
|
|
"contactor"=>'',
|
|
"mobile"=>'',
|
|
"mobile"=>'',
|
|
|
|
+ "depart"=>"",
|
|
"web_url"=>'',
|
|
"web_url"=>'',
|
|
"start"=>'',
|
|
"start"=>'',
|
|
"end"=>'',
|
|
"end"=>'',
|
|
"actCode"=>'',
|
|
"actCode"=>'',
|
|
|
|
+ 'settle_time'=>'',
|
|
"act_type"=>1,
|
|
"act_type"=>1,
|
|
],"post","trim");
|
|
],"post","trim");
|
|
|
|
|
|
@@ -129,24 +151,31 @@ class Act extends BaseController
|
|
'company_name|活动公司名称' => 'require',
|
|
'company_name|活动公司名称' => 'require',
|
|
'contactor|联系人' => 'require|max:255',
|
|
'contactor|联系人' => 'require|max:255',
|
|
'mobile|联系电话' => 'require',
|
|
'mobile|联系电话' => 'require',
|
|
|
|
+ 'depart|部门'=>'require',
|
|
|
|
+ 'settle_time|结算时间'=>'require',
|
|
]);
|
|
]);
|
|
- if($validate->check($param)==false)return json_show(1004,$validate->getError());
|
|
|
|
|
|
+ if($validate->check($param)==false)$this->error($validate->getError());
|
|
$actm=new Actm();
|
|
$actm=new Actm();
|
|
$info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
|
|
$info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
|
|
- if($info==false) return json_show(1005,"活动不存在");
|
|
|
|
|
|
+ if($info->isEmpty())$this->error("活动不存在");
|
|
|
|
+ if($info->status==1)$this->error("活动已发布,不能编辑");
|
|
|
|
+
|
|
$data=[
|
|
$data=[
|
|
"act_name"=>$param['act_name'],
|
|
"act_name"=>$param['act_name'],
|
|
"company_name"=>$param['company_name'],
|
|
"company_name"=>$param['company_name'],
|
|
"contactor"=>$param['contactor'],
|
|
"contactor"=>$param['contactor'],
|
|
"mobile"=>$param['mobile'],
|
|
"mobile"=>$param['mobile'],
|
|
"act_type"=>$param['act_type'],
|
|
"act_type"=>$param['act_type'],
|
|
|
|
+ "depart"=>$param['depart'],
|
|
|
|
+ "settle_time"=>date("Y-m-d H:i:s",strtotime($param['settle_time'])),
|
|
"startTime"=>$param['start']==''?null : $param['start'],
|
|
"startTime"=>$param['start']==''?null : $param['start'],
|
|
"endTime"=>$param['end']==''?null : $param['end'],
|
|
"endTime"=>$param['end']==''?null : $param['end'],
|
|
"web_url"=>$param['web_url']??"",
|
|
"web_url"=>$param['web_url']??"",
|
|
"updatetime"=>date("Y-m-d H:i:s"),
|
|
"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 +189,19 @@ class Act extends BaseController
|
|
$param = $this->request->only(["actCode"=>''],"post","trim");
|
|
$param = $this->request->only(["actCode"=>''],"post","trim");
|
|
$validate = Validate::rule([
|
|
$validate = Validate::rule([
|
|
'actCode|活动编号' => 'require',]);
|
|
'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();
|
|
|
|
+ if($info->isEmpty()) $this->error("活动不存在");
|
|
|
|
+ $info['act_status']=time()< strtotime($info['startTime'])?1:(time()> strtotime($info['endTime'])?3:2);
|
|
|
|
+ $info['goodInfo']->each(function(&$item){
|
|
|
|
+ $item['status_cn']=ActGood::$statusCn[$item['status']]??'';
|
|
|
|
+ });
|
|
|
|
+ $info['statusCn'] = \app\txx\model\Act::$statusCn[$info['status']]??'';
|
|
|
|
+ $info['act_status_cn']=self::$ActStatusCn[$info['act_status']];
|
|
|
|
+ $info['goodInfo']->visible(['id','actCode','yz_good_code','stock_num','status','addtime','updatetime',
|
|
|
|
+ 'sale_price','good_name','unit_name','cat_name','brand_name','fetch_url','roundId','status_cn']);;
|
|
|
|
+ $this->success("获取成功",$info);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -174,14 +212,18 @@ class Act extends BaseController
|
|
*/
|
|
*/
|
|
public function delete()
|
|
public function delete()
|
|
{
|
|
{
|
|
- $param = $this->request->only(["actCode"=>''],"post","trim");
|
|
|
|
|
|
+ $param = $this->request->only(["actCode"=>''],"post","trim");
|
|
$validate = Validate::rule([
|
|
$validate = Validate::rule([
|
|
'actCode|活动编号' => 'require',]);
|
|
'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("删除成功");
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|