Cash.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php
  2. namespace Option\Lib;
  3. use Dever;
  4. class Cash
  5. {
  6. private function getInfo($type, $cash)
  7. {
  8. if ($type > 3) {
  9. $cash_type = 2;
  10. } else {
  11. $cash_type = 1;
  12. }
  13. if ($type == 1 || $type == 4) {
  14. $table = 'jiaofu';
  15. $prefix = 'J';
  16. } elseif ($type == 2 || $type == 5) {
  17. $table = 'fafang';
  18. $prefix = 'F';
  19. } elseif ($type == 3 || $type == 6) {
  20. $table = 'duifu';
  21. $prefix = 'D';
  22. $cash = -1*$cash;
  23. }
  24. return array($table, $cash, $cash_type, $prefix);
  25. }
  26. public function resetParent($uid, $parent)
  27. {
  28. # 获取所有下级
  29. $child = $this->getChild($uid, false);
  30. if ($child) {
  31. foreach ($child as $k => $v) {
  32. if ($v['level'] > 1) {
  33. $this->update(array('id' => $v['id']), array('uid' => $parent));
  34. }
  35. }
  36. }
  37. return $this->delete(array('to_uid' => $uid, 'level' => 1), array('uid' => $parent));
  38. }
  39. public function up($aid, $type, $cash, $desc, $alert = true)
  40. {
  41. if ($cash == 0) {
  42. return;
  43. }
  44. $account = Dever::db('option/account')->find(array('id' => $aid, 'clear' => true));
  45. if ($account['status'] <= 2) {
  46. list($table, $cash, $cash_type, $prefix) = $this->getInfo($type, $cash);
  47. $where = array();
  48. $where['clear'] = true;
  49. $where['aid'] = $aid;
  50. $where['type'] = $cash_type;
  51. $info = false;
  52. if (!$info) {
  53. $data = $where;
  54. $data['order_num'] = $this->getOrderId($table, $prefix);
  55. $col = $table;
  56. $cash_info = Dever::db('option/cash')->find($where);
  57. if (!$cash_info) {
  58. Dever::db('option/cash')->insert($where);
  59. $cash_info = Dever::db('option/cash')->find($where);
  60. }
  61. if ($table == 'fafang') {
  62. $data['yue'] = $cash_info[$col] + $cash;
  63. $data['status'] = 1;
  64. if ($cash_info['jiaofu'] < $cash) {
  65. if ($alert) {
  66. Dever::alert('交付期权价值不足发放');
  67. } else {
  68. $data['status'] = 2;
  69. }
  70. }
  71. } elseif ($table == 'duifu') {
  72. $data['yue'] = $cash_info[$col] + $cash;
  73. $data['status'] = 1;
  74. if ($cash_info['fafang'] < $cash) {
  75. if ($alert) {
  76. Dever::alert('发放期权价值不足兑付');
  77. } else {
  78. $data['status'] = 2;
  79. }
  80. }
  81. } else {
  82. $col = 'dai' . $table;
  83. $data['status'] = 2;
  84. }
  85. $data['cash'] = $cash;
  86. $data['desc'] = $desc;
  87. $data['clear'] = true;
  88. $state = Dever::db('option/bill_' . $table)->insert($data);
  89. if ($state && $cash_info) {
  90. # 更新余额
  91. $update = array();
  92. $update['where_id'] = $cash_info['id'];
  93. $update['set_cash'] = $cash;
  94. $update['clear'] = true;
  95. $method = 'upCash_' . $col;
  96. if ($table == 'fafang') {
  97. $update['jiaofu'] = $cash;
  98. if ($data['status'] == 2) {
  99. $update['jiaofu'] = 0;
  100. }
  101. } elseif ($table == 'duifu') {
  102. $update['fafang'] = $cash;
  103. if ($data['status'] == 2) {
  104. $update['fafang'] = 0;
  105. }
  106. }
  107. Dever::db('option/cash')->$method($update);
  108. }
  109. }
  110. return $state;
  111. }
  112. return false;
  113. }
  114. /**
  115. * 生成订单号
  116. *
  117. * @return mixed
  118. */
  119. public function getOrderId($table, $prefix)
  120. {
  121. $where['order_num'] = Dever::order($prefix);
  122. $state = Dever::db('option/bill_' . $table)->one($where);
  123. if (!$state) {
  124. return $where['order_num'];
  125. } else {
  126. return $this->getOrderId($table, $prefix);
  127. }
  128. }
  129. # 获取日志列表
  130. public function getList($aid, $table, $status, $name, $audit = false)
  131. {
  132. $where = array();
  133. $where['aid'] = $aid;
  134. if ($status > 0) {
  135. $where['status'] = $status;
  136. }
  137. if ($audit) {
  138. $where['audit'] = $audit;
  139. }
  140. $table = 'option/bill_' . $table;
  141. if ($status == 2) {
  142. $data = Dever::db($table)->select($where);
  143. } else {
  144. $data = Dever::db($table)->getData($where);
  145. }
  146. if ($data) {
  147. $audit = Dever::db($table)->config['config_audit'];
  148. foreach ($data as $k => $v) {
  149. $data[$k] = $this->getOne($v, $name, $audit);
  150. }
  151. }
  152. return $data;
  153. }
  154. # 获取日志详情
  155. public function getView($id, $aid, $table, $name)
  156. {
  157. if (!$id) {
  158. Dever::alert('参数错误');
  159. }
  160. $where = array();
  161. $where['id'] = $id;
  162. $where['aid'] = $aid;
  163. $table = 'option/bill_' . $table;
  164. $data = Dever::db($table)->find($where);
  165. if ($data) {
  166. $audit = Dever::db($table)->config['config_audit'];
  167. $data = $this->getOne($data, $name, $audit);
  168. }
  169. return $data;
  170. }
  171. # 获取详情
  172. private function getOne($data, $name, $audit)
  173. {
  174. if ($data['type'] == 1) {
  175. $data['type_name'] = $name . '期权';
  176. } else {
  177. $data['type_name'] = $name . '原始期权';
  178. }
  179. $data['audit_name'] = $audit[$data['audit']];
  180. $data['cdate_string'] = date('Y-m-d H:i', $data['cdate']);
  181. return $data;
  182. }
  183. # 确认期权价值
  184. public function setValue_commit($info)
  185. {
  186. $cash = array();
  187. $state = Dever::db('option/bill_jiaofu')->update(array('status' => 1, 'where_id' => $info['id']));
  188. if ($state) {
  189. $account_cash = Dever::db('option/cash')->find(array('type' => $info['type'], 'aid' => $info['aid']));
  190. if ($account_cash) {
  191. $update['where_id'] = $account_cash['id'];
  192. $update['daijiaofu'] = $account_cash['daijiaofu'] - $info['cash'];
  193. $update['jiaofu'] = $account_cash['jiaofu'] + $info['cash'];
  194. if ($update['daijiaofu'] < 0) {
  195. $update['daijiaofu'] = 0;
  196. }
  197. $update['clear'] = true;
  198. Dever::db('option/cash')->update($update);
  199. # 获取待发放数据 对之前发放的数据进行发放
  200. $fafang = Dever::db('option/bill_fafang')->find(array('status' => 2, 'type' => $info['type'], 'aid' => $info['aid']));
  201. if ($fafang) {
  202. foreach ($fafang as $v) {
  203. if ($info['cash'] >= $v['cash']) {
  204. Dever::db('option/bill_fafang')->update(array('where_id' => $v['id'], 'status' => 1));
  205. $info['cash'] -= $v['cash'];
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. # 展示详情
  213. public function show()
  214. {
  215. $id = Dever::input('id');
  216. $config = Dever::db('bill/cash')->config['set'];
  217. $info = Dever::db('bill/cash')->one($id);
  218. $status = $config['status'][$info['status']];
  219. $type = $config['type'][$info['type']];
  220. $member = Dever::db('agent/member')->find($info['mid']);
  221. $role = Dever::db('setting/role')->one($member['role']);
  222. $level = Dever::db('setting/level')->one($member['level_id']);
  223. if ($member['shop_id']) {
  224. $shop = Dever::db('shop/info')->one($member['shop_id']);
  225. } else {
  226. $shop['id'] = -1;
  227. $shop['name'] = '无';
  228. }
  229. $cdate = date('Y-m-d H:i', $info['cdate']);
  230. if ($info['operdate']) {
  231. $opertime = date('Y-m-d H:i', $info['operdate']);
  232. } else {
  233. $opertime = '';
  234. }
  235. $result = array();
  236. $result['代理商信息'] = array
  237. (
  238. 'type' => 'info',
  239. 'content' => array
  240. (
  241. array
  242. (
  243. array('代理商', $member['name'] . ' ' . $member['mobile']),
  244. array('代理角色', $role['name'] . ($level ? '('.$level['name'].')' : '')),
  245. array('所属店铺', $shop['name']),
  246. ),
  247. array
  248. (
  249. array('资金余额', '¥' . $member['cash'] . '元'),
  250. //array('直推业绩', '¥' . $member['sell'] . '元'),
  251. array('团队业绩', '¥' . $member['group_sell'] . '元'),
  252. ),
  253. ),
  254. );
  255. $result['交易信息'] = array
  256. (
  257. 'type' => 'info',
  258. 'content' => array
  259. (
  260. array
  261. (
  262. array('流水号', $info['order_num']),
  263. array('交易时间', $cdate),
  264. array('交易类型', $type),
  265. ),
  266. array
  267. (
  268. array('交易金额', '¥' . $info['cash'] . '元'),
  269. array('交易后账户余额', '¥' . $info['yue'] . '元'),
  270. array('交易说明', $info['desc']),
  271. ),
  272. )
  273. );
  274. $result['审核信息'] = array
  275. (
  276. 'type' => 'info',
  277. 'content' => array
  278. (
  279. array
  280. (
  281. array('审核时间', $opertime),
  282. array('审核状态', $status),
  283. array('备注', $info['audit_desc']),
  284. ),
  285. )
  286. );
  287. # 提现信息
  288. $button = array();
  289. if ($info['status'] == 1) {
  290. $button[] = array
  291. (
  292. 'type' => 'edit',
  293. 'link' => Dever::url('project/database/update?project=bill&table=cash&where_id='.$info['id'].'&col=audit,audit_desc&oper_save_jump=cash&oper_table=cash&oper_parent=cash', 'manage'),
  294. 'name' => '审核',
  295. );
  296. }
  297. if ($info['type'] == 11) {
  298. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  299. if ($tixian) {
  300. if ($info['status'] == 2 && $tixian['status'] == 1) {
  301. $button[] = array
  302. (
  303. 'type' => 'edit',
  304. 'link' => Dever::url('project/database/update?project=bill&table=tixian&where_id='.$tixian['id'].'&col=audit,audit_desc,pic&oper_save_jump=tixian&oper_table=tixian&oper_parent=tixian', 'manage'),
  305. 'name' => '发放',
  306. );
  307. }
  308. $bank = Dever::db('setting/bank')->find($tixian['bank']);
  309. $result['提现信息'] = array
  310. (
  311. 'type' => 'info',
  312. 'content' => array
  313. (
  314. array
  315. (
  316. array('银行名称', $bank['name']),
  317. array('开户行', $tixian['bankname']),
  318. ),
  319. array
  320. (
  321. array('姓名', $tixian['name']),
  322. array('卡号', $tixian['card']),
  323. ),
  324. )
  325. );
  326. if ($tixian['status'] == 2) {
  327. if ($tixian['operdate']) {
  328. $opertime = date('Y-m-d H:i', $tixian['operdate']);
  329. } else {
  330. $opertime = '';
  331. }
  332. $pic = '';
  333. if ($tixian['pic']) {
  334. $temp = explode(',', $tixian['pic']);
  335. foreach ($temp as $k => $v) {
  336. $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
  337. }
  338. }
  339. $result['发放信息'] = array
  340. (
  341. 'type' => 'info',
  342. 'content' => array
  343. (
  344. array
  345. (
  346. array('发放时间', $opertime),
  347. array('备注', $tixian['audit_desc']),
  348. ),
  349. array
  350. (
  351. array('凭证', $pic),
  352. ),
  353. )
  354. );
  355. }
  356. }
  357. }
  358. $head = array
  359. (
  360. 'name' => '基本信息',
  361. 'btn' => $button,
  362. );
  363. $html = Dever::show($head, $result);
  364. return $html;
  365. }
  366. }