Manage.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <?php
  2. namespace Active\Lib;
  3. use Dever;
  4. Class Manage
  5. {
  6. #全额退款
  7. public function refund_api($id)
  8. {
  9. $data = Dever::db('active/order')->find($id);
  10. // if ($data['mid'] && $data['mid'] > 0) {
  11. // $user = Dever::db('active/user')->find(array('mid'=>$data['mid']));
  12. // if ($user && $user['id']) {
  13. // $uid = $user['id'];
  14. // }
  15. // } else {
  16. // $uid = $data['uid'];
  17. // }
  18. $this->common($data,1);
  19. return 'reload';
  20. }
  21. public function insertInfoRefund ($id,$name,$data)
  22. {
  23. $num = Dever::param('num',$data);
  24. $order_id = Dever::param('order_id',$data);
  25. $data = Dever::db('active/order')->find($order_id);
  26. if($num > $data['num']) {
  27. Dever::alert('退款数量大于购买数量');
  28. }
  29. $info = Dever::db('active/info_refund')->state(array('order_id'=>$order_id));
  30. $count = $data['num'] - count($info);
  31. if ($num > $count) {
  32. Dever::alert('退款数量大于购买数量');
  33. }
  34. }
  35. public function updateInfoRefund ($id,$name,$data)
  36. {
  37. $num = Dever::param('num',$data);
  38. $order_id = Dever::param('order_id',$data);
  39. $code_id = Dever::param('code_id',$data);
  40. $data = Dever::db('active/order')->find($order_id);
  41. // $info = Dever::db('active/info_refund')->state(array('order_id'=>$order_id));
  42. // $active = Dever::db('active/info')->find($data['active_id']);
  43. $this->common($data,2,$num,$id);
  44. return 'reload';
  45. }
  46. public function show($id)
  47. {
  48. $data = Dever::db('active/order')->find($id);
  49. $refund_admin = '-';
  50. $rdate = '-';
  51. if ($data && isset($data['refund_admin']) && $data['refund_admin'] && $data['refund_admin']>0 && $data['rdate']) {
  52. $admin = Dever::load('manage/admin-find',$data['refund_admin']);
  53. $refund_admin = $admin['username'];
  54. $rdate = date('Y-m-d H:i',$data['rdate']);
  55. }
  56. $html = $refund_admin.'<br/>'.$rdate;
  57. return $html;
  58. }
  59. public function active($id)
  60. {
  61. $data = Dever::db('active/info')->find($id);
  62. $html = array();
  63. $html['active_name'] = $data['name'];
  64. $info = Dever::db('active/code')->find($id);
  65. if ($info && isset($info['audit_admin']) && $info['audit_admin'] && $info['audit_admin'] > 0) {
  66. $aduit = Dever::load('manage/admin-find',$info['audit_admin']);
  67. $html['admin_name'] = $aduit['username'];
  68. } elseif ($info && $info['top_admin']) {
  69. $off = Dever::db('active/info_off')->find($info['top_admin']);
  70. $html['admin_name'] = $off['name'];
  71. }
  72. return $html;
  73. }
  74. public function user($id)
  75. {
  76. $data = Dever::db('active/user')->find($id);
  77. $html = $data['name'].'<br/>'.$data['mobile'];
  78. return $html;
  79. }
  80. public function dOff($id)
  81. {
  82. $data = Dever::db('active/code')->state(array('active_id' => $id,'status'=>1));
  83. $html = count($data);
  84. return $html;
  85. }
  86. public function insertInfoCode($id, $name, $data)
  87. {
  88. $code = Dever::param('code',$data);
  89. if ($code) {
  90. $info = Dever::db('active/info_code')->find(array('code'=>$code));
  91. if ($info['code']) {
  92. Dever::alert('核销码已核销');
  93. }
  94. }
  95. }
  96. public function updateInfoCode($id, $name, $data)
  97. {
  98. $code = Dever::param('code',$data);
  99. $data = Dever::db('active/code')->find(array('write_code'=>$code));
  100. if ($data) {
  101. $where['where_id'] = $data['id'];
  102. $where['status'] = 2;
  103. $where['offdate'] = time();
  104. $admin = Dever::load('manage/admin-find');
  105. $where['audit_admin'] = $admin['id'];
  106. Dever::db('active/code')->update($where);
  107. }
  108. }
  109. public function get()
  110. {
  111. $data[0]['name'] = '头衔';
  112. $data[0]['child'] = Dever::db('setting/title')->select();
  113. $data['state'] = 1;
  114. return $data;
  115. }
  116. public function search_api()
  117. {
  118. $value = Dever::input('value');
  119. if (!$value) {
  120. return '核销码不存在';
  121. }
  122. if ($value) {
  123. $data = Dever::db('active/code')->one(array('write_code' => $value,'state' =>1));
  124. $table = array();
  125. if ($data) {
  126. $user = Dever::db('active/user')->find(array('id'=>$data['join_uid']));
  127. $parent = Dever::db('active/user')->find(array('id'=>$data['buy_uid']));
  128. $table = array();
  129. $table['head'] = array('姓名', '手机号','邀请人', '邀请人手机号');
  130. $table['body'] = array();
  131. $table['body'] = array($user['name'], $user['mobile'],$parent['name'], $parent['mobile']);
  132. $result[] = array
  133. (
  134. 'type' => 'table',
  135. 'content' => $table,
  136. );
  137. $html = Dever::show('', $result, false, false);
  138. return $html;
  139. }else{
  140. return '核销码不存在';
  141. }
  142. } else {
  143. return '';
  144. }
  145. }
  146. public function checkMcode()
  147. {
  148. $mobile = Dever::input('mobile');
  149. $code = Dever::input('mcode');
  150. if (!$code) {
  151. Dever::alert('请输入验证码');
  152. }
  153. $code = Dever::load('passport/reg')->mcode($mobile, $code, 2);
  154. if (!$code) {
  155. Dever::alert('验证码输入错误');
  156. }
  157. return 'ok';
  158. }
  159. public function list()
  160. {
  161. $id = Dever::input('id');
  162. $info = Dever::db('active/order')->find($id);
  163. $active = Dever::db('active/info')->find($info['active_id']);
  164. $config = Dever::db('active/order')->config['config_status'];
  165. $status = Dever::status($config,$info['status']);
  166. if ( !$info['uid']) {
  167. $user = Dever::db('active/user')->find($info['mid']);
  168. $info['uid'] = $user['id'];
  169. }
  170. $code = Dever::db('active/code')->getCode(array('order_id' => $id,'status'=>'1,2'));
  171. $use_code = count($code);#已领取的所有数量
  172. if (!$info['refund_num']) {
  173. $info['refund_num'] = 0;
  174. }
  175. $no_code = $info['num'] - $use_code - $info['refund_num'];#未使用的数量
  176. if ($info['uid'] && $info['uid'] > 0) {
  177. $user = Dever::db('active/user')->find($info['uid']);
  178. $member = Dever::load('active/lib/user')->agent($user);
  179. $code = Dever::db('active/code')->state(array('order_id' => $id));
  180. $use_code = count($code);
  181. $no_code = $info['num'] - $use_code;
  182. if ($info['uid'] && $info['uid'] > 0) {
  183. $user = Dever::db('active/user')->find($info['uid']);
  184. $user_name = $user['name'];
  185. $user_mobile = $user['mobile'];
  186. $user_idcard = $user['idcard'];
  187. $member = Dever::load('active/lib/user')->agent($user);
  188. if ($member) {
  189. $role = Dever::db('setting/role')->find($member['role']);
  190. if (isset($role) && $role && isset($role['name']) && $role['name']) {
  191. $role_name = '<br/>'.$role['name'];
  192. } else {
  193. $role_name = '';
  194. }
  195. $title = Dever::db('setting/title')->find($member['title_id']);
  196. if (isset($title) && $title && isset($title['name']) && $title['name']) {
  197. $title_name = '('.$title['name'].')';
  198. } else {
  199. $title_name = '';
  200. }
  201. $level = Dever::db('setting/level')->find($member['level_id']);
  202. if (isset($level) && $level && isset($level['name']) && $level['name']) {
  203. $level_name = '('.$level['name'].')';
  204. } else {
  205. $level_name = '';
  206. }
  207. $user_name = $member['name'].$role_name.$title_name.$level_name;
  208. $user_mobile = $member['mobile'];
  209. $user_idcard = $member['idcard'];
  210. }
  211. }
  212. if ($active['col'] && $active['col'] == 'idcard') {
  213. $user_idcard = $user['idcard'];
  214. } else {
  215. $user_idcard = '';
  216. }
  217. $field_name = '';
  218. $field_value = '';
  219. $field_sname = '';
  220. $field_svalue = '';
  221. if ($info['path']) {
  222. $path = json_decode($info['path']);
  223. foreach ($path as $k => $v) {
  224. $v = (array)$v;
  225. $field = Dever::db('active/info_field')->find($v['id']);
  226. if ($field['type'] == 1) {
  227. $field_name = $field['name'];
  228. $field_value = $v['value'];
  229. } elseif ($field['type'] == 2) {
  230. $value = Dever::db('active/info_field_value')->find($v['value']);
  231. // print_R($value['name']);die;
  232. if ($value) {
  233. $field_sname = $field['name'];
  234. $field_svalue = $value['name'];
  235. }
  236. }
  237. }
  238. }
  239. $result['订单信息'] = array
  240. (
  241. 'type' => 'info',
  242. 'content' => array
  243. (
  244. array
  245. (
  246. array('订单单号', $info['order_num']),
  247. array('活动名称', $active['name']),
  248. array('订单状态', $status),
  249. ),
  250. array
  251. (
  252. array('购买数量', $info['num']),
  253. array('支付金额', $info['price']),
  254. ),
  255. array
  256. (
  257. array('已使用', $use_code),
  258. array('未使用', $no_code),
  259. array('退款数量', $info['refund_num']),
  260. ),
  261. ),
  262. );
  263. $result['用户信息'] = array
  264. (
  265. 'type' => 'info',
  266. 'content' => array
  267. (
  268. array
  269. (
  270. array('用户姓名', $user_name),
  271. array('用户电话', $user_mobile),
  272. array('用户身份证号', $user_idcard),
  273. ),
  274. ),
  275. );
  276. $result['报名信息'] = array
  277. (
  278. 'type' => 'info',
  279. 'content' => array
  280. (
  281. array
  282. (
  283. array($field_name, $field_value),
  284. array($field_sname, $field_svalue),
  285. // array('用户身份证号', $user_idcard),
  286. ),
  287. ),
  288. );
  289. $button = array();
  290. if ($info['status'] > 1 && $no_code > 0) {
  291. if (Dever::load('manage/auth')->checkFunc('active.order', 'editrefund', '未使用退款')) {
  292. $purl = Dever::url('project/database/update?project=active&table=info_refund&search_option_order_id='.$info['id'].'&col=num,order_id', 'manage');
  293. $button[] = array
  294. (
  295. 'type' => 'edit',
  296. 'link' => $purl,
  297. 'name' => '未使用退款',
  298. );
  299. }
  300. }
  301. if ($use_code > 0) {
  302. $result += $this->table($id);
  303. }
  304. $head = array
  305. (
  306. 'name' => '基本资料',
  307. 'btn' => $button,
  308. );
  309. $html = Dever::show($head, $result);
  310. return $html;
  311. }
  312. }
  313. private function table ($id)
  314. {
  315. $data = Dever::db('active/code')->state(array('order_id' => $id));
  316. if ($data) {
  317. $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销时间', '核销人', '管理');
  318. $body = array();
  319. foreach ($data as $k => $v) {
  320. $user = Dever::db('active/user')->find($v['join_uid']);
  321. $join_name = '';
  322. if ($user) {
  323. $join_name = $user['name'].'<br/>'.$user['mobile'];
  324. }
  325. $admin_name = '';
  326. if ($v['status'] == 1) {
  327. $status = '待核销';
  328. } elseif($v['status'] == 2) {
  329. $status = '已核销';
  330. if ($v['audit_admin'] && $v['audit_admin'] >0) {
  331. $admin = Dever::load('manage/admin-find',$v['audit_admin']);
  332. if ($admin) {
  333. $admin_name = $admin['username'];
  334. }
  335. } else {
  336. if ($v['top_admin'] && $v['top_admin'] > 0) {
  337. $admin = Dever::db('active/info_off')->find($v['top_admin']);
  338. if ($admin) {
  339. $admin_name = $admin['name'];
  340. }
  341. }
  342. }
  343. } else {
  344. $status = '已作废';
  345. }
  346. $cdate = '';
  347. if ($v['cdate']) {
  348. $cdate = date('Y-m-d H:i',$v['cdate']);
  349. }
  350. $offdate = '';
  351. if ($v['offdate']) {
  352. $offdate = date('Y-m-d H:i',$v['offdate']);
  353. }
  354. $m = '';
  355. if ($v['status'] == 1) {
  356. $url = Dever::url('lib/manage.setOrder&order_id=' . $v['order_id'].'&code_id='.$v['id'], 'active');
  357. $m = '<a href="javascript:;" onclick="load( \''.$url.'\')" class="layui-btn">退款</a>';
  358. }
  359. $d = array
  360. (
  361. $join_name,
  362. $v['write_code'],
  363. $status,
  364. $cdate,
  365. $offdate,
  366. $admin_name,
  367. $m,
  368. );
  369. $body[] = $d;
  370. }
  371. $result['核销码使用列表'] = array
  372. (
  373. 'type' => 'table',
  374. 'content' => array
  375. (
  376. 'head' => $head,
  377. 'body' => $body,
  378. )
  379. );
  380. return $result;
  381. }
  382. }
  383. public function setOrder_api($order_id,$code_id){
  384. $data = Dever::db('active/order')->find($order_id);
  385. $ids = $this->common($data,3,'',$code_id);
  386. if ($ids) {
  387. $w['where_id'] = $code_id;
  388. $w['status'] = 3;
  389. Dever::db('active/code')->update($w);
  390. }
  391. return 'reload';
  392. }
  393. public function common($data,$type,$num=false,$refund_id=false){
  394. $active = Dever::db('active/info')->find($data['active_id']);
  395. $info = Dever::db('active/info_refund')->state(array('order_id'=>$data['id']));
  396. if (time() > $active['act_start']) {
  397. Dever::alert('活动已开始,不能退款');
  398. }
  399. if ($type == 1) {
  400. if ($data['status'] != 2) {
  401. Dever::alert('此状态下不可退款');
  402. }
  403. $refund_num = $data['num'];
  404. $price = $data['price'];
  405. }
  406. if ($type == 2) {
  407. $price = $num * $active['price'];
  408. $refund_num = $num;
  409. }
  410. if ($type == 3) {
  411. $refund_num = 1;
  412. $price = $active['price'];
  413. }
  414. $param = array
  415. (
  416. 'project_id' => 6,
  417. 'channel_id' => 1,
  418. 'system_source' => 1,
  419. 'account_id' => 8,
  420. 'order_id' => $data['order_num'],
  421. 'refund_cash' => $price,
  422. //'refund_order_id' => '',
  423. );
  424. if ($type != 1) {
  425. $param['refund_order_id'] = $data['order_num'] . '_' . count($info);
  426. }
  427. if ($data['price'] > 0) {
  428. $result = Dever::load('pay/api.refund', $param);
  429. if (!$result) {
  430. # 退款失败,抛出错误
  431. //throw new \Exception('退款失败');
  432. Dever::alert('退款失败,请联系管理员');
  433. } else {
  434. $admin = Dever::load('manage/auth.data');
  435. $time = time();
  436. $where['where_id'] = $data['id'];
  437. $where['status'] = 6;
  438. $where['refund_admin'] = $admin['id'];
  439. $where['rdate'] = $time;
  440. if (!$data['refund_num']) {
  441. $data['refund_num'] = 0;
  442. }
  443. $where['refund_num'] = $refund_num + $data['refund_num'];
  444. if ($type == 1 || ($type == 2 && $price = $data['price'])) {
  445. Dever::db('active/order')->update($where);
  446. } elseif (($type == 2 && $price != $data['price']) || $type == 3) {
  447. $where['status'] = 5;
  448. $ids = Dever::db('active/order')->update($where);
  449. return $ids;
  450. }
  451. if ($type == 2) {
  452. $insert['status'] = 2;
  453. $insert['where_id'] = $refund_id;
  454. $insert['audit_admin'] = $admin['id'];
  455. Dever::db('active/info_refund')->update($insert);
  456. }
  457. }
  458. }
  459. }
  460. #更新数量
  461. public function upNum_api($order_id)
  462. {
  463. $data = Dever::db('active/order')->find($order_id);
  464. if (!$data['refund_num']) {
  465. $w['refund_num'] = 0;
  466. } else {
  467. $w['refund_num'] =$data['refund_num'];
  468. }
  469. if (!$data['code_num']) {
  470. $w['code_num'] = 0;
  471. }
  472. if (!$data['no_num']) {
  473. $w['no_num'] = 0;
  474. }
  475. #已使用的数量
  476. $code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>'1,2'));
  477. $w['code_num'] = count($code);
  478. #待核销的数量
  479. $no_code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>1));
  480. $w['no_num'] = count($no_code);
  481. $w['where_id'] = $data['id'];
  482. Dever::db('active_order')->update($w);
  483. }
  484. }