Manage.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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/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, 'buy_uid'=>$info['uid']));
  248. $use_code = count($code);
  249. $no_code = $info['num'] - $use_code;
  250. if ($info['mid'] && $info['mid'] > 0) {
  251. $user = Dever::db('active/user')->find($info['mid']);
  252. $member = Dever::db('agent/member')->find($info['mid']);
  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. } elseif ($info['uid'] && $info['uid'] > 0) {
  277. $user = Dever::db('active/user')->find($info['uid']);
  278. if ($user) {
  279. $user_name = $user['name'];
  280. $user_mobile = $user['mobile'];
  281. $user_idcdard = $user['idcard'];
  282. }
  283. }
  284. $result['订单信息'] = array
  285. (
  286. 'type' => 'info',
  287. 'content' => array
  288. (
  289. array
  290. (
  291. array('订单单号', $info['order_num']),
  292. array('活动名称', $active['name']),
  293. array('订单状态', $status),
  294. ),
  295. array
  296. (
  297. array('购买数量', $info['num']),
  298. array('支付金额', $info['price']),
  299. ),
  300. array
  301. (
  302. array('已使用', $use_code),
  303. array('未使用', $no_code),
  304. ),
  305. ),
  306. );
  307. $result['用户信息'] = array
  308. (
  309. 'type' => 'info',
  310. 'content' => array
  311. (
  312. array
  313. (
  314. array('用户姓名', $user_name),
  315. array('用户电话', $user_mobile),
  316. array('用户身份证号', $user_idcard),
  317. ),
  318. ),
  319. );
  320. if ($use_code > 0) {
  321. $result += $this->table($id,$user['id']);
  322. }
  323. $head = array
  324. (
  325. 'name' => '基本资料',
  326. 'btn' => '',
  327. );
  328. $html = Dever::show($head, $result);
  329. return $html;
  330. }
  331. private function table ($id,$uid)
  332. {
  333. $data = Dever::db('active/code')->state(array('order_id' => $id, 'join_uid' => $uid));
  334. if ($data) {
  335. $head = array('参加人信息', '核销码', '核销状态', '领取时间', '核销时间','核销人');
  336. $body = array();
  337. foreach ($data as $k => $v) {
  338. $user = Dever::db('active/user')->find($v['join_uid']);
  339. $join_name = '';
  340. if ($user) {
  341. $join_name = $user['name'].'<br/>'.$user['mobile'];
  342. }
  343. $admin_name = '';
  344. if ($v['status'] == 1) {
  345. $status = '待核销';
  346. } else {
  347. $status = '已核销';
  348. if ($v['audit_admin'] && $v['audit_admin'] >0) {
  349. $admin = Dever::load('manage/admin-find',$v['audit_admin']);
  350. if ($admin) {
  351. $admin_name = $admin['username'];
  352. }
  353. } else {
  354. if ($v['top_admin'] && $v['top_admin'] > 0) {
  355. $admin = Dever::db('active/info_off')->find($v['top_admin']);
  356. if ($admin) {
  357. $admin_name = $admin['name'];
  358. }
  359. }
  360. }
  361. }
  362. $cdate = '';
  363. if ($v['cdate']) {
  364. $cdate = date('Y-m-d H:i',$v['cdate']);
  365. }
  366. $offdate = '';
  367. if ($v['offdate']) {
  368. $offdate = date('Y-m-d H:i',$v['offdate']);
  369. }
  370. $d = array
  371. (
  372. $join_name,
  373. $v['write_code'],
  374. $status,
  375. $cdate,
  376. $offdate,
  377. $admin_name,
  378. );
  379. $body[] = $d;
  380. }
  381. $result['核销码使用列表'] = array
  382. (
  383. 'type' => 'table',
  384. 'content' => array
  385. (
  386. 'head' => $head,
  387. 'body' => $body,
  388. )
  389. );
  390. return $result;
  391. }
  392. }
  393. // #将已经注册活动的用户放到用户表中
  394. // public function user_cron()
  395. // {
  396. // $data = Dever::db('active/order')->state();
  397. // foreach ($data as $k => $v) {
  398. // $user = Dever::db('active/user')->find(array('mid'=>$v['mid']));
  399. // if (!$user) {
  400. // $member = Dever::db('agent/member')->find($v['mid']);
  401. // $where['mobile'] = $member['mobile'];
  402. // $where['idcard'] = $member['idcard'];
  403. // }
  404. // }
  405. // }
  406. }