123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?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,"活动删除失败");
- }
- }
|