attributes = get_params(); $form->store_id = $store_id; return $this->asJson($form->getList()); } /** * 设置分销商等级 */ public function actionSetShareLevel() { $store_id = get_store_id(); $form = new ShareListForm(); $form->attributes = post_params(); $form->store_id = $store_id; return $this->asJson($form->setShareLevel()); } /** * @return mixed|string * 佣金设置 */ public function actionBasicSetting() { $store_id = get_store_id(); $shareOption = Option::findOne([ 'store_id' => $store_id, 'group' => OptionSetting::SHARE_GROUP_NAME, 'name' => OptionSetting::SHARE_BASIC_SETTING ]); if (!$shareOption) { $shareOption = new Option(); } $form = new ShareSettingForm(); $form->data = post_params(); $form->model = $shareOption; $form->store_id = get_store_id(); return $this->asJson($form->setBasicSetting()); } /** * @return mixed|string * 佣金设置 */ public function actionSaasBasicSetting() { $store_id = -1; $shareOption = Option::findOne([ 'store_id' => $store_id, 'group' => OptionSetting::SHARE_GROUP_NAME, 'name' => OptionSetting::SHARE_BASIC_SETTING ]); if (!$shareOption) { $shareOption = new Option(); } $form = new ShareSettingForm(); $form->data = post_params(); $form->model = $shareOption; $form->store_id = $store_id; return $this->asJson($form->setSaasBasicSetting()); } /** * @return mixed|string * 佣金设置 */ public function actionMoneySetting() { $first_name = post_params('first_name'); if (empty($first_name)) { $first_name = '一级'; } $second_name = post_params('second_name'); if (empty($second_name)) { $second_name = '二级'; } $third_name = post_params('third_name'); if (empty($third_name)) { $third_name = '三级'; } $expire_day = !empty(post_params('expire_day')) ? post_params('expire_day') : 0; $scale = !empty(post_params('scale')) ? post_params('scale') : 0; // 佣金类型:1.会员佣金,2.订单佣金 $commission_type = !empty(post_params('commission_type')) ? post_params('commission_type') : ''; // 佣金发放类型:0.佣金,1.积分,2.余额 $giveType = !empty(post_params('giveType')) ? post_params('giveType') : ''; $value = [ 'level_one' => [ 'text' => $first_name, 'value' => post_params('first'), ], 'level_two' => [ 'text' => $second_name, 'value' => post_params('second'), ], 'level_three' => [ 'text' => $third_name, 'value' => post_params('third'), ], 'commission_type' => $commission_type, 'giveType' => $giveType, 'expire_day' => $expire_day, 'scale' => $scale, ]; if ( !is_numeric(post_params('first')) || !is_numeric(post_params('second')) || !is_numeric(post_params('third')) ) { return $this->asJson(['code' => 1, 'msg' => '佣金请输入数字!']); } $store_id = get_store_id(); $shareOption = Option::findOne([ 'store_id' => $store_id, 'group' => OptionSetting::SHARE_GROUP_NAME, 'name' => OptionSetting::SHARE_MONEY_SETTING ]); if (!$shareOption) { $shareOption = new Option(); } $form = new ShareSettingForm(); $form->data = $value; $form->model = $shareOption; $form->store_id = $store_id; return $this->asJson($form->setMoneySetting()); } /** * 分销商详情 */ public function actionDetail() { $form = new ShareOrderForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); return $this->asJson($form->detail()); } /** * 分销商订单 */ public function actionShareOrder() { $form = new ShareOrderForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); return $this->asJson($form->shareOrder()); } /** * @return mixed|string * 佣金设置获取 */ public function actionGetShareSetting() { $form = new ShareSettingForm(); $form->name = get_params('name'); $form->store_id = get_store_id(); return $this->asJson($form->getShareSetting()); } /** * @return mixed|string * saas佣金设置获取 */ public function actionGetSaasShareSetting() { $form = new ShareSettingForm(); $form->name = get_params('name'); $form->store_id = -1; return $this->asJson($form->getShareSetting()); } /** * 添加备注 * @return array */ public function actionSellerComments() { $id = post_params('id'); $seller_comments = post_params('seller_comments'); $share = Share::findOne([ 'store_id' => get_store_id(), 'is_delete' => Share::SHARE_NOT_DELETE, 'id' => $id ]); $share->seller_comments = $seller_comments; if ($share->save()) { return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } else { $this->asJson(['code' => 1, 'msg' => '保存异常']); } } /** * @param int $id * @param int $status * @return mixed|string * @DateTime 2021-12-09 * 申请审核 */ public function actionStatus() { $id = post_params('id'); $status = intval(post_params('status')); $store_id = get_store_id(); if (is_array($id)) { $share = Share::find()->where(['in','id',$id, 'is_delete' => Share::SHARE_NOT_DELETE, 'store_id' => $store_id])->asArray()->all(); } else { $share = Share::findOne(['id' => $id, 'is_delete' => Share::SHARE_NOT_DELETE, 'store_id' => $store_id]); } if (!$share) { return $this->asJson([ 'code' => 1, 'msg' => '网络异常,请刷新重试' ]); } if (!in_array($status, [1, 2])) { return $this->asJson([ 'code' => 1, 'msg' => '网络异常,请刷新重试' ]); } if ($status == 1) { if (is_array($share)) { $shares = SHare::updateAll(['status' => $status, 'created_at' => time()], ['in', 'id', $id]); foreach ($share as &$val) { User::updateAll(['time' => time(), 'is_distributor' => User::IS_DISTRIBUTOR], ['id' => $val['user_id'],'store_id' => $store_id]); NoticeSend::ShareExamine($val['user_id'], $val['mobile'], '通过', '分销商'); } } else { $shares = SHare::updateAll(['status' => $status, 'created_at' => time()], ['=', 'id', $id]); User::updateAll(['time' => time(), 'is_distributor' => User::IS_DISTRIBUTOR], ['id' => $share->user_id,'store_id' => $store_id]); NoticeSend::ShareExamine($share->user_id, $share->mobile, '通过', '分销商'); } } else { if (is_array($share)) { $shares = SHare::updateAll(['status' => $status, 'created_at' => time()], ['in', 'id', $id]); foreach ($share as &$val) { User::updateAll(['time' => time(), 'is_distributor' => User::NOT_DISTRIBUTOR], ['id' => $val['user_id'],'store_id' => $store_id]); NoticeSend::ShareExamine($val['user_id'], $val['mobile'], '不通过', '分销商'); } } else { $shares = SHare::updateAll(['status' => $status, 'created_at' => time()], ['=', 'id', $id]); User::updateAll(['time' => time(), 'is_distributor' => User::NOT_DISTRIBUTOR], [ 'id' => $share->user_id, 'store_id' => $store_id ]); NoticeSend::ShareExamine($share->user_id, $share->mobile, '不通过', '分销商'); } } if ($shares > 0 ) { return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '请刷新重试' ]); } } /** * @param int $id * @return mixed|string * @throws \yii\db\Exception * 删除分销商 */ public function actionDel() { $id = post_params('id'); $share = Share::findOne(['id' => $id, 'is_delete' => Share::SHARE_NOT_DELETE]); if (!$share) { return $this->asJson([ 'code' => 1, 'msg' => '网络异常' ]); } $t = \Yii::$app->db->beginTransaction(); $count1 = Share::updateAll(['is_delete' => Share::SHARE_IS_DELETE], 'id=:id', [':id' => $id]); $user = User::findOne($share->user_id); $user->is_distributor = User::NOT_DISTRIBUTOR; // $user->parent_id = 0; // $user->old_parent_id = 0; $user->time = time(); $user->save(); // User::updateAll(['parent_id' => 0], 'parent_id=:parent_id', [':parent_id' => $share->user_id]); if ($count1 != 0) { $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '网络异常' ]); } } /** * 分销提现列表 * @return \yii\web\Response */ public function actionCash() { $store_id = get_store_id(); $form = new CashForm(); $form->attributes = all_params(); $form->store_id = $store_id; if(get_mch_id()){ $form->mch = 1; $form->mch_id = get_mch_id(); $form->cash_type = Cash::IS_CASH_TYPE_MCH; } return $this->asJson($form->getShareCashList()); } /** * 用户分销提现列表 */ public function actionUserCash() { $store_id = get_store_id(); $form = new CashForm(); $form->attributes = get_params(); $form->store_id = $store_id; return $this->asJson($form->shareCashUserList()); } /** * 用户分销提现列表 */ public function actionSaasCash() { $store_id = -1; //saascash store_id 固定为-1 $form = new CashForm(); $form->attributes = get_params(); $form->store_id = $store_id; return $this->asJson($form->shareCashSaasList()); } /** * 修改分销商备注 */ public function actionSetShareSeller() { $id = post_params('id'); $seller_comments = post_params('seller_comments'); $share = Share::findOne(['id' => (int)$id]); if (!$share) { return $this->asJson([ 'code' => 1, 'msg' => '分销商不存在' ]); } $share->seller_comments = $seller_comments; if ($share->save()) { return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } } /** * 提现申请审核 * @return \yii\web\Response */ public function actionApply() { $id = post_params('id'); $status = post_params('status'); $store_id = get_store_id(); $cash = Cash::findOne([ 'id' => $id, 'is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id ]); if (!$cash) { return $this->asJson([ 'code' => 1, 'msg' => '提现记录不存在,请刷新重试' ]); } if (!$cash->order_no) { $order_no = null; while (true) { $order_no = date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } $cash->order_no = $order_no; $cash->save(); } \Yii::$app->cache->set('cash_cache_' . $id, $cash->order_no); if (!in_array($status, [1, 3])) { \Yii::$app->cache->set('cash_cache_' . $id, false); return $this->asJson([ 'code' => 1, 'msg' => '提现记录已审核,请刷新重试' ]); } $cash->status = $status; if ($status == Cash::STATUS_REFUSE) { $user = User::findOne(['id' => $cash->user_id]); // if (! $user) { // return $this->asJson([ // 'code' => 1, // 'msg' => '用户数据不存在' // ]); // } cash::cashRefuse($cash->id); NoticeSend::CashFail($cash->user_id, $user->binding, $cash->price, '提现被驳回', '提现被驳回'); } if ($cash->save()) { return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '网络异常,请刷新重试' ]); } } /** * 商盟saas提现申请审核 * @return \yii\web\Response */ public function actionSaasApply() { $id = post_params('id'); $status = post_params('status'); $store_id = -1; //saas 商盟店铺固定id为-1 $cash = Cash::findOne([ 'id' => $id, 'is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id ]); if (!$cash) { return $this->asJson([ 'code' => 1, 'msg' => '提现记录不存在,请刷新重试' ]); } if (!$cash->order_no) { $order_no = null; while (true) { $order_no = date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } $cash->order_no = $order_no; $cash->save(); } \Yii::$app->cache->set('cash_cache_' . $id, $cash->order_no); if (!in_array($status, [1, 3])) { \Yii::$app->cache->set('cash_cache_' . $id, false); return $this->asJson([ 'code' => 1, 'msg' => '提现记录已审核,请刷新重试' ]); } $cash->status = $status; if ($status == Cash::STATUS_REFUSE) { $saas = SaasUser::findOne(['id' => $cash->saas_id]); if (! $saas) { return $this->asJson([ 'code' => 1, 'msg' => '用户数据不存在' ]); } if ($cash->cash_type == 0) { $saas->price += $cash->price; if (!$saas->save()) { return $this->asJson([ 'code' => 1, 'msg' => '网络异常' ]); } } // else { // $user->tuan_price += $cash->price; // if (!$user->save()) { // return $this->asJson([ // 'code' => 1, // 'msg' => '网络异常' // ]); // } else { // $shop = Shop::findOne(['user_id'=> $user->id, 'store_id' => $user->store_id, 'is_delete' => 0,'shop_audit' => 1]); // $shop_form = new ShopShare(); // $shop_form->store_id = $user->store_id; // $shop_form->shop_id = $shop->id; // $shop_form->type = 0; // $shop_form->amount = $cash->price; // $shop_form->the_desc = '团长'.$user->nickname.'提现驳回'; // $shop_form->created_at = time(); // $shop_form->status = 1; // $shop_form->save(); // } // } //NoticeSend::CashFail($cash->user_id, $user->binding, $cash->price, '提现被驳回', '提现被驳回'); } if ($cash->save()) { return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '网络异常,请刷新重试' ]); } } public function actionConfirm() { $id = post_params('id'); $status = post_params('status'); $store_id = get_store_id(); $store = Store::findOne($store_id); $cash = Cash::findOne([ 'id' => $id, 'is_delete' => Cash::IS_DELETE_NO, 'store_id' => $store_id ]); if (!$cash) { return $this->asJson([ 'code' => 1, 'msg' => '提现记录不存在,请刷新重试' ]); } if ($status == Cash::STATUS_GIVEN) { if($store->is_platform_transfers == 1){ $store_wechat_cash = json_decode(Option::get('store_wechat_cash', $store_id, 'store')['value'], true); $val = 0; foreach ((array)$store_wechat_cash as $value) { if (!empty($value)) { $val = 1; break; } } if(!$val){ return $this->asJson([ 'code' => 1, 'msg' => '未配置平台微信提现设置' ]); } } } if (!$cash->order_no) { $order_no = null; while (true) { $order_no = date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } $cash->order_no = $order_no; $cash->save(); } if ($cash->status != 1) { return $this->asJson([ 'code' => 1, 'msg' => '操作错误,请刷新重试' ]); } $res = []; $cashExt = CashExt::findOne(['cash_id' => $cash['id'], 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); if ($cashExt) { $price = $cashExt->real_price; } else { $price = Cash::getServiceMoney($cash); } $servePrice = $cash->price * ($cash->service_charge / 100); if ($store->store_balance < $price && $store->is_platform_transfers == 1) { return $this->asJson([ 'code' => 1, 'msg' => '店铺剩余提现余额不足' ]); } $wechat_type = 1; $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value']; if($store->is_platform_transfers == 1){ $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value']; $wechat_type = 0; } $t = \Yii::$app->db->beginTransaction(); if ($status == Cash::STATUS_GIVEN) { //微信自动打款 $cash->status = Cash::STATUS_GIVEN; $cash->pay_time = time(); $cash->pay_type = Cash::PAY_TYPE_WX; $cash->wx_cash_status = -1; $user = User::findOne(['id' => $cash->user_id]); $data = [ 'partner_trade_no' => $cash->order_no, 'openid' => $user->wechat_open_id, 'check_name' => 'NO_CHECK', 'amount' => $price * 100, 'desc' => '转账', 'user_name' => $cash->name ]; if ((int)$cash->type === 0) { if (\Yii::$app->prod_is_dandianpu() && !\app\models\Store::hasIncoming($store_id)) { //商城是否进件 //商城余额是否充足 $storeMoney = \app\models\StoreCash::getMaxCash($store); if($storeMoney < $price){ $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '操作错误,商城余额不足! 当前余额:¥' . $storeMoney ]); } //扣除商城余额 $subMoney = \app\models\Store::subMoney($store, $price); if(!$subMoney){ $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '网络异常,subMoney失败1', ]); } } else { if (\Yii::$app->prod_is_duli()) { // $WechatConfig = WechatConfig::findOne(['store_id' => get_store_id()]); // if (empty($WechatConfig->mch_id) || empty($WechatConfig->pay_key) || empty($WechatConfig->app_id)|| empty($WechatConfig->cert_pem)|| empty($WechatConfig->key_pem)) { // return $this->asJson([ // 'code' => 1, // 'msg' => "后台参数配置错误,请检查参数后重试" // ]); // } } } if ($wechat_type == 0) { $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); $before = $store->store_balance; $store->store_balance -= $cashExt ? $cashExt->real_price : $price; $store->price -= $cashExt ? $cashExt->real_price : $price; $store->store_withdrawn_cash += $cashExt ? $cashExt->real_price : $price; $after = $store->store_balance; $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice; $cashExtPrice = $cashExt ? $cashExt->price : $cash->price; $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price; if ($store->save()) { StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type); } } $wechat = \Yii::$app->controller->wechatPay; // $res = $wechat->transfer->toBalance($data); $res = (new \app\utils\WechatMerchant\WxV3($wechat))->transferBatches(get_store_id(), $data); //判断是否使用新版本转账 增加转账标识 $wechat_cash = json_decode($wechat_cash, true); if (intval($wechat_cash['is_open']) === 2) { if (!$res['code']) { $cash->is_platform_transfers = intval($store->is_platform_transfers); $cash->wx_cash_type = Cash::WX_CASH_TYPE_NEW; $cash->wx_cash_state = $res['data']['state']; $cash->wx_cash_result_info = json_encode($res['data'], JSON_UNESCAPED_UNICODE); $cash->save(); } } NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '微信自动打款', ($cash->price - $price)); } elseif ((int)$cash->type === 1) { $order = (object)[ 'store_id' => $cash->store_id, 'order_no' => $cash->order_no, 'pay_price' => sprintf("%.2f", $price), 'name' => $cash->name ]; $result = Alipay::transfer($order, $cash->mobile); if (isset($result['code']) && $result['code'] == 1) { if (strpos($result['msg'], 'aop.invalid-app-auth-token-no-api')) { $result['msg'] = '接口未授权,请前往支付宝开放平台查询是否开通产品或授权支付宝转账产品'; } if (strpos($result['msg'], 'PAYEE_NOT_EXIST')) { $result['msg'] = '收款账号不存在或姓名有误,建议核实账号和姓名是否准确'; } if (strpos($result['msg'], 'BALANCE_IS_NOT_ENOUGH')) { $result['msg'] = '商户余额不足'; } return $this->asJson($result); } else { // TODO 扣除店铺提现金额 if ($wechat_type == 0) { $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); $before = $store->store_balance; $store->store_balance -= $cashExt ? $cashExt->real_price : $price; $store->price -= $cashExt ? $cashExt->real_price : $price; $store->store_withdrawn_cash += $cashExt ? $cashExt->real_price : $price; $after = $store->store_balance; $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice; $cashExtPrice = $cashExt ? $cashExt->price : $cash->price; $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price; if ($store->save()) { StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type); } } } $cash->save(); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); }elseif ((int)$cash->type === 4) { $user = User::findOne($cash->user_id); $saas = SaasUser::findOne(['mobile' => $user->binding]); $lg_info = Lg::find()->where(['user_id'=>$saas->id,'status'=>1,'is_delete'=>0])->one(); $lgApi = new LgApi($cash->store_id); //灵工提现 $post_data = [ 'store_id' => $cash->store_id, 'outTradeNo' => $cash->order_no,//唯一批次号 'accNo' => bcmul($price,100), 'amt' => bcmul($price,100), 'name' => $lg_info->name, 'certCard' => $lg_info->cert_card//身份证号 ]; $result = $lgApi->FlexiblePay($post_data); if (isset($result['status']) && $result['status'] == 999) { return $this->asJson($result); } $cash->status = 6;//灵工待打款 $cash->save(); $t->commit(); //灵工提现接口调用后消息队列查询状态 \queue_push(new LgCashJob(['id'=>$cash->id,'store_id'=>$store_id,'type'=>0,'retry' => 5]), 60); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } } elseif ($status == Cash::STATUS_HAND) { //手动打款 $user = User::findOne($cash->user_id); // TODO 扣除店铺提现金额 if ($wechat_type == 0) { $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); $before = $store->store_balance; $store->store_balance -= $cashExt ? $cashExt->real_price : $price; $store->price -= $cashExt ? $cashExt->real_price : $price; $store->store_withdrawn_cash += $cashExt ? $cashExt->real_price : $price; $after = $store->store_balance; $cashExtServePrice = $cashExt ? bcsub($cashExt->price, $cashExt->real_price, 2) : $servePrice; $cashExtPrice = $cashExt ? $cashExt->price : $cash->price; $cashExtRealPrice = $cashExt ? $cashExt->real_price : $price; if ($store->save()) { StoreMoneyLog::saveLog(get_store_id(), StoreMoneyLog::LOG_TYPE_EXPEND, StoreMoneyLog::TYPE_SHARE, $cashExtRealPrice, " ID{$id}:用户提现{$cashExtPrice}元,扣除手续费{$cashExtServePrice}元,提现实际扣除{$cashExtRealPrice}元", $before, $after, $wechat_type); } else { $t->rollBack(); } } $cash->status = Cash::STATUS_HAND; $cash->pay_time = time(); $cash->pay_type = Cash::PAY_TYPE_HAND; if ($cash->type == Cash::TYPE_RECHARGE) { $cashExt = CashExt::findOne(['cash_id' => $cash->id, 'cash_price_type' => CashExt::CASH_PRICE_TYPE_AMOUNT]); if ($cashExt && $cashExt->real_price > 0) { AccountLog::saveLog($cash->user_id, $cashExt->real_price, 2, 1, 0, 0, '佣金提现打款'); } } $res['result_code'] = "SUCCESS"; NoticeSend::CashSuccess($cash->user_id, $user->binding, $cashExt ? $cashExt->real_price : $price, '手动打款', ($cash->price - ($cashExt ? $cashExt->real_price : $price))); } if (isset($res['result_code']) && $res['result_code'] == 'SUCCESS') { $cash->save(); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => !empty($res['err_code_des']) ? $res['err_code_des'] : '请稍后重试', 'data' => $res ]); } } //saas确认打款 public function actionSaasConfirm() { $id = post_params('id'); $status = post_params('status'); $store_id = get_store_id(); $cash = Cash::findOne(['id' => $id, 'is_delete' => Cash::IS_DELETE_NO]); if (!$cash) { return $this->asJson([ 'code' => 1, 'msg' => '提现记录不存在,请刷新重试' ]); } if (!$cash->order_no) { $order_no = null; while (true) { $order_no = date('YmdHis') . mt_rand(100000, 999999); $exist_order_no = Cash::find()->where(['order_no' => $order_no])->exists(); if (!$exist_order_no) { break; } } $cash->order_no = $order_no; $cash->save(); } if ($cash->status != 1) { return $this->asJson([ 'code' => 1, 'msg' => '操作错误,请刷新重试' ]); } $res = []; $price = Cash::getServiceMoney($cash); if ($status == Cash::STATUS_GIVEN) { //微信自动打款 $cash->status = Cash::STATUS_GIVEN; $cash->pay_time = time(); $cash->pay_type = Cash::PAY_TYPE_WX; $saas = SaasUser::findOne(['id' => $cash->saas_id]); $data = [ 'partner_trade_no' => $cash->order_no, 'openid' => $saas->platform_open_id, 'check_name' => 'NO_CHECK', 'amount' => $price * 100, 'desc' => '转账', 'user_name' => $cash->name ]; // $WechatConfig = WechatConfig::findOne(['store_id' => get_store_id()]); // if (empty($WechatConfig->mch_id) || empty($WechatConfig->pay_key) || empty($WechatConfig->app_id)|| empty($WechatConfig->cert_pem)|| empty($WechatConfig->key_pem)) { // return $this->asJson([ // 'code' => 1, // 'msg' => "后台参数配置错误,请检查参数后重试" // ]); // } $store = Store::findOne($store_id); $wechat_cash = Option::get('wechat_cash', $store_id, 'store')['value']; if($store->is_platform_transfers == 1){ $wechat_cash = Option::get('store_wechat_cash', $store_id, 'store')['value']; } $wechat = \Yii::$app->controller->wechatPay; // $res = $wechat->transfer->toBalance($data); $res = (new \app\utils\WechatMerchant\WxV3($wechat))->transferBatches(get_store_id(), $data); //判断是否使用新版本转账 增加转账标识 $wechat_cash = json_decode($wechat_cash, true); if (intval($wechat_cash['is_open']) === 2) { if (!$res['code']) { $cash->is_platform_transfers = intval($store->is_platform_transfers); $cash->wx_cash_type = Cash::WX_CASH_TYPE_NEW; $cash->wx_cash_state = $res['data']['state']; $cash->wx_cash_result_info = json_encode($res['data'], JSON_UNESCAPED_UNICODE); $cash->save(); } } //NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '微信自动打款', ($cash->price - $price)); } elseif ($status == Cash::STATUS_HAND) { //手动打款 $cash->status = Cash::STATUS_GIVEN; $cash->pay_time = time(); $cash->pay_type = Cash::PAY_TYPE_HAND; // if ($cash->type == Cash::TYPE_RECHARGE) { // $user = User::findOne(['id' => $cash->user_id]); // $user->money += doubleval($price); // if (!$user->save()) { // \Yii::$app->cache->set('cash_cache_' . $id, false); // foreach ($user->errors as $error) { // return $this->asJson([ // 'code' => 1, // 'msg' => $error // ]); // } // } // } $res['result_code'] = "SUCCESS"; //NoticeSend::CashSuccess($cash->user_id, $user->binding, $price, '手动打款', ($cash->price - $price)); } if (isset($res['result_code']) && $res['result_code'] == 'SUCCESS') { $cash->save(); return $this->asJson([ 'code' => 0, 'msg' => '成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => !empty($res['err_code_des']) ? $res['err_code_des'] : '请稍后重试', 'data' => $res ]); } } /** * 订单 * @return \yii\web\Response */ public function actionOrder() { $store_id = get_store_id(); $form = new ShareOrderForm(); $form->attributes = get_params(); $form->store_id = $store_id; $form->parent_id = get_params('parent_id') ? (int)get_params('parent_id') : false; $data = $form->search(); foreach ($data['data']['data'] as &$item) { $order_detail = OrderDetail::find()->where(['order_id' => $item['id']])->select('delivery_type')->one(); $item['delivery_type'] = $order_detail['delivery_type']; } $return = [ 'code' => $data['code'], 'msg' => $data['msg'], 'data' => $data['data'], 'parent' => [] ]; if (get_params('parent_id')) { $user = User::findOne(['store_id' => $store_id, 'id' => get_params('parent_id')]); $return['parent'] = $user; } return $this->asJson($return); } /** * 充值订单 * @return \yii\web\Response */ public function actionTopUpOrder() { $store_id = get_store_id(); $form = new RechargeForm(); $form->attributes = get_params(); $form->store_id = $store_id; $form->phone = get_params('phone'); $form->order_no = get_params('order_no'); $data = $form->search(); $return = [ 'code' => $data['code'], 'msg' => $data['msg'], 'data' => $data['data'], 'parent' => [] ]; return $this->asJson($return); } /** * @return string * 获取用户分销二维码 */ public function actionGetQrcode() { $form = new QrcodeForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); return $this->asJson($form->search()); } /** * @return string * 设置推广海报 */ public function actionQrcode() { $store_id = get_store_id(); //兼容联盟 $is_saas = post_params('is_saas',0); if($is_saas){ $store_id = -1; } $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_SHARE]); if (!$qrcode) { $qrcode = new Qrcode(); } $form = new QrcodeForm(); $form->attributes = post_params(); $form->store_id = $store_id; $form->qrcode = $qrcode; $form->type = Qrcode::TYPE_SHARE; return $this->asJson($form->save()); } /** * @return \yii\web\Response */ public function actionGetQrcodeSetting() { //兼容联盟 $is_saas = get_params('is_saas',0); if($is_saas){ $store_id = -1; }else{ $store_id = get_store_id(); } $qrcode = Qrcode::findOne(['store_id' => $store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_SHARE]); // \Yii::error($qrcode->font); $color = Color::find()->select('id, color')->andWhere(['is_delete' => 0])->asArray()->all(); $font_position = json_decode($qrcode->font_position, true); $qrcode_position = json_decode($qrcode->qrcode_position, true); $avatar_position = json_decode($qrcode->avatar_position, true); $avatar_size = json_decode($qrcode->avatar_size, true); $qrcode_size = json_decode($qrcode->qrcode_size, true); $font_size = json_decode($qrcode->font, true); $invite_position = json_decode($qrcode->invite_position, true); // \Yii::error($font_size); $first = Color::findOne(['color' => $font_size['color']]); $res = [ 'qrcode_bg' => $qrcode->qrcode_bg ?: \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/2_1.png', 'qrcode_pic' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/1.png', 'avatar' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png', 'qrcode' => $qrcode, 'color' => $color, 'first' => $first->id, 'font_c' => Json::decode($qrcode->font, true)['color'] ? Json::decode($qrcode->font, true)['color'] : ($first->color ?: "#000"), 'avatar_w' => $avatar_size['w'] ?: '63', 'avatar_x' => $avatar_position['x'] ?: '50', 'avatar_y' => $avatar_position['y'] ?: '160', 'qrcode_w' => $qrcode_size['w'] ?: '169', 'qrcode_c' => empty($qrcode_size['c']) ? 1 : (($qrcode_size['c'] == "true") ? 1 : 0), 'qrcode_x' => $qrcode_position['x'] ?: '65', 'qrcode_y' => $qrcode_position['y'] ?: '240', 'font_x' => $font_position['x'] ?: '124', 'font_y' => $font_position['y'] ?: '180', 'font_w' => $font_size['size'] ?: '20', 'invite_x' => $invite_position['x'] ?: '0', 'invite_y' => $invite_position['y'] ?: '0', ]; return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]); } /** * 提现明细列表 */ public function actionCashDetail() { $form = new CashListForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->getList()); } public function actionAddShare() { $user_id = post_params('user_id', 0); $mobile = post_params('mobile', ''); $name = post_params('name', ''); $store_id = get_store_id(); $user = User::findOne($user_id); if (!$user) { return $this->asJson([ 'code' => 1, 'msg' => '用户信息查询失败' ]); } $share = Share::findOne(['user_id' => $user_id, 'is_delete' => 0, 'status' => [0, 1]]); if ($user->is_distributor || $share) { return $this->asJson([ 'code' => 1, 'msg' => '用户已经是分销商或审核中' ]); } $share = new Share(); $share->user_id = $user_id; $share->mobile = $mobile; $share->name = $name; $share->is_delete = 0; $share->store_id = $store_id; $share->status = 1; $share->created_at = time(); if (!$share->save()) { return $this->asJson([ 'code' => 1, 'msg' => implode(';', array_values($share->firstErrors)) ]); } $user->time = time(); $user->is_distributor = 1; if (!$user->save()) { return $this->asJson([ 'code' => 1, 'msg' => implode(';', array_values($user->firstErrors)) ]); } return $this->asJson([ 'code' => 0, 'msg' => "添加分销商成功" ]); } public function actionShareChildList() { $form = new ShareOrderForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); return $this->asJson($form->shareChildList()); } }