Movie.php 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/27
  6. */
  7. namespace app\controller\api\store\product;
  8. use app\common\repositories\store\product\ProductRepository;
  9. use app\common\repositories\system\groupData\GroupDataRepository;
  10. use app\controller\merchant\user\User;
  11. use app\Request;
  12. use think\App;
  13. use crmeb\basic\BaseController;
  14. use app\common\repositories\store\product\ProductRepository as repository;
  15. use think\Exception;
  16. use think\facade\Cache;
  17. use think\facade\Db;
  18. use think\facade\Log;
  19. class StoreProduct extends BaseController
  20. {
  21. /**
  22. * @var repository
  23. */
  24. protected $repository;
  25. protected $userInfo;
  26. private $source;
  27. private $merId;
  28. /**
  29. * StoreProduct constructor.
  30. * @param App $app
  31. * @param repository $repository
  32. */
  33. public function __construct(App $app, repository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  38. $this->source = request()->header('source');
  39. $this->merId = request()->header('merId');
  40. }
  41. /**
  42. * @Author:Qinii
  43. * @Date: 2020/5/28
  44. * @return mixed
  45. */
  46. public function lst()
  47. {
  48. [$page, $limit] = $this->getPage();
  49. $where = $this->request->params(['keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid']);
  50. return app('json')->success($this->repository->getApiSearch(null, $where, $page, $limit, $this->userInfo));
  51. }
  52. /**
  53. * @Author:Qinii
  54. * @Date: 2020/5/30
  55. * @param $id
  56. * @return mixed
  57. */
  58. public function detail($id)
  59. {
  60. $data = $this->repository->detail($id, $this->userInfo);
  61. $mer_status = Db::name('merchant')->where('mer_id', $data['mer_id'])->value('status');
  62. if ($mer_status != 1) {
  63. return app('json')->fail('商户已关闭');
  64. }
  65. // $data['yanglao'] = 11111;
  66. $merchent_type = Db::name('merchant')->where('mer_id', $data['mer_id'])->value('merchant_type');
  67. $data['merchant_type'] = $merchent_type;
  68. $seckill_status=0;
  69. $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');
  70. if ($data['seckill'] == 1 && $data['seckill_date_end']) {
  71. // $data['seckill_date_end'] = Db::name('product_seckill')->where('product_id', $data['product_id'])->where('status', 1)->value('seckill_date');
  72. $d = date('d', time());
  73. $newtime = date('H', time());
  74. $vd = date('d', strtotime($data['seckill_date_end']));
  75. $vtime = date('H', strtotime($data['seckill_date_end']));
  76. //1正在抢购 2 未开始 0 一结束
  77. if ($d < $vd) {
  78. $seckill_status=2;
  79. } else {
  80. if ($newtime < $vtime) {
  81. if ($d > $vd) {
  82. $seckill_status=0;
  83. } else {
  84. $seckill_status=2;
  85. }
  86. } else {
  87. if ($d > $vd||$newtime > $vtime) {
  88. $seckill_status=0;
  89. } else {
  90. $seckill_status=1;
  91. }
  92. }
  93. }
  94. // Db::name('log')->insert(['data'=>'商品秒杀状态'.$seckill_status]);
  95. $data['seckill_date_end']=date('Y-m-d H:i:s',strtotime($data['seckill_date_end'])+3600);
  96. }else{
  97. $data['seckill'] =0;
  98. }
  99. //$data['2222222']=11111;
  100. $data['seckill_s']=$seckill_status;
  101. if (!$data) return app('json')->fail('商品不存在');
  102. $data['dc_price']=set_price_rtrim($data['dc_price']);
  103. if ($id == 15323) {
  104. $data['year'] = '5年';
  105. $data['mark'] = '养老金金额(200)';
  106. }
  107. return app('json')->success($data);
  108. }
  109. public function getopenid()
  110. {
  111. $code=$this->request->params(['code']);
  112. if(empty($code['code'])){
  113. return app('json')->fail('参数:code 必填');
  114. }
  115. $openid=$this->repository->getopenid($code['code']);
  116. return app('json')->success($openid);
  117. }
  118. /**
  119. * @Author:T
  120. * @Date: 2021/11/03
  121. * @param $id
  122. * @return mixed
  123. */
  124. public function pay()
  125. {
  126. $price=$this->request->params(['price']);
  127. if(empty($price['price'])){
  128. return app('json')->fail('参数:price 必填');
  129. }
  130. $openid=$this->request->params(['openid']);
  131. if(empty($openid['openid'])){
  132. return app('json')->fail('参数:openid 必填');
  133. }
  134. $data = $this->repository->pay($price['price'],$openid['openid']);
  135. if (!$data) return app('json')->fail('商品不存在');
  136. return app('json')->success($data);
  137. }
  138. /**
  139. * @Author:Qinii
  140. * @Date: 2020/5/30
  141. * @return mixed
  142. */
  143. public function recommendList()
  144. {
  145. $mer_id = (int)$this->request->param('mer_id',0);
  146. [$page, $limit] = $this->getPage();
  147. if($this->source=='yhc' && $this->merId){
  148. $merId=$this->merId;
  149. } elseif($mer_id){
  150. $merId=$mer_id;
  151. } else{
  152. $merId=321;
  153. }
  154. return app('json')->success($this->repository->recommend($this->userInfo, $merId, $page, $limit, null, 'create_time', 5));
  155. }
  156. public function volunteer()
  157. {
  158. [$page, $limit] = $this->getPage();
  159. return app('json')->success($this->repository->recommend($this->userInfo, null, $page, $limit, 'volunteer'));
  160. }
  161. public function search_volunteer()
  162. {
  163. [$page, $limit] = $this->getPage();
  164. $key = $this->request->param('key');
  165. $cate_id = $this->request->param('cate_id', '');
  166. $uid='1824';
  167. try {
  168. $uid = $this->request->uid();
  169. }catch (Exception $exception){
  170. }
  171. return app('json')->success($this->repository->search_recommend($page, $limit, $key, $cate_id,$uid));
  172. }
  173. public function qrcode($id)
  174. {
  175. $param = $this->request->param('type');
  176. if (!$product = $this->repository->getWhere(['product_id' => $id, 'is_del' => 0]))
  177. return app('json')->fail('商品不存在');
  178. $url = $param == 'routine' ? $this->repository->routineQrCode($product, $this->request->userInfo()) : $this->repository->wxQrCode($product, $this->request->userInfo());
  179. if (!$url)
  180. return app('json')->fail('二维码生成失败');
  181. return app('json')->success(compact('url'));
  182. }
  183. public function getBagList()
  184. {
  185. [$page, $limit] = $this->getPage();
  186. return app('json')->success($this->repository->getBagList($this->repository->bagShow(), $page, $limit));
  187. }
  188. public function getBagrecomm()
  189. {
  190. $where = $this->repository->bagShow();
  191. $where['is_good'] = 1;
  192. return app('json')->success($this->repository->selectWhere($where));
  193. }
  194. public function getBagExplain()
  195. {
  196. $data = [
  197. 'explain' => systemConfig('promoter_explain'),
  198. 'data' => app()->make(GroupDataRepository::class)->groupData('promoter_config', 0),
  199. ];
  200. return app('json')->success($data);
  201. }
  202. public function hot($type)
  203. {
  204. [$page, $limit] = $this->getPage();
  205. return app('json')->success($this->repository->getApiSearch(null, ['hot_type' => $type, 'is_gift_bag' => 0, 'is_used' => 1], $page, $limit, $this->userInfo));
  206. }
  207. public function get_mp_access_token()
  208. {
  209. // $appid = 'wx82986c4471ce7efc';
  210. // $secret = '4ae3f790d8c5503a22579338504cdb61';
  211. $appid = 'wxfb755febdb800f23';
  212. $secret = '55ed00200ef0ec6662ca8502dc534a69';
  213. $access_token = Cache::get($appid . '_mp_access_token');
  214. if ($access_token)
  215. return $access_token;
  216. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
  217. $res = curlGet($url);
  218. Cache::set($appid . '_mp_access_token', $res['access_token'], $res['expires_in']);
  219. return $res['access_token'];
  220. }
  221. //生成邀请小程序码
  222. public function invite_code(){
  223. $uid = $this->request->param('uid',0);
  224. $type = 0;//0-储蓄保 1-国盛 2-一壶茶
  225. $imgId = $this->request->param('imgId',0);
  226. //删除老数据
  227. // DB::name('system_attachment')->where("create_time < '2023-12-21 09:39:40'")->whereIN('attachment_category_id',[8,9])->delete();
  228. $system_attachment=DB::name('system_attachment')->where('attachment_category_id',8)->where('user_id',$uid)->where('type',$type)->find();
  229. if($system_attachment){
  230. return $system_attachment['attachment_src'];
  231. }
  232. $user = app()->make(User::class);
  233. $access_token = $this->get_mp_access_token();
  234. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
  235. $data['scene'] = 'spread=' . $uid;
  236. // $data['page'] = 'pages/user/login/other-phone';
  237. $data['page'] = 'pages/user/login/register-agreement';
  238. $domain = $this->request->domain();
  239. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  240. // 域名中包含 "test.hebeiyhc.com'" 字符串
  241. $data['env_version'] = 'trial';
  242. }
  243. $res = $user->posturl($url, $data);
  244. //判断是否是 json格式
  245. if (is_null(json_decode($res))) {
  246. $new_file = (int)(microtime(true) * 1000);
  247. $dir = iconv("UTF-8", "GBK", "./public/mpqrcode");
  248. if (!file_exists($dir)) {
  249. mkdir($dir, 0777, true);
  250. }
  251. $path = $dir . '/' . $new_file . ".jpg";
  252. file_put_contents($path, $res);
  253. $key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg';
  254. $uploadType = (int)systemConfig('upload_type') ?: 1;
  255. $upload = \crmeb\services\UploadService::create($uploadType);
  256. if($uploadType != 1){
  257. $time = date('Y-m-d');
  258. $paths = "chuxubao/qrCode/" . $time . '/';
  259. $key = $paths.$key;
  260. }
  261. $res = $upload->to($path)->validate()->stream($res, $key);
  262. if ($res === false) {
  263. // return $upload->getError();
  264. } else {
  265. $info = $upload->getUploadInfo();
  266. $info['image_type'] = $uploadType;
  267. $insert['attachment_category_id']=8;
  268. $insert['attachment_name']=basename($info['dir']);
  269. $insert['attachment_src']=$info['dir'];
  270. $insert['upload_type']=3;
  271. $insert['user_type']=-1;
  272. $insert['share_image_id']=0;
  273. $insert['user_id']=$uid;
  274. $insert['type']=$type;
  275. DB::name('system_attachment')->insert($insert);
  276. return $info['dir'];
  277. }
  278. }else{
  279. $data=json_decode($res);
  280. //生成邀请小程序码------------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"}
  281. if(isset($data->errcode) && $data->errcode==40001){
  282. Cache::set('wx82986c4471ce7efc_mp_access_token', null);
  283. return $this->invite_code();
  284. }
  285. }
  286. //没有接收到数据流
  287. return "";
  288. }
  289. public function getQrCode($pid, $uid,$share_id)
  290. {
  291. $user = app()->make(User::class);
  292. $access_token = $this->get_mp_access_token();
  293. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
  294. // $data['scene'] = 'spread=' . $uid . '&goods_id=' . $pid;
  295. $data['scene'] = 'id=' . $pid . '&shareID=' . $share_id;
  296. $data['page'] = 'pages/store/product/detail';
  297. $domain = $this->request->domain();
  298. if(strpos($domain, 'test.hebeiyhc.com') !== false) {
  299. // 域名中包含 "test.hebeiyhc.com'" 字符串
  300. $data['env_version'] = 'trial';
  301. }
  302. $res = $user->posturl($url, $data);
  303. if(isset(json_decode($res,true)['errcode']) && json_decode($res,true)['errcode']=='40001'){
  304. Cache::delete('wx9082e5ac2fdb513f1_mp_access_token');
  305. $access_token = $this->get_mp_access_token();
  306. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
  307. $data['scene'] = 'id=' . $pid . '&shareID=' . $share_id;
  308. $data['page'] = 'pages/store/product/detail';
  309. $res = $user->posturl($url, $data);
  310. }
  311. //判断是否是 json格式
  312. if (is_null(json_decode($res))) {
  313. $new_file = (int)(microtime(true) * 1000);
  314. $dir = iconv("UTF-8", "GBK", "./public/mpqrcode");
  315. if (!file_exists($dir)) {
  316. mkdir($dir, 0777, true);
  317. }
  318. $path = $dir . '/' . $new_file . ".jpg";
  319. file_put_contents($path, $res);
  320. $imgurl = env('APP_URL') . "/mpqrcode/" . $new_file . ".jpg";
  321. return ['qrcode' => $imgurl, 'path' => $path];
  322. } else {
  323. //没有接收到数据流
  324. return false;
  325. }
  326. }
  327. public function product_share()
  328. {
  329. $id = $this->request->params(['pid'])['pid'];
  330. $type = $this->request->params(['type'])['type'] ?? 2;
  331. if (!$id) {
  332. return app('json')->fail('参数不正确');
  333. }
  334. try {
  335. $uid = $this->request->uid();
  336. $product_share_url = Db::name('product_share')->where('product_id',$id)->where('share_channel',$type)->where('`url` is not null')->value('url');
  337. //记录Sat
  338. $insert_data=[
  339. 'uid'=>$uid,
  340. 'product_id'=>$id,
  341. 'share_channel'=>$type,
  342. 'url'=>$product_share_url,
  343. 'ctime'=>date('Y-m-d')
  344. ];
  345. $res=Db::name('product_share')->insertGetId($insert_data);
  346. $product_share_id = $res;
  347. $share_id = $res;
  348. if(!$res)
  349. return app('json')->success('分享失败,请重新尝试');
  350. $pdata = Db::name('store_product')->where('product_id', $id)->column('image,price,store_name');
  351. //记录End
  352. if($type == 2 && $product_share_url){
  353. return app('json')->success([
  354. 'url' => $product_share_url,
  355. 'share_id' => $share_id
  356. ]);
  357. }
  358. if ($type == 1){
  359. // $res = [
  360. // 'url'=>$pdata[0]['image'],
  361. // 'share_id'=>$res
  362. // ];
  363. if ($id == 15323) {
  364. $res = $returndata = [
  365. 'url' => 'https://cdn.bjtdba.com/chuxubao/images/2024-04-16/5e928202404162007269551.jpg',
  366. 'share_id' => $share_id
  367. ];
  368. } else {
  369. $res = $this->good_friend($id, $share_id);
  370. }
  371. Db::name('product_share')->where('id',$product_share_id)->update(['url'=>$res['url']]);
  372. return app('json')->success($res);
  373. }
  374. if (empty($pdata)) {
  375. return app('json')->fail('获取商品信息失败');
  376. }
  377. $pdata = $pdata[0];
  378. $pic_list = array(
  379. $pdata['image'],
  380. );
  381. $qrcode = $this->getQrCode($id, $uid,$res);
  382. if (!$qrcode)
  383. return app('json')->fail('获取小程序二维码失败');
  384. $path = $qrcode['path'];
  385. $qrcode = $qrcode['qrcode'];
  386. $filename1 = time();
  387. $filename_shareimg = './public/shareimg/' . $filename1 . '.png';
  388. $bg_w = 800; // 背景图片宽度
  389. $bg_h = 1300; // 背景图片高度
  390. $background = imagecreatetruecolor($bg_w, $bg_h); // 背景图片
  391. imagecolorallocate($background, 0, 0, 0);
  392. $red = imagecolorallocate($background, 255, 255, 255);
  393. imagefill($background, 0, 0, $red);
  394. $pic_count = count($pic_list);
  395. $lineArr = array(); // 需要换行的位置
  396. $space_x = 3;
  397. $space_y = 3;
  398. $line_x = 0;
  399. switch ($pic_count) {
  400. case 1: // 中间位置并排
  401. $start_x = 0;
  402. $start_y = 0;
  403. $pic_w = intval($bg_w);
  404. $pic_h = intval(800);
  405. break;
  406. }
  407. foreach ($pic_list as $k => $pic_path) {
  408. if (!strstr($pic_path, 'http')) {
  409. $pic_path = 'https:' . $pic_path;
  410. }
  411. $kk = $k + 1;
  412. if (in_array($kk, $lineArr)) {
  413. $start_x = $line_x;
  414. $start_y = $start_y + $pic_h + $space_y;
  415. }
  416. $pathInfo = pathinfo($pic_path);
  417. $pathInfo['extension'] = $pathInfo['extension'] ?? 'jpg';
  418. switch (strtolower($pathInfo['extension'])) {
  419. case 'jpg':
  420. case 'jpeg':
  421. $imagecreatefromjpeg = 'imagecreatefromjpeg';
  422. break;
  423. case 'png':
  424. $imagecreatefromjpeg = 'imagecreatefrompng';
  425. break;
  426. case 'gif':
  427. default:
  428. $imagecreatefromjpeg = 'imagecreatefromstring';
  429. $pic_path = file_get_contents($pic_path);
  430. break;
  431. }
  432. $resource = $imagecreatefromjpeg($pic_path);
  433. if ($k == 0) {
  434. imagecopyresized($background, $resource, $start_x, $start_y, 0, 0, $pic_w, $pic_h, imagesx($resource), imagesy($resource)); // 最后两个参数为原始图片宽度和高度,倒数两个参数为copy时的图片宽度和高度
  435. }
  436. }
  437. header("Content-type: image/jpg");
  438. imagegif($background, $filename_shareimg);
  439. $filename = env('APP_URL').'/shareimg/' . $filename1 . '.png';
  440. $filelink = [
  441. 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  442. 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  443. ];
  444. $text = $pdata['store_name'];
  445. $t2 = array(
  446. 'text' => '',
  447. 'left' => 400,
  448. 'top' => 1020,
  449. 'fontPath' => $filelink['Bold'], //字体文件
  450. 'fontSize' => 24, //字号
  451. 'fontColor' => '255,255,255', //字体颜色
  452. 'angle' => 0,
  453. );
  454. $t1 = array(
  455. 'text' => $text,
  456. 'left' => 400,
  457. 'top' => 980,
  458. 'fontPath' => $filelink['Bold'], //字体文件
  459. 'fontSize' => 24, //字号
  460. 'fontColor' => '40,40,40', //字体颜色
  461. 'angle' => 0,
  462. );
  463. if (mb_strlen($text) > 10) {
  464. mb_substr($text, 0, 10);
  465. $t1 = array(
  466. 'text' => mb_substr($text, 0, 12),
  467. 'left' => 400,
  468. 'top' => 980,
  469. 'fontPath' => $filelink['Bold'], //字体文件
  470. 'fontSize' => 24, //字号
  471. 'fontColor' => '40,40,40', //字体颜色
  472. 'angle' => 0,
  473. );
  474. $t2 = array(
  475. 'text' => mb_substr($text, 12, 10) . "...",
  476. 'left' => 400,
  477. 'top' => 1020,
  478. 'fontPath' => $filelink['Bold'], //字体文件
  479. 'fontSize' => 24, //字号
  480. 'fontColor' => '40,40,40', //字体颜色
  481. 'angle' => 0,
  482. );
  483. }
  484. $config = array(
  485. 'image' => array(
  486. array(
  487. 'url' => $qrcode,//二维码资源
  488. 'stream' => 0,
  489. 'left' => 50,
  490. 'top' => 930,
  491. 'right' => 0,
  492. 'bottom' => 0,
  493. 'width' => 300,
  494. 'height' => 300,
  495. 'opacity' => 100
  496. )
  497. ),
  498. 'text' => array(
  499. $t1,
  500. $t2,
  501. array(
  502. 'text' => $pdata['price'],
  503. 'left' => 400,
  504. 'top' => 1080,
  505. 'fontPath' => $filelink['Normal'], //字体文件
  506. 'fontSize' => 26, //字号
  507. 'fontColor' => '255,0,0', //字体颜色
  508. 'angle' => 0,
  509. ),
  510. array(
  511. 'text' => '加入储蓄保,一起攒攒攒',
  512. 'left' => 400,
  513. 'top' => 1200,
  514. 'fontPath' => $filelink['Normal'], //字体文件
  515. 'fontSize' => 18, //字号
  516. 'fontColor' => '40,40,40', //字体颜色
  517. 'angle' => 0,
  518. )
  519. ),
  520. 'background' => $filename
  521. );
  522. $data = setSharePoster($config, 'routine/spread/poster');
  523. unlink($path);
  524. unlink($filename_shareimg);
  525. if (empty($data)) {
  526. return app('json')->fail('生成海报失败请重新尝试!');
  527. }
  528. Db::name('product_share')->where('id',$share_id)->update(['url'=>$data['dir']]);
  529. return app('json')->success(['url'=>$data['dir'],'share_id'=>$share_id]);
  530. } catch (\Exception $e) {
  531. log::info("生成海报失败请重新尝试".$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】');
  532. Db::name('log')->insert(['data'=>"生成海报失败请重新尝试".$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  533. unlink($path);
  534. unlink($filename_shareimg);
  535. return app('json')->fail('生成海报失败请重新尝试。');
  536. }
  537. }
  538. /**
  539. * 小程序任何界面分享都可以绑定邀请关系 故出这个接口,根据用户身份可以获取share_id
  540. * @return mixed
  541. */
  542. public function product_share_by_user()
  543. {
  544. $uid = $this->request->uid();
  545. $product_share_id = Db::name('product_share')->where('product_id', 0)->where('uid', $uid)->value('id');
  546. if(!$product_share_id){
  547. $insert_data = [
  548. 'uid' => $uid,
  549. 'product_id' => 0,
  550. 'share_channel' => 0,
  551. 'url' => '',
  552. 'ctime' => date('Y-m-d')
  553. ];
  554. $product_share_id = Db::name('product_share')->insertGetId($insert_data);
  555. if (!$product_share_id)
  556. return app('json')->success('分享失败,请重新尝试');;
  557. }
  558. return app('json')->success(['share_id' => $product_share_id]);
  559. }
  560. /**
  561. * @param $pdata
  562. * @param int $type 1-积分 2-秒杀
  563. * @return array
  564. */
  565. public function good_friend_integral($pdata,$type=1)
  566. {
  567. header("Content-type: image/jpg");
  568. // $filename = 'https://cdn.bjtdba.com/chuxubao/images/2023-10-10/e4bea202310102032462460.png';//普通商品
  569. $filelink = [
  570. 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  571. 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  572. ];
  573. if (!strstr($pdata['image'], 'http')) {
  574. $pdata['image'] = 'https:' . $pdata['image'];
  575. }
  576. if($type==2){
  577. $where=[
  578. 'ps.status'=>1,
  579. 'merchant.status' => 1,
  580. 'sp.is_del' =>0,
  581. 'sp.product_id' =>$pdata['product_id'],
  582. ];
  583. $product_data_time=Db::name('product_seckill')
  584. ->alias('ps')
  585. ->join('store_product sp','sp.product_id=ps.product_id')
  586. ->leftJoin('merchant merchant','sp.mer_id=merchant.mer_id')
  587. ->where('sp.is_show',1)
  588. ->where($where)->value('ps.seckill_date');
  589. // $ProductRepository=app() -> make(ProductRepository::class);
  590. // $yanglao=$ProductRepository->yanglaojin($pdata['product_id']);
  591. $pdata['seckill_price'] = Db::name('store_product_attr_value')->where('product_id', $pdata['product_id'])->value('dacang_price');
  592. $mer_fanyongbili = merchantConfig($pdata['mer_id'], 'base_commission');
  593. //如果商户返佣比例设置的是0怎查系统设设置的分佣比例
  594. if ($mer_fanyongbili == 0) {
  595. $mer_fanyongbili = merchantConfig(0, 'extension_one_rate');
  596. }
  597. $mer_fanyongbili=bcdiv($mer_fanyongbili, '100', 3);
  598. $yanglao= set_price_rtrim(bcmul(bcmul($pdata['seckill_price'],$mer_fanyongbili,2),'0.5',2));//养老金
  599. $filename='https://cdn.bjtdba.com/chuxubao/images/2023-10-24/4f2e3202310241717119393.png';//秒杀背景
  600. $config = array(
  601. 'text' => array(
  602. array(
  603. 'text' => $yanglao,
  604. 'left' => 160,
  605. 'top' => 300,
  606. 'fontPath' => $filelink['Normal'], //字体文件
  607. 'fontSize' => 16, //字号
  608. 'fontColor' => '254,18,64', //字体颜色
  609. 'angle' => 0,
  610. ),
  611. array(
  612. 'text' => $pdata['dc_price'],
  613. 'left' => 105,
  614. 'top' => 267,
  615. 'fontPath' => $filelink['Normal'], //字体文件
  616. 'fontSize' => 22, //字号
  617. 'fontColor' => '254,18,64', //字体颜色
  618. 'angle' => 0,
  619. ),
  620. array(
  621. 'text' => '立即购买',
  622. 'left' => 285,
  623. 'top' => 276,
  624. 'fontPath' => $filelink['Normal'], //字体文件
  625. 'fontSize' => 22, //字号
  626. 'fontColor' => '255,255,255', //字体颜色
  627. 'angle' => 0,
  628. ),
  629. array(
  630. 'text' =>date('m月d日 H点结束', strtotime($product_data_time)+3600),
  631. 'left' => 257,
  632. 'top' => 306,
  633. 'fontPath' => $filelink['Normal'], //字体文件
  634. 'fontSize' => 14, //字号
  635. 'fontColor' => '255,255,255', //字体颜色
  636. 'angle' => 0,)
  637. ),
  638. 'background' => $filename
  639. );
  640. }else{
  641. $filename = 'https://cdn.bjtdba.com/chuxubao/images/2023-10-24/c7ec9202310241544064190.png';//积分背景
  642. $config = array(
  643. 'text' => array(
  644. // array(
  645. // 'text' => $yanglao,
  646. // 'left' => 160,
  647. // 'top' => 315,
  648. // 'fontPath' => $filelink['Normal'], //字体文件
  649. // 'fontSize' => 16, //字号
  650. // 'fontColor' => '255,0,0', //字体颜色
  651. // 'angle' => 0,
  652. // ),
  653. array(
  654. 'text' => ($pdata['price']*30).'积分',
  655. 'left' => 35,
  656. 'top' => 295,
  657. 'fontPath' => $filelink['Normal'], //字体文件
  658. 'fontSize' => 22, //字号
  659. 'fontColor' => '254,0,50', //字体颜色
  660. 'angle' => 0,
  661. ),
  662. array(
  663. 'text' => '立即购买',
  664. 'left' => 275,
  665. 'top' => 296,
  666. 'fontPath' => $filelink['Normal'], //字体文件
  667. 'fontSize' => 26, //字号
  668. 'fontColor' => '255,255,255', //字体颜色
  669. 'angle' => 0,
  670. ),
  671. // array(
  672. // 'text' =>'让每一笔消费更有价值',
  673. // 'left' => 180,
  674. // 'top' => 413,
  675. // 'fontPath' => $filelink['Normal'], //字体文件
  676. // 'fontSize' => 18, //字号
  677. // 'fontColor' => '40,40,40', //字体颜色
  678. // 'angle' => 0,)
  679. ),
  680. 'background' => $filename
  681. );
  682. }
  683. if($pdata['type'] == 5){
  684. $config['image'] = [
  685. array(
  686. 'url' => $pdata['image'],//图片资源
  687. 'stream' => 0,
  688. 'left' => 127,
  689. 'top' => 15,
  690. 'right' => 0,
  691. 'bottom' => 0,
  692. 'width' => 204,
  693. 'height' => 204,
  694. 'opacity' => 100
  695. ),
  696. // array(
  697. // 'url' => 'https://cdn.bjtdba.com/vod/image/2022-07-11/20220711104440683.png',//图片资源
  698. // 'stream' => 0,
  699. // 'left' => 460,
  700. // 'top' => 162,
  701. // 'right' => 0,
  702. // 'bottom' => 0,
  703. // 'width' => 63,
  704. // 'height' => 28,
  705. // 'opacity' => 100
  706. // )
  707. ];
  708. }else{
  709. $config['image'] = [
  710. array(
  711. 'url' => $pdata['image'],//图片资源
  712. 'stream' => 0,
  713. 'left' => 127,
  714. 'top' => 15,
  715. 'right' => 0,
  716. 'bottom' => 0,
  717. 'width' => 204,
  718. 'height' => 204,
  719. 'opacity' => 100
  720. )
  721. ];
  722. }
  723. return $config;
  724. // $this->setSharePoster($config, 'routine/spread/poster');
  725. }
  726. function setSharePoster($config, $path)
  727. {
  728. $imageDefault = array(
  729. 'left' => 0,
  730. 'top' => 0,
  731. 'right' => 0,
  732. 'bottom' => 0,
  733. 'width' => 100,
  734. 'height' => 100,
  735. 'opacity' => 100
  736. );
  737. $textDefault = array(
  738. 'text' => '',
  739. 'left' => 0,
  740. 'top' => 0,
  741. 'fontSize' => 32, //字号
  742. 'fontColor' => '255,255,255', //字体颜色
  743. 'angle' => 0,
  744. );
  745. $background = $config['background'];//海报最底层得背景
  746. if (substr($background, 0, 1) === '/') {
  747. $background = substr($background, 1);
  748. }
  749. $backgroundInfo = getimagesize($background);
  750. $background = imagecreatefromstring(file_get_contents($background));
  751. $backgroundWidth = $backgroundInfo[0]; //背景宽度
  752. $backgroundHeight = $backgroundInfo[1]; //背景高度
  753. $imageRes = imageCreatetruecolor($backgroundWidth, $backgroundHeight);
  754. // $color = imagecolorallocate($imageRes, 0, 0, 0);
  755. $color = imagecolorallocate($imageRes, 255, 255, 255);
  756. imagefill($imageRes, 0, 0, $color);
  757. imagecopyresampled($imageRes, $background, 0, 0, 0, 0, imagesx($background), imagesy($background), imagesx($background), imagesy($background));
  758. if (!empty($config['image'])) {
  759. foreach ($config['image'] as $key => $val) {
  760. $val = array_merge($imageDefault, $val);
  761. $info = getimagesize($val['url']);
  762. $function = 'imagecreatefrom' . image_type_to_extension($info[2], false);
  763. if ($val['stream']) {
  764. $info = getimagesizefromstring($val['url']);
  765. $function = 'imagecreatefromstring';
  766. }
  767. $res = $function($val['url']);
  768. $resWidth = $info[0];
  769. $resHeight = $info[1];
  770. $canvas = imagecreatetruecolor($val['width'], $val['height']);
  771. imagefill($canvas, 0, 0, $color);
  772. imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
  773. $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) - $val['width'] : $val['left'];
  774. $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) - $val['height'] : $val['top'];
  775. imagecopymerge($imageRes, $canvas, $val['left'], $val['top'], $val['right'], $val['bottom'], $val['width'], $val['height'], $val['opacity']);//左,上,右,下,宽度,高度,透明度
  776. }
  777. }
  778. if (isset($config['text']) && !empty($config['text'])) {
  779. foreach ($config['text'] as $key => $val) {
  780. $val = array_merge($textDefault, $val);
  781. list($R, $G, $B) = explode(',', $val['fontColor']);
  782. $fontColor = imagecolorallocate($imageRes, $R, $G, $B);
  783. $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) : $val['left'];
  784. $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) : $val['top'];
  785. imagettftext($imageRes, $val['fontSize'], $val['angle'], $val['left'], $val['top'], $fontColor, $val['fontPath'], $val['text']);
  786. }
  787. }
  788. ob_start();
  789. $key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg';
  790. imagejpeg($imageRes,'./public/install/'.$key);
  791. imagedestroy($imageRes);
  792. // $res = ob_get_contents();
  793. // ob_end_clean();
  794. // 创建图像资源
  795. $imageRes = imagecreatefromjpeg('./public/install/'.$key);
  796. header('Content-Type: image/jpeg');
  797. imagejpeg($imageRes);
  798. imagedestroy($imageRes);
  799. // var_dump('http://172.16.0.44:8324/install/'.$key);
  800. }
  801. public function good_friend($id,$res)
  802. {
  803. $ProductRepository=app() -> make(ProductRepository::class);
  804. $pdata = Db::name('store_product')->where('product_id', $id)->column('product_id,image,price,store_name,mer_id,type,dc_price,dc_id,seckill');
  805. if (empty($pdata)) {
  806. return app('json')->fail('获取商品信息失败');
  807. }
  808. $pdata = $pdata[0];
  809. if( $pdata['mer_id']==148){//积分商品
  810. $config=$this->good_friend_integral($pdata);
  811. }else if($pdata['seckill']==1){
  812. $config=$this->good_friend_integral($pdata,2);
  813. }else{
  814. // $mmerchat_data = Db::name('merchant')->where('mer_id', $pdata['mer_id'])->find();
  815. // $mer_name = $mmerchat_data['mer_name'];
  816. $price = $pdata['price'];
  817. $yanglao=$ProductRepository->yanglaojin($pdata['product_id']);
  818. // if($pdata['type'] == 5){
  819. // $mer_name = Db::name('big_warehouse') -> where('id',$pdata['dc_id']) -> value('warehouse_name');
  820. // $price = $pdata['dc_price'];
  821. // }
  822. //mer_avatar logo
  823. header("Content-type: image/jpg");
  824. $filename = 'https://cdn.bjtdba.com/chuxubao/images/2023-10-10/e4bea202310102032462460.png';
  825. $filelink = [
  826. 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  827. 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  828. ];
  829. if (!strstr($pdata['image'], 'http')) {
  830. $pdata['image'] = 'https:' . $pdata['image'];
  831. }
  832. $config = array(
  833. 'text' => array(
  834. array(
  835. 'text' => $yanglao,
  836. 'left' => 160,
  837. 'top' => 315,
  838. 'fontPath' => $filelink['Normal'], //字体文件
  839. 'fontSize' => 16, //字号
  840. 'fontColor' => '255,0,0', //字体颜色
  841. 'angle' => 0,
  842. ),
  843. array(
  844. 'text' => $price,
  845. 'left' => 45,
  846. 'top' => 277,
  847. 'fontPath' => $filelink['Normal'], //字体文件
  848. 'fontSize' => 20, //字号
  849. 'fontColor' => '255,0,0', //字体颜色
  850. 'angle' => 0,
  851. ),
  852. /*array(
  853. 'text' => $strProductName,
  854. 'left' => 20,
  855. 'top' => 110,
  856. 'fontPath' => $filelink['Normal'], //字体文件
  857. 'fontSize' => 26, //字号
  858. 'fontColor' => '40,40,40', //字体颜色
  859. 'angle' => 0,
  860. ),
  861. array(
  862. 'text' =>'让每一笔消费更有价值',
  863. 'left' => 180,
  864. 'top' => 413,
  865. 'fontPath' => $filelink['Normal'], //字体文件
  866. 'fontSize' => 18, //字号
  867. 'fontColor' => '40,40,40', //字体颜色
  868. 'angle' => 0,)*/
  869. ),
  870. 'background' => $filename
  871. );
  872. if($pdata['type'] == 5){
  873. $config['image'] = [
  874. array(
  875. 'url' => $pdata['image'],//图片资源
  876. 'stream' => 0,
  877. 'left' => 127,
  878. 'top' => 15,
  879. 'right' => 0,
  880. 'bottom' => 0,
  881. 'width' => 204,
  882. 'height' => 204,
  883. 'opacity' => 100
  884. ),
  885. // array(
  886. // 'url' => 'https://cdn.bjtdba.com/vod/image/2022-07-11/20220711104440683.png',//图片资源
  887. // 'stream' => 0,
  888. // 'left' => 460,
  889. // 'top' => 162,
  890. // 'right' => 0,
  891. // 'bottom' => 0,
  892. // 'width' => 63,
  893. // 'height' => 28,
  894. // 'opacity' => 100
  895. // )
  896. ];
  897. }else{
  898. $config['image'] = [
  899. array(
  900. 'url' => $pdata['image'],//图片资源
  901. 'stream' => 0,
  902. 'left' => 127,
  903. 'top' => 15,
  904. 'right' => 0,
  905. 'bottom' => 0,
  906. 'width' => 204,
  907. 'height' => 204,
  908. 'opacity' => 100
  909. )
  910. ];
  911. }
  912. }
  913. $data = setSharePoster($config, 'routine/spread/poster');
  914. $returndata=[
  915. 'url'=>$data['dir'],
  916. 'share_id'=>$res
  917. ];
  918. return $returndata;
  919. // return app('json')->success(env('APP_URL') . $data['dir']);
  920. }
  921. /**
  922. * @return mixed
  923. * @throws \think\db\exception\DataNotFoundException
  924. * @throws \think\db\exception\DbException
  925. * @throws \think\db\exception\ModelNotFoundException
  926. * 总共分享次数及每条的展示
  927. */
  928. public function product_share_list()
  929. {
  930. $uid=$this->request->uid();
  931. [$page, $limit] = $this->getPage();
  932. $params=$this->request->params(['starTime','endTime']);
  933. $starTime=$params['starTime']??'';
  934. $endTime=$params['endTime']??'';
  935. if($starTime and $endTime){
  936. $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();
  937. if(!$data->isEmpty()){
  938. $data=$data->toArray();
  939. }else{
  940. return app('json')->fail('暂无数据');
  941. }
  942. // dd($data);
  943. foreach ($data as $k=>&$v){
  944. $v['list']=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->where('uid',$uid)->where('ctime',$v['ctime'])->select()->toArray();
  945. }
  946. //合计
  947. // $all_click_num=Db::name('product_share')->where('uid',$uid)->sum('click_num');
  948. // $all_buy_num=Db::name('product_share')->where('uid',$uid)->sum('buy_num');
  949. // $all_share_haoyou=Db::name('product_share')->where('uid',$uid)->where('share_channel',1)->count('id');
  950. // $all_share_pengyouquan=Db::name('product_share')->where('uid',$uid)->where('share_channel',2)->count('id');
  951. //合计结束
  952. foreach ($data as $key=>&$value){
  953. $value['ctime']=date('m/d',strtotime($value['ctime']));
  954. $value['click_num']=0;
  955. $value['buy_num']=0;
  956. $value['share_haoyou']=0;
  957. $value['share_pengyouquan']=0;
  958. foreach ($value['list'] as $item){
  959. $value['click_num']+=$item['click_num'];
  960. $value['buy_num']+=$item['buy_num'];
  961. if($item['share_channel']==1){
  962. $value['share_haoyou']++;
  963. }elseif($item['share_channel']==2){
  964. $value['share_pengyouquan']++;
  965. }
  966. }
  967. unset($data[$key]['list']);
  968. }
  969. //顶部数据
  970. $click=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->sum('click_num');
  971. $buy=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->sum('buy_num');
  972. $share=Db::name('product_share')->where('ctime','>=',$starTime)->where('ctime','<=',$endTime)->count('id');
  973. if($click){
  974. $product_click_rate=bcmul(bcdiv($click,$share,2),100).'%';
  975. }else{
  976. $product_click_rate='0%';
  977. }
  978. if($buy){
  979. $product_buy_rate=bcmul(bcdiv($buy,$click,2),100).'%';
  980. }else{
  981. $product_buy_rate='0%';
  982. }
  983. $returndata=[
  984. 'lower_data'=>$data,
  985. // 'middle_data'=>[
  986. // 'all_share_haoyou'=>$all_share_haoyou,
  987. // 'all_share_pengyouquan'=>$all_share_pengyouquan,
  988. // 'all_click_num'=>$all_click_num,
  989. // 'all_buy_num'=>$all_buy_num,
  990. // ],
  991. 'top_data'=>[
  992. 'product_click_rate'=>$product_click_rate,
  993. 'product_buy_rate'=>$product_buy_rate
  994. ]
  995. ];
  996. }else{
  997. $data=Db::name('product_share')->where('uid',$uid)->field('ctime')->page($page,$limit)->order('ctime','desc')->group('ctime')->select();
  998. if(!$data->isEmpty()){
  999. $data=$data->toArray();
  1000. }else{
  1001. return app('json')->fail('暂无数据');
  1002. }
  1003. // dd($data);
  1004. foreach ($data as $k=>&$v){
  1005. $v['list']=Db::name('product_share')->where('uid',$uid)->where('ctime',$v['ctime'])->select()->toArray();
  1006. }
  1007. //合计
  1008. // $all_click_num=Db::name('product_share')->where('uid',$uid)->sum('click_num');
  1009. // $all_buy_num=Db::name('product_share')->where('uid',$uid)->sum('buy_num');
  1010. // $all_share_haoyou=Db::name('product_share')->where('uid',$uid)->where('share_channel',1)->count('id');
  1011. // $all_share_pengyouquan=Db::name('product_share')->where('uid',$uid)->where('share_channel',2)->count('id');
  1012. //合计结束
  1013. foreach ($data as $key=>&$value){
  1014. $value['ctime']=date('m/d',strtotime($value['ctime']));
  1015. $value['click_num']=0;
  1016. $value['buy_num']=0;
  1017. $value['share_haoyou']=0;
  1018. $value['share_pengyouquan']=0;
  1019. foreach ($value['list'] as $item){
  1020. $value['click_num']+=$item['click_num'];
  1021. $value['buy_num']+=$item['buy_num'];
  1022. if($item['share_channel']==1){
  1023. $value['share_haoyou']++;
  1024. }elseif($item['share_channel']==2){
  1025. $value['share_pengyouquan']++;
  1026. }
  1027. }
  1028. unset($data[$key]['list']);
  1029. }
  1030. //顶部数据
  1031. $click=Db::name('product_share')->where('ctime',date('Y-m-d',time()))->sum('click_num');
  1032. $buy=Db::name('product_share')->where('ctime',date('Y-m-d',time()))->sum('buy_num');
  1033. $share=Db::name('product_share')->where('ctime',date('Y-m-d',time()))->count('id');
  1034. if($click){
  1035. $product_click_rate=bcmul(bcdiv($click,$share,2),100).'%';
  1036. }else{
  1037. $product_click_rate='0%';
  1038. }
  1039. if($buy){
  1040. $product_buy_rate=bcmul(bcdiv($buy,$click,2),100).'%';
  1041. }else{
  1042. $product_buy_rate='0%';
  1043. }
  1044. $returndata=[
  1045. 'lower_data'=>$data,
  1046. // 'middle_data'=>[
  1047. // 'all_share_haoyou'=>$all_share_haoyou,
  1048. // 'all_share_pengyouquan'=>$all_share_pengyouquan,
  1049. // 'all_click_num'=>$all_click_num,
  1050. // 'all_buy_num'=>$all_buy_num,
  1051. // ],
  1052. 'top_data'=>[
  1053. 'product_click_rate'=>$product_click_rate,
  1054. 'product_buy_rate'=>$product_buy_rate
  1055. ]
  1056. ];
  1057. }
  1058. return app('json')->success($returndata);
  1059. }
  1060. /**
  1061. * 关注列表- 志愿者
  1062. */
  1063. public function volunteer_list()
  1064. {
  1065. $uid = $this->request->uid();
  1066. $keys=$this->request->param('keys');
  1067. [$page, $limit] = $this->getPage();
  1068. //顶部数据
  1069. $volunteer_id=Db::name('store_product')->where('volunteer',1)->group('mer_id')->column('mer_id');
  1070. $top_data = Db::name('user_relation')
  1071. ->alias('u_r')
  1072. ->leftJoin('merchant m', 'm.mer_id=u_r.type_id')
  1073. // ->join('store_product s_p', 'm.mer_id=s_p.mer_id')
  1074. ->where('u_r.type', 10)
  1075. ->where('mer_id','in',$volunteer_id)
  1076. ->where('u_r.uid', $uid)
  1077. ->where('m.mer_state', 1)
  1078. ->where('m.is_del', 0)
  1079. // ->where('s_p.volunteer', 1)
  1080. // ->where('s_p.is_show', 1)
  1081. // ->where('s_p.is_used ', 1)
  1082. ->page($page,$limit)
  1083. ->field('m.mer_id,m.mer_avatar,m.mer_name')
  1084. ->select();
  1085. // dd($top_data->toArray());
  1086. $top_data = $top_data->toArray();
  1087. $top_data = array_unique($top_data, SORT_REGULAR);
  1088. //页面中间数据
  1089. $ids = '';
  1090. foreach ($top_data as $k => $v) {
  1091. $ids .= $v['mer_id'] . ',';
  1092. }
  1093. $ids = rtrim($ids, ',');
  1094. //根据ID 查到商户
  1095. if($keys){
  1096. $middle_data=Db::name('merchant')
  1097. ->alias('m')
  1098. ->leftJoin('store_product s_p','s_p.mer_id=m.mer_id')
  1099. ->whereLike('m.mer_name','%'.$keys.'%')
  1100. ->where('m.mer_state', 1)
  1101. ->where('m.is_del', 0)
  1102. ->where('s_p.volunteer', 1)
  1103. ->where('s_p.is_show', 1)
  1104. ->where('s_p.is_used ', 1)
  1105. ->field('m.*')
  1106. ->page($page,$limit)
  1107. ->select()
  1108. ;
  1109. }else{
  1110. $middle_data = Db::name('merchant')
  1111. ->alias('m')
  1112. // ->leftJoin('store_product s_p','m.mer_id=s_p.mer_id')
  1113. ->whereIn('m.mer_id', $ids)
  1114. ->where('m.mer_state', 1)
  1115. ->where('m.is_del', 0)
  1116. //
  1117. ->field('m.mer_id,m.mer_avatar,m.mer_name,m.sales,m.renqizhi')
  1118. ->select();
  1119. }
  1120. $middle_data = $middle_data->toArray();
  1121. $middle_data = array_unique($middle_data, SORT_REGULAR);
  1122. foreach ($middle_data as $key => &$value) {
  1123. //是否关注循环判断
  1124. $is_arr=Db::name('user_relation')->where(['uid'=>$uid,'type_id'=>$value['mer_id'],'type'=>10])->count('uid');
  1125. if($is_arr>=1){
  1126. $value['is_follow']=1;
  1127. }else{
  1128. $value['is_follow']=0;
  1129. }
  1130. //拿到商品数据
  1131. $middle_product_data = Db::name('store_product')
  1132. ->alias('s_p')
  1133. ->where('s_p.mer_id', $value['mer_id'])
  1134. ->where('s_p.volunteer', 1)
  1135. ->where('s_p.is_show', 1)
  1136. ->where('s_p.is_used ', 1)
  1137. ->limit('3')
  1138. ->select();
  1139. if (!$middle_product_data->isEmpty()) {
  1140. $middle_product_data = $middle_product_data->toArray();
  1141. }
  1142. $value['product'] = $middle_product_data;
  1143. }
  1144. // dd($middle_data);
  1145. //底部数据
  1146. $lower_data=Db::name('user_visit')
  1147. ->alias('uv')
  1148. ->leftJoin('store_product sp','uv.type_id=sp.product_id')
  1149. ->leftJoin('merchant m','m.mer_id=sp.mer_id')
  1150. ->where('uv.type','product')
  1151. ->where('uv.uid',$uid)
  1152. ->group('type_id')
  1153. -> where('m.mer_state',1)
  1154. -> where('m.is_del',0)
  1155. ->limit('10')
  1156. ->page($page,$limit)
  1157. ->field('m.mer_id,m.mer_avatar,m.mer_name,m.sales,m.renqizhi')
  1158. ->select();
  1159. if(!$lower_data->isEmpty()){
  1160. $lower_data=$lower_data->toArray();
  1161. }
  1162. //循环处理数据
  1163. foreach ($lower_data as $key => &$value) {
  1164. //是否关注
  1165. $is_arr=Db::name('user_relation')->where(['uid'=>$uid,'type_id'=>$value['mer_id'],'type'=>10])->count('uid');
  1166. if($is_arr>=1){
  1167. $value['is_follow']=1;
  1168. }else{
  1169. $value['is_follow']=1;
  1170. }
  1171. //商品数据
  1172. $lower_product_data = Db::name('store_product')
  1173. ->alias('s_p')
  1174. ->where('s_p.mer_id', $value['mer_id'])
  1175. ->where('s_p.volunteer', 1)
  1176. ->where('s_p.is_show', 1)
  1177. ->where('s_p.is_used ', 1)
  1178. ->limit('3')
  1179. ->select();
  1180. if (!$lower_product_data->isEmpty()) { //有志愿者商品 转成数组下一步
  1181. $lower_product_data = $lower_product_data->toArray();
  1182. }else{ //没有志愿者商品 跳出此次循环 并删除当前数据
  1183. unset($lower_data[$key]);
  1184. continue;
  1185. }
  1186. //拼装数据
  1187. $value['product'] = $lower_product_data;
  1188. }
  1189. //根据 是否关注排序 is_follow
  1190. $lower_data=$this->arraySort($lower_data, 'is_follow', SORT_ASC);
  1191. $is_have=1;
  1192. foreach ($lower_data as $kk=>$vv){
  1193. // dd($vv);
  1194. if($vv['is_follow']==0){
  1195. $is_have=2;
  1196. }
  1197. }
  1198. //上一步的数据是否有未关注的商家 有 返回 没有重新查一下
  1199. if(empty($lower_data) || $is_have==1){
  1200. $lower_data=$this->lower_data($page,$limit,$uid);
  1201. $lower_data=array_merge($lower_data);
  1202. if(!empty($lower_data)){
  1203. foreach ($lower_data['lower_data']as $k=>&$v){
  1204. $is_arr=Db::name('user_relation')->where(['uid'=>$uid,'type_id'=>$v['mer_id'],'type'=>10])->count('uid');
  1205. if($is_arr>=1){
  1206. $v['is_follow']=1;
  1207. }else{
  1208. $v['is_follow']=0;
  1209. }
  1210. }
  1211. $lower_data=$this->arraySort($lower_data['lower_data'], 'is_follow', SORT_ASC);
  1212. }
  1213. }
  1214. return app('json')->success(compact('top_data', 'middle_data','lower_data'));
  1215. }
  1216. public function lower_data($page,$limit,$uid)
  1217. {
  1218. $user_follow=Db::name('user_relation')->where('uid',$uid)->where('type',10)->column('type_id');
  1219. $user_follow=implode(',',$user_follow);
  1220. $lower_data=Db::name('store_product')
  1221. ->alias('sp')
  1222. ->join('merchant m','sp.mer_id=m.mer_id')
  1223. ->whereNotIn('m.mer_id',$user_follow)
  1224. ->where('sp.volunteer',1)
  1225. ->group('sp.mer_id')
  1226. ->order('sp.sales desc')
  1227. ->page($page,'5')
  1228. ->field('m.mer_id,m.mer_avatar,m.mer_name,m.sales,m.renqizhi')
  1229. ->select();
  1230. if (!$lower_data->isEmpty()) {
  1231. $lower_data = $lower_data->toArray();
  1232. }else{
  1233. return [];
  1234. }
  1235. foreach ($lower_data as $key => &$value) {
  1236. $lower_product_data = Db::name('store_product')
  1237. ->alias('s_p')
  1238. ->where('s_p.mer_id', $value['mer_id'])
  1239. ->where('s_p.volunteer', 1)
  1240. ->where('s_p.is_show', 1)
  1241. ->where('s_p.is_used ', 1)
  1242. ->limit('3')
  1243. ->select();
  1244. if (!$lower_product_data->isEmpty()) {
  1245. $lower_product_data = $lower_product_data->toArray();
  1246. }else{
  1247. unset($lower_data[$key]);
  1248. continue;
  1249. }
  1250. $value['product'] = $lower_product_data;
  1251. }
  1252. return compact('lower_data','page');
  1253. }
  1254. /**
  1255. * 二维数组根据某个字段排序
  1256. * @param array $array 要排序的数组
  1257. * @param string $keys 要排序的键字段
  1258. * @param string $sort 排序类型 SORT_ASC SORT_DESC
  1259. * @return array 排序后的数组
  1260. */
  1261. function arraySort($array, $keys, $sort = SORT_DESC) {
  1262. $keysValue = [];
  1263. foreach ($array as $k => $v) {
  1264. $keysValue[$k] = $v[$keys];
  1265. }
  1266. array_multisort($keysValue, $sort, $array);
  1267. return $array;
  1268. }
  1269. /**
  1270. * 分享点击
  1271. */
  1272. public function buy_product_share($id)
  1273. {
  1274. Db::name('product_share')->where('id',$id)->inc('click_num')->update();
  1275. return app('json')->success('success');
  1276. }
  1277. /**
  1278. * 分享购买
  1279. */
  1280. public function click_product_share($id)
  1281. {
  1282. Db::name('product_share')->where('id',$id)->inc('buy_num')->update();
  1283. return app('json')->success('success');
  1284. }
  1285. //大仓会员商品列表
  1286. public function dacang_lst()
  1287. {
  1288. [$page, $limit] = $this->getPage();
  1289. $type=$this->request->param('type');
  1290. if ($type == '2'){
  1291. //银卡会员商品
  1292. $product_id = explode('=',systemConfig('product_ids_yin'));
  1293. }else{
  1294. //金卡会员商品
  1295. $product_id = explode('=',systemConfig('product_ids'));
  1296. }
  1297. $product_lst=Db::name('store_product')->page($page,$limit)->whereIn('product_id',$product_id)->field('image,store_name,product_id,sales')->select()->toArray();
  1298. $count=Db::name('store_product')->whereIn('product_id',$product_id)->count('product_id');
  1299. $ProductRepository=app() -> make(ProductRepository::class);
  1300. foreach ($product_lst as $k=>&$v){
  1301. $v['yanglao']=$ProductRepository->yanglaojin($v['product_id']);
  1302. $product_attr_value=Db::name('store_product_attr_value')->where('product_id',$v['product_id'])->field('unique,ot_price,price') -> find();
  1303. $v['product_attr_unique'] = $product_attr_value['unique'];
  1304. $v['ot_price'] = $product_attr_value['ot_price'];
  1305. $v['price'] = $product_attr_value['price'];
  1306. }
  1307. $return_data=[
  1308. 'list'=>$product_lst,
  1309. 'count'=>$count
  1310. ];
  1311. return app('json')->success($return_data);
  1312. }
  1313. }