123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- namespace Bill\Lib;
- use Dever;
- class Cash
- {
- public function up($mid, $type, $cash, $role, $type_id, $desc, $status, $insert = false)
- {
- if ($cash == 0) {
- return false;
- }
- $member = Dever::db('agent/member')->find(array('id' => $mid, 'clear' => true));
- if ($member && $member['status'] <= 2) {
- $where['mid'] = $mid;
- if ($type == 11) {
- $cash = -1*$cash;
- }
- $where['type'] = $type;
- $where['type_id'] = $type_id;
- $where['clear'] = true;
- $info = Dever::db('bill/cash')->find($where);
- if (!$info) {
- $data = $where;
- $data['order_num'] = $this->getOrderId();
- $data['yue'] = $member['cash'] + $cash;
- $data['cash'] = $cash;
- $data['role'] = $role;
- $data['desc'] = $desc;
- $data['status'] = $status;
- if ($status == 2) {
- $data['operdate'] = time();
- }
- return Dever::db('bill/cash')->insert($data);
- }
- return !$insert ? $info['id'] : false;
- }
- return false;
- }
- /**
- * 生成订单号
- *
- * @return mixed
- */
- public function getOrderId()
- {
- $where['order_num'] = Dever::order('C');
- $where['clear'] = true;
- $state = Dever::db('bill/cash')->one($where);
- if (!$state) {
- return $where['order_num'];
- } else {
- return $this->getOrderId();
- }
- }
- # 展示详情
- public function show()
- {
- $id = Dever::input('id');
- $config = Dever::db('bill/cash')->config['set'];
- $info = Dever::db('bill/cash')->one($id);
- $status = $config['status'][$info['status']];
- $type = $config['type'][$info['type']];
- $member = Dever::db('agent/member')->find($info['mid']);
- $role = Dever::db('setting/role')->one($member['role']);
- $level = Dever::db('setting/level')->one($member['level_id']);
- if ($member['shop_id']) {
- $shop = Dever::db('shop/info')->one($member['shop_id']);
- } else {
- $shop['id'] = -1;
- $shop['name'] = '无';
- }
- $cdate = date('Y-m-d H:i', $info['cdate']);
- if ($info['operdate']) {
- $opertime = date('Y-m-d H:i', $info['operdate']);
- } else {
- $opertime = '';
- }
- $result = array();
- $result['代理商信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('代理商', $member['name'] . ' ' . $member['mobile']),
- array('代理角色', $role['name'] . ($level ? '('.$level['name'].')' : '')),
- array('所属店铺', $shop['name']),
- ),
- array
- (
- array('资金余额', '¥' . $member['cash'] . '元'),
- //array('直推业绩', '¥' . $member['sell'] . '元'),
- array('团队业绩', '¥' . $member['group_sell'] . '元'),
- ),
- ),
- );
- $result['交易信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('流水号', $info['order_num']),
- array('交易时间', $cdate),
- array('交易类型', $type),
- ),
- array
- (
- array('交易金额', '¥' . $info['cash'] . '元'),
- array('交易后账户余额', '¥' . $info['yue'] . '元'),
- array('交易说明', $info['desc']),
- ),
- )
- );
- $result['审核信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('审核时间', $opertime),
- array('审核状态', $status),
- array('备注', $info['audit_desc']),
- ),
- )
- );
-
- # 提现信息
- $button = array();
-
- if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit', '审核')) {
- if ($info['status'] == 1) {
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => Dever::url('project/database/update?project=bill&table=cash&where_id='.$info['id'].'&col=audit,audit_desc&oper_save_jump=cash&oper_table=cash&oper_parent=cash', 'manage'),
- 'name' => '审核',
- );
- }
- }
- if ($info['type'] == 11) {
- $tixian = Dever::db('bill/tixian')->find($info['type_id']);
- if ($tixian) {
- $config = Dever::db('bill/tixian')->config['set'];
- $status = $config['status'][$tixian['status']];
- if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit1', '发放')) {
- if ($info['status'] == 2 && $tixian['status'] == 1) {
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => Dever::url('project/database/update?project=bill&table=tixian&where_id='.$tixian['id'].'&col=audit,audit_desc,pic&oper_save_jump=tixian&oper_table=tixian&oper_parent=tixian', 'manage'),
- 'name' => '发放',
- );
- }
- }
- /*
- $bank = Dever::db('setting/bank')->find($tixian['bank']);
- $result['提现信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('银行名称', $bank['name']),
- array('开户行', $tixian['bankname']),
- ),
- array
- (
- array('姓名', $tixian['name']),
- array('卡号', $tixian['card']),
- ),
- )
- );
- */
- if ($tixian['status']) {
- if ($tixian['operdate']) {
- $opertime = date('Y-m-d H:i', $tixian['operdate']);
- } else {
- $opertime = '';
- }
- $pic = '';
- if ($tixian['pic']) {
- $temp = explode(',', $tixian['pic']);
- foreach ($temp as $k => $v) {
- $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
- }
- }
- $result['发放信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('发放时间', $opertime),
- array('发放状态', $status),
- array('备注', $tixian['audit_desc']),
- ),
- array
- (
- array('凭证', $pic),
- ),
- )
- );
- }
-
- }
- }
- $button[] = array
- (
- 'type' => 'link',
- 'link' => 'refer',
- 'name' => '返回上一页',
- );
- $head = array
- (
- 'name' => '基本信息',
- 'btn' => $button,
- );
- $html = Dever::show($head, $result);
- return $html;
- }
- public function order_num($id){
- $info = Dever::db('bill/cash')->find($id);
- $cdate = date('Y-m-d H:i',$info['cdate']);
- $odate = '';
- if ($info['operdate']) {
- $odate = date('Y-m-d H:i',$info['operdate']);
- }
- $html['num'] = $cdate . '<br/>'.$odate;
- $html['cash'] = $info['cash'] . '<br />' . $info['yue'];
- return $html;
- }
- #钱包管理数据导出
- public function out_cash_api($data){
- $header = array('邀请码', '姓名', '手机号', '身份证号', '代理角色', '代理商区域', '代理费', '审核时间', '直推收入', '团队收入', '管理员备注');
- $body = array();
- foreach($data as $k =>$v){
- $arr[] = Dever::db('agent/member')->find(array('id'=>$v['mid']));
- foreach($arr as $k1=>$v1){
- if($v['mid'] == $v1['id']){
- $arr[$k1]['operdate'] = $v['operdate'];
- $arr[$k1]['audit_desc'] = $v['audit_desc'];
- }
- }
- }
- $member = array();
- $arr=array_unique($arr, SORT_REGULAR);
- $rest=array();
- foreach($arr as $k=>$v){
- $rest[$v['id']]=$v;
- }
- $member=array_values($rest);
- foreach($member as $k => $v){
- $code = Dever::load("invite/api.code", $v['id']);
- $role = Dever::db('setting/role')->find(array('id'=>$v['role']));
- $area = Dever::load("area/api.string", $v['area']);
- $order = Dever::db('agent/order')->state(array('mid'=>$v['id']));
- $zhitui = Dever::db('bill/cash')->state(array('mid'=>$v['id'],'type'=>1));
- $total = 0;
- foreach($zhitui as $key => $val){
- $total += $val['cash'];
- }
- $tuandui = Dever::db('bill/cash')->state(array('mid'=>$v['id'],'type'=>2));
- $tuan = 0;
- foreach($tuandui as $t){
- $tuan += $t['cash'];
- }
- $sum = 0;
- foreach($order as $k1 => $v1){
- $sum += $v1['agent_cash'];
- }
- $operdate = '';
- if($v['operdate']){
- $operdate = date('Y-m-d',$v['operdate']);
- }
- $d = array
- (
- $code,
- $v['name'],
- $v['mobile'],
- $v['idcard'],
- $role['name'],
- $area,
- $sum,
- $operdate,
- $total,
- $tuan,
- $v['audit_desc'],
- );
- $body[] = $d;
- }
- $file = Dever::input('excel_name');
- return Dever::excelExport($body, $header, $file);
- }
- }
|