asJson($form->wastoreSessionGet(get_store_id(), $mini_id, $session_key)); } /** * 用户中心 * @return \yii\web\Response */ public function actionIndex() { $data = self::getDefaultIndexData(); $data = [ 'code' => 0, 'data' => $data, 'msg' => 'success' ]; $saasUser = get_saas_user(); $is_md_staff = 0; $is_md_manager = 0; $md_staff = null; $is_admin = 0; if ($saasUser) { $md_staff = MdStaff::findOne(['saas_user_id' => $saasUser['id'], 'is_delete' => 0, 'is_disable' => 0, 'store_id' => get_store_id()]); $is_admin = !empty($saasUser['id']) ? Admin::findOne(['saas_user_id' => $saasUser['id'], 'is_delete' => 0,'type'=>"admin"]) : ""; } if ($md_staff) { $is_md_staff = 1; $is_md_manager = $md_staff->is_manager; } if (is_platform()) { $user_data_info = [ 'access_token' => $saasUser['access_token'], 'avatar_url' => $saasUser['avatar'], 'binding' => $saasUser['mobile'], 'id' => $saasUser['id'], 'nickname' => $saasUser['name'], 'saas_money' => $saasUser['share_profit'], 'is_salesman' => $saasUser['is_salesman'], 'is_md_staff' => $is_md_staff, 'is_md_manager' => $is_md_manager, 'is_admin' => empty($is_admin) ? 0 : 1 ]; $data['data']['user_info'] = $user_data_info; } elseif (get_user()) { $user = User::find()->alias('u') ->leftJoin(['l' => Level::tableName()], 'u.level=l.level and l.is_delete = 0 and l.store_id='.get_store_id()) ->leftJoin(['p' => User::tableName()], 'u.old_parent_id=p.id') ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=p.binding') ->where(['u.id' => get_user_id(), 'u.store_id' => get_store_id()])->select('u.*, IFNULL(l.name, "普通用户") as `level_name`, IFNULL(su.name, "总店") as `parent`') ->asArray()->one(); //$admin = Admin::find()->where(['mobile' => $user['binding'], 'is_delete' => 0, 'type' => 'store'])->select('id, type_id')->one(); $is_admin = 0; if (\Yii::$app->prod_is_dandianpu() && get_user()->is_admin == 0) { $store = Store::findOne(get_store_id()); if ($store && $store->admin_id > 0) { $store_admin = Admin::findOne(['id' => $store->admin_id, 'is_delete' => 0]); if ($store_admin) { $admin_user = User::findOne(['binding' => $store_admin->mobile, 'store_id' => get_store_id(), 'is_delete' => 0]); if ($admin_user) { $is_admin = 1; $admin_user->is_admin = 1; $admin_user->save(); } } } } else { $is_admin = (get_user()->is_admin . ''); } $user_data_info = [ 'access_token' => $saasUser['access_token'], 'avatar_url' => get_user()['avatar_url'], 'binding' => $user['binding'], 'blacklist' => $user['blacklist'], 'id' => $user['id'], 'is_admin' => $is_admin, 'is_clerk' => $user['is_clerk'], 'is_saas_clerk' => (int)$user['is_saas_clerk'], 'is_delivery' => $user['is_delivery'], 'is_distributor' => $user['is_distributor'], 'is_live' => 0, 'is_real' => $user['is_real'], 'level' => $user['level'], 'level_name' => $user['level_name'], 'nickname' => get_user()['nickname'], 'parent' => $user['parent'], 'integral' => $user['integral'] ? $user['integral'] : 0, 'money' => $user['money'] ? $user['money'] : "0.00", 'price' => $user['price'] ? $user['price'] : '0.00', 'gender' => $user['gender'], 'saas_money' => SaasUser::findOne(['mobile' => $user['binding']])->share_profit, 'is_salesman' => $saasUser['is_salesman'], 'is_md_staff' => $is_md_staff, 'is_md_manager' => $is_md_manager, 'user_id' => get_user_id(), 'is_cashier' => $user['is_cashier'] == 1 && $user['cashier_status'] == 1 ? 1 : 0 ]; if (is_h5()) { $wechat_config = WechatConfig::findOne(['store_id' => get_store_id(), 'type' => WechatConfig::TYPE_CONFIG_MP]); $one_store_wechat_official_appid = Option::get('one_store_wechat_official_appid', 0, 'saas', '')['value']; if (!empty($wechat_config) || !empty($one_store_wechat_official_appid)) { // h5端,如果openid为空,返回授权链接 // Wechat::init(get_store_id(), Wechat::WECHAT_KIND_OFFICIAL, WechatConfig::TYPE_CONFIG_MP); // $baseUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl; // $store_id = get_store_id(); // $redirect_url = $baseUrl . '/index.php?r=client/v1/user/update-user-info&store_id='. $store_id .'&access_token=' . $saasUser['access_token']; // $user_data_info['oauth_redirect_url'] = Wechat::$wechat_official->oauth->scopes(['snsapi_userinfo'])->redirect($redirect_url); $user_data_info['oauth_redirect_url'] = LoginForm::getAuthLink(); } } if (\Yii::$app->prod_is_dandianpu()) { $user_data_info['is_show_toggle_store'] = 0; // 大于0表示显示切换,并且该值是store_id $user_data_info['has_store'] = 0; // 当前用户是否有商城 $admin = Admin::findOne(['saas_user_id' => $saasUser['id'], 'is_delete' => 0, 'type' => 'store']); if ($admin) { $store = Store::findOne(['id' => $admin->type_id, 'is_delete' => 0]); if ($store) { $user_data_info['has_store'] = $store->id; } $self_mini = intval(Option::get('self_mini', $store->id, 'store', 0)['value']); if ($store && $store->id != get_store_id() && !$self_mini) { $user_data_info['is_show_toggle_store'] = $store->id; } } } $share_holder = ShareHolder::findOne(['user_id' => get_user_id(), 'is_delete' => 0, 'store_id' => get_store_id(), 'status' => 1]); $user_data_info['is_holder'] = $share_holder ? 1 : 0; //抖品作者 $videoAuthor = VideoGoodsAuthor::findOne(['user_id' => get_user_id(), 'is_delete' => 0, 'store_id' => get_store_id(), 'status' => 1]); $user_data_info['is_video_author'] = $videoAuthor ? 1 : 0; $data['data']['user_info'] = $user_data_info; } /** * 获取用户优惠券数量 */ $coupon_num = UserCoupon::find()->where([ 'user_id' => get_user_id(), 'is_delete' => 0, 'is_use' => 0, 'is_expire' => 0, ])->count(); // 获取核销卡数量 $verify_num = VerifyCardSale::find()->where([ 'user_id' => get_user_id(), 'is_delete' => 0, ])->count(); /** * 获取用户可用卡券数量 */ $card_num = UserCard::find()->where([ 'user_id' => get_user_id(), 'store_id' => get_store_id(), 'is_use' => 0, 'is_delete' => 0, ])->count(); /** * 获取浏览记录数量(包含商品和店铺的总数) */ $browse_log_num = BrowseLog::find()->where([ 'user_id' => get_user_id(), 'store_id' => get_store_id(), 'is_delete' => 0, ])->count(); /** * 获取用户收藏商品数量 */ $favorite_goods_num = Favorite::find()->where([ 'store_id' => get_store_id(), 'user_id' => get_user_id(), 'is_delete' => 0, 'type' => Favorite::FAVORITE_GOODS ])->count(); if (isset($user) && isset($user['level'])) { $next_level = Level::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1]) ->andWhere(['>', 'level', $user['level']])->orderBy(['level' => SORT_ASC, 'id' => SORT_DESC])->asArray()->one(); } else { $next_level = 0; } $shareForm = new ShareForm(); $shareForm->store_id = get_store_id(); $share_setting = $shareForm->getShareSetting()['data']; $share_msg = $shareForm->getShareMsg(); //我的钱包 选项 $wallet['integral'] = 1; // $wallet['re'] = User$balance['recharge']; $wallet['re'] = UserCenterForm::get('recharge_custom_status', get_store_id(), 'recharge', 1); $order_count = OrderListForm::getCountData(get_store_id(), get_user_id()); // start 获取核销码 // TODO 这里要做支付宝小程序兼容 $code_url = ''; // TODO 影响速度,暂时注释 // if (get_user_id() > 0) { // if (is_wechat_platform() && !is_platform() && !is_h5()) { // 微信平台 // try { // $clerkCode = ShareQrcode::wxQrcode('user/clerk/clerk', "user_id:" . get_user_id() . ",store:" . get_store_id()); // if (isset($clerkCode['code']) && $clerkCode['code'] == 0) { // $code_url = $clerkCode['url_path']; // } // } catch (HttpException $e) { // } // } // } if (isset($data['data']['user_info'])) { $data['data']['user_info']['is_can_wechat'] = 0; if (strpos($data['data']['user_info']['nickname'], '****') !== false) { $data['data']['user_info']['is_can_wechat'] = 1; } } // $user_model = $user = get_user(); $saas_user_model = SaasUser::findOne(['mobile' => $user_model->binding]); if(!$saas_user_model->league_price){ $league_price = 0; }else{ $league_price = $saas_user_model->league_price; } $data['data']['user_info']['league_price'] = $league_price; //是否开启余额转佣金 $balance_to_commission = (int)Option::get('balance_to_commission', get_store_id(), 'recharge', 0)['value']; $recharge_wallet_status = (int)Option::get('recharge_wallet_status', get_store_id(), 'recharge', 0)['value']; $balancToCash = (int)Option::get(OptionSetting::BALANCE_TO_CASH, get_store_id(), 'recharge', 0)['value']; //调用自动升级判断一下 TeamGradesLevel::auto_upgrade(get_user()->id, get_store_id()); $is_team_grades = 0; $teamGrades = TeamGrades::getUserTeamGrades($user->id); if (!empty($teamGrades['id'])) { $is_team_grades = 1; } else { $teamGradesLevelList = TeamGradesLevel::getLevelList(get_store_id()); if (!empty($teamGradesLevelList)) { $is_open_apply = $teamGradesLevelList[0]['is_open_apply']; if ($is_open_apply) { $is_team_grades = 2; } } } $arr = [ 'code' => 0, 'msg' => 'success', 'data' => [ 'order_count' => $order_count, 'show_customer_service' => 1, 'contact_tel' => UserCenterForm::get('contact_tel', get_store_id(), 'store'), 'share_setting' => $share_setting, 'share_msg' => $share_msg, 'user_info' => isset($data['data']['user_info']) ? $data['data']['user_info'] : null, 'next_level' => $next_level, 'orders' => $data['data']['orders'], 'coupon_num' => $coupon_num, 'favorite_goods_num' => $favorite_goods_num, 'card_num' => $card_num, 'browse_log_num' => $browse_log_num, 'wallet' => $wallet, 'code_url' => $code_url, 'verify_num' => $verify_num, 'balanc_to_cash' => $balancToCash, 'balance_to_commission' => $balance_to_commission, 'recharge_wallet_status' => $recharge_wallet_status, 'is_team_grades' => $is_team_grades, ], ]; return $this->asJson($arr); } // 更新公众号用户信息 public function actionUpdateUserInfo() { $baseUrl = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl; $redirect_url = $baseUrl . '/h5/#/pages/my/my'; try { $code = get_params('code'); Wechat::init(get_store_id(), Wechat::WECHAT_KIND_OFFICIAL, WechatConfig::TYPE_CONFIG_MP); $result = Wechat::$wechat_official->oauth->userFromCode($code); $result = $result->toArray(); if (isset($result['raw']['openid'])) { $user = get_user(); $saas_user = get_saas_user(); if ($user) { $user->wechat_platform_open_id = $result['raw']['openid']; if (isset($result['raw']['unionid'])) { $user->wechat_union_id = $result['raw']['unionid']; } if (strpos($user->nickname, '******') !== false) { $user->nickname = $result['raw']['nickname']; } if (strpos($user->avatar_url, 'avatar.png') !== false) { $user->avatar_url = $result['raw']['headimgurl']; } $user->save(); } if ($saas_user) { if (strpos($saas_user->name, '******') !== false) { $saas_user->name = $result['raw']['nickname']; } if (strpos($saas_user->avatar, 'avatar.png') !== false) { $saas_user->avatar = $result['raw']['headimgurl']; } $saas_user->save(); } } return $this->redirect($redirect_url); } catch (\Exception $e) { return $this->redirect($redirect_url); } } /** * 获取用户信息 */ public function actionGetUserInfo() { $saasUser = get_saas_user(); //入驻商提现配置需要灵工提现设置 $lg = Lg::find()->where(['user_id'=>$saasUser->id,'status'=>1,'is_delete'=>0])->one(); if ($lg){ $withdraw_method = json_decode($saasUser->withdraw_method,true); if ($withdraw_method){ $lg_info['type'] ='lg'; $lg_info['name'] =$lg->name; $lg_info['account'] =$lg->mobile; array_push($withdraw_method,$lg_info); $saasUser->withdraw_method = json_encode($withdraw_method); } } $user = get_user(); return $this->asJson([ 'code' => 0, 'msg' => 'ok', 'data' => [ 'saasUser' => $saasUser, 'user' => $user, ], ]); } /** * 修改用户信息 */ public function actionEditUserInfo() { // 这里修改为用户商城的头像和昵称 $user = get_user(); if ($user) { $avatar_url = input_params('avatar_url', ''); $nickname = input_params('nickname', ''); $gender = input_params('gender', ''); $openid = input_params('openid', ''); if (!empty($avatar_url)) { $user->avatar_url = $avatar_url; } if (!empty($nickname)) { $user->nickname = $nickname; } if (!empty($gender) && in_array($gender, [0, 1, 2])) { $user->gender = $gender; } if ($user->save()) { return $this->asJson([ 'code' => 0, 'msg' => '保存成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => '保存失败', ]); } return $this->asJson([ 'code' => 1, 'msg' => '非法访问', ]); } /** * 更新用户wechat_app_open_id */ public function actionUpdateWechatAppOpenId() { $id = input_params('user_id'); $openid = input_params('open_id'); if (!$id || !$openid) { return $this->asJson([ 'code' => 1, 'msg' => '缺少参数', ]); } $user = User::findOne($id); if (!$user) { return $this->asJson([ 'code' => 1, 'msg' => '用户未找到', ]); } $user->wechat_app_open_id = $openid; $user->save(); return $this->asJson([ 'code' => 0, 'msg' => '更新成功', ]); } /** * 更新用户wechat_app_open_id */ public function actionUpdateWechatOpenId() { if (\Yii::$app->prod_is_dandianpu()) { $saas_user = get_saas_user(); $binding = $saas_user->mobile; // $wechat = \Yii::$app->controller->wechat; $wechat = WechatMini::getWechatConfig(get_store_id()); $code = post_params('code'); $session = $wechat->auth->session($code); if (!empty($session['openid']) && !empty($binding)) { User::updateAll(['wechat_open_id' => $session['openid']], ['binding' => $binding]); } } else { $user_id = get_user_id(); $user = User::findOne($user_id); $wechat = \Yii::$app->controller->wechat; $code = post_params('code'); $session = $wechat->auth->session($code); if (!empty($session['openid']) && !empty($user)) { $user->wechat_open_id = $session['openid']; if($session['unionid']){ $user->wechat_union_id = $session['unionid']; } $user->save(); } } } /** * Undocumented function * * @Author LGL 24963@qq.com * @DateTime 2021-02-04 * @desc: 绑定手机号 * @return string */ public function actionUserBinding() { $form = new UserForm(); $form->platform = $this->platform; $form->iv = post_params('iv'); $form->encryptedData = post_params('encryptedData'); $form->code = post_params('code'); return $this->asJson($form->WxBinding()); } // 授权手机号确认 public function actionUserEmpower() { $form = new UserForm(); $form->attributes = post_params(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); return $this->asJson($form->userEmpower()); } private static function getDefaultIndexData() { $form = new UserCenterForm(); $form->store_id = get_store_id(); $data = $form->getData(); return $data['data']; } /** * 获取收货地址 * @return \yii\web\Response */ public function actionAddressList() { $userId = get_params('user_id',0); if($userId){ $user = User::findOne($userId); $saasUserId = SaasUser::find()->where(['mobile' => $user->binding])->one()->id; } $query = Address::find()->where([ 'is_delete' => 0, 'user_id' => isset($saasUserId) && $saasUserId > 0 ? $saasUserId : get_saas_user_id(), ]); // if (is_platform()) { // $query->andWhere([ // 'user_id' => get_saas_user_id() // ]); // } else { // $query->andWhere([ // 'user_id' => get_user_id() // ]); // } $list = $query->orderBy('is_default DESC,addtime DESC')->select('id,name,mobile,province_id,province,city_id,city,district_id,village_id,town_id,district,detail,is_default,town,village')->asArray()->all(); foreach ($list as $i => $item) { $list[$i]['address'] = $item['province'] . $item['city'] . $item['district'] . $item['town'] . $item['village'] . $item['detail']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, ], ]); } /** * 保存收货地址 * @return \yii\web\Response */ public function actionAddressSave() { $form = new AddressSaveForm(); $form->attributes = post_params(); $userId = post_params('user_id',0); if($userId){ $user = User::findOne($userId); $saasUserId = SaasUser::find()->where(['mobile' => $user->binding])->one()->id; } $form->store_id = get_store_id(); // if (is_platform()) { $form->user_id = isset($saasUserId) && $saasUserId > 0 ? $saasUserId : get_saas_user_id(); // } else { // $form->user_id = get_user_id(); // } return $this->asJson($form->save()); } /** * 设为默认收货地址 * @return \yii\web\Response */ public function actionAddressSetDefault() { $form = new AddressSetDefaultForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); // if (is_platform()) { $form->user_id = get_saas_user_id(); // } else { // $form->user_id = get_user_id(); // } return $this->asJson($form->save()); } /** * 收货地址详情 * @return \Yii\web\Response */ public function actionAddressDetail() { $form = new AddressSetDefaultForm(); $userId = get_params('user_id',0); if($userId){ $user = User::findOne($userId); $saasUserId = SaasUser::find()->where(['mobile' => $user->binding])->one()->id; } $form->address_id = get_params('id'); $form->store_id = get_store_id(); // if (is_platform()) { $form->user_id = isset($saasUserId) && $saasUserId > 0 ? $saasUserId : get_saas_user_id(); // } else { // $form->user_id = get_user_id(); // } return $this->asJson($form->info()); } /** * 删除收货地址 * @return \yii\web\Response */ public function actionAddressDelete() { $form = new AddressSetDefaultForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); // if (is_platform()) { $form->user_id = get_saas_user_id(); // } else { // $form->user_id = get_user_id(); // } return $this->asJson($form->delete()); } /** * 添加商品或店铺或技师到我的喜欢 */ public function actionFavoriteAdd() { $form = new FavoriteAddForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 喜欢的商品或店铺列表 */ public function actionFavoriteList() { $form = new FavoriteListForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); return $this->asJson($form->search()); } /** * 取消喜欢的商品或店铺列表 */ public function actionRemoveFavorite() { $id = post_params('id'); if (empty($id)) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误' ]); } // if (!is_array($id)) { // $res = Favorite::updateAll(['is_delete' => 1], ['goods_id' => $id, 'user_id' => get_user_id(), 'type' => post_params('type', 0)]); // } else { // $res = Favorite::updateAll(['is_delete' => 1], ['and', ['in', 'goods_id', $id], ['user_id' => get_user_id(), 'type' => post_params('type', 0)]]); // } $res = Favorite::updateAll(['is_delete' => 1], ['id' => $id, 'user_id' => get_user_id(), 'type' => post_params('type', 0)]); if ($res) { return $this->asJson([ 'code' => 0, 'msg' => '删除成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => 'fail', 'err' => $res ]); } } /** * 收藏专题列表 */ public function actionTopicFavoriteList() { $form = new TopicFavoriteListForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } /** * 收藏|取消收藏专题 */ public function actionTopicFavorite() { $form = new TopicFavoriteForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 用户卡券 * @return \yii\web\Response */ public function actionCard() { $form = new CardListForm(); $form->store_id = $this->store_id; $form->user_id = get_user_id(); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * 卡券二维码 * @return \yii\web\Response */ public function actionCardQrcode() { $user_card_id = get_params('user_card_id'); $form = new QrcodeForm(); $form->page = "user/card-clerk/card-clerk"; $form->width = 100; $form->scene = "{$user_card_id}"; $form->store_id = $this->store_id; return $this->asJson($form->getQrcode()); } /** * 卡券核销 * @return \yii\web\Response */ public function actionCardClerk() { $user_card_id = get_params('user_card_id'); if (\Yii::$app->cache->get('card_id_' . $user_card_id)) { return $this->asJson([ 'code' => 1, 'msg' => '卡券核销中,请稍后重试' ]); } \Yii::$app->cache->set('card_id_' . $user_card_id, true); $user_card = UserCard::findOne(['id' => $user_card_id]); if ($user_card->is_use != 0) { \Yii::$app->cache->set('card_id_' . $user_card_id, false); return $this->asJson([ 'code' => 1, 'msg' => '卡券已核销' ]); } $user = get_user(); if ($user->is_clerk != 1) { \Yii::$app->cache->set('card_id_' . $user_card_id, false); return $this->asJson([ 'code' => 1, 'msg' => '不是核销员禁止核销' ]); } $user_card->clerk_id = $user->id; $user_card->shop_id = $user->shop_id; $user_card->clerk_time = time(); $user_card->is_use = 1; if ($user_card->save()) { \Yii::$app->cache->set('card_id_' . $user_card_id, false); return $this->asJson([ 'code' => 0, 'msg' => '核销成功' ]); } else { \Yii::$app->cache->set('card_id_' . $user_card_id, false); return $this->asJson([ 'code' => 1, 'msg' => '核销失败' ]); } } /** * 卡券详情 * @return \yii\web\Response */ public function actionCardDetail() { $form = new CardListForm(); $form->store_id = $this->store_id; $form->user_id = get_user_id(); $form->user_card_id = get_params('user_card_id'); return $this->asJson($form->detail()); } // 短信验证是否开启 public function actionSmsSetting() { $option = UserCenterForm::get('user_center_data', get_store_id(), 'store'); // $option = json_decode($option, true); $option['manual_mobile_auth'] = 1; if ($option['manual_mobile_auth'] == 1) { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => 1 ]); } else { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => 0 ]); } } // 会员权益 public function actionMember() { $_form = post_params('_form'); $level = is_null(get_user()->level) ? -1 : get_user()->level; $money = get_user()->money; $list = Level::find() ->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1]) ->orderBy('level asc')->asArray()->all(); foreach ($list as &$val) { $val['level'] = intval($val['level']); $val['synopsis'] = $val['synopsis'] == '[]' || !$val['synopsis'] ? [] : json_decode($val['synopsis'], true); $val['pages_css'] = json_decode($val['pages_css'],true); } $now_level = Level::find()->where(['store_id' => get_store_id(), 'level' => $level, 'is_delete' => 0])->asArray()->one(); if ($now_level && $now_level['synopsis']) { $synopsis = json_decode($now_level['synopsis'], true); $now_level['synopsis'] = $synopsis; } else { $now_level['synopsis'] = []; } $user_info = [ 'nickname' => get_saas_user()->name, 'avatar_url' => get_saas_user()->avatar, 'id' => get_user()->id, 'level' => $level, 'level_name' => !empty($now_level['name']) ? $now_level['name'] : "普通会员", 'user_level_expires' => get_user()->user_level_expires > 0 ? date('Y年m月d日 H:i:s', get_user()->user_level_expires) : '永久有效', 'growth_value' => get_user()->growth_value, ]; $time = time(); $after_sale_time = Option::get('after_sale_time', get_store_id(), 'store'); $sale_time = $time - ($after_sale_time['value'] * 86400); $next_level = Level::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1]) ->andWhere(['>', 'level', $level])->orderBy(['level' => SORT_ASC, 'id' => SORT_DESC])->asArray()->one(); $order_money = Order::find()->where(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'is_delete' => 0]) ->andWhere(['is_pay' => 1, 'trade_status' => Order::ORDER_FLOW_CONFIRM])->andWhere(['<=', 'confirm_time', $sale_time])->select([ 'sum(pay_price)' ])->scalar(); $percent = 100; $s_money = 0; $order_money = $order_money ? $order_money : 0; if ($next_level) { if ($next_level['money'] != 0) { $percent = round($order_money / $next_level['money'] * 100, 2); } $s_money = round($next_level['money'] - $order_money, 2); } $growthValue = UserGrowthValueLog::find()->where(['user_id' => get_user_id(),'from'=>UserGrowthValueLog::TYPE_BUY,'log_type'=>UserGrowthValueLog::LOG_TYPE_ADD])->sum('amount') ?? 0; $today_day = date('Y-m-d'); $today = Register::find()->where(['register_time' => $today_day, 'store_id' => get_store_id(), 'user_id' => get_user_id()])->asArray()->one(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'pay_type_list' => $this->getPayTypeList($_form), 'user_info' => $user_info, 'next_level' => $next_level, 'now_level' => $now_level, 'order_money' => $order_money, 'percent' => $percent, 's_money' => $s_money, 'money' => $money, 'list' => $list, 'growth_value' => $growthValue, 'is_sign' => $today ? 1 : 0 ], ]); } /** * 会员支付 */ public function actionSubmitMember() { $form = new OrderMemberForm(); $form->store_id = get_store_id(); $form->user = get_user(); $form->attributes = post_params(); return $this->asJson($form->save()); } /** * 支付 * @return \yii\web\Response */ public function actionMemberPayData() { $form = new LevelPayDataForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user = get_user(); return $this->asJson($form->search()); } // 获取支付方式TODO临时 protected function getPayTypeList($_form = '') { $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'pay', Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store', '{"wechat":{"text":"微信支付","value":1}}')['value']); $pay_type_list = Json::decode($pay_type_list_json['value']); if (!(is_array($pay_type_list) || $pay_type_list instanceof \ArrayObject)) { return []; } $new_list = []; foreach ($pay_type_list as $index => $value) { // if ($index == 'wechat' && $value['value'] == 1) { // $new_list[] = [ // 'name' => '微信支付', // 'payment' => 0, // ]; // } // // if ($index == 'alipay' && $value['value'] == 1) { // $new_list[] = [ // 'name' => '支付宝支付', // 'payment' => 4, // ]; // } if ((is_wechat_platform() || $_form === 'app' || $_form === 'h5') && $index == 'wechat' && $value['value'] == 1) { $new_list[] = [ 'name' => '微信支付', 'payment' => 1, // 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png' ]; } if ((is_wechat_platform()) && $index == Order::PAY_TYPE_KEY_WX_B2B && $value['value'] == 1) { $new_list[] = [ 'name' => Order::PAY_TYPE_NAME_WX_B2B, 'payment' => Order::PAY_TYPE_WX_B2B, 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png' ]; } if ((is_alipay_platform() || $_form === 'app') && $index == 'alipay' && $value['value'] == 1) { $new_list[] = [ 'name' => '支付宝支付', 'payment' => 4, // 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png' ]; } if ($index == 'balance' && $value['value'] == 1) { $balance = Option::get('recharge_wallet_status', get_store_id(), 'recharge'); if ($balance && $balance['value'] == 1) { $new_list[] = [ 'name' => '余额支付', 'payment' => 3, ]; } } } debug_log($new_list, 'pay_type.log'); return $new_list; } /** * 修改saas user信息 * @return \yii\web\Response */ public function actionSaasUserModify() { $form = new SaasUserForm(); $form->mobile = post_params('mobile'); $form->attributes = post_params(); return $this->asJson($form->modify()); } public function actionBalanceToCommission() { $price = (float)post_params('price'); if ($price <= 0) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $user = get_user(); $store_id = get_store_id(); if ($user->is_distributor != 1) { return $this->asJson([ 'code' => 1, 'msg' => '您还不是分销商,暂不能把余额转到佣金', ]); } if ($price > $user->money) { return $this->asJson([ 'code' => 1, 'msg' => '待转的余额不能大于已有余额', ]); } $transaction = \Yii::$app->db->beginTransaction(); try { $money = $user->money; $user->money -= $price; $user->price += $price; $user->total_price += $price; $user->save(); $log = new AccountLog(); $log->store_id = $store_id; $log->user_id = $user->id; $log->type = AccountLog::TYPE_BALANCE; $log->log_type = AccountLog::LOG_TYPE_EXPEND; $log->amount = $price; $log->desc = '余额转分销佣金'; $log->before = $money; $log->after = $user->money; $log->operator = ''; $log->operator_id = 0; $log->order_type = AccountLog::TYPE_BALANCE_TO_COMMISSION; $log->order_id = 0; $log->operator_type = AccountLog::TYPE_OPERATOR_NORMAL; $log->created_at = time(); $res = $log->save(); if ($res) { $transaction->commit(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } $transaction->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '操作失败!', ]); } catch (\Exception $e) { \Yii::error($e->getMessage()); $transaction->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => '操作失败!', ]); } } public function actionCodeToOpenid() { $code = post_params('code', ''); if (empty($code)) { return $this->asJson([ 'code' => 1, 'msg' => 'code为空' ]); } try { Wechat::init(get_store_id(), Wechat::WECHAT_KIND_OFFICIAL, WechatConfig::TYPE_CONFIG_MP); $result = Wechat::$wechat_official->oauth->userFromCode($code); if ($result && $result->getId()) { \Yii::error($result->getRaw()); $raw = $result->getRaw(); $user = get_user(); $user->wechat_platform_open_id = $result->getId(); if ($raw['unionid']) { $user->wechat_union_id = $raw['unionid']; } if (strpos($user->nickname, '******') !== false && $result->getNickname()) { $user->nickname = $result->getNickname(); } if (strpos($user->avatar_url, 'avatar.png') !== false && $raw['headimgurl']) { $user->avatar_url = $raw['headimgurl']; } if ($user->save()) { $saas_user = get_saas_user(); if (strpos($saas_user->name, '******') !== false) { $saas_user->name = $result->getNickname(); } if (strpos($saas_user->avatar, 'avatar.png') !== false) { $saas_user->avatar = $raw['headimgurl']; } $saas_user->save(); return $this->asJson([ 'code' => 0, 'msg' => '授权成功' ]); } } return $this->asJson([ 'code' => 1, 'msg' => '授权失败' ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //确定代理已经安装 public function actionAgentIsInstall() { $t = \Yii::$app->db->beginTransaction(); try { $order_detail_id = get_params('order_detail_id'); $order_detail = OrderDetail::findOne($order_detail_id); if (empty($order_detail)) { throw new \Exception("订单未找到"); } $agent_install_log = AgentGoodsInstallLog::findOne(['order_detail_id' => $order_detail_id, 'order_type' => AgentGoodsInstallLog::ORDER_TYPE_NORMAL]); if (!in_array($agent_install_log->status, [0, 1])) { throw new \Exception("已经操作完成,不可重复操作"); } $agent_install_log->status = 2; if (!$agent_install_log->save()) { throw new \Exception(json_encode($agent_install_log->errors)); } //判断是否全部确认收货 $install_all_log = AgentGoodsInstallLog::find()->where(['AND', ['order_id' => $agent_install_log->order_id, 'order_type' => AgentGoodsInstallLog::ORDER_TYPE_NORMAL]])->asArray()->all(); if ($install_all_log) { $count = OrderDetail::find()->where(['order_id' => $agent_install_log->order_id])->count(); if (count($install_all_log) >= $count) { $order = Order::findOne($agent_install_log->order_id); $order->trade_status = Order::ORDER_FLOW_CONFIRM; if (!$order->save()) { throw new \Exception("订单信息错误"); } } } //判断是否已过售后时间 $time = time(); $after_sale_time = Option::get(OptionSetting::STORE_AFTER_SALE_TIME, $this->store_id)['value']; $sale_time = $time - ($after_sale_time * 86400); $order = Order::find()->alias('o') ->where([ 'and', ['o.store_id' => get_store_id()], ['o.is_delete' => 0, 'o.trade_status' => Order::ORDER_FLOW_CONFIRM], ['<=', 'o.confirm_time', $sale_time], ['o.id' => $order_detail->order_id], ])->andWhere(['<>', 'trade_status', Order::ORDER_FLOW_CANCEL]) ->leftJoin(OrderRefund::tableName() . ' r', "r.order_id = o.id and r.is_delete = 0") ->select(['o.*'])->groupBy('o.id') ->andWhere([ 'or', 'isnull(r.id)', ['r.type' => 2], ['in', 'r.status', [2, 3]], ])->asArray()->one(); if (!empty($order) && (int)$order['is_sale'] === 1) { $goods = Goods::findOne($order_detail->goods_id); if (!(!empty($goods) && $goods->cloud_goods_id)) { throw new \Exception('非云仓商品,不可操作'); } $agent_goods_bind_goods = AgentGoodsBindGoods::findOne(['cloud_goods_id' => $goods->cloud_goods_id]); if (empty($agent_goods_bind_goods)) { throw new \Exception('未绑定产品代理,不可操作'); } $option = Option::get('goods_agent_price_config', 0, 'saas', [])['value']; $option = json_decode($option, true); $goods_agent_install_percent = $option['goods_agent_install_percent'] ?? 0; $supplier = Supplier::findOne(['cloud_supplier_id' => $agent_goods_bind_goods->cloud_supplier_id]); if (empty($supplier)) { throw new \Exception('供货商查询失败,不可操作'); } $supplier_rate = $supplier->rate; //计算上门安装佣金 $admin = Admin::findOne($agent_install_log->goods_agent_admin_id); if (!empty($admin)) { $agent_rebate = $order_detail->total_price * ($supplier_rate / 100) * ($goods_agent_install_percent / 100); //给用户增加佣金 $SaasUser = SaasUser::findOne($admin->saas_user_id); $SaasUser->share_profit = ($SaasUser->share_profit * 1) + ($agent_rebate * 1); if (!$SaasUser->save()) { throw new \Exception(json_encode($SaasUser->errors)); } $StoreShareMoney = new StoreShareMoney(); $StoreShareMoney->user_id = $SaasUser->id; $StoreShareMoney->store_id = $order['store_id']; $StoreShareMoney->profit = $goods_agent_install_percent; $StoreShareMoney->total_price = $order_detail->total_price; $StoreShareMoney->desc = '产品代理上门安装佣金发放,安装商品' . $order_detail->goods_name; $StoreShareMoney->order_id = $order['id']; $StoreShareMoney->created_at = time(); $StoreShareMoney->status = StoreShareMoney::STATUS_STORE_ORDER; $StoreShareMoney->type = StoreShareMoney::TYPE_GOODS_AGENT; $StoreShareMoney->commission = $agent_rebate; $StoreShareMoney->is_send = 1; if (!$StoreShareMoney->save()) { throw new \Exception(json_encode($StoreShareMoney->errors)); } } } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功' ]); } catch (\Exception $e) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } public function actionCommissionToBalance() { $transaction = \Yii::$app->db->beginTransaction(); try { $price = post_params('price'); if (empty($price)) { return $this->asJson([ 'code' => 1, 'msg' => '缺少必要参数', ]); } if ($price <= 0) { return $this->asJson([ 'code' => 1, 'msg' => '佣金数量数据错误', ]); } $user = get_user(); $store_id = get_store_id(); if ($user->is_distributor != 1) { return $this->asJson([ 'code' => 1, 'msg' => '您还不是分销商,暂不能把佣金转到余额', ]); } if ($price > $user->price) { return $this->asJson([ 'code' => 1, 'msg' => '待转的佣金不能大于已有佣金数额', ]); } $money = $user->money; // $user->money += $price; //计算手续费 $profit = Option::get('commission_to_balance', get_store_id(), 'recharge', 0)['value']; if ($profit) { $profit = $price * ($profit / 100); } $user->price -= $price; $user->save(); if ($profit) { $price = sprintf("%.2f", ($price - $profit)); } AccountLog::saveLog($user->id, $price, 2, 1, 0, 0, '分销佣金转余额,手续费:' . $profit . '元', 3, $user->id, $profit); $transaction->commit(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } catch (\Exception $e) { $transaction->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //积分 / 余额转赠 public function actionGiveAssets() { $t = \Yii::$app->db->beginTransaction(); try { $user = get_user(); $saas_user = get_saas_user(); $give_user_id = post_params('give_user_id'); $money = post_params('money', 0); $type = post_params('type', 2); // 2 余额 1 积分 if (!in_array($type, [1, 2])) { throw new \Exception('参数类型错误'); } $give_user = User::find()->alias('u') ->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile') ->where(['u.id' => $give_user_id, 'u.is_delete' => 0]) ->select('u.id, su.name')->asArray()->one(); if (!$give_user) { throw new \Exception('用户查找失败'); } if ((int)$type === 2) { //计算手续费 $profit = Option::get('give_balance_profit', get_store_id(), 'recharge', 0)['value']; if ($user->money < $money) { throw new \Exception('可转赠余额不足'); } } else { //计算手续费 $profit = Option::get('give_integral_profit', get_store_id(), 'recharge', 0)['value']; if ($user->integral < $money) { throw new \Exception('可转赠积分数量不足'); } } if ($money > 0) { $profit = (float)sprintf("%.2f", $money * (($profit ?: 0) / 100)); AccountLog::saveLog($user->id, $money, $type, 2, 0, 0, '转赠给用户' . $give_user['name'] . ',手续费' . $profit, 1, $give_user['id'], $profit); $money = (float)sprintf("%.2f", ($money - $profit)); AccountLog::saveLog($give_user['id'], $money, $type, 1, 0, 0, '用户' . $saas_user->name . '转赠', 2, $user->id, $profit); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功' ]); } catch (\Exception $e) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() . $e->getLine() ]); } } //查询用户 public function actionSearchUser() { try { $mobile = get_params('mobile'); if ($mobile) { $give_user = User::find()->alias('u') ->leftJoin(['su' => SaasUser::tableName()], 'u.binding = su.mobile') ->where(['u.is_delete' => 0, 'u.store_id' => get_store_id()]) ->andWhere(['OR', ['u.id' => $mobile], ['u.binding' => $mobile]]) ->select('u.id, su.name, su.avatar')->asArray()->one(); if (empty($give_user)) { $give_user = null; } if ((int)$give_user['id'] === (int)get_user_id()) { $give_user = null; } } else { $give_user = null; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $give_user ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //获取佣金 余额 积分 转赠记录 public function actionGetAccountLog() { try { $type = (int)get_params('type', 0); $log_type = get_params('log_type'); $page = get_params('page', 1); $limit = get_params('limit', 10); $user_id = get_user_id(); $store_id = get_store_id(); switch ($type) { case 1: //积分 且 赠送 $type = 2; $from = [1, 2]; break; case 2://余额 且 佣金转 $type = 2; $from = 3; break; default: //余额 且 赠送 $type = 1; $from = [1, 2]; break; } $query = AccountLog::find()->where([ 'store_id' => $store_id, 'user_id' => $user_id, 'type' => $type, // 余额 'from' =>$from ]); if (in_array($log_type, [1, 2])) { $query->andWhere(['log_type' => $log_type]); } $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'page' => $page - 1, 'pageSize' => $limit]); $list = $query->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all(); foreach ($list as $key => &$value) { $value['date'] = date('Y-m-d H:i:s', $value['created_at']); $value['content'] = $value['desc']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $list, 'page_count' => $pagination->getPageCount(), 'row_count' => $count,//总数 ] ]); }catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //获取手续费 public function actionGetProfit() { //计算手续费 $commission_to_balance = Option::get('commission_to_balance', get_store_id(), 'recharge', 0)['value']; //计算手续费 $give_balance_profit = Option::get('give_balance_profit', get_store_id(), 'recharge', 20)['value']; //计算手续费 $give_integral_profit = Option::get('give_integral_profit', get_store_id(), 'recharge', 25)['value']; return $this->asJson([ 'code' => '0', 'msg' => '获取成功', 'data' => [ "commission_to_balance" => $commission_to_balance, "give_balance_profit" => $give_balance_profit, "give_integral_profit" => $give_integral_profit ] ]); } /** * 修改手机号 */ public function actionUpdateMobile() { $t = \Yii::$app->db->beginTransaction(); try { $store_id = get_store_id(); $mobile = \input_params('mobile'); $code = \input_params('code'); if (!$mobile || !$code) { throw new \Exception('参数错误'); } $form = new LoginForm(); $form->store_id = $store_id; $form->phone = $mobile; $form->verify_code = $code; $verifySmsCode = $form->verifySmsCode(LoginForm::CACHE_KEY_BIND_PHONE); if ($verifySmsCode['code'] != 0) { throw new \Exception($verifySmsCode['msg']); } $is = User::findOne(['binding' => $mobile, 'is_delete' => 0]); if ($is) { throw new \Exception('该手机号已被绑定'); } $currentUser = get_user(); $users = User::find()->where(['binding' => $currentUser->binding, 'is_delete' => 0])->all(); foreach ($users as $user) { $user->binding = $mobile; $user->save(); } $saasUser = SaasUser::findOne(['mobile' => $currentUser->binding, 'is_delete' => 0]); if ($saasUser) { $saasUser->mobile = $mobile; $saasUser->save(); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '修改成功', ]); } catch (\Exception $e) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } /** * 模块名:actionUpdateRemarkName * 代码描述:修改用户备注 * 作者:WPing丶 * 请求方式:GET * 创建时间:2024/03/14 10:07:25 * @param int id 用户ID * @param string remark_name 备注名 */ public function actionUpdateRemarkName() { $id = get_params('id', 0); $remark_name = get_params('remark_name', 0); $user_id = get_user_id(); $store_id = get_store_id(); $user_info = User::findOne(['id'=>$id, 'store_id' => $store_id]); if(!$user_info) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在' ]); } if($user_info->old_parent_id != $user_id) { return $this->asJson([ 'code' => 1, 'msg' => '您不是此用户的推荐人,无法修改备注' ]); } $user_info->remark_name = $remark_name; if(!$user_info->save()) { return $this->asJson([ 'code' => 1, 'msg' => '保存User表失败' ]); } else { return $this->asJson([ 'code' => 0, 'msg' => '修改成功', ]); } } /** * 模块名:actionCheckStudent * 代码描述:快速获取学生身份API * 作者:WPing丶 * 请求方式:GET * 创建时间:2024/03/18 11:14:42 * @param string wx_studentcheck_code 用户授权查询code */ public function actionCheckStudent() { $wx_studentcheck_code = get_params('wx_studentcheck_code', 0); $user_id = get_user_id(); $store_id = get_store_id(); $user_info = User::findOne(['id' => $user_id, 'store_id' => $store_id]); if(!$user_info) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在', ]); } $app = (new WechatMini())::getWechatConfig($store_id); if (!$app) { throw new \Exception('获取小程序信息失败'); } $client = new BaseClient($app); $params_ = [ 'openid' => $user_info->wechat_open_id, 'wx_studentcheck_code' => $wx_studentcheck_code, ]; $result = $client->httpPostJson('intp/quickcheckstudentidentity',$params_); if($result['is_student']) { //判断是否设置学生会员 $student_level = Level::findOne(['is_student' => 1, 'status' => 1, 'is_delete' => 0]); if($student_level && $student_level->level > $user_info->level) { $user_info->level = $student_level->level; } $user_info->is_student = 1; if(!$user_info->save()) { return $this->asJson([ 'code' => 1, 'msg' => '保存用户信息失败', 'data' => [ 'store_id' => $store_id, 'user_id' => $user_id, 'user_info' => $user_info, 'error_msg' => $user_info->getErrors(), ] ]); } } $result['code'] = $result['errcode'] == 0 ? 0 : 1; $result['msg'] = $result['errmsg']; return $this->asJson($result); } /** * 根据用户手机号生成条形码以及二维码获取手机号 */ public function actionGetUserMobileQrcode() { $user = get_user(); $mobile = $user->binding; $file_name = md5($mobile . '_' . get_store_id() . '_user_mobile_qrcode'). '.jpg'; // 保存小程序码到文件 $dir = \Yii::$app->runtimePath . '/image/wx_qrcode'; if (! is_dir($dir)) { mkdir($dir, 0777, true); } $url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/wx_qrcode/' . $file_name); QrCode::image($mobile, 600, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $dir. '/' .$file_name ); $generator = new BarcodeGeneratorJPG(); $barcode = $generator->getBarcode($mobile, $generator::TYPE_CODE_128, 2, 30); $file_name = md5($mobile . '_' . get_store_id() . '_user_mobile_barcode'). '.jpg'; $code_path = \Yii::$app->runtimePath . '/image/' . $file_name; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $file_name); file_put_contents($code_path, $barcode); return $this->asJson([ 'code' => 0, 'msg' => '', 'data' => [ 'user_qrcode' => $url, 'user_barcode' => $pic_url, 'mobile' => $mobile ] ]); } public function actionUserAuditSetting() { $userAuditSetting = UserAuditSetting::findOne(['store_id' => get_store_id()]); return $this->asJson([ 'code' => 0, 'data' => $userAuditSetting, ]); } public function actionWxCode2session() { $code = input_params('code'); [$wechat_open_id, $ali_user_id, $ali_open_id, $session_key] = (new UserForm())->getOpenId($code); return $this->asJson([ 'code' => 0, 'data' => [ 'session_key' => $session_key, ], 'res' => [$wechat_open_id, $ali_user_id, $ali_open_id, $session_key], ]); } /** * 获取申请信息 */ public function actionUserAudit() { try { $user = get_user();//获取当前用户信息 $saasUser = get_saas_user(); $store_id = get_store_id();//获取商城id $avatar = post_params('avatar');//获取头像信息 $custom_form = post_params('custom_form');//获取自定义表单信息 $mobile = post_params('mobile'); $userAuditSetting = UserAuditSetting::findOne(['store_id' => $store_id]);//获取当前商城用户审核的设置 $session_key = post_params('session_key', ''); $wechat_open_id = post_params('wechat_open_id', ''); $ali_user_id = post_params('ali_user_id', ''); $ali_open_id = post_params('ali_open_id', ''); $code = get_params('code'); if (!$user) { //用户未登陆时 获取openid来分辨用户 [$wechat_open_id, $ali_user_id, $ali_open_id, $session_key] = (new UserForm())->getOpenId($code, [ 'wechat_open_id' => $wechat_open_id, 'ali_user_id' => $ali_user_id, 'ali_open_id' => $ali_open_id, ]); } if (!empty($wechat_open_id)) { $user = User::findOne(['store_id' => $store_id, 'wechat_open_id' => $wechat_open_id, 'is_delete' => 0]); if ($user && $user->binding) { $saasUser = SaasUser::findOne(['is_delete' => 0, 'mobile' => $user->binding]); } } if (!empty($ali_user_id)) { $user = User::findOne(['store_id' => $store_id, 'alipay_open_id' => $ali_user_id, 'is_delete' => 0]); if ($user) { if ($user->binding) { $saasUser = SaasUser::findOne(['is_delete' => 0, 'mobile' => $user->binding]); } else { $saasUser = SaasUser::findOne(['is_delete' => 0, 'ali_user_id' => $ali_user_id]); } } } if (!empty($ali_open_id)) { $user = User::findOne(['store_id' => $store_id, 'ali_openId' => $ali_open_id, 'is_delete' => 0]); if ($user) { if ($user->binding) { $saasUser = SaasUser::findOne(['is_delete' => 0, 'mobile' => $user->binding]); } else { $saasUser = SaasUser::findOne(['is_delete' => 0, 'ali_openId' => $ali_open_id]); } } } if ($user) { $userAuditLog = UserAuditLog::findOne(['user_id' => $user->id, 'is_delete' => 0]);//获取当前用户审核记录 } else { $userAuditLog = UserAuditLog::find()->where(['store_id' => $store_id, 'is_delete' => 0]); if ($wechat_open_id || $ali_user_id || $ali_open_id) { if ($wechat_open_id) { $userAuditLog->andWhere(['wechat_open_id' => $wechat_open_id]); } if ($ali_user_id) { $userAuditLog->andWhere(['ali_user_id' => $ali_user_id]); } if ($ali_open_id) { $userAuditLog->andWhere(['ali_openId' => $ali_open_id]); } $userAuditLog = $userAuditLog->one(); } else { $userAuditLog = null; } } if (\Yii::$app->request->isGet) {//判断是否是get请求 $custom_form_str = $userAuditSetting->custom_form; $custom_form = []; if ($custom_form_str) { $custom_form = json_decode($custom_form_str, true); } if ($userAuditLog) { $data = [ 'id' => $userAuditLog->id, 'avatar' => $userAuditLog->avatar ?: $saasUser->avatar, 'status' => intval($userAuditLog->status), 'pass_remark' => $userAuditLog->pass_remark, 'mobile' => $userAuditLog->mobile ?: '' ]; if ($userAuditLog->status == UserAuditLog::STATUS_AGREE) { $data['token'] = $saasUser->access_token; $data['session_key'] = $session_key ?: ''; } } else { $data = [ 'id' => 0, 'avatar' => $saasUser->avatar, 'status' => UserAuditLog::STATUS_NOT_AUDIT, 'pass_remark' => '', 'token' => null, 'mobile' => $saasUser->mobile ?: '' ]; } $user_custom_form = []; if (!empty($userAuditLog->custom_form)) { $user_custom_form_str = $userAuditLog->custom_form; if ($user_custom_form_str) { $user_custom_form = json_decode($user_custom_form_str, true); } } $data = array_merge($data, [ 'custom_form' => $user_custom_form ?: $custom_form, 'bg_image' => $userAuditSetting->bg_image ?: '', 'protocol' => $userAuditSetting->protocol, 'form_name' => $userAuditSetting->form_name, 'open_params' => [ 'wechat_open_id' => $wechat_open_id, 'ali_user_id' => $ali_user_id, 'ali_open_id' => $ali_open_id, ] ]); if (!empty($data['custom_form'])) { foreach ($data['custom_form'] as &$custom_item) { if (in_array($custom_item['type'], ['radio', 'checkbox']) && !empty($custom_item['default'])) { $custom_item['default_list'] = explode(',', $custom_item['default']); $list = explode(',', $custom_item['default']); $list_arr = []; foreach ($list as $list_index => &$list_item) { $arr = []; $arr['name'] = $list_item; $arr['checked'] = true; if ($list_index) { $arr['checked'] = false; } array_push($list_arr, $arr); } $custom_item['default_list'] = $list_arr; } $custom_item['default'] = $custom_item['default'] ?: ''; } } return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $data ]); } else { if (empty($userAuditSetting)) {//判断当前商城用户审核的设置是否存在 throw new \Exception('系统未配置 无需提交审核'); } if (intval($userAuditSetting->status) === 0) {//判断当前商城用户审核的设置是否开启 throw new \Exception('系统未配置 无需提交审核'); } //判断当前用户审核记录是否存在或已提交/已通过审核 禁止重复提交 if (!empty($userAuditLog) && in_array(intval($userAuditLog->status), [UserAuditLog::STATUS_NOT_AGREE, UserAuditLog::STATUS_AGREE])) { throw new \Exception('已经提交审核或已通过 请勿重复提交'); } //为空就新增数据库model if (empty($userAuditLog)) { $userAuditLog = new UserAuditLog(); $userAuditLog->store_id = $store_id; $userAuditLog->user_id = $user->id; } if (is_wechat_platform()) { $userAuditLog->type = UserAuditLog::TYPE_WX; } if (is_alipay_platform()) { $userAuditLog->type = UserAuditLog::TYPE_ALI; } if (is_app_platform()) { $userAuditLog->type = UserAuditLog::TYPE_APP; } if (is_h5()) { $userAuditLog->type = UserAuditLog::TYPE_H5; } if (!empty($wechat_open_id)) { $userAuditLog->wechat_open_id = $wechat_open_id; } if (!empty($ali_user_id)) { $userAuditLog->ali_user_id = $ali_user_id; } if (!empty($ali_open_id)) { $userAuditLog->ali_openId = $ali_open_id; } $userAuditLog->mobile = $mobile; $userAuditLog->avatar = $avatar; $userAuditLog->custom_form = json_encode($custom_form, JSON_UNESCAPED_UNICODE); $userAuditLog->status = UserAuditLog::STATUS_NOT_AGREE; if (!$userAuditLog->save()) { return $this->asJson([ 'code' => 1, 'msg' => '保存失败' . json_encode($userAuditLog->errors, JSON_UNESCAPED_UNICODE) ]); } return $this->asJson([ 'code' => 0, 'msg' => '提交成功' ]); } } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //月付客户订单记录 public function actionMoneyMonthLog() { $store_id = get_store_id(); $user_id = get_user_id(); $month = input_params('month'); if(empty($month)){ $month = date('Y-m'); } $begin_time = strtotime($month . '-01 00:00:00'); $end_time = strtotime(date('Y-m-01', $begin_time + 86400 * 31)) - 1; $query = UserPayMonth::find()->where(['store_id' => $store_id, 'user_id' => $user_id]); $query->andWhere(['>=', 'created_at', $begin_time]); $query->andWhere(['<=', 'created_at', $end_time]); $querySum = (clone $query)->andWhere(['type' => 0]); $sumMoney = (float)$querySum->sum('money'); $query->orderBy('id DESC'); $data = pagination_make($query); foreach($data['list'] as &$item){ $item['day'] = date('n月d日', $item['created_at']); } return $this->asJson([ 'q' => $query->createCommand()->getRawSql(), 'code' => 0, 'msg' => 'ok', 'data' => $data, 'sumMoney' => $sumMoney, 'user_info' => get_user(), ]); } //月付客户历史订单汇总 public function actionMoneyMonthSum() { $store_id = get_store_id(); $user_id = get_user_id(); $begin_time = date('Y-m-01 00:00:00', time() - 86400 * 365); $query = UserPayMonth::find()->where(['store_id' => $store_id, 'user_id' => $user_id, 'type' => 0]); $query->andWhere(['>=', 'created_at', strtotime($begin_time)]); $query->groupBy(['pay_year', 'pay_month']); $query->orderBy('pay_year DESC'); $query->addOrderBy(['CONVERT(pay_month, UNSIGNED)' => SORT_DESC]); $query->select(['sum(money) AS sum_money', 'FROM_UNIXTIME(created_at,"%Y") AS pay_year', 'FROM_UNIXTIME(created_at,"%c") AS pay_month']); $data = $query->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'ok', 'data' => $data, 'user_info' => get_user(), ]); } /** * 免单队列 * @return void */ public function actionFreeQueue() { $status = get_params('status',0); $user_info = User::find()->where(['id' => get_user_id()])->asArray()->one(); //参与免单人数 $queue_peopel_num = QueueLog::find()->where(['store_id' => get_store_id()])->andWhere(['!=', 'status', 2])->groupBy('user_id')->count() ?? 0; //最新免单返现信息 $queue_account_new = QueueAccountLog::find()->andWhere(['type' =>0, 'store_id'=>get_store_id()])->orderBy('created_at desc')->asArray()->one(); if ($queue_account_new) { //根据最近返现时间 $timestamp = $queue_account_new['created_at']; // 示例时间戳 $now = new \DateTime("now"); $ago = $now->getTimestamp() - $timestamp; $days = intval($ago / (3600 * 24)); $hours = intval(($ago % (3600 * 24)) / 3600); $minutes = intval(($ago % 3600) / 60); $result = ""; if ($days > 0) { $result .= $days . "天 "; } if ($hours > 0) { $result .= $hours . "小时 "; } $result .= $minutes . "分钟"; $queue_account_new['current_time'] = $result;//获取距离时间 $new_user_info = User::find()->where(['id' => $queue_account_new['user_id']])->asArray()->one(); $queue_account_new['nickname'] = mb_substr($new_user_info['nickname'],0,1) .'***'; $queue_account_new['avatar_url'] = $new_user_info['avatar_url']; }else{ $queue_account_new = []; } //已返免单金额 $free_money = $user_info['free_money']??0; //累计免单金额 $total_free_money = $user_info['total_free_money']??0; //队列列表 $query = QueueLog::find() ->alias('q') ->leftJoin(['o'=> Order::tableName()],'q.order_id = o.id') ->leftJoin(['g'=> Goods::tableName()],'g.id = q.goods_id') ->leftJoin(['u'=> User::tableName()],'u.id = q.user_id') ->where(['q.store_id' => get_store_id()]) ->andWhere(['!=','q.status',2]) ->andWhere(['q.user_id' => get_user_id()]) ->orderBy('q.sort desc'); if ($status == 0) { // //排队中,等待发放 $query->andWhere(['q.status' => 0]); } if($status== 1){ //免单中,正在返现 $query->andWhere(['q.status' => 3]); } if($status == 2){ //已完成 $query->andWhere(['q.status' => 1]); } $query->select('q.*,o.order_no,o.is_sale,g.cover_pic,g.name as goods_name,u.nickname,g.attr'); $pagination = pagination_make($query); foreach ($pagination['list'] as $key => $value){ $pagination['list'][$key]['activity'] = \app\models\FreeQueue::findOne($value['queue_id']); $attr_info = ''; foreach (Json::decode($value['attr']) as $k=>$v){ $attr_info.=$v['attr_group_name'] ?? '规格'.':'.$v['attr_list'][0]['attr_name'].' '; } $pagination['list'][$key]['attr_info'] = $attr_info; $pagination['list'][$key]['goods_price'] =$value['goods_price'] * $value['num']; $count = OrderUtil::getQueueSort($value['queue_id'], $value['id'], true); $pagination['list'][$key]['total_count'] = $count['total_count']; $pagination['list'][$key]['current_sort'] = $count['current_sort']; $pagination['list'][$key]['created_at'] = $value['created_at']?date('Y-m-d H:i:s',$value['created_at']):''; $pagination['list'][$key]['updated_at'] = $value['updated_at']?date('Y-m-d H:i:s',$value['updated_at']):''; } return $this->asJson([ 'code' => 0, 'msg' => '修改成功', 'data'=>[ 'queue_account'=>$queue_account_new, 'queue_peopel_num'=>$queue_peopel_num,//参与免单人数 'free_money'=>$free_money,//免单金额 'total_free_money'=>$total_free_money,//累计免单金额 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]); } /** * 免单返现明细 * @return \yii\web\Response */ public function actionQueueAccountLog() { $status = get_params('status',-1); //队列列表 $query = QueueAccountLog::find() ->where(['store_id' => get_store_id()]) ->andWhere(['user_id'=>get_user_id()]) ->orderBy('created_at desc'); if($status == 1){ //已收入 $query->andWhere(['type' => 0]); } if($status== 2){ //已支出 $query->andWhere(['type' => 1]); } $pagination = pagination_make($query); if (count($pagination['list']) > 0){ foreach ($pagination['list'] as $key => $value){ //查询订单号 if ($value['type'] == 0){ $pagination['list'][$key]['order_no'] = Order::find()->where(['id' => $value['order_id']])->one()['order_no']; } if ($value['type'] == 1){ $pagination['list'][$key]['order_no'] = Cash::find()->where(['id' => $value['order_id']])->one()['order_no']; } $pagination['list'][$key]['created_at'] = $value['created_at']?date('Y-m-d H:i:s',$value['created_at']):''; } } return $this->asJson([ 'code' => 0, 'msg' => '修改成功', 'data'=>[ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]); } public function actionQueueToIntegral() { $store_id = get_store_id(); $queue_id = \post_params('queue_log_id'); if (!$queue_id) { return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $integral_bili = \app\models\Option::get('integral', $store_id, 'store', 0)['value']; if ($integral_bili == 0) { return $this->asJson([ 'code' => 1, 'msg' => '暂未设置兑换比例', ]); } $queue_log = QueueLog::find()->where(['id' => $queue_id])->one(); if ($queue_log->is_meet == 1) { return $this->asJson([ 'code' => 1, 'msg' => '该队列已返现', ]); } if ($queue_log->status == 2) { return $this->asJson([ 'code' => 1, 'msg' => '该队列已取消', ]); } if ($queue_log->status == 1) { return $this->asJson([ 'code' => 1, 'msg' => '该队列已完成', ]); } // if ($queue_log->status == 3) { // return $this->asJson([ // 'code' => 1, // 'msg' => '该队列已经在进行中了,无法兑换', // ]); // } $user = User::findOne($queue_log->user_id); if (!$user) { return $this->asJson([ 'code' => 1, 'msg' => '用户不存在', ]); } $total_money = $queue_log->total_money - $queue_log->returned_money; $integral = \round($total_money * $integral_bili, 2); $before = $user->integral; $user->integral += $integral; $user->total_integral += $integral; $user->save(); $queue_log->is_meet = 1; $queue_log->status = 1; $queue_log->integral = $integral; $queue_log->save(); $log = new AccountLog(); $log->store_id = $store_id; $log->user_id = $queue_log->user_id; $log->type = AccountLog::TYPE_INTEGRAL; $log->log_type = AccountLog::LOG_TYPE_INCOME; $log->amount = $integral; $log->desc = '免单队列转积分'; $log->before = $before; $log->after = $user->integral; $log->operator = ''; $log->operator_id = 0; $log->operator_type = AccountLog::TYPE_OPERATOR_NORMAL; $log->created_at = time(); $log->order_id = $queue_log->order_id; $log->order_type = AccountLog::TYPE_PLATFORM_ORDER; $log->save(); return $this->asJson([ 'code' => 0, 'msg' => '兑换成功', ]); } /** * 灵工-收款人进件提交 * @return \yii\web\Response */ public function actionLgSubmit() { $form = new LgForm(); $form->attributes = post_params(); /* begin 2025/07/08 09:21:37 灵工进件时如果未匹配到银行编码填默认的9999 WPing丶 */ if(!post_params('bank_code')) { $form->bank_code = '9999'; } /* end */ $form->store_id = get_store_id(); $form->user_id = get_saas_user_id(); return $this->asJson($form->save()); } /** * 灵工-收款人进件状态 * @return \yii\web\Response */ public function actionLgAuditStatus() { $saas_user_id = get_saas_user_id(); $lg = Lg::find()->where(['user_id' => $saas_user_id, 'store_id' => get_store_id(), 'is_delete' => 0]) ->orderBy('id desc') ->limit(1) ->one(); if (!$lg) { return $this->asJson([ 'code' => 0, 'msg' => '进件记录不存在', 'data' => ['status' => -1] ]); } return $this->asJson([ 'code' => 0, 'data' => ['status' => $lg->status,'id'=> $lg->id,'refuse_desc'=>$lg->refuse_desc] ]); } /** * 灵工-获取收款人银行信息 * @return \yii\web\Response */ public function actionLgBank() { $lgApi = new LgApi(get_store_id()); //需要通过三方查询收款银行信息编码 $data = $lgApi->FlexibleBanks(); return $this->asJson([ 'code' => 0, 'data' => $data ]); } /** * 灵工-收款人进件状态查询 * @return \yii\web\Response */ public function lgQuery($certCard,$user_id) { $post_data = []; $post_data['certCard'] = $certCard; $lgApi = new LgApi(get_store_id()); $res = $lgApi->FlexibleQuery($post_data); $lg = Lg::find()->where(['cert_card' => $certCard, 'store_id' => get_store_id(), 'is_delete' => 0,'user_id'=>$user_id])->one(); if (!$lg){ \Yii::error('灵工-收款人进件状态查询-进件记录不存在'.$certCard); return false; } //审核中 if ($res['status'] == 100 || $res['status'] == 200){ $lg->status = 0; $lg->updated_at = time(); $lg->save(); } //成功 if ($res['status'] == 300){ $lg->status = 1; $lg->updated_at = time(); $lg->save(); } //失败 if ($res['status'] == 999){ $lg->status = 2; $lg->updated_at = time(); $lg->refuse_desc = $res['msg']; $lg->save(); } } /** * 灵工-收款人进件信息 * @return \yii\web\Response */ public function actionLgInfo() { $saas_user_id = get_saas_user_id(); $lg = Lg::find()->where(['user_id' => $saas_user_id, 'store_id' => get_store_id(), 'is_delete' => 0]) ->asArray() ->one(); if (!$lg) { return $this->asJson([ 'code' => 1, 'msg' => '进件记录不存在', ]); } $lg['id_card_start'] = $lg['id_card_start']?date('Y-m-d',$lg['id_card_start']):''; $lg['id_card_end'] = $lg['id_card_end']?date('Y-m-d',$lg['id_card_end']):''; return $this->asJson([ 'code' => 0, 'data' => [ 'apply' => $lg ], ]); } // 获取用户坐标 public function actionGetGeo() { try { $access_token = \input_params('access_token'); if (!$access_token) { throw new \Exception('access_token不能为空'); } $saasUser = SaasUser::findOne(['access_token' => $access_token, 'is_delete' => 0]); if (!$saasUser) { throw new \Exception('access_token无效'); } $addressModel = Address::findOne(['user_id' => $saasUser->id, 'is_default' => 1, 'is_delete' => 0]); if (!$addressModel) { throw new \Exception('地址不存在'); } $address = $addressModel->province . $addressModel->city . $addressModel->district . $addressModel->town . $addressModel->detail; if ($addressModel->latitude && $addressModel->longitude) { return $this->asJson([ 'code' => 0, 'data' => [ 'latitude' => $addressModel->latitude, 'longitude' => $addressModel->longitude, 'address' => $address, ], ]); } $appcode = Option::get(OptionSetting::MAP_APP_CODE, get_store_id(), 'app', '')['value']; if (empty($appcode)) { throw new \Exception('地图服务未配置'); } $res = \app\utils\AddressGeo::AliCloud($address, $appcode); return $this->asJson([ 'code' => 0, 'data' => [ 'latitude' => $res['lat'], 'longitude' => $res['lng'], 'address' => $address, ], ]); } catch (\Throwable $e) { return $this->asJson([ 'code' => 0, 'data' => [ 'latitude' => 0, 'longitude' => 0, 'address' => '', ], ]); } } /** * 获取用户成长值记录 * @return \yii\web\Response * @author: hankaige * @Time: 2025/4/22 09:08 */ public function actionGetGrowthLog(){ $user = get_user(); $storeId = get_store_id(); $query = UserGrowthValueLog::find()->where(['user_id' => $user->id,'store_id' => $storeId]); $list = pagination_make($query,true,'created_at DESC'); foreach($list['list'] as &$item){ $item['created_at'] = date('Y-m-d H:i:s',$item['created_at']); $item['from_text'] = UserGrowthValueLog::TYPE_MAP[$item['from']]; } $list['growth_value'] = $user->growth_value; return $this->asJson([ 'code' => 0, 'msg' => 'ok', 'data' => $list, ]); } }