Bonus.php 6.4 KB

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