Act.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\controller;
  4. use think\facade\Validate;
  5. use app\txx\model\Act as Actm;
  6. use think\App;
  7. class Act extends Base
  8. {
  9. protected $uid=0;
  10. protected $uname='';
  11. protected $model;
  12. public function __construct(App $app) {
  13. parent::__construct($app);
  14. if($this->request->isCx==1){
  15. $this->uid=$this->request->uid;
  16. $this->uname=$this->request->uname;
  17. }
  18. $this->model=new Actm();
  19. }
  20. /**
  21. * 显示资源列表
  22. *
  23. * @return \think\Response
  24. */
  25. public function list()
  26. {
  27. $param = $this->request->only([
  28. "page"=>1,
  29. "size"=>15,
  30. "act_name"=>'',
  31. "actCode"=>'',
  32. "company_name"=>'',
  33. "contactor"=>'',
  34. "act_type"=>'',
  35. "start"=>'',
  36. "end"=>'',
  37. "status"=>'',
  38. 'act_status'=>'',
  39. ],"post",'trim');
  40. $condition=[["is_del","=",0]];
  41. if($param['act_name']!='') $condition[]=["act_name","like","%{$param['act_name']}%"];
  42. if($param['actCode']!='') $condition[]=["actCode","like","%{$param['actCode']}%"];
  43. if($param['company_name']!='') $condition[]=["company_name","like","%{$param['company_name']}%"];
  44. if($param['contactor']!='') $condition[]=["contactor","like","%{$param['contactor']}%"];
  45. if($param['act_type']!='') $condition[]=["act_type","=",$param["act_type"]];
  46. if($param['start']!='') $condition[]=["addtime",">=",$param["start"]." 00:00:00"];
  47. if($param['end']!='') $condition[]=["addtime","<=",$param["end"]." 23:59:59"];
  48. if($param['status']!='') $condition[]=["status","=",$param["status"]];
  49. if($param['act_status']!='') {
  50. if($param['act_status']==1){
  51. $condition[]=["startTime",">",date("Y-m-d H:i:s")];
  52. }elseif($param['act_status']==2){
  53. $condition[]=['startTime','<',date('Y-m-d H:i:s')];
  54. $condition[]=['endTime','>',date('Y-m-d H:i:s')];
  55. }elseif($param['act_status']==3){
  56. $condition[]=['endTime','<',date('Y-m-d H:i:s')];
  57. }
  58. }
  59. $list=$this->model->where($condition)
  60. ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']])
  61. ->each(function(&$item){
  62. $item['act_status']=time()< strtotime($item['startTime'])?1:(time()> strtotime($item['endTime'])?3:2);
  63. });
  64. $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  65. }
  66. /**
  67. * 显示创建资源表单页.
  68. *
  69. * @return \think\Response
  70. */
  71. public function create()
  72. {
  73. $param = $this->request->only([
  74. "act_name"=>"",
  75. "company_name"=>'',
  76. "contactor"=>'',
  77. "mobile"=>'',
  78. "web_url"=>'',
  79. "start"=>'',
  80. "end"=>'',
  81. "act_type"=>1,
  82. ],"post","trim");
  83. $validate = Validate::rule([
  84. 'act_name|活动名称' => 'require',
  85. 'company_name|活动公司名称' => 'require',
  86. 'contactor|联系人' => 'require|max:255',
  87. 'mobile|联系电话' => 'require',
  88. ]);
  89. if($validate->check($param)==false)return json_show(1004,$validate->getError());
  90. $actCode=makeNo("ACE");
  91. $data=[
  92. "actCode"=>$actCode,
  93. "act_name"=>$param['act_name'],
  94. "company_name"=>$param['company_name'],
  95. "contactor"=>$param['contactor'],
  96. "mobile"=>$param['mobile'],
  97. "act_type"=>$param['act_type'],
  98. "startTime"=>$param['start']==''?null : $param['start'],
  99. "endTime"=>$param['end']==''?null : $param['end'],
  100. "web_url"=>$param['web_url']??"",
  101. "status"=>0,
  102. "apply_id"=>$this->uid,
  103. "apply_name"=>$this->uname,
  104. "addtime"=>date("Y-m-d H:i:s"),
  105. "updatetime"=>date("Y-m-d H:i:s"),
  106. ];
  107. $add =$this->model->create($data);
  108. if($add->isEmpty())$this->error("活动添加失败");
  109. $this->success("添加成功",["actCode"=>$actCode]);
  110. }
  111. /**
  112. * 保存新建的资源
  113. *
  114. * @param \think\Request $request
  115. * @return \think\Response
  116. */
  117. public function save()
  118. {
  119. $param = $this->request->only([
  120. "act_name"=>"",
  121. "company_name"=>'',
  122. "contactor"=>'',
  123. "mobile"=>'',
  124. "web_url"=>'',
  125. "start"=>'',
  126. "end"=>'',
  127. "actCode"=>'',
  128. "act_type"=>1,
  129. ],"post","trim");
  130. $validate = Validate::rule([
  131. 'act_name|活动名称' => 'require',
  132. 'actCode|活动编号' => 'require',
  133. 'company_name|活动公司名称' => 'require',
  134. 'contactor|联系人' => 'require|max:255',
  135. 'mobile|联系电话' => 'require',
  136. ]);
  137. if($validate->check($param)==false)return json_show(1004,$validate->getError());
  138. $actm=new Actm();
  139. $info = $actm->where(["actCode"=>$param['actCode'],"is_del"=>0])->find();
  140. if($info==false) return json_show(1005,"活动不存在");
  141. $data=[
  142. "act_name"=>$param['act_name'],
  143. "company_name"=>$param['company_name'],
  144. "contactor"=>$param['contactor'],
  145. "mobile"=>$param['mobile'],
  146. "act_type"=>$param['act_type'],
  147. "startTime"=>$param['start']==''?null : $param['start'],
  148. "endTime"=>$param['end']==''?null : $param['end'],
  149. "web_url"=>$param['web_url']??"",
  150. "updatetime"=>date("Y-m-d H:i:s"),
  151. ];
  152. $add =$info->save($data);
  153. if($add==false)$this->error('活动修改失败');
  154. $this->success('活动修改成功');
  155. }
  156. /**
  157. * 显示指定的资源
  158. *
  159. * @param int $id
  160. * @return \think\Response
  161. */
  162. public function info()
  163. {
  164. $param = $this->request->only(["actCode"=>''],"post","trim");
  165. $validate = Validate::rule([
  166. 'actCode|活动编号' => 'require',]);
  167. if($validate->check($param)==false)$this->error($validate->getError());
  168. $info = $this->model->with(["goodInfo"])->where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
  169. $this->success("获取成功",$info);
  170. }
  171. /**
  172. * 删除指定资源
  173. *
  174. * @param int $id
  175. * @return \think\Response
  176. */
  177. public function delete()
  178. {
  179. $param = $this->request->only(["actCode"=>''],"post","trim");
  180. $validate = Validate::rule([
  181. 'actCode|活动编号' => 'require',]);
  182. if($validate->check($param)==false)$this->error($validate->getError());
  183. ;
  184. $info = $this->model->where(["actCode"=>$param['actCode'],"is_del"=>0])->findOrEmpty();
  185. if($info==false) $this->error("活动不存在");
  186. $info->is_del=1;
  187. $info->save();
  188. $info->goodInfo()->update(["is_del"=>1]);
  189. $this->success("删除成功");
  190. }
  191. }