You've already forked qlg.tsgz.moe
							
							
		
			
				
	
	
		
			804 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			804 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
| <?php
 | |
| 
 | |
| namespace wstmart\admin\model;
 | |
| 
 | |
| use think\Db;
 | |
| 
 | |
| use think\Loader;
 | |
| 
 | |
| /**
 | |
| 
 | |
|  * ============================================================================
 | |
| 
 | |
|  * 提现分类业务处理
 | |
| 
 | |
|  */
 | |
| 
 | |
| class CashDraws extends Base{
 | |
| 
 | |
| 	/**
 | |
| 
 | |
| 	 * 分页
 | |
| 
 | |
| 	 */
 | |
| 
 | |
| 	public function pageQuery(){
 | |
| 
 | |
| 		$targetType = input('targetType',-1);
 | |
| 
 | |
| 		$cashNo = input('cashNo');
 | |
| 
 | |
| 		$cashSatus = input('cashSatus',-1);
 | |
| 
 | |
|         $where = [];
 | |
| 
 | |
|         if(in_array($targetType,[0,1]))$where['targetType'] = $targetType;
 | |
| 
 | |
|         if(in_array($cashSatus,[0,1]))$where['cashSatus'] = $cashSatus;
 | |
| 
 | |
|         if($cashNo!='')$where['cashNo'] = ['like','%'.$cashNo.'%'];
 | |
| 
 | |
|        
 | |
| 
 | |
| 		$sort = input('sort');
 | |
| 
 | |
| 		$order = [];
 | |
| 
 | |
| 		if($sort!=''){
 | |
| 
 | |
| 			$sortArr = explode('.',$sort);
 | |
| 
 | |
| 			$order = $sortArr[0].' '.$sortArr[1];
 | |
| 
 | |
| 			if($sortArr[0]=='cashNo'){
 | |
| 
 | |
| 				$order = $sortArr[0].'+0 '.$sortArr[1];
 | |
| 
 | |
| 			}
 | |
| 
 | |
| 		}
 | |
| 
 | |
| 		//mark by cheng 只显示超过一天的提现数据
 | |
| 
 | |
|         //$page = $this->where($where)->whereTime('createTime','<=', date('Y-m-d'))->order($order)->order('createTime desc')->paginate(input('limit/d'))->toArray();
 | |
|         $page = $this->where($where)->order($order)->order('createTime desc')->paginate(input('limit/d'))->toArray();
 | |
| 
 | |
| 	    if(count($page['Rows'])>0){
 | |
| 
 | |
| 	    	$userIds = [];
 | |
| 
 | |
| 	    	$shopIds = [];
 | |
| 
 | |
| 	    	foreach ($page['Rows'] as $key => $v) {
 | |
| 
 | |
| 	    		if($v['targetType']==0)$userIds[] = $v['targetId'];
 | |
| 
 | |
| 	    		if($v['targetType']==1)$shopIds[] = $v['targetId'];
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    	$userMap = [];
 | |
| 
 | |
| 	    	if(count($userIds)>0){
 | |
| 
 | |
| 	    		$user = Db::name('users')->where(['userId'=>['in',$userIds]])->field('userId,loginName,userName')->select();
 | |
| 
 | |
| 	    	    foreach ($user as $key => $v) {
 | |
| 
 | |
| 	    	    	$userMap["0_".$v['userId']] = $v; 
 | |
| 
 | |
| 	    	    }
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    	if(count($shopIds)>0){
 | |
| 
 | |
| 	    		$user = Db::name('shops')->alias('s')
 | |
| 
 | |
| 	    		          ->join('__USERS__ u','u.userId=s.userId')
 | |
| 
 | |
| 	    		          ->where(['shopId'=>['in',$shopIds]])
 | |
| 
 | |
| 	    		          ->field('s.shopId,u.loginName,s.shopName as userName')
 | |
| 
 | |
| 	    		          ->select();
 | |
| 
 | |
| 	    	    foreach ($user as $key => $v) {
 | |
| 
 | |
| 	    	    	$userMap["1_".$v['shopId']] = $v; 
 | |
| 
 | |
| 	    	    }
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    	foreach ($page['Rows'] as $key => $v) {
 | |
| 
 | |
| 	    		$page['Rows'][$key]['loginName'] = $userMap[$v['targetType']."_".$v['targetId']]['loginName'];
 | |
| 
 | |
| 	    		$page['Rows'][$key]['userName'] = $userMap[$v['targetType']."_".$v['targetId']]['userName'];
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    }
 | |
| 
 | |
| 	    return $page;
 | |
| 
 | |
| 	}
 | |
|     /**
 | |
|      * 查看报表
 | |
|      * @return [type] [description]
 | |
|      */
 | |
|     public function viewReport($date,$isSave=0){
 | |
| 
 | |
|         $orders['list'] = Db::name('orders')
 | |
|         	->where('orderStatus=2 AND dataFlag=1')
 | |
|     		->whereTime('receiveTime',[$date,date('Y-m-d',strtotime('+1 day',strtotime($date)))])
 | |
|     		->field('orderId,shopId,userId,productTaxFee,productHandlingFee,couponsHandlingFee,couponsTaxFee,realTotalMoney,receiveTime,payable')
 | |
|     		->select();
 | |
|     		//dump(Db::getlastsql());
 | |
| 		$discountMoney = 0;
 | |
|         $m = Model('common/Table');
 | |
|         $orders['allPaySum']=0;//消费总额
 | |
|         $orders['coupousEarningsSum'] = 0;//优惠款总收益
 | |
|         $orders['hasVouchersEearningsSum'] = 0;//已获券总收益        
 | |
| 		$orders['taxFeeSum'] = 0;//税费总收益
 | |
| 		$orders['collectionPaySum']=0;//公司需付商家,即商家已获旺旺券总额
 | |
|     	$orders['collectionGatheringSum']=0;//商家需付公司总额
 | |
|     	$orders['collection']=[];
 | |
|     	$orders['yesterdayMoney']=0;    	
 | |
|     	$orders['todayMoney']=0;
 | |
|     	$m->setTable('log_day_money');
 | |
|     	$orders['yesterdayMoney'] = $m->getSum('setTime < '.strtotime($date),'money');   
 | |
|     	foreach ($orders['list'] as &$v) {
 | |
|     		$orders['allPaySum'] += $v['realTotalMoney'];
 | |
|         	$m->setTable('order_goods');
 | |
|     		$orderGoodsList = $m->getList(['orderId'=>$v['orderId']],'goodsPrice,goodsNum,freight,discountRate');
 | |
| 	        $discountMoney = 0;//优惠款
 | |
| 	        foreach ($orderGoodsList as &$val) {
 | |
| 	            $discountMoney += ($val['goodsPrice']*$val['goodsNum'] + $val['freight']) * ($val['discountRate']*0.01);//优惠款
 | |
| 	        }
 | |
| 	        $v['discountMoney'] = $discountMoney;	        		
 | |
|     		$v['coupousEarnings'] = $discountMoney * 0.1;//优惠款收益 
 | |
|     		$orders['coupousEarningsSum']+=$v['coupousEarnings'];
 | |
| 
 | |
|     		$v['hasVouchersEearnings'] = $v['productHandlingFee'] + $v['couponsHandlingFee'];//已获券收益
 | |
|     		$orders['hasVouchersEearningsSum']+=$v['hasVouchersEearnings'];
 | |
| 
 | |
|     		$v['taxFee'] =	$v['productTaxFee']+$v['couponsTaxFee'];//税费
 | |
| 			$orders['taxFeeSum']+=$v['taxFee'];
 | |
| 
 | |
|     		$m->setTable('shops');
 | |
|     		$shopUserId = $m->getField(['shopId'=>$v['shopId']],'userId');
 | |
|     		$m->setTable('users');
 | |
|     		$v['loginName'] = $m->getField(['userId'=>$v['userId']],'loginName');
 | |
|     		$v['shopLoginName'] = $m->getField(['userId'=>$shopUserId],'loginName');
 | |
| //    		if(!isset($orders['collection'][$shopUserId]['gathering'])) $orders['collection'][$shopUserId]['gathering']=0;
 | |
| //    		if(!isset($orders['collection'][$shopUserId]['pay'])) $orders['collection'][$shopUserId]['pay']=0;
 | |
| //    		$orders['collection'][$shopUserId]['shopLoginName'] = $v['shopLoginName'];
 | |
| //
 | |
| //    		if($v['payable']>0){
 | |
| //				//公司需付商家,即提现
 | |
| //				$orders['collection'][$shopUserId]['pay']+=$v['payable'];//代付款
 | |
| //    			$orders['collectionPaySum'] += $v['payable'];
 | |
| //    		}else{
 | |
| //    			//商家需付公司
 | |
| //    			$orders['collection'][$shopUserId]['gathering'] += abs($v['payable']);//代收款
 | |
| //    			$orders['collectionGatheringSum'] += abs($v['payable']);
 | |
| //    		}
 | |
|     	}
 | |
|     	$data = Db::name('cash_draws')->whereIn('cashId',
 | |
|             Db::name('log_moneys')
 | |
|                 ->whereTime('createTime',[$date,date('Y-m-d',strtotime('+1 day',strtotime($date)))])
 | |
|                 ->where('dataSrc', '=', 3)->column('dataId')
 | |
|         )->select();
 | |
|     	foreach ($data as $item){
 | |
|             $m->setTable('shops');
 | |
|             $shopUserId = $m->getField(['shopId'=>$item['targetId']],'userId');
 | |
|             $m->setTable('users');
 | |
|             $name = $m->getField(['userId'=>$shopUserId],'loginName');
 | |
|             if(!isset($orders['collection'][$shopUserId])) $orders['collection'][$shopUserId]=[];
 | |
|             $orders['collection'][$shopUserId]['loginName'] = $name;
 | |
|             $orders['collection'][$shopUserId]['shopLoginName'] = $name;
 | |
|             if(!isset($orders['collection'][$shopUserId]['gathering'])) $orders['collection'][$shopUserId]['gathering']=0;
 | |
|             if(!isset($orders['collection'][$shopUserId]['pay'])) $orders['collection'][$shopUserId]['pay']=0;
 | |
|             $orders['collection'][$shopUserId]['pay']+=$item['money'];//代付款
 | |
|             $orders['collectionPaySum'] += $item['money'];
 | |
|         }
 | |
|     	$data = Db::name('order_shop_certificate')->whereTime('createTime',[$date,date('Y-m-d',strtotime('+1 day',strtotime($date)))])
 | |
|             ->select();
 | |
|     	foreach ($data as $item) {
 | |
|             $m->setTable('users');
 | |
|             $name = $m->getField(['userId'=>$item['userId']],'loginName');
 | |
|             if(!isset($orders['collection'][$item['userId']])) $orders['collection'][$item['userId']]=[];
 | |
|             $orders['collection'][$item['userId']]['loginName'] = $name;
 | |
|             $orders['collection'][$item['userId']]['shopLoginName'] = $name;
 | |
|             if(!isset($orders['collection'][$item['userId']]['gathering'])) $orders['collection'][$item['userId']]['gathering']=0;
 | |
|             if(!isset($orders['collection'][$item['userId']]['pay'])) $orders['collection'][$item['userId']]['pay']=0;
 | |
|             $sum = Db::name('orders')->whereIn('orderId', $item['orderIds'])->sum('abs(`payable`)');
 | |
|             $orders['collection'][$item['userId']]['gathering'] += $sum;//代收款
 | |
|             $orders['collectionGatheringSum'] += $sum;
 | |
|         }
 | |
|     	$allMoney =  $orders['collectionGatheringSum']-($orders['coupousEarningsSum']+$orders['hasVouchersEearningsSum']+$orders['taxFeeSum']+$orders['collectionPaySum']);
 | |
|     	$orders['todayMoney'] = $orders['yesterdayMoney'] + $allMoney;
 | |
|     	if(1 == $isSave && $allMoney != 0){
 | |
|     		$data['money'] = $allMoney;//充值/扣除数量       
 | |
| 	        if($allMoney >= 0 ){
 | |
| 	            $reTypeName = '充值';            
 | |
| 	        }else{
 | |
| 	            $reTypeName = '扣除';
 | |
| 	        }
 | |
| 	        $data['adminId'] = 0;
 | |
| 	        $data['logContent'] = '系统'.$reTypeName;
 | |
| 	        $data['setTime'] = time();
 | |
| 	        $data['createTime'] = time();
 | |
| 	        $m->setTable('log_day_money');
 | |
| 	        $m->insertInfo($data);
 | |
| 	        echo $allMoney;
 | |
| 	        return true;
 | |
| 	    }
 | |
|     	//$orders['collection'] = Db::name('orders')->where();
 | |
|     	return $orders;
 | |
|     }
 | |
| 	/**
 | |
| 
 | |
| 	 * 获取提现详情
 | |
| 
 | |
| 	 */
 | |
| 
 | |
| 	public function getById(){
 | |
| 
 | |
| 		$id = (int)input('id');
 | |
| 
 | |
| 		$rs =  $this->get($id);
 | |
| 
 | |
| 		$user = [];
 | |
| 
 | |
| 		if($rs['targetType']==1){
 | |
| 
 | |
| 			$user = Db::name('shops')->alias('s')
 | |
| 
 | |
| 	    		      ->join('__USERS__ u','u.userId=s.userId')
 | |
| 
 | |
| 	    		      ->where('shopId',$rs['targetId'])
 | |
| 
 | |
| 	    		      ->field('s.shopId,u.loginName,s.shopName as userName')
 | |
| 
 | |
| 	    		      ->find();
 | |
| 
 | |
|             
 | |
| 
 | |
| 		}else{
 | |
| 
 | |
| 			$user = Db::name('users')->where('userId',$rs['targetId'])->field('userId,loginName,userName')->find();   
 | |
| 
 | |
| 		}
 | |
| 
 | |
| 		$rs['userName'] = $user['userName'];
 | |
| 
 | |
|         $rs['loginName'] = $user['loginName'];
 | |
| 
 | |
| 		return $rs;
 | |
| 
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 
 | |
| 	/**
 | |
| 
 | |
| 	 * 处理提现成功
 | |
| 
 | |
| 	 */
 | |
| 
 | |
| 	public function handle(){
 | |
| 
 | |
| 		$id = (int)input('cashId');
 | |
| 
 | |
| 		$cash = $this->get($id);
 | |
| 
 | |
| 		if(empty($cash))return WSTReturn('无效的提现申请记录');
 | |
| 
 | |
| 		Db::startTrans();
 | |
| 
 | |
| 		try{
 | |
| 
 | |
| 			
 | |
| 
 | |
|             if($cash->targetType==0){
 | |
| 
 | |
| 		        $user = model('users')->get($cash->targetId);
 | |
| 
 | |
| 				// if($user->lockMoney<$cash->money)return WSTReturn('操作失败,被冻结的金额小于提现金额');
 | |
| 
 | |
| 				// $user->lockMoney = $user->lockMoney-$cash->money;
 | |
| 
 | |
|     //         	$user->save();
 | |
| 
 | |
|             	$targetId = $user->userId;
 | |
| 
 | |
|             }else{
 | |
| 
 | |
|                 $shop = model('shops')->get($cash->targetId);
 | |
| 
 | |
| 				// if($shop->lockMoney<$cash->money)return WSTReturn('操作失败,被冻结的金额小于提现金额');
 | |
| 
 | |
|     //             $shop->lockMoney = $shop->lockMoney-$cash->money;
 | |
| 
 | |
|     //         	$shop->save();
 | |
| 
 | |
|             	$targetId = $shop->userId;
 | |
| 
 | |
|             }
 | |
| 
 | |
|             $cash->cashSatus = 1;
 | |
| 
 | |
|             $cash->cashRemarks = input('cashRemarks');
 | |
| 
 | |
|             $result = $cash->save();
 | |
| 
 | |
| 
 | |
| 
 | |
|             if(false != $result){
 | |
| 
 | |
|             	//创建一条流水记录
 | |
| 
 | |
|             	$lm = [];
 | |
| 
 | |
| 				$lm['targetType'] = $cash->targetType;
 | |
| 
 | |
| 				$lm['targetId'] = $targetId;
 | |
| 
 | |
| 				$lm['dataId'] = $id;
 | |
| 
 | |
| 				$lm['dataSrc'] = 3;
 | |
| 
 | |
| 				$lm['remark'] = '提现申请单【'.$cash->cashNo.'】申请提现¥'.$cash->money.'。'.(($cash->cashRemarks!='')?"【操作备注】:".$cash->cashRemarks:'');
 | |
| 
 | |
| 				$lm['moneyType'] = 0;
 | |
| 
 | |
| 				$lm['money'] = $cash->money;
 | |
| 
 | |
| 				$lm['payType'] = 0;
 | |
| 
 | |
| 				$lm['createTime'] = date('Y-m-d H:i:s');
 | |
| 
 | |
| 				model('LogMoneys')->insert($lm);
 | |
| 
 | |
| 				//发送信息信息
 | |
| 
 | |
| 				$tpl = WSTMsgTemplates('CASH_DRAW_SUCCESS');
 | |
| 
 | |
| 		        if( $tpl['tplContent']!='' && $tpl['status']=='1'){
 | |
| 
 | |
| 		            $find = ['${CASH_NO}'];
 | |
| 
 | |
| 		            $replace = [$cash->cashNo];
 | |
| 
 | |
| 		            WSTSendMsg($targetId,str_replace($find,$replace,$tpl['tplContent']),['from'=>5,'dataId'=>$id]);
 | |
| 
 | |
| 		        } 
 | |
| 
 | |
| 				//微信消息
 | |
| 
 | |
| 				if((int)WSTConf('CONF.wxenabled')==1){
 | |
| 
 | |
| 					$params = [];
 | |
| 
 | |
| 					$params['CASH_NO'] = $cash->cashNo;
 | |
| 
 | |
| 					$params['MONEY'] = $cash->money;
 | |
| 
 | |
| 					$params['CASH_TYPE'] = '银行提现';           
 | |
| 
 | |
| 					$params['CASH_TIME'] = $cash['createTime'];
 | |
| 
 | |
| 					$params['CASH_RESULT'] = "审核通过。【备注:".((input('cashRemarks')=='')?"无":input('cashRemarks'))."】";
 | |
| 
 | |
| 					$params['EXAMINE_TIME'] = date('Y-m-d H:i:s');
 | |
| 
 | |
| 					WSTWxMessage(['CODE'=>'WX_CASH_DRAW_SUCCESS','userId'=>$targetId,'params'=>$params]);
 | |
| 
 | |
| 				}
 | |
| 
 | |
| 				Db::commit();
 | |
| 
 | |
| 				return WSTReturn('操作成功!',1);
 | |
| 
 | |
|             }
 | |
| 
 | |
| 		}catch (\Exception $e) {
 | |
| 
 | |
|             Db::rollback();errLog($e);
 | |
| 
 | |
|         }
 | |
| 
 | |
| 		return WSTReturn('操作失败!',-1);
 | |
| 
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 
 | |
| 	/**
 | |
| 
 | |
| 	 * 处理提现失败
 | |
| 
 | |
| 	 */
 | |
| 
 | |
| 	public function handleFail(){
 | |
| 
 | |
| 		$id = (int)input('cashId');
 | |
| 
 | |
| 		$cash = $this->get($id);
 | |
| 
 | |
| 		if(empty($cash))return WSTReturn('无效的提现申请记录');
 | |
| 
 | |
| 		if(input('cashRemarks')=='')return WSTReturn('请输入提现失败原因');
 | |
| 
 | |
| 		Db::startTrans();
 | |
| 
 | |
| 		try{
 | |
| 
 | |
| 			
 | |
| 
 | |
|             if($cash->targetType==0){
 | |
| 
 | |
| 		        $user = model('users')->get($cash->targetId);
 | |
| 
 | |
| 				if($user->lockMoney<$cash->money)return WSTReturn('操作失败,无效的冻结的金额');
 | |
| 
 | |
| 				$user->userMoney = $user->userMoney + $cash->money;
 | |
| 
 | |
| 				$user->lockMoney = $user->lockMoney-$cash->money;
 | |
| 
 | |
|             	$user->save();
 | |
| 
 | |
|             	$targetId = $user->userId;
 | |
| 
 | |
|             }else{
 | |
| 
 | |
|                 $shop = model('shops')->get($cash->targetId);
 | |
| 
 | |
| 				if($shop->lockMoney<$cash->money)return WSTReturn('操作失败,无效的冻结的金额');
 | |
| 
 | |
|                 $shop->shopMoney = $shop->shopMoney + $cash->money;
 | |
| 
 | |
|                 $shop->lockMoney = $shop->lockMoney-$cash->money;
 | |
| 
 | |
|             	$shop->save();
 | |
| 
 | |
|             	$targetId = $shop->userId;
 | |
| 
 | |
|             }
 | |
| 
 | |
|             $cash->cashSatus = -1;
 | |
| 
 | |
|             $cash->cashRemarks = input('cashRemarks');
 | |
| 
 | |
|             $result = $cash->save();
 | |
| 
 | |
| 
 | |
| 
 | |
|             if(false != $result){
 | |
| 
 | |
| 				//发送信息信息
 | |
| 
 | |
| 				$tpl = WSTMsgTemplates('CASH_DRAW_FAIL');
 | |
| 
 | |
| 		        if( $tpl['tplContent']!='' && $tpl['status']=='1'){
 | |
| 
 | |
| 		            $find = ['${CASH_NO}','${CASH_RESULT}'];
 | |
| 
 | |
| 		            $replace = [$cash->cashNo,input('cashRemarks')];
 | |
| 
 | |
| 		            WSTSendMsg($targetId,str_replace($find,$replace,$tpl['tplContent']),['from'=>5,'dataId'=>$id]);
 | |
| 
 | |
| 		        } 
 | |
| 
 | |
| 				//微信消息
 | |
| 
 | |
| 				if((int)WSTConf('CONF.wxenabled')==1){
 | |
| 
 | |
| 					$params = [];
 | |
| 
 | |
| 					$params['CASH_NO'] = $cash->cashNo;
 | |
| 
 | |
| 					$params['MONEY'] = $cash->money;
 | |
| 
 | |
| 					$params['CASH_TYPE'] = '银行提现';           
 | |
| 
 | |
| 					$params['CASH_TIME'] = $cash['createTime'];
 | |
| 
 | |
| 					$params['CASH_RESULT'] = "审核不通过。【备注:".((input('cashRemarks')=='')?"无":input('cashRemarks'))."】";
 | |
| 
 | |
| 					$params['EXAMINE_TIME'] = date('Y-m-d H:i:s');
 | |
| 
 | |
| 					WSTWxMessage(['CODE'=>'WX_CASH_DRAW_FAIL','userId'=>$targetId,'params'=>$params]);
 | |
| 
 | |
| 				}
 | |
| 
 | |
| 				Db::commit();
 | |
| 
 | |
| 				return WSTReturn('操作成功!',1);
 | |
| 
 | |
|             }
 | |
| 
 | |
| 		}catch (\Exception $e) {
 | |
| 
 | |
|             Db::rollback();errLog($e);
 | |
| 
 | |
|         }
 | |
| 
 | |
| 		return WSTReturn('操作失败!',-1);
 | |
| 
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 
 | |
| 	 * 导出提现申请
 | |
| 
 | |
| 	 */
 | |
| 
 | |
| 	public function toExport(){
 | |
| 
 | |
| 		$name='提现申请表';
 | |
| 
 | |
| 		$targetType = input('targetType',-1);
 | |
| 
 | |
| 		$cashNo = input('cashNo');
 | |
| 
 | |
| 		$cashSatus = input('cashSatus',-1);
 | |
| 
 | |
|         $where = [];
 | |
| 
 | |
|         if(in_array($targetType,[0,1]))$where['targetType'] = $targetType;
 | |
| 
 | |
|         if(in_array($cashSatus,[0,1]))$where['cashSatus'] = $cashSatus;
 | |
| 
 | |
|         if($cashNo!='')$where['cashNo'] = ['like','%'.$cashNo.'%'];
 | |
| 
 | |
|         // 排序
 | |
| 
 | |
| 		$sort = input('sort');
 | |
| 
 | |
| 		$order = [];
 | |
| 
 | |
| 		if($sort!=''){
 | |
| 
 | |
| 			$sortArr = explode('.',$sort);
 | |
| 
 | |
| 			$order = $sortArr[0].' '.$sortArr[1];
 | |
| 
 | |
| 			if($sortArr[0]=='cashNo'){
 | |
| 
 | |
| 				$order = $sortArr[0].'+0 '.$sortArr[1];
 | |
| 
 | |
| 			}
 | |
| 
 | |
| 		}
 | |
| 
 | |
|         $page = $this->where($where)->order($order)->order('createTime desc')->select();
 | |
| 
 | |
| 	    if(count($page)>0){
 | |
| 
 | |
| 	    	$userIds = [];
 | |
| 
 | |
| 	    	$shopIds = [];
 | |
| 
 | |
| 	    	foreach ($page as $key => $v) {
 | |
| 
 | |
| 	    		if($v['targetType']==0)$userIds[] = $v['targetId'];
 | |
| 
 | |
| 	    		if($v['targetType']==1)$shopIds[] = $v['targetId'];
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    	$userMap = [];
 | |
| 
 | |
| 	    	if(count($userIds)>0){
 | |
| 
 | |
| 	    		$user = Db::name('users')->where(['userId'=>['in',$userIds]])->field('userId,loginName,userName')->select();
 | |
| 
 | |
| 	    	    foreach ($user as $key => $v) {
 | |
| 
 | |
| 	    	    	$userMap["0_".$v['userId']] = $v; 
 | |
| 
 | |
| 	    	    }
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    	if(count($shopIds)>0){
 | |
| 
 | |
| 	    		$user = Db::name('shops')->alias('s')
 | |
| 
 | |
| 	    		          ->join('__USERS__ u','u.userId=s.userId')
 | |
| 
 | |
| 	    		          ->where(['shopId'=>['in',$shopIds]])
 | |
| 
 | |
| 	    		          ->field('s.shopId,u.loginName,s.shopName as userName')
 | |
| 
 | |
| 	    		          ->select();
 | |
| 
 | |
| 	    	    foreach ($user as $key => $v) {
 | |
| 
 | |
| 	    	    	$userMap["1_".$v['shopId']] = $v; 
 | |
| 
 | |
| 	    	    }
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    	foreach ($page as $key => $v) {
 | |
| 
 | |
| 	    		$page[$key]['userType'] = ($v['targetType']==1)?"【商家】":"【会员】";
 | |
| 
 | |
| 	    		$page[$key]['loginName'] = $userMap[$v['targetType']."_".$v['targetId']]['loginName'];
 | |
| 
 | |
| 	    		$page[$key]['userName'] = $userMap[$v['targetType']."_".$v['targetId']]['userName'];
 | |
| 
 | |
| 	    		$page[$key]['cashSatus'] = ($page[$key]['cashSatus']==1)?'提现成功':(($page[$key]['cashSatus']==-1)?'提现失败':'待处理');
 | |
| 
 | |
| 	    	}
 | |
| 
 | |
| 	    }
 | |
| 
 | |
| 	   
 | |
| 
 | |
| 
 | |
| 
 | |
| 		Loader::import('phpexcel.PHPExcel.IOFactory');
 | |
| 
 | |
| 		$objPHPExcel = new \PHPExcel();
 | |
| 
 | |
| 		// 设置excel文档的属性
 | |
| 
 | |
| 		$objPHPExcel->getProperties()->setCreator("WSTMart")//创建人
 | |
| 
 | |
| 		->setLastModifiedBy("WSTMart")//最后修改人
 | |
| 
 | |
| 		->setTitle($name)//标题
 | |
| 
 | |
| 		->setSubject($name)//题目
 | |
| 
 | |
| 		->setDescription($name)//描述
 | |
| 
 | |
| 		->setKeywords("提现")//关键字
 | |
| 
 | |
| 		->setCategory("Test result file");//种类
 | |
| 
 | |
| 	
 | |
| 
 | |
| 		// 开始操作excel表
 | |
| 
 | |
| 		$objPHPExcel->setActiveSheetIndex(0);
 | |
| 
 | |
| 		// 设置工作薄名称
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->setTitle(iconv('gbk', 'utf-8', 'Sheet'));
 | |
| 
 | |
| 		// 设置默认字体和大小
 | |
| 
 | |
| 		$objPHPExcel->getDefaultStyle()->getFont()->setName(iconv('gbk', 'utf-8', ''));
 | |
| 
 | |
| 		$objPHPExcel->getDefaultStyle()->getFont()->setSize(11);
 | |
| 
 | |
| 		$styleArray = array(
 | |
| 
 | |
| 				'font' => array(
 | |
| 
 | |
| 						'bold' => true,
 | |
| 
 | |
| 						'color'=>array(
 | |
| 
 | |
| 								'argb' => 'ffffffff',
 | |
| 
 | |
| 						)
 | |
| 
 | |
| 				),
 | |
| 
 | |
| 				'borders' => array (
 | |
| 
 | |
| 						'outline' => array (
 | |
| 
 | |
| 								'style' => \PHPExcel_Style_Border::BORDER_THIN,  //设置border样式
 | |
| 
 | |
| 								'color' => array ('argb' => 'FF000000'),     //设置border颜色
 | |
| 
 | |
| 						)
 | |
| 
 | |
| 				)
 | |
| 
 | |
| 		);
 | |
| 
 | |
| 		//设置宽
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(12);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12);
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->getFill()->getStartColor()->setARGB('333399');
 | |
| 
 | |
| 		
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->setCellValue('A1', '提现单号')
 | |
| 
 | |
| 		->setCellValue('B1', '会员类型')->setCellValue('C1', '会员名称')
 | |
| 
 | |
| 		->setCellValue('D1', '提现银行')->setCellValue('E1', '银行卡号')
 | |
| 
 | |
| 		->setCellValue('F1', '持卡人')->setCellValue('G1', '提现金额')
 | |
| 
 | |
| 		->setCellValue('H1', '提现时间')->setCellValue('I1', '状态');
 | |
| 
 | |
| 		$objPHPExcel->getActiveSheet()->getStyle('A1:I1')->applyFromArray($styleArray);
 | |
| 
 | |
| 	
 | |
| 
 | |
| 		for ($row = 0; $row < count($page); $row++){
 | |
| 
 | |
| 			$i = $row+2;
 | |
| 
 | |
| 			$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $page[$row]['cashNo'])
 | |
| 
 | |
| 			->setCellValue('B'.$i, $page[$row]['userType'])->setCellValue('C'.$i, $page[$row]['userName'].'('.$page[$row]['loginName'].')' )
 | |
| 
 | |
| 			->setCellValue('D'.$i, $page[$row]['accTargetName'])->setCellValue('E'.$i, $page[$row]['accNo'])
 | |
| 
 | |
| 			->setCellValue('F'.$i, $page[$row]['accUser'])->setCellValue('G'.$i, '¥'.$page[$row]['money'])
 | |
| 
 | |
| 			->setCellValue('H'.$i, $page[$row]['createTime'])->setCellValue('I'.$i, $page[$row]['cashSatus']);
 | |
| 
 | |
| 		}
 | |
| 
 | |
| 	
 | |
| 
 | |
| 		//输出EXCEL格式
 | |
| 
 | |
| 		$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
 | |
| 
 | |
| 		// 从浏览器直接输出$filename
 | |
| 
 | |
| 		header('Content-Type:application/csv;charset=UTF-8');
 | |
| 
 | |
| 		header("Pragma: public");
 | |
| 
 | |
| 		header("Expires: 0");
 | |
| 
 | |
| 		header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
 | |
| 
 | |
| 		header("Content-Type:application/force-download");
 | |
| 
 | |
| 		header("Content-Type:application/vnd.ms-excel;");
 | |
| 
 | |
| 		header("Content-Type:application/octet-stream");
 | |
| 
 | |
| 		header("Content-Type:application/download");
 | |
| 
 | |
| 		header('Content-Disposition: attachment;filename="'.$name.'.xls"');
 | |
| 
 | |
| 		header("Content-Transfer-Encoding:binary");
 | |
| 
 | |
| 		$objWriter->save('php://output');
 | |
| 
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 |