diff --git a/Application/Admin/Controller/SubSpendController.class.php b/Application/Admin/Controller/SubSpendController.class.php index 9f4cdb744..ca2127c1b 100644 --- a/Application/Admin/Controller/SubSpendController.class.php +++ b/Application/Admin/Controller/SubSpendController.class.php @@ -193,6 +193,8 @@ class SubSpendController extends ThinkController return $resarr; } + + public function addSubSpendSet(){ if(!isset($_REQUEST['time'])) $this->error("参数错误"); $time = $_REQUEST['time']; @@ -204,6 +206,13 @@ class SubSpendController extends ThinkController $this->ajaxReturn(["status"=>0,"info"=>"固化数据任务登记错误"]); } } + public function changeSubSpend(){ + if (IS_POST) { + $this->editSubSpend(); + }else{ + $this->showChooseSubSpendCount(); + } + } public function updateSubSpend(){ if(!isset($_REQUEST['begin']) || !isset($_REQUEST['end'])) $this->error("参数错误"); @@ -240,6 +249,75 @@ class SubSpendController extends ThinkController )); } + protected function editSubSpend(){ + if(!isset($_REQUEST['ids']) || !isset($_REQUEST['company_id']) ) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + $company_id = $_REQUEST['company_id']; + //获取会长及adminid + $promote = M("promote","tab_")->field("id,account,admin_id")->where("company_id = '{$company_id}' and level = '1' and status = '1'")->find(); + $saveData = [ + "promote_id"=>$promote['id'], + "promote_account"=>$promote['account'], + "market_admin_id"=>$promote['admin_id'], + ]; + $where = [ + "id"=>['in',$ids] + ]; + M("spend","tab_",SUBSITE_DB)->where($where)->save($saveData); + $this->ajaxReturn([ + 'status' => 1, + "info"=>"换绑成功" + ]); + + } + + + protected function showChooseSubSpendCount(){ + if(!isset($_REQUEST['ids'])) $this->error("参数错误"); + $ids = $_REQUEST['ids']; + + $dbres = M("spend","tab_",SUBSITE_DB)->where("id in ({$ids})")->group("promote_id")->getField("promote_id,SUM(pay_amount) pay_amount"); + //获取公司 + $promoteIds = implode(",",array_keys($dbres)); + $company = M("promote","tab_") + ->alias('p') + ->where("p.id in ({$promoteIds})") + ->join("tab_promote_company c on p.company_id = c.id","left") + ->group("p.company_id") + ->getField("company_id,group_concat(p.id) promote_ids,c.company_name"); + $sendData = [ + "count" => 0, + "list"=>[] + ]; + foreach ($company as $k => $v) { + $v['promote_ids'] = explode(",",$v['promote_ids']); + $v['pay_amount'] = 0; + foreach($v['promote_ids'] as $promote_id){ + $v['pay_amount'] += ($dbres[$promote_id]-0); + unset($dbres[$promote_id]); + } + unset($v['promote_ids'],$v['company_id']); + $sendData['count'] += $v['pay_amount']; + $sendData['list'][] = $v; + } + if(count($dbres) > 0){ + $office_pay_amount = 0; + foreach ($dbres as $value) { + $office_pay_amount += ($value-0); + } + $sendData['list'][]= ["company_name"=>DEFAULT_COMPANY,"pay_amount"=>$office_pay_amount]; + $sendData['count'] += $office_pay_amount; + } + //获取所有公司 + $promoteCompany = M('promote_company','tab_')->field('id, company_name as name')->where(['status' => 1])->select(); + + + $this->assign('promoteCompany', $promoteCompany); + $this->assign('data', $sendData); + $this->assign('ids', $ids); + $this->display("showChooseSubSpendCount"); + } + protected function editOrderIscheck($ids,$oldval,$newval){ $dbres = M("spend","tab_",SUBSITE_DB)->where("id in ({$ids}) and is_check = '{$oldval}'")->select(); if(empty($dbres)) return false; diff --git a/Application/Admin/View/SubSpend/lists.html b/Application/Admin/View/SubSpend/lists.html index abbcbdbd7..6889b78da 100644 --- a/Application/Admin/View/SubSpend/lists.html +++ b/Application/Admin/View/SubSpend/lists.html @@ -518,6 +518,18 @@ success:callback }); }, + oepnIframe(text){ + var url = "{:U('changeSubSpend')}"+"&ids="+text; + layer.open({ + type: 2, + title: "海南万盟天下科技有限公司", + shadeClose: true, + shade: 0.8, + area: ['40%', '60%'], + content: url + }); + // layer.closeAll("loading"); + }, mainEven(){ $("#addSubSpendSet").on("click",function() { SPENDOP.oepnHtml("新增固定订单","#addSubSpendTpl",SPENDOP.addSubSpendSetEvent); @@ -525,7 +537,22 @@ $("#updateSubSpend").on("click",function() { SPENDOP.oepnHtml("重新固定订单","#updateSubSpendTpl",SPENDOP.updateSubSpendEvent); }); - + $("#changeSubSpend").on("click",function() { + var ids= SPENDOP.getSelectIds(); + if(ids){ + SPENDOP.oepnIframe(ids); + } + }); + }, + getSelectIds(){ + var text = $("input:checkbox[name='ids[]']:checked").map(function(index,elem) { + return $(elem).val(); + }).get(); + if(text.length < 1){ + layer.msg("请先选择需要换绑的数据"); + return; + } + return text.join(","); }, addSubSpendSetEvent(){ $("#addSubSpendSubmit").off("click"); @@ -622,6 +649,9 @@ + + + + + + + + + + + + + + + + + + + + 说明:换绑后的数据将归属到选择的公司 + + + + + + + 选择下游公司: + + + + 请选择换绑公司 + + {$vo.name} + + + + + + + + 确认换绑 + + + + + + + + 所选订单统计: + + + + + + 公司 + 金额 + + + + + + + {$vo.company_name} + {$vo.pay_amount} + + + + 合计: + {$data['count']} + + + + + + + + +