repository = $repository; $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null; $this->source = request()->header('source'); $this->merId = request()->header('merId'); } /** * @Author:Qinii * @Date: 2020/5/28 * @return mixed */ public function lst() { [$page, $limit] = $this->getPage(); $where = $this->request->params(['keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid']); return app('json')->success($this->repository->getApiSearch(null, $where, $page, $limit, $this->userInfo)); } /** * @Author:Qinii * @Date: 2020/5/30 * @param $id * @return mixed */ public function detail($id) { $data = $this->repository->detail($id, $this->userInfo); $mer_status = Db::name('merchant')->where('mer_id', $data['mer_id'])->value('status'); if ($mer_status != 1) { return app('json')->fail('商户已关闭'); } // $data['yanglao'] = 11111; $merchent_type = Db::name('merchant')->where('mer_id', $data['mer_id'])->value('merchant_type'); $data['merchant_type'] = $merchent_type; $seckill_status=0; $data['seckill_date_end'] = Db::name('product_seckill')->where("`seckill_date` < '".date('Y-m-d',time()+60*60*24)."'" )->where('product_id', $data['product_id'])->where('status', 1)->value('seckill_date'); if ($data['seckill'] == 1 && $data['seckill_date_end']) { // $data['seckill_date_end'] = Db::name('product_seckill')->where('product_id', $data['product_id'])->where('status', 1)->value('seckill_date'); $d = date('d', time()); $newtime = date('H', time()); $vd = date('d', strtotime($data['seckill_date_end'])); $vtime = date('H', strtotime($data['seckill_date_end'])); //1正在抢购 2 未开始 0 一结束 if ($d < $vd) { $seckill_status=2; } else { if ($newtime < $vtime) { if ($d > $vd) { $seckill_status=0; } else { $seckill_status=2; } } else { if ($d > $vd||$newtime > $vtime) { $seckill_status=0; } else { $seckill_status=1; } } } // Db::name('log')->insert(['data'=>'商品秒杀状态'.$seckill_status]); $data['seckill_date_end']=date('Y-m-d H:i:s',strtotime($data['seckill_date_end'])+3600); }else{ $data['seckill'] =0; } //$data['2222222']=11111; $data['seckill_s']=$seckill_status; if (!$data) return app('json')->fail('商品不存在'); $data['dc_price']=set_price_rtrim($data['dc_price']); if ($id == 15323) { $data['year'] = '5年'; $data['mark'] = '养老金金额(200)'; } return app('json')->success($data); } public function getopenid() { $code=$this->request->params(['code']); if(empty($code['code'])){ return app('json')->fail('参数:code 必填'); } $openid=$this->repository->getopenid($code['code']); return app('json')->success($openid); } /** * @Author:T * @Date: 2021/11/03 * @param $id * @return mixed */ public function pay() { $price=$this->request->params(['price']); if(empty($price['price'])){ return app('json')->fail('参数:price 必填'); } $openid=$this->request->params(['openid']); if(empty($openid['openid'])){ return app('json')->fail('参数:openid 必填'); } $data = $this->repository->pay($price['price'],$openid['openid']); if (!$data) return app('json')->fail('商品不存在'); return app('json')->success($data); } /** * @Author:Qinii * @Date: 2020/5/30 * @return mixed */ public function recommendList() { $mer_id = (int)$this->request->param('mer_id',0); [$page, $limit] = $this->getPage(); if($this->source=='yhc' && $this->merId){ $merId=$this->merId; } elseif($mer_id){ $merId=$mer_id; } else{ $merId=321; } return app('json')->success($this->repository->recommend($this->userInfo, $merId, $page, $limit, null, 'create_time', 5)); } public function volunteer() { [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->recommend($this->userInfo, null, $page, $limit, 'volunteer')); } public function search_volunteer() { [$page, $limit] = $this->getPage(); $key = $this->request->param('key'); $cate_id = $this->request->param('cate_id', ''); $uid='1824'; try { $uid = $this->request->uid(); }catch (Exception $exception){ } return app('json')->success($this->repository->search_recommend($page, $limit, $key, $cate_id,$uid)); } public function qrcode($id) { $param = $this->request->param('type'); if (!$product = $this->repository->getWhere(['product_id' => $id, 'is_del' => 0])) return app('json')->fail('商品不存在'); $url = $param == 'routine' ? $this->repository->routineQrCode($product, $this->request->userInfo()) : $this->repository->wxQrCode($product, $this->request->userInfo()); if (!$url) return app('json')->fail('二维码生成失败'); return app('json')->success(compact('url')); } public function getBagList() { [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->getBagList($this->repository->bagShow(), $page, $limit)); } public function getBagrecomm() { $where = $this->repository->bagShow(); $where['is_good'] = 1; return app('json')->success($this->repository->selectWhere($where)); } public function getBagExplain() { $data = [ 'explain' => systemConfig('promoter_explain'), 'data' => app()->make(GroupDataRepository::class)->groupData('promoter_config', 0), ]; return app('json')->success($data); } public function hot($type) { [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->getApiSearch(null, ['hot_type' => $type, 'is_gift_bag' => 0, 'is_used' => 1], $page, $limit, $this->userInfo)); } public function get_mp_access_token() { // $appid = 'wx82986c4471ce7efc'; // $secret = '4ae3f790d8c5503a22579338504cdb61'; $appid = 'wxfb755febdb800f23'; $secret = '55ed00200ef0ec6662ca8502dc534a69'; $access_token = Cache::get($appid . '_mp_access_token'); if ($access_token) return $access_token; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $res = curlGet($url); Cache::set($appid . '_mp_access_token', $res['access_token'], $res['expires_in']); return $res['access_token']; } //生成邀请小程序码 public function invite_code(){ $uid = $this->request->param('uid',0); $type = 0;//0-储蓄保 1-国盛 2-一壶茶 $imgId = $this->request->param('imgId',0); //删除老数据 // DB::name('system_attachment')->where("create_time < '2023-12-21 09:39:40'")->whereIN('attachment_category_id',[8,9])->delete(); $system_attachment=DB::name('system_attachment')->where('attachment_category_id',8)->where('user_id',$uid)->where('type',$type)->find(); if($system_attachment){ return $system_attachment['attachment_src']; } $user = app()->make(User::class); $access_token = $this->get_mp_access_token(); $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token; $data['scene'] = 'spread=' . $uid; // $data['page'] = 'pages/user/login/other-phone'; $data['page'] = 'pages/user/login/register-agreement'; $domain = $this->request->domain(); if(strpos($domain, 'test.hebeiyhc.com') !== false) { // 域名中包含 "test.hebeiyhc.com'" 字符串 $data['env_version'] = 'trial'; } $res = $user->posturl($url, $data); //判断是否是 json格式 if (is_null(json_decode($res))) { $new_file = (int)(microtime(true) * 1000); $dir = iconv("UTF-8", "GBK", "./public/mpqrcode"); if (!file_exists($dir)) { mkdir($dir, 0777, true); } $path = $dir . '/' . $new_file . ".jpg"; file_put_contents($path, $res); $key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg'; $uploadType = (int)systemConfig('upload_type') ?: 1; $upload = \crmeb\services\UploadService::create($uploadType); if($uploadType != 1){ $time = date('Y-m-d'); $paths = "chuxubao/qrCode/" . $time . '/'; $key = $paths.$key; } $res = $upload->to($path)->validate()->stream($res, $key); if ($res === false) { // return $upload->getError(); } else { $info = $upload->getUploadInfo(); $info['image_type'] = $uploadType; $insert['attachment_category_id']=8; $insert['attachment_name']=basename($info['dir']); $insert['attachment_src']=$info['dir']; $insert['upload_type']=3; $insert['user_type']=-1; $insert['share_image_id']=0; $insert['user_id']=$uid; $insert['type']=$type; DB::name('system_attachment')->insert($insert); return $info['dir']; } }else{ $data=json_decode($res); //生成邀请小程序码------------posturl:{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest, could get access_token by getStableAccessToken, more details at https://mmbizurl.cn/s/JtxxFh33r rid: 65a882ef-2c368b68-6f4a0755"} if(isset($data->errcode) && $data->errcode==40001){ Cache::set('wx82986c4471ce7efc_mp_access_token', null); return $this->invite_code(); } } //没有接收到数据流 return ""; } public function getQrCode($pid, $uid,$share_id) { $user = app()->make(User::class); $access_token = $this->get_mp_access_token(); $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token; // $data['scene'] = 'spread=' . $uid . '&goods_id=' . $pid; $data['scene'] = 'id=' . $pid . '&shareID=' . $share_id; $data['page'] = 'pages/store/product/detail'; $domain = $this->request->domain(); if(strpos($domain, 'test.hebeiyhc.com') !== false) { // 域名中包含 "test.hebeiyhc.com'" 字符串 $data['env_version'] = 'trial'; } $res = $user->posturl($url, $data); if(isset(json_decode($res,true)['errcode']) && json_decode($res,true)['errcode']=='40001'){ Cache::delete('wx9082e5ac2fdb513f1_mp_access_token'); $access_token = $this->get_mp_access_token(); $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token; $data['scene'] = 'id=' . $pid . '&shareID=' . $share_id; $data['page'] = 'pages/store/product/detail'; $res = $user->posturl($url, $data); } //判断是否是 json格式 if (is_null(json_decode($res))) { $new_file = (int)(microtime(true) * 1000); $dir = iconv("UTF-8", "GBK", "./public/mpqrcode"); if (!file_exists($dir)) { mkdir($dir, 0777, true); } $path = $dir . '/' . $new_file . ".jpg"; file_put_contents($path, $res); $imgurl = env('APP_URL') . "/mpqrcode/" . $new_file . ".jpg"; return ['qrcode' => $imgurl, 'path' => $path]; } else { //没有接收到数据流 return false; } } public function product_share() { $id = $this->request->params(['pid'])['pid']; $type = $this->request->params(['type'])['type'] ?? 2; if (!$id) { return app('json')->fail('参数不正确'); } try { $uid = $this->request->uid(); $product_share_url = Db::name('product_share')->where('product_id',$id)->where('share_channel',$type)->where('`url` is not null')->value('url'); //记录Sat $insert_data=[ 'uid'=>$uid, 'product_id'=>$id, 'share_channel'=>$type, 'url'=>$product_share_url, 'ctime'=>date('Y-m-d') ]; $res=Db::name('product_share')->insertGetId($insert_data); $product_share_id = $res; $share_id = $res; if(!$res) return app('json')->success('分享失败,请重新尝试'); $pdata = Db::name('store_product')->where('product_id', $id)->column('image,price,store_name'); //记录End if($type == 2 && $product_share_url){ return app('json')->success([ 'url' => $product_share_url, 'share_id' => $share_id ]); } if ($type == 1){ // $res = [ // 'url'=>$pdata[0]['image'], // 'share_id'=>$res // ]; if ($id == 15323) { $res = $returndata = [ 'url' => 'https://cdn.bjtdba.com/chuxubao/images/2024-04-16/5e928202404162007269551.jpg', 'share_id' => $share_id ]; } else { $res = $this->good_friend($id, $share_id); } Db::name('product_share')->where('id',$product_share_id)->update(['url'=>$res['url']]); return app('json')->success($res); } if (empty($pdata)) { return app('json')->fail('获取商品信息失败'); } $pdata = $pdata[0]; $pic_list = array( $pdata['image'], ); $qrcode = $this->getQrCode($id, $uid,$res); if (!$qrcode) return app('json')->fail('获取小程序二维码失败'); $path = $qrcode['path']; $qrcode = $qrcode['qrcode']; $filename1 = time(); $filename_shareimg = './public/shareimg/' . $filename1 . '.png'; $bg_w = 800; // 背景图片宽度 $bg_h = 1300; // 背景图片高度 $background = imagecreatetruecolor($bg_w, $bg_h); // 背景图片 imagecolorallocate($background, 0, 0, 0); $red = imagecolorallocate($background, 255, 255, 255); imagefill($background, 0, 0, $red); $pic_count = count($pic_list); $lineArr = array(); // 需要换行的位置 $space_x = 3; $space_y = 3; $line_x = 0; switch ($pic_count) { case 1: // 中间位置并排 $start_x = 0; $start_y = 0; $pic_w = intval($bg_w); $pic_h = intval(800); break; } foreach ($pic_list as $k => $pic_path) { if (!strstr($pic_path, 'http')) { $pic_path = 'https:' . $pic_path; } $kk = $k + 1; if (in_array($kk, $lineArr)) { $start_x = $line_x; $start_y = $start_y + $pic_h + $space_y; } $pathInfo = pathinfo($pic_path); $pathInfo['extension'] = $pathInfo['extension'] ?? 'jpg'; switch (strtolower($pathInfo['extension'])) { case 'jpg': case 'jpeg': $imagecreatefromjpeg = 'imagecreatefromjpeg'; break; case 'png': $imagecreatefromjpeg = 'imagecreatefrompng'; break; case 'gif': default: $imagecreatefromjpeg = 'imagecreatefromstring'; $pic_path = file_get_contents($pic_path); break; } $resource = $imagecreatefromjpeg($pic_path); if ($k == 0) { imagecopyresized($background, $resource, $start_x, $start_y, 0, 0, $pic_w, $pic_h, imagesx($resource), imagesy($resource)); // 最后两个参数为原始图片宽度和高度,倒数两个参数为copy时的图片宽度和高度 } } header("Content-type: image/jpg"); imagegif($background, $filename_shareimg); $filename = env('APP_URL').'/shareimg/' . $filename1 . '.png'; $filelink = [ 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf', 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf', ]; $text = $pdata['store_name']; $t2 = array( 'text' => '', 'left' => 400, 'top' => 1020, 'fontPath' => $filelink['Bold'], //字体文件 'fontSize' => 24, //字号 'fontColor' => '255,255,255', //字体颜色 'angle' => 0, ); $t1 = array( 'text' => $text, 'left' => 400, 'top' => 980, 'fontPath' => $filelink['Bold'], //字体文件 'fontSize' => 24, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ); if (mb_strlen($text) > 10) { mb_substr($text, 0, 10); $t1 = array( 'text' => mb_substr($text, 0, 12), 'left' => 400, 'top' => 980, 'fontPath' => $filelink['Bold'], //字体文件 'fontSize' => 24, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ); $t2 = array( 'text' => mb_substr($text, 12, 10) . "...", 'left' => 400, 'top' => 1020, 'fontPath' => $filelink['Bold'], //字体文件 'fontSize' => 24, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ); } $config = array( 'image' => array( array( 'url' => $qrcode,//二维码资源 'stream' => 0, 'left' => 50, 'top' => 930, 'right' => 0, 'bottom' => 0, 'width' => 300, 'height' => 300, 'opacity' => 100 ) ), 'text' => array( $t1, $t2, array( 'text' => $pdata['price'], 'left' => 400, 'top' => 1080, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 26, //字号 'fontColor' => '255,0,0', //字体颜色 'angle' => 0, ), array( 'text' => '加入储蓄保,一起攒攒攒', 'left' => 400, 'top' => 1200, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 18, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ) ), 'background' => $filename ); $data = setSharePoster($config, 'routine/spread/poster'); unlink($path); unlink($filename_shareimg); if (empty($data)) { return app('json')->fail('生成海报失败请重新尝试!'); } Db::name('product_share')->where('id',$share_id)->update(['url'=>$data['dir']]); return app('json')->success(['url'=>$data['dir'],'share_id'=>$share_id]); } catch (\Exception $e) { log::info("生成海报失败请重新尝试".$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】'); Db::name('log')->insert(['data'=>"生成海报失败请重新尝试".$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']); unlink($path); unlink($filename_shareimg); return app('json')->fail('生成海报失败请重新尝试。'); } } /** * 小程序任何界面分享都可以绑定邀请关系 故出这个接口,根据用户身份可以获取share_id * @return mixed */ public function product_share_by_user() { $uid = $this->request->uid(); $product_share_id = Db::name('product_share')->where('product_id', 0)->where('uid', $uid)->value('id'); if(!$product_share_id){ $insert_data = [ 'uid' => $uid, 'product_id' => 0, 'share_channel' => 0, 'url' => '', 'ctime' => date('Y-m-d') ]; $product_share_id = Db::name('product_share')->insertGetId($insert_data); if (!$product_share_id) return app('json')->success('分享失败,请重新尝试');; } return app('json')->success(['share_id' => $product_share_id]); } /** * @param $pdata * @param int $type 1-积分 2-秒杀 * @return array */ public function good_friend_integral($pdata,$type=1) { header("Content-type: image/jpg"); // $filename = 'https://cdn.bjtdba.com/chuxubao/images/2023-10-10/e4bea202310102032462460.png';//普通商品 $filelink = [ 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf', 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf', ]; if (!strstr($pdata['image'], 'http')) { $pdata['image'] = 'https:' . $pdata['image']; } if($type==2){ $where=[ 'ps.status'=>1, 'merchant.status' => 1, 'sp.is_del' =>0, 'sp.product_id' =>$pdata['product_id'], ]; $product_data_time=Db::name('product_seckill') ->alias('ps') ->join('store_product sp','sp.product_id=ps.product_id') ->leftJoin('merchant merchant','sp.mer_id=merchant.mer_id') ->where('sp.is_show',1) ->where($where)->value('ps.seckill_date'); // $ProductRepository=app() -> make(ProductRepository::class); // $yanglao=$ProductRepository->yanglaojin($pdata['product_id']); $pdata['seckill_price'] = Db::name('store_product_attr_value')->where('product_id', $pdata['product_id'])->value('dacang_price'); $mer_fanyongbili = merchantConfig($pdata['mer_id'], 'base_commission'); //如果商户返佣比例设置的是0怎查系统设设置的分佣比例 if ($mer_fanyongbili == 0) { $mer_fanyongbili = merchantConfig(0, 'extension_one_rate'); } $mer_fanyongbili=bcdiv($mer_fanyongbili, '100', 3); $yanglao= set_price_rtrim(bcmul(bcmul($pdata['seckill_price'],$mer_fanyongbili,2),'0.5',2));//养老金 $filename='https://cdn.bjtdba.com/chuxubao/images/2023-10-24/4f2e3202310241717119393.png';//秒杀背景 $config = array( 'text' => array( array( 'text' => $yanglao, 'left' => 160, 'top' => 300, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 16, //字号 'fontColor' => '254,18,64', //字体颜色 'angle' => 0, ), array( 'text' => $pdata['dc_price'], 'left' => 105, 'top' => 267, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 22, //字号 'fontColor' => '254,18,64', //字体颜色 'angle' => 0, ), array( 'text' => '立即购买', 'left' => 285, 'top' => 276, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 22, //字号 'fontColor' => '255,255,255', //字体颜色 'angle' => 0, ), array( 'text' =>date('m月d日 H点结束', strtotime($product_data_time)+3600), 'left' => 257, 'top' => 306, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 14, //字号 'fontColor' => '255,255,255', //字体颜色 'angle' => 0,) ), 'background' => $filename ); }else{ $filename = 'https://cdn.bjtdba.com/chuxubao/images/2023-10-24/c7ec9202310241544064190.png';//积分背景 $config = array( 'text' => array( // array( // 'text' => $yanglao, // 'left' => 160, // 'top' => 315, // 'fontPath' => $filelink['Normal'], //字体文件 // 'fontSize' => 16, //字号 // 'fontColor' => '255,0,0', //字体颜色 // 'angle' => 0, // ), array( 'text' => ($pdata['price']*30).'积分', 'left' => 35, 'top' => 295, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 22, //字号 'fontColor' => '254,0,50', //字体颜色 'angle' => 0, ), array( 'text' => '立即购买', 'left' => 275, 'top' => 296, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 26, //字号 'fontColor' => '255,255,255', //字体颜色 'angle' => 0, ), // array( // 'text' =>'让每一笔消费更有价值', // 'left' => 180, // 'top' => 413, // 'fontPath' => $filelink['Normal'], //字体文件 // 'fontSize' => 18, //字号 // 'fontColor' => '40,40,40', //字体颜色 // 'angle' => 0,) ), 'background' => $filename ); } if($pdata['type'] == 5){ $config['image'] = [ array( 'url' => $pdata['image'],//图片资源 'stream' => 0, 'left' => 127, 'top' => 15, 'right' => 0, 'bottom' => 0, 'width' => 204, 'height' => 204, 'opacity' => 100 ), // array( // 'url' => 'https://cdn.bjtdba.com/vod/image/2022-07-11/20220711104440683.png',//图片资源 // 'stream' => 0, // 'left' => 460, // 'top' => 162, // 'right' => 0, // 'bottom' => 0, // 'width' => 63, // 'height' => 28, // 'opacity' => 100 // ) ]; }else{ $config['image'] = [ array( 'url' => $pdata['image'],//图片资源 'stream' => 0, 'left' => 127, 'top' => 15, 'right' => 0, 'bottom' => 0, 'width' => 204, 'height' => 204, 'opacity' => 100 ) ]; } return $config; // $this->setSharePoster($config, 'routine/spread/poster'); } function setSharePoster($config, $path) { $imageDefault = array( 'left' => 0, 'top' => 0, 'right' => 0, 'bottom' => 0, 'width' => 100, 'height' => 100, 'opacity' => 100 ); $textDefault = array( 'text' => '', 'left' => 0, 'top' => 0, 'fontSize' => 32, //字号 'fontColor' => '255,255,255', //字体颜色 'angle' => 0, ); $background = $config['background'];//海报最底层得背景 if (substr($background, 0, 1) === '/') { $background = substr($background, 1); } $backgroundInfo = getimagesize($background); $background = imagecreatefromstring(file_get_contents($background)); $backgroundWidth = $backgroundInfo[0]; //背景宽度 $backgroundHeight = $backgroundInfo[1]; //背景高度 $imageRes = imageCreatetruecolor($backgroundWidth, $backgroundHeight); // $color = imagecolorallocate($imageRes, 0, 0, 0); $color = imagecolorallocate($imageRes, 255, 255, 255); imagefill($imageRes, 0, 0, $color); imagecopyresampled($imageRes, $background, 0, 0, 0, 0, imagesx($background), imagesy($background), imagesx($background), imagesy($background)); if (!empty($config['image'])) { foreach ($config['image'] as $key => $val) { $val = array_merge($imageDefault, $val); $info = getimagesize($val['url']); $function = 'imagecreatefrom' . image_type_to_extension($info[2], false); if ($val['stream']) { $info = getimagesizefromstring($val['url']); $function = 'imagecreatefromstring'; } $res = $function($val['url']); $resWidth = $info[0]; $resHeight = $info[1]; $canvas = imagecreatetruecolor($val['width'], $val['height']); imagefill($canvas, 0, 0, $color); imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight); $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) - $val['width'] : $val['left']; $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) - $val['height'] : $val['top']; imagecopymerge($imageRes, $canvas, $val['left'], $val['top'], $val['right'], $val['bottom'], $val['width'], $val['height'], $val['opacity']);//左,上,右,下,宽度,高度,透明度 } } if (isset($config['text']) && !empty($config['text'])) { foreach ($config['text'] as $key => $val) { $val = array_merge($textDefault, $val); list($R, $G, $B) = explode(',', $val['fontColor']); $fontColor = imagecolorallocate($imageRes, $R, $G, $B); $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) : $val['left']; $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) : $val['top']; imagettftext($imageRes, $val['fontSize'], $val['angle'], $val['left'], $val['top'], $fontColor, $val['fontPath'], $val['text']); } } ob_start(); $key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg'; imagejpeg($imageRes,'./public/install/'.$key); imagedestroy($imageRes); // $res = ob_get_contents(); // ob_end_clean(); // 创建图像资源 $imageRes = imagecreatefromjpeg('./public/install/'.$key); header('Content-Type: image/jpeg'); imagejpeg($imageRes); imagedestroy($imageRes); // var_dump('http://172.16.0.44:8324/install/'.$key); } public function good_friend($id,$res) { $ProductRepository=app() -> make(ProductRepository::class); $pdata = Db::name('store_product')->where('product_id', $id)->column('product_id,image,price,store_name,mer_id,type,dc_price,dc_id,seckill'); if (empty($pdata)) { return app('json')->fail('获取商品信息失败'); } $pdata = $pdata[0]; if( $pdata['mer_id']==148){//积分商品 $config=$this->good_friend_integral($pdata); }else if($pdata['seckill']==1){ $config=$this->good_friend_integral($pdata,2); }else{ // $mmerchat_data = Db::name('merchant')->where('mer_id', $pdata['mer_id'])->find(); // $mer_name = $mmerchat_data['mer_name']; $price = $pdata['price']; $yanglao=$ProductRepository->yanglaojin($pdata['product_id']); // if($pdata['type'] == 5){ // $mer_name = Db::name('big_warehouse') -> where('id',$pdata['dc_id']) -> value('warehouse_name'); // $price = $pdata['dc_price']; // } //mer_avatar logo header("Content-type: image/jpg"); $filename = 'https://cdn.bjtdba.com/chuxubao/images/2023-10-10/e4bea202310102032462460.png'; $filelink = [ 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf', 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf', ]; if (!strstr($pdata['image'], 'http')) { $pdata['image'] = 'https:' . $pdata['image']; } $config = array( 'text' => array( array( 'text' => $yanglao, 'left' => 160, 'top' => 315, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 16, //字号 'fontColor' => '255,0,0', //字体颜色 'angle' => 0, ), array( 'text' => $price, 'left' => 45, 'top' => 277, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 20, //字号 'fontColor' => '255,0,0', //字体颜色 'angle' => 0, ), /*array( 'text' => $strProductName, 'left' => 20, 'top' => 110, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 26, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ), array( 'text' =>'让每一笔消费更有价值', 'left' => 180, 'top' => 413, 'fontPath' => $filelink['Normal'], //字体文件 'fontSize' => 18, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0,)*/ ), 'background' => $filename ); if($pdata['type'] == 5){ $config['image'] = [ array( 'url' => $pdata['image'],//图片资源 'stream' => 0, 'left' => 127, 'top' => 15, 'right' => 0, 'bottom' => 0, 'width' => 204, 'height' => 204, 'opacity' => 100 ), // array( // 'url' => 'https://cdn.bjtdba.com/vod/image/2022-07-11/20220711104440683.png',//图片资源 // 'stream' => 0, // 'left' => 460, // 'top' => 162, // 'right' => 0, // 'bottom' => 0, // 'width' => 63, // 'height' => 28, // 'opacity' => 100 // ) ]; }else{ $config['image'] = [ array( 'url' => $pdata['image'],//图片资源 'stream' => 0, 'left' => 127, 'top' => 15, 'right' => 0, 'bottom' => 0, 'width' => 204, 'height' => 204, 'opacity' => 100 ) ]; } } $data = setSharePoster($config, 'routine/spread/poster'); $returndata=[ 'url'=>$data['dir'], 'share_id'=>$res ]; return $returndata; // return app('json')->success(env('APP_URL') . $data['dir']); } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * 总共分享次数及每条的展示 */ public function product_share_list() { $uid=$this->request->uid(); [$page, $limit] = $this->getPage(); $params=$this->request->params(['starTime','endTime']); $starTime=$params['starTime']??''; $endTime=$params['endTime']??''; if($starTime and $endTime){ $data=Db::name('product_share')->where('uid',$uid)->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->field('ctime')->page($page,$limit)->order('ctime','desc')->group('ctime')->select(); if(!$data->isEmpty()){ $data=$data->toArray(); }else{ return app('json')->fail('暂无数据'); } // dd($data); foreach ($data as $k=>&$v){ $v['list']=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->where('uid',$uid)->where('ctime',$v['ctime'])->select()->toArray(); } //合计 // $all_click_num=Db::name('product_share')->where('uid',$uid)->sum('click_num'); // $all_buy_num=Db::name('product_share')->where('uid',$uid)->sum('buy_num'); // $all_share_haoyou=Db::name('product_share')->where('uid',$uid)->where('share_channel',1)->count('id'); // $all_share_pengyouquan=Db::name('product_share')->where('uid',$uid)->where('share_channel',2)->count('id'); //合计结束 foreach ($data as $key=>&$value){ $value['ctime']=date('m/d',strtotime($value['ctime'])); $value['click_num']=0; $value['buy_num']=0; $value['share_haoyou']=0; $value['share_pengyouquan']=0; foreach ($value['list'] as $item){ $value['click_num']+=$item['click_num']; $value['buy_num']+=$item['buy_num']; if($item['share_channel']==1){ $value['share_haoyou']++; }elseif($item['share_channel']==2){ $value['share_pengyouquan']++; } } unset($data[$key]['list']); } //顶部数据 $click=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->sum('click_num'); $buy=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->sum('buy_num'); $share=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->count('id'); if($click){ $product_click_rate=bcmul(bcdiv($click,$share,2),100).'%'; }else{ $product_click_rate='0%'; } if($buy){ $product_buy_rate=bcmul(bcdiv($buy,$click,2),100).'%'; }else{ $product_buy_rate='0%'; } $returndata=[ 'lower_data'=>$data, // 'middle_data'=>[ // 'all_share_haoyou'=>$all_share_haoyou, // 'all_share_pengyouquan'=>$all_share_pengyouquan, // 'all_click_num'=>$all_click_num, // 'all_buy_num'=>$all_buy_num, // ], 'top_data'=>[ 'product_click_rate'=>$product_click_rate, 'product_buy_rate'=>$product_buy_rate ] ]; }else{ $data=Db::name('product_share')->where('uid',$uid)->field('ctime')->page($page,$limit)->order('ctime','desc')->group('ctime')->select(); if(!$data->isEmpty()){ $data=$data->toArray(); }else{ return app('json')->fail('暂无数据'); } // dd($data); foreach ($data as $k=>&$v){ $v['list']=Db::name('product_share')->where('uid',$uid)->where('ctime',$v['ctime'])->select()->toArray(); } //合计 // $all_click_num=Db::name('product_share')->where('uid',$uid)->sum('click_num'); // $all_buy_num=Db::name('product_share')->where('uid',$uid)->sum('buy_num'); // $all_share_haoyou=Db::name('product_share')->where('uid',$uid)->where('share_channel',1)->count('id'); // $all_share_pengyouquan=Db::name('product_share')->where('uid',$uid)->where('share_channel',2)->count('id'); //合计结束 foreach ($data as $key=>&$value){ $value['ctime']=date('m/d',strtotime($value['ctime'])); $value['click_num']=0; $value['buy_num']=0; $value['share_haoyou']=0; $value['share_pengyouquan']=0; foreach ($value['list'] as $item){ $value['click_num']+=$item['click_num']; $value['buy_num']+=$item['buy_num']; if($item['share_channel']==1){ $value['share_haoyou']++; }elseif($item['share_channel']==2){ $value['share_pengyouquan']++; } } unset($data[$key]['list']); } //顶部数据 $click=Db::name('product_share')->where('ctime',date('Y-m-d',time()))->sum('click_num'); $buy=Db::name('product_share')->where('ctime',date('Y-m-d',time()))->sum('buy_num'); $share=Db::name('product_share')->where('ctime',date('Y-m-d',time()))->count('id'); if($click){ $product_click_rate=bcmul(bcdiv($click,$share,2),100).'%'; }else{ $product_click_rate='0%'; } if($buy){ $product_buy_rate=bcmul(bcdiv($buy,$click,2),100).'%'; }else{ $product_buy_rate='0%'; } $returndata=[ 'lower_data'=>$data, // 'middle_data'=>[ // 'all_share_haoyou'=>$all_share_haoyou, // 'all_share_pengyouquan'=>$all_share_pengyouquan, // 'all_click_num'=>$all_click_num, // 'all_buy_num'=>$all_buy_num, // ], 'top_data'=>[ 'product_click_rate'=>$product_click_rate, 'product_buy_rate'=>$product_buy_rate ] ]; } return app('json')->success($returndata); } /** * 关注列表- 志愿者 */ public function volunteer_list() { $uid = $this->request->uid(); $keys=$this->request->param('keys'); [$page, $limit] = $this->getPage(); //顶部数据 $volunteer_id=Db::name('store_product')->where('volunteer',1)->group('mer_id')->column('mer_id'); $top_data = Db::name('user_relation') ->alias('u_r') ->leftJoin('merchant m', 'm.mer_id=u_r.type_id') // ->join('store_product s_p', 'm.mer_id=s_p.mer_id') ->where('u_r.type', 10) ->where('mer_id','in',$volunteer_id) ->where('u_r.uid', $uid) ->where('m.mer_state', 1) ->where('m.is_del', 0) // ->where('s_p.volunteer', 1) // ->where('s_p.is_show', 1) // ->where('s_p.is_used ', 1) ->page($page,$limit) ->field('m.mer_id,m.mer_avatar,m.mer_name') ->select(); // dd($top_data->toArray()); $top_data = $top_data->toArray(); $top_data = array_unique($top_data, SORT_REGULAR); //页面中间数据 $ids = ''; foreach ($top_data as $k => $v) { $ids .= $v['mer_id'] . ','; } $ids = rtrim($ids, ','); //根据ID 查到商户 if($keys){ $middle_data=Db::name('merchant') ->alias('m') ->leftJoin('store_product s_p','s_p.mer_id=m.mer_id') ->whereLike('m.mer_name','%'.$keys.'%') ->where('m.mer_state', 1) ->where('m.is_del', 0) ->where('s_p.volunteer', 1) ->where('s_p.is_show', 1) ->where('s_p.is_used ', 1) ->field('m.*') ->page($page,$limit) ->select() ; }else{ $middle_data = Db::name('merchant') ->alias('m') // ->leftJoin('store_product s_p','m.mer_id=s_p.mer_id') ->whereIn('m.mer_id', $ids) ->where('m.mer_state', 1) ->where('m.is_del', 0) // ->field('m.mer_id,m.mer_avatar,m.mer_name,m.sales,m.renqizhi') ->select(); } $middle_data = $middle_data->toArray(); $middle_data = array_unique($middle_data, SORT_REGULAR); foreach ($middle_data as $key => &$value) { //是否关注循环判断 $is_arr=Db::name('user_relation')->where(['uid'=>$uid,'type_id'=>$value['mer_id'],'type'=>10])->count('uid'); if($is_arr>=1){ $value['is_follow']=1; }else{ $value['is_follow']=0; } //拿到商品数据 $middle_product_data = Db::name('store_product') ->alias('s_p') ->where('s_p.mer_id', $value['mer_id']) ->where('s_p.volunteer', 1) ->where('s_p.is_show', 1) ->where('s_p.is_used ', 1) ->limit('3') ->select(); if (!$middle_product_data->isEmpty()) { $middle_product_data = $middle_product_data->toArray(); } $value['product'] = $middle_product_data; } // dd($middle_data); //底部数据 $lower_data=Db::name('user_visit') ->alias('uv') ->leftJoin('store_product sp','uv.type_id=sp.product_id') ->leftJoin('merchant m','m.mer_id=sp.mer_id') ->where('uv.type','product') ->where('uv.uid',$uid) ->group('type_id') -> where('m.mer_state',1) -> where('m.is_del',0) ->limit('10') ->page($page,$limit) ->field('m.mer_id,m.mer_avatar,m.mer_name,m.sales,m.renqizhi') ->select(); if(!$lower_data->isEmpty()){ $lower_data=$lower_data->toArray(); } //循环处理数据 foreach ($lower_data as $key => &$value) { //是否关注 $is_arr=Db::name('user_relation')->where(['uid'=>$uid,'type_id'=>$value['mer_id'],'type'=>10])->count('uid'); if($is_arr>=1){ $value['is_follow']=1; }else{ $value['is_follow']=1; } //商品数据 $lower_product_data = Db::name('store_product') ->alias('s_p') ->where('s_p.mer_id', $value['mer_id']) ->where('s_p.volunteer', 1) ->where('s_p.is_show', 1) ->where('s_p.is_used ', 1) ->limit('3') ->select(); if (!$lower_product_data->isEmpty()) { //有志愿者商品 转成数组下一步 $lower_product_data = $lower_product_data->toArray(); }else{ //没有志愿者商品 跳出此次循环 并删除当前数据 unset($lower_data[$key]); continue; } //拼装数据 $value['product'] = $lower_product_data; } //根据 是否关注排序 is_follow $lower_data=$this->arraySort($lower_data, 'is_follow', SORT_ASC); $is_have=1; foreach ($lower_data as $kk=>$vv){ // dd($vv); if($vv['is_follow']==0){ $is_have=2; } } //上一步的数据是否有未关注的商家 有 返回 没有重新查一下 if(empty($lower_data) || $is_have==1){ $lower_data=$this->lower_data($page,$limit,$uid); $lower_data=array_merge($lower_data); if(!empty($lower_data)){ foreach ($lower_data['lower_data']as $k=>&$v){ $is_arr=Db::name('user_relation')->where(['uid'=>$uid,'type_id'=>$v['mer_id'],'type'=>10])->count('uid'); if($is_arr>=1){ $v['is_follow']=1; }else{ $v['is_follow']=0; } } $lower_data=$this->arraySort($lower_data['lower_data'], 'is_follow', SORT_ASC); } } return app('json')->success(compact('top_data', 'middle_data','lower_data')); } public function lower_data($page,$limit,$uid) { $user_follow=Db::name('user_relation')->where('uid',$uid)->where('type',10)->column('type_id'); $user_follow=implode(',',$user_follow); $lower_data=Db::name('store_product') ->alias('sp') ->join('merchant m','sp.mer_id=m.mer_id') ->whereNotIn('m.mer_id',$user_follow) ->where('sp.volunteer',1) ->group('sp.mer_id') ->order('sp.sales desc') ->page($page,'5') ->field('m.mer_id,m.mer_avatar,m.mer_name,m.sales,m.renqizhi') ->select(); if (!$lower_data->isEmpty()) { $lower_data = $lower_data->toArray(); }else{ return []; } foreach ($lower_data as $key => &$value) { $lower_product_data = Db::name('store_product') ->alias('s_p') ->where('s_p.mer_id', $value['mer_id']) ->where('s_p.volunteer', 1) ->where('s_p.is_show', 1) ->where('s_p.is_used ', 1) ->limit('3') ->select(); if (!$lower_product_data->isEmpty()) { $lower_product_data = $lower_product_data->toArray(); }else{ unset($lower_data[$key]); continue; } $value['product'] = $lower_product_data; } return compact('lower_data','page'); } /** * 二维数组根据某个字段排序 * @param array $array 要排序的数组 * @param string $keys 要排序的键字段 * @param string $sort 排序类型 SORT_ASC SORT_DESC * @return array 排序后的数组 */ function arraySort($array, $keys, $sort = SORT_DESC) { $keysValue = []; foreach ($array as $k => $v) { $keysValue[$k] = $v[$keys]; } array_multisort($keysValue, $sort, $array); return $array; } /** * 分享点击 */ public function buy_product_share($id) { Db::name('product_share')->where('id',$id)->inc('click_num')->update(); return app('json')->success('success'); } /** * 分享购买 */ public function click_product_share($id) { Db::name('product_share')->where('id',$id)->inc('buy_num')->update(); return app('json')->success('success'); } //大仓会员商品列表 public function dacang_lst() { [$page, $limit] = $this->getPage(); $type=$this->request->param('type'); if ($type == '2'){ //银卡会员商品 $product_id = explode('=',systemConfig('product_ids_yin')); }else{ //金卡会员商品 $product_id = explode('=',systemConfig('product_ids')); } $product_lst=Db::name('store_product')->page($page,$limit)->whereIn('product_id',$product_id)->field('image,store_name,product_id,sales')->select()->toArray(); $count=Db::name('store_product')->whereIn('product_id',$product_id)->count('product_id'); $ProductRepository=app() -> make(ProductRepository::class); foreach ($product_lst as $k=>&$v){ $v['yanglao']=$ProductRepository->yanglaojin($v['product_id']); $product_attr_value=Db::name('store_product_attr_value')->where('product_id',$v['product_id'])->field('unique,ot_price,price') -> find(); $v['product_attr_unique'] = $product_attr_value['unique']; $v['ot_price'] = $product_attr_value['ot_price']; $v['price'] = $product_attr_value['price']; } $return_data=[ 'list'=>$product_lst, 'count'=>$count ]; return app('json')->success($return_data); } }