| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/27
- */
- namespace app\controller\api\store\product;
- use app\common\repositories\store\product\ProductRepository;
- use app\common\repositories\system\groupData\GroupDataRepository;
- use app\controller\merchant\user\User;
- use app\Request;
- use think\App;
- use crmeb\basic\BaseController;
- use app\common\repositories\store\product\ProductRepository as repository;
- use think\Exception;
- use think\facade\Cache;
- use think\facade\Db;
- use think\facade\Log;
- class StoreProduct extends BaseController
- {
- /**
- * @var repository
- */
- protected $repository;
- protected $userInfo;
- private $source;
- private $merId;
- /**
- * StoreProduct constructor.
- * @param App $app
- * @param repository $repository
- */
- public function __construct(App $app, repository $repository)
- {
- parent::__construct($app);
- $this->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);
- }
- }
|