Manage.php 29 KB

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