Manage.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 updateAccount($id, $name, $data)
  34. {
  35. Dever::config('base')->hook = true;
  36. $update = array();
  37. $audit = Dever::param('audit', $data);
  38. $send_email = Dever::param('send_email', $data);
  39. $email = Dever::param('email', $data);
  40. $info = Dever::db('option/account')->one($id);
  41. if ($info) {
  42. if ($audit && $audit > 2) {
  43. $update['audit_date'] = time();
  44. $update['where_id'] = $info['id'];
  45. Dever::db('option/account')->update($update);
  46. }
  47. if ($send_email == 2 && $email && $email != $info['email']) {
  48. $update = array();
  49. $update['is_email'] = 2;
  50. $update['where_id'] = $info['id'];
  51. Dever::db('option/account')->update($update);
  52. if ($send_email == 2) {
  53. $member = Dever::db('option/account')->one($info['mid']);
  54. if ($member) {
  55. $code = Dever::load('passport/reg')->code(false, false);
  56. $email = base64_encode($email);
  57. Dever::daemon('lib/email.renzheng?aid='.$this->uid.'&email=' . $email . '&code=' . $code . '&username=' . $member['name'], 'option');
  58. }
  59. }
  60. }
  61. }
  62. }
  63. # 协议审核
  64. public function setAgreement($id, $name, $data)
  65. {
  66. Dever::config('base')->hook = true;
  67. $update = array();
  68. $audit = Dever::param('audit', $data);
  69. $info = Dever::db('option/agreement')->one($id);
  70. if ($audit > 1 && $info) {
  71. $admin = Dever::load('manage/auth.info');
  72. $update['audit_date'] = time();
  73. $update['audit_admin'] = $admin['id'];
  74. if ($audit == 3) {
  75. $update['status'] = 2;
  76. }
  77. $update['where_id'] = $info['id'];
  78. $state = Dever::db('option/agreement')->update($update);
  79. if ($state && $audit == 3) {
  80. Dever::load('option/lib/cash.setValue_commit', $info);
  81. }
  82. }
  83. }
  84. # 交付审核 已废弃
  85. public function setJiaofu($id, $name, $data)
  86. {
  87. Dever::config('base')->hook = true;
  88. $update = array();
  89. $audit = Dever::param('audit', $data);
  90. $info = Dever::db('option/bill_jiaofu')->one($id);
  91. if ($audit > 1 && $info) {
  92. $admin = Dever::load('manage/auth.info');
  93. $update['audit_date'] = time();
  94. $update['audit_admin'] = $admin['id'];
  95. $update['where_id'] = $info['id'];
  96. $state = Dever::db('option/bill_jiaofu')->update($update);
  97. if ($state && $audit == 3) {
  98. Dever::load('option/lib/cash.setValue_commit', $info);
  99. }
  100. }
  101. }
  102. public function setFafang($id, $name, $data)
  103. {
  104. Dever::config('base')->hook = true;
  105. $update = array();
  106. $audit = Dever::param('audit', $data);
  107. $info = Dever::db('option/bill_fafang')->one($id);
  108. if ($audit > 1 && $info) {
  109. $admin = Dever::load('manage/auth.info');
  110. $update['audit_date'] = time();
  111. $update['audit_admin'] = $admin['id'];
  112. $update['where_id'] = $info['id'];
  113. $state = Dever::db('option/bill_fafang')->update($update);
  114. if ($state && $audit == 2) {
  115. # 已作废,减掉这个数据
  116. $account_cash = Dever::db('option/cash')->find(array('type' => $info['type'], 'aid' => $info['aid']));
  117. if ($account_cash) {
  118. $update['where_id'] = $account_cash['id'];
  119. $update['fafang'] = $account_cash['fafang'] - $info['cash'];
  120. $update['jiaofu'] = $account_cash['jiaofu'] + $info['cash'];
  121. if ($update['fafang'] < 0) {
  122. $update['fafang'] = 0;
  123. }
  124. $update['clear'] = true;
  125. Dever::db('option/cash')->update($update);
  126. }
  127. }
  128. }
  129. }
  130. public function setDuifu($id, $name, $data)
  131. {
  132. Dever::config('base')->hook = true;
  133. $update = array();
  134. $audit = Dever::param('audit', $data);
  135. $info = Dever::db('option/bill_duifu')->one($id);
  136. if ($audit && $audit > 1 && $info) {
  137. $admin = Dever::load('manage/auth.info');
  138. $update['audit_date'] = time();
  139. $update['audit_admin'] = $admin['id'];
  140. $update['where_id'] = $info['id'];
  141. $state = Dever::db('option/bill_duifu')->update($update);
  142. if ($state && $audit == 2) {
  143. # 已作废,恢复这个数据
  144. $account_cash = Dever::db('option/cash')->find(array('type' => $info['type'], 'aid' => $info['aid']));
  145. if ($account_cash) {
  146. $update['where_id'] = $account_cash['id'];
  147. $update['duifu'] = $account_cash['duifu'] - $info['cash'];
  148. $update['fafang'] = $account_cash['fafang'] + $info['cash'];
  149. if ($update['duifu'] < 0) {
  150. $update['duifu'] = 0;
  151. }
  152. $update['clear'] = true;
  153. Dever::db('option/cash')->update($update);
  154. }
  155. }
  156. }
  157. }
  158. public function cashUpdate($id, $name, $data)
  159. {
  160. Dever::config('base')->hook = true;
  161. $aid = Dever::param('aid', $data);
  162. $mid = Dever::param('mid', $data);
  163. $type = Dever::param('type', $data);
  164. $cash = Dever::param('cash', $data);
  165. $desc = Dever::param('desc', $data);
  166. if ($aid && $type && $cash && $desc) {
  167. $account = Dever::db('option/account')->find($aid);
  168. if ($account && $account['status'] <= 2) {
  169. Dever::load('option/lib/cash')->up($aid, $mid, $type, $cash, $desc);
  170. } else {
  171. Dever::db('option/push_cash')->update(array('where_id' => $id, 'status' => 2));
  172. Dever::alert('期权账户已停用或者未审核,操作失败');
  173. }
  174. }
  175. }
  176. public function getDate($id)
  177. {
  178. $info = Dever::db('option/agreement')->find($id);
  179. if ($info) {
  180. $html = '';
  181. $html .= '处理时间:' . date('Y-m-d H:i', $info['cdate']);
  182. if ($info['qdate']) {
  183. $html .= '<br />确认时间:' . date('Y-m-d H:i', $info['qdate']);
  184. }
  185. if ($info['audit_date']) {
  186. $html .= '<br />审核时间:' . date('Y-m-d H:i', $info['audit_date']);
  187. }
  188. return $html;
  189. }
  190. return '';
  191. }
  192. public function upAgreement_api()
  193. {
  194. $id = Dever::input('id');
  195. if ($id) {
  196. Dever::load('option/lib/agreement')->upContent($id);
  197. }
  198. return 'reload';
  199. }
  200. public function dropAgreement_api()
  201. {
  202. $id = Dever::input('id');
  203. if ($id) {
  204. Dever::load('option/lib/agreement')->drop($id);
  205. }
  206. return 'reload';
  207. }
  208. public function checkMember($id, $name, $data)
  209. {
  210. $main = Dever::param('main', $data);
  211. $key = Dever::param('key', $data);
  212. if (!$key) {
  213. Dever::alert('请传入账户索引');
  214. }
  215. if ($main == 2) {
  216. $main = Dever::db('option/member')->getMain(array('key' => $key));
  217. if (!$main) {
  218. Dever::alert('请先创建主账号');
  219. }
  220. } elseif ($main == 1) {
  221. $main = Dever::db('option/member')->getMain(array('key' => $key));
  222. if ($main) {
  223. Dever::alert('已存在主账号');
  224. }
  225. }
  226. }
  227. }