PropertyActivityLogic.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\facade\Db;
  19. use think\facade\Log;
  20. /**
  21. * PropertyActivity逻辑
  22. * Class PropertyActivityLogic
  23. * @package app\adminapi\logic
  24. */
  25. class PropertyActivityLogic extends BaseLogic
  26. {
  27. /**
  28. * @notes 添加
  29. * @param array $params
  30. * @return bool
  31. * @author likeadmin
  32. * @date 2024/11/21 15:04
  33. */
  34. public static function add(array $params): bool
  35. {
  36. Db::startTrans();
  37. try {
  38. PropertyActivity::create([
  39. 'property_head_id' => $params['property_head_id'],
  40. 'activity_name' => $params['activity_name'],
  41. 'activity_start_time' => $params['activity_start_time'],
  42. 'activity_end_time' => $params['activity_end_time'],
  43. 'url_page' => $params['url_page']??'',
  44. 'page_type' => $params['page_type']??0,
  45. ]);
  46. Db::commit();
  47. return true;
  48. } catch (\Exception $e) {
  49. Db::rollback();
  50. self::setError($e->getMessage());
  51. return false;
  52. }
  53. }
  54. /**
  55. * @notes 编辑
  56. * @param array $params
  57. * @return bool
  58. * @author likeadmin
  59. * @date 2024/11/21 15:04
  60. */
  61. public static function edit(array $params): bool
  62. {
  63. Db::startTrans();
  64. try {
  65. PropertyActivity::where('id', $params['id'])->update([
  66. 'property_head_id' => $params['property_head_id'],
  67. 'activity_name' => $params['activity_name'],
  68. 'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0,
  69. 'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0,
  70. 'block_data' => json_encode($params['block_data']??[]),
  71. 'url_page' => $params['url_page']??'',
  72. 'page_type' => $params['page_type']??0,
  73. ]);
  74. Db::commit();
  75. return true;
  76. } catch (\Exception $e) {
  77. Db::rollback();
  78. self::setError($e->getMessage());
  79. return false;
  80. }
  81. }
  82. /**
  83. * @notes 删除
  84. * @param array $params
  85. * @return bool
  86. * @author likeadmin
  87. * @date 2024/11/21 15:04
  88. */
  89. public static function delete(array $params): bool
  90. {
  91. return PropertyActivity::destroy($params['id']);
  92. }
  93. /**
  94. * @notes 获取详情
  95. * @param $params
  96. * @return array
  97. * @author likeadmin
  98. * @date 2024/11/21 15:04
  99. */
  100. public static function detail($params): array
  101. {
  102. return PropertyActivity::findOrEmpty($params['id'])->toArray();
  103. }
  104. public static function getQRCode($params)
  105. {
  106. try {
  107. $mnp_page = (isset($params['mnp_page']) && $params['mnp_page'])?urldecode($params['mnp_page']):env('miniprogram.property_activity_qrcode', '');
  108. //$mnp_page = env('miniprogram.property_activity_qrcode', '');
  109. Log::info('getQRCode:'.json_encode([$params,$mnp_page]));
  110. $response = (new WeChatMnpService())->getUnlimitedQRCode(
  111. 'property_activity_id='.$params['id'],
  112. $mnp_page,
  113. env('miniprogram.mini_env_version', 'release'),
  114. false
  115. );
  116. Log::info('getQRCode:'.json_encode([$response]));
  117. $qrcode = $response->getContent();
  118. if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
  119. mkdir('./uploads/wx_qrcode/'.date('Ymd'));
  120. }
  121. $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
  122. file_put_contents($file_name, $qrcode);
  123. //$file_name = 'https://fushencdn.kyjlkj.com/uploads/miniqrcode/27f140aae615bbe16c1e888c14c9ab10.png';
  124. return 'https://weixiu.zhongdunzhizhao.com/'.$file_name;
  125. } catch (\Throwable $e) {
  126. Log::info('getQRCode:'.$e->getMessage());
  127. return '';
  128. }
  129. }
  130. }