Manage.php 9.8 KB

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