UserCouponLogic.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\coupon;
  15. use app\adminapi\logic\user\UserLogic;
  16. use app\common\model\coupon\UserCoupon;
  17. use app\common\logic\BaseLogic;
  18. use think\facade\Db;
  19. /**
  20. * UserCoupon逻辑
  21. * Class UserCouponLogic
  22. * @package app\adminapi\logic
  23. */
  24. class UserCouponLogic extends BaseLogic
  25. {
  26. /**
  27. * @notes 添加
  28. * @param array $params
  29. * @return bool
  30. * @author likeadmin
  31. * @date 2025/05/28 11:42
  32. */
  33. public static function add(array $params): bool
  34. {
  35. Db::startTrans();
  36. try {
  37. //注册用户
  38. $userId = UserLogic::getUserIdByMobile($params['mobile']);
  39. $codes = [$params['code']];
  40. if($codes){
  41. \app\api\logic\UserCouponLogic::grant($codes,$userId,1);
  42. }
  43. Db::commit();
  44. return true;
  45. } catch (\Exception $e) {
  46. Db::rollback();
  47. self::setError($e->getMessage());
  48. return false;
  49. }
  50. }
  51. /**
  52. * @notes 编辑
  53. * @param array $params
  54. * @return bool
  55. * @author likeadmin
  56. * @date 2025/05/28 11:42
  57. */
  58. public static function edit(array $params): bool
  59. {
  60. Db::startTrans();
  61. try {
  62. /*UserCoupon::where('id', $params['id'])->update([
  63. 'user_id' => $params['user_id'],
  64. 'coupon_id' => $params['coupon_id'],
  65. 'coupon_target' => $params['coupon_target'],
  66. 'code' => $params['code'],
  67. 'voucher_status' => $params['voucher_status'],
  68. 'voucher_count' => $params['voucher_count'],
  69. 'amount' => $params['amount'],
  70. 'amount_require' => $params['amount_require'],
  71. 'begin_use' => $params['begin_use'],
  72. 'discount_ratio' => $params['discount_ratio'],
  73. 'event_name' => $params['event_name'],
  74. 'expire_time' => $params['expire_time'],
  75. 'max_deductible_price' => $params['max_deductible_price'],
  76. 'mold_type' => $params['mold_type'],
  77. 'server_category_name' => $params['server_category_name'],
  78. 'property_activity_id' => $params['property_activity_id'],
  79. ]);*/
  80. Db::commit();
  81. return true;
  82. } catch (\Exception $e) {
  83. Db::rollback();
  84. self::setError($e->getMessage());
  85. return false;
  86. }
  87. }
  88. /**
  89. * @notes 删除
  90. * @param array $params
  91. * @return bool
  92. * @author likeadmin
  93. * @date 2025/05/28 11:42
  94. */
  95. public static function delete(array $params): bool
  96. {
  97. return UserCoupon::destroy($params['id']);
  98. }
  99. /**
  100. * @notes 获取详情
  101. * @param $params
  102. * @return array
  103. * @author likeadmin
  104. * @date 2025/05/28 11:42
  105. */
  106. public static function detail($params): array
  107. {
  108. return UserCoupon::findOrEmpty($params['id'])->toArray();
  109. }
  110. }