Manage.php 32 KB

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