|
@@ -21,14 +21,14 @@ class CompanyCatProfit extends Base
|
|
|
|
|
|
$count = Db::name('cat')
|
|
|
->alias('a')
|
|
|
- ->leftJoin('business_cat_profit b', 'b.cat_id=a.id AND companyNo=\'' . $param['companyNo'] . '\'')
|
|
|
+ ->leftJoin('company_cat_profit b', 'b.cat_id=a.id AND companyNo=\'' . $param['companyNo'] . '\'')
|
|
|
->where($where)
|
|
|
->count('a.id');
|
|
|
|
|
|
$list = Db::name('cat')
|
|
|
->alias('a')
|
|
|
->field('a.id cat_id,a.cat_name,a.level,b.rate,b.order_rate,b.money_rate,b.low_rate,b.sale_rate,b.status')
|
|
|
- ->leftJoin('business_cat_profit b', 'b.is_del=0 AND b.cat_id=a.id AND companyNo=\'' . $param['companyNo'] . '\'')
|
|
|
+ ->leftJoin('company_cat_profit b', 'b.is_del=0 AND b.cat_id=a.id AND companyNo=\'' . $param['companyNo'] . '\'')
|
|
|
->where($where)
|
|
|
->withAttr('status', function ($val) {
|
|
|
return (int)$val;
|
|
@@ -58,7 +58,7 @@ class CompanyCatProfit extends Base
|
|
|
|
|
|
if (!$val->check($param)) return json_show(1004, $val->getError());
|
|
|
|
|
|
- $tmp = Db::name('business_cat_profit')
|
|
|
+ $tmp = Db::name('company_cat_profit')
|
|
|
->field('id')
|
|
|
->where(['is_del' => 0, 'companyNo' => $param['companyNo'], 'cat_id' => $param['cat_id']])
|
|
|
->findOrEmpty();
|
|
@@ -66,7 +66,7 @@ class CompanyCatProfit extends Base
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
if (empty($tmp)) {
|
|
|
- $rs = Db::name('business_cat_profit')
|
|
|
+ $rs = Db::name('company_cat_profit')
|
|
|
->insert([
|
|
|
'companyNo' => $param['companyNo'],
|
|
|
'cat_id' => $param['cat_id'],
|
|
@@ -81,7 +81,7 @@ class CompanyCatProfit extends Base
|
|
|
'updatetime' => $date
|
|
|
]);
|
|
|
} else {
|
|
|
- $rs = Db::name('business_cat_profit')
|
|
|
+ $rs = Db::name('company_cat_profit')
|
|
|
->where(['is_del' => 0, 'id' => $tmp['id']])
|
|
|
->update([
|
|
|
'rate' => $param['rate'],
|
|
@@ -114,37 +114,37 @@ class CompanyCatProfit extends Base
|
|
|
->where(['id' => $param['cat_id'], 'is_del' => 0])
|
|
|
->findOrEmpty();
|
|
|
|
|
|
- if(empty($cat)) return json_show(1005,'该分类不存在');
|
|
|
+ if (empty($cat)) return json_show(1005, '该分类不存在');
|
|
|
|
|
|
//要操作的分类id集合
|
|
|
- switch ($cat['level']){
|
|
|
+ switch ($cat['level']) {
|
|
|
case 1:
|
|
|
$first_ids = Db::name('cat')
|
|
|
- ->where(['is_del'=>0,'pid'=>$param['cat_id']])
|
|
|
+ ->where(['is_del' => 0, 'pid' => $param['cat_id']])
|
|
|
->column('id');
|
|
|
|
|
|
$second_ids = Db::name('cat')
|
|
|
- ->where('is_del',0)
|
|
|
- ->whereIn('pid',$first_ids)
|
|
|
+ ->where('is_del', 0)
|
|
|
+ ->whereIn('pid', $first_ids)
|
|
|
->column('id');
|
|
|
|
|
|
- $cat_ids = array_merge($first_ids,$second_ids);
|
|
|
+ $cat_ids = array_merge($first_ids, $second_ids);
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
$cat_ids = Db::name('cat')
|
|
|
- ->where(['is_del'=>0,'pid'=>$param['cat_id']])
|
|
|
+ ->where(['is_del' => 0, 'pid' => $param['cat_id']])
|
|
|
->column('id');
|
|
|
break;
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
- $cat_ids[]=$param['cat_id'];
|
|
|
+ $cat_ids[] = $param['cat_id'];
|
|
|
|
|
|
- $rs = Db::name('business_cat_profit')
|
|
|
- ->where(['is_del' => 0 , 'companyNo' => $param['companyNo']])
|
|
|
- ->whereIn('cat_id',$cat_ids)
|
|
|
+ $rs = Db::name('company_cat_profit')
|
|
|
+ ->where(['is_del' => 0, 'companyNo' => $param['companyNo']])
|
|
|
+ ->whereIn('cat_id', $cat_ids)
|
|
|
->where('status', '<>', $param['status'])
|
|
|
->update([
|
|
|
'status' => $param['status'],
|
|
@@ -167,7 +167,7 @@ class CompanyCatProfit extends Base
|
|
|
|
|
|
if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
|
|
|
|
- $rs = Db::name('business_cat_profit')
|
|
|
+ $rs = Db::name('company_cat_profit')
|
|
|
->where(['is_del' => 0, 'companyNo' => $param['companyNo'], 'cat_id' => $param['cat_id']])
|
|
|
->update([
|
|
|
'is_del' => 1,
|
|
@@ -177,4 +177,46 @@ class CompanyCatProfit extends Base
|
|
|
return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败');
|
|
|
}
|
|
|
|
|
|
+ //筛选指定公司下的所有分类
|
|
|
+ public function getListByCompany()
|
|
|
+ {
|
|
|
+
|
|
|
+ $param = $this->request->only(['companyNo', 'cat_name' => '', 'page' => 1, 'size' => 10], 'post', 'trim');
|
|
|
+
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'companyNo|公司编码' => 'require|length:18',
|
|
|
+ 'cat_name|分类名称' => 'max:255'
|
|
|
+ ]);
|
|
|
+ if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ ['a.companyNo', '=', $param['companyNo']],
|
|
|
+ ['a.is_del', '=', 0],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ($param['cat_name'] != '') $where[] = ['b.cat_name', 'like', '%' . $param['cat_name'] . '%'];
|
|
|
+
|
|
|
+ $count = Db::name('company_cat_profit')
|
|
|
+ ->alias('a')
|
|
|
+ ->leftJoin('cat b', 'b.id=a.cat_id')
|
|
|
+ ->leftJoin('cat c', 'b.id=b.pid')
|
|
|
+ ->leftJoin('cat d', 'd.id=c.pid')
|
|
|
+ ->where($where)
|
|
|
+ ->count('a.id');
|
|
|
+
|
|
|
+ $list = Db::name('company_cat_profit')
|
|
|
+ ->alias('a')
|
|
|
+ ->leftJoin('cat b', 'b.id=a.cat_id')
|
|
|
+ ->leftJoin('cat c', 'c.id=b.pid')
|
|
|
+ ->leftJoin('cat d', 'd.id=c.pid')
|
|
|
+ ->field('a.id,concat_ws("_",d.cat_name,c.cat_name,b.cat_name) cat_name,a.cat_id,a.rate,a.order_rate,a.money_rate,a.low_rate,a.sale_rate,a.status')
|
|
|
+ ->where($where)
|
|
|
+ ->order(['a.id' => 'desc'])
|
|
|
+ ->page($param['page'], $param['size'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ return json_show(0, '获取成功', ['count' => $count, 'list' => $list]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|