where(['saas_id'=>$saas_id,'is_delete'=>0])->asArray()->one(); $rightDurationInfo = BusinessRightDuration::find()->where(['saas_id'=>$saas_id,'is_delete'=>0])->asArray()->all(); $rightInfo = $rightIds = []; $is_expire = false; $start_time = time(); $end_time = time() + (86400 * 3); foreach($rightDurationInfo as $val){ if($val['expire_time'] != 0 && $val['expire_time'] >= $start_time && $val['expire_time'] <= $end_time ){ $is_expire = true; } if($val['expire_time'] == 0 || $val['expire_time'] >= $start_time ){ $rightIds[] = $val['right_id']; } } if(!empty($rightIds)){ $rightInfo = BusinessRightInfo::resetRightInfo($rightIds, 'id,name,explanation'); }else{ $rightInfo = []; } if(empty($distributionInfo)){ $distributionInfo['platform_open_id'] = ''; $distributionInfo['ali_name'] = ''; $distributionInfo['name'] = ''; } $distributionInfo['is_expire'] = $is_expire; $distributionInfo['right_info'] = $rightInfo; $total_wechat_bind_count = 0; $current_wechat_bind_count = 0; if (\Yii::$app->prod_is_dandianpu()) { $init_store_ids = Option::find()->where([ 'name' => 'self_mini', 'value' => 1 ])->select('store_id')->column();//供应链独立店铺ID $init_store_ids = Store::find()->where(['id' => $init_store_ids, 'is_delete' => 0])->select('id')->column(); $total_wechat_bind_count += count($init_store_ids); $current_wechat_bind_count = User::find()->where(['store_id' => $init_store_ids, 'is_delete' => 0]) ->andWhere(['<>', 'wechat_open_id', ''])->select('wechat_open_id')->count(); //非独立店铺ID $storeList = Store::find()->where([ 'is_delete' => 0, 'business_model' => 1, ])->andWhere(['NOT IN', 'id', $init_store_ids])->select('id')->column(); if ($storeList) { $total_wechat_bind_count += count($storeList); $user = User::find()->where(['is_delete' => 0, 'binding' => $saas_user->mobile, 'store_id' => $storeList]) ->andWhere(['<>', 'wechat_open_id', '']) ->select('wechat_open_id')->asArray()->one(); if ($user && $user['wechat_open_id']) { $current_wechat_bind_count += count($storeList); } } } if (\Yii::$app->prod_is_shangmengduli() || \Yii::$app->prod_is_shangmengduli() || \Yii::$app->prod_is_saas()) { $storeList = Store::find()->where([ 'is_delete' => 0, 'business_model' => 1 ])->select('id')->column(); $total_wechat_bind_count = count($storeList); $current_wechat_bind_count = User::find()->where(['store_id' => $storeList, 'is_delete' => 0, 'binding' => $saas_user->mobile]) ->andWhere(['<>', 'wechat_open_id', ''])->select('wechat_open_id')->count(); $storeList = Store::find()->where([ 'is_delete' => 0, 'business_model' => [2, 3, 4] ])->select('id')->column(); if ($storeList) { $total_wechat_bind_count += count($storeList); if (!empty($saas_user->platform_open_id)) { $current_wechat_bind_count += count($storeList); } } } $distributionInfo['total_wechat_bind_count'] = $total_wechat_bind_count; $distributionInfo['current_wechat_bind_count'] = $current_wechat_bind_count; return [ 'code' => 0, 'msg' => '获取成功', 'data' => $distributionInfo ]; } public function getDistributionStore() { try { $saas_user = get_saas_user(); $store_name = $this->store_name; $is_dandianpu = 0; $is_dandianpu_bind = 0; //判断是否是供应链系统 且 是否是供应链小程序用户绑定过微信openid if (\Yii::$app->prod_is_dandianpu()) { $init_store_ids = Option::find()->where([ 'name' => 'self_mini', 'value' => 1 ])->select('store_id')->column();//供应链独立店铺ID $init_store_ids = Store::find()->where(['id' => $init_store_ids, 'is_delete' => 0])->select('id')->column(); //非独立店铺ID $storeList = Store::find()->where([ 'is_delete' => 0, 'business_model' => 1, ])->andWhere(['NOT IN', 'id', $init_store_ids])->select('id')->column(); if ($storeList) { $user = User::find()->where(['is_delete' => 0, 'binding' => $saas_user->mobile, 'store_id' => $storeList]) ->andWhere(['<>', 'wechat_open_id', ''])->select('wechat_open_id, created_at')->asArray()->one(); if ($user) { $is_dandianpu_bind = 1; } } $is_dandianpu = 1; } $query = Store::find()->where(['is_delete' => 0])->select('id, name, logo, business_model')->orderBy('id desc'); if (trim($store_name) && !empty($store_name)) { $query->andWhere(['like', 'name', $store_name]); } $pagination = pagination_make($query,true); foreach($pagination['list'] as &$value){ $is_bind = 0; if ($is_dandianpu) { $self_mini = Option::get('self_mini', $value['id'], 'store', 0)['value']; if (intval($self_mini)) { $value['appid'] = WechatConfig::findOne(['store_id' => $value['id'], 'type' => 1])->app_id ?: ''; $user = User::find()->where(['store_id' => $value['id'], 'is_delete' => 0, 'binding' => $saas_user->mobile]) ->andWhere(['<>', 'wechat_open_id', ''])->select('wechat_open_id, created_at')->asArray()->one(); if ($user) { $is_bind = 1; } $value['path'] = "pages/home/home"; } else { $value['appid'] = Option::get('one_store_wechat_appid', 0, 'saas')['value'] ?: ''; $value['path'] = "pages/home/home?store_id={$value['id']}"; $is_bind = $is_dandianpu_bind; } } else { if (intval($value['business_model']) === 1) { $user = User::find()->where(['store_id' => $value['id'], 'is_delete' => 0, 'binding' => $saas_user->mobile]) ->andWhere(['<>', 'wechat_open_id', ''])->select('wechat_open_id, created_at')->asArray()->one(); if ($user) { $is_bind = 1; } $wechatConfig = WechatConfig::findOne(['store_id' => $value['id'], 'type' => 1]); $value['appid'] = $wechatConfig->app_id ?: ''; $value['path'] = "pages/home/home"; } else { $is_bind = intval($saas_user->platform_open_id); $value['appid'] = Option::get('platform_appid', 0, 'saas')['value'] ?: ''; if (intval($value['business_model']) === 2) { $value['path'] = "pages/shop/shopIndex?store_id={$value['id']}"; } elseif (intval($value['business_model']) === 3) { $value['path'] = "pages/shop/shopDetail?store_id={$value['id']}"; } elseif (intval($value['business_model']) === 4) { $value['path'] = "alipay-order/orderMeal/orderMeal?store_id={$value['id']}"; } if ($is_bind) { $value['created_at'] = date('Y-m-d H:i:s', $saas_user->created_at); } } } $value['created_at'] = isset($user) ? date('Y-m-d H:i:s', $user['created_at']) : ($value['created_at'] ?: ''); $value['is_bind'] = $is_bind; } $pagination['user_info'] = [ 'name' => $saas_user->name, 'avatar' => $saas_user->avatar, 'level_name' => '店铺会员' ]; return [ 'code' => 0, 'msg' => '获取成功', 'data' => $pagination ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), ]; } } public function wechatDistribution($code,$open_id){ if(empty($open_id) && empty($code)){ return [ 'code' => 1, 'msg' => '参数不能为空', ]; } $type = 0; if(empty($open_id)){ $wechat_mini = WechatBusinessPay::BussinessWechatMini(); $mini_res = $wechat_mini->auth->session($code); if(!isset($mini_res['openid'])){ return [ 'code' => 1, 'msg' => '获取微信息失败', 'res' => $mini_res, ]; } $open_id = $mini_res['openid']; $type = 1; //小程序获取 }else{ $type = 2; //app获取 } $saas_id = get_saas_user_id(); $distributionInfo = SaasDistribution::findOne(['saas_id'=>$saas_id]); if(!$distributionInfo){ $distributionInfo = new SaasDistribution(); $distributionInfo->created_at = time(); } $distributionInfo->wechat_type = $type; $distributionInfo->saas_id = $saas_id; $distributionInfo->platform_open_id = $open_id; $distributionInfo->bank = ''; if($distributionInfo->save() ){ return [ 'code' => 0, 'msg' => '设置成功' ]; }else{ return [ 'code' => 1, 'msg' => '设置失败' ]; } } public function aliDistribution($name,$ali_name){ $saas_id = get_saas_user_id(); $distributionInfo = SaasDistribution::findOne(['saas_id'=>$saas_id]); if(!$distributionInfo){ $distributionInfo = new SaasDistribution(); $distributionInfo->created_at = time(); } $distributionInfo->saas_id = $saas_id; $distributionInfo->name = $name; $distributionInfo->ali_name = $ali_name; $distributionInfo->bank = ''; if($distributionInfo->save() ){ return [ 'code' => 0, 'msg' => '设置成功' ]; }else{ return [ 'code' => 1, 'msg' => $distributionInfo->errors ]; } } public function bankDistribution($saas_id, $conf){ if(is_string($conf)){ $conf = json_decode($conf, true); } if(!$conf || empty($conf)){ return [ 'code' => 1, 'msg' => '参数错误', ]; } $distributionInfo = SaasDistribution::findOne(['saas_id'=>$saas_id]); if(!$distributionInfo){ $distributionInfo = new SaasDistribution(); $distributionInfo->created_at = time(); } $distributionInfo->saas_id = $saas_id; $distributionInfo->bank = json_encode($conf); if($distributionInfo->save() ){ return [ 'code' => 0, 'msg' => '设置成功' ]; }else{ return [ 'code' => 1, 'msg' => $distributionInfo->errors ]; } } }