request->only(['page' => 1, 'size' => 10, 'companyNo', 'platform_id', 'cat_name' => '', 'pid' => 0], 'post', 'trim'); $val = Validate::rule([ 'companyNo|公司编码' => 'require|length:18', 'platform_id|平台id' => 'require|number|gt:0', 'pid|父级分类id' => 'require|number|egt:0', ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); $where = [ ['a.is_del', '=', 0], ['a.pid', '=', $param['pid']], ]; if ($param['cat_name'] != '') $where[] = ['a.cat_name', 'like', '%' . $param['cat_name'] . '%']; $count = Db::name('cat') ->alias('a') ->leftJoin('company_platform_cat_profit b', 'b.cat_id=a.id AND b.is_del=0') ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0') ->where($where) ->count('a.id'); $list = Db::name('cat') ->alias('a') ->field('a.id cat_id,a.cat_name,a.level,p.platform_name,b.rate,b.order_rate,b.money_rate,b.low_rate,b.sale_rate,b.status') ->leftJoin('company_platform_cat_profit b', 'b.cat_id=a.id AND b.is_del=0 AND b.companyNo=\'' . $param['companyNo'] . '\' AND b.platform_id=\'' . $param['platform_id'] . '\'') ->leftJoin('platform p', 'p.id=b.platform_id AND p.is_del=0') ->where($where) ->order('a.id', 'desc') ->page($param['page'], $param['size']) ->select() ->toArray(); return json_show(0, '获取列表成功', ['count' => $count, 'list' => $list]); } //设置 public function set() { $param = $this->request->only(['companyNo', 'platform_id', 'cat_id', 'rate', 'order_rate', 'money_rate', 'low_rate', 'sale_rate'], 'post', 'trim'); $val = Validate::rule([ 'companyNo|公司编码' => 'require|length:18', 'platform_id|平台id' => 'require|number|gt:0', 'cat_id|分类id' => 'require|number|gt:0', 'rate|主管利率' => 'require|float|between:0,100', 'order_rate|预算成本' => 'require|float|between:0,100', 'money_rate|财务利率' => 'require|float|between:0,100', 'low_rate|最低利率' => 'require|float|between:0,100', 'sale_rate|成本售价' => 'require|float|between:0,100', ]); if (!$val->check($param)) return json_show(1004, $val->getError()); $rs = Db::name('company_platform_cat_profit') ->field('id') ->where([ 'is_del' => 0, 'companyNo' => $param['companyNo'], 'platform_id' => $param['platform_id'], 'cat_id' => $param['cat_id'], ]) ->findOrEmpty(); $date = date('Y-m-d H:i:s'); if (empty($rs)) { $rs = Db::name('company_platform_cat_profit') ->insert([ 'companyNo' => $param['companyNo'], 'platform_id' => $param['platform_id'], 'cat_id' => $param['cat_id'], 'rate' => $param['rate'], 'order_rate' => $param['order_rate'], 'money_rate' => $param['money_rate'], 'low_rate' => $param['low_rate'], 'sale_rate' => $param['sale_rate'], 'status' => 1, 'is_del' => 0, 'addtime' => $date, 'updatetime' => $date, ]); } else { $rs = Db::name('company_platform_cat_profit') ->where(['is_del' => 0, 'id' => $rs['id']]) ->update([ 'rate' => $param['rate'], 'order_rate' => $param['order_rate'], 'money_rate' => $param['money_rate'], 'low_rate' => $param['low_rate'], 'sale_rate' => $param['sale_rate'], 'updatetime' => $date ]); } return $rs ? json_show(0, '设置成功') : json_show(1004, '设置失败'); } //启禁用 // public function status() // { // $param = $this->request->only(['cat_id', 'companyNo', 'platform_id', 'status'], 'post', 'trim'); // // $val = Validate::rule([ // 'cat_id|分类id' => 'require|number|gt:0', // 'platform_id|平台id' => 'require|number|gt:0', // 'companyNo|公司编码' => 'require|length:18', // 'status|状态' => 'require|number|in:0,1', // ]); // // if ($val->check($param) == false) return json_show(1004, $val->getError()); // // $cat = Db::name('cat') // ->field('id,level') // ->where(['id' => $param['cat_id'], 'is_del' => 0]) // ->findOrEmpty(); // // if (empty($cat)) return json_show(1005, '该分类不存在'); // // //要操作的分类id集合 // switch ($cat['level']) { // case 1: // $first_ids = Db::name('cat') // ->where(['is_del' => 0, 'pid' => $param['cat_id']]) // ->column('id'); // // $second_ids = Db::name('cat') // ->where('is_del', 0) // ->whereIn('pid', $first_ids) // ->column('id'); // // $cat_ids = array_merge($first_ids, $second_ids); // break; // // case 2: // $cat_ids = Db::name('cat') // ->where(['is_del' => 0, 'pid' => $param['cat_id']]) // ->column('id'); // break; // } // // $cat_ids[] = $param['cat_id']; // // $rs = Db::name('company_platform_cat_profit') // ->where(['is_del' => 0, 'companyNo' => $param['companyNo'], 'platform_id' => $param['platform_id']]) // ->whereIn('cat_id', $cat_ids) // ->where('status', '<>', $param['status']) // ->update([ // 'status' => $param['status'], // 'updatetime' => date('Y-m-d H:i:s') // ]); // return $rs ? json_show(0, '操作成功') : json_show(1004, '操作失败,该记录不存在或重复操作'); // // } //删除 public function delete() { $param = $this->request->only(['companyNo', 'platform_id', 'cat_id'], 'post', 'trim'); $val = Validate::rule([ 'companyNo|公司编码' => 'require|length:18', 'platform_id|平台id' => 'require|number|gt:0', 'cat_id|分类id' => 'require|number|gt:0', ]); if ($val->check($param) == false) return json_show(1004, $val->getError()); $rs = Db::name('company_platform_cat_profit') ->where([ 'is_del' => 0, 'companyNo' => $param['companyNo'], 'platform_id' => $param['platform_id'], 'cat_id' => $param['cat_id'], ]) ->update([ 'is_del' => 1, 'updatetime' => date('Y-m-d H:i:s') ]); return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败'); } }