Manage.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. // print_R($use_code);die;
  173. if (!$info['refund_num']) {
  174. $info['refund_num'] = 0;
  175. }
  176. $no_code = $info['num'] - $use_code - $info['refund_num'];#未使用的数量
  177. if ($info['uid'] && $info['uid'] > 0) {
  178. $user = Dever::db('active/user')->find($info['uid']);
  179. $user_name = $user['name'];
  180. $user_mobile = $user['mobile'];
  181. $user_idcard = $user['idcard'];
  182. $member = Dever::load('active/lib/user')->agent($user);
  183. if ($member) {
  184. $role = Dever::db('setting/role')->find($member['role']);
  185. if (isset($role) && $role && isset($role['name']) && $role['name']) {
  186. $role_name = '<br/>'.$role['name'];
  187. } else {
  188. $role_name = '';
  189. }
  190. $title = Dever::db('setting/title')->find($member['title_id']);
  191. if (isset($title) && $title && isset($title['name']) && $title['name']) {
  192. $title_name = '('.$title['name'].')';
  193. } else {
  194. $title_name = '';
  195. }
  196. $level = Dever::db('setting/level')->find($member['level_id']);
  197. if (isset($level) && $level && isset($level['name']) && $level['name']) {
  198. $level_name = '('.$level['name'].')';
  199. } else {
  200. $level_name = '';
  201. }
  202. $user_name = $member['name'].$role_name.$title_name.$level_name;
  203. $user_mobile = $member['mobile'];
  204. $user_idcard = $member['idcard'];
  205. }
  206. }
  207. if ($active['col'] && $active['col'] == 'idcard') {
  208. $user_idcard = $user['idcard'];
  209. } else {
  210. $user_idcard = '';
  211. }
  212. $field_name = '';
  213. $field_value = '';
  214. $field_sname = '';
  215. $field_svalue = '';
  216. $path = array();
  217. if ($info['path']) {
  218. $path = json_decode($info['path']);
  219. // print_R($path);die;
  220. foreach ($path as $k => $v) {
  221. $v = (array)$v;
  222. $field = Dever::db('active/info_field')->find($v['id']);
  223. if ($field['type'] == 1) {
  224. $field_name = $field['name'];
  225. $field_value = $v['value'];
  226. } elseif ($field['type'] == 2) {
  227. $value = Dever::db('active/info_field_value')->find($v['value']);
  228. // print_R($value['name']);die;
  229. if ($value) {
  230. $field_sname = $field['name'];
  231. $field_svalue = $value['name'];
  232. }
  233. }
  234. }
  235. }
  236. $result['订单信息'] = array
  237. (
  238. 'type' => 'info',
  239. 'content' => array
  240. (
  241. array
  242. (
  243. array('订单单号', $info['order_num']),
  244. array('活动名称', $active['name']),
  245. array('订单状态', $status),
  246. ),
  247. array
  248. (
  249. array('购买数量', $info['num']),
  250. array('支付金额', $info['price']),
  251. ),
  252. array
  253. (
  254. array('已使用', $use_code),
  255. array('未使用', $no_code),
  256. array('退款数量', $info['refund_num']),
  257. ),
  258. ),
  259. );
  260. $result['用户信息'] = array
  261. (
  262. 'type' => 'info',
  263. 'content' => array
  264. (
  265. array
  266. (
  267. array('用户姓名', $user_name),
  268. array('用户电话', $user_mobile),
  269. array('用户身份证号', $user_idcard),
  270. ),
  271. ),
  272. );
  273. if ($path) {
  274. $result['报名信息'] = array
  275. (
  276. 'type' => 'info',
  277. 'content' => array
  278. (
  279. array
  280. (
  281. array($field_name, $field_value),
  282. array($field_sname, $field_svalue),
  283. // array('用户身份证号', $user_idcard),
  284. ),
  285. ),
  286. );
  287. }
  288. $button = array();
  289. if ($info['status'] > 1 && $no_code > 0) {
  290. if (Dever::load('manage/auth')->checkFunc('active.order', 'editrefund', '未使用退款')) {
  291. $purl = Dever::url('project/database/update?project=active&table=info_refund&search_option_order_id='.$info['id'].'&col=num,order_id', 'manage');
  292. $button[] = array
  293. (
  294. 'type' => 'edit',
  295. 'link' => $purl,
  296. 'name' => '未使用退款',
  297. );
  298. }
  299. }
  300. if ($use_code > 0) {
  301. $result += $this->table($id);
  302. }
  303. $head = array
  304. (
  305. 'name' => '基本资料',
  306. 'btn' => $button,
  307. );
  308. $html = Dever::show($head, $result);
  309. return $html;
  310. }
  311. private function table ($id)
  312. {
  313. $data = Dever::db('active/code')->state(array('order_id' => $id));
  314. if ($data) {
  315. $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销时间', '核销人', '管理');
  316. $body = array();
  317. foreach ($data as $k => $v) {
  318. $user = Dever::db('active/user')->find($v['join_uid']);
  319. $join_name = '';
  320. if ($user) {
  321. $join_name = $user['name'].'<br/>'.$user['mobile'];
  322. }
  323. $admin_name = '';
  324. if ($v['status'] == 1) {
  325. $status = '待核销';
  326. } elseif($v['status'] == 2) {
  327. $status = '已核销';
  328. if ($v['audit_admin'] && $v['audit_admin'] >0) {
  329. $admin = Dever::load('manage/admin-find',$v['audit_admin']);
  330. if ($admin) {
  331. $admin_name = $admin['username'];
  332. }
  333. } else {
  334. if ($v['top_admin'] && $v['top_admin'] > 0) {
  335. $admin = Dever::db('active/info_off')->find($v['top_admin']);
  336. if ($admin) {
  337. $admin_name = $admin['name'];
  338. }
  339. }
  340. }
  341. } else {
  342. $status = '已作废';
  343. }
  344. $cdate = '';
  345. if ($v['cdate']) {
  346. $cdate = date('Y-m-d H:i',$v['cdate']);
  347. }
  348. $offdate = '';
  349. if ($v['offdate']) {
  350. $offdate = date('Y-m-d H:i',$v['offdate']);
  351. }
  352. $m = '';
  353. if ($v['status'] == 1) {
  354. $url = Dever::url('lib/manage.setOrder&order_id=' . $v['order_id'].'&code_id='.$v['id'], 'active');
  355. $m = '<a href="javascript:;" onclick="load( \''.$url.'\')" class="layui-btn">退款</a>';
  356. }
  357. $d = array
  358. (
  359. $join_name,
  360. $v['write_code'],
  361. $status,
  362. $cdate,
  363. $offdate,
  364. $admin_name,
  365. $m,
  366. );
  367. $body[] = $d;
  368. }
  369. $result['核销码使用列表'] = array
  370. (
  371. 'type' => 'table',
  372. 'content' => array
  373. (
  374. 'head' => $head,
  375. 'body' => $body,
  376. )
  377. );
  378. return $result;
  379. }
  380. }
  381. public function setOrder_api($order_id,$code_id){
  382. $data = Dever::db('active/order')->find($order_id);
  383. $ids = $this->common($data,3,'',$code_id);
  384. if ($ids) {
  385. $w['where_id'] = $code_id;
  386. $w['status'] = 3;
  387. Dever::db('active/code')->update($w);
  388. }
  389. return 'reload';
  390. }
  391. public function common($data,$type,$num=false,$refund_id=false){
  392. $active = Dever::db('active/info')->find($data['active_id']);
  393. $info = Dever::db('active/info_refund')->state(array('order_id'=>$data['id']));
  394. if (time() > $active['act_start']) {
  395. Dever::alert('活动已开始,不能退款');
  396. }
  397. if ($type == 1) {
  398. if ($data['status'] != 2) {
  399. Dever::alert('此状态下不可退款');
  400. }
  401. $refund_num = $data['num'];
  402. $price = $data['price'];
  403. }
  404. if ($type == 2) {
  405. $price = $num * $active['price'];
  406. $refund_num = $num;
  407. }
  408. if ($type == 3) {
  409. $refund_num = 1;
  410. $price = $active['price'];
  411. }
  412. $param = array
  413. (
  414. 'project_id' => 6,
  415. 'channel_id' => 1,
  416. 'system_source' => 1,
  417. 'account_id' => 8,
  418. 'order_id' => $data['order_num'],
  419. 'refund_cash' => $price,
  420. //'refund_order_id' => '',
  421. );
  422. if ($type != 1) {
  423. $param['refund_order_id'] = $data['order_num'] . '_' . count($info);
  424. }
  425. if ($data['price'] > 0) {
  426. $result = Dever::load('pay/api.refund', $param);
  427. if (!$result) {
  428. # 退款失败,抛出错误
  429. //throw new \Exception('退款失败');
  430. Dever::alert('退款失败,请联系管理员');
  431. } else {
  432. $admin = Dever::load('manage/auth.data');
  433. $time = time();
  434. $where['where_id'] = $data['id'];
  435. $where['status'] = 6;
  436. $where['refund_admin'] = $admin['id'];
  437. $where['rdate'] = $time;
  438. if (!$data['refund_num']) {
  439. $data['refund_num'] = 0;
  440. }
  441. $where['refund_num'] = $refund_num + $data['refund_num'];
  442. if ($type == 1 || ($type == 2 && $price = $data['price'])) {
  443. Dever::db('active/order')->update($where);
  444. } elseif (($type == 2 && $price != $data['price']) || $type == 3) {
  445. $where['status'] = 5;
  446. $ids = Dever::db('active/order')->update($where);
  447. return $ids;
  448. }
  449. if ($type == 2) {
  450. $insert['status'] = 2;
  451. $insert['where_id'] = $refund_id;
  452. $insert['audit_admin'] = $admin['id'];
  453. Dever::db('active/info_refund')->update($insert);
  454. }
  455. }
  456. }
  457. }
  458. #更新数量
  459. public function upNum_api($order_id)
  460. {
  461. $data = Dever::db('active/order')->find($order_id);
  462. if (!$data['refund_num']) {
  463. $w['refund_num'] = 0;
  464. } else {
  465. $w['refund_num'] =$data['refund_num'];
  466. }
  467. if (!$data['code_num']) {
  468. $w['code_num'] = 0;
  469. }
  470. if (!$data['no_num']) {
  471. $w['no_num'] = 0;
  472. }
  473. #已使用的数量
  474. $code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>'1,2'));
  475. $w['code_num'] = count($code);
  476. #待核销的数量
  477. $no_code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>1));
  478. $w['no_num'] = count($no_code);
  479. $w['where_id'] = $data['id'];
  480. Dever::db('active_order')->update($w);
  481. }
  482. }