Manage.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. namespace Option\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function updateMember($id, $name, $data)
  7. {
  8. Dever::config('base')->hook = true;
  9. $where['id'] = $id;
  10. $where['clear'] = true;
  11. $info = Dever::db('option/member')->find($where);
  12. if ($info) {
  13. if ($info['main'] == 1) {
  14. $update['mid'] = $id;
  15. $account = Dever::db('option/account')->one($update);
  16. if (!$account) {
  17. $update['audit'] = 1;
  18. $aid = Dever::db('option/account')->insert($update);
  19. } else {
  20. $aid = $account['id'];
  21. }
  22. Dever::db('option/member')->update(array('where_id' => $info['id'], 'aid' => $aid));
  23. }
  24. $main = Dever::db('option/member')->getMain(array('key' => $info['key']));
  25. if ($main && $main['aid']) {
  26. $where = array();
  27. $where['option_key'] = $info['key'];
  28. $where['set_aid'] = $main['aid'];
  29. Dever::db('option/member')->updates($where);
  30. }
  31. }
  32. }
  33. public function updateMain($id, $name, $data)
  34. {
  35. Dever::config('base')->hook = true;
  36. $main = Dever::param('main', $data);
  37. if ($main && $main == 1) {
  38. $member = Dever::db('option/member')->find($id);
  39. if ($member) {
  40. $main_member = Dever::db('option/member')->select(array('main' => 1, 'aid' => $member['aid']));
  41. if ($main_member) {
  42. foreach ($main_member as $k => $v) {
  43. if ($v['id'] != $id) {
  44. Dever::db('option/member')->update(array('where_id' => $v['id'], 'main' => 2));
  45. }
  46. }
  47. }
  48. $account = Dever::db('option/account')->find($member['aid']);
  49. if ($account) {
  50. Dever::db('option/account')->update(array('where_id' => $account['id'], 'mid' => $member['id']));
  51. }
  52. }
  53. }
  54. }
  55. public function updateAccount($id, $name, $data)
  56. {
  57. Dever::config('base')->hook = true;
  58. $update = array();
  59. $audit = Dever::param('audit', $data);
  60. $desc = Dever::param('audit_desc', $data);
  61. $send_email = Dever::param('send_email', $data);
  62. $email = Dever::param('email', $data);
  63. $info = Dever::db('option/account')->one($id);
  64. if ($info) {
  65. if ($audit && $audit > 2) {
  66. $update['audit_date'] = time();
  67. $update['where_id'] = $info['id'];
  68. Dever::db('option/account')->update($update);
  69. }
  70. if ($send_email == 2 && (($email && $email != $info['email']) || $info['is_email'] == 2)) {
  71. $update = array();
  72. $update['is_email'] = 2;
  73. $update['where_id'] = $info['id'];
  74. Dever::db('option/account')->update($update);
  75. if ($send_email == 2) {
  76. $member = Dever::db('option/member')->one($info['mid']);
  77. if ($member) {
  78. $code = Dever::load('passport/reg')->code(false, false);
  79. $email = base64_encode($email);
  80. //Dever::daemon('lib/email.renzheng?aid='.$info['id'].'&email=' . $email . '&code=' . $code . '&username=' . $member['name'], 'option');
  81. Dever::load('option/lib/email.renzheng?aid='.$info['id'].'&email=' . $email . '&code=' . $code . '&username=' . $member['name']);
  82. }
  83. }
  84. }
  85. $member = Dever::db('option/member')->one($info['mid']);
  86. if ($audit == 3) {
  87. if (Dever::project('sms')) {
  88. Dever::load('sms/api')->send('qiquan_reg_yes', $member['mobile'], array('name' => $member['name']));
  89. }
  90. } elseif ($audit == 4) {
  91. if (Dever::project('sms')) {
  92. Dever::load('sms/api')->send('qiquan_reg_no', $member['mobile'], array('name' => $member['name'], 'content' => $desc));
  93. }
  94. }
  95. }
  96. }
  97. # 协议审核
  98. public function setAgreement($id, $name, $data)
  99. {
  100. Dever::config('base')->hook = true;
  101. $update = array();
  102. $audit = Dever::param('audit', $data);
  103. $desc = Dever::param('audit_desc', $data);
  104. if ($audit > 1) {
  105. $mul_type = Dever::config('base')->mul_type;
  106. if ($mul_type == 2) {
  107. $list = Dever::db('option/agreement')->select(array('status' => 2));
  108. } else {
  109. $list = explode(',', $id);
  110. }
  111. $admin = Dever::load('manage/auth.info');
  112. if (!$admin) {
  113. foreach ($list as $k => $v) {
  114. Dever::db('option/agreement')->update(array('where_id' => $v, 'audit' => 2));
  115. }
  116. Dever::alert('请先登录');
  117. }
  118. $update['audit_date'] = time();
  119. $update['audit_admin'] = $admin['id'];
  120. if ($audit == 3) {
  121. $update['status'] = 2;
  122. }
  123. foreach ($list as $k => $v) {
  124. $info = Dever::db('option/agreement')->one($v);
  125. if ($info) {
  126. $update['where_id'] = $info['id'];
  127. $state = Dever::db('option/agreement')->update($update);
  128. if ($state && $audit == 3) {
  129. Dever::load('option/lib/cash.setValue_act', $info);
  130. }
  131. if ($audit == 3) {
  132. if (Dever::project('sms')) {
  133. Dever::load('sms/api')->send('qiquan_audit', $info['mobile'], array('name' => $info['name']));
  134. }
  135. } elseif ($audit == 4) {
  136. if (Dever::project('sms')) {
  137. Dever::load('sms/api')->send('qiquan_audit', $info['mobile'], array('name' => $info['name'], 'content' => $desc));
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. # 交付审核 已废弃
  145. public function setJiaofu($id, $name, $data)
  146. {
  147. Dever::config('base')->hook = true;
  148. $update = array();
  149. $audit = Dever::param('audit', $data);
  150. $info = Dever::db('option/bill_jiaofu')->one($id);
  151. if ($audit > 1 && $info) {
  152. $admin = Dever::load('manage/auth.info');
  153. $update['audit_date'] = time();
  154. $update['audit_admin'] = $admin['id'];
  155. $update['where_id'] = $info['id'];
  156. $state = Dever::db('option/bill_jiaofu')->update($update);
  157. if ($state && $audit == 3) {
  158. Dever::load('option/lib/cash.setValue_commit', $info);
  159. }
  160. }
  161. }
  162. public function setFafang($id, $name, $data)
  163. {
  164. Dever::config('base')->hook = true;
  165. $update = array();
  166. $audit = Dever::param('audit', $data);
  167. $info = Dever::db('option/bill_fafang')->one($id);
  168. if ($audit > 1 && $info) {
  169. $admin = Dever::load('manage/auth.info');
  170. $update['audit_date'] = time();
  171. $update['audit_admin'] = $admin['id'];
  172. $update['where_id'] = $info['id'];
  173. $state = Dever::db('option/bill_fafang')->update($update);
  174. if ($state && $audit == 2) {
  175. # 已作废,减掉这个数据
  176. $account_cash = Dever::db('option/cash')->find(array('type' => $info['type'], 'aid' => $info['aid']));
  177. if ($account_cash) {
  178. $update['where_id'] = $account_cash['id'];
  179. $update['fafang'] = $account_cash['fafang'] - $info['cash'];
  180. $update['jiaofu'] = $account_cash['jiaofu'] + $info['cash'];
  181. if ($update['fafang'] < 0) {
  182. $update['fafang'] = 0;
  183. }
  184. $update['clear'] = true;
  185. Dever::db('option/cash')->update($update);
  186. }
  187. }
  188. }
  189. }
  190. public function setDuifu($id, $name, $data)
  191. {
  192. Dever::config('base')->hook = true;
  193. $update = array();
  194. $audit = Dever::param('audit', $data);
  195. $info = Dever::db('option/bill_duifu')->one($id);
  196. if ($audit && $audit > 1 && $info) {
  197. $admin = Dever::load('manage/auth.info');
  198. $update['audit_date'] = time();
  199. $update['audit_admin'] = $admin['id'];
  200. $update['where_id'] = $info['id'];
  201. $state = Dever::db('option/bill_duifu')->update($update);
  202. if ($state && $audit == 2) {
  203. # 已作废,恢复这个数据
  204. $account_cash = Dever::db('option/cash')->find(array('type' => $info['type'], 'aid' => $info['aid']));
  205. if ($account_cash) {
  206. $update['where_id'] = $account_cash['id'];
  207. $update['duifu'] = $account_cash['duifu'] - $info['cash'];
  208. $update['fafang'] = $account_cash['fafang'] + $info['cash'];
  209. if ($update['duifu'] < 0) {
  210. $update['duifu'] = 0;
  211. }
  212. $update['clear'] = true;
  213. Dever::db('option/cash')->update($update);
  214. }
  215. }
  216. }
  217. }
  218. public function cashUpdate($id, $name, $data)
  219. {
  220. Dever::config('base')->hook = true;
  221. $aid = Dever::param('aid', $data);
  222. $mid = Dever::param('mid', $data);
  223. $type = Dever::param('type', $data);
  224. $cash = Dever::param('cash', $data);
  225. $desc = Dever::param('desc', $data);
  226. if ($aid && $type && $cash && $desc) {
  227. $account = Dever::db('option/account')->find($aid);
  228. if ($account && $account['status'] <= 2) {
  229. Dever::load('option/lib/cash')->up($aid, $mid, $type, $cash, $desc);
  230. } else {
  231. Dever::db('option/push_cash')->update(array('where_id' => $id, 'status' => 2));
  232. Dever::alert('期权账户已停用或者未审核,操作失败');
  233. }
  234. }
  235. }
  236. public function getDate($id)
  237. {
  238. $info = Dever::db('option/agreement')->find($id);
  239. if ($info) {
  240. $html = '';
  241. $html .= '处理时间:' . date('Y-m-d H:i', $info['cdate']);
  242. if ($info['qdate']) {
  243. $html .= '<br />确认时间:' . date('Y-m-d H:i', $info['qdate']);
  244. }
  245. if ($info['audit_date']) {
  246. $html .= '<br />审核时间:' . date('Y-m-d H:i', $info['audit_date']);
  247. }
  248. return $html;
  249. }
  250. return '';
  251. }
  252. public function upAgreement_api()
  253. {
  254. $id = Dever::input('id');
  255. if ($id) {
  256. Dever::load('option/lib/agreement')->upContent($id);
  257. }
  258. return 'reload';
  259. }
  260. public function dropAgreement_api()
  261. {
  262. $id = Dever::input('id');
  263. if ($id) {
  264. Dever::load('option/lib/agreement')->drop($id);
  265. }
  266. return 'reload';
  267. }
  268. public function checkMember($id, $name, $data)
  269. {
  270. $main = Dever::param('main', $data);
  271. $key = Dever::param('key', $data);
  272. if (!$key) {
  273. Dever::alert('请传入账户索引');
  274. }
  275. if ($main == 2) {
  276. $main = Dever::db('option/member')->getMain(array('key' => $key));
  277. if (!$main) {
  278. Dever::alert('请先创建主账号');
  279. }
  280. } elseif ($main == 1) {
  281. $main = Dever::db('option/member')->getMain(array('key' => $key));
  282. if ($main) {
  283. Dever::alert('已存在主账号');
  284. }
  285. }
  286. }
  287. public function setAudit($id, $name, $data)
  288. {
  289. $audit = Dever::param('audit', $data);
  290. if ($audit == 3) {
  291. $data['set_audit_desc'] = 'null';
  292. return $data;
  293. } else {
  294. return $data;
  295. }
  296. }
  297. }