|
@@ -109,64 +109,6 @@ class CompanyPlatformCatProfit extends Base
|
|
|
}
|
|
|
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()
|
|
|
{
|
|
@@ -194,5 +136,62 @@ class CompanyPlatformCatProfit extends Base
|
|
|
|
|
|
return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ public function copyProfit(){
|
|
|
+ $param = $this->request->only(['companyNo', 'platform_id', 'cat_id',"copy_companyNo",'copy_platform_id', 'copy_cat_id',], 'post', 'trim');
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'companyNo|公司编码' => 'requireIf:platform_id,0|alphaNum|length:18',
|
|
|
+ 'platform_id|平台id' => 'requireIf:companyNo,0|number|egt:0',
|
|
|
+ 'cat_id|分类id' => 'number|egt:0',
|
|
|
+ 'copy_companyNo|源头公司编码' => 'requireWith:companyNo|alphaNum|length:18',
|
|
|
+ 'copy_platform_id|源头平台id' => 'requireWith:platform_id|number|egt:0',
|
|
|
+ 'copy_cat_id|源头分类id' => 'requireWith:cat_id|number|egt:0',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($val->check($param) == false)$this->error($val->getError());
|
|
|
+ $where = [["is_del","=",0]];
|
|
|
+ if($param['copy_companyNo']!=0){
|
|
|
+ $where[]=["companyNo","=",$param['copy_companyNo']];
|
|
|
+ }
|
|
|
+
|
|
|
+ if($param['copy_platform_id']!=0){
|
|
|
+ $where[]=['platform_id','=',$param['copy_platform_id']];
|
|
|
+ }
|
|
|
+ if($param['copy_cat_id']!=0){
|
|
|
+ $where[]=['cat_id','=',$param['copy_cat_id']];
|
|
|
+ }
|
|
|
+ if($param['copy_companyNo']==$param['companyNo'] &&$param['copy_platform_id']==$param['platform_id'] &&
|
|
|
+ $param['copy_cat_id']==$param['cat_id']){
|
|
|
+ $this->error("数据已存在,请删除后在复制");
|
|
|
+ }
|
|
|
+ $rs = Db::name('company_platform_cat_profit')->where($where)->field("companyNo,platform_id,cat_id,rate,order_rate,money_rate,low_rate,sale_rate ")->select();
|
|
|
+ if(empty($rs)) $this->error('未找到可复制数据');
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $temp=[];
|
|
|
+ foreach ($rs as $key=>$value){
|
|
|
+ if($param['platform_id']!=0){
|
|
|
+ $value['platform_id'] = $param['platform_id'];
|
|
|
+ }
|
|
|
+ if($param['cat_id']!=0){
|
|
|
+ $value['cat_id'] = $param['cat_id'];
|
|
|
+ }
|
|
|
+ if($param['companyNo']!=0){
|
|
|
+ $value['companyNo'] = $param['companyNo'];
|
|
|
+ }
|
|
|
+ $temp[]=$value;
|
|
|
+ if($key%1000==0){
|
|
|
+ Db::name('company_platform_cat_profit')->insertAll($temp);
|
|
|
+ $temp=[];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(empty($temp)==false) Db::name('company_platform_cat_profit')->insertAll($temp);
|
|
|
+ Db::commit();
|
|
|
+ $this->success("复制成功");
|
|
|
+ }catch (\Exception $exception)
|
|
|
+ {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($exception->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|