| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?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\property;
- use app\common\model\property\PropertyActivity;
- use app\common\logic\BaseLogic;
- use app\common\service\wechat\WeChatMnpService;
- use think\facade\Db;
- use think\facade\Log;
- /**
- * PropertyActivity逻辑
- * Class PropertyActivityLogic
- * @package app\adminapi\logic
- */
- class PropertyActivityLogic extends BaseLogic
- {
- /**
- * @notes 添加
- * @param array $params
- * @return bool
- * @author likeadmin
- * @date 2024/11/21 15:04
- */
- public static function add(array $params): bool
- {
- Db::startTrans();
- try {
- PropertyActivity::create([
- 'property_head_id' => $params['property_head_id'],
- 'activity_name' => $params['activity_name'],
- 'activity_start_time' => $params['activity_start_time'],
- 'activity_end_time' => $params['activity_end_time'],
- ]);
- Db::commit();
- return true;
- } catch (\Exception $e) {
- Db::rollback();
- self::setError($e->getMessage());
- return false;
- }
- }
- /**
- * @notes 编辑
- * @param array $params
- * @return bool
- * @author likeadmin
- * @date 2024/11/21 15:04
- */
- public static function edit(array $params): bool
- {
- Db::startTrans();
- try {
- PropertyActivity::where('id', $params['id'])->update([
- 'property_head_id' => $params['property_head_id'],
- 'activity_name' => $params['activity_name'],
- 'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0,
- 'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0,
- ]);
- Db::commit();
- return true;
- } catch (\Exception $e) {
- Db::rollback();
- self::setError($e->getMessage());
- return false;
- }
- }
- /**
- * @notes 删除
- * @param array $params
- * @return bool
- * @author likeadmin
- * @date 2024/11/21 15:04
- */
- public static function delete(array $params): bool
- {
- return PropertyActivity::destroy($params['id']);
- }
- /**
- * @notes 获取详情
- * @param $params
- * @return array
- * @author likeadmin
- * @date 2024/11/21 15:04
- */
- public static function detail($params): array
- {
- return PropertyActivity::findOrEmpty($params['id'])->toArray();
- }
- public static function getQRCode($params)
- {
- try {
- $response = (new WeChatMnpService())->getUnlimitedQRCode(
- '&property_activity_id='.$params['id'],
- env('miniprogram.property_activity_qrcode', ''),
- env('miniprogram.mini_env_version', 'release'),
- false
- );
- $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);
- //$file_name = 'https://fushencdn.kyjlkj.com/uploads/miniqrcode/27f140aae615bbe16c1e888c14c9ab10.png';
- return 'https://weixiu.zhongdunzhizhao.com/'.$file_name;
- } catch (\Throwable $e) {
- Log::info('getQRCode:'.$e->getMessage());
- return '';
- }
- }
- }
|