0 ? date('Y-m-d H:i:s', $value) : 0; } /** * 获取器:打款方式 */ public function getPayTypeAttr($value) { return ['text' => $this->payType[$value], 'value' => $value]; } /** * 获取队长提现列表 */ public function getList($user_id = null, $apply_status = -1, $pay_type = -1, $search = '', $params = []) { $model = $this; // 构建查询规则 $model = $model->alias('cash') ->with(['user']) ->field('cash.*, bonus.real_name, bonus.mobile, user.nickName, user.avatarUrl') ->join('user', 'user.user_id = cash.user_id') ->join('bonus_user bonus', 'bonus.user_id = cash.user_id') ->order(['cash.create_time' => 'desc']); // 查询条件 if (!empty($search)) { if ($params['search_type'] == 'user_id') { $model = $model->where('cash.user_id', '=', $search); } else if ($params['search_type'] == 'nickName') { $model = $model->where('user.nickName', 'like', '%' . $search . '%'); } else { $model = $model->where('agent.real_name|agent.mobile', 'like', '%' . $search . '%'); } } if ($apply_status > 0) { $model = $model->where('cash.apply_status', '=', $apply_status); } if ($pay_type > 0) { $model = $model->where('cash.pay_type', '=', $pay_type); } //搜索时间段 if (isset($params['create_time']) && $params['create_time'] != '') { $model = $model->where('cash.create_time', 'between', [strtotime($params['create_time'][0]), strtotime($params['create_time'][1]) + 86399]); } // 获取列表数据 return $model->paginate($params); } /** * 队长提现审核 */ public function submit($param) { $data = ['apply_status' => $param['apply_status']]; if ($param['apply_status'] == 30) { $data['reject_reason'] = $param['reject_reason']; } // 更新申请记录 $data['audit_time'] = time(); self::update($data, ['id' => $param['id']]); // 提现驳回:解冻队长资金 if ($param['apply_status'] == 30) { User::backFreezeMoney($param['user_id'], $param['money']); } // 发送模板消息 (new MessageService)->cash($this); return true; } /** * 确认已打款 */ public function money() { // 如果是完税系统打款 by lyzflash if ($this['is_yms']) { return $this->ymsMoney(); } $this->startTrans(); try { // 更新申请状态 $data = ['apply_status' => 40, 'audit_time' => time()]; self::update($data, ['id' => $this['id']]); // 如果是打款到余额 if ($this['pay_type']['value'] == 40) { UserModel::cashToBalance($this['user_id'], $this['money'], '分红提现到余额-cash_id:' . $this['id']); } // 更新队长累积提现佣金 User::totalMoney($this['user_id'], $this['money']); // 记录队长资金明细 Capital::add([ 'user_id' => $this['user_id'], 'flow_type' => 20, 'money' => -$this['money'], 'describe' => '申请提现', ]); // 发送模板消息 //(new Message)->withdraw($this); // 事务提交 $this->commit(); return true; } catch (\Exception $e) { $this->error = $e->getMessage(); $this->rollback(); return false; } } /** * 完税系统打款 by lyzflash */ public function ymsMoney() { $this->startTrans(); try { $result = (new YmsModel($this['app_id']))->batchPay([$this]); if ($result && $result['code'] != '0') { $this->error = $result['msg']; return false; } $resData = $result['data']; // 统一记录付款信息 $ymsData = []; $errorArr = []; foreach ($resData['payItemList'] as $item) { if ($item['status'] == '0') { (new CashModel)->where('cash_no', '=', $item['merchantOrderId'])->save([ 'merBatchId' => $resData['merchantBatchId'], // 商户批次号 'payItemId' => $item['orderNo'], // 订单流水号 'apply_status' => 50, // 付款中 ]); $ymsData[] = [ 'user_id' => $this['user_id'], 'merOrderId' => $item['merchantOrderId'], // 商户订单号(cash_no) 'payItemId' => $item['orderNo'], // 完税系统返回的订单流水号 'merBatchId' => $resData['merchantBatchId'], // 商户批次号 'orderBatchNo' => $resData['orderBatchNo'], // 订单批次号 'cash_type' => CashTypeEnum::BONUS, // 提现来源标识 'money' => $item['amt'] / 100, 'app_id' => $this['app_id'], ]; } else { $this->error = $item['errorMsg']; return false; } } if ($ymsData) { (new YmsSettlementModel)->saveAll($ymsData); } // 事务提交 $this->commit(); return true; } catch (\Exception $e) { $this->error = $e->getMessage(); $this->rollback(); return false; } } /** * 队长提现:微信支付企业付款 */ public function wechatPay() { // 微信用户信息 $user = UserModel::detail($this['user_id']); // 生成付款订单号 $orderNO = OrderService::createOrderNo(); // 付款描述 $desc = '队长提现付款'; // 微信支付api:企业付款到零钱 $open_id = ''; $app = []; if($user['reg_source'] == 'mp'){ $app = AppMp::getWxPayApp($user['app_id']); $open_id = $user['mpopen_id']; }else if($user['reg_source'] == 'wx'){ $app = AppWx::getWxPayApp($user['app_id']); $open_id = $user['open_id']; } if($open_id == ''){ $this->error = '未找到用户open_id'; return false; } $WxPay = new WxPay($app); //打款金额 $money = floatval($this['money']) - floatval($this['fee_money']); // 请求付款api if ($WxPay->transfers($orderNO, $open_id, $money, $desc)) { // 确认已打款 $this->money(); return true; } return false; } /* *统计提现总数量 */ public function getteamOrderTotal() { return $this->count('id'); } /* * 统计提现待审核总数量 */ public function getteamApplyTotal($apply_status) { return $this->where('apply_status', '=', $apply_status)->count(); } /* * 统计提现待审核金额 */ public function getteamApplyMoney() { return $this->where('apply_status', '=', 10)->sum('real_money'); } /* *获取提现待打款总数量 by lyzflash 2023.02.08 */ public function getCashPayNum() { return $this->where('apply_status', '=', 20)->count(); } /* *统计待打款的金额 by lyzflash 2023.02.08 */ public function getCashPayMoney() { return $this->where('apply_status', '=', 20)->sum('real_money'); } /** * 导出分红提现 */ public function exportList($user_id = null, $apply_status = -1, $pay_type = -1, $search = '', $params = []) { $model = $this; // 构建查询规则 $model = $model->alias('cash') ->with(['user']) ->field('cash.*, agent.real_name, agent.mobile, user.nickName, user.avatarUrl') ->join('user', 'user.user_id = cash.user_id') ->join('agent_user agent', 'agent.user_id = cash.user_id') ->order(['cash.create_time' => 'desc']); // 查询条件 if (!empty($search)) { if ($params['search_type'] == 'user_id') { $model = $model->where('cash.user_id', '=', $search); } else if ($params['search_type'] == 'nickName') { $model = $model->where('user.nickName', 'like', '%' . $search . '%'); } else { $model = $model->where('agent.real_name|agent.mobile', 'like', '%' . $search . '%'); } } if ($apply_status > 0) { $model = $model->where('cash.apply_status', '=', $apply_status); } if ($pay_type > 0) { $model = $model->where('cash.pay_type', '=', $pay_type); } //搜索时间段 if (isset($params['create_time']) && $params['create_time'] != '') { $model = $model->where('cash.create_time', 'between', [strtotime($params['create_time'][0]), strtotime($params['create_time'][1]) + 86399]); } // 获取列表数据 $list = $model->select(); // 导出excel文件 (new Exportservice)->bonusCashList($list); } }