Cat.php 24 KB

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