Bonus.php 6.1 KB

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