123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- declare (strict_types = 1);
- namespace app\txx\controller;
- use app\txx\model\ActGood;
- use think\facade\Validate;
- use app\txx\model\Act as Actm;
- use think\App;
- class Act extends Base
- {
- protected $model;
- protected static $ActStatusCn=["无状态",'活动未开始','活动进行中',"活动已结束"];
- 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();
- }
- /**
- * 显示资源列表
- *
- * @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"=>'',
- 'act_status'=>'',
- ],"post",'trim');
- $condition=[["is_del","=",0],["version","=","2.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"]];
- 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()]);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- $param = $this->request->only([
- "act_name"=>"",
- "company_name"=>'',
- "depart"=>"",
- "contactor"=>'',
- "mobile"=>'',
- "web_url"=>'',
- "start"=>'',
- "end"=>'',
- "settle_time"=>"",
- "act_type"=>1,
- ],"post","trim");
- $validate = Validate::rule([
- 'act_name|活动名称' => 'require',
- 'company_name|活动公司名称' => 'require',
- 'contactor|联系人' => 'require|max:255',
- 'mobile|联系电话' => 'require',
- "depart|部门"=>"require",
- "settle_time|结算时间"=>"require",
- ]);
- if($validate->check($param)==false)$this->error($validate->getError());
- $actCode=makeNo("ACE");
- $data=[
- "actCode"=>$actCode,
- "act_name"=>$param['act_name'],
- "company_name"=>$param['company_name'],
- "contactor"=>$param['contactor'],
- "mobile"=>$param['mobile'],
- "depart"=>$param['depart'],
- "act_type"=>$param['act_type'],
- "startTime"=>$param['start']==''?null : $param['start'],
- "endTime"=>$param['end']==''?null : $param['end'],
- "web_url"=>$param['web_url']??"",
- "settle_time"=>date("Y-m-d H:i:s",strtotime($param['settle_time'])),
- "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 =$this->model->create($data);
- if($add->isEmpty())$this->error("活动添加失败");
- $this->success("添加成功",["actCode"=>$actCode]);
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save()
- {
- $param = $this->request->only([
- "act_name"=>"",
- "company_name"=>'',
- "contactor"=>'',
- "mobile"=>'',
- "depart"=>"",
- "web_url"=>'',
- "start"=>'',
- "end"=>'',
- "actCode"=>'',
- 'settle_time'=>'',
- "act_type"=>1,
- ],"post","trim");
- $validate = Validate::rule([
- 'act_name|活动名称' => 'require',
- 'actCode|活动编号' => 'require',
- 'company_name|活动公司名称' => 'require',
- 'contactor|联系人' => 'require|max:255',
- 'mobile|联系电话' => 'require',
- 'depart|部门'=>'require',
- 'settle_time|结算时间'=>'require',
- ]);
- if($validate->check($param)==false)$this->error($validate->getError());
- $actm=new Actm();
- $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
- if($info->isEmpty())$this->error("活动不存在");
- if($info->status==1)$this->error("活动已发布,不能编辑");
- $data=[
- "act_name"=>$param['act_name'],
- "company_name"=>$param['company_name'],
- "contactor"=>$param['contactor'],
- "mobile"=>$param['mobile'],
- "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'],
- "endTime"=>$param['end']==''?null : $param['end'],
- "web_url"=>$param['web_url']??"",
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $add =$info->save($data);
- if($add==false)$this->error('活动修改失败');
- $this->success('活动修改成功');
- }
- /**
- * 显示指定的资源
- *
- * @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)$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);
- }
- /**
- * 删除指定资源
- *
- * @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)$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("删除成功");
- }
- }
|