Cat.php 22 KB

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