|
@@ -5,7 +5,9 @@ namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
use think\App;
|
|
|
+use think\Exception;
|
|
|
use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
|
|
|
|
|
|
class Exclusive extends Base
|
|
@@ -89,7 +91,9 @@ class Exclusive extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function status(){
|
|
|
+
|
|
|
+ public function status()
|
|
|
+ {
|
|
|
|
|
|
|
|
|
|
|
@@ -107,51 +111,138 @@ class Exclusive extends Base
|
|
|
|
|
|
|
|
|
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
|
|
|
- if($id===""){
|
|
|
- return error_show(1002,"参数id不能为空");
|
|
|
- }
|
|
|
- $stn = Db::name('exclusive')->where(['id'=>$id])->find();
|
|
|
- if(empty($stn)){
|
|
|
- return error_show(1002,"未找到商品数据");
|
|
|
- }
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
|
|
|
- if($status===""){
|
|
|
- return error_show(1002,"参数status不能为空");
|
|
|
- }
|
|
|
- if ($stn['level']==2) {
|
|
|
- if($status==1){
|
|
|
- $can = mai($stn['id']);
|
|
|
- $cat=array_column($can,'id');
|
|
|
- }else{
|
|
|
- $cat =$stn['id'];
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if($stn['level']==1){
|
|
|
- if($status==1){
|
|
|
- return error_show(1002,"所在等级不能启用");
|
|
|
- }else{
|
|
|
- $db= Db::name('exclusive')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
|
|
|
- if($db==0){
|
|
|
- $cat = $stn['id'];
|
|
|
- }else{
|
|
|
- return error_show(1002,"子级分类未禁用");
|
|
|
+
|
|
|
+
|
|
|
+ $param = $this->request->only(['id', 'status']);
|
|
|
+
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'id' => 'require|number|gt:0',
|
|
|
+ 'status' => 'require|number|in:0,1',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!$val->check($param)) return error_show(1004, $val->getError());
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $res = Db::name('exclusive')
|
|
|
+ ->field('id,level,status,pid')
|
|
|
+ ->where('id', $param['id'])
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ if (empty($res)) throw new Exception('该专属类型不存在');
|
|
|
+
|
|
|
+
|
|
|
+ if ($param['status'] == 1) {
|
|
|
+
|
|
|
+ if ($res['level'] == 1) {
|
|
|
+
|
|
|
+
|
|
|
+ $total = Db::name('exclusive')
|
|
|
+ ->where(['pid' => $param['id'], 'is_del' => 0])
|
|
|
+ ->count('id');
|
|
|
+
|
|
|
+ if ($total) {
|
|
|
+
|
|
|
+ $child_id = Db::name('exclusive')
|
|
|
+ ->field('id')
|
|
|
+ ->where(['pid' => $param['id'], 'is_del' => 0, 'status' => 1])
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ if (empty($child_id)) throw new Exception('请先启用一个子级');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ Db::name('exclusive')
|
|
|
+ ->where(['id' => $res['pid'], 'is_del' => 0, 'status' => 0])
|
|
|
+ ->update(['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')]);
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ } elseif ($param['status'] == 0) {
|
|
|
+
|
|
|
+ if ($res['level'] == 1) {
|
|
|
+
|
|
|
+
|
|
|
+ $total = Db::name('exclusive')
|
|
|
+ ->where(['pid' => $param['id'], 'is_del' => 0])
|
|
|
+ ->count('id');
|
|
|
+
|
|
|
+ if ($total) {
|
|
|
+
|
|
|
+ $child_id = Db::name('exclusive')
|
|
|
+ ->field('id')
|
|
|
+ ->where(['pid' => $param['id'], 'is_del' => 0, 'status' => 1])
|
|
|
+ ->find();
|
|
|
+ if (!empty($child_id)) throw new Exception('请先禁用全部子级');
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ Db::name('exclusive')
|
|
|
+ ->where(['id' => $param['id'], 'is_del' => 0])
|
|
|
+ ->update(['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')]);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return error_show(0, "状态更新成功");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- $it=[];
|
|
|
- $it['status']=$status;
|
|
|
- $it['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $str = Db::name('exclusive')->where(['id'=>$cat,'is_del'=>0])->save($it);
|
|
|
- if($str){
|
|
|
-
|
|
|
-
|
|
|
- return error_show(0,"状态更新成功");
|
|
|
- }else{
|
|
|
- return error_show(1002,"状态更新失败");
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public function query(){
|