Manage.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <?php
  2. namespace Active\Lib;
  3. use Dever;
  4. Class Manage
  5. {
  6. #全额退款
  7. public function refund_api($id)
  8. {
  9. $data = Dever::db('active/order')->find($id);
  10. if ($data['mid'] && $data['mid'] > 0) {
  11. $user = Dever::db('active/user')->find(array('mid'=>$data['mid']));
  12. if ($user && $user['id']) {
  13. $uid = $user['id'];
  14. }
  15. } else {
  16. $uid = $data['uid'];
  17. }
  18. $this->common($data,1);
  19. return 'reload';
  20. }
  21. public function insertInfoRefund ($id,$name,$data)
  22. {
  23. $num = Dever::param('num',$data);
  24. $order_id = Dever::param('order_id',$data);
  25. $data = Dever::db('active/order')->find($order_id);
  26. if($num > $data['num']) {
  27. Dever::alert('退款数量大于购买数量');
  28. }
  29. $info = Dever::db('active/info_refund')->state(array('order_id'=>$order_id));
  30. $count = $data['num'] - count($info);
  31. if ($num > $count) {
  32. Dever::alert('退款数量大于购买数量');
  33. }
  34. }
  35. public function updateInfoRefund ($id,$name,$data)
  36. {
  37. $num = Dever::param('num',$data);
  38. $order_id = Dever::param('order_id',$data);
  39. $code_id = Dever::param('code_id',$data);
  40. $data = Dever::db('active/order')->find($order_id);
  41. // $info = Dever::db('active/info_refund')->state(array('order_id'=>$order_id));
  42. // $active = Dever::db('active/info')->find($data['active_id']);
  43. $this->common($data,2,$num,$id);
  44. return 'reload';
  45. }
  46. public function show($id)
  47. {
  48. $data = Dever::db('active/order')->find($id);
  49. $refund_admin = '-';
  50. $rdate = '-';
  51. if ($data && isset($data['refund_admin']) && $data['refund_admin'] && $data['refund_admin']>0 && $data['rdate']) {
  52. $admin = Dever::load('manage/admin-find',$data['refund_admin']);
  53. $refund_admin = $admin['username'];
  54. $rdate = date('Y-m-d H:i',$data['rdate']);
  55. }
  56. $html = $refund_admin.'<br/>'.$rdate;
  57. return $html;
  58. }
  59. public function active($id)
  60. {
  61. $data = Dever::db('active/info')->find($id);
  62. $html = array();
  63. $html['active_name'] = $data['name'];
  64. $info = Dever::db('active/code')->find($id);
  65. if ($info && isset($info['audit_admin']) && $info['audit_admin'] && $info['audit_admin'] > 0) {
  66. $aduit = Dever::load('manage/admin-find',$info['audit_admin']);
  67. $html['admin_name'] = $aduit['username'];
  68. } elseif ($info && $info['top_admin']) {
  69. $off = Dever::db('active/info_off')->find($info['top_admin']);
  70. $html['admin_name'] = $off['name'];
  71. }
  72. return $html;
  73. }
  74. public function user($id)
  75. {
  76. $data = Dever::db('active/user')->find($id);
  77. $html = $data['name'].'<br/>'.$data['mobile'];
  78. return $html;
  79. }
  80. public function dOff($id)
  81. {
  82. $data = Dever::db('active/code')->state(array('active_id' => $id,'status'=>1));
  83. $html = count($data);
  84. return $html;
  85. }
  86. public function insertInfoCode($id, $name, $data)
  87. {
  88. $code = Dever::param('code',$data);
  89. if ($code) {
  90. $info = Dever::db('active/info_code')->find(array('code'=>$code));
  91. if ($info['code']) {
  92. Dever::alert('核销码已核销');
  93. }
  94. }
  95. }
  96. public function updateInfoCode($id, $name, $data)
  97. {
  98. $code = Dever::param('code',$data);
  99. $data = Dever::db('active/code')->find(array('write_code'=>$code));
  100. if ($data) {
  101. $where['where_id'] = $data['id'];
  102. $where['status'] = 2;
  103. $where['offdate'] = time();
  104. $admin = Dever::load('manage/admin-find');
  105. $where['audit_admin'] = $admin['id'];
  106. Dever::db('active/code')->update($where);
  107. }
  108. }
  109. public function get()
  110. {
  111. $data[0]['name'] = '头衔';
  112. $data[0]['child'] = Dever::db('setting/title')->select();
  113. $data['state'] = 1;
  114. return $data;
  115. }
  116. public function search_api()
  117. {
  118. $value = Dever::input('value');
  119. if (!$value) {
  120. return '核销码不存在';
  121. }
  122. if ($value) {
  123. $data = Dever::db('active/code')->one(array('write_code' => $value,'state' =>1));
  124. $table = array();
  125. if ($data) {
  126. $user = Dever::db('active/user')->find(array('id'=>$data['join_uid']));
  127. $parent = Dever::db('active/user')->find(array('id'=>$data['buy_uid']));
  128. $table = array();
  129. $table['head'] = array('姓名', '手机号','邀请人', '邀请人手机号');
  130. $table['body'] = array();
  131. $table['body'] = array($user['name'], $user['mobile'],$parent['name'], $parent['mobile']);
  132. $result[] = array
  133. (
  134. 'type' => 'table',
  135. 'content' => $table,
  136. );
  137. $html = Dever::show('', $result, false, false);
  138. return $html;
  139. }else{
  140. return '核销码不存在';
  141. }
  142. } else {
  143. return '';
  144. }
  145. }
  146. public function checkMcode()
  147. {
  148. $mobile = Dever::input('mobile');
  149. $code = Dever::input('mcode');
  150. if (!$code) {
  151. Dever::alert('请输入验证码');
  152. }
  153. $code = Dever::load('passport/reg')->mcode($mobile, $code, 2);
  154. if (!$code) {
  155. Dever::alert('验证码输入错误');
  156. }
  157. return 'ok';
  158. }
  159. public function list()
  160. {
  161. $id = Dever::input('id');
  162. $info = Dever::db('active/order')->find($id);
  163. $active = Dever::db('active/info')->find($info['active_id']);
  164. $config = Dever::db('active/order')->config['config_status'];
  165. $status = Dever::status($config,$info['status']);
  166. if ( !$info['uid']) {
  167. $user = Dever::db('active/user')->find($info['mid']);
  168. $info['uid'] = $user['id'];
  169. }
  170. $code = Dever::db('active/code')->getCode(array('order_id' => $id,'status'=>'1,2'));
  171. $use_code = count($code);#已领取的所有数量
  172. if (!$info['refund_num']) {
  173. $info['refund_num'] = 0;
  174. }
  175. $no_code = $info['num'] - $use_code - $info['refund_num'];#未使用的数量
  176. if ($info['mid'] && $info['mid'] > 0) {
  177. $user = Dever::db('active/user')->find($info['mid']);
  178. $member = Dever::db('agent/member')->find($info['mid']);
  179. $code = Dever::db('active/code')->state(array('order_id' => $id));
  180. $use_code = count($code);
  181. $no_code = $info['num'] - $use_code;
  182. if ($info['uid'] && $info['uid'] > 0) {
  183. $user = Dever::db('active/user')->find($info['uid']);
  184. $user_name = $user['name'];
  185. $user_mobile = $user['mobile'];
  186. $user_idcard = $user['idcard'];
  187. $member = Dever::load('active/lib/user')->agent($user);
  188. if ($member) {
  189. $role = Dever::db('setting/role')->find($member['role']);
  190. if (isset($role) && $role && isset($role['name']) && $role['name']) {
  191. $role_name = '<br/>'.$role['name'];
  192. } else {
  193. $role_name = '';
  194. }
  195. $title = Dever::db('setting/title')->find($member['title_id']);
  196. if (isset($title) && $title && isset($title['name']) && $title['name']) {
  197. $title_name = '('.$title['name'].')';
  198. } else {
  199. $title_name = '';
  200. }
  201. $level = Dever::db('setting/level')->find($member['level_id']);
  202. if (isset($level) && $level && isset($level['name']) && $level['name']) {
  203. $level_name = '('.$level['name'].')';
  204. } else {
  205. $level_name = '';
  206. }
  207. $user_name = $member['name'].$role_name.$title_name.$level_name;
  208. $user_mobile = $member['mobile'];
  209. $user_idcard = $member['idcard'];
  210. }
  211. }
  212. $result['订单信息'] = array
  213. (
  214. 'type' => 'info',
  215. 'content' => array
  216. (
  217. array
  218. (
  219. array('订单单号', $info['order_num']),
  220. array('活动名称', $active['name']),
  221. array('订单状态', $status),
  222. ),
  223. array
  224. (
  225. array('购买数量', $info['num']),
  226. array('支付金额', $info['price']),
  227. ),
  228. array
  229. (
  230. array('已使用', $use_code),
  231. array('未使用', $no_code),
  232. array('退款数量', $info['refund_num']),
  233. ),
  234. ),
  235. );
  236. $result['用户信息'] = array
  237. (
  238. 'type' => 'info',
  239. 'content' => array
  240. (
  241. array
  242. (
  243. array('用户姓名', $user_name),
  244. array('用户电话', $user_mobile),
  245. array('用户身份证号', $user_idcard),
  246. ),
  247. ),
  248. );
  249. $button = array();
  250. if ($info['status'] > 1 && $no_code > 0) {
  251. if (Dever::load('manage/auth')->checkFunc('active.order', 'editrefund', '未使用退款')) {
  252. $purl = Dever::url('project/database/update?project=active&table=info_refund&search_option_order_id='.$info['id'].'&col=num,order_id', 'manage');
  253. $button[] = array
  254. (
  255. 'type' => 'edit',
  256. 'link' => $purl,
  257. 'name' => '未使用退款',
  258. );
  259. }
  260. }
  261. if ($use_code > 0) {
  262. $result += $this->table($id);
  263. }
  264. $head = array
  265. (
  266. 'name' => '基本资料',
  267. 'btn' => $button,
  268. );
  269. $html = Dever::show($head, $result);
  270. return $html;
  271. }
  272. private function table ($id)
  273. {
  274. $data = Dever::db('active/code')->state(array('order_id' => $id));
  275. if ($data) {
  276. $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销时间', '核销人', '管理');
  277. $body = array();
  278. foreach ($data as $k => $v) {
  279. $user = Dever::db('active/user')->find($v['join_uid']);
  280. $join_name = '';
  281. if ($user) {
  282. $join_name = $user['name'].'<br/>'.$user['mobile'];
  283. }
  284. $admin_name = '';
  285. if ($v['status'] == 1) {
  286. $status = '待核销';
  287. } elseif($v['status'] == 2) {
  288. $status = '已核销';
  289. if ($v['audit_admin'] && $v['audit_admin'] >0) {
  290. $admin = Dever::load('manage/admin-find',$v['audit_admin']);
  291. if ($admin) {
  292. $admin_name = $admin['username'];
  293. }
  294. } else {
  295. if ($v['top_admin'] && $v['top_admin'] > 0) {
  296. $admin = Dever::db('active/info_off')->find($v['top_admin']);
  297. if ($admin) {
  298. $admin_name = $admin['name'];
  299. }
  300. }
  301. }
  302. } else {
  303. $status = '已作废';
  304. }
  305. $cdate = '';
  306. if ($v['cdate']) {
  307. $cdate = date('Y-m-d H:i',$v['cdate']);
  308. }
  309. $offdate = '';
  310. if ($v['offdate']) {
  311. $offdate = date('Y-m-d H:i',$v['offdate']);
  312. }
  313. $m = '';
  314. if ($v['status'] == 1) {
  315. $url = Dever::url('lib/manage.setOrder&order_id=' . $v['order_id'].'&code_id='.$v['id'], 'active');
  316. $m = '<a href="javascript:;" onclick="load( \''.$url.'\')" class="layui-btn">退款</a>';
  317. }
  318. $d = array
  319. (
  320. $join_name,
  321. $v['write_code'],
  322. $status,
  323. $cdate,
  324. $offdate,
  325. $admin_name,
  326. $m,
  327. );
  328. $body[] = $d;
  329. }
  330. $result['核销码使用列表'] = array
  331. (
  332. 'type' => 'table',
  333. 'content' => array
  334. (
  335. 'head' => $head,
  336. 'body' => $body,
  337. )
  338. );
  339. return $result;
  340. }
  341. }
  342. public function setOrder_api($order_id,$code_id){
  343. $data = Dever::db('active/order')->find($order_id);
  344. $ids = $this->common($data,3,'',$code_id);
  345. if ($ids) {
  346. $w['where_id'] = $code_id;
  347. $w['status'] = 3;
  348. Dever::db('active/code')->update($w);
  349. }
  350. return 'reload';
  351. }
  352. public function common($data,$type,$num=false,$refund_id=false){
  353. $active = Dever::db('active/info')->find($data['active_id']);
  354. $info = Dever::db('active/info_refund')->state(array('order_id'=>$data['id']));
  355. if (time() > $active['act_start']) {
  356. Dever::alert('活动已开始,不能退款');
  357. }
  358. if ($type == 1) {
  359. if ($data['status'] != 2) {
  360. Dever::alert('此状态下不可退款');
  361. }
  362. $refund_num = $data['num'];
  363. $price = $data['price'];
  364. }
  365. if ($type == 2) {
  366. $price = $num * $active['price'];
  367. $refund_num = $num;
  368. }
  369. if ($type == 3) {
  370. $refund_num = 1;
  371. $price = $active['price'];
  372. }
  373. $param = array
  374. (
  375. 'project_id' => 6,
  376. 'channel_id' => 1,
  377. 'system_source' => 1,
  378. 'account_id' => 8,
  379. 'order_id' => $data['order_num'],
  380. 'refund_cash' => $price,
  381. //'refund_order_id' => '',
  382. );
  383. if ($type != 1) {
  384. $param['refund_order_id'] = $data['order_num'] . '_' . count($info);
  385. }
  386. if ($data['price'] > 0) {
  387. $result = Dever::load('pay/api.refund', $param);
  388. if (!$result) {
  389. # 退款失败,抛出错误
  390. //throw new \Exception('退款失败');
  391. Dever::alert('退款失败,请联系管理员');
  392. } else {
  393. $admin = Dever::load('manage/auth.data');
  394. $time = time();
  395. $where['where_id'] = $data['id'];
  396. $where['status'] = 6;
  397. $where['refund_admin'] = $admin['id'];
  398. $where['rdate'] = $time;
  399. if (!$data['refund_num']) {
  400. $data['refund_num'] = 0;
  401. }
  402. $where['refund_num'] = $refund_num + $data['refund_num'];
  403. if ($type == 1 || ($type == 2 && $price = $data['price'])) {
  404. Dever::db('active/order')->update($where);
  405. } elseif (($type == 2 && $price != $data['price']) || $type == 3) {
  406. $where['status'] = 5;
  407. $ids = Dever::db('active/order')->update($where);
  408. return $ids;
  409. }
  410. if ($type == 2) {
  411. $insert['status'] = 2;
  412. $insert['where_id'] = $refund_id;
  413. $insert['audit_admin'] = $admin['id'];
  414. Dever::db('active/info_refund')->update($insert);
  415. }
  416. }
  417. }
  418. }
  419. #更新数量
  420. public function upNum_api($order_id)
  421. {
  422. $data = Dever::db('active/order')->find($order_id);
  423. if (!$data['refund_num']) {
  424. $w['refund_num'] = 0;
  425. } else {
  426. $w['refund_num'] =$data['refund_num'];
  427. }
  428. if (!$data['code_num']) {
  429. $w['code_num'] = 0;
  430. }
  431. if (!$data['no_num']) {
  432. $w['no_num'] = 0;
  433. }
  434. #已使用的数量
  435. $code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>'1,2'));
  436. $w['code_num'] = count($code);
  437. #待核销的数量
  438. $no_code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>1));
  439. $w['no_num'] = count($no_code);
  440. $w['where_id'] = $data['id'];
  441. Dever::db('active_order')->update($w);
  442. }
  443. }