123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- /**
- * SettleLogic.php UTF-8
- * 提现
- *
- * @date : 2018/5/18 16:27
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\logic\finance;
- use huo\model\common\CommonModel;
- use huo\model\finance\SettleModel;
- use huo\model\user\UserModel;
- use huolib\constant\CommonConst;
- class SettleLogic extends CommonModel {
- /**
- * 获取提现列表
- *
- * @param $agent_id
- * @param $param
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getSettleList($agent_id, $param, $page = '1,10', $order = '-create_time') {
- $_map = $this->getWhere($param, $agent_id);
- $field = $this->getField($agent_id);
- return $this->getList($field, $_map, $page, $order);
- }
- /**
- * @param array $param
- * @param int $agent_id
- *
- * @return array
- */
- protected function getWhere($param = [], $agent_id = 0) {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['end_time'])) {
- $_map['create_time']
- = [
- 'between',
- [
- strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])
- ]
- ];
- } elseif (!empty($param['start_time'])) {
- $_map['create_time'] = ['egt', strtotime($param['start_time'])];
- } elseif (!empty($param['end_time'])) {
- $_map['create_time'] = ['elt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($agent_id)) {
- $_map['agent_id'] = $agent_id;
- }
- if (!empty($param['agent_id']) && empty($_map['agent_id'])) {
- $_map['agent_id'] = $param['agent_id'];
- }
- if (!empty($param['agent_name']) && empty($_map['agent_id'])) {
- $_map['agent_id'] = (new UserModel())->getIdByName($param['agent_name']);
- }
- if (!empty($param['agent_nickname']) && empty($_map['agent_id'])) {
- $_ids = (new UserModel())->getIdsByNickName($param['agent_nickname']);
- $_map['agent_id'] = ['in', $_ids];
- }
- if (!empty($param['mem_id']) && empty($_map['agent_id'])) {
- $_map['agent_id'] = (new UserModel())->getIdByMemId($param['mem_id']);
- }
- if (!empty($param['status'])) {
- $_map['status'] = $param['status'];
- }
- if (!empty($param['type'])) {
- $_map['type'] = $param['type'];
- }
- if (!empty($param['cardholder'])) {
- $_map['cardholder'] = $param['cardholder'];
- }
- if (!empty($param['tag'])) {
- $_map['tag'] = $param['tag'];
- }
- return $_map;
- }
- public function getField($agent_id) {
- return [];
- }
- /**
- * 获取提现列表
- *
- * @param array $field
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getList($field, $where, $page = '1,10', $order = '-create_time') {
- $_map = $where;
- $_settle_model = new SettleModel();
- $_count = $_settle_model->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'sum' => ['sum_amount' => 0, 'amount' => 0],
- 'list' => []
- ];
- }
- $_sum_data = $_settle_model
- ->where($where)
- ->sum('amount');
- $_field = [
- 'id' => 'id',
- 'agent_id' => 'agent_id',
- 'amount' => 'amount',
- 'type' => 'type',
- 'bankname' => 'bankname',
- 'branchname' => 'branchname',
- 'cardholder' => 'cardholder',
- 'banknum' => 'banknum',
- 'status' => 'status',
- 'is_return' => 'is_return',
- 'failreason' => 'failreason',
- 'create_time' => 'create_time',
- 'check_time' => 'check_time',
- 'settle_time' => 'settle_time',
- ];
- $_field = array_merge($_field, $field);
- $_order = $_settle_model->orderFilter($order);
- $_settle_datas = $_settle_model
- ->with('agent,remain,memtag')
- ->field($_field)
- ->where($where)
- ->order($_order)
- ->page($page)
- ->select();
- if (is_object($_settle_datas)) {
- $_settle_datas = $_settle_datas->toArray();
- }
- if (empty($_settle_datas)) {
- return [
- 'count' => $_count,
- 'sum' => ['sum_amount' => round($_sum_data, 2), 'amount' => round($_sum_data, 2)],
- 'list' => []
- ];
- }
- $_data = [];
- foreach ($_settle_datas as $_settle_data) {
- foreach ($_field as $_v) {
- $_list[$_v] = $_settle_data[$_v];
- }
- $_list['agent_name'] = $_settle_data['agent']['user_login'];
- $_list['agent_nickname'] = $_settle_data['agent']['user_nicename'];
- $_list['share_total'] = $_settle_data['remain']['share_total'];
- $_list['frozen_amount'] = $_settle_data['remain']['frozen_amount'];
- $_list['share_remain'] = $_settle_data['remain']['share_remain'];
- $_list['memtag'] = empty($_settle_data['memtag']['type']) ? 0 : $_settle_data['memtag']['type'];
- $_data[] = $_list;
- }
- return [
- 'count' => $_count,
- 'sum' => ['sum_amount' => round($_sum_data, 2), 'amount' => round($_sum_data, 2)],
- 'list' => $_data
- ];
- }
- /**
- * 提现详情
- *
- * @param int $id
- *
- * @return false|array
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getDetail($id) {
- if (empty($id)) {
- return false;
- }
- $_map['id'] = $id;
- $_field = [
- 'id' => 'id',
- 'agent_id' => 'agent_id',
- 'amount' => 'amount',
- 'type' => 'type',
- 'bankname' => 'bankname',
- 'branchname' => 'branchname',
- 'cardholder' => 'cardholder',
- 'banknum' => 'banknum',
- 'status' => 'status',
- 'is_return' => 'is_return',
- 'failreason' => 'failreason',
- 'create_time' => 'create_time',
- 'check_time' => 'check_time',
- 'settle_time' => 'settle_time',
- ];
- $_data = (new SettleModel())
- ->with('agent')
- ->with('remain')
- ->field($_field)
- ->where($_map)
- ->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (empty($_data)) {
- return false;
- }
- foreach ($_field as $_v) {
- $_list[$_v] = $_data[$_v];
- }
- $_list['agent_name'] = $_data['agent']['user_login'];
- $_list['agent_nickname'] = $_data['agent']['user_nicename'];
- $_list['share_total'] = $_data['remain']['share_total'];
- $_list['frozen_amount'] = $_data['remain']['frozen_amount'];
- $_list['share_remain'] = $_data['remain']['share_remain'];
- return $_list;
- }
- }
|