Money.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\common\controller\Api;
  5. use app\common\model\GiftUserParty;
  6. use app\common\model\UserExchangeLog;
  7. use app\common\model\UserExchsoundLog;
  8. use applebuy\applebuy;
  9. use fast\Random;
  10. use app\common\model\RecharOrder;
  11. use kjpay\kjpay;
  12. use kjwithdraw\kjwithdraw;
  13. use think\Exception;
  14. use think\exception\PDOException;
  15. use think\exception\ValidateException;
  16. use think\Request;
  17. use think\Db;
  18. use app\common\library\Sms as Smslib;
  19. /**
  20. * 钱包接口
  21. */
  22. class Money extends Api
  23. {
  24. protected $noNeedLogin = ['getRecharConfig', 'getRateMoney', 'getExchangeConfig', 'getExchsoundConfig', 'rebateDuty',
  25. 'kjRecharge', 'changeWithDrawStatus','moneyConfig'];
  26. protected $noNeedRight = '*';
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. }
  31. /**
  32. * 消息-聊天-更多-转账-钻石
  33. */
  34. public function givejeweltouser(){
  35. $money = intval(input('money',0));
  36. $user_id = input('user_id',0);
  37. $pay_password = input('paypassword','');
  38. //验证用户权限是否能转账
  39. if($this->auth->power->transfer == 1){
  40. $this->error('您已经被限制消费-转账');
  41. }
  42. //不允许给自己转账
  43. if ($user_id == $this->auth->id) {
  44. $this->error('不允许给自己转账');
  45. }
  46. //验证被转账用户存在
  47. $check = Db::name('user')->where('id',$user_id)->find();
  48. if(empty($check)){
  49. $this->error('不存在的用户');
  50. }
  51. //验证操作密码
  52. if(!$this->auth->pay_password){
  53. $this->error('请先设置支付密码');
  54. }
  55. if ($this->auth->pay_password != $this->getEncryptPassword($pay_password, $this->auth->pay_salt)) {
  56. $this->error('支付密码有误');
  57. }
  58. Db::startTrans();
  59. //减少和增加余额
  60. $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,$money,'-',0,'私聊转账给:'.$check['nickname'],11,'jewel');
  61. if($rs_wallet['status'] === false){
  62. Db::rollback();
  63. $this->error($rs_wallet['msg']);
  64. }
  65. $rs_wallet = model('wallet')->lockChangeAccountRemain($user_id,$money,'+',0,$this->auth->nickname.':私聊到账',12,'jewel');
  66. if($rs_wallet['status'] === false){
  67. Db::rollback();
  68. $this->error($rs_wallet['msg']);
  69. }
  70. Db::commit();
  71. $this->success('转账成功');
  72. }
  73. /**
  74. * 获取密码加密后的字符串
  75. * @param string $password 密码
  76. * @param string $salt 密码盐
  77. * @return string
  78. */
  79. private function getEncryptPassword($password, $salt = '')
  80. {
  81. return md5(md5($password) . $salt);
  82. }
  83. //提现转账(新版2020-01-01)
  84. public function withdrawTransfer() {
  85. $info = [
  86. 'money' => 0.10,
  87. 'alipay_account' => '',
  88. 'name' => '',
  89. ];
  90. $data['out_biz_no'] = getMillisecond() . mt_rand(1, 1000); //商户订单号
  91. $data['trans_amount'] = $info['money']; //订单总金额,单位为元,精确到小数点后两位
  92. $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';//业务产品码,收发现金红包固定为:STD_RED_PACKET;单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD;单笔无密转账到银行卡固定为:TRANS_BANKCARD_NO_PWD
  93. $data['biz_scene'] = 'DIRECT_TRANSFER'; //描述特定的业务场景,可传的参数如下:PERSONAL_COLLECTION:C2C现金红包-领红包;DIRECT_TRANSFER:B2C现金红包、单笔无密转账到支付宝/银行卡
  94. $data['order_title'] = 'GG语音提现'; //转账业务的标题,用于在支付宝用户的账单里显示
  95. $data['payee_info']['identity'] = $info['alipay_account'];//收款方支付宝id或支付宝账户
  96. /*if ($info['alipay_type'] == 1) { //支付宝账户
  97. $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
  98. //收款支付宝账号真实姓名, 不为空时支付宝会验证
  99. $data['payee_info']['name'] = $info['name'];
  100. } else { //支付宝id
  101. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  102. $data['payee_info']['name'] = '';
  103. }*/
  104. //支付宝id
  105. $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
  106. $data['payee_info']['name'] = $info['name'];
  107. //转账备注(支持200个英文/100个汉字)。当付款方为企业账户,且转账金额达到(大于等于)50000元,remark不能为空。收款方可见,会展示在收款用户的收支详情中。
  108. $data['remark'] = 'GG语音提现';
  109. require_once("../extend/AliPay/AliPay.php");
  110. $alipay =new \AliPay();
  111. $result =$alipay->AliPayWithdraw($data);
  112. return $result;
  113. }
  114. }