Cat.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
  284. $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
  285. if (empty($specs_id)) {
  286. return error_show(1002, "参数specs_id不能为空");
  287. }
  288. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  289. if($token==''){
  290. return error_show(105,"参数token不能为空");
  291. }
  292. $user =GetUserInfo($token);
  293. if(empty($user)||$user['code']!=0){
  294. return error_show(102,"创建人数据不存在");
  295. }
  296. $level =1;
  297. if ($pid !== 0) {
  298. $levl=Db::name('cat')->where(['id'=>$pid])->find();
  299. if(empty($levl)){
  300. return error_show(1002,"未找到父级数据");
  301. }
  302. $level =$levl['level']+1;
  303. $temp = $levl['search'];
  304. }
  305. if($level==1){
  306. $search = $cat_name;
  307. }else{
  308. $search= $temp."_".$cat_name;
  309. }
  310. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  311. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  312. //$level = isset($this->post['level']) && $this->post['level'] !=="" ? intval($this->post['level']) :"";
  313. $weight = isset($this->post['weight']) && $this->post['weight']!==""? intval($this->post['weight']):"0";
  314. $status = isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']) :"0";
  315. Db::startTrans();
  316. try{
  317. $str = [
  318. "id"=>$id,
  319. "cat_name"=>$cat_name,
  320. "pid"=>$pid,
  321. "level"=>$level,
  322. "weight"=>$weight,
  323. // "status"=>$status,
  324. "cat_desc"=>$cat_desc,
  325. "is_del"=>0,
  326. "fund_code"=>$fund_code,
  327. "updatetime"=>date("Y-m-d H:i:s"),
  328. "search"=>$search
  329. ];
  330. $strinfo = Db::name('cat')->where(['id'=>$id])->save($str);
  331. if($strinfo){
  332. $order = ["order_code"=>$id,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
  333. ActionLog::logAdd($this->post['token'],$order,"sxd",$status,$order);
  334. $spc =[];
  335. $vp = Db::name('cat_spec')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->find();
  336. $str ="";
  337. if($vp!=false){
  338. isset($vp['id']) && $vp['id'] !== "" ? $spc['id'] = $vp['id'] : '';
  339. $spc['cat_id']=$idinfo['id'];
  340. $spc['exam_status']=0;
  341. $spc['status']=0;
  342. $spc['is_del']=0;
  343. $spc['updatetime']=date("Y-m_d H:i:s");
  344. $str=$vp['id'];
  345. $vpn = Db::name('cat_spec')->save($spc);
  346. }else{
  347. $spc['cat_id']=$idinfo['id'];
  348. $spc['exam_status']=0;
  349. $spc['status']=0;
  350. $spc['creater']=$creater;
  351. $spc['createrid']=$createrid;
  352. $spc['is_del']=0;
  353. $spc['addtime']=date("Y-m-d H:i:d");
  354. $spc['updatetime']=date("Y-m_d H:i:s");
  355. $vpn = Db::name('cat_spec')->insert($spc,true);
  356. $str=$vpn;
  357. }
  358. if ($vpn == false) {
  359. Db::rollback();
  360. return error_show(1002, "更新失败");
  361. }
  362. $db = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column("specs_id");
  363. if(empty($db)){
  364. $db=[];
  365. }
  366. $sn = array_diff($specs_id,$db);
  367. $st = array_diff($db,$specs_id);
  368. if(!empty($st)){
  369. $int['is_del']=1;
  370. $dn = Db::name('cat_specs')->where(['specs_id'=>$st,'is_del'=>0])->save($int);
  371. if ($dn==false) {
  372. Db::rollback();
  373. return error_show(1002, "编辑失败");
  374. }
  375. }
  376. if(!empty($sn)){
  377. $vat=[];
  378. foreach ($sn as $value){
  379. $item=[];
  380. $item['cat_id']=$idinfo['id'];
  381. $item['specs_id']=$value;
  382. $item['is_del']=0;
  383. $item['addtime'] = date("Y-m-d H:i:s");
  384. $vat[] = $item;
  385. }
  386. $vp = Db::name('cat_specs')->insertAll($vat);
  387. if ($vp==0) {
  388. Db::rollback();
  389. return error_show(1002, "编辑失败");
  390. }
  391. }
  392. $itn =sear($id);
  393. Db::commit();
  394. return error_show(0,"编辑成功");
  395. }else{
  396. Db::rollback();
  397. return error_show(1002,"编辑失败");
  398. }
  399. }catch (\Exception $e){
  400. Db::rollback();
  401. return error_show(1005,$e->getMessage());
  402. }
  403. }
  404. public function ratedit(){
  405. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  406. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  407. if($idinfo==""){
  408. return error_show(1002,"未找到商品数据");
  409. }
  410. $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? floatval($this->post['rate']) : "";
  411. $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? floatval($this->post['order_rate']) : "";
  412. $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== "" ? floatval($this->post['sale_rate']) : "";
  413. $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? floatval($this->post['lower_rate']) :"";
  414. $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !=="" ? floatval($this->post['money_rate']):"";
  415. $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !=="" ? floatval($this->post['low_rate']):"";
  416. if($idinfo['pid']==0){
  417. if($rate===""){
  418. return error_show(1003,"参数rate不能为空");
  419. }
  420. if($order_rate===""){
  421. return error_show(1003,"参数order_rate不能为空");
  422. }
  423. if($sale_rate===""){
  424. return error_show(1003,"参数sale_rate不能为空");
  425. }
  426. if($lower_rate===""){
  427. return error_show(1003,"参数lower_rate不能为空");
  428. }
  429. if($money_rate==""){
  430. return error_show(1003,"参数money_rate不能为空");
  431. }
  432. if($low_rate==""){
  433. return error_show(1003,"参数low_rate不能为空");
  434. }
  435. }
  436. $data =[
  437. "id"=>$id,
  438. "rate" => $rate,
  439. "lower_rate"=>$lower_rate,
  440. "order_rate"=>$order_rate,
  441. "sale_rate"=>$sale_rate,
  442. "money_rate"=>$money_rate,
  443. "low_rate"=>$low_rate,
  444. "is_del"=>0,
  445. "updatetime"=>date("Y-m-d H:i:s"),
  446. ];
  447. $strinfo = Db::name('cat')->where(['id'=>$id])->save($data);
  448. if($strinfo){
  449. return error_show(0,"更新成功");
  450. }else{
  451. return error_show(1002,"更新失败");
  452. }
  453. }
  454. public function info(){
  455. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  456. if($id==""){
  457. return error_show(1002,"参数id不能为空");
  458. }
  459. $idinfo = Db::name('cat')->where(['id'=>$id])->find();
  460. if($idinfo==""){
  461. return error_show(1002,"未找到数据");
  462. }
  463. $info = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column('specs_id');
  464. $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id,spec_name")->select();
  465. //$idinfo['cat_id']=$info['cat_id'];
  466. $idinfo['spec']=$temp;
  467. // $idinfo['specs_id']=$info;
  468. return app_show(0,"获取成功",$idinfo);
  469. }
  470. public function status(){
  471. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  472. if($id===""){
  473. return error_show(1002,"参数id不能为空");
  474. }
  475. $stn = Db::name('cat')->where(['id'=>$id])->find();
  476. if(empty($stn)){
  477. return error_show(1002,"未找到商品数据");
  478. }
  479. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  480. if($status===""){
  481. return error_show(1002,"参数status不能为空");
  482. }
  483. if ($stn['level']==3) {
  484. if($status==1){
  485. $can = made($stn['id']);
  486. $cat=array_column($can,'id');
  487. }else{
  488. $cat =$stn['id'];
  489. }
  490. // return error_show(1002, "所在级别不能启用");
  491. }
  492. if($stn['level']==2 || $stn['level']==1){
  493. if($status==1){
  494. return error_show(1002,"所在等级不能启用");
  495. }else{
  496. $db= Db::name('cat')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
  497. if($db==0){
  498. $cat = $stn['id'];
  499. }else{
  500. return error_show(1002,"子级分类未禁用");
  501. }
  502. }
  503. }
  504. // $pd= $stn['status'];
  505. $it=[];
  506. $it['status']=$status;
  507. $it['updatetime']=date("Y-m-d H:i:s");
  508. $str = Db::name('cat')->where(['id'=>$cat,'is_del'=>0])->save($it);
  509. if($str){
  510. // $order = ["order_code"=>$id,"status"=>$pd,"action_remark"=>'',"action_type"=>"edit"];
  511. // ActionLog::logAdd($this->post['token'],$order,"sxd",$stn['status'],$order);
  512. return error_show(0,"状态更新成功");
  513. }else{
  514. return error_show(1002,"状态更新失败");
  515. }
  516. }
  517. public function delete(){
  518. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  519. $info = Db::name('cat')->where(["is_del"=>0,'id'=>$id])->find();
  520. if($info==false){
  521. return error_show(1002,"未找到数据");
  522. }
  523. $supp= Db::name('cat')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  524. if($supp){
  525. return error_show(0,"删除成功");
  526. }else{
  527. return error_show(1002,"删除失败");
  528. }
  529. }
  530. }