123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- <?php
- namespace App\Modules\Channel\Services;
- use App\Modules\OfficialAccount\Models\DistributionSelfDefineConfig;
- use App\Modules\Channel\Models\Channel;
- use App\Modules\Finance\Services\FinanceService;
- use App\Modules\SendOrder\Services\SendOrderService;
- use App\Modules\Trade\Services\PayMerchantService;
- use DB;
- class ChannelService
- {
-
- static function getAllChannels($params = [])
- {
- return Channel::getAllChannels($params);
- }
-
- static function getByPhone($phone)
- {
- return Channel::getByPhone($phone);
- }
-
- static function getIdByNickName($nickName)
- {
- return Channel::getIdByNickName($nickName);
- }
-
- static function getByChannelUserId($channel_user_id)
- {
- return Channel::getByChannelUserId($channel_user_id);
- }
-
-
- static function deleteChannel($distribution_channel_id, $channel_user_id)
- {
- return Channel::deleteChannel($distribution_channel_id, $channel_user_id);
- }
-
-
- static function getById($id)
- {
- return Channel::getById($id);
- }
-
- static function getChannelNameById($id)
- {
- if (empty($id)) {
- return '';
- }
- return Channel::getChannelNameById($id);
- }
-
- static function getUserIdById($id)
- {
- if (empty($id)) {
- return 0;
- }
- return Channel::getUserIdById($id);
- }
-
- static function getChannelNicknameById($id)
- {
- if (empty($id)) {
- return "";
- }
- $result = Channel::getChannelNicknameById($id);
- if (empty($result)) {
- return "";
- }
- return $result['nickname'];
- }
-
- static function getChannelCompanyNameById($id)
- {
- if (empty($id)) {
- return "";
- }
- $result = Channel::getChannelCompanyNameById($id);
- return $result;
- }
-
- static function getChannelBankSourceById($id)
- {
-
- $channel = self::getById($id);
- if (!empty($channel) && $channel['pay_merchant_id'] > 0) {
- $payMerchant = PayMerchantService::getPayMerchantSingle($channel['pay_merchant_id']);
- if (!empty($payMerchant) && !empty($payMerchant['source'])) {
- return $payMerchant['source'];
- }
- }
- return config('common.tonglianpay');
- }
-
- static function createChannel($params)
- {
- return Channel::createChannel($params);
- }
-
- static function getChannelData()
- {
-
- $channels = Channel::getAllChannels();
-
- $avaliableBalanceAll = FinanceService::getChannelAccountBalanceAll();
-
- if (empty($channels)) {
- foreach ($channels as $channelItem) {
- $channelId = $channelItem->id;
-
- $channelAvaliableBalance = FinanceService::getChannelAccountBalance($channelId);
-
-
- $sendOrderCount = SendOrderService::getPromotionCountByChannelId($channelId);
- }
- }
- }
-
- static function modifyPassword($phone, $password)
- {
- return Channel::modifyPassword($phone, $password);
- }
-
- public static function updateChannelData($id, $params = [])
- {
- return Channel::updateChannelData($id, $params);
- }
-
- public static function getChannelList($params = [], $isAll = '')
- {
- return Channel::getChannelList($params, $isAll);
- }
-
- public static function getChannelIdList($distribution_manages_id = '')
- {
- return Channel::getChannelIdList($distribution_manages_id);
- }
- public static function getSourceName($source)
- {
- if (config('common.tonglianpay') == $source) {
- return "通联支付";
- } else if (config('common.lianlianpay') == $source) {
- return "连连支付";
- } else if (config('common.officialpay') == $source) {
- return "官方支付";
- }
- return "";
- }
- static function getDefault($channel_user_id)
- {
- return Channel::getDefault($channel_user_id);
- }
-
- static function getUserChannel($distribution_channle_id, $channel_user_id)
- {
- return Channel::getUserChannel($distribution_channle_id, $channel_user_id);
- }
-
- static function getUserChannelIds($channel_user_id)
- {
- return Channel::getUserChannelIds($channel_user_id);
- }
- static function getUserChannelIdsV2($channel_user_id)
- {
- return Channel::where('channel_user_id', $channel_user_id)->get()->pluck('id')->toArray();
- }
-
- static function setChannelSiteNickName($distribution_channle_id, $nick_name)
- {
- return Channel::where('id', $distribution_channle_id)->update(['site_nick_name' => $nick_name]);
- }
-
- static function getByDistributionManagesId($distribution_manage_id)
- {
- return Channel::getByDistributionManagesId($distribution_manage_id);
- }
-
-
- static function updateDistributionOuterSiteSwitch($distribution_channel_id,$status)
- {
- return Channel::updateDistributionOuterSiteSwitch($distribution_channel_id,$status);
- }
-
-
- static function updateDistributionOldUserSiteSwitch($distribution_channel_id,$status)
- {
- return Channel::updateDistributionOldUserSiteSwitch($distribution_channel_id,$status);
- }
-
-
-
- static function getDistributionChannel($distribution_channel_id)
- {
- return Channel::getDistributionChannel($distribution_channel_id);
- }
-
-
- static function getDistributionChannelSwitchByCategory($distribution_channel_id,$category)
- {
- return DistributionSelfDefineConfig::getDistributionSelfDefineConfig($distribution_channel_id,$category);
- }
-
-
- static function getDistributionChannelSwitchByCategoryAndCompany($company_id,$category)
- {
- return DistributionSelfDefineConfig::getDistributionChannelSwitchByCategoryAndCompany($company_id,$category);
- }
-
-
- static function check_channel_company_priv($distribution_channel_id,$category){
- $distribution = self::getDistributionChannel($distribution_channel_id);
- $channel_user_id = isset($distribution->channel_user_id)?$distribution->channel_user_id:'';
- $channel_user = ChannelUserService::getById($channel_user_id);
- $company_id = isset($channel_user->company_id)?$channel_user->company_id:'';
-
- \Log::info('check_channel_company_priv:category:'.$category.' distribution_channel_id:'.$distribution_channel_id.' channel_user_id:'.$channel_user_id.' company_id:'.$company_id);
- return self::getDistributionChannelSwitchByCategoryAndCompany($company_id,$category);
- }
-
-
- static function check_channel_account_priv($distribution_channel_id,$category){
- $distribution = self::getDistributionChannel($distribution_channel_id);
- $channel_user_id = isset($distribution->channel_user_id)?$distribution->channel_user_id:'';
- $channel_user = ChannelUserService::getById($channel_user_id);
- $account = isset($channel_user->phone)?$channel_user->phone:'';
-
- \Log::info('check_channel_company_priv:category:'.$category.' distribution_channel_id:'.$distribution_channel_id.' channel_user_id:'.$channel_user_id.' account:'.$account);
- return self::getDistributionChannelSwitchByCategoryAndAccount($account,$category);
- }
-
- static function getDistributionChannelSwitchByCategoryAndAccount($account,$category)
- {
- return DistributionSelfDefineConfig::getDistributionChannelSwitchByCategoryAndAccount($account,$category);
- }
-
-
- static function convertChannelReplyUrl($is_outer_site,$appid,$openid,$content,$fromwhere='',$keyword='')
- {
- if(!$is_outer_site) return $content;
- $matchs = [];
- $from_where_str = '&fromwhere='.$fromwhere;
- if ($keyword) $keyword = '&fromtype='.$keyword;
- \Log::Info('convertChannelReplyUrl_before:appid'.$appid.' openid:'.$openid.' is_outer_site:'.$is_outer_site.' fromwhere:'.$fromwhere);
- $new_content = $content;
-
- if(is_array($new_content)){
- foreach ($new_content as $key=>$one_content){
- if(isset($new_content[$key]['url']) && !empty($new_content[$key]['url'])){
- if(strpos($new_content[$key]['url'],'?') > -1){
- $new_content[$key]['url'] = $new_content[$key]['url'].'&appid='.$appid.'&openid='.$openid.$from_where_str;
- }else{
- $new_content[$key]['url'] = $new_content[$key]['url'].'?appid='.$appid.'&openid='.$openid.$from_where_str;
- }
- }
- }
- }
-
- else{
-
-
- preg_match_all("/<a(s*[^>]+s*)href=([\"|']?)([^\"'>\s]+)([\"|']?)/ies",$content,$matchs);
- $matchs_all = isset($matchs[3])?$matchs[3]:[];
- \Log::info('$matchs_all');\Log::info($matchs_all);
-
- if(!empty($matchs_all)){
- foreach($matchs_all as $match){
- $match = str_replace(array('\r','\n'),"",$match);
- $match = trim($match);
- $new_url = $url = $match;
-
- if(strpos($url,'?') > -1){
- $new_url = $url.'&appid='.$appid.'&openid='.$openid.$from_where_str.$keyword;
- }else{
- $new_url = $url.'?appid='.$appid.'&openid='.$openid.$from_where_str.$keyword;
- }
-
- $new_content = str_replace($url.'\n"',$new_url.'"',$new_content);
- $new_content = str_replace($url."\n'",$new_url."'",$new_content);
- $new_content = str_replace($url.'"',$new_url.'"',$new_content);
- $new_content = str_replace($url."'",$new_url."'",$new_content);
- }
- }
- }
-
- \Log::Info('convertChannelReplyUrl_after:appid'.$appid.' openid:'.$openid);
- \Log::Info('$new_content');\Log::Info($new_content);
- return $new_content;
- }
- static function getContentByUrl($url)
- {
- $ch = curl_init();
- $timeout = 10;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36');
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $html = curl_exec($ch);
- return $html;
- }
- public static function getChannelCompanyInfo($distribution_channel_id){
- return Channel::select(DB::raw("companies.*"))
- ->leftjoin('channel_users','channel_users.id','=','distribution_channels.channel_user_id')
- ->leftjoin('companies','companies.id','=','channel_users.company_id')
- ->where('distribution_channels.id',$distribution_channel_id)
- ->first();
- }
-
- public static function getChannelCompanySex($distribution_channel_id){
- $company = Channel::select(DB::raw("companies.*"))
- ->leftjoin('channel_users','channel_users.id','=','distribution_channels.channel_user_id')
- ->leftjoin('companies','companies.id','=','channel_users.company_id')
- ->where('distribution_channels.id',$distribution_channel_id)
- ->first();
-
- $sex = isset($company->fans_gender)?$company->fans_gender:'3';
- return $sex;
- }
- }
|