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("删除成功"); } }