Money.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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,$order_id);
  75. }
  76. return 'ok';
  77. }
  78. public function up($uid, $type, $cash, $type_id, $desc, $status,$order_id)
  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'] = $order_id;
  96. // $this->getOrderId();
  97. $data['yue'] = $user['cash'] + $cash;
  98. $data['cash'] = $cash;
  99. $data['desc'] = $desc;
  100. $data['status'] = $status;
  101. if ($status == 2) {
  102. $data['operdate'] = time();
  103. }
  104. $update['where_id'] = $uid;
  105. $update['set_cash'] = $cash;
  106. //$update['clear'] = true;
  107. Dever::db('passport/user')->upCash($update);
  108. return Dever::db('shop/user_money')->insert($data);
  109. }
  110. return $info['id'];
  111. }
  112. return false;
  113. }
  114. /**
  115. * 生成订单号
  116. *
  117. * @return mixed
  118. */
  119. public function getOrderId()
  120. {
  121. $where['order_num'] = Dever::order('UM');
  122. $where['clear'] = true;
  123. $state = Dever::db('shop/user_money')->one($where);
  124. if (!$state) {
  125. return $where['order_num'];
  126. } else {
  127. return $this->getOrderId();
  128. }
  129. }
  130. # 展示详情
  131. public function show()
  132. {
  133. $id = Dever::input('id');
  134. $config = Dever::db('shop/user_money')->config['set'];
  135. $info = Dever::db('shop/user_money')->one($id);
  136. $status = $config['status'][$info['status']];
  137. $type = $config['type'][$info['type']];
  138. $user = Dever::db('passport/user')->find($info['uid']);
  139. $cdate = date('Y-m-d H:i', $info['cdate']);
  140. if ($info['operdate']) {
  141. $opertime = date('Y-m-d H:i', $info['operdate']);
  142. } else {
  143. $opertime = '';
  144. }
  145. $result = array();
  146. $result['用户信息'] = array
  147. (
  148. 'type' => 'info',
  149. 'content' => array
  150. (
  151. array
  152. (
  153. array('昵称', $user['username']),
  154. array('手机号', $user['mobile']),
  155. array('资金余额', '¥' . $user['cash'] . '元'),
  156. ),
  157. ),
  158. );
  159. $result['交易信息'] = array
  160. (
  161. 'type' => 'info',
  162. 'content' => array
  163. (
  164. array
  165. (
  166. array('流水号', $info['order_num']),
  167. array('交易时间', $cdate),
  168. array('交易类型', $type),
  169. ),
  170. array
  171. (
  172. array('交易金额', '¥' . $info['cash'] . '元'),
  173. array('交易后账户余额', '¥' . $info['yue'] . '元'),
  174. array('交易说明', $info['desc']),
  175. ),
  176. )
  177. );
  178. $result['审核信息'] = array
  179. (
  180. 'type' => 'info',
  181. 'content' => array
  182. (
  183. array
  184. (
  185. array('审核时间', $opertime),
  186. array('审核状态', $status),
  187. array('备注', $info['audit_desc']),
  188. ),
  189. )
  190. );
  191. # 提现信息
  192. $button = array();
  193. if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit', '审核')) {
  194. if ($info['status'] == 1) {
  195. $button[] = array
  196. (
  197. 'type' => 'edit',
  198. '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'),
  199. 'name' => '审核',
  200. );
  201. }
  202. }
  203. if ($info['type'] == 11) {
  204. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  205. if ($tixian) {
  206. $config = Dever::db('bill/tixian')->config['set'];
  207. $status = $config['status'][$tixian['status']];
  208. if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit1', '发放')) {
  209. if ($info['status'] == 2 && $tixian['status'] == 1) {
  210. $button[] = array
  211. (
  212. 'type' => 'edit',
  213. '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'),
  214. 'name' => '发放',
  215. );
  216. }
  217. }
  218. /*
  219. $bank = Dever::db('setting/bank')->find($tixian['bank']);
  220. $result['提现信息'] = array
  221. (
  222. 'type' => 'info',
  223. 'content' => array
  224. (
  225. array
  226. (
  227. array('银行名称', $bank['name']),
  228. array('开户行', $tixian['bankname']),
  229. ),
  230. array
  231. (
  232. array('姓名', $tixian['name']),
  233. array('卡号', $tixian['card']),
  234. ),
  235. )
  236. );
  237. */
  238. if ($tixian['status']) {
  239. if ($tixian['operdate']) {
  240. $opertime = date('Y-m-d H:i', $tixian['operdate']);
  241. } else {
  242. $opertime = '';
  243. }
  244. $pic = '';
  245. if ($tixian['pic']) {
  246. $temp = explode(',', $tixian['pic']);
  247. foreach ($temp as $k => $v) {
  248. $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
  249. }
  250. }
  251. $result['发放信息'] = array
  252. (
  253. 'type' => 'info',
  254. 'content' => array
  255. (
  256. array
  257. (
  258. array('发放时间', $opertime),
  259. array('发放状态', $status),
  260. array('备注', $tixian['audit_desc']),
  261. ),
  262. array
  263. (
  264. array('凭证', $pic),
  265. ),
  266. )
  267. );
  268. }
  269. }
  270. }
  271. $button[] = array
  272. (
  273. 'type' => 'link',
  274. 'link' => 'refer',
  275. 'name' => '返回上一页',
  276. );
  277. $head = array
  278. (
  279. 'name' => '基本信息',
  280. 'btn' => $button,
  281. );
  282. $html = Dever::show($head, $result);
  283. return $html;
  284. }
  285. public function order_num($id){
  286. $info = Dever::db('shop/user_money')->find($id);
  287. $cdate = date('Y-m-d H:i',$info['cdate']);
  288. $odate = '';
  289. if ($info['operdate']) {
  290. $odate = date('Y-m-d H:i',$info['operdate']);
  291. }
  292. $html['num'] = $cdate . '<br/>'.$odate;
  293. $html['cash'] = $info['cash'] . '<br />' . $info['yue'];
  294. return $html;
  295. }
  296. #钱包管理数据导出
  297. public function out_cash_api($data){
  298. $header = array('邀请码', '姓名', '手机号', '身份证号', '代理角色', '代理商区域', '代理费', '审核时间', '直推收入', '团队收入', '管理员备注');
  299. $body = array();
  300. foreach($data as $k =>$v){
  301. $arr[] = Dever::db('agent/member')->find(array('id'=>$v['mid']));
  302. foreach($arr as $k1=>$v1){
  303. if($v['mid'] == $v1['id']){
  304. $arr[$k1]['operdate'] = $v['operdate'];
  305. $arr[$k1]['audit_desc'] = $v['audit_desc'];
  306. }
  307. }
  308. }
  309. $member = array();
  310. $arr=array_unique($arr, SORT_REGULAR);
  311. $rest=array();
  312. foreach($arr as $k=>$v){
  313. $rest[$v['id']]=$v;
  314. }
  315. $member=array_values($rest);
  316. foreach($member as $k => $v){
  317. $code = Dever::load("invite/api.code", $v['id']);
  318. $role = Dever::db('setting/role')->find(array('id'=>$v['role']));
  319. $area = Dever::load("area/api.string", $v['area']);
  320. $order = Dever::db('agent/order')->state(array('mid'=>$v['id']));
  321. $zhitui = Dever::db('shop/user_money')->state(array('mid'=>$v['id'],'type'=>1));
  322. $total = 0;
  323. foreach($zhitui as $key => $val){
  324. $total += $val['cash'];
  325. }
  326. $tuandui = Dever::db('shop/user_money')->state(array('mid'=>$v['id'],'type'=>2));
  327. $tuan = 0;
  328. foreach($tuandui as $t){
  329. $tuan += $t['cash'];
  330. }
  331. $sum = 0;
  332. foreach($order as $k1 => $v1){
  333. $sum += $v1['agent_cash'];
  334. }
  335. $operdate = '';
  336. if($v['operdate']){
  337. $operdate = date('Y-m-d',$v['operdate']);
  338. }
  339. $d = array
  340. (
  341. $code,
  342. $v['name'],
  343. $v['mobile'],
  344. $v['idcard'],
  345. $role['name'],
  346. $area,
  347. $sum,
  348. $operdate,
  349. $total,
  350. $tuan,
  351. $v['audit_desc'],
  352. );
  353. $body[] = $d;
  354. }
  355. $file = Dever::input('excel_name');
  356. return Dever::excelExport($body, $header, $file);
  357. }
  358. }