Manage.php 23 KB

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