Manage.php 25 KB

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