123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523 |
- <?php
- namespace Agent\Lib;
- use Dever;
- Class Soft_cash
- {
- public function updateSoft($id, $name, $data){
- // print_R($data);die;
- $mobile = Dever::param('mobile', $data);
- $cash = Dever::param('cash', $data);
- $price = Dever::param('price', $data);
- $pic = Dever::param('pic', $data);
- $status = Dever::param('status', $data);
- $audit = Dever::param('audit', $data);
- $audit_desc = Dever::param('audit_desc', $data);
- $cdate = Dever::param('cdate',$data);
- $buy_cdate = Dever::param('buy_cdate',$data);
- $soft = Dever::db('agent/soft_cash')->one($id);
- $info = Dever::db('agent/member')->find(array('mobile'=>$soft['mobile']));
- if($info){
- $update['where_id'] = $id;
- $update['set_mid'] = $info['id'];
- $update['set_role'] = $info['role'];
- if (!$soft['order_num']) {
- $update['set_order_num'] = $this->getOrderId($id);
- }
-
- if($cash){
- $update['set_cash'] = $cash;
- } else {
- $cash = $soft['cash'];
- }
- if($price){
- $update['set_price'] = $price;
- }
- if($pic){
- $update['set_pic'] = $pic;
- }
- if($status){
- $update['set_status'] = $status;
- }
- if($audit){
- $update['set_audit'] = $audit;
- }
- if($audit_desc){
- $update['set_audit_desc'] = $audit_desc;
- }
-
- if($soft){
- if($audit == 3 ){
- $update['set_status'] = 4;
- } elseif($audit == 2){
- $update['set_status'] = 3;
- $update['set_zdate'] = time();
- $order['role'] = $info['role'];
- $order['soft_cash'] = $cash;
- $order['price'] = $cash;
- $order['cdate'] = $cdate;
- $order['type'] = 3;
- $order['sign'] = '';
- $order['name'] = $info['name'];
- $order['mobile'] = $info['mobile'];
- $order['mid'] = $info['id'];
- $order['id'] = $id;
- $order['area'] = $info['area'];
- $order['idcard'] = $info['idcard'];
- $order['idcard_front'] = $info['idcard_front'];
- $order['idcard_back'] = $info['idcard_back'];
- $order['company_name'] = $info['company_name'];
- $order['company_pic'] = $info['company_pic'];
- // print_R($order);die;
- $update['set_agreement_id'] = Dever::load('agent/lib/agreement')->up($order,1,3);
- }
-
- }
-
- if (!$audit) {
- if ($soft['status'] == 4) {
- $update['status'] = 2;
- }
- }
- if ($soft) {
- if ($soft['audit_admin'] <1 || !$soft['audit_admin']) {
- $admin = Dever::load('manage/auth.info');
- $update['audit_admin'] = $admin['id'];
- }
- }
- $ids=Dever::db('agent/soft_cash')->update($update);
- }
- }
- public function admin_name($id)
- {
- if ($id < 1) {
- return '';
- } else {
- $audit = Dever::db('manage/admin')->find($id);
- // print_R($audit);die;
- return $audit['username'];
- }
-
- }
- public function getOrderId($id)
- {
- $order = Dever::order();
- $info = Dever::db('agent/soft_cash')->one(array('order_num'=>$order));
- if ($info) {
- return $this->createOrderId($id);
- } else {
- return $order;
- }
- }
- public function soft_show($id){
- $info = Dever::db('agent/soft_cash')->find($id);
- $html['num'] = $info['order_num'].'</br>'.date('Y-m-d',$info['buy_date']).'<br/>'.date('Y-m-d',$info['cdate']);
- return $html;
- }
- public function show(){
- $id = Dever::input('id');
- $info = Dever::db('agent/soft_cash')->one($id);
- $member = Dever::db('agent/member')->one($info['mid']);
- $type = Dever::db('agent/member')->config['config_type'];
- $config_status = Dever::db('agent/soft_cash')->config['config_status'];
- $status = Dever::status($config_status,$info['status']);
- // print_R($status);die;
- $buy_date = date('Y-m-d H:i',$info['buy_date']);
- $role = Dever::db('setting/role')->one($member['role']);
- $area = Dever::load("area/api.string", $member['area']);
- $idcard_pic = '<a href="'.$member['idcard_front'].'" target="_blank"><img src="'.$member['idcard_front'].'" width="100" /></a>';
- if ($member['idcard_back']) {
- $idcard_pic .= '<a href="'.$member['idcard_back'].'" target="_blank"><img src="'.$member['idcard_back'].'" width="100" /></a>';
- }
- $picture = explode(',',$info['pic']);
- $pic = '';
- foreach ($picture as $k => $v){
- $pic .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100" /></a>';
- }
- $result['订单信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('订单号', $info['order_num']),
- array('订单状态', $status),
- array('购买时间', $buy_date),
- ),
- array
- (
- array('备注', $info['audit_desc']),
- array('管理员备注', $info['admin_desc']),
- // array('购买时间', $buy_date),
- ),
- ),
- );
- $result['代理商信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('手机号', $member['mobile']),
- array('名称', $member['name']),
- array('类型', $type[$member['type']]),
- ),
- array
- (
- array('代理商角色', $role['name']),
- array('代理区域', $area),
- array('身份证号', $member['idcard']),
- ),
- array
- (
- array('身份证照片', $idcard_pic),
- ),
- ),
- );
- $result['费用信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('软件服务费', $info['cash']),
- array('原始期权价值', $info['price']),
- ),
- array
- (
- array('支付凭证', $pic),
- ),
- ),
- );
- $button = $this->show_button($info);
- if($info['status'] == 3 ){
- $member_goods = Dever::db('agent/member_agreement')->find($info['agreement_id']);
- if ($member_goods && $member_goods['sign']) {
- $sign_pic = '<a href="'.$member_goods['sign'].'" target="_blank"><img src="'.$member_goods['sign'].'" width="100" /></a>';
- } else {
- $sign_pic = '暂无';
- }
-
- $this->show_agreement($info, $role, $sign_pic, $result);
- }
- $head = array
- (
- 'name' => '基本信息',
- 'btn' => $button,
- );
-
- // $foot = $button;
- $html = Dever::show($head, $result);
- return $html;
- }
- public function show_button($info){
- $button = array();
- $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&col=audit_desc', 'manage');
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => $purl,
- 'name' => '备注',
- );
- $purl = Dever::url('project/database/update&project=agent&&page_type=2&table=soft_cash&menu=agent&search_option_state=1&where_id='.$info['id']);
- if($info['status'] < 3 || $info['status'] == 4){
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => $purl,
- 'name' => '修改信息',
- );
-
- }
- $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&audit=2&col=id,audit,audit_desc', 'manage');
- // if($aduit)
- if($info['status'] == 1){
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => $purl,
- 'name' => '待业务初审',
- );
- }
- $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&audit=2&col=id,audit,audit_desc', 'manage');
- if (Dever::load('manage/auth')->checkFunc('agent.soft_cash', 'edit1', '待财务终审')) {
- if($info['status'] == 2){
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => $purl,
- 'name' => '待财务终审',
- );
- }
- }
-
- $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&audit=3&col=id,audit,audit_desc', 'manage');
- if (Dever::load('manage/auth')->checkFunc('agent.soft_cash', 'edit2', '驳回')) {
- if($info['status'] == 4){
-
- }
- }
- if (Dever::load('manage/auth')->checkFunc('agent.soft_cash', 'close', '取消订单')) {
- if ($info['status'] == 4) {
- # 未完成审核的订单,可以随时挂起
- $button[] = array
- (
- 'type' => 'action',
- 'link' => Dever::url('lib/soft_cash.setOrderStatus?id=' . $info['id'] . '&value=4', 'agent'),
- 'name' => '取消订单',
- );
- }
- }
- $button[] = array
- (
- 'type' => 'link',
- 'link' => 'refer',
- 'name' => '返回上一页',
- );
- return $button;
- }
- public function setOrderStatus_api()
- {
- $where['where_id'] = Dever::input('id');
- $order = Dever::db('agent/soft_cash')->find($where['where_id']);
- if ($order) {
- $where['status'] = Dever::input('value');
- if ($where['status'] == 4) {
- $where['status'] = 5;
- $where['state'] = 2;
- }
- // print_R($where);die;
- Dever::db('agent/soft_cash')->update($where);
- }
-
- return 'reload';
- }
- private function show_agreement($info, $role, $sign_pic, &$result)
- {
- $table = array();
- $table['head'] = array('合同类型', '合同名称', '合同签名', '合同状态');
- $table['body'] = array();
- $agreement_type = Dever::db('setting/agreement')->config['config_type'];
- $agreement_status = Dever::db('agent/member_agreement')->config['status'];
- if($info['status'] == 3 && $info['agreement_id']){
- $agreement_title = '(已生成合同)';
- $agreement_button = array();
- $agreement = Dever::db('agent/member_agreement')->find(array('id' => $info['agreement_id']));
- if($agreement){
- $agreement_info = Dever::db('setting/agreement')->find($agreement['agreement_id']);
- // print_r($agreement_info);die;
- $agreement_status_name = Dever::status($agreement_status, $agreement['status']);
- // echo dever::sql();die;
- $table['body'] = array(Dever::status($agreement_type, $agreement_info['type']), Dever::load('agent/lib/agreement')->name($agreement_info, $agreement, $role, 2), $sign_pic, $agreement_status_name);
- }else{
- $agreement_title = '';
- }
- }
- $result['生成软件服务合同' . $agreement_title] = array
- (
- 'type' => 'table',
- 'head' => array('name' => ' ', 'btn' => $agreement_button),
- 'content' => $table
- );
- }
- public function insertSoft($id,$name,$data){
- $mobile = Dever::param('mobile',$data);
- $member = Dever::db('agent/member')->find(array('mobile'=>$mobile));
- if(!$member){
- Dever::alert('代理商不存在');
- }
- }
- public function search_api()
- {
- $value = Dever::input('value');
- if(!preg_match('/^1[3|5|6|7|8|9]\d{9}$/', $value)){
- return '代理商手机号不正确';
- }
- if ($value) {
- $data = Dever::db('agent/member')->one(array('mobile' => $value,'state' =>1));
- $table = array();
- $table['body'] = array();
- if ($data) {
- $info = Dever::db('agent/soft_cash')->find(array('mobile'=>$value));
- if ($info) {
- $info['buy_date'] = '<p style="color:red">'.date('Y-m-d H:i',$info['buy_date']).'</p>';
- $table['head'] = array('序列号', '姓名', '手机号','上次购买时间');
- $table['body'] = array($data['id'], $data['name'], $data['mobile'],$info['buy_date']);
- } else {
- $table['head'] = array('序列号', '姓名', '手机号');
- $table['body'] = array($data['id'], $data['name'], $data['mobile']);
- }
-
-
- // $table['head'] = array('序列号', '姓名', '手机号','上次购买时间');
-
- // $table['body'] = array($data['id'], $data['name'], $data['mobile']);
- // foreach ($data as $k => $v) {
- // $member = Dever::db('agent/member')->find($v['mid']);
- // $table['body'][] = array($k+1, $member['name'], $v['mobile']);
- // }
- $result[] = array
- (
- 'type' => 'table',
- 'content' => $table,
- );
- $html = Dever::show('', $result, false, false);
- return $html;
- }else{
- return '代理商不存在';
- // Dever::alert('代理商不存在');
- }
- // Dever::alert('暂无账号');
- // return '暂无账号';
- } else {
- return '';
- }
- }
- public function list($id){
- $info = Dever::db('agent/soft_cash')->find(array('id'=>$id));
- $config_status = Dever::db('agent/soft_cash')->config['config_status'];
- $data['status'] = Dever::status($config_status,$info['status'],true);
- $config_type = Dever::db('agent/soft_cash')->config['config_type'];
- $data['type'] = Dever::status($config_type,$info['type']);
- if($info['zdate']){
- $data['zdate'] = date('Y-m-d H:i',$info['zdate']);
- }else{
- $data['zdate'] = '-';
- }
- if($info['fdate']){
- $data['fdate'] = date('Y-m-d H:i',$info['fdate']);
- }else{
- $data['fdate'] = '-';
- }
- // print_R($data);die;
- $html = $data['status'];
- $html .= '<br />' . $data['type'];
- $html .= '<br />' . $data['zdate'];
- $html .= '<br />' . $data['fdate'];
- return $html;
- }
- #数据导出
- public function out_soft_cash_api($data){
- $header = array('合同乙方', '手机号码', '身份证号码','合同总期数(年)', '合同类型', '签订日期', '合同金额', '购买日期', '录入日期', '终审日期');
- $body = array();
- $agreement_name = '';
- foreach($data as $k => $v){
- $member = Dever::db('agent/member')->find($v['mid']);
- $role = Dever::db('setting/role')->find($member['role']);
- $agreement = Dever::db('agent/member_agreement')->find(array('id'=>$v['agreement_id'],'mid'=>$v['mid']));
- if($agreement && $agreement['agreement_id']){
- $name = Dever::db('setting/agreement')->find(array('id'=>$agreement['agreement_id']));
- $config_type= Dever::db('setting/agreement')->config['config_type'];
- $agreement_name = Dever::status($config_type,$name['type']);
- }
- $type = 2;
- # 这里加判断
- if ($role['type'] == 2 && $role['area'] == 1) {
- $type = 1;
- } elseif ($v['cash'] > 6000 && $v['cash'] <= 30000 && $v['cash']%5000 == 0) {
- $type = 3;
- } elseif ($v['cash'] <= 6000 && $v['cash']%1000 == 0) {
- $type = 4;
- } else {
- $type = 2;
- }
- # 城市代理
- if ($type == 1) {
- $name = '城市代理版';
- $year = 1;
- }
- # 定制版
- elseif ($type == 2) {
- $name = '定制版';
- $year = 1;
- }
- # 升级版
- elseif ($type == 3) {
- $name = '升级版';
- $year = intval($v['cash']/5000);
- if ($year > 6) {
- $year = 6;
- }
- }
- # 基础版
- else {
- $name = '基础版';
- $year = intval($v['cash']/1000);
- if ($year > 6) {
- $year = 6;
- }
- }
- if($v['fdate']){
- $fdate = date('Y-m-d H:i',$v['fdate']);
- }else{
- $fdate = '-';
- }
- if($v['buy_date']){
- $buy_date = date('Y-m-d H:i',$v['buy_date']);
- }else{
- $buy_date = '-';
- }
- if($v['zdate']){
- $zdate = date('Y-m-d H:i',$v['zdate']);
- }else{
- $zdate = '-';
- }
- if($v['cdate']){
- $cdate = date('Y-m-d H:i',$v['cdate']);
- }else{
- $cdate = '-';
- }
- $d = array
- (
- $member['name'],
- $v['mobile'],
- $member['idcard'],
- $year,
- $name,
- $fdate,
- $v['cash'],
- $buy_date,
- $cdate,
- $zdate,
- );
- $body[] = $d;
- }
- $file = Dever::input('excel_name');
- return Dever::excelExport($body, $header, $file);
- }
- public function update_role_api(){
- $data = Dever::db('agent/soft_cash')->state();
- foreach($data as $k => $v){
- if(!$v['role']){
- $member = Dever::db('agent/member')->find($v['mid']);
- $where['where_id'] = $v['id'];
- $where['set_role'] = $member['role'];
- Dever::db('agent/soft_cash')->update($where);
- }
- if(!$v['fdate'] && $v['status'] == 3){
- $agreement = Dever::db('agent/member_agreement')->find(array('id'=>$v['agreement_id'],'mid'=>$v['mid']));
- $where['where_id'] = $v['id'];
- $where['set_type'] = $agreement['status'];
- $where['set_zdate'] = $agreement['qdate'];
- $where['set_fdate'] = $agreement['qdate'];
- Dever::db('agent/soft_cash')->update($where);
- }
- }
- }
- }
|