GroupActivityLogic.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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\group_activity;
  15. use think\Exception;
  16. use think\facade\Db;
  17. use think\facade\Log;
  18. use app\common\logic\BaseLogic;
  19. use app\common\service\wechat\WeChatMnpService;
  20. use app\common\model\group_activity\GroupActivity;
  21. /**
  22. * 拼团活动逻辑
  23. * Class GroupActivityLogic
  24. * @package app\adminapi\logic\group_activity
  25. */
  26. class GroupActivityLogic extends BaseLogic
  27. {
  28. /**
  29. * @notes 添加拼团活动
  30. * @param array $params
  31. * @return bool
  32. * @author likeadmin
  33. * @date 2025/03/13 10:31
  34. */
  35. public static function add(array $params): bool
  36. {
  37. Db::startTrans();
  38. try {
  39. if ($params['type'] == 1) {
  40. $params['price'] = $params['price'][0];
  41. $params['participant_num'] = $params['participant_num'][0];
  42. } else {
  43. $params['price'] = implode(",",$params['price']);
  44. $params['participant_num'] = implode(",",$params['participant_num']);
  45. }
  46. if ($params['is_simulate_form'] == 1) {
  47. $params['simulate_num'] = $params['type'] == 1 ? $params['simulate_num'][0] : implode(",",$params['simulate_num']);
  48. } else {
  49. $params['simulate_num'] = '';
  50. }
  51. $params['area'] = implode(",",$params['area']);
  52. GroupActivity::create([
  53. 'title' => $params['title'],
  54. 'image' => $params['image'],
  55. 'equity_id' => $params['equity_id'],
  56. 'origin_price' => $params['origin_price'],
  57. 'price' => $params['price'],
  58. 'start_time' => strtotime($params['start_time']),
  59. 'end_time' => strtotime($params['end_time']),
  60. 'participant_num' => $params['participant_num'],
  61. 'type' => $params['type'],
  62. 'form_time_limit' => $params['form_time_limit'],
  63. 'is_online_join' => $params['is_online_join'],
  64. 'is_simulate_form' => $params['is_simulate_form'],
  65. 'simulate_num' => $params['simulate_num'],
  66. 'is_preheat' => $params['is_preheat'],
  67. 'is_support_refund' => $params['is_support_refund'],
  68. 'area' => $params['area'],
  69. ]);
  70. Db::commit();
  71. return true;
  72. } catch (\Exception $e) {
  73. Db::rollback();
  74. self::setError($e->getMessage());
  75. return false;
  76. }
  77. }
  78. /**
  79. * @notes 编辑拼团活动
  80. * @param array $params
  81. * @return bool
  82. * @author likeadmin
  83. * @date 2025/03/13 10:31
  84. */
  85. public static function edit(array $params): bool
  86. {
  87. Db::startTrans();
  88. try {
  89. if ($params['type'] == 1) {
  90. $params['price'] = $params['price'][0];
  91. $params['participant_num'] = $params['participant_num'][0];
  92. } else {
  93. $params['price'] = implode(",",$params['price']);
  94. $params['participant_num'] = implode(",",$params['participant_num']);
  95. }
  96. if ($params['is_simulate_form'] == 1) {
  97. $params['simulate_num'] = $params['type'] == 1 ? $params['simulate_num'][0] : implode(",",$params['simulate_num']);
  98. } else {
  99. $params['simulate_num'] = '';
  100. }
  101. $params['area'] = implode(",",$params['area']);
  102. GroupActivity::where('id', $params['id'])->update([
  103. 'title' => $params['title'],
  104. 'image' => $params['image'],
  105. 'equity_id' => $params['equity_id'],
  106. 'origin_price' => $params['origin_price'],
  107. 'price' => $params['price'],
  108. 'start_time' => strtotime($params['start_time']),
  109. 'end_time' => strtotime($params['end_time']),
  110. 'participant_num' => $params['participant_num'],
  111. 'type' => $params['type'],
  112. 'form_time_limit' => $params['form_time_limit'],
  113. 'is_online_join' => $params['is_online_join'],
  114. 'is_simulate_form' => $params['is_simulate_form'],
  115. 'simulate_num' => $params['simulate_num'],
  116. 'is_preheat' => $params['is_preheat'],
  117. 'is_support_refund' => $params['is_support_refund'],
  118. 'area' => $params['area'],
  119. ]);
  120. Db::commit();
  121. return true;
  122. } catch (\Exception $e) {
  123. Db::rollback();
  124. self::setError($e->getMessage());
  125. return false;
  126. }
  127. }
  128. /**
  129. * @notes 删除拼团活动
  130. * @param array $params
  131. * @return bool
  132. * @author likeadmin
  133. * @date 2025/03/13 10:31
  134. */
  135. public static function delete(array $params): bool
  136. {
  137. return GroupActivity::destroy($params['id']);
  138. }
  139. /**
  140. * @notes 获取拼团活动详情
  141. * @param $params
  142. * @return array
  143. * @author likeadmin
  144. * @date 2025/03/13 10:31
  145. */
  146. public static function detail($params): array
  147. {
  148. $detail = GroupActivity::findOrEmpty($params['id'])->toArray();
  149. $detail['area'] = explode(",",$detail['area']);
  150. return $detail;
  151. }
  152. /**
  153. * 获取活动二维码
  154. * @return string|void
  155. */
  156. public static function getQRCode($params,$url)
  157. {
  158. try {
  159. $mnp_page = 'pages/web_view/group';
  160. $scene_page = 'group';
  161. Log::info('getQRCode:'.rawurlencode($scene_page));
  162. $response = (new WeChatMnpService())->getUnlimitedQRCode(
  163. 'page='.$scene_page.'&id='.$params['id'],
  164. $mnp_page,
  165. env('miniprogram.mini_env_version', 'release'),
  166. false
  167. );
  168. Log::info('getQRCode:'.json_encode([$response]));
  169. $qrcode = $response->getContent();
  170. if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
  171. mkdir('./uploads/wx_qrcode/'.date('Ymd'));
  172. }
  173. $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
  174. file_put_contents($file_name, $qrcode);
  175. return $url.'/'.$file_name;
  176. } catch (\Throwable $e) {
  177. Log::info('getQRCode:'.$e->getMessage());
  178. return '';
  179. }
  180. }
  181. }