123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- <?php
- namespace Cash\Lib;
- use Dever;
- class Set
- {
- public function getCash($cash)
- {
- if (!$cash || $cash <= 0) {
- return 0;
- }
- return round($cash, 2);
- }
- public function info($audit_type, $audit)
- {
- $config = Dever::db('cash/order')->config;
- return $config['config_audit_type'][$audit_type] . $config['config_audit'][$audit];
- }
- public function statDate($type, $day)
- {
- if ($type == 1) {
- $string = 'Y年m月';
- } elseif ($type == 2) {
- $string = 'Y年W周';
- } else {
- $string = 'Y年m月d日';
- }
- return date($string, $day);
- }
- public function statYes($info, $type, $source = false)
- {
- $table = 'cash/' . $type;
- if ($type == 'shop_sell') {
- $type = 'shop';
- }
- $info = is_array($info) ? $info : Dever::db($table)->one($info);
- $other = Dever::db($type . '/info')->find($info[$type . '_id']);
- if (!$other) {
- return '';
- }
- if ($type == 'store') {
- return $this->statDate($info['type'], $info['day']) . '与'.$other['name'].'对账单数量是否正确<br />对账数量' . $info['num'] . '个';
- }
- return $this->statDate($info['type'], $info['day']) . '与'.$other['name'].'对账单款项是否正确<br />对账金额¥' . round($info['cash'],2) . '元';
- }
- public function statTime($start, $end)
- {
- return date('Y-m-d', $start) . ' ~ ' . date('Y-m-d', $end);
- }
- public function orderUpdate_commit($id, $name, $data)
- {
- Dever::config('base')->hook = true;
- $update = array();
- $audit = Dever::param('audit', $data);
- $info = Dever::db('cash/order')->one($id);
- if ($audit > 1 && $info['refund_id'] && $info['refund_id'] > 0) {
- Dever::load('shop/lib/refund')->set('buy')->action($info['refund_id'], $audit, false, false);
- if ($audit == 2) {
- $state = Dever::db('cash/order')->update(array('where_id' => $id, 'status' => 2, 'operdate' => time(), 'fdate' => time()));
- $order = Dever::db('shop/buy_order')->find(array('id' => $info['source_order_id'], 'clear' => true));
- if ($state && $info['jstype'] == 2 && isset($order['status']) && $order['status'] == 8) {
- # 如果是退款结算,同时要把主订单也结算
- $where = array();
- $where['source_order_id'] = $order['id'];
- $where['jstype'] = 1;
- $where['audit'] = 1;
- $info = Dever::db('cash/order')->find($where);
- if ($info) {
- $set['status'] = 2;
- $set['audit'] = 2;
- $set['where_id'] = $info['id'];
- $set['operdate'] = time();
- $set['fdate'] = time();
- Dever::db('cash/order')->update($set);
- }
- }
- }
- }
- }
- # 审核对账
- public function audit_api()
- {
- Dever::config('base')->hook = true;
- $id = Dever::input('id');
- $type = Dever::input('type', 'shop');
- $table = 'cash/' . $type;
- $data = Dever::db($table)->one($id);
-
- if ($data) {
- Dever::db($table)->update(array('where_id' => $id, 'status' => 2));
- if ($type == 'shop_sell' && $data['cash'] > 0) {
- return 'reload';
- $card = Dever::db('cash/order')->getCardAll(array('start'=>$data['start'],'end'=>$data['end'],'pay_type'=>2,'status'=>2,'type'=>1,'type_id'=>$data['shop_id'],'state'=>1));
- $shop = Dever::db('shop/info')->find($data['shop_id']);
- if ($card && $card['cash'] > 0) {
- $cash = sprintf("%01.2f", $card['cash']);
- $yue = $shop['price'] + $cash;
- $explan = date('Y年m月d日',$data['end']).'礼品卡对账金额';
- Dever::load('shop/lib/record')->pingtai($data['shop_id'],$shop['sid'],8,$data['shop_id'],$cash,$yue,$explan);
- }
- $bao = Dever::db('cash/order')->getCardAll(array('start'=>$data['start'],'end'=>$data['end'],'pay_type'=>3,'status'=>2,'type'=>1,'type_id'=>$data['shop_id'],'state'=>1));
- if($bao && $bao['cash']>0){
- $shop = Dever::db('shop/info')->find(array('id'=>$shop['id'],'s'=>1));
- $cash = sprintf("%01.2f", $bao['cash']);
- $yue = $shop['price'] + $cash;
- $explan = date('Y年m月d日',$data['end']).'钱包对账金额';
- Dever::load('shop/lib/record')->pingtai($data['shop_id'],$shop['sid'],8,$data['shop_id'],$cash,$yue,$explan);
- }
- }
- }
- return 'reload';
- }
- # 批量审核对账
- public function auditShopMul($id, $name, $data)
- {
- Dever::config('base')->hook = true;
- $table = 'cash/shop';
- if ($id) {
- $list = explode(',', $id);
- if ($list) {
- foreach ($list as $k => $v) {
- $data = Dever::db($table)->one($v);
-
- if ($data) {
- Dever::db($table)->update(array('where_id' => $v, 'status' => 2));
- }
- }
- }
- }
- return 'reload';
- }
- # 审核对账
- public function audit_other_api()
- {
- $id = Dever::input('id');
- $type = Dever::input('type', 'shop');
- $table = 'cash/' . $type;
- $info = Dever::db($table)->one($id);
- if ($info) {
- Dever::db($table)->update(array('where_id' => $id, $type . '_status' => 2));
- }
- return 'reload';
- }
- # 查看对账单详情
- public function view_api()
- {
- $id = Dever::input('id');
- if (!$id) {
- return false;
- }
- $show = Dever::input('show', 1);
- $type = Dever::input('type', 'shop');
- $pay_type = 1;
- $table = 'cash/' . $type;
- $source_type = $type;
- if ($type == 'shop') {
- $search_option_type = 1;
- $name = '门店';
- } if ($type == 'shop_sell') {
- $search_option_type = 1;
- $pay_type = '2,3';
- $name = '门店零售';
- $type = 'shop';
- } elseif ($type == 'store') {
- $search_option_type = 3;
- $name = '仓库';
- } elseif ($type == 'factory') {
- $search_option_type = 2;
- $name = '工厂';
- }
- $config = Dever::db($table)->config;
- $info = Dever::db($table)->one($id);
- $status = $config['config_status'][$info['status']];
- $other_status = $config['config_status'][$info[$type . '_status']];
- $other = Dever::db($type . '/info')->find($info[$type . '_id']);
- $html = '<div class="layui-col-md12"><div class="layui-card"><div class="layui-card-header">对账单详情</div><div class="layui-card-body">';
- $html .= '<table class="layui-table"><tbody>';
- $html .= '<tr>
- <td width="100">对账'.$name.'</td>
- <td>'.$this->table(false, array(array($other['name']))).'</td>
- </tr>';
- $html .= '<tr>
- <td width="80">对账时间</td>
- <td>'.$this->table(false, array(array($this->statDate($info['type'], $info['day'])))).'</td>
- </tr>';
- $html .= '<tr>
- <td width="80">对账周期</td>
- <td>'.$this->table(false, array(array($this->statTime($info['start'], $info['end'])))).'</td>
- </tr>';
- if ($type == 'store') {
- $html .= '<tr>
- <td width="80">商品数量</td>
- <td>'.$this->table(false, array(array($info['num']))).'</td>
- </tr>';
- } else {
- $html .= '<tr>
- <td width="80">对账金额</td>
- <td>'.$this->table(false, array(array('¥' . round($info['cash'], 2)))).'</td>
- </tr>';
- }
- if ($show == 1) {
-
- $manage_config = Dever::db('main/manage_config')->find();
- $s = 2;
- if ($table == 'cash/shop' && $manage_config['buy_dz'] == 1) {
- $s = 1;
- }
- if ($table == 'cash/shop_sell' && $manage_config['sell_dz'] == 1) {
- $s = 1;
- }
- if ($s == 1) {
- $html .= '<tr>
- <td width="80">'.$name.'对账状态</td>
- <td>'.$this->table(false, array(array($other_status))).'</td>
- </tr>';
- }
- $html .= '<tr>
- <td width="100">平台对账状态</td>
- <td>'.$this->table(false, array(array($status))).'</td>
- </tr>';
-
- } else {
- $html .= '<tr>
- <td width="80">对账状态</td>
- <td>'.$this->table(false, array(array($other_status))).'</td>
- </tr>';
- }
- $button = array();
- if ($show == 1) {
- if ($info['status'] == 1) {
- $url = Dever::url('lib/set.audit&id='.$id.'&type=' . $source_type, 'cash');
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $source_type).'\', \'请确认\')">立即确认</button>';
- }
- $config['phone'] = '联系人:' . $other['truename'] . ',联系电话:' . $other['mobile'];
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系'.$name.'</button>';
- $start = date('Y-m-d H:i:s', $info['start']);
- $end = date('Y-m-d H:i:s', $info['end']);
- $out = Dever::url('lib/set.excel?id=' . $info['id'] . '&type=' . $source_type, 'cash');
-
- $button[] = '<a class="layui-btn layui-btn-primary" href="'.$out.'">导出对账单</a>';
- } elseif ($show == 2) {
- if ($info[$type . '_status'] == 1 && $show != 1) {
- $url = Dever::url('lib/set.audit_other&id='.$id.'&type=' . $source_type, 'cash');
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $source_type).'\', \'请确认\')">立即确认</button>';
- }
- $config = Dever::load('factory/admin/auth.config');
- $config['phone'] = '联系电话:' . $config['dz_phone'];
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系对账专员</button>';
-
- $print = Dever::url('admin/stat.print?id=' . $info['id'] . '&type=' . $source_type, $type);
- $button[] = '<a class="layui-btn layui-btn-primary" href="'.$print.'" target="_blank">打印对账单</a>';
- }
-
- $html .= '<tr>
- <td>功能按钮</td>
- <td>'.$this->table(false, array($button)).'</td>
- </tr>';
- $html .= '</tbody></table></div></div>';
- $data = $this->getOrderData($type, $info, '', $pay_type);
- if ($data) {
-
- $body = array();
- $config = Dever::db('cash/order')->config;
- foreach ($data as $k => $v) {
- $cdate = date('Y-m-d H:i', $v['cdate']);
- $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
- $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
- $noprice = 2;
- if ($type == 'factory') {
- $set_type = 2;
- $cash = '¥' . round($v['p_cash'], 2);
- } else {
- $cash = '¥' . round($v['cash'], 2);
- $set_type = 1;
- }
- if ($show == 1) {
- if ($v['source_type'] == 4) {
- $url = Dever::url('project/database/list?project=shop&table=sell_order_goods&order_id='.$v['source_order_id'].'&page_type=1&noprice=' . $noprice . '&type=' . $set_type, 'manage');
- } else {
- $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1&noprice=' . $noprice . '&type=' . $set_type, 'manage');
- }
-
- $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
- $head = array('结算单号', '订货单号', '结算类型', '下单日期', '完成日期', '结算日期', '对账金额');
- if ($type == 'store') {
- $head[6] = '商品数量';
- }
- $head[] = '结算状态';
- $d = array
- (
- $v['order_num'],
- $v['source_order_num'],
- $config['config_jstype'][$v['jstype']],
- $cdate,
- $fdate,
- $operdate,
- $cash,
- );
- if ($type == 'store') {
- $d[6] = $v['num'];
- }
- $d[] = '已入账';
- $body[] = $d;
- } else {
- $head = array('订货单号', '下单日期', '完成日期', '对账金额');
- if ($type == 'store') {
- $head[3] = '商品数量';
- }
- $head[] = '状态';
- $d = array
- (
- $v['source_order_num'],
- $cdate,
- $fdate,
- $cash,
- );
- if ($type == 'store') {
- $d[3] = $v['num'];
- }
- $d[] = '已入账';
- $body[] = $d;
- }
- }
- $page = Dever::page("current");
- $html .= '<div class="layui-card"><div class="layui-card-header">对账清单</div><div class="layui-card-body" style="max-heights: 500px;overflow: auto;">' . $this->table($head, $body) . $page . '</div></div>';
- }
- $html .= '</div>';
- return '<div class="layui-card-body">' . $html . '</div>';
- }
- private function table($head, $data)
- {
- $html = '';
- if ($head) {
- $html = '<table class="layui-table">';
- $html .= '<thead><tr>';
- foreach ($head as $k => $v) {
- $html .= '<th>'.$v.'</th>';
- }
- $html .= '</tr></thead>';
- $html .= '<tbody>';
- foreach ($data as $k => $v) {
- $html .= '<tr>';
- foreach ($v as $k1 => $v1) {
- $html .= '<td>'.$v1.'</td>';
- }
- $html .= '</tr>';
- }
- $html .= '</tbody>';
- $html .= '</table>';
- } else {
- foreach ($data as $k => $v) {
- $html .= '';
- foreach ($v as $k1 => $v1) {
- $html .= $v1 . ' ';
- }
- $html .= '';
- }
- }
- return $html;
- }
- # 导出对账单
- public function excel_api()
- {
- $type = Dever::input('type');
- $id = Dever::input('id');
- $table = 'cash/' . $type;
- $pay_type = 1;
- if ($type == 'shop_sell') {
- $pay_type = '2,3';
- $type = 'shop';
- }
- $config = Dever::db($table)->config;
- $info = Dever::db($table)->one($id);
- $data = $this->getOrderData($type, $info, 'NoPage', $pay_type);
- $stat_type = Dever::db('cash/shop')->config['config_type'];
- $other = Dever::db($type . '/info')->find($info[$type . '_id']);
- $status = $config['config_status'][$info['status']];
- $other_status = $config['config_status'][$info[$type . '_status']];
- $info['name'] = Dever::load('cash/lib/set')->statDate($stat_type, $info['day']);
- $info['status_name'] = $status;
- $file = $other['name'] . '的' . $info['name'] . '对账单';
- $header = $body = array();
- $header = array
- (
- 'top' => array
- (
- $file . ' ' . $info['status_name'] . ' 对账金额¥' . $info['cash']. ' 商品数量¥' . $info['num'],
- ),
- '结算单号',
- '订货单号',
- '结算类型',
- '下单日期',
- '完成日期',
- '结算日期',
- '对账金额',
- '礼品卡卡号',
- '礼品卡抵扣金额',
- );
- if ($type == 'store') {
- $head[6] = '商品数量';
- }
- $head[] = '结算状态';
- if ($data) {
- $body = array();
- foreach ($data as $k => $v) {
- $cdate = date('Y-m-d H:i', $v['cdate']);
- $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
- $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
- if ($type == 'factory') {
- $cash = '¥' . round($v['p_cash'], 2);
- } else {
- $cash = '¥' . round($v['cash'], 2);
- }
- $card_code_card = '';
- $card_code_cash = '';
- if ($v['pay_type'] == 2) {
- $sell_order = Dever::db('shop/sell_order')->find($v['source_order_id']);
- if ($sell_order) {
- $card_code_card = $sell_order['card_code_card'];
- $card_code_cash = $sell_order['card_code_cash'];
- }
- }
- $jstype = Dever::db('cash/order')->config['config_jstype'][$v['jstype']];
- $body[$k][0] = $v['order_num'];
- $body[$k][1] = $v['source_order_num'];
- $body[$k][2] = $jstype;
- $body[$k][3] = $cdate;
- $body[$k][4] = $operdate;
- $body[$k][5] = $fdate;
- $body[$k][6] = $cash;
- if ($type == 'store') {
- $body[$k][6] = $v['num'];
- }
- $body[$k][7] = $card_code_card;
- $body[$k][8] = $card_code_cash;
- $body[$k][] = '已入账';
- }
- }
- Dever::excelExport($body, $header, $file);
- }
- # 打印订单单
- public function printer($user)
- {
- $id = Dever::input('id');
- if (!$id) {
- return false;
- }
- $type = Dever::input('type', 'shop');
- $table = 'cash/' . $type;
- $pay_type = 1;
- if ($type == 'shop') {
- $name = '门店';
- } elseif ($type == 'shop_sell') {
- $pay_type = '2,3';
- $name = '门店';
- $type = 'shop';
- } elseif ($type == 'store') {
- $name = '仓库';
- } elseif ($type == 'factory') {
- $name = '工厂';
- }
- $config = Dever::db($table)->config;
- $info = Dever::db($table)->one($id);
- $status = $config['config_status'][$info['status']];
- $other_status = $config['config_status'][$info[$type . '_status']];
- $other = Dever::db($type . '/info')->find($info[$type . '_id']);
- $member = Dever::db($type . '/member')->find($user['id']);
- $factory_config = Dever::db('main/factory_config')->find();
- $main_config = Dever::db('main/config')->find();
- $pdf = Dever::load('pdf/lib/base')->init();
- $pdf->hr('-', $other['name']);
- $pdf->br()->font(20)->center('对账周期:' . $this->statTime($info['start'], $info['end']));
- $pdf->font(10);
- $pdf->br();
- $pdf->br()->left('对账日期:' . $this->statDate($info['type'], $info['day']), 80)->left('制单人:' . $member['name'], 60)->left('制单时间:' . date('Y-m-d H:i'), 40);
- $pdf->hr();
- $data = $this->getOrderData($type, $info, 'NoPage', $pay_type);
- $body = array();
- $body_total = array();
- $body_total['cash'] = 0;
- $body_total['num'] = 0;
- if ($data) {
- foreach ($data as $k => $v) {
- $cdate = date('Y-m-d H:i', $v['cdate']);
- $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
- $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
- $prefix = '¥';
- if ($type == 'store') {
- $cash = $v['num'];
- $prefix = '';
- } elseif ($type == 'factory') {
- $cash = $v['p_cash'];
- } else {
- $cash = $v['cash'];
- }
- $cash = round($cash, 2);
- $body[] = array
- (
- $v['source_order_num'],
- $cdate,
- $fdate,
- $prefix . $cash,
- '已入账'
- );
- $body_total['cash'] += $cash;
- $body_total['num'] += 1;
- }
- }
- $head = array(array('订单号', 60), array('下单日期', 43), array('完成日期', 43), array('对账金额', 30), array('状态', 20));
- if ($type == 'store') {
- $head[3][0] = '对账数量';
- }
- if ($body) {
- $pdf->br();
- foreach ($head as $k => $v) {
- $pdf->left($v[0], $v[1]);
- }
- foreach ($body as $k => $v) {
- $pdf->br();
- foreach ($head as $k1 => $v1) {
- $pdf->left($v[$k1], $v1[1]);
- }
- }
- $pdf->br();
- if ($type == 'store') {
- $pdf->right('共'.$body_total['num'].'个订单,合计对账数量' . $body_total['cash'] . '个');
- } else {
- $pdf->right('共'.$body_total['num'].'个订单,合计对账金额¥' . $body_total['cash'] . '元');
- }
-
- $pdf->hr();
- }
- $pdf->br(1);
- //$pdf->SetY(-100);
-
- $pdf->right('如遇任何问题请致电客服');
- $pdf->br();
- $pdf->font(20);
- $pdf->left($main_config['name'], 160);
- $pdf->font(10);
- $pdf->right('电话:' . $factory_config['phone'], 30);
- $pdf->br();
- $pdf->left($main_config['site'], 160);
- $pdf->font(10);
- $pdf->right($main_config['worktime'], 30);
- $pdf->out('对账单');
- }
- # 获取对账单数据
- public function getOrderData($type, $info, $page = 'NoPage', $pay_type = 1)
- {
- $id = $info[$type . '_id'];;
- if ($type == 'shop' || $type == 'shop_sell') {
- $where['type'] = 1;
- $where['type_id'] = $id;
- $where['pay_type'] = $pay_type;
- $m = 'getAll';
- } elseif ($type == 'factory') {
- $where['source_type'] = 3;
- $where['source_id'] = $id;
- $m = 'getAll';
- } else {
- $where['type'] = 2;
- $where['type_id'] = $id;
- $where['source_type'] = 2;
- $where['source_id'] = $id;
- $m = 'getAllByStore';
- }
- $m .= $page;
-
- $where['status'] = 2;
- $where['start'] = $info['start'];
- $where['end'] = $info['end'];
- return Dever::db('cash/order')->$m($where);
- }
- }
|