Cash.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. namespace Bill\Lib;
  3. use Dever;
  4. class Cash
  5. {
  6. public function up($mid, $type, $cash, $role, $type_id, $desc, $status, $insert = false)
  7. {
  8. if ($cash == 0) {
  9. return false;
  10. }
  11. $member = Dever::db('agent/member')->find(array('id' => $mid, 'clear' => true));
  12. if ($member && $member['status'] <= 2) {
  13. $where['mid'] = $mid;
  14. if ($type == 11) {
  15. $cash = -1*$cash;
  16. }
  17. $where['type'] = $type;
  18. $where['type_id'] = $type_id;
  19. $where['clear'] = true;
  20. $info = Dever::db('bill/cash')->find($where);
  21. if (!$info) {
  22. $data = $where;
  23. $data['order_num'] = $this->getOrderId();
  24. $data['yue'] = $member['cash'] + $cash;
  25. $data['cash'] = $cash;
  26. $data['role'] = $role;
  27. $data['desc'] = $desc;
  28. $data['status'] = $status;
  29. if ($status == 2) {
  30. $data['operdate'] = time();
  31. }
  32. return Dever::db('bill/cash')->insert($data);
  33. }
  34. return !$insert ? $info['id'] : false;
  35. }
  36. return false;
  37. }
  38. /**
  39. * 生成订单号
  40. *
  41. * @return mixed
  42. */
  43. public function getOrderId()
  44. {
  45. $where['order_num'] = Dever::order('C');
  46. $where['clear'] = true;
  47. $state = Dever::db('bill/cash')->one($where);
  48. if (!$state) {
  49. return $where['order_num'];
  50. } else {
  51. return $this->getOrderId();
  52. }
  53. }
  54. # 展示详情
  55. public function show()
  56. {
  57. $id = Dever::input('id');
  58. $config = Dever::db('bill/cash')->config['set'];
  59. $info = Dever::db('bill/cash')->one($id);
  60. $status = $config['status'][$info['status']];
  61. $type = $config['type'][$info['type']];
  62. $member = Dever::db('agent/member')->find($info['mid']);
  63. $role = Dever::db('setting/role')->one($member['role']);
  64. $level = Dever::db('setting/level')->one($member['level_id']);
  65. if ($member['shop_id']) {
  66. $shop = Dever::db('shop/info')->one($member['shop_id']);
  67. } else {
  68. $shop['id'] = -1;
  69. $shop['name'] = '无';
  70. }
  71. $cdate = date('Y-m-d H:i', $info['cdate']);
  72. if ($info['operdate']) {
  73. $opertime = date('Y-m-d H:i', $info['operdate']);
  74. } else {
  75. $opertime = '';
  76. }
  77. $result = array();
  78. $result['代理商信息'] = array
  79. (
  80. 'type' => 'info',
  81. 'content' => array
  82. (
  83. array
  84. (
  85. array('代理商', $member['name'] . ' ' . $member['mobile']),
  86. array('代理角色', $role['name'] . ($level ? '('.$level['name'].')' : '')),
  87. array('所属店铺', $shop['name']),
  88. ),
  89. array
  90. (
  91. array('资金余额', '¥' . $member['cash'] . '元'),
  92. //array('直推业绩', '¥' . $member['sell'] . '元'),
  93. array('团队业绩', '¥' . $member['group_sell'] . '元'),
  94. ),
  95. ),
  96. );
  97. $result['交易信息'] = array
  98. (
  99. 'type' => 'info',
  100. 'content' => array
  101. (
  102. array
  103. (
  104. array('流水号', $info['order_num']),
  105. array('交易时间', $cdate),
  106. array('交易类型', $type),
  107. ),
  108. array
  109. (
  110. array('交易金额', '¥' . $info['cash'] . '元'),
  111. array('交易后账户余额', '¥' . $info['yue'] . '元'),
  112. array('交易说明', $info['desc']),
  113. ),
  114. )
  115. );
  116. $result['审核信息'] = array
  117. (
  118. 'type' => 'info',
  119. 'content' => array
  120. (
  121. array
  122. (
  123. array('审核时间', $opertime),
  124. array('审核状态', $status),
  125. array('备注', $info['audit_desc']),
  126. ),
  127. )
  128. );
  129. # 提现信息
  130. $button = array();
  131. if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit', '审核')) {
  132. if ($info['status'] == 1) {
  133. $button[] = array
  134. (
  135. 'type' => 'edit',
  136. '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'),
  137. 'name' => '审核',
  138. );
  139. }
  140. }
  141. if ($info['type'] == 11) {
  142. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  143. if ($tixian) {
  144. $config = Dever::db('bill/tixian')->config['set'];
  145. $status = $config['status'][$tixian['status']];
  146. if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit1', '发放')) {
  147. if ($info['status'] == 2 && $tixian['status'] == 1) {
  148. $button[] = array
  149. (
  150. 'type' => 'edit',
  151. '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'),
  152. 'name' => '发放',
  153. );
  154. }
  155. }
  156. /*
  157. $bank = Dever::db('setting/bank')->find($tixian['bank']);
  158. $result['提现信息'] = array
  159. (
  160. 'type' => 'info',
  161. 'content' => array
  162. (
  163. array
  164. (
  165. array('银行名称', $bank['name']),
  166. array('开户行', $tixian['bankname']),
  167. ),
  168. array
  169. (
  170. array('姓名', $tixian['name']),
  171. array('卡号', $tixian['card']),
  172. ),
  173. )
  174. );
  175. */
  176. if ($tixian['status']) {
  177. if ($tixian['operdate']) {
  178. $opertime = date('Y-m-d H:i', $tixian['operdate']);
  179. } else {
  180. $opertime = '';
  181. }
  182. $pic = '';
  183. if ($tixian['pic']) {
  184. $temp = explode(',', $tixian['pic']);
  185. foreach ($temp as $k => $v) {
  186. $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
  187. }
  188. }
  189. $result['发放信息'] = array
  190. (
  191. 'type' => 'info',
  192. 'content' => array
  193. (
  194. array
  195. (
  196. array('发放时间', $opertime),
  197. array('发放状态', $status),
  198. array('备注', $tixian['audit_desc']),
  199. ),
  200. array
  201. (
  202. array('凭证', $pic),
  203. ),
  204. )
  205. );
  206. }
  207. }
  208. }
  209. $button[] = array
  210. (
  211. 'type' => 'link',
  212. 'link' => 'refer',
  213. 'name' => '返回上一页',
  214. );
  215. $head = array
  216. (
  217. 'name' => '基本信息',
  218. 'btn' => $button,
  219. );
  220. $html = Dever::show($head, $result);
  221. return $html;
  222. }
  223. public function order_num($id){
  224. $info = Dever::db('bill/cash')->find($id);
  225. $cdate = date('Y-m-d H:i',$info['cdate']);
  226. $odate = '';
  227. if ($info['operdate']) {
  228. $odate = date('Y-m-d H:i',$info['operdate']);
  229. }
  230. $html['num'] = $cdate . '<br/>'.$odate;
  231. $html['cash'] = $info['cash'] . '<br />' . $info['yue'];
  232. return $html;
  233. }
  234. #钱包管理数据导出
  235. public function out_cash_api($data){
  236. $header = array('邀请码', '姓名', '手机号', '身份证号', '代理角色', '代理商区域', '代理费', '审核时间', '直推收入', '团队收入', '管理员备注');
  237. $body = array();
  238. foreach($data as $k =>$v){
  239. $arr[] = Dever::db('agent/member')->find(array('id'=>$v['mid']));
  240. foreach($arr as $k1=>$v1){
  241. if($v['mid'] == $v1['id']){
  242. $arr[$k1]['operdate'] = $v['operdate'];
  243. $arr[$k1]['audit_desc'] = $v['audit_desc'];
  244. }
  245. }
  246. }
  247. $member = array();
  248. $arr=array_unique($arr, SORT_REGULAR);
  249. $rest=array();
  250. foreach($arr as $k=>$v){
  251. $rest[$v['id']]=$v;
  252. }
  253. $member=array_values($rest);
  254. foreach($member as $k => $v){
  255. $code = Dever::load("invite/api.code", $v['id']);
  256. $role = Dever::db('setting/role')->find(array('id'=>$v['role']));
  257. $area = Dever::load("area/api.string", $v['area']);
  258. $order = Dever::db('agent/order')->state(array('mid'=>$v['id']));
  259. $zhitui = Dever::db('bill/cash')->state(array('mid'=>$v['id'],'type'=>1));
  260. $total = 0;
  261. foreach($zhitui as $key => $val){
  262. $total += $val['cash'];
  263. }
  264. $tuandui = Dever::db('bill/cash')->state(array('mid'=>$v['id'],'type'=>2));
  265. $tuan = 0;
  266. foreach($tuandui as $t){
  267. $tuan += $t['cash'];
  268. }
  269. $sum = 0;
  270. foreach($order as $k1 => $v1){
  271. $sum += $v1['agent_cash'];
  272. }
  273. $operdate = '';
  274. if($v['operdate']){
  275. $operdate = date('Y-m-d',$v['operdate']);
  276. }
  277. $d = array
  278. (
  279. $code,
  280. $v['name'],
  281. $v['mobile'],
  282. $v['idcard'],
  283. $role['name'],
  284. $area,
  285. $sum,
  286. $operdate,
  287. $total,
  288. $tuan,
  289. $v['audit_desc'],
  290. );
  291. $body[] = $d;
  292. }
  293. $file = Dever::input('excel_name');
  294. return Dever::excelExport($body, $header, $file);
  295. }
  296. }