|
|
@@ -0,0 +1,147 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
|
+// | 开源版本可自由商用,可去除界面版权logo
|
|
|
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
|
+// | github下载:https://github.com/likeshop-github/likeadmin
|
|
|
+// | 访问官网:https://www.likeadmin.cn
|
|
|
+// | likeadmin团队 版权所有 拥有最终解释权
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | author: likeadminTeam
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+
|
|
|
+namespace app\adminapi\logic\group_activity;
|
|
|
+
|
|
|
+
|
|
|
+use think\Exception;
|
|
|
+use think\facade\Db;
|
|
|
+use think\facade\Log;
|
|
|
+use app\common\logic\BaseLogic;
|
|
|
+use app\common\model\group_activity\GroupActivity;
|
|
|
+use app\common\service\wechat\WeChatMnpService;
|
|
|
+use app\common\model\group_activity\GroupActivityCategory;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 拼团活动分类逻辑
|
|
|
+ * Class GroupActivityCategoryLogic
|
|
|
+ * @package app\adminapi\logic\group_activity
|
|
|
+ */
|
|
|
+class GroupActivityCategoryLogic extends BaseLogic
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 添加
|
|
|
+ * @param array $params
|
|
|
+ * @return bool
|
|
|
+ * @author likeadmin
|
|
|
+ * @date 2025/03/13 10:31
|
|
|
+ */
|
|
|
+ public static function add(array $params): bool
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params['block_data'] = json_encode($params['block_data']);
|
|
|
+ $params['images'] = implode(",",$params['images']);
|
|
|
+ GroupActivityCategory::create([
|
|
|
+ 'title' => $params['title'],
|
|
|
+ 'images' => $params['images'],
|
|
|
+ 'block_data' => $params['block_data'],
|
|
|
+ 'status' => $params['status'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 编辑拼团活动
|
|
|
+ * @param array $params
|
|
|
+ * @return bool
|
|
|
+ * @author likeadmin
|
|
|
+ * @date 2025/03/13 10:31
|
|
|
+ */
|
|
|
+ public static function edit(array $params): bool
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $params['block_data'] = json_encode($params['block_data']);
|
|
|
+ $params['images'] = implode(",",$params['images']);
|
|
|
+ GroupActivityCategory::where('id', $params['id'])->update([
|
|
|
+ 'title' => $params['title'],
|
|
|
+ 'images' => $params['images'],
|
|
|
+ 'block_data' => $params['block_data'],
|
|
|
+ 'status' => $params['status'],
|
|
|
+ ]);
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 删除
|
|
|
+ * @param array $params
|
|
|
+ * @return bool
|
|
|
+ * @author likeadmin
|
|
|
+ * @date 2025/03/13 10:31
|
|
|
+ */
|
|
|
+ public static function delete(array $params): bool
|
|
|
+ {
|
|
|
+ return GroupActivityCategory::destroy($params['id']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 获取拼团活动详情
|
|
|
+ * @param $params
|
|
|
+ * @return array
|
|
|
+ * @author likeadmin
|
|
|
+ * @date 2025/03/13 10:31
|
|
|
+ */
|
|
|
+ public static function detail($params): array
|
|
|
+ {
|
|
|
+ $detail = GroupActivityCategory::findOrEmpty($params['id'])->toArray();
|
|
|
+ $detail['block_data'] = $detail['block_data'] ? json_decode($detail['block_data'],true) : [];
|
|
|
+ $detail['images'] = $detail['images'] ? explode(",",$detail['images']) : [];
|
|
|
+ $detail['activity'] = GroupActivity::with('goods')->field('id,equity_id,title,image')->select()->toArray();
|
|
|
+ return $detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取二维码
|
|
|
+ * @return string|void
|
|
|
+ */
|
|
|
+ public static function getQRCode($params,$url)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $mnp_page = 'pages/web_view/group_catogory';
|
|
|
+
|
|
|
+ $scene_page = 'group';
|
|
|
+ Log::info('getQRCode:'.rawurlencode($scene_page));
|
|
|
+ $response = (new WeChatMnpService())->getUnlimitedQRCode(
|
|
|
+ 'page='.$scene_page.'&id='.$params['id'],
|
|
|
+ $mnp_page,
|
|
|
+ env('miniprogram.mini_env_version', 'release'),
|
|
|
+ false
|
|
|
+ );
|
|
|
+ Log::info('getQRCode:'.json_encode([$response]));
|
|
|
+ $qrcode = $response->getContent();
|
|
|
+ if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
|
|
|
+ mkdir('./uploads/wx_qrcode/'.date('Ymd'));
|
|
|
+ }
|
|
|
+ $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
|
|
|
+ file_put_contents($file_name, $qrcode);
|
|
|
+ return $url.'/'.$file_name;
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ Log::info('getQRCode:'.$e->getMessage());
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|