Cash.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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)
  131. {
  132. $where = array();
  133. $where['aid'] = $aid;
  134. if ($status > 0) {
  135. $where['status'] = $status;
  136. }
  137. $table = 'option/bill_' . $table;
  138. $data = Dever::db($table)->getData($where);
  139. if ($data) {
  140. $audit = Dever::db($table)->config['config_audit'];
  141. foreach ($data as $k => $v) {
  142. $data[$k] = $this->getOne($v, $name, $audit);
  143. }
  144. }
  145. return $data;
  146. }
  147. # 获取日志详情
  148. public function getView($id, $aid, $table, $name)
  149. {
  150. if (!$id) {
  151. Dever::alert('参数错误');
  152. }
  153. $where = array();
  154. $where['id'] = $id;
  155. $where['aid'] = $aid;
  156. $table = 'option/bill_' . $table;
  157. $data = Dever::db($table)->find($where);
  158. if ($data) {
  159. $audit = Dever::db($table)->config['config_audit'];
  160. $data = $this->getOne($data, $name, $audit);
  161. }
  162. return $data;
  163. }
  164. # 获取详情
  165. private function getOne($data, $name, $audit)
  166. {
  167. if ($data['type'] == 1) {
  168. $data['type_name'] = $name . '期权';
  169. } else {
  170. $data['type_name'] = $name . '原始期权';
  171. }
  172. $data['audit_name'] = $audit[$data['audit']];
  173. $data['cdate_string'] = date('Y-m-d H:i', $data['cdate']);
  174. return $data;
  175. }
  176. # 展示详情
  177. public function show()
  178. {
  179. $id = Dever::input('id');
  180. $config = Dever::db('bill/cash')->config['set'];
  181. $info = Dever::db('bill/cash')->one($id);
  182. $status = $config['status'][$info['status']];
  183. $type = $config['type'][$info['type']];
  184. $member = Dever::db('agent/member')->find($info['mid']);
  185. $role = Dever::db('setting/role')->one($member['role']);
  186. $level = Dever::db('setting/level')->one($member['level_id']);
  187. if ($member['shop_id']) {
  188. $shop = Dever::db('shop/info')->one($member['shop_id']);
  189. } else {
  190. $shop['id'] = -1;
  191. $shop['name'] = '无';
  192. }
  193. $cdate = date('Y-m-d H:i', $info['cdate']);
  194. if ($info['operdate']) {
  195. $opertime = date('Y-m-d H:i', $info['operdate']);
  196. } else {
  197. $opertime = '';
  198. }
  199. $result = array();
  200. $result['代理商信息'] = array
  201. (
  202. 'type' => 'info',
  203. 'content' => array
  204. (
  205. array
  206. (
  207. array('代理商', $member['name'] . ' ' . $member['mobile']),
  208. array('代理角色', $role['name'] . ($level ? '('.$level['name'].')' : '')),
  209. array('所属店铺', $shop['name']),
  210. ),
  211. array
  212. (
  213. array('资金余额', '¥' . $member['cash'] . '元'),
  214. //array('直推业绩', '¥' . $member['sell'] . '元'),
  215. array('团队业绩', '¥' . $member['group_sell'] . '元'),
  216. ),
  217. ),
  218. );
  219. $result['交易信息'] = array
  220. (
  221. 'type' => 'info',
  222. 'content' => array
  223. (
  224. array
  225. (
  226. array('流水号', $info['order_num']),
  227. array('交易时间', $cdate),
  228. array('交易类型', $type),
  229. ),
  230. array
  231. (
  232. array('交易金额', '¥' . $info['cash'] . '元'),
  233. array('交易后账户余额', '¥' . $info['yue'] . '元'),
  234. array('交易说明', $info['desc']),
  235. ),
  236. )
  237. );
  238. $result['审核信息'] = array
  239. (
  240. 'type' => 'info',
  241. 'content' => array
  242. (
  243. array
  244. (
  245. array('审核时间', $opertime),
  246. array('审核状态', $status),
  247. array('备注', $info['audit_desc']),
  248. ),
  249. )
  250. );
  251. # 提现信息
  252. $button = array();
  253. if ($info['status'] == 1) {
  254. $button[] = array
  255. (
  256. 'type' => 'edit',
  257. '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'),
  258. 'name' => '审核',
  259. );
  260. }
  261. if ($info['type'] == 11) {
  262. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  263. if ($tixian) {
  264. if ($info['status'] == 2 && $tixian['status'] == 1) {
  265. $button[] = array
  266. (
  267. 'type' => 'edit',
  268. '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'),
  269. 'name' => '发放',
  270. );
  271. }
  272. $bank = Dever::db('setting/bank')->find($tixian['bank']);
  273. $result['提现信息'] = array
  274. (
  275. 'type' => 'info',
  276. 'content' => array
  277. (
  278. array
  279. (
  280. array('银行名称', $bank['name']),
  281. array('开户行', $tixian['bankname']),
  282. ),
  283. array
  284. (
  285. array('姓名', $tixian['name']),
  286. array('卡号', $tixian['card']),
  287. ),
  288. )
  289. );
  290. if ($tixian['status'] == 2) {
  291. if ($tixian['operdate']) {
  292. $opertime = date('Y-m-d H:i', $tixian['operdate']);
  293. } else {
  294. $opertime = '';
  295. }
  296. $pic = '';
  297. if ($tixian['pic']) {
  298. $temp = explode(',', $tixian['pic']);
  299. foreach ($temp as $k => $v) {
  300. $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
  301. }
  302. }
  303. $result['发放信息'] = array
  304. (
  305. 'type' => 'info',
  306. 'content' => array
  307. (
  308. array
  309. (
  310. array('发放时间', $opertime),
  311. array('备注', $tixian['audit_desc']),
  312. ),
  313. array
  314. (
  315. array('凭证', $pic),
  316. ),
  317. )
  318. );
  319. }
  320. }
  321. }
  322. $head = array
  323. (
  324. 'name' => '基本信息',
  325. 'btn' => $button,
  326. );
  327. $html = Dever::show($head, $result);
  328. return $html;
  329. }
  330. }