| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\utils\WechatMerchant\WxV3;
- use Yii;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%cash}}".
- *
- * @property int $id
- * @property int $user_id 用户id
- * @property int $saas_id 商盟id
- * @property int $store_id 商城id
- * @property float $price 提现金额
- * @property int $status 申请状态 0--申请中 1--确认申请 2--已打款 3--驳回 5--余额通过
- * @property int $is_delete 是否删除
- * @property int|null $created_at 添加時間
- * @property int $pay_time 付款
- * @property int $type 支付方式 0--微信支付 1--支付宝 2--银行卡 3--余额
- * @property string|null $mobile 支付宝账号
- * @property string|null $name 支付宝姓名
- * @property string|null $bank_name 开户行名称
- * @property int|null $pay_type 打款方式 0--之前未统计的 1--微信自动打款 2--手动打款
- * @property string|null $order_no 微信自动打款订单号
- * @property float $service_charge 提现手续费
- * @property int|null $cash_type 0、正常,1、自提点提现
- * @property int|null $updated_at 更新时间
- * @property int $md_id 门店id
- * @property string|null $out_detail_no 微信转账明细单号
- * @property string|null $batch_id 微信转账明细单号
- * @property string|null $transfer_status 转账状态
- * @property string|null $transfer_time 转账成功时间
- * @property string|null $transfer_detail 微信返回的原始转账明细
- * @property string|null $partner_trade_no 微信返回的订单号 *
- * @property int $is_ref 是否重新打款
- * @property string|null $ref_order_no 重新打款订单号
- */
- class StoreCash extends \yii\db\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%store_cash}}';
- }
- /**
- * 已删除
- */
- const IS_DELETE_YES = 1;
- /**
- * 未删除
- */
- const IS_DELETE_NO = 0;
- /**
- * 申请中
- */
- const STATUS_APPLY = 0;
- /**
- * 确认申请
- */
- const STATUS_CONFIRM = 1;
- /**
- * 已打款
- */
- const STATUS_GIVEN = 2;
- /**
- * 驳回
- */
- const STATUS_REFUSE = 3;
- /**
- * 手动打款
- */
- const STATUS_HAND = 4;
- /**
- * 余额通过
- */
- const STATUS_RECHARGE = 5;
- /**
- * 微信打款
- */
- const TYPE_WX = 0;
- /**
- * 支付宝打款
- */
- const TYPE_ALIPAY = 1;
- /**
- * 银行卡打款
- */
- const TYPE_BANK = 2;
- /**
- * 余额打款
- */
- const TYPE_RECHARGE = 3;
- /**
- * 之前未统计的
- */
- const PAY_TYPE_NO = 0;
- /**
- * 微信自动打款
- */
- const PAY_TYPE_WX = 1;
- /**
- * 手动拨款
- */
- const PAY_TYPE_HAND = 2;
- /**
- * 正常
- */
- const CASH_TYPE_NORMAL = 0;
- /**
- * 联盟券
- */
- const CASH_TYPE_ALLIANCE_COUPON = 1;
- /**
- * 串码红包
- */
- const CASH_TYPE_STRING_CODE = 2;
- public static $status = [
- '待审核',
- '待打款',
- '已打款',
- '无效'
- ];
- public static $type = [
- '微信线下支付',
- '支付宝支付',
- '银行卡支付',
- '余额支付',
- ];
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['store_id'], 'required'],
- [['md_id', 'user_id', 'saas_id', 'store_id', 'status', 'is_delete', 'created_at', 'pay_time', 'type', 'pay_type', 'cash_type', 'updated_at'], 'integer'],
- [['price', 'service_charge'], 'number'],
- [['mobile', 'name', 'order_no'], 'string', 'max' => 255],
- [['bank_name'], 'string', 'max' => 30],
- [['user_id', 'pay_time', 'reject_reason'], 'safe'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => '用户id',
- 'saas_id' => '商盟用户id',
- 'store_id' => '商城id',
- 'price' => '提现金额',
- 'status' => '申请状态 0--申请中 1--确认申请 2--已打款 3--驳回 5--余额通过',
- 'is_delete' => '是否删除',
- 'created_at' => '添加時間',
- 'pay_time' => '付款',
- 'type' => '支付方式 0--微信支付 1--支付宝 2--银行卡 3--余额',
- 'mobile' => '支付宝账号',
- 'name' => '支付宝姓名',
- 'bank_name' => '开户行名称',
- 'pay_type' => '打款方式 0--之前未统计的 1--微信自动打款 2--手动打款',
- 'order_no' => '微信自动打款订单号',
- 'service_charge' => '提现手续费',
- 'cash_type' => '0、正常,1、自提点提现',
- 'updated_at' => '更新时间',
- ];
- }
- public static function getStatusName($cash)
- {
- $name = '';
- if($cash['status'] == 0){
- $name = '申请中';
- }
- if($cash['status'] == 1){
- $name = '确认申请';
- }
- if($cash['status'] == 2){
- $name = '已打款';
- }
- if($cash['status'] == 3){
- $name = '驳回';
- }
- if($cash['status'] == 5){
- $name = '余额通过';
- }
- return $name;
- }
- public static function getTypeName($cash)
- {
- $name = '';
- if($cash['type'] == 0){
- $name = '微信';
- }
- if($cash['type'] == 1){
- $name = '支付宝';
- }
- if($cash['type'] == 2){
- $name = '银行卡';
- }
- if($cash['type'] == 3){
- $name = '余额';
- }
- return $name;
- }
- public static function getServiceMoney($cash)
- {
- if($cash['service_charge'] == 0){
- $price = $cash['price'];
- }else{
- $cashPrice = floatval($cash['price']);
- $price = $cashPrice * (100 - $cash['service_charge']) / 100;
- }
- return round($price, 2);
- }
-
- //最大提现金额
- public static function getMaxCash($store, &$data = []) {
- $storeMoney = Store::getMoney($store);
- $storeMoneyTotal = Store::getTotalMoney($store);
- $moneyMd = Md::find()->where(['store_id' => $store->id, 'is_delete' => 0])
- ->andWhere(['>', 'cash_profit', 0])
- ->sum('cash_profit') ?: 0;
- $moneyUser = User::find()->where(['store_id' => $store->id, 'is_delete' => 0])
- ->andWhere(['>', 'price', 0])
- ->sum('price') ?: 0;
- $hasIncoming = Store::hasIncoming($store->id);
- if($hasIncoming){
- $max = $storeMoney;
- }else{
- $max = bcsub(bcsub($storeMoney, $moneyMd, 2), $moneyUser, 2);//$storeMoney - $moneyMd - $moneyUser;
- }
- $data['storeMoneyTotal'] = $storeMoneyTotal;
- $data['storeMoney'] = $storeMoney;
- $data['moneyUser'] = $moneyUser;
- $data['moneyMd'] = $moneyMd;
- $data['moneyFrozen'] = bcadd($moneyMd, $moneyUser, 2);
- return $max;
- }
- //新增判断openid
- // public function beforeSave($insert)
- // {
- // // 判断是否有 openid
- // if (empty($this->mobile)) {
- // // 如果没有 openid
- // return false;
- // }
- // // 如果有 openid,继续保存
- // return parent::beforeSave($insert);
- // }
- public static function getRejectReason($batch_id){
- $wechat = getAllianceClientWxConfig();
- $result = (new WxV3($wechat))->queryTransferStatus($batch_id, 0);
- $resfobj = json_decode($result);
- $transfer_detail_list = $resfobj->transfer_detail_list;
- $detailref = '';
- if ($transfer_detail_list) {
- $detail_response = (new WxV3($wechat))->queryTransferDetail($batch_id, $transfer_detail_list[0]->detail_id, 0);
- $detail_response_obj = json_decode($detail_response);
- $detailref = self::handleTransferFailure($detail_response_obj->fail_reason);
- }
- return $detailref;
- }
- public static function handleTransferFailure($failure_reason)
- {
- // 根据失败原因进行处理
- switch ($failure_reason) {
- case 'ACCOUNT_FROZEN':
- return "该用户账户被冻结,请联系客服处理。";
- case 'REAL_NAME_CHECK_FAIL':
- return "收款人未实名认证,需要用户完成微信实名认证。";
- case 'NAME_NOT_CORRECT':
- return "收款人姓名校验不通过,请核实信息。";
- case 'OPENID_INVALID':
- return "Openid格式错误或者不属于商家公众账号。";
- case 'TRANSFER_QUOTA_EXCEED':
- return "超过用户单笔收款额度,请核实产品设置是否准确。";
- case 'DAY_RECEIVED_QUOTA_EXCEED':
- return "超过用户单日收款额度,请核实产品设置是否准确。";
- case 'MONTH_RECEIVED_QUOTA_EXCEED':
- return "超过用户单月收款额度,请核实产品设置是否准确。";
- case 'DAY_RECEIVED_COUNT_EXCEED':
- return "超过用户单日收款次数,请核实产品设置是否准确。";
- case 'PRODUCT_AUTH_CHECK_FAIL':
- return "未开通该权限或权限被冻结,请核实产品权限状态。";
- case 'OVERDUE_CLOSE':
- return "超过系统重试期,系统自动关闭。";
- case 'ID_CARD_NOT_CORRECT':
- return "收款人身份证校验不通过,请核实信息。";
- case 'ACCOUNT_NOT_EXIST':
- return "该用户账户不存在,请核实用户信息。";
- case 'TRANSFER_RISK':
- return "该笔转账可能存在风险,已被微信拦截。";
- case 'OTHER_FAIL_REASON_TYPE':
- return "其它失败原因,请联系微信支付客服。";
- case 'REALNAME_ACCOUNT_RECEIVED_QUOTA_EXCEED':
- return "用户账户收款受限,请引导用户在微信支付查看详情。";
- case 'RECEIVE_ACCOUNT_NOT_PERMMIT':
- return "未配置该用户为转账收款人,请在产品设置中调整,添加该用户为收款人。";
- case 'PAYEE_ACCOUNT_ABNORMAL':
- return "用户账户收款异常,请联系用户完善其在微信支付的身份信息。";
- case 'PAYER_ACCOUNT_ABNORMAL':
- return "商户账户付款受限,请前往商户平台获取解除功能限制指引。";
- case 'TRANSFER_SCENE_UNAVAILABLE':
- return "该转账场景暂不可用,请确认转账场景ID是否正确。";
- case 'TRANSFER_SCENE_INVALID':
- return "你尚未获取该转账场景,请确认转账场景ID是否正确。";
- case 'TRANSFER_REMARK_SET_FAIL':
- return "转账备注设置失败,请调整后重新再试。";
- case 'RECEIVE_ACCOUNT_NOT_CONFIGURE':
- return "请前往商户平台-商家转账到零钱-前往功能-转账场景中添加。";
- case 'BLOCK_B2C_USERLIMITAMOUNT_BSRULE_MONTH':
- return "超出用户单月转账收款20w限额,本月不支持继续向该用户付款。";
- case 'BLOCK_B2C_USERLIMITAMOUNT_MONTH':
- return "用户账户存在风险收款受限,本月不支持继续向该用户付款。";
- case 'MERCHANT_REJECT':
- return "商户员工(转账验密人)已驳回转账,请检查操作。";
- case 'MERCHANT_NOT_CONFIRM':
- return "商户员工(转账验密人)超时未验密,请及时完成操作。";
- default:
- return "未知的失败原因,请稍后重试或联系微信支付客服。";
- }
- }
- }
|