Money.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Money
  5. {
  6. # 查看用户信息
  7. public function showUser($uid)
  8. {
  9. $user = Dever::db('passport/user')->one($uid);
  10. return $user['username'] . '<br />' . $user['mobile'];
  11. }
  12. public function getCash($id)
  13. {
  14. $info = Dever::db('shop/user_money')->find($id);
  15. $cdate = date('Y-m-d H:i',$info['cdate']);
  16. $odate = '';
  17. if ($info['operdate']) {
  18. $odate = date('Y-m-d H:i',$info['operdate']);
  19. }
  20. return $info['cash'] . '<br />' . $info['yue'];
  21. }
  22. # 发起支付
  23. public function pay($uid, $cash)
  24. {
  25. $openid = false;
  26. if ($uid > 0) {
  27. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 1));
  28. if (!$wechat) {
  29. Dever::alert('错误的用户信息');
  30. }
  31. $openid = $wechat['openid'];
  32. }
  33. $param = array
  34. (
  35. 'project_id' => 5,
  36. 'channel_id' => 1,
  37. 'system_source' => 5,
  38. 'account_id' => 5,
  39. 'uid' => $uid,
  40. 'name' => '用户充值',
  41. 'openid' => $openid,
  42. 'cash' => $cash,
  43. 'product_id' => $uid,
  44. 'refer' => '',
  45. );
  46. $result = Dever::load('pay/api.pay', $param);
  47. return $result;
  48. }
  49. # 支付成功回调 安全加密 设置token
  50. public function success_secure_api_token()
  51. {
  52. $project_id = Dever::input('pay_project_id');
  53. $info = Dever::db('pay/project')->one($project_id);
  54. if ($info) {
  55. return $info['key'];
  56. }
  57. return 'cash_buy_dever_2020';
  58. }
  59. # 支付成功回调 安全加密
  60. public function success_secure_api($param = array())
  61. {
  62. $this->success($param);
  63. }
  64. # 支付成功回调
  65. public function success($param = array())
  66. {
  67. $send = $param ? $param : Dever::preInput('pay_');
  68. $product_id = $send['pay_product_id'];
  69. $order_id = $send['pay_order_id'];
  70. $status = $send['pay_status'];
  71. $cash = $send['pay_cash'];
  72. $msg = $send['pay_msg'];
  73. if ($status == 2) {
  74. $this->up($product_id, 1, $cash, $send['pay_id'], '充值', 2);
  75. }
  76. return 'ok';
  77. }
  78. public function up($uid, $type, $cash, $type_id, $desc, $status)
  79. {
  80. if ($cash == 0) {
  81. return false;
  82. }
  83. $user = Dever::db('passport/user')->find(array('id' => $uid, 'clear' => true));
  84. if ($user) {
  85. $where['uid'] = $uid;
  86. if ($type > 10) {
  87. $cash = -1*$cash;
  88. }
  89. $where['type'] = $type;
  90. $where['type_id'] = $type_id;
  91. $where['clear'] = true;
  92. $info = Dever::db('shop/user_money')->find($where);
  93. if (!$info) {
  94. $data = $where;
  95. $data['order_num'] = $this->getOrderId();
  96. $data['yue'] = $user['cash'] + $cash;
  97. $data['cash'] = $cash;
  98. $data['desc'] = $desc;
  99. $data['status'] = $status;
  100. if ($status == 2) {
  101. $data['operdate'] = time();
  102. }
  103. $update['where_id'] = $uid;
  104. $update['set_cash'] = $cash;
  105. //$update['clear'] = true;
  106. Dever::db('passport/user')->upCash($update);
  107. return Dever::db('shop/user_money')->insert($data);
  108. }
  109. return $info['id'];
  110. }
  111. return false;
  112. }
  113. /**
  114. * 生成订单号
  115. *
  116. * @return mixed
  117. */
  118. public function getOrderId()
  119. {
  120. $where['order_num'] = Dever::order('UM');
  121. $where['clear'] = true;
  122. $state = Dever::db('shop/user_money')->one($where);
  123. if (!$state) {
  124. return $where['order_num'];
  125. } else {
  126. return $this->getOrderId();
  127. }
  128. }
  129. # 展示详情
  130. public function show()
  131. {
  132. $id = Dever::input('id');
  133. $config = Dever::db('shop/user_money')->config['set'];
  134. $info = Dever::db('shop/user_money')->one($id);
  135. $status = $config['status'][$info['status']];
  136. $type = $config['type'][$info['type']];
  137. $user = Dever::db('passport/user')->find($info['uid']);
  138. $cdate = date('Y-m-d H:i', $info['cdate']);
  139. if ($info['operdate']) {
  140. $opertime = date('Y-m-d H:i', $info['operdate']);
  141. } else {
  142. $opertime = '';
  143. }
  144. $result = array();
  145. $result['用户信息'] = array
  146. (
  147. 'type' => 'info',
  148. 'content' => array
  149. (
  150. array
  151. (
  152. array('昵称', $user['username']),
  153. array('手机号', $user['mobile']),
  154. array('资金余额', '¥' . $user['cash'] . '元'),
  155. ),
  156. ),
  157. );
  158. $result['交易信息'] = array
  159. (
  160. 'type' => 'info',
  161. 'content' => array
  162. (
  163. array
  164. (
  165. array('流水号', $info['order_num']),
  166. array('交易时间', $cdate),
  167. array('交易类型', $type),
  168. ),
  169. array
  170. (
  171. array('交易金额', '¥' . $info['cash'] . '元'),
  172. array('交易后账户余额', '¥' . $info['yue'] . '元'),
  173. array('交易说明', $info['desc']),
  174. ),
  175. )
  176. );
  177. $result['审核信息'] = array
  178. (
  179. 'type' => 'info',
  180. 'content' => array
  181. (
  182. array
  183. (
  184. array('审核时间', $opertime),
  185. array('审核状态', $status),
  186. array('备注', $info['audit_desc']),
  187. ),
  188. )
  189. );
  190. # 提现信息
  191. $button = array();
  192. if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit', '审核')) {
  193. if ($info['status'] == 1) {
  194. $button[] = array
  195. (
  196. 'type' => 'edit',
  197. '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'),
  198. 'name' => '审核',
  199. );
  200. }
  201. }
  202. if ($info['type'] == 11) {
  203. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  204. if ($tixian) {
  205. $config = Dever::db('bill/tixian')->config['set'];
  206. $status = $config['status'][$tixian['status']];
  207. if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit1', '发放')) {
  208. if ($info['status'] == 2 && $tixian['status'] == 1) {
  209. $button[] = array
  210. (
  211. 'type' => 'edit',
  212. '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'),
  213. 'name' => '发放',
  214. );
  215. }
  216. }
  217. /*
  218. $bank = Dever::db('setting/bank')->find($tixian['bank']);
  219. $result['提现信息'] = array
  220. (
  221. 'type' => 'info',
  222. 'content' => array
  223. (
  224. array
  225. (
  226. array('银行名称', $bank['name']),
  227. array('开户行', $tixian['bankname']),
  228. ),
  229. array
  230. (
  231. array('姓名', $tixian['name']),
  232. array('卡号', $tixian['card']),
  233. ),
  234. )
  235. );
  236. */
  237. if ($tixian['status']) {
  238. if ($tixian['operdate']) {
  239. $opertime = date('Y-m-d H:i', $tixian['operdate']);
  240. } else {
  241. $opertime = '';
  242. }
  243. $pic = '';
  244. if ($tixian['pic']) {
  245. $temp = explode(',', $tixian['pic']);
  246. foreach ($temp as $k => $v) {
  247. $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
  248. }
  249. }
  250. $result['发放信息'] = array
  251. (
  252. 'type' => 'info',
  253. 'content' => array
  254. (
  255. array
  256. (
  257. array('发放时间', $opertime),
  258. array('发放状态', $status),
  259. array('备注', $tixian['audit_desc']),
  260. ),
  261. array
  262. (
  263. array('凭证', $pic),
  264. ),
  265. )
  266. );
  267. }
  268. }
  269. }
  270. $button[] = array
  271. (
  272. 'type' => 'link',
  273. 'link' => 'refer',
  274. 'name' => '返回上一页',
  275. );
  276. $head = array
  277. (
  278. 'name' => '基本信息',
  279. 'btn' => $button,
  280. );
  281. $html = Dever::show($head, $result);
  282. return $html;
  283. }
  284. public function order_num($id){
  285. $info = Dever::db('shop/user_money')->find($id);
  286. $cdate = date('Y-m-d H:i',$info['cdate']);
  287. $odate = '';
  288. if ($info['operdate']) {
  289. $odate = date('Y-m-d H:i',$info['operdate']);
  290. }
  291. $html['num'] = $cdate . '<br/>'.$odate;
  292. $html['cash'] = $info['cash'] . '<br />' . $info['yue'];
  293. return $html;
  294. }
  295. #钱包管理数据导出
  296. public function out_cash_api($data){
  297. $header = array('邀请码', '姓名', '手机号', '身份证号', '代理角色', '代理商区域', '代理费', '审核时间', '直推收入', '团队收入', '管理员备注');
  298. $body = array();
  299. foreach($data as $k =>$v){
  300. $arr[] = Dever::db('agent/member')->find(array('id'=>$v['mid']));
  301. foreach($arr as $k1=>$v1){
  302. if($v['mid'] == $v1['id']){
  303. $arr[$k1]['operdate'] = $v['operdate'];
  304. $arr[$k1]['audit_desc'] = $v['audit_desc'];
  305. }
  306. }
  307. }
  308. $member = array();
  309. $arr=array_unique($arr, SORT_REGULAR);
  310. $rest=array();
  311. foreach($arr as $k=>$v){
  312. $rest[$v['id']]=$v;
  313. }
  314. $member=array_values($rest);
  315. foreach($member as $k => $v){
  316. $code = Dever::load("invite/api.code", $v['id']);
  317. $role = Dever::db('setting/role')->find(array('id'=>$v['role']));
  318. $area = Dever::load("area/api.string", $v['area']);
  319. $order = Dever::db('agent/order')->state(array('mid'=>$v['id']));
  320. $zhitui = Dever::db('shop/user_money')->state(array('mid'=>$v['id'],'type'=>1));
  321. $total = 0;
  322. foreach($zhitui as $key => $val){
  323. $total += $val['cash'];
  324. }
  325. $tuandui = Dever::db('shop/user_money')->state(array('mid'=>$v['id'],'type'=>2));
  326. $tuan = 0;
  327. foreach($tuandui as $t){
  328. $tuan += $t['cash'];
  329. }
  330. $sum = 0;
  331. foreach($order as $k1 => $v1){
  332. $sum += $v1['agent_cash'];
  333. }
  334. $operdate = '';
  335. if($v['operdate']){
  336. $operdate = date('Y-m-d',$v['operdate']);
  337. }
  338. $d = array
  339. (
  340. $code,
  341. $v['name'],
  342. $v['mobile'],
  343. $v['idcard'],
  344. $role['name'],
  345. $area,
  346. $sum,
  347. $operdate,
  348. $total,
  349. $tuan,
  350. $v['audit_desc'],
  351. );
  352. $body[] = $d;
  353. }
  354. $file = Dever::input('excel_name');
  355. return Dever::excelExport($body, $header, $file);
  356. }
  357. }