payment.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin','admin',0);
  4. pc_base::load_sys_class('format', '', 0);
  5. pc_base::load_sys_class('form', '', 0);
  6. pc_base::load_app_func('global');
  7. class payment extends admin {
  8. private $db, $account_db, $member_db;
  9. function __construct() {
  10. if (!module_exists(ROUTE_M)) showmessage(L('module_not_exists'));
  11. parent::__construct();
  12. $this->db = pc_base::load_model('pay_payment_model');
  13. $this->account_db = pc_base::load_model('pay_account_model');
  14. $this->member_db = pc_base::load_model('member_model');
  15. $this->modules_path = PC_PATH.'modules'.DIRECTORY_SEPARATOR.'pay';
  16. pc_base::load_app_class('pay_method','','0');
  17. $this->method = new pay_method($this->modules_path);
  18. }
  19. /**
  20. * 支付模块列表
  21. */
  22. public function init() {
  23. $infos = $this->method->get_list();
  24. $show_dialog = true;
  25. include $this->admin_tpl('payment_list');
  26. }
  27. /*
  28. * 增加支付模块
  29. */
  30. public function add() {
  31. if(isset($_POST['dosubmit'])) {
  32. $info = $infos = array();
  33. $infos = $this->method->get_payment($_POST['pay_code']);
  34. $config = $infos['config'];
  35. foreach ($_POST['config_name'] as $key => $value) {
  36. $config[$value]['value'] = trim($_POST['config_value'][$key]);
  37. }
  38. $info['config'] = array2string($config);
  39. $info['name'] = $_POST['name'];
  40. $info['pay_name'] = $_POST['pay_name'];
  41. $info['pay_desc'] = $_POST['description'];
  42. $info['pay_id'] = $_POST['pay_id'];
  43. $info['pay_code'] = $_POST['pay_code'];
  44. $info['is_cod'] = $_POST['is_cod'];
  45. $info['is_online'] = $_POST['is_online'];
  46. $info['pay_fee'] = intval($_POST['pay_fee']);
  47. $info['pay_method'] = intval($_POST['pay_method']);
  48. $info['pay_order'] = intval($_POST['pay_order']);
  49. $info['enabled'] = '1';
  50. $info['author'] = $infos['author'];
  51. $info['website'] = $infos['website'];
  52. $info['version'] = $infos['version'];
  53. $this->db->insert($info);
  54. if($this->db->insert_id()){
  55. showmessage(L('operation_success'), '', '', 'add');
  56. }
  57. } else {
  58. $infos = $this->method->get_payment($_GET['code']);
  59. extract($infos);
  60. $show_header = true;
  61. $show_validator = true;
  62. include $this->admin_tpl('payment_detail');
  63. }
  64. }
  65. /*
  66. * 编辑支付模块
  67. */
  68. public function edit() {
  69. if(isset($_POST['dosubmit'])) {
  70. $infos = $this->method->get_payment($_POST['pay_code']);
  71. $config = $infos['config'];
  72. foreach ($_POST['config_name'] as $key => $value) {
  73. $config[$value]['value'] = trim($_POST['config_value'][$key]);
  74. }
  75. $info['config'] = array2string($config);
  76. $info['name'] = trim($_POST['name']);
  77. $info['pay_name'] = trim($_POST['pay_name']);
  78. $info['pay_desc'] = trim($_POST['description']);
  79. $info['pay_id'] = $_POST['pay_id'];
  80. $info['pay_code'] = trim($_POST['pay_code']);
  81. $info['pay_order'] = intval($_POST['pay_order']);
  82. $info['pay_method'] = intval($_POST['pay_method']);
  83. $info['pay_fee'] = (intval($_POST['pay_method'])==0) ? intval($_POST['pay_rate']) : intval($_POST['pay_fix']);
  84. $info['is_cod'] = trim($_POST['is_cod']);
  85. $info['is_online'] = trim($_POST['is_online']);
  86. $info['enabled'] = '1';
  87. $info['author'] = $infos['author'];
  88. $info['website'] = $infos['website'];
  89. $info['version'] = $infos['version'];
  90. $infos = $this->db->update($info,array('pay_id'=>$info['pay_id']));
  91. showmessage(L('edit').L('succ'), '', '', 'edit');
  92. } else {
  93. $pay_id = intval($_GET['id']);
  94. $infos = $this->db->get_one(array('pay_id'=>$pay_id));
  95. extract($infos);
  96. $config = string2array($config);
  97. $show_header = true;
  98. $show_validator = true;
  99. include $this->admin_tpl('payment_detail');
  100. }
  101. }
  102. /**
  103. * 卸载支付模块
  104. */
  105. public function delete() {
  106. $pay_id = intval($_GET['id']);
  107. $this->db->delete(array('pay_id'=>$pay_id));
  108. showmessage(L('delete_succ'),'?m=pay&c=payment');
  109. }
  110. /**
  111. * 支付订单列表
  112. */
  113. public function pay_list() {
  114. $where = '';
  115. if($_GET['dosubmit']){
  116. extract($_GET['info']);
  117. if($trade_sn) $where = "AND `trade_sn` LIKE '%$trade_sn%' ";
  118. if($username) $where = "AND `username` LIKE '%$username%' ";
  119. if($start_addtime && $end_addtime) {
  120. $start = strtotime($start_addtime.' 00:00:00');
  121. $end = strtotime($end_addtime.' 23:59:59');
  122. $where .= "AND `addtime` >= '$start' AND `addtime` <= '$end'";
  123. }
  124. if($status) $where .= "AND `status` LIKE '%$status%' ";
  125. if($where) $where = substr($where, 3);
  126. }
  127. $infos = array();
  128. foreach(L('select') as $key=>$value) {
  129. $trade_status[$key] = $value;
  130. }
  131. $page = $_GET['page'] ? $_GET['page'] : '1';
  132. $infos = $this->account_db->listinfo($where, $order = 'addtime DESC,id DESC', $page, $pagesize = 20);
  133. $pages = $this->account_db->pages;
  134. $number = count($infos);
  135. include $this->admin_tpl('pay_list');
  136. }
  137. /**
  138. * 财务统计
  139. * Enter description here ...
  140. */
  141. public function pay_stat() {
  142. $where = '';
  143. $infos = array();
  144. if($_GET['dosubmit']){
  145. extract($_GET['info']);
  146. if($username) $where = "AND `username` LIKE '%$username%' ";
  147. if($start_addtime && $end_addtime) {
  148. $start = strtotime($start_addtime.' 00:00:00');
  149. $end = strtotime($end_addtime.' 23:59:59');
  150. $where .= "AND `addtime` >= '$start' AND `addtime` <= '$end'";
  151. }
  152. if($status) $where .= "AND `status` LIKE '%$status%' ";
  153. if($where) $where = substr($where, 3);
  154. $infos = $this->account_db->select($where);
  155. $num= count($infos);
  156. foreach ($infos as $_v) {
  157. if($_v['type'] == 1) {
  158. $amount_num++;
  159. $amount += $_v['money'];
  160. if($_v['status'] =='succ') {$amount_succ += $_v['money'];$amount_num_succ++;}
  161. } elseif ($_v['type'] == 2) {
  162. $point_num++;
  163. $point += $_v['money'];
  164. if($_v['status'] =='succ') {$point_succ += $_v['money'];$point_num_succ++;}
  165. }
  166. }
  167. }
  168. foreach(L('select') as $key=>$value) $trade_status[$key] = $value;
  169. $total_infos = $this->account_db->select();
  170. $total_num= count($total_infos);
  171. foreach ($total_infos as $_v) {
  172. if($_v['type'] == 1) {
  173. $total_amount_num++;
  174. $total_amount += $_v['money'];
  175. if($_v['status'] =='succ') {$total_amount_succ += $_v['money'];$total_amount_num_succ++;}
  176. } elseif ($_v['type'] == 2) {
  177. $total_point_num++;
  178. $total_point += $_v['money'];
  179. if($_v['status'] =='succ') {$total_point_succ += $_v['money'];$total_point_num_succ++;}
  180. }
  181. }
  182. include $this->admin_tpl('pay_stat');
  183. }
  184. /**
  185. * 支付打折
  186. * Enter description here ...
  187. */
  188. public function discount() {
  189. if(isset($_POST['dosubmit'])) {
  190. $discount = floatval($_POST['discount']);
  191. $id = intval($_POST['id']);
  192. $infos = $this->account_db->update(array('discount'=>$discount),array('id'=>$id));
  193. showmessage(L('public_discount_succ'), '', '', 'discount');
  194. } else {
  195. $show_header = true;
  196. $show_validator = true;
  197. $id = intval($_GET['id']);
  198. $infos = $this->account_db->get_one(array('id'=>$id));
  199. extract($infos);
  200. include $this->admin_tpl('pay_discount');
  201. }
  202. }
  203. /**
  204. * 修改财务
  205. * Enter description here ...
  206. */
  207. public function modify_deposit() {
  208. if(isset($_POST['dosubmit'])) {
  209. $username = isset($_POST['username']) && trim($_POST['username']) ? trim($_POST['username']) : showmessage(L('username').L('error'));
  210. $usernote = isset($_POST['usernote']) && trim($_POST['usernote']) ? addslashes(trim($_POST['usernote'])) : showmessage(L('usernote').L('error'));
  211. $userinfo = $this->get_useid($username);
  212. if($userinfo) {
  213. //如果增加金钱或点数,想pay_account 中记录数据
  214. if($_POST['pay_unit']) {
  215. $value = floatval($_POST['unit']);
  216. $payment = L('admin_recharge');
  217. $receipts = pc_base::load_app_class('receipts');
  218. $func = $_POST['pay_type'] == '1' ? 'amount' :'point';
  219. $receipts->$func($value, $userinfo['userid'] , $username, create_sn(), 'offline', $payment, param::get_cookie('admin_username'), $status = 'succ',$usernote);
  220. } else {
  221. $value = floatval($_POST['unit']);
  222. $msg = L('background_operation').$usernote;
  223. $spend = pc_base::load_app_class('spend');
  224. $func = $_POST['pay_type'] == '1' ? 'amount' :'point';
  225. $spend->$func($value,$msg,$userinfo['userid'],$username,param::get_cookie('userid'),param::get_cookie('admin_username'));
  226. }
  227. if(intval($_POST['sendemail'])) {
  228. pc_base::load_sys_func('mail');
  229. $op = $_POST['pay_unit'] ? $value: '-'.$value;
  230. $op = $_POST['pay_type'] ? $op.L('yuan') : $op.L('point');
  231. $msg = L('account_changes_notice_tips',array('username'=>$username,'time'=>date('Y-m-d H:i:s',SYS_TIME),'op'=>$op,'note'=>$usernote,'amount'=>$userinfo['amount'],'point'=>$userinfo['point']));
  232. sendmail($userinfo['email'],L('send_account_changes_notice'),$msg);
  233. }
  234. showmessage(L('public_discount_succ'),HTTP_REFERER);
  235. }
  236. } else {
  237. $show_validator = true;
  238. include $this->admin_tpl('modify_deposit');
  239. }
  240. }
  241. /*
  242. * 支付删除
  243. */
  244. public function pay_del() {
  245. $id = intval($_GET['id']);
  246. $this->account_db->delete(array('id'=>$id));
  247. showmessage(L('delete_succ'),'?m=pay&c=payment&a=pay_list&menuid='.$_GET['menuid']);
  248. }
  249. /*
  250. * 支付取消
  251. */
  252. public function pay_cancel() {
  253. $id = intval($_GET['id']);
  254. $this->account_db->update(array('status'=>'cancel'),array('id'=>$id));
  255. showmessage(L('state_change_succ'),HTTP_REFERER);
  256. }
  257. /*
  258. * 支付详情
  259. */
  260. public function public_pay_detail() {
  261. $id = intval($_GET['id']);
  262. $infos = $this->account_db->get_one(array('id'=>$id));
  263. extract($infos);
  264. $show_header = true;
  265. include $this->admin_tpl('pay_detail');
  266. }
  267. public function public_check() {
  268. $id = intval($_GET['id']);
  269. $infos = $this->account_db->get_one(array('id'=>$id));
  270. $userinfo = $this->member_db->get_one(array('userid'=>$infos['userid']));
  271. $amount = $userinfo['amount'] + $infos['money'];
  272. $this->account_db->update(array('status'=>'succ','adminnote'=>param::get_cookie('admin_username')),array('id'=>$id));
  273. $this->member_db->update(array('amount'=>$amount),array('userid'=>$infos['userid']));
  274. showmessage(L('check_passed'),'?m=pay&c=payment&a=pay_list');
  275. }
  276. private function get_useid($username) {
  277. $username = trim($username);
  278. if ($result = $this->member_db->get_one(array('username'=>$username))){
  279. return $result;
  280. } else {
  281. return false;
  282. }
  283. }
  284. /**
  285. * 检查用户名
  286. * @param string $username 用户名
  287. */
  288. public function public_checkname_ajax() {
  289. $username = isset($_GET['username']) && trim($_GET['username']) ? trim($_GET['username']) : exit(0);
  290. if(CHARSET != 'utf-8') {
  291. $username = iconv('utf-8', CHARSET, $username);
  292. $username = addslashes($username);
  293. }
  294. $this->member_db = pc_base::load_model('member_model');
  295. if ($r = $this->member_db->get_one(array('username'=>$username))){
  296. exit(L('user_balance').$r['amount'].' '.L('point').' '.$r['point']);
  297. } else {
  298. exit('FALSE');
  299. }
  300. }
  301. }
  302. ?>