123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- <?php
- namespace Bill\Lib;
- use Dever;
- class Manage
- {
- public function cashUpdate($id, $name, $data)
- {
- Dever::config('base')->hook = true;
- $mid = Dever::param('mid', $data);
- $cash = Dever::param('cash', $data);
- $desc = Dever::param('desc', $data);
- $type = Dever::param('type', $data);
- if (!$type) {
- $type = 10;
- }
- if ($mid && $cash && $desc && $type) {
- $member = Dever::db('agent/member')->find($mid);
- if ($member && $member['status'] == 2) {
- Dever::load('bill/lib/cash')->up($mid, $type, $cash, $member['role'], $id, $desc, 2);
- $where = array();
- $where['where_id'] = $mid;
- $where['cash'] = $cash;
- $where['clear'] = true;
- Dever::db('agent/member')->upCash($where);
- } else {
- Dever::db('bill/push_cash')->update(array('where_id' => $id, 'status' => 2));
- Dever::alert('代理商未审核通过,发放失败');
- }
- }
- }
- public function cashAuditUpdateStart($param, $name, $data)
- {
- $mul_type = Dever::config('base')->mul_type;
- if ($mul_type == 2) {
- $list = Dever::db('bill/cash')->select(array('status' => 1));
- } else {
- $list = explode(',', $param['where_id']);
- }
- }
- public function cashAuditUpdate($id, $name, $data)
- {
- Dever::config('base')->hook = true;
- $audit = Dever::param('audit', $data);
- if ($audit > 1) {
- $mul_type = Dever::config('base')->mul_type;
- if ($mul_type == 2) {
- $list = Dever::db('bill/cash')->select(array('status' => 1));
- } else {
- $list = explode(',', $id);
- }
-
- foreach ($list as $k => $v) {
- if (is_array($v)) {
- $id = $v['id'];
- $info = Dever::db('bill/cash')->find(array('id' => $id, 'clear' => true));
- } else {
- $id = $v;
- $info = Dever::db('bill/cash')->find(array('id' => $id, 'clear' => true));
- }
-
- if ($info['status'] != 1) {
- continue;
- }
- #已审核
- if ($audit == 2) {
- Dever::db('bill/cash')->update(array('where_id' => $id, 'status' => 2, 'operdate' => time()));
- $info = Dever::db('bill/cash')->find($id);
- if ($info && $info['type'] <= 10) {
- $where['where_id'] = $info['mid'];
- $where['cash'] = $info['cash'];
- Dever::db('agent/member')->upCash($where);
- }elseif ($info && $info['type'] == 11) {
- $tixian = Dever::db('bill/tixian')->find($info['type_id']);
- $where['where_id'] = $tixian['id'];
- $where['status'] = 1;
- $admin = Dever::load('manage/auth.data');
- $where['audit_admin'] = $admin['id'];
- Dever::db('bill/tixian')->update($where);
- }
- } else {
- #作废
- Dever::db('bill/cash')->update(array('where_id' => $id, 'status' => 3, 'operdate' => time()));
- $info = Dever::db('bill/cash')->find($id);
- if ($info && $info['type'] == 11) {
- $tixian = Dever::db('bill/tixian')->find($info['type_id']);
- $where['where_id'] = $info['mid'];
- $where['cash'] = -1*$tixian['ycash'];
- Dever::db('agent/member')->upCash($where);
- $update['where_id'] = $tixian['id'];
- $update['status'] = 3;
- $admin = Dever::load('manage/auth.data');
- $update['audit_admin'] = $admin['id'];
- Dever::db('bill/tixian')->update($update);
- }
- }
- }
- }
- }
- public function tixianAuditUpdate($id, $name, $data)
- {
- Dever::config('base')->hook = true;
- $audit = Dever::param('audit', $data);
- $desc = Dever::param('audit_desc', $data);
- if ($audit > 1) {
- $mul_type = Dever::config('base')->mul_type;
- if ($mul_type == 2) {
- $list = Dever::db('bill/tixian')->select(array('status' => 1));
- } else {
- $list = explode(',', $id);
- }
-
- foreach ($list as $k => $v) {
- if (is_array($v)) {
- $id = $v['id'];
- $tixian = Dever::db('bill/tixian')->find(array('id' => $id, 'clear' => true));
- } else {
- $id = $v;
- $tixian = Dever::db('bill/tixian')->find(array('id' => $id, 'clear' => true));
- }
- if (!$tixian) {
- continue;
- }
-
- if ($tixian['status'] != 1) {
- continue;
- }
- if ($tixian['type'] == 1) {
- $info = Dever::db('bill/cash')->find(array('type' => 11, 'type_id' => $id));
- $table = 'bill/cash';
- } elseif ($tixian['type'] == 2) {
- $info = Dever::db('shop/record')->find(array('type' => 2, 'type_id' => $id));
- $table = 'shop/record';
- } elseif ($tixian['type'] == 3) {
- $info = Dever::db('shop/user_money')->find(array('type' => 11, 'type_id' => $id));
- $table = 'shop/user_money';
- }
-
- if (!$info) {
- continue;
- }
- if ($audit == 2) {
- $admin = Dever::load('manage/auth.data');
- $where['audit_admin'] = $admin['id'];
- Dever::db('bill/tixian')->update(array('where_id' => $id, 'status' => 2, 'audit_admin' => $where['audit_admin'],'operdate' => time()));
- if ($info && $info['status'] == 1) {
- Dever::db($table)->update(array('where_id' => $id, 'status' => 2, 'operdate' => time()));
- }
- # 通知短信
- /*
- if (Dever::project('sms')) {
- $member = Dever::db('agent/member')->find($info['mid']);
- Dever::load('sms/api')->send('daili_tixian_yes', $member['mobile'], array('name' => $member['name']));
- }
- */
- } else {
- $admin = Dever::load('manage/auth.data');
- $where['audit_admin'] = $admin['id'];
- Dever::db('bill/tixian')->update(array('where_id' => $id, 'status' => 3, 'audit_admin' => $where['audit_admin'],'operdate' => time()));
- $w = array();
-
- if ($tixian['type'] == 1) {
- $w['where_id'] = $info['mid'];
- $w['cash'] = -1*$tixian['ycash'];
- $w['clear'] = true;
- Dever::db('agent/member')->upCash($w);
- } elseif ($tixian['type'] == 2) {
- $w['where_id'] = $info['shop_id'];
- $w['price'] = -1*$tixian['ycash'];
- $w['clear'] = true;
- Dever::db('shop/info')->upCash($w);
- Dever::db($table)->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
- } elseif ($tixian['type'] == 3) {
- $w['where_id'] = $info['uid'];
- $w['cash'] = -1*$tixian['ycash'];
- $w['clear'] = true;
- Dever::db('passport/user')->upCash($w);
- }
- # 通知短信
- /*
- if (Dever::project('sms')) {
- $member = Dever::db('agent/member')->find($info['mid']);
- Dever::load('sms/api')->send('daili_tixian_no', $member['mobile'], array('name' => $member['name'], 'content' => $desc));
- }
- */
- }
- }
- }
- }
- public function sellUpdate($id, $name, $data)
- {
- Dever::config('base')->hook = true;
- $mid = Dever::param('mid', $data);
- $num = Dever::param('num', $data);
- $desc = Dever::param('desc', $data);
- $type = Dever::param('type', $data);
- $cdate = Dever::param('cdate',$data);
- if(!$cdate){
- $cdate = false;
- } else {
- $cdate = Dever::maketime($cdate);
- }
- if ($mid && $num && $desc) {
- $member = Dever::db('agent/member')->find($mid);
- if ($member && $member['status'] == 2) {
- if ($type == 1) {
- Dever::load('bill/lib/sell.push_one_commit', $mid, $num, $member['role'], $id, $desc,$cdate);
- } else {
- Dever::load('bill/lib/sell.push_all_commit', $mid, $num, $member['role'], $id, $desc,$cdate);
- }
- } else {
- Dever::db('bill/push_sell')->update(array('where_id' => $id, 'status' => 2));
- Dever::alert('代理商未审核通过,发放失败');
- }
- }
- }
- # 获取新增业绩
- public function getSellNewNum($num, $month, $mid)
- {
- $where = array('month' => $month, 'mid' => $mid);
- $search = Dever::search_button();
- if ($search) {
- $where['config']['group'] = $search[0];
- $where['config']['col'] = str_replace('|id', '', $search[1]);
- }
- if ($num < 0) {
- $num = 0;
- }
- $new_num = 0;
- $prev = Dever::db('bill/sell_stat')->prev($where);
- if ($prev && $num > 0 && $prev['num'] >= 0) {
- $new_num = $num - $prev['num'];
- }
- return $new_num;
- }
- #提现导出
- public function tixian_out($data){
- $header = array('提现单号', '姓名', '手机号', '身份证号', '会员角色', '提现金额', '到账金额', '手续费金额', '申请时间', '审核时间', '审核状态', '发放时间','发放状态','审核人', '来源');
- $body = array();
- foreach($data as $k => $v){
- $member = Dever::db('agent/member')->find(array('id'=>$v['mid']));
- $role = Dever::db('setting/role')->find(array('id'=>$member['role']));
-
- if($v['status'] == -1){
- $status = '未审核待发放';
- $audit = '待审核';
- }elseif($v['status'] == 1){
- $status = '已审核待发放';
- $audit = '已审核';
- }elseif($v['status'] == 2){
- $status = '已发放';
- $audit = '已审核';
- }else{
- $status = '已作废';
- $audit = '已作废';
- }
- $cdate = date('Y-m-d H:i',$v['cdate']);
- if ($v['type'] == 1) {
- $cash = Dever::db('bill/cash')->find($v['cash_id']);
- } elseif ($v['type'] == 2) {
- $cash = Dever::db('shop/record')->find($v['cash_id']);
- } elseif ($v['type'] == 3) {
- $cash = Dever::db('shop/user_money')->find($v['cash_id']);
- }
-
- if ($cash['operdate']) {
- $adate = date('Y-m-d H:i',$cash['operdate']);
- } else {
- $adate = '-';
- }
- if ($v['operdate']) {
- $operdate = date('Y-m-d H:i',$v['operdate']);
- } else {
- $operdate = '-';
- }
-
- if($v['audit_admin']){
- $admin = Dever::load('manage/admin-find',$v['audit_admin']);
- $username = $admin['username'];
- }else{
- $username = '';
- }
-
- if($v['ycash'] < 0){
- $ycash = $v['ycash'] * (-1);
- }else{
- $ycash = $v['ycash'];
- }
- if($v['cash'] < 0){
- $cash = $v['cash'] * (-1);
- }else{
- $cash = $v['cash'];
- }
- $d = array
- (
- $v['order_num'],
- $member['name'],
- $member['mobile'],
- $member['idcard'],
- $role['name'],
- $ycash,
- $cash,
- $ycash-$cash,
- $cdate,
- $adate,
- $audit,
- $operdate,
- $status,
- $username,
- '',
- );
- $body[] = $d;
- }
- $file = Dever::input('excel_name');
- return Dever::excelExport($body, $header, $file);
- }
- #归店统计导出
- public function out_shop_stat($data){
- $header = array('月份', '门店名称','门店编号','门店联系人','联系人手机号','联系人身份证','所属代理商', '区域招商补贴', '名额外创V补贴', '补贴总金额', '采购金额','归店业绩(除创V外)','代理商数','创客数','创V数','名额外创V','名额外创V业绩', '确认状态', '发放状态');
- $body = array();
- foreach($data as $k => $v){
- $month = date('Y-m',$v['month'])."\t";
- $shop = Dever::db('shop/info')->find(array('id'=>$v['shop_id']));
- if ($shop['type'] != 1) {
- continue;
- }
- if($shop['mid'] && $shop['mid'] >0){
- $member = Dever::db('agent/member')->find($shop['mid']);
- if($member){
- $dl_mobile = $member['mobile'];
- }else{
- $dl_mobile = '-';
- }
- }else{
- $dl_mobile = '-';
- }
- $shop_truename = '';
- if ($shop['truename']) {
- $shop_truename = $shop['truename'];
- }
- $shop_mobile = '';
- if ($shop['mobile']) {
- $shop_mobile = $shop['mobile'];
- }
- $shop_idcard = '';
- if ($shop['idcard']) {
- $shop_idcard = $shop['idcard'];
- }
- $status_name = '';
- if ($v['status'] == 1) {
- $status_name = '已确认';
- } elseif ($v['status'] == 2) {
- $status_name = '未确认';
- }
- $cash_status_name = '';
- if ($v['cash_status'] == 1) {
- $cash_status_name = '已发放';
- } elseif ($v['cash_status'] == 2) {
- $cash_status_name = '未发放';
- }
- $d = array
- (
- $month,
- $shop['name'],
- $shop['sid'],
- $shop_truename,
- $shop_mobile,
- $shop_idcard,
- $dl_mobile,
- $v['dl_subsidy'],
- $v['v_subsidy'],
- $v['dl_subsidy'] + $v['v_subsidy'],
- $v['c_money'],
- $v['dl_money'],
- $v['dl_num'],
- $v['ck_num'],
- $v['v_num'],
- $v['out_num'],
- $v['out_money'],
- $status_name,
- $cash_status_name,
- );
- $body[] = $d;
- }
- $file = Dever::input('excel_name');
- return Dever::excelExport($body, $header, $file);
- }
- #归店列表显示
- public function shop_stat_api($id){
- $info = Dever::db('bill/shop_stat')->find($id);
- $shop = Dever::db('shop/info')->find($info['shop_id']);
- $html = $shop['name'];
- $html .= '<br />' .$shop['sid'];
- if($shop['agent_mid'] && $shop['agent_mid']>0){
- $member = Dever::db('agent/member')->find($shop['agent_mid']);
- if($member){
- $html .= '<br />' .$member['name'].$member['mobile'];
- }
- }
- return $html;
- }
- public function guidian($mid){
- $member = Dever::db('agent/member')->find($mid);
- $area = Dever::load("area/api.string", $member['area']);
- $data = array();
- $data = $member['name'].'<br/>'.$member['mobile'].'<br/>'.$area;
- return $data;
- }
- public function role($mid){
- $member = Dever::db('agent/member')->find($mid);
- $role = Dever::db('setting/role')->find($member['role']);
- $data = array();
- $prize_type = '';
- if($member['role'] == 8 && $member['prize_type'] == 1){
- $prize_type = '(名额外)';
- }elseif($member['role'] == 8 && $member['prize_type'] == 2){
- $prize_type = '(名额内)';
- }
- $data = $role['name'].$prize_type;
- return $data;
- }
- public function yeji($mid){
- $start = Dever::input('search_option_start_dever_time');
- $end = Dever::input('search_option_dever_time');
- $where['start'] = $start;
- $where['end'] = $end;
- $where['mid'] = $mid;
- $where['state'] = 1;
- $money = Dever::db('agent/order')->getCount($where);
- return $money['total'];
- }
- }
|