| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 | 
							- <?php
 
- namespace Card\Lib;
 
- use Dever;
 
- class Manage
 
- {
 
-     # 获取用户信息
 
-     public function user($id)
 
-     {
 
-         $info = Dever::db('card/order')->one($id);
 
-         if ($info['uid'] && $info['uid'] > 0) {
 
-             $user = Dever::db('passport/user')->one($info['uid']);
 
-             $result = $user['username'];
 
-             if ($info['mobile']) {
 
-                 $result .= '('.$info['mobile'].')';
 
-             }
 
-         } else {
 
-             $result = $info['mobile'];
 
-         }
 
-         
 
-         return $result;
 
-     }
 
-     /**
 
-      * 获取礼品卡数量
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function getNum($id)
 
-     {
 
-         //$info = Dever::db('card/info')->find($id);
 
-         $where['card_id'] = $id;
 
-         return Dever::db('card/code')->total($where);
 
-     }
 
-     public function getCardNum($id)
 
-     {
 
-         $where['card_id'] = $id;
 
-         $html = array();
 
-         #兑换的数量
 
-         $dnum = Dever::db('card/code')->getNum(array('card_id'=>$id,'status'=>3,'state'=>1));
 
-         #发放的数量
 
-         $num = Dever::db('card/code')->total($where);
 
-         return $dnum.'/'.$num;
 
-     }
 
-     public function getDprice($id,$type=false){
 
-         $card = Dever::db('card/info')->find($id);
 
-         #已兑换的面值
 
-         $dui_total = 0;
 
-         if($card['create_type'] != 3){
 
-             $dnum = Dever::db('card/code')->getNum(array('card_id'=>$id,'status'=>3,'state'=>1));
 
-             $dui_total = $dnum*$card['value'];
 
-             
 
-         }else{
 
-             $dui = Dever::db('card/code')->getDuiprice(array('card_id'=>$id,'status'=>3,'state'=>1));
 
-             $dui_total = $dui['total'];
 
-         }
 
-         if(!$type){
 
-             return $dui_total;
 
-         }
 
-         #已使用的面值
 
-         $info = Dever::db('card/code')->getDprice(array('card_id'=>$id,'state'=>1));
 
-         $use_total = sprintf ('%01.2f',$info['total']);
 
-         if($type==1){
 
-             return $use_total;
 
-         }
 
-         #未兑换的面值
 
-          $wdui_total = 0;
 
-         if($card['create_type'] != 3){
 
-             $where['card_id'] = $id;
 
-             $num = Dever::db('card/code')->total($where);
 
-             $wdui_total = ($num-$dnum) *$card['value'];
 
-         }else{
 
-             $wdui = Dever::db('card/code')->getDuiprice(array('card_id'=>$id,'status'=>'1,2','state'=>1));
 
-             $wdui_total = $wdui['total'];
 
-         }
 
-         if($type == 2){
 
-             return $wdui_total;
 
-         }
 
-        
 
-     }
 
-     /**
 
-      * 显示用户信息
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function showUserInfo($id)
 
-     {
 
-         $info = Dever::db('card/code')->find($id);
 
-         $table = array();
 
-         if ($info && $info['status'] > 1) {
 
-             if ($info['uid']) {
 
-                 $user = Dever::load('passport/user-one', $info['uid']);
 
-                 if ($user) {
 
-                     $table['购买人'] = $user['username'] . '('.$user['mobile'].')';
 
-                     $table['下单时间'] = date('Y-m-d H:i:s', $info['cdate']);
 
-                     $table['支付时间'] = date('Y-m-d H:i:s', $info['bdate']);
 
-                 }
 
-             }
 
-             if (isset($info['dh_uid']) && $info['dh_uid'] && $info['dh_uid'] > 0) {
 
-                 $user = Dever::load('passport/user-one', $info['dh_uid']);
 
-                 if ($user) {
 
-                     $table['兑换人'] = $user['username'] . '('.$user['mobile'].')';
 
-                     $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
 
-                 }
 
-             }
 
-         }
 
-         if (!$info['total_cash']) {
 
-             $card_info = Dever::db('card/info')->find($info['card_id']);
 
-             $info['total_cash'] = $card_info['value'];
 
-         }
 
-         if (!$info['use_cash']) {
 
-             $info['use_cash'] = 0;
 
-         }
 
-         $table['总面值'] = $info['total_cash'];
 
-         $table['已用面值'] = $info['use_cash'];
 
-         $table['剩余面值'] = $info['total_cash'] - $info['use_cash'];
 
-         if ($table) {
 
-             return Dever::table($table);
 
-         }
 
-         return '暂无';
 
-     }
 
-     /**
 
-      * 更新信息
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function orderPs($id, $name, $data)
 
-     {
 
-         $order_id = Dever::param('order_id', $data);
 
-         if ($order_id) {
 
-             $update['where_id'] = $order_id;
 
-             $update['set_status'] = 3;
 
-             Dever::db('card/order')->update($update);
 
-         }
 
-     }
 
-     /**
 
-      * 更新信息
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function orderSh($id, $name, $data)
 
-     {
 
-         $order_id = Dever::param('order_id', $data);
 
-         if ($order_id) {
 
-             $update['where_id'] = $order_id;
 
-             $update['set_status'] = 4;
 
-             Dever::db('card/order')->update($update);
 
-         }
 
-     }
 
-     # 收货
 
-     public function send_api()
 
-     {
 
-         return Dever::load('card/lib/buy')->send();
 
-     }
 
-     /**
 
-      * 作废
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function drop_api($id)
 
-     {
 
-         $update['where_id'] = $id;
 
-         $update['type'] = 4;
 
-         Dever::db('card/code')->update($update);
 
-         return 'ok';
 
-     }
 
-     public function recovery_api($id)
 
-     {
 
-         $update['where_id'] = $id;
 
-         $update['type'] = 1;
 
-         Dever::db('card/code')->update($update);
 
-         return 'ok';
 
-     }
 
- }
 
 
  |