dao = new UserExtractDao(); } /** * 列表 * @param array $param */ public function getList(array $param = [],string $field = '*', int $page = 0,int $limit = 0,string $order = 'id desc') { $list = $this->dao->getList($this->searchFilter($param),$field,$page,$limit,$order); $count = $this->dao->count($this->searchFilter($param)); return compact('list','count'); } protected function searchFilter(array $param = []): array { $filter = []; !empty($param['status']) && $filter[] = ["status", '=', $param['status']]; return $filter; } public function cash(array $user,array $data):bool { $userService = new UserService(); $extractPrice = $user['brokerage_price']; $userExtractMinPrice = sConf('extract.extract_min_price'); if ($data['price'] < $userExtractMinPrice) { throw new ValidateException('提现金额不能小于' . $userExtractMinPrice . '元'); } if ($extractPrice < 0) { throw new ValidateException('提现佣金不足' . $data['price']); } if ($data['price'] > $extractPrice) { throw new ValidateException('提现佣金不足' . $data['price']); } if ($data['price'] <= 0) { throw new ValidateException('提现佣金大于0'); } //手续费 $charge = $data['price'] * (0 / 100); $insertData = [ 'real_name'=>$data['real_name'], 'uid' => $user['uid'], 'bank_code' => $data['bank_code'], 'bank_address' => $data['bank_address'], 'card' => $data['card'], // 'extract_type' => $data['extract_type'], 'price' => $data['price'], //提现金额 'extract_price' => $data['price'] - $charge, //到账金额 'service_price'=>$charge, //手续费 'balance' => $user['brokerage_price'] - $data['price'], 'status' => 0 ]; $mark = '提现' . $data['price'] . '元'."(手续费:$charge 元)"; return $this->transaction(function () use ($insertData, $data, $user, $userService, $mark) { if (!$res = $this->dao->save($insertData)) { throw new ValidateException('提现失败'); } if (!$userService->decField(['uid'=>$user['uid']], 'brokerage_price', $data['price'])) { throw new ValidateException('修改用户信息失败'); } $balance = bcsub((string)$user['brokerage_price'], (string)$data['price'], 2) ?? 0; //保存佣金记录 $userBrokerageServices = new UserBrokerageService(); $userBrokerageServices->income('extract', $user['uid'], ['mark' => $mark, 'number' => $data['price']], $balance, $res['id']); return true; }); } /** * 拒绝 * @param $id * @return mixed */ public function refuse(int $id, string $message) { $extract = $this->dao->getOne(['id'=>$id]); if ($extract->isEmpty()) { throw new ValidateException('操作记录不存在'); } if ($extract->status == 1) { throw new ValidateException('已经提现,错误操作'); } if ($extract->status == -1) { throw new ValidateException('您的提现申请已被拒绝,请勿重复操作!'); } $fail_time = getDateFull(); $extract_number = $extract['extract_price'] + $extract['service_price']; $mark = '提现失败,退回佣金' . $extract_number . '元'; $uid = $extract['uid']; $status = -1; $userServices = new UserService(); $user = $userServices->getOne(['uid'=>$uid]); return $this->transaction(function () use ($user, $uid, $id, $extract_number, $message, $userServices, $status, $fail_time) { //增加佣金记录 $userBrokerageServices = new UserBrokerageService(); $now_brokerage = bcadd((string)$user['brokerage_price'], (string)$extract_number, 2); $userBrokerageServices->income('extract_fail', $uid, $extract_number, $now_brokerage, $id); if (!$userServices->incField(['uid'=>$uid], 'brokerage_price', $extract_number)) throw new ValidateException('增加用户佣金失败'); if (!$this->dao->update($id, ['fail_time' => $fail_time, 'fail_msg' => $message, 'status' => $status])) { throw new ValidateException('增加用户佣金失败'); } return true; }); } /** * 通过 * @param $id * @return mixed */ public function adopt(int $id) { $extract = $this->dao->getOne(['id'=>$id]); if ($extract->isEmpty()) { throw new ValidateException('操作记录不存在'); } if ($extract->status == 1) { throw new AdminException('您已提现,请勿重复提现!'); } if ($extract->status == -1) { throw new AdminException('您的提现申请已被拒绝!'); } $data['status'] = 1; $data['succeed_time'] = getDateFull(); return $this->dao->update($id, $data); } }