Manage.php 30 KB

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