Manage.php 13 KB

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