model = model('Orders'); $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("stateList", $this->model->getStateList()); $finishtime ='0'; $aid = null; $this->assignconfig('searchFormVisibleStatus',1); // 此处为打款管理->渠道商查看详情->筛选参数 if(isset($_GET['t']) && $_GET['t'] != ''){ $t = date('Y-m-d',strtotime($_GET['t'])); $finishtime = $t.' 00:00:00 _ '.''.$t.' 23:59:59'; $aid = intval($_GET['aid']); $this->assignconfig('searchFormVisibleStatus',0); } $group = model('AuthGroupAccess')->where('uid',$this->auth->id)->find(); $truegroupId = $group->group_id; if(isset($_GET['channel_id']) && intval($_GET['channel_id'])>0){ $groupObj = model('AuthGroupAccess')->where('uid',$_GET['channel_id'])->find(); if($groupObj){ $thisGroup = $groupObj->group_id; if($thisGroup > 2){ //判断传过来的不是管理员的id if($thisGroup==3){ //如果是渠道商 if($truegroupId <3){ //只有管理员才有此操作 $this->authId = $_GET['channel_id']; $thisChannel = model('Admin')->where('id',$this->authId)->find(); $this->groupId = 3; $this->assign('channelTitle','当前是渠道商('.$thisChannel->nickname.')的数据'); $this->assignconfig('channelstr','?channel_id='.$this->authId); $pay = empty($this->request->get('pay'))? 0:intval($this->request->get('pay')); if(isset($_GET['ids'])){ $this->path = '/admin/orders/index?pay='.$pay.'&ids='.$_GET['ids'].'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&ids='.$_GET['ids']; }else{ $this->path = '/admin/orders/index?pay='.$pay.'&channel_id='.$this->authId.'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&channel_id='.$this->authId; } } }else{ if($truegroupId <4){ //管理员或渠道商才有此操作 if($truegroupId == 3){ //如果是从渠道商查来的,判断当前代理商是不是渠道商下属 $isCh = model('AdminExtend')->where(['admin_id'=>$_GET['channel_id'],'create_by'=>$group->uid])->find(); if($isCh){ //如果是当前渠道商的下属 $this->authId = $_GET['channel_id']; $thisChannel = model('Admin')->where('id',$this->authId)->find(); $this->groupId = 4; $this->assign('channelTitle','当前是代理商('.$thisChannel->nickname.')的数据'); $this->assignconfig('channelstr','?channel_id='.$this->authId); $pay = empty($this->request->get('pay'))? 0:intval($this->request->get('pay')); if(isset($_GET['ids'])){ $this->path = '/admin/orders/index?pay='.$pay.'&ids='.$_GET['ids'].'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&ids='.$_GET['ids']; }else{ $this->path = '/admin/orders/index?pay='.$pay.'&channel_id='.$this->authId.'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&channel_id='.$this->authId; } } }else{ //管理员查过来的 $this->authId = $_GET['channel_id']; $thisChannel = model('Admin')->where('id',$this->authId)->find(); $this->groupId = 4; $this->assign('channelTitle','当前是代理商('.$thisChannel->nickname.')的数据'); $this->assignconfig('channelstr','?channel_id='.$this->authId); $pay = empty($this->request->get('pay'))? 0:intval($this->request->get('pay')); if(isset($_GET['ids'])){ $this->path = '/admin/orders/index?pay='.$pay.'&ids='.$_GET['ids'].'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&ids='.$_GET['ids']; }else{ $this->path = '/admin/orders/index?pay='.$pay.'&channel_id='.$this->authId.'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&channel_id='.$this->authId; } } } } } } }else{ $this->authId = $this->auth->id; $this->groupId = $truegroupId; $pay = empty($this->request->get('pay'))? 0:intval($this->request->get('pay')); if(isset($_GET['ids'])){ $this->path = '/admin/orders/index?pay='.$pay.'&ids='.$_GET['ids'].'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?pay='.$pay.'&ids='.$_GET['ids']; }else{ $this->path = '/admin/orders/index?aid='.$aid.'&t='.$finishtime.'&pay='.$pay.'&ref=addtabs'; $this->exportPath = '/admin/orders/ordersexport?aid='.$aid.'&t='.$finishtime.'&pay='.$pay; } } if($this->request->has('mark') || $this->request->param('push_id') || $this->request->param('push_idx')){ $mark_lock['mark'] = $this->request->param('mark'); $mark_lock['push_id'] = $this->request->param('push_id'); $mark_lock['push_idx'] = $this->request->param('push_idx'); $this->path .= '&'.http_build_query($mark_lock); $this->exportPath .= '&'.http_build_query($mark_lock); } $this->assignconfig('orderpath',$this->path); $this->assignconfig('exportpath',$this->exportPath); } /** * 导出csv * @author 李聪聪 */ public function ordersexport(){ ini_set('memory_limit', '512M'); //内存限制 $filter = $this->request->get("filter", '{}'); $filter = json_decode($filter, true); if (array_key_exists('orders.createtime', $filter) || array_key_exists('createtime', $filter)) { $sort = 'orders.createtime'; //判断时间区间 if (isset($filter['orders.createtime'])) { $timeRange = explode(' - ',$filter['orders.createtime']); } else if (isset($filter['createtime'])) { $timeRange = explode(' - ',$filter['createtime']); } $stime = strtotime($timeRange[0]); $etime = strtotime($timeRange[1]); if (abs($etime-$stime) > (86400*31)) { $this->error("查询时间范围超过一个月", null, 13); } } //提现详情页筛选时间 $groupId = $this->groupId; //用户组 $condition_finishtime = []; if(isset($_GET['t']) & !empty($_GET['t']) ){ $time = explode('_',$_GET['t']); $condition_finishtime['orders.finishtime'] = array(array('egt',strtotime($time[0])),array('elt',strtotime($time[1]))); $conStr= intval($_GET['aid']);// 覆盖掉前面的admin_id //为管理员筛选渠道商订单详情 if($groupId==2){ $collect = model('AdminExtend')->where('create_by',$conStr)->field('admin_id')->select(); $condition['orders.admin_id'] = ''; if($collect){ foreach($collect as $val){ $search_id[]=$val->admin_id; } $search_id[]= $conStr; $condition['orders.admin_id'] = array('in',implode(',',$search_id)); }else{ $condition['orders.admin_id'] = array('in',$conStr); } } } $columns = [ '商户单号', '交易单号', '用户','用户关注时间','用户注册时间','类型','充值金额','支付状态','下单时间','完成时间','推广链接ID','推广链接渠道', '是否分账']; if (in_array($this->group, [ AdminConstants::ADMIN_SUPER_MANAGER_ID, AdminConstants::ADMIN_GROUP_ID_ADMIN, AdminConstants::ADMIN_GROUP_ID_SETTLEMENT, AdminConstants::ADMIN_GROUP_ID_CHANNEL, ] )) { array_push($columns,'书名'); } if (in_array($this->group, [ AdminConstants::ADMIN_SUPER_MANAGER_ID, AdminConstants::ADMIN_GROUP_ID_ADMIN, AdminConstants::ADMIN_GROUP_ID_CHANNEL, AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE, AdminConstants::ADMIN_GROUP_ID_SETTLEMENT, ])) { array_push($columns, '代理商'); } if (in_array($this->group, [ AdminConstants::ADMIN_SUPER_MANAGER_ID, AdminConstants::ADMIN_GROUP_ID_ADMIN, AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE, AdminConstants::ADMIN_GROUP_ID_SETTLEMENT, ])) { array_push($columns,'渠道商'); array_push($columns,'渠道商Id'); array_push($columns,'渠道商用户名'); } $pay = empty($this->request->get('pay'))? 0:intval($this->request->get('pay')); $condition = []; //条件数组 $condition_referral = []; //推广条件 $condition_referral_or = []; //推广条件 if(isset($_GET['ids'])){ $ids = $_GET['ids']; $condition_referral_or = function ($query) use ($ids) { $query->where('orders.referral_id', $ids) ->whereOr('orders.referral_id_permanent', $ids); return $query; }; $condition_referral['orders.resource_id'] = [['exp','is null'],['=',0],'or'];//资源id } $ext_var = ''; if ($this->request->has('mark') || $this->request->param('push_id') || $this->request->param('push_idx')) { $ext_var = "orders.ext != '' AND JSON_VALID(ext)"; if ($this->request->param('mark')) { $condition_referral['JSON_EXTRACT(`orders`.ext,"$.mark") + 0'] = (int)$this->request->param('mark'); } if ($this->request->param('push_id')) { $condition_referral['JSON_EXTRACT(`orders`.ext,"$.push_id") + 0'] = (int)$this->request->param('push_id'); } if ($this->request->param('push_idx')) { $condition_referral['JSON_EXTRACT(`orders`.ext,"$.push_idx") + 0'] = (int)$this->request->param('push_idx'); } } if($groupId==3){ //渠道商 $collect = model('AdminExtend')->where('create_by',$this->authId)->select(); $conStr = ''; if($collect){ foreach($collect as $val){ $conStr.=$val->admin_id.','; } $conStr .= $this->authId; }else{ $conStr = $this->authId; } }elseif($groupId==4){ //代理商 $condition['orders.admin_id'] = $this->authId; } //取代理商和渠道商的昵称 $channels = model('admin')->join('auth_group_access a','a.uid= admin.id')->where('a.group_id','>',2)->select(); $cNames = []; $qrImages = []; foreach ($channels as $channel) { if($channel->group_id == 3){ $cNames['channel'][$channel->id] = $channel->nickname; $qrImages[$channel['id']]['cusername'] = $channel['username']; }else{ $cNames['agent'][$channel->id] = $channel->nickname; } } //取渠道商的公众号二维码及admin_id $qrchannnels = model('admin_config')->join('auth_group_access a','a.uid = admin_config.admin_id')->where('a.group_id',3)->select(); foreach ($qrchannnels as $qrchannnel){ $qrImages[$qrchannnel['admin_id']]['qrimage'] = empty($qrchannnel['qrcode_image']) ? 'https://open.weixin.qq.com/qr/code?username='.$qrchannnel['json']['authorizer_info']['user_name'] : $qrchannnel['qrcode_image']; $qrImages[$qrchannnel['admin_id']]['cchannelid'] = $qrchannnel['admin_id']; } //取代理商和渠道商的对应关系 $extend = model('adminExtend')->alias('e')->field('e.admin_id,e.create_by')->join('auth_group_access a', 'a.uid= e.admin_id')->where('a.group_id', '>', 2)->select(); $agentBy = []; foreach ($extend as $key => $value) { $agentBy[$value['admin_id']] = $value['create_by']; } if($pay > 0){ if($pay == 1){ $condition['orders.state'] = '1'; }elseif($pay == 2){ $condition['orders.state'] = '0'; } } $orderId = 0; [$where, $sort, $order, $offset, $limit] = $this->buildparams(); // $sort = 'admin_id'; $limit = 2000; $data = []; mb_convert_variables('GBK', 'UTF-8', $columns); $data[] = $columns; if($groupId == 3){ $total = $this->model ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where('admin_id','in',$conStr) ->count(); $pages = ceil($total / $limit); for($i = 1; $i <= $pages; $i++) { $offset = 0; if ($i == 1){ $list = $this->model //->join('referral r', 'r.id=orders.referral_id', 'left') //->join('book b', 'orders.book_id = b.id', 'left') ->field('orders.*') ->force('index_admin_deduct_state') ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where('orders.admin_id', 'in', $conStr) ->order($sort, $order) ->limit($offset, $limit) ->select(); }else{ $list = $this->model //->join('referral r', 'r.id=orders.referral_id', 'left') //->join('book b', 'orders.book_id = b.id', 'left') ->field('orders.*') ->force('index_admin_deduct_state') ->where($where) ->where($ext_var) ->where('orders.id','<',$orderId) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where('orders.admin_id', 'in', $conStr) ->order($sort, $order) ->limit($offset, $limit) ->select(); } if ($list){ $this->getBookReferralInfo($list); } $endArr = end($list); $orderId = $endArr['id']; $result = $this->getUserData($list,$cNames,$qrImages,$agentBy); $data = array_merge($data, $result); } }else{ $total = $this->model ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where($condition) ->count(); $pages = ceil($total / $limit); for($i = 1; $i <= $pages; $i++) { $offset = 0; if ($i == 1){ $list = $this->model //->join('referral r', 'r.id=orders.referral_id', 'left')->join('book b', 'orders.book_id = b.id', 'left') ->field('orders.*') ->force('index_admin_deduct_state') ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where($condition) ->order($sort, $order) ->limit($offset, $limit) ->select(); }else{ $list = $this->model //->join('referral r', 'r.id=orders.referral_id', 'left')->join('book b', 'orders.book_id = b.id', 'left') ->field('orders.*') ->force('index_admin_deduct_state') ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where($condition) ->where('orders.id','<',$orderId) ->order($sort, $order) ->limit($offset, $limit) ->select(); } if ($list){ $this->getBookReferralInfo($list); } $endArr = end($list); $orderId = $endArr['id']; $result = $this->getUserData($list,$cNames,$qrImages,$agentBy); $data = array_merge($data, $result); } } $fileName = "导出订单数据-".date('YmdHis', time()).".csv"; // 头部标题 $content = ''; foreach ($data as $k => $v) { $content .= implode(',', $v) . PHP_EOL; } header('Expires: 0'); header('Content-Encoding: utf-8'); header("Content-type:text/csv; charset=utf-8"); Header("Accept-Length: " . strlen($content)); header("Content-Disposition:attachment;filename=" . $fileName); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Pragma:public'); echo $content;exit; } private function getBookReferralInfo(&$list) { $bookIds = array_unique( array_column($list,'book_id') ); $booksInfo = []; $referralInfo = []; if ($bookIds){ $booksInfo = model('book')->getBooksInfo($bookIds); } $referralIds = array_unique(array_column($list,'referral_id')); if ($referralIds){ $referralInfo = model("Referral")->field('id,name,admin_id')->where('id', 'in', $referralIds)->select(); $referralInfo = ArrayHelper::index($referralInfo, 'id'); } foreach($list as $k => &$v){ $v['pdqd'] = isset($referralInfo[$v['referral_id']])?$referralInfo[$v['referral_id']]['name']:''; $v['radmin_id'] = isset($referralInfo[$v['referral_id']])?$referralInfo[$v['referral_id']]['admin_id']:1; $v['bookname'] = isset($booksInfo[$v['book_id']])?$booksInfo[$v['book_id']]['name']:''; } } /** * @param $fp * @param $list * @param null $agentBy * @author 李聪聪 */ public function getUserData($list,$cNames=null,$qrImages=null,$agentBy=null){ //支付状态 $payStatus = ['0'=>'未支付','1'=>'已支付']; $orderIds = array_column($list, 'out_trade_no'); $splitRows = model("PalmpaySplitAccountLog")->field('order_id')->where('order_id', 'in', $orderIds)->where('channel_amount', '>', 0)->select(); if ($splitRows) { $splitRows = ArrayHelper::index($splitRows, 'order_id'); } $mUser = model('user'); $result = []; foreach ($list as $k => $v) { $newUser = $mUser->setConnect($v['user_id']) ->where(['id'=>$v['user_id']]) ->field('id,channel_id,nickname,createtime,avatar,subscribe_time') ->select(); if($newUser){ $aUser = $newUser[0]->getData(); unset($newUser); if(empty($cNames['agent'][$v['admin_id']])){ $aUser['agent_id'] = '无'; if(empty($cNames['channel'][$v['admin_id']])){ $aUser['channel_id'] = ''; }else{ $aUser['channel_id'] = $cNames['channel'][$v['admin_id']]; } //二维码图片 if(empty($qrImages[$v['admin_id']])){ $aUser['qrimage'] = ''; $aUser['cusername'] = ''; $aUser['cchannelid'] = ''; }else{ $aUser['qrimage'] = empty($qrImages[$v['admin_id']]['qrimage']) ? '':$qrImages[$v['admin_id']]['qrimage']; $aUser['cusername'] = empty($qrImages[$v['admin_id']]['cusername'])?'':$qrImages[$v['admin_id']]['cusername']; $aUser['cchannelid'] = empty($qrImages[$v['admin_id']]['cchannelid'])?'':$qrImages[$v['admin_id']]['cchannelid']; } }else{ $aUser['agent_id'] = $cNames['agent'][$v['admin_id']]; $aUser['channel_id'] = $cNames['channel'][$agentBy[$v['admin_id']]]; if(empty($qrImages[$agentBy[$v['admin_id']]])){ $aUser['qrimage'] = ''; $aUser['cusername'] = ''; $aUser['cchannelid'] = ''; }else{ $aUser['cusername'] = empty($qrImages[$agentBy[$v['admin_id']]]['cusername'])? '':$qrImages[$agentBy[$v['admin_id']]]['cusername']; $aUser['cchannelid'] = empty($qrImages[$agentBy[$v['admin_id']]]['cchannelid']) ? '':$qrImages[$agentBy[$v['admin_id']]]['cchannelid']; $aUser['qrimage'] = empty($qrImages[$agentBy[$v['admin_id']]]['qrimage'])? '': $qrImages[$agentBy[$v['admin_id']]]['qrimage']; } } //获取每列数据,转换处理成需要导出的数据 $groupId = $this->groupId; //用户组 //是否分账 $split = '否'; if ($splitRows && isset($splitRows[$v['out_trade_no']])) { $split = '是'; } // '\t' 可以解决科学技术法问题 $rowData = [ '"'.$v['out_trade_no'].'"', empty($v['transaction_id'])?"无":"\t".$v['transaction_id']."\t", str_replace(["\n", "\t", ","], ["", "", ""], $aUser['nickname']."({$v['user_id']})"), $aUser['subscribe_time'] ? date('Y-m-d H:i:s', $aUser['subscribe_time']) : '-', date('Y-m-d H:i:s',$aUser['createtime']), $v['type_text'], $v['money'], $payStatus[$v['state']], date('Y-m-d H:i:s',$v['createtime']), empty($v['finishtime'])?'无':date('Y-m-d H:i:s',$v['finishtime']), $v['referral_id'], $v['pdqd'], $split, ]; if (in_array($groupId, [ AdminConstants::ADMIN_SUPER_MANAGER_ID, AdminConstants::ADMIN_GROUP_ID_ADMIN, AdminConstants::ADMIN_GROUP_ID_SETTLEMENT, AdminConstants::ADMIN_GROUP_ID_CHANNEL, ])) { array_push($rowData, $v['bookname']); } if (in_array($this->group, [ AdminConstants::ADMIN_SUPER_MANAGER_ID, AdminConstants::ADMIN_GROUP_ID_ADMIN, AdminConstants::ADMIN_GROUP_ID_CHANNEL, AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE, AdminConstants::ADMIN_GROUP_ID_SETTLEMENT, ])) { array_push($rowData,$aUser['agent_id'] ?? '无'); } if (in_array($this->group, [ AdminConstants::ADMIN_SUPER_MANAGER_ID, AdminConstants::ADMIN_GROUP_ID_ADMIN, AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE, AdminConstants::ADMIN_GROUP_ID_SETTLEMENT, ])) { array_push($rowData,$aUser['channel_id'] ?? ''); array_push($rowData,$aUser['cchannelid'] ?? ''); array_push($rowData,$aUser['cusername'] ?? ''); } //需要格式转换,否则会乱码 mb_convert_variables('GBK', 'UTF-8', $rowData); // fputcsv($fp, $rowData); $result[] = $rowData; unset($rowData); } } unset($list); unset($mUser); unset($splitRows); unset($cNames); unset($qrImages); unset($agentBy); return $result; } /** * 查单 */ public function searchorder(){ header("Cache-control:private"); if($this->request->isPost()){ $oid = $this->request->post('oid'); $patten = array("\r\n", "\n", "\r"); if(empty($oid)){ $this->error('请填写数据'); } $oid = str_replace($patten,',',$oid); $oidArr = explode(',',$oid); foreach ($oidArr as $key=>$val){ $oidArr[$key] = trim($val); if(empty($val)){ unset($oidArr[$key]); } } $orderRes = collection(model('Orders')->where('transaction_id','in',$oidArr)->select())->toArray(); $wxpayList = OfficialAccountsService::instance()->getWxpayModel()->column("id,mcid,quartet_merchant_id"); $wxpay = []; foreach($wxpayList as $item){ $wxpay[$item['id']] = $item; } $res = []; if ($orderRes) { foreach ($orderRes as $val) { if (array_key_exists($val['wxpay_id'], $wxpay)) { $val['mcid'] = $wxpay[$val['wxpay_id']]['mcid']; if (array_key_exists($val['payment_method'], ApiConstants::$allPaymentMethods)) { $val['payinfo'] = ApiConstants::$allPaymentMethods[$val['payment_method']]; } else { $val['payinfo'] = '微信支付 '; } if ($val['payment_method'] != ApiConstants::PAYMENT_METHOD_WECHAT) { $val['mcid'] = $wxpay[$val['wxpay_id']]['quartet_merchant_id']; } } else { $val['mcid'] = ''; $val['payinfo'] = ''; } array_push($res, $val); } } if (count($res) !== count($oidArr)){ $tranArr = array_column($res, 'transaction_id'); $arrDiff = array_diff($oidArr,$tranArr); foreach ($arrDiff as $val){ array_push($res,['transaction_id'=>$val,'user_id'=>'未查到','wxpay_id'=>'未查到','mcid'=>'未查到','payinfo'=>'未查到']); } } $this->assign('res',$res); }else{ $this->assign('res',''); } return $this->view->fetch(); } /** * 查看 */ public function index() { ini_set('memory_limit', '256M'); //内存限制 //当前是否为关联查询 $this->relationSearch = true; $pay = empty($this->request->get('pay'))? 0:intval($this->request->get('pay')); $groupId = $this->groupId; //用户组 $condition = []; //条件数组 $condition_referral_or = $condition_referral = []; //推广条件 if(isset($_GET['ids'])){ $ids = $_GET['ids']; // $condition_referral['orders.referral_id'] = $_GET['ids'];//推广id $condition_referral['orders.resource_id'] = [['exp','is null'],['=',0],'or'];//资源id $condition_referral_or = function ($query) use ($ids) { $query->where('orders.referral_id', $ids) ->whereOr('orders.referral_id_permanent', $ids); return $query; }; } if($groupId==3){ //渠道商 $collect = model('AdminExtend')->where('create_by',$this->authId)->select(); $conStr = ''; if($collect){ foreach($collect as $val){ $conStr.=$val->admin_id.','; } $conStr .= $this->authId; }else{ $conStr = $this->authId; } }elseif($groupId==4){ //代理商 $condition['orders.admin_id'] = $this->authId; } if ($this->request->isAjax()) { $ext_var = ''; if ($this->request->has('mark') || $this->request->param('push_id') || $this->request->param('push_idx')) { $ext_var = "orders.ext != '' AND JSON_VALID(ext)"; if ($this->request->param('mark')) { $condition_referral['JSON_EXTRACT(`orders`.ext,"$.mark") + 0'] = (int)$this->request->param('mark'); } if ($this->request->param('push_id')) { $condition_referral['JSON_EXTRACT(`orders`.ext,"$.push_id") + 0'] = (int)$this->request->param('push_id'); } if ($this->request->param('push_idx')) { $condition_referral['JSON_EXTRACT(`orders`.ext,"$.push_idx") + 0'] = (int)$this->request->param('push_idx'); } } if($pay > 0){ if($pay == 1){ $condition['orders.state'] = '1'; }elseif($pay == 2){ $condition['orders.state'] = '0'; } } //提现详情页筛选时间 $condition_finishtime = []; if(isset($_GET['t']) & !empty($_GET['t']) ){ $time = explode('_',$_GET['t']); $condition_finishtime['orders.finishtime'] = array(array('egt',strtotime($time[0])),array('elt',strtotime($time[1]))); if (abs(strtotime($time[1])-strtotime($time[0])) > (86400*31)) { $this->error("查询时间范围超过一个月", null, 13); } $conStr= intval($_GET['aid']);// 覆盖掉前面的admin_id //为管理员筛选渠道商订单详情 if($groupId==2){ $collect = model('AdminExtend')->where('create_by',$conStr)->field('admin_id')->select(); $condition['orders.admin_id'] = ''; if($collect){ foreach($collect as $val){ $search_id[]=$val->admin_id; } $search_id[]= $conStr; $condition['orders.admin_id'] = array('in',implode(',',$search_id)); }else{ $condition['orders.admin_id'] = array('in',$conStr); } } } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $limit = 10; $filter = $this->request->get("filter", '{}'); $filter = json_decode($filter, true); if (array_key_exists('orders.createtime', $filter) || array_key_exists('createtime', $filter)) { //判断时间区间 if (isset($filter['orders.createtime'])) { $timeRange = explode(' - ',$filter['orders.createtime']); } else if (isset($filter['createtime'])) { $timeRange = explode(' - ',$filter['createtime']); } $stime = strtotime($timeRange[0]); $etime = strtotime($timeRange[1]); if (abs($etime-$stime) > (86400*31)) { $this->error("查询时间范围超过一个月", null, 13); } } if (in_array($groupId, [AdminConstants::ADMIN_GROUP_ID_CHANNEL, AdminConstants::ADMIN_GROUP_ID_AGENT])){ $sort = 'orders.updatetime'; } else { if ($filter) { $sort = 'orders.updatetime'; } else { $sort = 'orders.createtime'; } } $order = 'desc'; if($groupId ==3){ $total = $this->model ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where('admin_id','in',$conStr) ->count(); $list = $this->model ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where('orders.admin_id','in',$conStr) ->order($sort, $order) ->limit($offset, $limit) ->select(); }else{ $total = $this->model ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where($condition) ->count(); $list = $this->model ->where($where) ->where($ext_var) ->where($condition_referral) ->where($condition_referral_or) ->where($condition_finishtime) ->where($condition) ->order($sort, $order) ->limit($offset, $limit) ->select(); } $referralRows = []; $booksInfo = []; if ($list) { $referralIds = array_column($list, 'referral_id'); $preferralIds = array_column($list, 'referral_id_permanent'); $referralIds = array_unique(array_merge($referralIds, $preferralIds)); if ($referralIds) { $referralRows = model("Referral")->field('id,name,admin_id')->where('id', 'in', $referralIds)->select(); $referralRows = ArrayHelper::index($referralRows, 'id'); } $bookIds = array_column($list, 'book_id'); $bookIds = array_filter($bookIds); if (!empty($bookIds)) { $booksInfo = model('book')->getBooksInfo($bookIds); } $adminIds = array_column($list, 'admin_id'); $agentRef = AdminService::instance()->getAdminExtendModel() ->alias('a') ->whereIn('admin_id', $adminIds) ->join('auth_group_access aga', 'aga.uid = a.create_by') ->where('aga.group_id', AdminConstants::ADMIN_GROUP_ID_CHANNEL) ->column('a.admin_id,a.create_by'); $agentIds = array_keys($agentRef); $channelIds = array_merge(array_diff($adminIds, $agentIds), array_values($agentRef)); $channelList = AdminService::instance()->getAdminConfigModel() ->alias('ac') ->join('admin a','a.id=admin_config.admin_id', 'RIGHT') ->whereIn('a.id', array_merge($agentIds, $channelIds)) ->field('a.id,ac.json,a.nickname,a.username') ->select(); $cNames = []; foreach ($channelList as $adminInfo) { if (in_array($adminInfo['id'], $channelIds)) { if ($adminInfo['qrcode_image']) { $qrImages[$adminInfo['id']]['qrimage'] = $adminInfo['qrcode_image']; } elseif ($adminInfo['json']['authorizer_info']['user_name']) { $qrImages[$adminInfo['id']]['qrimage'] = 'https://open.weixin.qq.com/qr/code?username=' . $adminInfo['json']['authorizer_info']['user_name']; } else { $qrImages[$adminInfo['id']]['qrimage'] = ''; } $qrImages[$adminInfo['id']]['cchannelid'] = $adminInfo['id']; $qrImages[$adminInfo['id']]['cusername'] = $adminInfo['username']; } $cNames[$adminInfo['id']] = $adminInfo['nickname']; } } foreach ($list as $k => &$v) { unset($v['deduct']); $user = model('user') ->setConnect($v['user_id']) ->where(['id'=>$v['user_id']]) ->field('id,channel_id,nickname,createtime,avatar,subscribe_time') ->select(); if ($user) { $user = $user[0]; } if(in_array($v['admin_id'], $channelIds)){ $user['agent_id'] = '无'; $user['channel_id'] = $cNames[$v['admin_id']]; //二维码图片 if(empty($qrImages[$v['admin_id']])){ $user['qrimage'] = ''; $user['cusername'] = ''; $user['cchannelid'] = ''; }else{ $user['qrimage'] = empty($qrImages[$v['admin_id']]['qrimage']) ? '':$qrImages[$v['admin_id']]['qrimage']; $user['cusername'] = empty($qrImages[$v['admin_id']]['cusername'])?'':$qrImages[$v['admin_id']]['cusername']; $user['cchannelid'] = empty($qrImages[$v['admin_id']]['cchannelid'])?'':$qrImages[$v['admin_id']]['cchannelid']; } }else{ $user['agent_id'] = $cNames[$v['admin_id']]; $channelId = $agentRef[$v['admin_id']]; $user['channel_id'] = $cNames[$channelId]; if(empty($qrImages[$channelId])){ $user['qrimage'] = ''; $user['cusername'] = ''; $user['cchannelid'] = ''; }else{ $user['cusername'] = empty($qrImages[$channelId]['cusername'])? '':$qrImages[$channelId]['cusername']; $user['cchannelid'] = empty($qrImages[$channelId]['cchannelid']) ? '':$qrImages[$channelId]['cchannelid']; $user['qrimage'] = empty($qrImages[$channelId]['qrimage'])? '': $qrImages[$channelId]['qrimage']; } } $v['user'] = $user; //组装推广链接信息 if ($v['referral_id'] && isset($referralRows[$v['referral_id']])) { $v['pdqd'] = $referralRows[$v['referral_id']]['name']; $v['radmin_id'] = $referralRows[$v['referral_id']]['admin_id']; } elseif ($v['referral_id_permanent'] && $referralRows[$v['referral_id_permanent']]) { $v['pdqd'] = $referralRows[$v['referral_id_permanent']]['name']; $v['radmin_id'] = $referralRows[$v['referral_id_permanent']]['admin_id']; } else { $v['pdqd'] = null; $v['radmin_id'] = null; } //组装书籍名称 if ($v['book_id'] && isset($booksInfo[$v['book_id']])) { $v['bookname'] = $booksInfo[$v['book_id']]['name']; } else { $v['bookname'] = ''; } } unset($v); $result = array("total" => $total, "rows" => $list); return json($result); } $this->view->assign('pay',$pay); $isShowBusinessLine = true; if (in_array($this->group, [3, 4, 7, 8])) { $isShowBusinessLine = false; if (AppGuideService::instance()->isShowAdminMenu($this->auth->id)) { $isShowBusinessLine = true; } } $this->assignconfig('isShowBusinessLine', $isShowBusinessLine); return $this->view->fetch(); } //管理员查kl单 public function klorder(){ if ($this->request->isAjax()) { [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $total = $this->model ->where($where) ->where('deduct', 1) ->count(); $list = $this->model ->where($where) ->where('deduct', 1) ->order('id desc') ->limit($offset, $limit) ->select(); foreach ($list as $k => &$v) { $adminData = model('Admin')->field('nickname')->where(['id' => $v['admin_id']]) ->find() -> toarray(); $v['cnickname'] = $adminData['nickname'] ?? ''; $v['user'] = model('user')->setConnect($v['user_id'])->where(['id'=>$v['user_id']])->find(); } $result = array("total" => $total, "rows" => $list); return json($result); } $this->assignconfig('orderType',1); return $this->fetch(); } }