Manage.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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,3'));
  239. $use_code = count($code);#已领取的所有数量
  240. // print_R($use_code);die;
  241. if (!$info['refund_num']) {
  242. $info['refund_num'] = 0;
  243. }
  244. $tui_code = $info['num'] - $info['refund_num'];#未使用的数量
  245. // $no_code = $info['num'] - $use_code - $info['refund_num'];#未使用的数量
  246. $no_code = $info['num'] - $use_code;#未使用的数量
  247. if ($info['uid'] && $info['uid'] > 0) {
  248. $user = Dever::db('active/user')->find($info['uid']);
  249. $user_name = $user['name'];
  250. $user_mobile = $user['mobile'];
  251. $user_idcard = $user['idcard'];
  252. $member = Dever::load('active/lib/user')->agent($user);
  253. if ($member) {
  254. $role = Dever::db('setting/role')->find($member['role']);
  255. if (isset($role) && $role && isset($role['name']) && $role['name']) {
  256. $role_name = '<br/>'.$role['name'];
  257. } else {
  258. $role_name = '';
  259. }
  260. $title = Dever::db('setting/title')->find($member['title_id']);
  261. if (isset($title) && $title && isset($title['name']) && $title['name']) {
  262. $title_name = '('.$title['name'].')';
  263. } else {
  264. $title_name = '';
  265. }
  266. $level = Dever::db('setting/level')->find($member['level_id']);
  267. if (isset($level) && $level && isset($level['name']) && $level['name']) {
  268. $level_name = '('.$level['name'].')';
  269. } else {
  270. $level_name = '';
  271. }
  272. $user_name = $member['name'].$role_name.$title_name.$level_name;
  273. $user_mobile = $member['mobile'];
  274. $user_idcard = $member['idcard'];
  275. }
  276. }
  277. // print_R($id);die;
  278. $refund = Dever::db('active/info_refund')->getSearch(array('order_id'=>$id));
  279. $refund_path = array();
  280. $refund_desc = '';
  281. if ($refund) {
  282. foreach ($refund as $k1 => $v1) {
  283. $refund_log = Dever::db('active/info_refund_log')->getSearch(array('order_id'=>$v1['id']));
  284. $refund_desc = $v1['desc'];
  285. if ($refund_log) {
  286. if ($refund_log['desc'] != $v1['desc']) {
  287. $refund_desc = $refund_log['desc'];
  288. }
  289. }
  290. if (!$v1['num']) {
  291. $v1['num'] = 0;
  292. }
  293. if (!$v1['price']) {
  294. $v1['price'] = 0;
  295. }
  296. $refund_path[] = array('退款数量',$v1['num']);
  297. $refund_path[] = array('退款金额',$v1['price']);
  298. $refund_path[] = array('退款备注',$refund_desc);
  299. }
  300. }
  301. $path = array();
  302. $path_data = array();
  303. if ($info['path']) {
  304. $path = Dever::json_decode($info['path']);
  305. foreach ($path as $k => $v) {
  306. $field = Dever::db('active/info_field')->find($v['id']);
  307. if ($field['type'] == 1) {
  308. $path_data[] = array($field['name'], $v['value']);
  309. } elseif ($field['type'] == 2) {
  310. $value = Dever::db('active/info_field_value')->find($v['value']);
  311. if ($value) {
  312. $path_data[] = array($field['name'], $value['name']);
  313. }
  314. }
  315. }
  316. }
  317. $result['订单信息'] = array
  318. (
  319. 'type' => 'info',
  320. 'content' => array
  321. (
  322. array
  323. (
  324. array('订单单号', $info['order_num']),
  325. array('活动名称', $active['name']),
  326. array('订单状态', $status),
  327. ),
  328. array
  329. (
  330. array('购买数量', $info['num']),
  331. array('支付金额', $info['price']),
  332. array('备注',$info['remark']),
  333. ),
  334. array
  335. (
  336. array('已使用', $use_code),
  337. array('未使用', $no_code),
  338. // array('退款数量', $info['refund_num']),
  339. ),
  340. array
  341. (
  342. // array('退款数量', $info['refund_num']),
  343. // array('退款总金额', $refund_money),
  344. // array('退款备注', $refund_desc),
  345. ),
  346. ),
  347. );
  348. if ($refund_path && $refund) {
  349. $result['退款信息'] = array
  350. (
  351. 'type' => 'info',
  352. 'content' => array
  353. (
  354. $refund_path,
  355. ),
  356. );
  357. }
  358. $result['用户信息'] = array
  359. (
  360. 'type' => 'info',
  361. 'content' => array
  362. (
  363. array
  364. (
  365. array('用户姓名', $user_name),
  366. array('用户电话', $user_mobile),
  367. array('用户身份证号', $user_idcard),
  368. ),
  369. ),
  370. );
  371. if ($path) {
  372. $result['报名信息'] = array
  373. (
  374. 'type' => 'info',
  375. 'content' => array
  376. (
  377. $path_data,
  378. ),
  379. );
  380. }
  381. $button = array();
  382. if (Dever::load('manage/auth')->checkFunc('active.order', 'edit', '备注')) {
  383. $purl = Dever::url('project/database/update?project=active&table=order&where_id='.$info['id'].'&col=remark', 'manage');
  384. $button[] = array
  385. (
  386. 'type' => 'edit',
  387. 'link' => $purl,
  388. 'name' => '备注',
  389. );
  390. }
  391. if ($info['status'] == 2 && $info['code_num'] < 1 && time() < $active['act_start'] && $active['refund_type'] == 2 ) {
  392. if (Dever::load('manage/auth')->checkFunc('active.order', 'editrefund', '全额退款')) {
  393. $purl = Dever::url('active/lib/manage.refund&id='.$id);
  394. $button[] = array
  395. (
  396. 'type' => 'action',
  397. 'link' => $purl,
  398. 'name' => '全额退款',
  399. );
  400. }
  401. }
  402. if ($info['status'] > 1 && $tui_code > 0 && $info['status'] != 3 && $active['refund_type'] == 2) {
  403. // && time()<$active['act_start']
  404. if (Dever::load('manage/auth')->checkFunc('active.order', 'editrefund1', '未使用退款')) {
  405. $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');
  406. $button[] = array
  407. (
  408. 'type' => 'edit',
  409. 'link' => $purl,
  410. 'name' => '未使用退款',
  411. );
  412. }
  413. }
  414. if ($use_code >= 0) {
  415. $result += $this->table($id);
  416. }
  417. $head = array
  418. (
  419. 'name' => '基本资料',
  420. 'btn' => $button,
  421. );
  422. $html = Dever::show($head, $result);
  423. return $html;
  424. }
  425. private function table ($id)
  426. {
  427. $data = Dever::db('active/code')->state(array('order_id' => $id));
  428. if ($data) {
  429. $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销人', '管理');
  430. // '核销时间',
  431. $body = array();
  432. foreach ($data as $k => $v) {
  433. $user = Dever::db('active/user')->find($v['join_uid']);
  434. $join_name = '';
  435. if ($user) {
  436. $join_name = $user['name'].'<br/>'.$user['mobile'];
  437. }
  438. $admin_name = '';
  439. if ($v['status'] == 1) {
  440. $status = '待核销';
  441. } elseif($v['status'] == 2) {
  442. $status = '已核销';
  443. if ($v['audit_admin'] && $v['audit_admin'] >0) {
  444. $admin = Dever::load('manage/admin-find',$v['audit_admin']);
  445. if ($admin) {
  446. $admin_name = $admin['username'];
  447. }
  448. } else {
  449. if ($v['top_admin'] && $v['top_admin'] > 0) {
  450. $admin = Dever::db('active/info_off')->find($v['top_admin']);
  451. if ($admin) {
  452. $admin_name = $admin['name'];
  453. }
  454. }
  455. }
  456. } else {
  457. $status = '已作废';
  458. }
  459. $cdate = '';
  460. if ($v['cdate']) {
  461. $cdate = date('Y-m-d H:i',$v['cdate']);
  462. }
  463. // $offdate = '';
  464. // if ($v['offdate']) {
  465. // $offdate = date('Y-m-d H:i',$v['offdate']);
  466. // }
  467. $active = Dever::db('active/info')->find($v['active_id']);
  468. $m = '';
  469. if ($v['status'] == 1 && $active['refund_type'] == 2 ) {
  470. // && time()<$active['act_start']
  471. if ($active['off_type'] == 2) {
  472. if ($v['status']!=3) {
  473. $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');
  474. }
  475. } else {
  476. if ($v['status']==1) {
  477. $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');
  478. }
  479. }
  480. // $url = Dever::url('lib/manage.setOrder&order_id=' . $v['order_id'].'&code_id='.$v['id'].'&col=price', 'active');
  481. if (Dever::load('manage/auth')->checkFunc('active.order', 'editorder', '退款')) {
  482. $m = '<a href="javascript:;" onclick="fastEdit($(this), \''.$url.'\')" class="layui-btn">退款</a>';
  483. }
  484. }
  485. $d = array
  486. (
  487. $join_name,
  488. $v['write_code'],
  489. $status,
  490. $cdate,
  491. // $offdate,
  492. $admin_name,
  493. $m,
  494. );
  495. $body[] = $d;
  496. }
  497. $result['核销码使用列表'] = array
  498. (
  499. 'type' => 'table',
  500. 'content' => array
  501. (
  502. 'head' => $head,
  503. 'body' => $body,
  504. )
  505. );
  506. return $result;
  507. } else {
  508. return array();
  509. }
  510. }
  511. public function insertInfoRefundLog($id,$name,$data)
  512. {
  513. $price = Dever::param('price',$data);
  514. $order_id = Dever::param('order_id',$data);
  515. $code_id = Dever::param('code_id',$data);
  516. $order = Dever::db('active/order')->find($order_id);
  517. $active = Dever::db('active/info')->find($order['active_id']);
  518. if (!$price) {
  519. Dever::alert('退款金额不能为空');
  520. }
  521. if ($price > $active['price']) {
  522. Dever::alert('退款金额大于购买金额');
  523. }
  524. $data = Dever::db('active/info_refund_log')->find(Array('order_id'=>$order_id,'code_id'=>$code_id));
  525. if($data) {
  526. // Dever::alert('不可重复退款');
  527. }
  528. }
  529. public function updateInfoRefundLog($id,$name,$data)
  530. {
  531. $price = Dever::param('price',$data);
  532. $order_id = Dever::param('order_id',$data);
  533. $code_id = Dever::param('code_id',$data);
  534. $desc = Dever::param('desc',$data);
  535. $order = Dever::db('active/order')->find($order_id);
  536. $where['order_id'] = $order_id;
  537. $where['code_id'] = $code_id;
  538. $where['price'] = trim($price);
  539. $where['desc'] = $desc;
  540. $data = Dever::db('active/order')->find($order_id);
  541. $ids = $this->common($data,3,false,false,$price,$desc);
  542. if ($ids) {
  543. $where['status'] = 2;
  544. $where['id'] = $id;
  545. Dever::db('active/info_refund_log')->update($where);
  546. $admin = Dever::load('manage/auth.info');
  547. $w['where_id'] = $code_id;
  548. $w['status'] = 3;
  549. $w['offdate'] = time();
  550. $w['audit_admin'] = $admin['id'];
  551. Dever::db('active/code')->update($w);
  552. }
  553. return 'reload';
  554. }
  555. public function setOrder_api($order_id,$code_id){
  556. $data = Dever::db('active/order')->find($order_id);
  557. $ids = $this->common($data,3);
  558. if ($ids) {
  559. $admin = Dever::load('manage/auth.info');
  560. $w['where_id'] = $code_id;
  561. $w['status'] = 3;
  562. $w['offdate'] = time();
  563. $w['audit_admin'] = $admin['id'];
  564. Dever::db('active/code')->update($w);
  565. }
  566. return 'reload';
  567. }
  568. public function common($data,$type,$num=false,$refund_id=false,$refund_price=false,$refund_desc=false){
  569. Dever::config('base')->hook = true;
  570. $active = Dever::db('active/info')->find($data['active_id']);
  571. $info = Dever::db('active/info_refund')->state(array('order_id'=>$data['id']));
  572. if (time() > $active['act_start']) {
  573. // Dever::alert('活动已开始,不能退款');
  574. }
  575. if ($type == 1) {
  576. $code = Dever::db('active/code')->find(array('order_id'=>$data['id']));
  577. if ($data['code_num'] > 0 || (isset($code) && $code)) {
  578. Dever::alert('此状态下不可退款');
  579. }
  580. if ($data['status'] != 2) {
  581. Dever::alert('此状态下不可退款');
  582. }
  583. $refund_num = $data['num'];
  584. $price = $data['price'];
  585. }
  586. if ($type == 2) {
  587. if ($refund_price) {
  588. $price = $num * $refund_price;
  589. } else {
  590. $price = $num * $active['price'];
  591. }
  592. $refund_num = $num;
  593. }
  594. if ($type == 3) {
  595. $refund_num = 1;
  596. if ($refund_price) {
  597. $price = $refund_price;
  598. } else {
  599. $price = $active['price'];
  600. }
  601. }
  602. // if ($refund_desc) {
  603. // $where['desc'] = $refund_desc;
  604. // }
  605. $param = array
  606. (
  607. 'project_id' => 6,
  608. 'channel_id' => 1,
  609. 'system_source' => 1,
  610. 'account_id' => 8,
  611. 'order_id' => $data['order_num'],
  612. 'refund_cash' => $price,
  613. //'refund_order_id' => '',
  614. );
  615. if ($type != 1) {
  616. $param['refund_order_id'] = count($info) + 1;
  617. }
  618. if ($data['price'] > 0) {
  619. $result = Dever::load('pay/api.refund', $param);
  620. if (!$result) {
  621. # 退款失败,抛出错误
  622. //throw new \Exception('退款失败');
  623. Dever::alert('退款失败,请联系管理员');
  624. } else {
  625. $admin = Dever::load('manage/auth.info');
  626. $time = time();
  627. $where['where_id'] = $data['id'];
  628. $where['status'] = 6;
  629. $where['refund_admin'] = $admin['id'];
  630. $where['rdate'] = $time;
  631. if (!$data['refund_num']) {
  632. $data['refund_num'] = 0;
  633. }
  634. $where['refund_num'] = $refund_num + $data['refund_num'];
  635. if ($type == 1 || ($price == $data['price']) || ($data['num'] == $where['refund_num'])) {
  636. $ids = Dever::db('active/order')->update($where);
  637. } else {
  638. // $where['status'] = 2;
  639. $where['status'] = 7;
  640. $ids = Dever::db('active/order')->update($where);
  641. }
  642. if ($type == 2) {
  643. $insert['status'] = 2;
  644. $insert['where_id'] = $refund_id;
  645. $insert['audit_admin'] = $admin['id'];
  646. if ($refund_desc) {
  647. $insert['desc'] = $refund_desc;
  648. }
  649. $insert['price'] = $price;
  650. Dever::db('active/info_refund')->update($insert);
  651. } elseif ($type == 3) {
  652. $add['status'] = 2;
  653. $add['order_id'] = $data['id'];
  654. $add['num'] = 1;
  655. $add['price'] = $price;
  656. if ($refund_desc) {
  657. $add['desc'] = $refund_desc;
  658. }
  659. Dever::db('active/info_refund')->insert($add);
  660. }
  661. if (isset($ids) && $ids){
  662. return $ids;
  663. }
  664. }
  665. }
  666. }
  667. #扫码核销活动
  668. public function code_api(){
  669. $active_id = Dever::input('id');
  670. if (!$active_id) {
  671. return '活动id不存在';
  672. }
  673. $active = Dever::db('active/info')->find($active_id);
  674. $config = Dever::db('active/info')->config['config_act_status'];
  675. $code = Dever::input('code');
  676. if (!$code) {
  677. $data = array();
  678. $data['active_name'] = $active['name'];
  679. $data['status'] = Dever::status($config,$active['act_status']);
  680. $data['act_time'] = date('Y.m.d H:i:s',$active['act_start']).'~'.date('Y.m.d H:i:s',$active['act_end']);
  681. $data['active_id'] = $active_id;
  682. $one = Dever::db('active/code')->find(array('code'=>$code));
  683. $data['seat_num'] = $one['seat_num'];
  684. return Dever::render('off_code', $data);
  685. }
  686. // print_R($code);die;
  687. $data = Dever::db('active/code')->find(array('write_code'=>$code,'active_id'=>$active_id,'status'=>1));
  688. if ($data) {
  689. $data['active_name'] = $active['name'];
  690. $data['status'] = Dever::status($config,$active['act_status']);
  691. $data['act_time'] = date('Y.m.d H:i:s',$active['act_start']).'~'.date('Y.m.d H:i:s',$active['act_end']);
  692. $join_user = Dever::db('active/user')->find($data['join_uid']);
  693. $data['join_name'] = $join_user['name'];
  694. $data['join_mobile'] = $join_user['mobile'];
  695. $con = Dever::db('deploy/base-one');
  696. if ($join_user['avatar']) {
  697. $data['join_avatar'] = $join_user['avatar'];
  698. } else {
  699. $data['join_avatar'] = $con['avatar'];
  700. }
  701. $data['buy_name'] = '';
  702. $data['buy_mobile'] = '';
  703. $data['buy_avatar'] = '';
  704. $buy_user = Dever::db('active/user')->find($data['buy_uid']);
  705. if ($buy_user) {
  706. $data['buy_name'] = $buy_user['name'];
  707. $data['buy_mobile'] = $buy_user['mobile'];
  708. $data['buy_avatar'] = '';
  709. if ($buy_user['avatar']) {
  710. $data['buy_avatar'] = $buy_user['avatar'];
  711. }
  712. }
  713. $member = Dever::load('active/lib/user')->agent($buy_user);
  714. $data['role_name'] ='';
  715. $data['title_name'] = '';
  716. if ($member) {
  717. $role = Dever::db('setting/role')->find($member['role']);
  718. $title = Dever::db('setting/title')->find($member['title_id']);
  719. $level = Dever::db('setting/level')->find($member['level_id']);
  720. if ($role) {
  721. if (isset($level) && $level && isset($level['name']) && $level['name']) {
  722. $data['role_name'] = $role['name'] .'('.$level['name'].')';
  723. } else {
  724. $data['role_name'] = $role['name'];
  725. }
  726. }
  727. if ($title && $title['name']) {
  728. $data['title_name'] = $title['name'];
  729. }
  730. if (!$data['buy_avatar']) {
  731. $data['buy_avatar'] = $member['avatar'];
  732. } else {
  733. $data['buy_avatar'] = $con['avatar'];
  734. }
  735. }
  736. } else {
  737. return '核销码不存在或已核销';
  738. }
  739. $type = Dever::input('type');
  740. if ($type == 1) {
  741. return Dever::render('off_code', $data);
  742. }else {
  743. return $data;
  744. }
  745. }
  746. }