Manage.php 19 KB

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