Bonus.php 5.9 KB

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