Manage.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace Card\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. # 获取用户信息
  7. public function user($id)
  8. {
  9. $info = Dever::db('card/order')->one($id);
  10. if ($info['uid'] && $info['uid'] > 0) {
  11. $user = Dever::db('passport/user')->one($info['uid']);
  12. $result = $user['username'];
  13. if ($info['mobile']) {
  14. $result .= '('.$info['mobile'].')';
  15. }
  16. } else {
  17. $result = $info['mobile'];
  18. }
  19. return $result;
  20. }
  21. /**
  22. * 获取礼品卡数量
  23. *
  24. * @return mixed
  25. */
  26. public function getNum($id)
  27. {
  28. //$info = Dever::db('card/info')->find($id);
  29. $where['card_id'] = $id;
  30. return Dever::db('card/code')->total($where);
  31. }
  32. public function getCardNum($id)
  33. {
  34. $where['card_id'] = $id;
  35. $html = array();
  36. #兑换的数量
  37. $dnum = Dever::db('card/code')->getNum(array('card_id'=>$id,'status'=>3,'state'=>1));
  38. #发放的数量
  39. $num = Dever::db('card/code')->total($where);
  40. return $dnum.'/'.$num;
  41. }
  42. public function getDprice($id,$type=false){
  43. $card = Dever::db('card/info')->find($id);
  44. #已兑换的面值
  45. $dui_total = 0;
  46. if($card['create_type'] != 3){
  47. $dnum = Dever::db('card/code')->getNum(array('card_id'=>$id,'status'=>3,'state'=>1));
  48. $dui_total = sprintf ("%01.2f", $dnum*$card['value']);
  49. }else{
  50. $dui = Dever::db('card/code')->getDuiprice(array('card_id'=>$id,'status'=>3,'state'=>1));
  51. $dui_total = sprintf ("%01.2f", $dui['total']);
  52. }
  53. if(!$type){
  54. return $dui_total;
  55. }
  56. #已使用的面值
  57. $info = Dever::db('card/code')->getDprice(array('card_id'=>$id,'state'=>1));
  58. $use_total = sprintf ('%01.2f',$info['total']);
  59. if($type==1){
  60. return $use_total;
  61. }
  62. #未兑换的面值
  63. $wdui_total = 0;
  64. if($card['create_type'] != 3){
  65. $where['card_id'] = $id;
  66. $num = Dever::db('card/code')->total($where);
  67. $wdui_total = sprintf ("%01.2f", ($num-$dnum) *$card['value']);
  68. }else{
  69. $wdui = Dever::db('card/code')->getDuiprice(array('card_id'=>$id,'status'=>'1,2','state'=>1));
  70. $wdui_total = sprintf ("%01.2f", $wdui['total']);
  71. }
  72. if($type == 2){
  73. return $wdui_total;
  74. }
  75. }
  76. /**
  77. * 显示用户信息
  78. *
  79. * @return mixed
  80. */
  81. public function showUserInfo($id)
  82. {
  83. $info = Dever::db('card/code')->find($id);
  84. $table = array();
  85. if ($info && $info['status'] > 1) {
  86. if ($info['uid']) {
  87. $user = Dever::load('passport/user-one', $info['uid']);
  88. if ($user) {
  89. $table['购买人'] = $user['username'] . '('.$user['mobile'].')';
  90. $table['下单时间'] = date('Y-m-d H:i:s', $info['cdate']);
  91. $table['支付时间'] = date('Y-m-d H:i:s', $info['bdate']);
  92. }
  93. }
  94. if (isset($info['dh_uid']) && $info['dh_uid'] && $info['dh_uid'] > 0) {
  95. $user = Dever::load('passport/user-one', $info['dh_uid']);
  96. if ($user) {
  97. $table['兑换人'] = $user['username'] . '('.$user['mobile'].')';
  98. $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
  99. }
  100. }
  101. }
  102. if (!$info['total_cash']) {
  103. $card_info = Dever::db('card/info')->find($info['card_id']);
  104. $info['total_cash'] = $card_info['value'];
  105. }
  106. if (!$info['use_cash']) {
  107. $info['use_cash'] = 0;
  108. }
  109. $table['总面值'] = $info['total_cash'];
  110. $table['已用面值'] = $info['use_cash'];
  111. $table['剩余面值'] = $info['total_cash'] - $info['use_cash'];
  112. if ($table) {
  113. return Dever::table($table);
  114. }
  115. return '暂无';
  116. }
  117. /**
  118. * 更新信息
  119. *
  120. * @return mixed
  121. */
  122. public function orderPs($id, $name, $data)
  123. {
  124. $order_id = Dever::param('order_id', $data);
  125. if ($order_id) {
  126. $update['where_id'] = $order_id;
  127. $update['set_status'] = 3;
  128. Dever::db('card/order')->update($update);
  129. }
  130. }
  131. /**
  132. * 更新信息
  133. *
  134. * @return mixed
  135. */
  136. public function orderSh($id, $name, $data)
  137. {
  138. $order_id = Dever::param('order_id', $data);
  139. if ($order_id) {
  140. $update['where_id'] = $order_id;
  141. $update['set_status'] = 4;
  142. Dever::db('card/order')->update($update);
  143. }
  144. }
  145. # 收货
  146. public function send_api()
  147. {
  148. return Dever::load('card/lib/buy')->send();
  149. }
  150. /**
  151. * 作废
  152. *
  153. * @return mixed
  154. */
  155. public function drop_api($id)
  156. {
  157. $update['where_id'] = $id;
  158. $update['type'] = 4;
  159. Dever::db('card/code')->update($update);
  160. return 'ok';
  161. }
  162. public function recovery_api($id)
  163. {
  164. $update['where_id'] = $id;
  165. $update['type'] = 1;
  166. Dever::db('card/code')->update($update);
  167. return 'ok';
  168. }
  169. public function outCode($data)
  170. {
  171. $header = array('礼品卡名称', '卡号', '总面值', '已用面值', '剩余面值', '使用状态', '兑换时间' ,'绑定时间');
  172. $body = array();
  173. $config = Dever::db('card/code')->config;
  174. foreach($data as $k => $v) {
  175. $card = Dever::db('card/info')->find($v['card_id']);
  176. $date = '';
  177. if ($v['ddate']) {
  178. $date = date('Y-m-d H:i', $v['ddate']);
  179. }
  180. $bdate = '';
  181. if ($v['bdate']) {
  182. $bdate = date('Y-m-d H:i',$v['bdate']);
  183. }
  184. $status = $config['status'][$v['status']];
  185. $d = array
  186. (
  187. $card['name'],
  188. $v['card'] . "\t",
  189. $v['total_cash'],
  190. $v['use_cash'],
  191. round($v['total_cash'] - $v['use_cash'], 2),
  192. $status,
  193. $date,
  194. $bdate,
  195. );
  196. $body[] = $d;
  197. }
  198. $file = Dever::input('excel_name');
  199. return Dever::excelExport($body, $header, $file);
  200. }
  201. }