Bonus.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Bonus extends BaseModel {
  16. public $page_info;
  17. /**
  18. * 吸粉红包列表
  19. * @author csdeshang
  20. * @param array $condition 检索条件
  21. * @param array $pagesize 分页信息
  22. * @return array 数组类型的返回结果
  23. */
  24. public function getBonusList($condition,$pagesize ,$limit = 0,$order='bonus_id desc') {
  25. if($pagesize){
  26. $result = Db::name('bonus')->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  27. $this->page_info=$result;
  28. return $result->items();
  29. }else{
  30. $result = Db::name('bonus')->where($condition)->order($order)->limit($limit)->select()->toArray();
  31. return $result;
  32. }
  33. }
  34. /**
  35. * 取单个吸粉红包的内容
  36. * @author csdeshang
  37. * @param array $condition 检索条件
  38. * @return array 数组类型的返回结果
  39. */
  40. public function getOneBonus($condition) {
  41. return Db::name('bonus')->where($condition)->find();
  42. }
  43. /**
  44. * 新增
  45. * @author csdeshang
  46. * @param array $data 参数内容
  47. * @return bool 布尔类型的返回结果
  48. */
  49. public function addBonus($data) {
  50. if (empty($data)) {
  51. return false;
  52. }
  53. return Db::name('bonus')->insertGetId($data);
  54. }
  55. /**
  56. * 更新信息
  57. * @author csdeshang
  58. * @param array $condition 条件
  59. * @param array $data 更新数据
  60. * @return bool 布尔类型的返回结果
  61. */
  62. public function editBonus($condition,$data) {
  63. if (empty($data)) {
  64. return false;
  65. }
  66. return Db::name('bonus')->where($condition)->update($data);
  67. }
  68. /**
  69. * 删除
  70. * @author csdeshang
  71. * @param array $condition 检索条件
  72. * @return array $rs_row 返回数组形式的查询结果
  73. */
  74. public function delBonus($condition) {
  75. return Db::name('bonus')->where($condition)->delete();
  76. }
  77. // 获取红包类型
  78. public function bonus_type_list()
  79. {
  80. return array(
  81. '1'=>'活动红包',
  82. '2'=>'注册红包',
  83. '3'=>'奖品红包'
  84. );
  85. }
  86. // 获取红包状态
  87. public function bonus_state_list()
  88. {
  89. return array(
  90. '1'=>'正在进行',
  91. '2'=>'已过期',
  92. '3'=>'已失效'
  93. );
  94. }
  95. /**
  96. * 吸粉红包领取列表
  97. * @author csdeshang
  98. * @param array $condition 检索条件
  99. * @param array $pagesize 分页信息
  100. * @return array 数组类型的返回结果
  101. */
  102. public function getBonusreceiveList($condition,$pagesize ,$limit=0) {
  103. if($pagesize){
  104. $result = Db::name('bonusreceive')->where($condition)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  105. $this->page_info=$result;
  106. return $result->items();
  107. }else{
  108. $result = Db::name('bonusreceive')->where($condition)->limit($limit)->select()->toArray();
  109. return $result;
  110. }
  111. }
  112. /**
  113. * 取吸粉红包的领取详情
  114. * @author csdeshang
  115. * @param array $condition 检索条件
  116. * @return array 数组类型的返回结果
  117. */
  118. public function getOneBonusreceive($condition) {
  119. return Db::name('bonusreceive')->where($condition)->find();
  120. }
  121. /**
  122. * 更新信息
  123. * @author csdeshang
  124. * @param array $bonusreceive_id 条件
  125. * @param array $data 更新数据
  126. * @return bool 布尔类型的返回结果
  127. */
  128. public function editBonusreceive($bonusreceive_id,$data) {
  129. if (empty($data)) {
  130. return false;
  131. }
  132. return Db::name('bonusreceive')->where('bonusreceive_id',$bonusreceive_id)->update($data);
  133. }
  134. /**
  135. * 领取红包
  136. * @author csdeshang
  137. * @param array $member_info 用户信息
  138. * @param array $bonus 红包信息
  139. * @param array $bonusreceive 红包领取信息
  140. * @param string $lg_desc 描述信息
  141. * @return bool 布尔类型的返回结果
  142. */
  143. public function receiveBonus($member_info,$bonus,$bonusreceive,$lg_desc) {
  144. $data_bonusreceive = array(
  145. 'member_id' => $member_info['member_id'],
  146. 'member_name' => $member_info['member_name'],
  147. 'bonusreceive_time' => TIMESTAMP,
  148. 'bonusreceive_transformed' => 1, //是否转入预存款
  149. );
  150. $flag=$this->editBonusreceive($bonusreceive['bonusreceive_id'], $data_bonusreceive);
  151. if(!$flag){
  152. return ds_callback(false, '红包领取信息更新失败');
  153. }
  154. //更新活动红包统计
  155. $data_bonus = array(
  156. 'bonus_receivecount' => $bonus['bonus_receivecount'] + 1,
  157. 'bonus_receiveprice' => $bonus['bonus_receiveprice'] + $bonusreceive['bonusreceive_price'],
  158. );
  159. $flag=$this->editBonus(array('bonus_id' => $bonus['bonus_id']), $data_bonus);
  160. if(!$flag){
  161. return ds_callback(false, '红包信息更新失败');
  162. }
  163. //把红包加入预存款
  164. $data = array();
  165. $data['member_id'] = $member_info['member_id'];
  166. $data['member_name'] = $member_info['member_name'];
  167. $data['amount'] = $bonusreceive['bonusreceive_price'];
  168. $data['order_sn'] = $bonusreceive['bonusreceive_id'];
  169. $data['rcblog_description'] = $lg_desc;
  170. model('predeposit')->changeRcb('bonus', $data);
  171. return ds_callback(true);
  172. }
  173. }
  174. ?>