Act.php 6.3 KB

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