$access_token]); if (!$saasUser) { \Yii::$app->response->format = Response::FORMAT_JSON; \Yii::$app->response->data = [ 'code' => 401, 'msg' => '登录失败' ]; return false; } if (!is_merchant()) { return true; } $admin = Admin::findOne(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type' => Admin::ADMIN_TYPE_STORE]); $store = Store::findOne(['id' => $admin->type_id, 'is_delete' => 0]); if (!$store) { \Yii::$app->response->format = Response::FORMAT_JSON; \Yii::$app->response->data = [ 'code' => 1, 'msg' => '用户未绑定商城' ]; return false; } $this->store_id = $store->id; return true; } /** * 联盟券获取金额信息 */ public function actionStoreMoney() { $store_id = $this->store_id; $store = Store::findOne($store_id); return $this->asJson([ 'code' => 0, 'msg' => '', 'data' => [ 'league_price' => $store->league_price, ] ]); } /** * 联盟券获取支付方式 */ /** * 联盟券提现 */ public function actionCashApply() { $price = post_params('cash'); $type = post_params('type'); $saas_user = get_saas_user(); if (!$price || !in_array($type, ['alipay', 'bank_card', 'wechat', 'wechat_auto'])) { return $this->asJson([ 'code' => 1, 'msg' => '参数非法', ]); } $store_id = $this->store_id; $store = Store::findOne($store_id); if ($price > $store->league_price) { return $this->asJson([ 'code' => 1, 'msg' => '提现金额不能大于联盟券余额', ]); } $t = \Yii::$app->db->beginTransaction(); try { $cash = new StoreCash(); $cash->order_no = OrderNo::getOrderNo(OrderNo::ORDER_CASH); $cash->is_delete = 0; $cash->status = 0; $cash->price = $price; $cash->created_at = time(); $cash->user_id = 0; $cash->store_id = $store->id; $cash->saas_id = $saas_user->id; $withdraw_method = json_decode($saas_user->withdraw_method, true); if ($withdraw_method) { $withdraw_method = array_column($withdraw_method, null, 'type'); if ($type == 'wechat') { $cash->type = 0; $cash->name = $withdraw_method['wechat']['name']; $cash->mobile = $withdraw_method['wechat']['account']; } if ($type == 'alipay') { $cash->type = 1; $cash->name = $withdraw_method['alipay']['name']; $cash->mobile = $withdraw_method['alipay']['account']; } if ($type == 'bank_card') { $cash->type = 2; $cash->name = $withdraw_method['bank_card']['name']; $cash->mobile = $withdraw_method['bank_card']['account']; $cash->bank_name = $withdraw_method['bank_card']['bank']; } } if ($type == 'wechat_auto') { $cash->type = 4; // 微信自动打款 } $cash->pay_time = 0; $cash->cash_type = StoreCash::CASH_TYPE_ALLIANCE_COUPON; if (!$cash->save()) { throw new \Exception('申请失败'); } $before = $store->league_price; $store->updateCounters(['league_price' => -floatval($price)]); \app\models\SaaSLeaguePriceLog::setLeaguePriceLog( $store->id, $cash->saas_id, $cash->price, $before, \app\models\SaaSLeaguePriceLog::TYPE_WITHDRAW, \app\models\SaaSLeaguePriceLog::TAKE_TYPE, \app\models\SaaSLeaguePriceLog::ROLE_STORE, $cash->id ); $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '申请成功', ]); } catch (\Exception $e) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '申请失败', ]); } } }