Exclusive.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. //泰康专属的一个列表
  6. class Exclusive extends Base
  7. {
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. }
  12. public function list(){
  13. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  14. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  15. $where =[["is_del","=",0]];
  16. $cat_name=isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']) :"";
  17. if($cat_name!==""){
  18. $where[]=['name',"like","%$cat_name%"];
  19. }
  20. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  21. if($pid!==""){
  22. $where[]=['pid',"=",$pid];
  23. }
  24. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  25. if($status!==""){
  26. $where[]=['status',"=",$status];
  27. }
  28. $count = Db::name("exclusive")->where($where)->count();
  29. $total = ceil($count / $size);
  30. $page = $page >= $total ? $total : $page;
  31. $list = Db::name('exclusive')->where($where)->page($page, $size)->select();
  32. return app_show(0, "获取成功", ['list' =>$list, 'count' => $count]);
  33. }
  34. public function add(){
  35. $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  36. if($name==""){
  37. return error_show(1004,"参数name不能为空");
  38. }
  39. $rename = Db::name('exclusive')->where(['is_del' => 0, 'name' => $name])->find();
  40. if (!empty($rename)) {
  41. return error_show(1002, "专属类型名称已存在");
  42. }
  43. $pid =isset($this->post['pid'])&&$this->post['pid']!=="" ? intval($this->post['pid']):0;
  44. if($pid==""){
  45. return error_show(1002,"父级id不能为空");
  46. }
  47. $level=1;
  48. $search = $name;
  49. if($pid!==0){
  50. $parent= Db::name("exclusive")->where(["id"=>$pid,"is_del"=>0])->find();
  51. if($parent==false){
  52. return error_show(1003,"父级数据未找到");
  53. }
  54. $search=$parent['search']."/".$name;
  55. $level=$parent['level']+1;
  56. }
  57. $token = isset($this->post['token'])&&$this->post['token']!="" ? trim($this->post['token']):"";
  58. $user =GetUserInfo($token);
  59. if(empty($user)||$user['code']!=0){
  60. return error_show($user['code'],$user['msg']);
  61. }
  62. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  63. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  64. $data=[
  65. "name"=>$name,
  66. "pid"=>$pid,
  67. "level"=>$level,
  68. "search"=>$search,
  69. "createrid"=>$createrid,
  70. "creater"=>$creater,
  71. "status"=>0,
  72. "is_del"=>0,
  73. "addtime"=>date("Y-m-d H:i:s"),
  74. "updatetime"=>date("Y-m-d H:i:s")
  75. ];
  76. $in =Db::name("exclusive")->insert($data);
  77. if($in){
  78. return app_show(0,"新建成功");
  79. }else{
  80. return error_show(1003,"新建失败");
  81. }
  82. }
  83. public function status(){
  84. // $id=isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']):"";
  85. // if($id===""){
  86. // return error_show(1004,"参数id不能为空");
  87. // }
  88. // $exclusive=Db::name("exclusive")->where(["id"=>$id,"is_del"=>0])->find();
  89. // if($exclusive==false){
  90. // return error_show(1004,"未找到数据");
  91. // }
  92. // $msg = $exclusive['status']==0? "启用":"禁用";
  93. // $exclusive['status'] = $exclusive['status']==0?1:0;
  94. // $exclusive['updatetime'] =date("Y-m-d H:i:s");
  95. // $in =Db::name("exclusive")->save($exclusive);
  96. // if($in){
  97. // return app_show(0,"{$msg}成功");
  98. // }else{
  99. // return error_show(1004,"{$msg}失败");
  100. // }
  101. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  102. if($id===""){
  103. return error_show(1002,"参数id不能为空");
  104. }
  105. $stn = Db::name('exclusive')->where(['id'=>$id])->find();
  106. if(empty($stn)){
  107. return error_show(1002,"未找到商品数据");
  108. }
  109. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  110. if($status===""){
  111. return error_show(1002,"参数status不能为空");
  112. }
  113. if ($stn['level']==2) {
  114. if($status==1){
  115. $can = mai($stn['id']);
  116. $cat=array_column($can,'id');
  117. }else{
  118. $cat =$stn['id'];
  119. }
  120. // return error_show(1002, "所在级别不能启用");
  121. }
  122. if($stn['level']==1){
  123. if($status==1){
  124. return error_show(1002,"所在等级不能启用");
  125. }else{
  126. $db= Db::name('exclusive')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
  127. if($db==0){
  128. $cat = $stn['id'];
  129. }else{
  130. return error_show(1002,"子级分类未禁用");
  131. }
  132. }
  133. }
  134. // $pd= $stn['status'];
  135. $it=[];
  136. $it['status']=$status;
  137. $it['updatetime']=date("Y-m-d H:i:s");
  138. $str = Db::name('exclusive')->where(['id'=>$cat,'is_del'=>0])->save($it);
  139. if($str){
  140. // $order = ["order_code"=>$id,"status"=>$pd,"action_remark"=>'',"action_type"=>"edit"];
  141. // ActionLog::logAdd($this->post['token'],$order,"sxd",$stn['status'],$order);
  142. return error_show(0,"状态更新成功");
  143. }else{
  144. return error_show(1002,"状态更新失败");
  145. }
  146. }
  147. public function query(){
  148. // $where =[["is_del","=",0]];
  149. // $cat_name=isset($this->post['name']) && $this->post['name'] !==""? trim($this->post['name']) :"";
  150. // if($cat_name!==""){
  151. // $where[]=['name',"like","%$cat_name%"];
  152. // }
  153. // $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  154. // if($pid!==""){
  155. // $where[]=['pid',"=",$pid];
  156. // }
  157. // $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  158. // if($status!==""){
  159. // $where[]=['status',"=",$status];
  160. // }
  161. // $level=isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']) :"";
  162. // if($level!==""){
  163. // $where[]=['level',"=",$level];
  164. // }
  165. // $list = Db::name("exclusive")->where($where)->select();
  166. // return app_show(0,"获取成功",$list);
  167. $where=[["is_del","=",0]];
  168. $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
  169. $where[]=["pid","=",$pid];
  170. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
  171. if($cat_name!==""){
  172. $where[]=['cat_name',"like","%$cat_name%"];
  173. }
  174. $data = Db::name("exclusive")->where($where)->select();
  175. $vmp = [];
  176. foreach ($data as $sts){
  177. $vmp[]=coco($sts);
  178. }
  179. return app_show(0,"获取成功",$vmp);
  180. }
  181. public function edit(){
  182. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  183. if($id==""){
  184. return error_show(1004,"参数id不能为空");
  185. }
  186. $info = Db::name('exclusive')->where(['id'=>$id,'is_del'=>0])->find();
  187. if($info==""){
  188. return error_show(1002,"未找到数据");
  189. }
  190. if($info['status']===1){
  191. return error_show(1004,"启用状态不可编辑");
  192. }
  193. $name = isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
  194. if($name==""){
  195. return error_show(1004,"参数name不能为空");
  196. }
  197. $pid =isset($this->post['pid'])&&$this->post['pid']!=="" ? intval($this->post['pid']):0;
  198. if($pid==""){
  199. return error_show(1004,"参数pid不能为空");
  200. }
  201. $level=1;
  202. $search = $name;
  203. if($pid!==0){
  204. $parent= Db::name("exclusive")->where(["id"=>$pid,"is_del"=>0])->find();
  205. if($parent==false){
  206. return error_show(1003,"父级数据未找到");
  207. }
  208. $search=$parent['search']."/".$name;
  209. $level=$parent['level']+1;
  210. }
  211. $data=[
  212. "id"=>$id,
  213. "name"=>$name,
  214. "pid"=>$pid,
  215. "level"=>$level,
  216. "search"=>$search,
  217. "status"=>0,
  218. "is_del"=>0,
  219. "updatetime"=>date("Y-m-d H:i:s")
  220. ];
  221. $in =Db::name("exclusive")->save($data);
  222. if($in){
  223. return app_show(0,"编辑成功");
  224. }else{
  225. return error_show(1003,"编辑失败");
  226. }
  227. }
  228. public function delete(){
  229. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  230. $info = Db::name('exclusive')->where(["is_del"=>0,'id'=>$id])->find();
  231. if($info==false){
  232. return error_show(1002,"未找到数据");
  233. }
  234. $supp= Db::name('exclusive')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  235. if($supp){
  236. return error_show(0,"删除成功");
  237. }else{
  238. return error_show(1002,"删除失败");
  239. }
  240. }
  241. }