Memberrecharge.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\memberrecharge\model;
  13. use addon\coupon\model\CouponType;
  14. use app\model\BaseModel;
  15. use think\facade\Cache;
  16. use app\model\system\Config as ConfigModel;
  17. /**
  18. * 会员充值
  19. */
  20. class Memberrecharge extends BaseModel
  21. {
  22. /**
  23. * 添加套餐
  24. * @param $data
  25. * @return array
  26. */
  27. public function addMemberRecharge($data)
  28. {
  29. $data['create_time'] = time();
  30. $data['status'] = 1;
  31. $res = model('member_recharge')->add($data);
  32. Cache::tag("member_recharge")->clear();
  33. return $this->success($res);
  34. }
  35. /**
  36. * 编辑套餐
  37. * @param array $condition
  38. * @param $data
  39. * @return array
  40. */
  41. public function editMemberRecharge($condition = [], $data)
  42. {
  43. $data['update_time'] = time();
  44. $res = model('member_recharge')->update($data, $condition);
  45. Cache::tag("member_recharge")->clear();
  46. return $this->success($res);
  47. }
  48. /**
  49. * 删除套餐详情
  50. * @param array $condition
  51. * @return mixed
  52. */
  53. public function deleteMemberRecharge($condition = [])
  54. {
  55. $res = model('member_recharge')->delete($condition);
  56. Cache::tag("member_recharge")->clear();
  57. return $this->success($res);
  58. }
  59. /**
  60. * 套餐详情
  61. * @param array $condition
  62. * @param string $field
  63. * @return array
  64. */
  65. public function getMemberRechargeInfo($condition = [], $field = '*')
  66. {
  67. $recharge = model('member_recharge')->getInfo($condition, $field);
  68. if ($recharge) {
  69. //获取优惠券信息
  70. if ($recharge['coupon_id']) {
  71. //优惠券字段
  72. $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term';
  73. $model = new CouponType();
  74. $coupon = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $recharge['coupon_id'] ] ], $coupon_field);
  75. $recharge['coupon_list'] = $coupon;
  76. }
  77. }
  78. Cache::tag("member_recharge")->clear();
  79. return $this->success($recharge);
  80. }
  81. /**
  82. * 套餐列表
  83. * @param array $condition
  84. * @param int $page
  85. * @param int $page_size
  86. * @param string $order
  87. * @param string $field
  88. * @return array
  89. */
  90. public function getMemberRechargePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  91. {
  92. $list = model('member_recharge')->pageList($condition, $field, $order, $page, $page_size);
  93. Cache::tag("member_recharge")->clear();
  94. return $this->success($list);
  95. }
  96. /**
  97. * 设置会员充值配置
  98. * @param $data
  99. * @param $is_use
  100. * @return array
  101. */
  102. public function setConfig($data,$is_use)
  103. {
  104. $config = new ConfigModel();
  105. $res = $config->setConfig($data, '会员充值配置', $is_use, [ [ 'site_id', '=', 0 ], [ 'app_module', '=', 'admin' ], [ 'config_key', '=', 'MEMBER_RECHARGE_CONFIG' ] ]);
  106. return $res;
  107. }
  108. /**
  109. * 获取会员充值配置
  110. */
  111. public function getConfig()
  112. {
  113. $config = new ConfigModel();
  114. $res = $config->getConfig([ [ 'site_id', '=', 0 ], [ 'app_module', '=', 'admin' ], [ 'config_key', '=', 'MEMBER_RECHARGE_CONFIG' ] ]);
  115. return $res;
  116. }
  117. }