PropertyActivityLogic.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\property;
  15. use app\common\model\property\PropertyActivity;
  16. use app\common\logic\BaseLogic;
  17. use app\common\service\wechat\WeChatMnpService;
  18. use think\Exception;
  19. use think\facade\Db;
  20. use think\facade\Log;
  21. /**
  22. * PropertyActivity逻辑
  23. * Class PropertyActivityLogic
  24. * @package app\adminapi\logic
  25. */
  26. class PropertyActivityLogic extends BaseLogic
  27. {
  28. /**
  29. * @notes 添加
  30. * @param array $params
  31. * @return bool
  32. * @author likeadmin
  33. * @date 2024/11/21 15:04
  34. */
  35. public static function add(array $params): bool
  36. {
  37. Db::startTrans();
  38. try {
  39. PropertyActivity::create([
  40. 'property_head_id' => $params['property_head_id'],
  41. 'activity_name' => $params['activity_name'],
  42. 'activity_start_time' => $params['activity_start_time'],
  43. 'activity_end_time' => $params['activity_end_time'],
  44. 'url_page' => $params['url_page']??'',
  45. 'page_type' => $params['page_type']??0,
  46. ]);
  47. Db::commit();
  48. return true;
  49. } catch (\Exception $e) {
  50. Db::rollback();
  51. self::setError($e->getMessage());
  52. return false;
  53. }
  54. }
  55. /**
  56. * @notes 编辑
  57. * @param array $params
  58. * @return bool
  59. * @author likeadmin
  60. * @date 2024/11/21 15:04
  61. */
  62. public static function edit(array $params): bool
  63. {
  64. Db::startTrans();
  65. try {
  66. PropertyActivity::where('id', $params['id'])->update([
  67. 'property_head_id' => $params['property_head_id'],
  68. 'activity_name' => $params['activity_name'],
  69. 'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0,
  70. 'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0,
  71. 'block_data' => json_encode($params['block_data']??[]),
  72. 'url_page' => $params['url_page']??'',
  73. 'page_type' => $params['page_type']??0,
  74. ]);
  75. Db::commit();
  76. return true;
  77. } catch (\Exception $e) {
  78. Db::rollback();
  79. self::setError($e->getMessage());
  80. return false;
  81. }
  82. }
  83. /**
  84. * @notes 删除
  85. * @param array $params
  86. * @return bool
  87. * @author likeadmin
  88. * @date 2024/11/21 15:04
  89. */
  90. public static function delete(array $params): bool
  91. {
  92. return PropertyActivity::destroy($params['id']);
  93. }
  94. /**
  95. * @notes 获取详情
  96. * @param $params
  97. * @return array
  98. * @author likeadmin
  99. * @date 2024/11/21 15:04
  100. */
  101. public static function detail($params): array
  102. {
  103. return PropertyActivity::findOrEmpty($params['id'])->toArray();
  104. }
  105. public static function getQRCode($params)
  106. {
  107. try {
  108. // $mnp_page = (isset($params['mnp_page']) && $params['mnp_page'])?urldecode($params['mnp_page']):env('miniprogram.property_activity_qrcode', '');
  109. $mnp_page = 'pages/web_view/index';
  110. if(empty($params['mnp_page'])){
  111. throw new Exception('路径错误');
  112. }
  113. $scene_page = (isset($params['mnp_page']) && $params['mnp_page'])? $params['mnp_page']:'';
  114. Log::info('getQRCode:'.rawurlencode($scene_page));
  115. $response = (new WeChatMnpService())->getUnlimitedQRCode(
  116. 'page='.$scene_page.'&id='.$params['id'],
  117. $mnp_page,
  118. env('miniprogram.mini_env_version', 'release'),
  119. false
  120. );
  121. Log::info('getQRCode:'.json_encode([$response]));
  122. $qrcode = $response->getContent();
  123. if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
  124. mkdir('./uploads/wx_qrcode/'.date('Ymd'));
  125. }
  126. $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
  127. file_put_contents($file_name, $qrcode);
  128. //$file_name = 'https://fushencdn.kyjlkj.com/uploads/miniqrcode/27f140aae615bbe16c1e888c14c9ab10.png';
  129. return 'https://weixiu.zhongdunzhizhao.com/'.$file_name;
  130. } catch (\Throwable $e) {
  131. Log::info('getQRCode:'.$e->getMessage());
  132. return '';
  133. }
  134. }
  135. }