|
@@ -6,614 +6,653 @@ use app\admin\model\ActionLog;
|
|
|
use app\admin\model\ChangeLog;
|
|
|
use app\BaseController;
|
|
|
use think\App;
|
|
|
+use think\Exception;
|
|
|
use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
|
|
|
//分类
|
|
|
class Cat extends Base
|
|
|
{
|
|
|
|
|
|
-public function __construct(App $app)
|
|
|
-{
|
|
|
- parent::__construct($app);
|
|
|
-}
|
|
|
-public function list(){
|
|
|
- $where=[["is_del","=",0]];
|
|
|
- $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
|
|
|
- $where[]=["pid","=",$pid];
|
|
|
-
|
|
|
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
|
|
|
- if($cat_name!==""){
|
|
|
- $where[]=['cat_name',"like","%$cat_name%"];
|
|
|
- }
|
|
|
- $data = Db::name("cat")->where($where)->select();
|
|
|
- $vmp = [];
|
|
|
- foreach ($data as $sts){
|
|
|
- $vmp[]=stro($sts);
|
|
|
- }
|
|
|
- return app_show(0,"获取成功",$vmp);
|
|
|
-}
|
|
|
-public function plist(){
|
|
|
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
|
|
|
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
|
|
|
- $where =[["c.is_del","=",0]];
|
|
|
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
|
|
|
- if($cat_name!==""){
|
|
|
- $where[]=['c.cat_name',"like","%$cat_name%"];
|
|
|
- }
|
|
|
- $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
|
|
|
- if($pid!==""){
|
|
|
- $where[]=['c.pid',"=",$pid];
|
|
|
- }
|
|
|
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
|
|
|
- if($status!==""){
|
|
|
- $where[]=['c.status',"=",$status];
|
|
|
- }
|
|
|
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
|
|
|
- if ($company_name !== "") $where[] = ["c.createrid", 'in', get_company_item_user_by_name($company_name)];
|
|
|
-
|
|
|
- $count = Db::name("cat")->alias('c')->where($where)->count();
|
|
|
- $total = ceil($count / $size);
|
|
|
- $page = $page >= $total ? $total : $page;
|
|
|
- $list = Db::name('cat')
|
|
|
- ->alias('c')
|
|
|
- ->field('c.*,u.itemid')
|
|
|
- ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
|
|
|
- ->where($where)
|
|
|
- ->page($page, $size)
|
|
|
- ->cursor();
|
|
|
- $var =[];
|
|
|
- foreach ($list as $value){
|
|
|
- $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
|
|
|
- $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
|
|
|
- if(empty($temp)){
|
|
|
- $temp=[];
|
|
|
- }
|
|
|
- $value['im']=$temp;
|
|
|
- $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
|
|
|
- $var[]=$value;
|
|
|
- }
|
|
|
- return app_show(0, "获取成功", ['list' =>$var, 'count' => $count]);
|
|
|
-}
|
|
|
-
|
|
|
- public function wlist(){
|
|
|
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
|
|
|
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
|
|
|
- $where =[["is_del","=",0],['level',"=",3]];
|
|
|
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
|
|
|
- if($cat_name!==""){
|
|
|
- $where[]=['cat_name',"like","%$cat_name%"];
|
|
|
- }
|
|
|
- $search=isset($this->post['search']) && $this->post['search'] !==""? trim($this->post['search']) :"";
|
|
|
- if($search!==""){
|
|
|
- $where[]=['search',"like","%$search%"];
|
|
|
- }
|
|
|
- $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
|
|
|
- if($pid!==""){
|
|
|
- $where[]=['pid',"=",$pid];
|
|
|
- }
|
|
|
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
|
|
|
- if($status!==""){
|
|
|
- $where[]=['status',"=",$status];
|
|
|
- }
|
|
|
- $count = Db::name("cat")->where($where)->count();
|
|
|
- $total = ceil($count / $size);
|
|
|
- $page = $page >= $total ? $total : $page;
|
|
|
- $list = Db::name('cat')->where($where)->page($page, $size)->select();
|
|
|
- $data=[];
|
|
|
- foreach ($list as $value){
|
|
|
- $temp= isset($value['id']) && $value['id'] !=0 ? made($value['id']):[];
|
|
|
- $value['item'] = array_column($temp,'id');
|
|
|
- $data[]=$value;
|
|
|
- }
|
|
|
- return app_show(0, "获取成功", ['list' =>$data, 'count' => $count]);
|
|
|
- }
|
|
|
+ //树状列表
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['pid' => 0, 'cat_name' => '', 'supplierNo' => ''], 'post', 'trim');
|
|
|
|
|
|
-public function title(){
|
|
|
- $where =[["is_del","=",0]];
|
|
|
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
|
|
|
- if($cat_name!==""){
|
|
|
- $where[]=['cat_name',"like","%$cat_name%"];
|
|
|
- }
|
|
|
- $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
|
|
|
- if($pid!==""){
|
|
|
- $where[]=["pid","=",$pid];
|
|
|
- }
|
|
|
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
|
|
|
- if($status!==""){
|
|
|
- $where[]=['status',"=",$status];
|
|
|
- }
|
|
|
- $list = Db::name('cat')->where($where)->select();
|
|
|
- return app_show(0, "获取成功",$list);
|
|
|
-}
|
|
|
- public function tlist(){
|
|
|
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
|
|
|
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
|
|
|
- $where =[['c.is_del',"=",0]];
|
|
|
- $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
|
|
|
- if($cat_name!==""){
|
|
|
- $where[]=['c.cat_name',"like","%$cat_name%"];
|
|
|
- }
|
|
|
- $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
|
|
|
- if($status!==""){
|
|
|
- $where[]=['c.status',"=",$status];
|
|
|
- }
|
|
|
- $creater=isset($this->post['creater']) && $this->post['creater'] !==""? trim($this->post['creater']) :"";
|
|
|
- if($creater!==""){
|
|
|
- $where[]=['c.creater',"like","%$creater%"];
|
|
|
- }
|
|
|
+ $where = [['is_del', '=', 0], ['pid', '=', $param['pid']]];
|
|
|
|
|
|
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
|
|
|
- if($start!==""){
|
|
|
- $where[]=['c.addtime',">=",$start];
|
|
|
- }
|
|
|
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
|
|
|
- if($end !==""){
|
|
|
- $where[]=['c.addtime',"<=",$end];
|
|
|
+ if ($param['cat_name'] !== '') $where[] = ['cat_name', 'like', '%' . $param['cat_name'] . '%'];
|
|
|
+ if ($param['supplierNo'] !== '') $where[] = ['supplierNo', '=', $param['supplierNo']];
|
|
|
+
|
|
|
+ $data = Db::name('cat')->where($where)->cursor();
|
|
|
+ $vmp = [];
|
|
|
+ foreach ($data as $sts) {
|
|
|
+ $vmp[] = stro($sts);
|
|
|
}
|
|
|
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
|
|
|
- if ($company_name !== "") $where[] = ["c.createrid", 'in', get_company_item_user_by_name($company_name)];
|
|
|
+ return app_show(0, '获取成功', $vmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ //列表(含规格和创建人部门)
|
|
|
+ public function plist()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_name' => '', 'pid' => '', 'status' => '', 'company_name' => '', 'supplierNo' => ''], 'post', 'trim');
|
|
|
+ $where = [['c.is_del', '=', 0]];
|
|
|
+ if ($param['cat_name'] !== '') $where[] = ['c.cat_name', 'like', '%' . $param['cat_name'] . '%'];
|
|
|
+ if ($param['supplierNo'] !== '') $where[] = ['c.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
|
|
|
+ if ($param['pid'] !== '') $where[] = ['c.pid', '=', $param['pid']];
|
|
|
+ if ($param['status'] !== '') $where[] = ['c.status', '=', $param['status']];
|
|
|
+ if ($param['company_name'] !== '') $where[] = ['c.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
|
|
|
|
|
|
$count = Db::name('cat')->alias('c')->where($where)->count();
|
|
|
- $total = ceil($count / $size);
|
|
|
- $page = $page >= $total ? $total : $page;
|
|
|
+// $total = ceil($count / $size);
|
|
|
+// $page = $page >= $total ? $total : $page;
|
|
|
$list = Db::name('cat')
|
|
|
->alias('c')
|
|
|
->field('c.*,u.itemid')
|
|
|
- ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
|
|
|
+ ->leftJoin('depart_user u', 'u.uid=c.createrid AND u.is_del=0')
|
|
|
->where($where)
|
|
|
- ->page($page, $size)
|
|
|
+ ->page($param['page'], $param['size'])
|
|
|
->cursor();
|
|
|
- $var =[];
|
|
|
- foreach ($list as $value){
|
|
|
- $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
|
|
|
- $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
|
|
|
- if(empty($temp)){
|
|
|
- $temp=[];
|
|
|
+ $var = [];
|
|
|
+
|
|
|
+ foreach ($list as $value) {
|
|
|
+ $temp = Db::name('cat_specs')
|
|
|
+ ->field('a.specs_id,b.spec_name')
|
|
|
+ ->alias('a')
|
|
|
+ ->leftJoin('specs b', 'b.id=a.specs_id')
|
|
|
+ ->where(['a.cat_id' => $value['id'], 'a.is_del' => 0])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+// $temp = Db::name('specs')
|
|
|
+// ->where(['id' => $info, 'is_del' => 0])
|
|
|
+// ->field('id as specid,spec_name')
|
|
|
+// ->select()
|
|
|
+// ->toArray();
|
|
|
+ if (empty($temp)) {
|
|
|
+ $temp = [];
|
|
|
}
|
|
|
- $value['im']=$temp;
|
|
|
+ $value['im'] = $temp;
|
|
|
$value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
|
|
|
- $var[]=$value;
|
|
|
+ $var[] = $value;
|
|
|
}
|
|
|
- return app_show(0, "获取成功", ['list' => $var, 'count' => $count]);
|
|
|
+ return app_show(0, '获取成功', ['list' => $var, 'count' => $count]);
|
|
|
}
|
|
|
|
|
|
-public function create()
|
|
|
-{
|
|
|
- $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
|
|
|
- if ($cat_name == "") {
|
|
|
- return error_show(1002, "参数cat_name不能为空");
|
|
|
- }
|
|
|
- $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "0";
|
|
|
- if ($pid === "") {
|
|
|
- return error_show(1002, "参数pid不能为空");
|
|
|
- }
|
|
|
+ //查看所有三级分类
|
|
|
+ public function wlist()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_name' => '', 'search' => '', 'pid' => '', 'status' => '', 'supplierNo' => ''], 'post', 'trim');
|
|
|
|
|
|
- $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== "" ? trim($this->post['cat_desc']) : "";
|
|
|
- $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
|
|
|
+ $where = [['is_del', '=', 0], ['level', '=', 3]];
|
|
|
+ if ($param['cat_name'] !== '') $where[] = ['cat_name', 'like', '%' . $param['cat_name'] . '%'];
|
|
|
+ if ($param['search'] !== '') $where[] = ['search', 'like', '%' . $param['search'] . '%'];
|
|
|
+ if ($param['pid'] !== '') $where[] = ['pid', '=', $param['pid']];
|
|
|
+ if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
|
|
|
+ if ($param['supplierNo'] !== '') $where[] = ['supplierNo', '=', $param['supplierNo']];
|
|
|
|
|
|
- $level =1;
|
|
|
- if ($pid !== 0) {
|
|
|
- $levl=Db::name('cat')->where(['id'=>$pid])->find();
|
|
|
- if(empty($levl)){
|
|
|
- return error_show(1002,"未找到父级数据");
|
|
|
+ $count = Db::name('cat')
|
|
|
+ ->where($where)
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ $list = Db::name('cat')
|
|
|
+ ->where($where)
|
|
|
+ ->page($param['page'], $param['size'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $data = [];
|
|
|
+ foreach ($list as $value) {
|
|
|
+ $value['item'] = array_column(made($value['id'] ?? 0), 'id');
|
|
|
+ $data[] = $value;
|
|
|
}
|
|
|
- $level =$levl['level']+1;
|
|
|
- $temp = $levl['search'];
|
|
|
- }
|
|
|
- if($level==1){
|
|
|
- $search = $cat_name;
|
|
|
- }else{
|
|
|
- $search= $temp."-".$cat_name;
|
|
|
+ return app_show(0, '获取成功', ['list' => $data, 'count' => $count]);
|
|
|
}
|
|
|
- $repeat_name = Db::name("cat")->where(["is_del"=>0,"cat_name"=>$cat_name])->find();
|
|
|
- $int =isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
|
|
|
- $im = array_column($int,'name');
|
|
|
- $in=implode('/',$im);
|
|
|
- if(!empty($repeat_name)){
|
|
|
- return error_show(1004,"分类名称已在{$in}存在");
|
|
|
- }
|
|
|
- $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
|
|
|
- if (empty($specs_id)) {
|
|
|
- return error_show(1002, "参数specs_id不能为空");
|
|
|
- }
|
|
|
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
|
|
|
- if($token==''){
|
|
|
- return error_show(105,"参数token不能为空");
|
|
|
+
|
|
|
+ //列表
|
|
|
+ public function title()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['cat_name' => '', 'pid' => '', 'status' => '', 'supplierNo' => ''], 'post', 'trim');
|
|
|
+
|
|
|
+
|
|
|
+ $where = [['is_del', '=', 0]];
|
|
|
+ if ($param['cat_name'] !== '') $where[] = ['cat_name', 'like', '%' . $param['cat_name'] . '%'];
|
|
|
+ if ($param['pid'] !== '') $where[] = ['pid', '=', $param['pid']];
|
|
|
+ if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
|
|
|
+ if ($param['supplierNo'] !== '') $where[] = ['supplierNo', '=', $param['supplierNo']];
|
|
|
+
|
|
|
+ $list = Db::name('cat')
|
|
|
+ ->where($where)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ return app_show(0, '获取成功', $list);
|
|
|
}
|
|
|
- $user =GetUserInfo($token);
|
|
|
- if(empty($user)||$user['code']!=0){
|
|
|
- return error_show(102,"创建人数据不存在");
|
|
|
+
|
|
|
+ //列表
|
|
|
+ public function tlist()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_name' => '', 'status' => '', 'creater' => '', 'start' => '', 'end' => '', 'company_name' => '', 'supplierNo' => ''], 'post', 'trim');
|
|
|
+
|
|
|
+
|
|
|
+ $where = [['c.is_del', '=', 0]];
|
|
|
+ if ($param['cat_name'] !== '') $where[] = ['c.cat_name', 'like', '%' . $param['cat_name'] . '%'];
|
|
|
+ if ($param['status'] !== '') $where[] = ['c.status', '=', $param['status']];
|
|
|
+ if ($param['creater'] !== '') $where[] = ['c.creater', 'like', '%' . $param['creater'] . '%'];
|
|
|
+ if ($param['start'] !== '') $where[] = ['c.addtime', '>=', $param['start']];
|
|
|
+ if ($param['end'] !== '') $where[] = ['c.addtime', '<=', $param['end']];
|
|
|
+ if ($param['company_name'] !== '') $where[] = ['c.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
|
|
|
+ if ($param['supplierNo'] !== '') $where[] = ['c.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
|
|
|
+
|
|
|
+ $count = Db::name('cat')
|
|
|
+ ->alias('c')
|
|
|
+ ->leftJoin('depart_user u', 'u.uid=c.createrid AND u.is_del=0')
|
|
|
+ ->where($where)
|
|
|
+ ->count();
|
|
|
+// $total = ceil($count / $size);
|
|
|
+// $page = $page >= $total ? $total : $page;
|
|
|
+ $list = Db::name('cat')
|
|
|
+ ->alias('c')
|
|
|
+ ->field('c.*,u.itemid')
|
|
|
+ ->leftJoin('depart_user u', 'u.uid=c.createrid AND u.is_del=0')
|
|
|
+ ->where($where)
|
|
|
+ ->page($param['page'], $param['size'])
|
|
|
+ ->cursor();
|
|
|
+ $var = [];
|
|
|
+ foreach ($list as $value) {
|
|
|
+ $temp = Db::name('cat_specs')
|
|
|
+ ->field('a.specs_id,b.spec_name')
|
|
|
+ ->alias('a')
|
|
|
+ ->leftJoin('specs b', 'b.id=a.specs_id')
|
|
|
+ ->where(['a.cat_id' => $value['id'], 'a.is_del' => 0])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $value['im'] = $temp;
|
|
|
+ $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
|
|
|
+ $var[] = $value;
|
|
|
+ }
|
|
|
+ return app_show(0, '获取成功', ['list' => $var, 'count' => $count]);
|
|
|
}
|
|
|
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
- $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? intval($this->post['weight']) : "0";
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
|
|
|
- Db::startTrans();
|
|
|
- try{
|
|
|
- $data = [
|
|
|
- "cat_name" => $cat_name,
|
|
|
- "pid" => $pid,
|
|
|
- "level" => $level,
|
|
|
- "search" => $search,
|
|
|
- "weight" => $weight,
|
|
|
- "status" => $status,
|
|
|
- "cat_desc"=>$cat_desc,
|
|
|
- "fund_code"=>$fund_code,
|
|
|
- "creater"=>$creater,
|
|
|
- "createrid"=>$createrid,
|
|
|
- "is_del"=>0,
|
|
|
- "addtime" => date("Y-m-d H:i:s"),
|
|
|
- "updatetime" => date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
- $datainfo = Db::name('cat')->insert($data,true);
|
|
|
- $vat =[];
|
|
|
- if ($datainfo>0) {
|
|
|
- $stx = ["order_code"=>$pid,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
|
|
|
- ActionLog::logAdd($this->post['token'],$stx,"sxd",$status,$stx);
|
|
|
- $spc =[];
|
|
|
- $spc['cat_id']=$datainfo;
|
|
|
- $spc['exam_status']=0;
|
|
|
- $spc['status']=0;
|
|
|
- $spc['creater']=$creater;
|
|
|
- $spc['createrid']=$createrid;
|
|
|
- $spc['is_del']=0;
|
|
|
- $spc['addtime']=date("Y-m-d H:i:d");
|
|
|
- $spc['updatetime']=date("Y-m_d H:i:s");
|
|
|
- $vpn = Db::name('cat_spec')->insert($spc,true);
|
|
|
- if ($vpn == "") {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "新建失败");
|
|
|
- }
|
|
|
- foreach ($specs_id as $value){
|
|
|
- $item =[];
|
|
|
- $item['cat_id']=$datainfo;
|
|
|
- $item['specs_id']=$value;
|
|
|
- $item['is_del']=0;
|
|
|
- $item['addtime']=date("Y-m-d H:i:s");
|
|
|
- $vat[] = $item;
|
|
|
- }
|
|
|
- $vp = Db::name('cat_specs')->insertAll($vat);
|
|
|
- if ($vp==0) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, "新建失败");
|
|
|
- }
|
|
|
|
|
|
- $catinfo=['cat_id'=>$datainfo,'apply_name'=>$creater,"apply_id"=>$createrid,"fund_code"=>$fund_code,"status"=>0];
|
|
|
+ //创建
|
|
|
+ public function create()
|
|
|
+ {
|
|
|
+ $param = $this->request->only(['cat_name', 'pid', 'cat_desc' => '', 'fund_code' => '', 'specs_id', 'weight' => 0, 'status' => 0, 'ssupplierNo'], 'post', 'trim');
|
|
|
+// $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== '' ? trim($this->post['cat_name']) : '';
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'cat_name|分类名称' => 'require|max:255',
|
|
|
+ 'pid|父级id' => 'require|number|egt:0',
|
|
|
+ 'specs_id' => 'require|array|max:100',
|
|
|
+ 'weight|权重' => 'number|egt:0',
|
|
|
+ 'status|状态' => 'number|in:0,1',
|
|
|
+ 'ssupplierNo|公司编码' => 'require|length:18',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (!$val->check($param)) return json_show(1004, $val->getError());
|
|
|
+
|
|
|
+// if ($cat_name == '') {
|
|
|
+// return error_show(1002, '参数cat_name不能为空');
|
|
|
+// }
|
|
|
+// $pid = isset($this->post['pid']) && $this->post['pid'] !== '' ? intval($this->post['pid']) : '0';
|
|
|
+// if ($pid === '') {
|
|
|
+// return error_show(1002, '参数pid不能为空');
|
|
|
+// }
|
|
|
+
|
|
|
+// $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== '' ? trim($this->post['cat_desc']) : '';
|
|
|
+// $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== '' ? trim($this->post['fund_code']) : '';
|
|
|
+
|
|
|
+ $level = 1;
|
|
|
+ if ($param['pid'] !== 0) {
|
|
|
+ $levl = Db::name('cat')
|
|
|
+ ->field('id,level,search')
|
|
|
+ ->where(['id' => $param['pid']])
|
|
|
+ ->find();
|
|
|
+ if (empty($levl)) return json_show(1002, '未找到父级数据');
|
|
|
+
|
|
|
+ $level = $levl['level'] + 1;
|
|
|
+ $temp = $levl['search'];
|
|
|
+ }
|
|
|
+ if ($level == 1) $search = $param['cat_name'];
|
|
|
+ else $search = $temp . '-' . $param['cat_name'];
|
|
|
+
|
|
|
+ $repeat_name = Db::name('cat')
|
|
|
+ ->field('id')
|
|
|
+ ->where(['is_del' => 0, 'cat_name' => $param['cat_name']])
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ $int = isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
|
|
|
+ $im = array_column($int, 'name');
|
|
|
+ $in = implode('/', $im);
|
|
|
+ if (!empty($repeat_name)) {
|
|
|
+ return json_show(1004, "分类名称已在{$in}存在");
|
|
|
+ }
|
|
|
+// $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== '' ? $this->post['specs_id'] : [];
|
|
|
+// if (empty($specs_id)) {
|
|
|
+// return error_show(1002, '参数specs_id不能为空');
|
|
|
+// }
|
|
|
+// $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : '';
|
|
|
+// if ($token == '') {
|
|
|
+// return error_show(105, '参数token不能为空');
|
|
|
+// }
|
|
|
+// $user = GetUserInfo($token);
|
|
|
+// if (empty($user) || $user['code'] != 0) {
|
|
|
+// return error_show(102, '创建人数据不存在');
|
|
|
+// }
|
|
|
+ $createrid = $this->uid;//isset($user['data']['id']) ? $user['data']['id'] : '';
|
|
|
+ $creater = $this->uname;//($user['data']['nickname']) ? $user['data']['nickname'] : '';
|
|
|
+// $weight = isset($this->post['weight']) && $this->post['weight'] !== '' ? intval($this->post['weight']) : '0';
|
|
|
+// $status = isset($this->post['status']) && $this->post['status'] !== '' ? intval($this->post['status']) : '0';
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+ $data = [
|
|
|
+ 'cat_name' => $param['cat_name'],
|
|
|
+ 'pid' => $param['pid'],
|
|
|
+ 'level' => $level,
|
|
|
+ 'search' => $search,
|
|
|
+ 'weight' => $param['weight'],
|
|
|
+ 'status' => $param['status'],
|
|
|
+ 'cat_desc' => $param['cat_desc'],
|
|
|
+ 'fund_code' => $param['fund_code'],
|
|
|
+ 'supplierNo' => $param['ssupplierNo'],
|
|
|
+ 'creater' => $creater,
|
|
|
+ 'createrid' => $createrid,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ];
|
|
|
+ $datainfo = Db::name('cat')->insertGetId($data);
|
|
|
+ $vat = [];
|
|
|
+ if ($datainfo > 0) {
|
|
|
+ $stx = ['order_code' => $param['pid'], 'status' => $param['status'], 'action_remark' => '', 'action_type' => 'create'];
|
|
|
+ ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], $stx, 'sxd', $param['status'], $stx);
|
|
|
+ $spc = [];
|
|
|
+ $spc['cat_id'] = $datainfo;
|
|
|
+ $spc['exam_status'] = 0;
|
|
|
+ $spc['status'] = 0;
|
|
|
+ $spc['creater'] = $creater;
|
|
|
+ $spc['createrid'] = $createrid;
|
|
|
+ $spc['is_del'] = 0;
|
|
|
+ $spc['addtime'] = $date;
|
|
|
+ $spc['updatetime'] = $date;
|
|
|
+ $vpn = Db::name('cat_spec')->insertGetId($spc);
|
|
|
+ if ($vpn == '') throw new Exception('新建失败');
|
|
|
+
|
|
|
+ foreach ($param['specs_id'] as $value) {
|
|
|
+ $item = [];
|
|
|
+ $item['cat_id'] = $datainfo;
|
|
|
+ $item['specs_id'] = $value;
|
|
|
+ $item['is_del'] = 0;
|
|
|
+ $item['addtime'] = $date;
|
|
|
+ $vat[] = $item;
|
|
|
+ }
|
|
|
+ $vp = Db::name('cat_specs')->insertAll($vat);
|
|
|
+ if ($vp == 0) throw new Exception('新建失败');
|
|
|
+
|
|
|
+
|
|
|
+ $catinfo = ['cat_id' => $datainfo, 'apply_name' => $creater, 'apply_id' => $createrid, 'fund_code' => $param['fund_code'], 'status' => 0];
|
|
|
$this->addPlat($catinfo);
|
|
|
- Db::commit();
|
|
|
- return error_show(0, "新建成功");
|
|
|
- } else {
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, '新建成功');
|
|
|
+ } else {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1002, '新建失败');
|
|
|
+ }
|
|
|
+ } catch (Exception $exception) {
|
|
|
Db::rollback();
|
|
|
- return error_show(1002, "新建失败");
|
|
|
+ return json_show(1005, $exception->getMessage());
|
|
|
}
|
|
|
- }catch (\Exception $e){
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005,$e->getMessage());
|
|
|
- }
|
|
|
|
|
|
-}
|
|
|
-public function edit(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
|
|
|
- $idinfo = Db::name('cat')->where(['id'=>$id])->find();
|
|
|
- if($idinfo==""){
|
|
|
- return error_show(1002,"未找到商品数据");
|
|
|
- }
|
|
|
- $cat_name= isset($this->post['cat_name']) && $this->post['cat_name'] !=="" ? trim($this->post['cat_name']) :"";
|
|
|
- if($cat_name==""){
|
|
|
- return error_show(1002,"参数cat_name不能为空");
|
|
|
- }
|
|
|
- $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']) :"";
|
|
|
- if($pid===""){
|
|
|
- return error_show(1002,"参数pid不能为空");
|
|
|
- }
|
|
|
- $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !=="" ? trim($this->post['cat_desc']) :"";
|
|
|
- $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
|
|
|
- $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
|
|
|
- if (empty($specs_id)) {
|
|
|
- return error_show(1002, "参数specs_id不能为空");
|
|
|
- }
|
|
|
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
|
|
|
- if($token==''){
|
|
|
- return error_show(105,"参数token不能为空");
|
|
|
- }
|
|
|
- $user =GetUserInfo($token);
|
|
|
- if(empty($user)||$user['code']!=0){
|
|
|
- return error_show(102,"创建人数据不存在");
|
|
|
}
|
|
|
|
|
|
- $level =1;
|
|
|
- if ($pid !== 0) {
|
|
|
- $levl=Db::name('cat')->where(['id'=>$pid])->find();
|
|
|
- if(empty($levl)){
|
|
|
- return error_show(1002,"未找到父级数据");
|
|
|
+ //编辑
|
|
|
+ public function edit()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
|
|
|
+ $idinfo = Db::name('cat')->where(['id' => $id])->find();
|
|
|
+ if ($idinfo == '') {
|
|
|
+ return error_show(1002, '未找到商品数据');
|
|
|
}
|
|
|
- $level =$levl['level']+1;
|
|
|
- $temp = $levl['search'];
|
|
|
- }
|
|
|
- if($level==1){
|
|
|
- $search = $cat_name;
|
|
|
- }else{
|
|
|
- $search= $temp."_".$cat_name;
|
|
|
- }
|
|
|
- $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
- $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
- //$level = isset($this->post['level']) && $this->post['level'] !=="" ? intval($this->post['level']) :"";
|
|
|
-
|
|
|
- $weight = isset($this->post['weight']) && $this->post['weight']!==""? intval($this->post['weight']):"0";
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']) :"0";
|
|
|
- Db::startTrans();
|
|
|
- try{
|
|
|
- $str = [
|
|
|
- "id"=>$id,
|
|
|
- "cat_name"=>$cat_name,
|
|
|
- "pid"=>$pid,
|
|
|
- "level"=>$level,
|
|
|
- "weight"=>$weight,
|
|
|
- // "status"=>$status,
|
|
|
- "cat_desc"=>$cat_desc,
|
|
|
- "is_del"=>0,
|
|
|
- "fund_code"=>$fund_code,
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
- "search"=>$search
|
|
|
- ];
|
|
|
- $strinfo = Db::name('cat')->where(['id'=>$id])->save($str);
|
|
|
- $temp = array_diff($str,$idinfo);
|
|
|
- $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
|
|
|
- $jsp = json_encode($idinfo,JSON_UNESCAPED_UNICODE);
|
|
|
- if($strinfo){
|
|
|
- $order = ["order_code"=>$id,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
|
|
|
- ActionLog::logAdd($this->post['token'],$order,"sxd",$status,$order);
|
|
|
- ChangeLog::logAdd(7,$idinfo['id'],$jsp,$json,$this->post['token'],$this->post);
|
|
|
- $spc =[];
|
|
|
- $vp = Db::name('cat_spec')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->find();
|
|
|
- $str ="";
|
|
|
- if($vp!=false){
|
|
|
- isset($vp['id']) && $vp['id'] !== "" ? $spc['id'] = $vp['id'] : '';
|
|
|
- $spc['cat_id']=$idinfo['id'];
|
|
|
- $spc['exam_status']=0;
|
|
|
- $spc['status']=0;
|
|
|
- $spc['is_del']=0;
|
|
|
- $spc['updatetime']=date("Y-m_d H:i:s");
|
|
|
- $str=$vp['id'];
|
|
|
- $vpn = Db::name('cat_spec')->save($spc);
|
|
|
- }else{
|
|
|
-
|
|
|
- $spc['cat_id']=$idinfo['id'];
|
|
|
- $spc['exam_status']=0;
|
|
|
- $spc['status']=0;
|
|
|
- $spc['creater']=$creater;
|
|
|
- $spc['createrid']=$createrid;
|
|
|
- $spc['is_del']=0;
|
|
|
- $spc['addtime']=date("Y-m-d H:i:d");
|
|
|
- $spc['updatetime']=date("Y-m_d H:i:s");
|
|
|
-
|
|
|
- $vpn = Db::name('cat_spec')->insert($spc,true);
|
|
|
- $str=$vpn;
|
|
|
+ $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== '' ? trim($this->post['cat_name']) : '';
|
|
|
+ if ($cat_name == '') {
|
|
|
+ return error_show(1002, '参数cat_name不能为空');
|
|
|
}
|
|
|
- if ($vpn == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "更新失败");
|
|
|
+ $pid = isset($this->post['pid']) && $this->post['pid'] !== '' ? intval($this->post['pid']) : '';
|
|
|
+ if ($pid === '') {
|
|
|
+ return error_show(1002, '参数pid不能为空');
|
|
|
+ }
|
|
|
+ $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== '' ? trim($this->post['cat_desc']) : '';
|
|
|
+ $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== '' ? trim($this->post['fund_code']) : '';
|
|
|
+ $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== '' ? $this->post['specs_id'] : [];
|
|
|
+ if (empty($specs_id)) {
|
|
|
+ return error_show(1002, '参数specs_id不能为空');
|
|
|
+ }
|
|
|
+ $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : '';
|
|
|
+ if ($token == '') {
|
|
|
+ return error_show(105, '参数token不能为空');
|
|
|
+ }
|
|
|
+ $user = GetUserInfo($token);
|
|
|
+ if (empty($user) || $user['code'] != 0) {
|
|
|
+ return error_show(102, '创建人数据不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $level = 1;
|
|
|
+ if ($pid !== 0) {
|
|
|
+ $levl = Db::name('cat')->where(['id' => $pid])->find();
|
|
|
+ if (empty($levl)) {
|
|
|
+ return error_show(1002, '未找到父级数据');
|
|
|
}
|
|
|
- $db = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column("specs_id");
|
|
|
- if(empty($db)){
|
|
|
- $db=[];
|
|
|
- }
|
|
|
- $sn = array_diff($specs_id,$db);
|
|
|
-
|
|
|
- $st = array_diff($db,$specs_id);
|
|
|
- if(!empty($st)){
|
|
|
- $int['is_del']=1;
|
|
|
- $dn = Db::name('cat_specs')->where(['specs_id'=>$st,'is_del'=>0])->save($int);
|
|
|
- if ($dn==false) {
|
|
|
+ $level = $levl['level'] + 1;
|
|
|
+ $temp = $levl['search'];
|
|
|
+ }
|
|
|
+ if ($level == 1) {
|
|
|
+ $search = $cat_name;
|
|
|
+ } else {
|
|
|
+ $search = $temp . '_' . $cat_name;
|
|
|
+ }
|
|
|
+ $createrid = isset($user['data']['id']) ? $user['data']['id'] : '';
|
|
|
+ $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
|
|
|
+ //$level = isset($this->post['level']) && $this->post['level'] !=='' ? intval($this->post['level']) :'';
|
|
|
+
|
|
|
+ $weight = isset($this->post['weight']) && $this->post['weight'] !== '' ? intval($this->post['weight']) : '0';
|
|
|
+ $status = isset($this->post['status']) && $this->post['status'] !== '' ? intval($this->post['status']) : '0';
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $str = [
|
|
|
+ 'id' => $id,
|
|
|
+ 'cat_name' => $cat_name,
|
|
|
+ 'pid' => $pid,
|
|
|
+ 'level' => $level,
|
|
|
+ 'weight' => $weight,
|
|
|
+ // 'status'=>$status,
|
|
|
+ 'cat_desc' => $cat_desc,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'fund_code' => $fund_code,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ 'search' => $search
|
|
|
+ ];
|
|
|
+ $strinfo = Db::name('cat')->where(['id' => $id])->save($str);
|
|
|
+ $temp = array_diff($str, $idinfo);
|
|
|
+ $json = json_encode($temp, JSON_UNESCAPED_UNICODE);
|
|
|
+ $jsp = json_encode($idinfo, JSON_UNESCAPED_UNICODE);
|
|
|
+ if ($strinfo) {
|
|
|
+ $order = ['order_code' => $id, 'status' => $status, 'action_remark' => '', 'action_type' => 'edit'];
|
|
|
+ ActionLog::logAdd($this->post['token'], $order, 'sxd', $status, $order);
|
|
|
+ ChangeLog::logAdd(7, $idinfo['id'], $jsp, $json, $this->post['token'], $this->post);
|
|
|
+ $spc = [];
|
|
|
+ $vp = Db::name('cat_spec')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->find();
|
|
|
+ $str = '';
|
|
|
+ if ($vp != false) {
|
|
|
+ isset($vp['id']) && $vp['id'] !== '' ? $spc['id'] = $vp['id'] : '';
|
|
|
+ $spc['cat_id'] = $idinfo['id'];
|
|
|
+ $spc['exam_status'] = 0;
|
|
|
+ $spc['status'] = 0;
|
|
|
+ $spc['is_del'] = 0;
|
|
|
+ $spc['updatetime'] = date('Y-m_d H:i:s');
|
|
|
+ $str = $vp['id'];
|
|
|
+ $vpn = Db::name('cat_spec')->save($spc);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $spc['cat_id'] = $idinfo['id'];
|
|
|
+ $spc['exam_status'] = 0;
|
|
|
+ $spc['status'] = 0;
|
|
|
+ $spc['creater'] = $creater;
|
|
|
+ $spc['createrid'] = $createrid;
|
|
|
+ $spc['is_del'] = 0;
|
|
|
+ $spc['addtime'] = date('Y-m-d H:i:d');
|
|
|
+ $spc['updatetime'] = date('Y-m_d H:i:s');
|
|
|
+
|
|
|
+ $vpn = Db::name('cat_spec')->insert($spc, true);
|
|
|
+ $str = $vpn;
|
|
|
+ }
|
|
|
+ if ($vpn == false) {
|
|
|
Db::rollback();
|
|
|
- return error_show(1002, "编辑失败");
|
|
|
+ return error_show(1002, '更新失败');
|
|
|
}
|
|
|
- }
|
|
|
- if(!empty($sn)){
|
|
|
- $vat=[];
|
|
|
- foreach ($sn as $value){
|
|
|
- $item=[];
|
|
|
- $item['cat_id']=$idinfo['id'];
|
|
|
- $item['specs_id']=$value;
|
|
|
- $item['is_del']=0;
|
|
|
- $item['addtime'] = date("Y-m-d H:i:s");
|
|
|
- $vat[] = $item;
|
|
|
+ $db = Db::name('cat_specs')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->column('specs_id');
|
|
|
+ if (empty($db)) {
|
|
|
+ $db = [];
|
|
|
}
|
|
|
- $vp = Db::name('cat_specs')->insertAll($vat);
|
|
|
- if ($vp==0) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "编辑失败");
|
|
|
+ $sn = array_diff($specs_id, $db);
|
|
|
+
|
|
|
+ $st = array_diff($db, $specs_id);
|
|
|
+ if (!empty($st)) {
|
|
|
+ $int['is_del'] = 1;
|
|
|
+ $dn = Db::name('cat_specs')->where(['specs_id' => $st, 'is_del' => 0])->save($int);
|
|
|
+ if ($dn == false) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, '编辑失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($sn)) {
|
|
|
+ $vat = [];
|
|
|
+ foreach ($sn as $value) {
|
|
|
+ $item = [];
|
|
|
+ $item['cat_id'] = $idinfo['id'];
|
|
|
+ $item['specs_id'] = $value;
|
|
|
+ $item['is_del'] = 0;
|
|
|
+ $item['addtime'] = date('Y-m-d H:i:s');
|
|
|
+ $vat[] = $item;
|
|
|
+ }
|
|
|
+ $vp = Db::name('cat_specs')->insertAll($vat);
|
|
|
+ if ($vp == 0) {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, '编辑失败');
|
|
|
+ }
|
|
|
}
|
|
|
+ $itn = sear($id);
|
|
|
+ Db::commit();
|
|
|
+ return error_show(0, '编辑成功');
|
|
|
+ } else {
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002, '编辑失败');
|
|
|
}
|
|
|
- $itn =sear($id);
|
|
|
- Db::commit();
|
|
|
- return error_show(0,"编辑成功");
|
|
|
- }else{
|
|
|
+ } catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
|
- return error_show(1002,"编辑失败");
|
|
|
+ return error_show(1005, $e->getMessage());
|
|
|
}
|
|
|
- }catch (\Exception $e){
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005,$e->getMessage());
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
- public function ratedit(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
|
|
|
- $idinfo = Db::name('cat')->where(['id'=>$id])->find();
|
|
|
- if($idinfo==""){
|
|
|
- return error_show(1002,"未找到商品数据");
|
|
|
+ //更新分类利率相关
|
|
|
+ public function ratedit()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
|
|
|
+ $idinfo = Db::name('cat')->where(['id' => $id])->find();
|
|
|
+ if ($idinfo == '') {
|
|
|
+ return error_show(1002, '未找到商品数据');
|
|
|
}
|
|
|
- $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? floatval($this->post['rate']) : "";
|
|
|
- $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? floatval($this->post['order_rate']) : "";
|
|
|
- $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== "" ? floatval($this->post['sale_rate']) : "";
|
|
|
- $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ? floatval($this->post['lower_rate']) :"";
|
|
|
- $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !=="" ? floatval($this->post['money_rate']):"";
|
|
|
- $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !=="" ? floatval($this->post['low_rate']):"";
|
|
|
- if($idinfo['pid']==0){
|
|
|
- if($rate===""){
|
|
|
- return error_show(1003,"参数rate不能为空");
|
|
|
+ $rate = isset($this->post['rate']) && $this->post['rate'] !== '' ? floatval($this->post['rate']) : '';
|
|
|
+ $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== '' ? floatval($this->post['order_rate']) : '';
|
|
|
+ $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== '' ? floatval($this->post['sale_rate']) : '';
|
|
|
+ $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== '' ? floatval($this->post['lower_rate']) : '';
|
|
|
+ $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !== '' ? floatval($this->post['money_rate']) : '';
|
|
|
+ $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !== '' ? floatval($this->post['low_rate']) : '';
|
|
|
+ if ($idinfo['pid'] == 0) {
|
|
|
+ if ($rate === '') {
|
|
|
+ return error_show(1003, '参数rate不能为空');
|
|
|
}
|
|
|
- if($order_rate===""){
|
|
|
- return error_show(1003,"参数order_rate不能为空");
|
|
|
+ if ($order_rate === '') {
|
|
|
+ return error_show(1003, '参数order_rate不能为空');
|
|
|
}
|
|
|
- if($sale_rate===""){
|
|
|
- return error_show(1003,"参数sale_rate不能为空");
|
|
|
+ if ($sale_rate === '') {
|
|
|
+ return error_show(1003, '参数sale_rate不能为空');
|
|
|
}
|
|
|
- if($lower_rate===""){
|
|
|
- return error_show(1003,"参数lower_rate不能为空");
|
|
|
+ if ($lower_rate === '') {
|
|
|
+ return error_show(1003, '参数lower_rate不能为空');
|
|
|
}
|
|
|
- if($money_rate==""){
|
|
|
- return error_show(1003,"参数money_rate不能为空");
|
|
|
+ if ($money_rate == '') {
|
|
|
+ return error_show(1003, '参数money_rate不能为空');
|
|
|
}
|
|
|
- if($low_rate==""){
|
|
|
- return error_show(1003,"参数low_rate不能为空");
|
|
|
+ if ($low_rate == '') {
|
|
|
+ return error_show(1003, '参数low_rate不能为空');
|
|
|
}
|
|
|
}
|
|
|
- $data =[
|
|
|
- "id"=>$id,
|
|
|
- "rate" => $rate,
|
|
|
- "lower_rate"=>$lower_rate,
|
|
|
- "order_rate"=>$order_rate,
|
|
|
- "sale_rate"=>$sale_rate,
|
|
|
- "money_rate"=>$money_rate,
|
|
|
- "low_rate"=>$low_rate,
|
|
|
- "is_del"=>0,
|
|
|
- "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ $data = [
|
|
|
+ 'id' => $id,
|
|
|
+ 'rate' => $rate,
|
|
|
+ 'lower_rate' => $lower_rate,
|
|
|
+ 'order_rate' => $order_rate,
|
|
|
+ 'sale_rate' => $sale_rate,
|
|
|
+ 'money_rate' => $money_rate,
|
|
|
+ 'low_rate' => $low_rate,
|
|
|
+ 'is_del' => 0,
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
- $strinfo = Db::name('cat')->where(['id'=>$id])->save($data);
|
|
|
- if($strinfo){
|
|
|
- return error_show(0,"更新成功");
|
|
|
- }else{
|
|
|
- return error_show(1002,"更新失败");
|
|
|
+ $strinfo = Db::name('cat')->where(['id' => $id])->save($data);
|
|
|
+ if ($strinfo) {
|
|
|
+ return error_show(0, '更新成功');
|
|
|
+ } else {
|
|
|
+ return error_show(1002, '更新失败');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-public function info(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
|
|
|
- if($id==""){
|
|
|
- return error_show(1002,"参数id不能为空");
|
|
|
- }
|
|
|
- $idinfo = Db::name('cat')->where(['id'=>$id])->find();
|
|
|
- if($idinfo==""){
|
|
|
- return error_show(1002,"未找到数据");
|
|
|
- }
|
|
|
- $info = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column('specs_id');
|
|
|
- $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id,spec_name")->select();
|
|
|
- //$idinfo['cat_id']=$info['cat_id'];
|
|
|
- $idinfo['spec']=$temp;
|
|
|
- // $idinfo['specs_id']=$info;
|
|
|
- return app_show(0,"获取成功",$idinfo);
|
|
|
-}
|
|
|
-public function status(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
|
|
|
- if($id===""){
|
|
|
- return error_show(1002,"参数id不能为空");
|
|
|
- }
|
|
|
- $stn = Db::name('cat')->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($status==1){
|
|
|
- if($stn['rate']===""){
|
|
|
- return error_show(1003,"单品修改下限未设置");
|
|
|
+ //详情
|
|
|
+ public function info()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
|
|
|
+ if ($id == '') {
|
|
|
+ return error_show(1002, '参数id不能为空');
|
|
|
}
|
|
|
- if($stn['order_rate']===""){
|
|
|
- return error_show(1003,"预算成本利率未设置");
|
|
|
+ $idinfo = Db::name('cat')->where(['id' => $id])->find();
|
|
|
+ if ($idinfo == '') {
|
|
|
+ return error_show(1002, '未找到数据');
|
|
|
}
|
|
|
- if($stn['sale_rate']===""){
|
|
|
- return error_show(1003,"分类成本售价利率未设置");
|
|
|
+ $info = Db::name('cat_specs')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->column('specs_id');
|
|
|
+ $temp = Db::name('specs')->where(['id' => $info, 'is_del' => 0])->field('id,spec_name')->select();
|
|
|
+ //$idinfo['cat_id']=$info['cat_id'];
|
|
|
+ $idinfo['spec'] = $temp;
|
|
|
+ // $idinfo['specs_id']=$info;
|
|
|
+ return app_show(0, '获取成功', $idinfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //启禁用
|
|
|
+ public function status()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
|
|
|
+ if ($id === '') {
|
|
|
+ return error_show(1002, '参数id不能为空');
|
|
|
}
|
|
|
- if($stn['lower_rate']===""){
|
|
|
- return error_show(1003,"分类最低毛利率未设置");
|
|
|
+ $stn = Db::name('cat')->where(['id' => $id])->find();
|
|
|
+ if (empty($stn)) {
|
|
|
+ return error_show(1002, '未找到商品数据');
|
|
|
}
|
|
|
-// if($stn['money_rate']==""){
|
|
|
-// return error_show(1003,"分类财务利率未设置");
|
|
|
+ $status = isset($this->post['status']) && $this->post['status'] !== '' ? intval($this->post['status']) : '';
|
|
|
+ if ($status === '') {
|
|
|
+ return error_show(1002, '参数status不能为空');
|
|
|
+ }
|
|
|
+ if ($status == 1) {
|
|
|
+ if ($stn['rate'] === '') {
|
|
|
+ return error_show(1003, '单品修改下限未设置');
|
|
|
+ }
|
|
|
+ if ($stn['order_rate'] === '') {
|
|
|
+ return error_show(1003, '预算成本利率未设置');
|
|
|
+ }
|
|
|
+ if ($stn['sale_rate'] === '') {
|
|
|
+ return error_show(1003, '分类成本售价利率未设置');
|
|
|
+ }
|
|
|
+ if ($stn['lower_rate'] === '') {
|
|
|
+ return error_show(1003, '分类最低毛利率未设置');
|
|
|
+ }
|
|
|
+// if($stn['money_rate']==''){
|
|
|
+// return error_show(1003,'分类财务利率未设置');
|
|
|
// }
|
|
|
-// if($stn['low_rate']==""){
|
|
|
-// return error_show(1003,"分类最低毛利未设置");
|
|
|
+// if($stn['low_rate']==''){
|
|
|
+// return error_show(1003,'分类最低毛利未设置');
|
|
|
// }
|
|
|
-// if($stn['fund_code']==""){
|
|
|
-// return error_show(1003,"分类核算码未设置");
|
|
|
+// if($stn['fund_code']==''){
|
|
|
+// return error_show(1003,'分类核算码未设置');
|
|
|
// }
|
|
|
- }
|
|
|
- if ($stn['level']==3) {
|
|
|
- if($status==1){
|
|
|
- $can = made($stn['id']);
|
|
|
- $cat=array_column($can,'id');
|
|
|
- }else{
|
|
|
- $cat =$stn['id'];
|
|
|
}
|
|
|
- // return error_show(1002, "所在级别不能启用");
|
|
|
- }
|
|
|
- if($stn['level']==2 || $stn['level']==1){
|
|
|
- if($status==1){
|
|
|
- return error_show(1002,"所在等级不能启用");
|
|
|
- }else{
|
|
|
- $db= Db::name('cat')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
|
|
|
- if($db==0){
|
|
|
+ if ($stn['level'] == 3) {
|
|
|
+ if ($status == 1) {
|
|
|
+ $can = made($stn['id']);
|
|
|
+ $cat = array_column($can, 'id');
|
|
|
+ } else {
|
|
|
$cat = $stn['id'];
|
|
|
- }else{
|
|
|
- return error_show(1002,"子级分类未禁用");
|
|
|
}
|
|
|
+ // return error_show(1002, '所在级别不能启用');
|
|
|
}
|
|
|
- }
|
|
|
- // $pd= $stn['status'];
|
|
|
- $it=[];
|
|
|
- $it['status']=$status;
|
|
|
- $it['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $str = Db::name('cat')->where(['id'=>$cat,'is_del'=>0])->save($it);
|
|
|
- if($str){
|
|
|
-
|
|
|
- $catinfo=['cat_id'=>$id,"status"=>$status];
|
|
|
- $this->addPlat($catinfo);
|
|
|
- if (!empty($cat)){
|
|
|
- $catinfo=['cat_id'=> $cat,"status"=>$status];
|
|
|
+ if ($stn['level'] == 2 || $stn['level'] == 1) {
|
|
|
+ if ($status == 1) {
|
|
|
+ return error_show(1002, '所在等级不能启用');
|
|
|
+ } else {
|
|
|
+ $db = Db::name('cat')->where(['pid' => $stn['id'], 'status' => 1, 'is_del' => 0])->count();
|
|
|
+ if ($db == 0) {
|
|
|
+ $cat = $stn['id'];
|
|
|
+ } else {
|
|
|
+ return error_show(1002, '子级分类未禁用');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // $pd= $stn['status'];
|
|
|
+ $it = [];
|
|
|
+ $it['status'] = $status;
|
|
|
+ $it['updatetime'] = date('Y-m-d H:i:s');
|
|
|
+ $str = Db::name('cat')->where(['id' => $cat, 'is_del' => 0])->save($it);
|
|
|
+ if ($str) {
|
|
|
+
|
|
|
+ $catinfo = ['cat_id' => $id, 'status' => $status];
|
|
|
+ $this->addPlat($catinfo);
|
|
|
+ if (!empty($cat)) {
|
|
|
+ $catinfo = ['cat_id' => $cat, 'status' => $status];
|
|
|
$this->addPlat($catinfo);
|
|
|
}
|
|
|
- return error_show(0,"状态更新成功");
|
|
|
- }else{
|
|
|
- return error_show(1002,"状态更新失败");
|
|
|
+ return error_show(0, '状态更新成功');
|
|
|
+ } else {
|
|
|
+ return error_show(1002, '状态更新失败');
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
- public function delete(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
|
|
|
- $info = Db::name('cat')->where(["is_del"=>0,'id'=>$id])->find();
|
|
|
- if($info==false){
|
|
|
- return error_show(1002,"未找到数据");
|
|
|
+
|
|
|
+ //删除
|
|
|
+ public function delete()
|
|
|
+ {
|
|
|
+ $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
|
|
|
+ $info = Db::name('cat')->where(['is_del' => 0, 'id' => $id])->find();
|
|
|
+ if ($info == false) {
|
|
|
+ return error_show(1002, '未找到数据');
|
|
|
}
|
|
|
- $supp= Db::name('cat')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
- if($supp){
|
|
|
- return error_show(0,"删除成功");
|
|
|
- }else{
|
|
|
- return error_show(1002,"删除失败");
|
|
|
+ $supp = Db::name('cat')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
|
|
|
+ if ($supp) {
|
|
|
+ return error_show(0, '删除成功');
|
|
|
+ } else {
|
|
|
+ return error_show(1002, '删除失败');
|
|
|
}
|
|
|
}
|
|
|
- /** 平台添加分类 **/
|
|
|
- private function addPlat($cat){
|
|
|
- $plat =Db::name("platform")->where(["platform_type"=>1,"is_del"=>0])->select()->toArray();
|
|
|
- if (empty($plat)){
|
|
|
- return '';
|
|
|
- }
|
|
|
- foreach ($plat as $value){
|
|
|
- $cat['platform_id']=$value['id'];
|
|
|
- $cat['addtime']=date("Y-m-d H:i:s");
|
|
|
- $cat['updatetime']=date("Y-m-d H:i:s");
|
|
|
- $isT = Db::name("cat_plat")->where(["cat_id"=>$cat['cat_id'],"platform_id"=>$cat['platform_id'],"is_del"=>0])->column("cat_id");
|
|
|
- if($isT){
|
|
|
- $data=$cat;
|
|
|
- unset($data['cat_id']);
|
|
|
- unset($data['addtime']);
|
|
|
- Db::name("cat_plat")->where(["cat_id"=>$cat['cat_id'],"platform_id"=>$cat['platform_id'],"is_del"=>0])->update($data);
|
|
|
- }else{
|
|
|
- Db::name("cat_plat")->save($cat);
|
|
|
- }
|
|
|
+
|
|
|
+ //平台添加分类
|
|
|
+ private function addPlat($cat)
|
|
|
+ {
|
|
|
+ $plat = Db::name('platform')
|
|
|
+ ->field('id')
|
|
|
+ ->where(['platform_type' => 1, 'is_del' => 0])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ if (empty($plat)) return false;
|
|
|
+
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ $isT = Db::name('cat_plat')
|
|
|
+ ->where(['cat_id' => $cat['cat_id'], 'is_del' => 0])
|
|
|
+ ->column('id', 'platform_id');
|
|
|
+
|
|
|
+ foreach ($plat as $value) {
|
|
|
+ $cat['platform_id'] = $value['id'];
|
|
|
+ $cat['addtime'] = $date;
|
|
|
+ $cat['updatetime'] = $date;
|
|
|
+// $isT = Db::name('cat_plat')
|
|
|
+// ->where(['cat_id' => $cat['cat_id'], 'platform_id' => $cat['platform_id'], 'is_del' => 0])
|
|
|
+// ->column('cat_id');
|
|
|
+ if (isset($isT[$cat['platform_id']])) {
|
|
|
+ $data = $cat;
|
|
|
+ unset($data['cat_id']);
|
|
|
+ unset($data['addtime']);
|
|
|
+ Db::name('cat_plat')
|
|
|
+ ->where('id', $isT[$cat['platform_id']])
|
|
|
+ ->update($data);
|
|
|
+ } else Db::name('cat_plat')->save($cat);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
+ return true;
|
|
|
+
|
|
|
}
|
|
|
}
|