Cat.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ChangeLog;
  5. use app\BaseController;
  6. use think\App;
  7. use think\facade\Db;
  8. //分类
  9. class Cat extends BaseController
  10. {
  11. public $post="";
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->post=$this->request->post();
  16. }
  17. public function list(){
  18. $where=[["is_del","=",0]];
  19. $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
  20. $where[]=["pid","=",$pid];
  21. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
  22. if($cat_name!==""){
  23. $where[]=['cat_name',"like","%$cat_name%"];
  24. }
  25. $data = Db::name("cat")->where($where)->select();
  26. $vmp = [];
  27. foreach ($data as $sts){
  28. $vmp[]=stro($sts);
  29. }
  30. return app_show(0,"获取成功",$vmp);
  31. }
  32. public function plist(){
  33. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  34. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  35. $where =[["is_del","=",0]];
  36. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  37. if($cat_name!==""){
  38. $where[]=['cat_name',"like","%$cat_name%"];
  39. }
  40. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  41. if($pid!==""){
  42. $where[]=['pid',"=",$pid];
  43. }
  44. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  45. if($status!==""){
  46. $where[]=['status',"=",$status];
  47. }
  48. $count = Db::name("cat")->where($where)->count();
  49. $total = ceil($count / $size);
  50. $page = $page >= $total ? $total : $page;
  51. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  52. $var =[];
  53. foreach ($list as $value){
  54. $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
  55. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
  56. if(empty($temp)){
  57. $temp=[];
  58. }
  59. $value['im']=$temp;
  60. $var[]=$value;
  61. }
  62. return app_show(0, "获取成功", ['list' =>$var, 'count' => $count]);
  63. }
  64. public function wlist(){
  65. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  66. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  67. $where =[["is_del","=",0],['level',"=",3]];
  68. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  69. if($cat_name!==""){
  70. $where[]=['cat_name',"like","%$cat_name%"];
  71. }
  72. $search=isset($this->post['search']) && $this->post['search'] !==""? trim($this->post['search']) :"";
  73. if($search!==""){
  74. $where[]=['search',"like","%$search%"];
  75. }
  76. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  77. if($pid!==""){
  78. $where[]=['pid',"=",$pid];
  79. }
  80. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  81. if($status!==""){
  82. $where[]=['status',"=",$status];
  83. }
  84. $count = Db::name("cat")->where($where)->count();
  85. $total = ceil($count / $size);
  86. $page = $page >= $total ? $total : $page;
  87. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  88. $data=[];
  89. foreach ($list as $value){
  90. $temp= isset($value['id']) && $value['id'] !=0 ? made($value['id']):[];
  91. $value['item'] = array_column($temp,'id');
  92. $data[]=$value;
  93. }
  94. return app_show(0, "获取成功", ['list' =>$data, 'count' => $count]);
  95. }
  96. public function title(){
  97. $where =[["is_del","=",0]];
  98. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  99. if($cat_name!==""){
  100. $where[]=['cat_name',"like","%$cat_name%"];
  101. }
  102. $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
  103. if($pid!==""){
  104. $where[]=["pid","=",$pid];
  105. }
  106. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  107. if($status!==""){
  108. $where[]=['status',"=",$status];
  109. }
  110. $list = Db::name('cat')->where($where)->select();
  111. return app_show(0, "获取成功",$list);
  112. }
  113. public function tlist(){
  114. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  115. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  116. $where =[['is_del',"=",0]];
  117. $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
  118. if($cat_name!==""){
  119. $where[]=['cat_name',"like","%$cat_name%"];
  120. }
  121. $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
  122. if($status!==""){
  123. $where[]=['status',"=",$status];
  124. }
  125. $creater=isset($this->post['creater']) && $this->post['creater'] !==""? trim($this->post['creater']) :"";
  126. if($creater!==""){
  127. $where[]=['creater',"like","%$creater%"];
  128. }
  129. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  130. if($start!==""){
  131. $where[]=['addtime',">=",$start];
  132. }
  133. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  134. if($end !==""){
  135. $where[]=['addtime',"<=",$end];
  136. }
  137. $count = Db::name('cat')->where($where)->count();
  138. $total = ceil($count / $size);
  139. $page = $page >= $total ? $total : $page;
  140. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  141. $var =[];
  142. foreach ($list as $value){
  143. $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
  144. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
  145. if(empty($temp)){
  146. $temp=[];
  147. }
  148. $value['im']=$temp;
  149. $var[]=$value;
  150. }
  151. return app_show(0, "获取成功", ['list' => $var, 'count' => $count]);
  152. }
  153. public function create()
  154. {
  155. $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
  156. if ($cat_name == "") {
  157. return error_show(1002, "参数cat_name不能为空");
  158. }
  159. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "0";
  160. if ($pid === "") {
  161. return error_show(1002, "参数pid不能为空");
  162. }
  163. $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== "" ? trim($this->post['cat_desc']) : "";
  164. $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
  165. $level =1;
  166. if ($pid !== 0) {
  167. $levl=Db::name('cat')->where(['id'=>$pid])->find();
  168. if(empty($levl)){
  169. return error_show(1002,"未找到父级数据");
  170. }
  171. $level =$levl['level']+1;
  172. $temp = $levl['search'];
  173. }
  174. if($level==1){
  175. $search = $cat_name;
  176. }else{
  177. $search= $temp."-".$cat_name;
  178. }
  179. $repeat_name = Db::name("cat")->where(["is_del"=>0,"cat_name"=>$cat_name])->find();
  180. $int =isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
  181. $im = array_column($int,'name');
  182. $in=implode('/',$im);
  183. if(!empty($repeat_name)){
  184. return error_show(1004,"分类名称已在{$in}存在");
  185. }
  186. $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
  187. if (empty($specs_id)) {
  188. return error_show(1002, "参数specs_id不能为空");
  189. }
  190. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  191. if($token==''){
  192. return error_show(105,"参数token不能为空");
  193. }
  194. $user =GetUserInfo($token);
  195. if(empty($user)||$user['code']!=0){
  196. return error_show(102,"创建人数据不存在");
  197. }
  198. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  199. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  200. // $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? intval($this->post['rate']) : "";
  201. // $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? intval($this->post['order_rate']) : "";
  202. // $sale_rate = isset($this->post['sale_rate ']) && $this->post['sale_rate '] !== "" ? intval($this->post['sale_rate ']) : "";
  203. // $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? intval($this->post['lower_rate']) : "";
  204. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? intval($this->post['weight']) : "0";
  205. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  206. Db::startTrans();
  207. try{
  208. $data = [
  209. "cat_name" => $cat_name,
  210. "pid" => $pid,
  211. "level" => $level,
  212. "search" => $search,
  213. // "rate" => $rate,
  214. // "lower_rate"=>$lower_rate,
  215. // "order_rate"=>$order_rate,
  216. // "sale_rate"=>$sale_rate,
  217. "weight" => $weight,
  218. "status" => $status,
  219. "cat_desc"=>$cat_desc,
  220. "fund_code"=>$fund_code,
  221. "creater"=>$creater,
  222. "createrid"=>$createrid,
  223. "is_del"=>0,
  224. "addtime" => date("Y-m-d H:i:s"),
  225. "updatetime" => date("Y-m-d H:i:s"),
  226. ];
  227. $datainfo = Db::name('cat')->insert($data,true);
  228. $vat =[];
  229. if ($datainfo>0) {
  230. $stx = ["order_code"=>$pid,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  231. ActionLog::logAdd($this->post['token'],$stx,"sxd",$status,$stx);
  232. $spc =[];
  233. $spc['cat_id']=$datainfo;
  234. $spc['exam_status']=0;
  235. $spc['status']=0;
  236. $spc['creater']=$creater;
  237. $spc['createrid']=$createrid;
  238. $spc['is_del']=0;
  239. $spc['addtime']=date("Y-m-d H:i:d");
  240. $spc['updatetime']=date("Y-m_d H:i:s");
  241. $vpn = Db::name('cat_spec')->insert($spc,true);
  242. if ($vpn == "") {
  243. Db::rollback();
  244. return error_show(1002, "新建失败");
  245. }
  246. foreach ($specs_id as $value){
  247. $item =[];
  248. $item['cat_id']=$datainfo;
  249. $item['specs_id']=$value;
  250. $item['is_del']=0;
  251. $item['addtime']=date("Y-m-d H:i:s");
  252. $vat[] = $item;
  253. }
  254. $vp = Db::name('cat_specs')->insertAll($vat);
  255. if ($vp==0) {
  256. Db::rollback();
  257. return error_show(1005, "新建失败");
  258. }
  259. Db::commit();
  260. return error_show(0, "新建成功");
  261. } else {
  262. Db::rollback();
  263. return error_show(1002, "新建失败");
  264. }
  265. }catch (\Exception $e){
  266. Db::rollback();
  267. return error_show(1005,$e->getMessage());
  268. }
  269. }
  270. public function edit(){
  271. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  272. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  273. if($idinfo==""){
  274. return error_show(1002,"未找到商品数据");
  275. }
  276. $cat_name= isset($this->post['cat_name']) && $this->post['cat_name'] !=="" ? trim($this->post['cat_name']) :"";
  277. if($cat_name==""){
  278. return error_show(1002,"参数cat_name不能为空");
  279. }
  280. $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']) :"";
  281. if($pid===""){
  282. return error_show(1002,"参数pid不能为空");
  283. }
  284. $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !=="" ? trim($this->post['cat_desc']) :"";
  285. $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
  286. $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
  287. if (empty($specs_id)) {
  288. return error_show(1002, "参数specs_id不能为空");
  289. }
  290. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  291. if($token==''){
  292. return error_show(105,"参数token不能为空");
  293. }
  294. $user =GetUserInfo($token);
  295. if(empty($user)||$user['code']!=0){
  296. return error_show(102,"创建人数据不存在");
  297. }
  298. $level =1;
  299. if ($pid !== 0) {
  300. $levl=Db::name('cat')->where(['id'=>$pid])->find();
  301. if(empty($levl)){
  302. return error_show(1002,"未找到父级数据");
  303. }
  304. $level =$levl['level']+1;
  305. $temp = $levl['search'];
  306. }
  307. if($level==1){
  308. $search = $cat_name;
  309. }else{
  310. $search= $temp."_".$cat_name;
  311. }
  312. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  313. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  314. //$level = isset($this->post['level']) && $this->post['level'] !=="" ? intval($this->post['level']) :"";
  315. $weight = isset($this->post['weight']) && $this->post['weight']!==""? intval($this->post['weight']):"0";
  316. $status = isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']) :"0";
  317. Db::startTrans();
  318. try{
  319. $str = [
  320. "id"=>$id,
  321. "cat_name"=>$cat_name,
  322. "pid"=>$pid,
  323. "level"=>$level,
  324. "weight"=>$weight,
  325. // "status"=>$status,
  326. "cat_desc"=>$cat_desc,
  327. "is_del"=>0,
  328. "fund_code"=>$fund_code,
  329. "updatetime"=>date("Y-m-d H:i:s"),
  330. "search"=>$search
  331. ];
  332. $strinfo = Db::name('cat')->where(['id'=>$id])->save($str);
  333. $temp = array_diff($str,$idinfo);
  334. $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  335. $jsp = json_encode($idinfo,JSON_UNESCAPED_UNICODE);
  336. if($strinfo){
  337. $order = ["order_code"=>$id,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
  338. ActionLog::logAdd($this->post['token'],$order,"sxd",$status,$order);
  339. ChangeLog::logAdd(7,$idinfo['id'],$jsp,$json,$this->post['token'],$this->post);
  340. $spc =[];
  341. $vp = Db::name('cat_spec')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->find();
  342. $str ="";
  343. if($vp!=false){
  344. isset($vp['id']) && $vp['id'] !== "" ? $spc['id'] = $vp['id'] : '';
  345. $spc['cat_id']=$idinfo['id'];
  346. $spc['exam_status']=0;
  347. $spc['status']=0;
  348. $spc['is_del']=0;
  349. $spc['updatetime']=date("Y-m_d H:i:s");
  350. $str=$vp['id'];
  351. $vpn = Db::name('cat_spec')->save($spc);
  352. }else{
  353. $spc['cat_id']=$idinfo['id'];
  354. $spc['exam_status']=0;
  355. $spc['status']=0;
  356. $spc['creater']=$creater;
  357. $spc['createrid']=$createrid;
  358. $spc['is_del']=0;
  359. $spc['addtime']=date("Y-m-d H:i:d");
  360. $spc['updatetime']=date("Y-m_d H:i:s");
  361. $vpn = Db::name('cat_spec')->insert($spc,true);
  362. $str=$vpn;
  363. }
  364. if ($vpn == false) {
  365. Db::rollback();
  366. return error_show(1002, "更新失败");
  367. }
  368. $db = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column("specs_id");
  369. if(empty($db)){
  370. $db=[];
  371. }
  372. $sn = array_diff($specs_id,$db);
  373. $st = array_diff($db,$specs_id);
  374. if(!empty($st)){
  375. $int['is_del']=1;
  376. $dn = Db::name('cat_specs')->where(['specs_id'=>$st,'is_del'=>0])->save($int);
  377. if ($dn==false) {
  378. Db::rollback();
  379. return error_show(1002, "编辑失败");
  380. }
  381. }
  382. if(!empty($sn)){
  383. $vat=[];
  384. foreach ($sn as $value){
  385. $item=[];
  386. $item['cat_id']=$idinfo['id'];
  387. $item['specs_id']=$value;
  388. $item['is_del']=0;
  389. $item['addtime'] = date("Y-m-d H:i:s");
  390. $vat[] = $item;
  391. }
  392. $vp = Db::name('cat_specs')->insertAll($vat);
  393. if ($vp==0) {
  394. Db::rollback();
  395. return error_show(1002, "编辑失败");
  396. }
  397. }
  398. $itn =sear($id);
  399. Db::commit();
  400. return error_show(0,"编辑成功");
  401. }else{
  402. Db::rollback();
  403. return error_show(1002,"编辑失败");
  404. }
  405. }catch (\Exception $e){
  406. Db::rollback();
  407. return error_show(1005,$e->getMessage());
  408. }
  409. }
  410. public function ratedit(){
  411. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  412. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  413. if($idinfo==""){
  414. return error_show(1002,"未找到商品数据");
  415. }
  416. $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? floatval($this->post['rate']) : "";
  417. $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? floatval($this->post['order_rate']) : "";
  418. $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== "" ? floatval($this->post['sale_rate']) : "";
  419. $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? floatval($this->post['lower_rate']) :"";
  420. $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !=="" ? floatval($this->post['money_rate']):"";
  421. $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !=="" ? floatval($this->post['low_rate']):"";
  422. if($idinfo['pid']==0){
  423. if($rate===""){
  424. return error_show(1003,"参数rate不能为空");
  425. }
  426. if($order_rate===""){
  427. return error_show(1003,"参数order_rate不能为空");
  428. }
  429. if($sale_rate===""){
  430. return error_show(1003,"参数sale_rate不能为空");
  431. }
  432. if($lower_rate===""){
  433. return error_show(1003,"参数lower_rate不能为空");
  434. }
  435. if($money_rate==""){
  436. return error_show(1003,"参数money_rate不能为空");
  437. }
  438. if($low_rate==""){
  439. return error_show(1003,"参数low_rate不能为空");
  440. }
  441. }
  442. $data =[
  443. "id"=>$id,
  444. "rate" => $rate,
  445. "lower_rate"=>$lower_rate,
  446. "order_rate"=>$order_rate,
  447. "sale_rate"=>$sale_rate,
  448. "money_rate"=>$money_rate,
  449. "low_rate"=>$low_rate,
  450. "is_del"=>0,
  451. "updatetime"=>date("Y-m-d H:i:s"),
  452. ];
  453. $strinfo = Db::name('cat')->where(['id'=>$id])->save($data);
  454. if($strinfo){
  455. return error_show(0,"更新成功");
  456. }else{
  457. return error_show(1002,"更新失败");
  458. }
  459. }
  460. public function info(){
  461. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  462. if($id==""){
  463. return error_show(1002,"参数id不能为空");
  464. }
  465. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  466. if($idinfo==""){
  467. return error_show(1002,"未找到数据");
  468. }
  469. $info = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column('specs_id');
  470. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id,spec_name")->select();
  471. //$idinfo['cat_id']=$info['cat_id'];
  472. $idinfo['spec']=$temp;
  473. // $idinfo['specs_id']=$info;
  474. return app_show(0,"获取成功",$idinfo);
  475. }
  476. public function status(){
  477. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  478. if($id===""){
  479. return error_show(1002,"参数id不能为空");
  480. }
  481. $stn = Db::name('cat')->where(['id'=>$id])->find();
  482. if(empty($stn)){
  483. return error_show(1002,"未找到商品数据");
  484. }
  485. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  486. if($status===""){
  487. return error_show(1002,"参数status不能为空");
  488. }
  489. if ($stn['level']==3) {
  490. if($status==1){
  491. $can = made($stn['id']);
  492. $cat=array_column($can,'id');
  493. }else{
  494. $cat =$stn['id'];
  495. }
  496. // return error_show(1002, "所在级别不能启用");
  497. }
  498. if($stn['level']==2 || $stn['level']==1){
  499. if($status==1){
  500. return error_show(1002,"所在等级不能启用");
  501. }else{
  502. $db= Db::name('cat')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
  503. if($db==0){
  504. $cat = $stn['id'];
  505. }else{
  506. return error_show(1002,"子级分类未禁用");
  507. }
  508. }
  509. }
  510. // $pd= $stn['status'];
  511. $it=[];
  512. $it['status']=$status;
  513. $it['updatetime']=date("Y-m-d H:i:s");
  514. $str = Db::name('cat')->where(['id'=>$cat,'is_del'=>0])->save($it);
  515. if($str){
  516. // $order = ["order_code"=>$id,"status"=>$pd,"action_remark"=>'',"action_type"=>"edit"];
  517. // ActionLog::logAdd($this->post['token'],$order,"sxd",$stn['status'],$order);
  518. return error_show(0,"状态更新成功");
  519. }else{
  520. return error_show(1002,"状态更新失败");
  521. }
  522. }
  523. public function delete(){
  524. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  525. $info = Db::name('cat')->where(["is_del"=>0,'id'=>$id])->find();
  526. if($info==false){
  527. return error_show(1002,"未找到数据");
  528. }
  529. $supp= Db::name('cat')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  530. if($supp){
  531. return error_show(0,"删除成功");
  532. }else{
  533. return error_show(1002,"删除失败");
  534. }
  535. }
  536. }