Manage.php 13 KB

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