php实现微信企业号支付个人的方法详解(2)

企业付款

private function _enterprisePay($number, $member_id, $amount, $desc)
{
    // 获取openid
    $wxuser_id = M('Member')->where(array('id' => $member_id))->getField('wxuser_id');
    $openid  = M('Wxuser')->where(array('id' => $wxuser_id))->getField('openid');
    $pay = C('PAY_WEIXIN');
    import('@.Action.WxDevelop');
    $enterprise = new WxEnterprise($pay['appid'], $pay['appsecret'], $pay['mchid']);
    $params = array(
      'partner_trade_no' => $number,
      'openid' => $openid,
      'check_name' => 'NO_CHECK',
      'amount' => $amount, // 总计
      'desc' => $desc,
    );
    $result = $enterprise->payToUser($params, $pay['key'], $pay['apiclient_cert'], $pay['apiclient_key']);
    return $result;
}

处理分销商提现

private function _handle($truename, $price) { // 处理分销商提现
    $withdrawid = date("ymdHis") . strval(rand(1000, 9999));
    $data = array('withdrawid' => $withdrawid, 'store_id' => $this->store_id, 'member_id' => $this->member_id, 'truename' => $truename, 'price' => $price, 'addtime' => time());
    //免审核
    if ($price >= C('withdraw_uncheck_value')) {
      $data['need_check'] = 0;
      $data['status'] = 1;
      if ($this->withdrawModel->add($data)) {
        $result = $this->_enterprisePay($withdrawid, $this->member_id, $price * 100, '分销商(' . $truename . ')提现');
        //遇到支付信息出错,转为需审核提现
        if ($result['return_code'] != 'SUCCESS') {
          $this->withdrawModel->where(array('withdrawid' => $withdrawid))->save(array('need_check' => 1, 'status' => 0));
          $this->assign('success', 2);
        }
        else {
          //设置微信交易号
          $this->withdrawModel->where(array('withdrawid' => $withdrawid))->save(array('payment_no' => $result['payment_no']));
          //增加佣金流水,待修复
          $data = array('store_id' => $this->store_id, 'user_type' => 2, 'user_id' => $this->shop_id, 'trade_type' => 2, 'trade_no' => $withdrawid, 'price' => -$price, 'status'=> 1, 'message' => $truename.'提现', 'addtime' => time());
          M('Twitter_log')->add($data);
          //减少相应可提佣金
          M('Member')->where(array('id' => $this->member_id))->setInc('money', -$price);
          $this->assign('success', 1);
          //发送佣金变动消息
          import('@.Action.Tmplmsg');
          $tmplmsg = new Tmplmsg();
          $tmplmsg->send(Tmplmsg::PRICE_CHANGE, $this->member_id, array('token' => $this->token, 'intro' => '分销佣金提现转出', 'price' => $price, 'business' => BUSINESS));
        }
      }
      else {
        $this->error('提现信息错误!');
      }
    }
    //需要审核
    else {
      $this->withdrawModel->add($data);
      $this->assign('success' , 2);
    }
}

      

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2384.html