截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RechargeLogic.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\api\logic;
  3. use app\common\basics\Logic;
  4. use app\common\model\RechargeTemplate;
  5. use app\common\model\RechargeOrder;
  6. use app\common\server\ConfigServer;
  7. use app\common\enum\PayEnum;
  8. use think\facade\Db;
  9. use app\common\logic\AccountLogLogic;
  10. use app\common\model\AccountLog;
  11. class RechargeLogic extends Logic
  12. {
  13. public static function getTemplate(){
  14. $list = RechargeTemplate::where(['del'=>0])
  15. ->order('sort desc')
  16. ->field('id,money,give_money,is_recommend')
  17. ->select()
  18. ->toArray();
  19. foreach ($list as &$item){
  20. $item['tips'] = '';
  21. if($item['give_money'] > 0){
  22. $item['tips'] = '充'.intval($item['money']).'赠送'.intval($item['give_money']).'元';
  23. }
  24. }
  25. return $list;
  26. }
  27. public static function recharge($user_id,$client,$post)
  28. {
  29. try{
  30. $give_growth = ConfigServer::get('recharge', 'give_growth', 0);
  31. //充值模板
  32. if(isset($post['id'])){
  33. $template = RechargeTemplate::where(['del'=>0,'id'=>$post['id']])
  34. ->field('id,money,give_money')
  35. ->findOrEmpty();
  36. if($template->isEmpty()) {
  37. throw new \think\Exception('充值模板不存在');
  38. }
  39. $money = $template['money'];
  40. $give_money = $template['give_money'];
  41. }else{//自定义充值金额
  42. $template = RechargeTemplate::where(['del'=>0,'money'=>$post['money']])
  43. ->field('id,money,give_money')
  44. ->findOrEmpty();
  45. $money = $post['money'];
  46. $give_money = 0;
  47. if(!$template->isEmpty()){
  48. $money = $template['money'];
  49. $give_money = $template['give_money'];
  50. }
  51. }
  52. //赠送的积分和成长值
  53. $growth = $money * $give_growth;
  54. $growth = $growth > 0 ? intval($growth) : 0;
  55. $add_order = [
  56. 'user_id' => $user_id,
  57. 'order_sn' => createSn('recharge_order','order_sn'),
  58. 'order_amount' => $money,
  59. 'order_source' => $client,
  60. 'pay_status' => PayEnum::UNPAID, //待支付状态;
  61. 'pay_way' => $post['pay_way'] ?? 1,
  62. 'template_id' => $template['id'] ?? 0,
  63. 'give_money' => $give_money,
  64. 'give_growth' => $growth,
  65. 'create_time' => time(),
  66. ];
  67. $id = Db::name('recharge_order')->insertGetId($add_order);
  68. if($id){
  69. return Db::name('recharge_order')->where(['id'=>$id])->field('id,order_sn,give_growth')->find();
  70. }
  71. return [];
  72. }catch(\Exception $e) {
  73. self::$error = $e->getMessage();
  74. return false;
  75. }
  76. }
  77. public static function rechargeRecord($get)
  78. {
  79. $list = RechargeOrder::field('order_sn, order_amount, give_money, create_time')
  80. ->where([
  81. 'user_id' => $get['user_id'],
  82. 'pay_status' => PayEnum::ISPAID, // 已支付的
  83. ])
  84. ->order('create_time', 'desc')
  85. ->page($get['page_no'], $get['page_size'])
  86. ->select()
  87. ->toArray();
  88. $count = RechargeOrder::where([
  89. 'user_id' => $get['user_id'],
  90. 'pay_status' => PayEnum::ISPAID
  91. ])
  92. ->count();
  93. foreach($list as &$item) {
  94. if($item['give_money'] > 0) {
  95. $item['desc'] = '充值'. clearZero($item['order_amount']) . '赠送' . clearZero($item['give_money']);
  96. }else{
  97. $item['desc'] = '充值'. clearZero($item['order_amount']);
  98. }
  99. $item['total'] = $item['order_amount'] + $item['give_money']; // 充值金额 + 赠送金额
  100. }
  101. $result = [
  102. 'count' => $count,
  103. 'lists' => $list,
  104. 'more' => is_more($count, $get['page_no'], $get['page_size']),
  105. 'page_no' => $get['page_no'],
  106. 'page_size' => $get['page_size']
  107. ];
  108. return $result;
  109. }
  110. }