Manage.php 15 KB

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