Ppintuangroup.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * 拼团活动模型
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 数据层模型
  19. */
  20. class Ppintuangroup extends BaseModel {
  21. public $page_info;
  22. const PINTUANGROUP_STATE_CLOSE = 0;
  23. const PINTUANGROUP_STATE_NORMAL = 1;
  24. const PINTUANGROUP_STATE_SUCCESS = 2;
  25. private $pintuangroup_state_array = array(
  26. self::PINTUANGROUP_STATE_CLOSE => '拼团取消',
  27. self::PINTUANGROUP_STATE_NORMAL => '参团中',
  28. self::PINTUANGROUP_STATE_SUCCESS => '拼团成功'
  29. );
  30. /**
  31. * 获取开团表列表
  32. * @access public
  33. * @author csdeshang
  34. * @param type $condition 条件
  35. * @param type $pagesize 分页
  36. * @param type $order 排序
  37. * @return type
  38. */
  39. public function getPpintuangroupList($condition, $pagesize = '',$order='pintuangroup_starttime desc') {
  40. $field = "ppintuangroup.*,member.member_name";
  41. if ($pagesize) {
  42. $result = Db::name('ppintuangroup')->alias('ppintuangroup')->join('member member','ppintuangroup.pintuangroup_headid=member.member_id')->field($field)->where($condition)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  43. $this->page_info = $result;
  44. $ppintuangroup_list = $result->items();
  45. }else{
  46. $ppintuangroup_list = Db::name('ppintuangroup')->alias('ppintuangroup')->join('member member','ppintuangroup.pintuangroup_headid=member.member_id')->field($field)->where($condition)->order($order)->select()->toArray();
  47. }
  48. if (!empty($ppintuangroup_list)) {
  49. foreach ($ppintuangroup_list as $key => $ppintuangroup) {
  50. //此拼团发起活动剩余还可购买的份额
  51. $pintuangroup_surplus = $ppintuangroup['pintuangroup_limit_number'] - $ppintuangroup['pintuangroup_joined'];
  52. $ppintuangroup_list[$key]['pintuangroup_state_text'] = $this->pintuangroup_state_array[$ppintuangroup['pintuangroup_state']];
  53. $ppintuangroup_list[$key]['pintuangroup_surplus'] = $pintuangroup_surplus;
  54. $ppintuangroup_list[$key]['pintuangroup_avatar'] = get_member_avatar_for_id($ppintuangroup['pintuangroup_headid']);
  55. }
  56. }
  57. return $ppintuangroup_list;
  58. }
  59. /**
  60. * 获取单个单团信息
  61. * @access public
  62. * @author csdeshang
  63. * @param type $condition 条件
  64. * @return type
  65. */
  66. public function getOnePpintuangroup($condition){
  67. return Db::name('ppintuangroup')->where($condition)->find();
  68. }
  69. /**
  70. * 插入拼团开团表
  71. * @access public
  72. * @author csdeshang
  73. * @param type $data 参数数据
  74. * @return type
  75. */
  76. public function addPpintuangroup($data)
  77. {
  78. return Db::name('ppintuangroup')->insertGetId($data);
  79. }
  80. /**
  81. * 编辑拼团开团表
  82. * @access public
  83. * @author csdeshang
  84. * @param type $condition 条件
  85. * @param type $data 数据
  86. * @return type
  87. */
  88. public function editPpintuangroup($condition,$data)
  89. {
  90. return Db::name('ppintuangroup')->where($condition)->update($data);
  91. }
  92. /**
  93. * 拼团成功,拼团订单信息
  94. * @access public
  95. * @author csdeshang
  96. * @param type $condition 条件
  97. */
  98. public function successPpintuangroup($condition,$condition2)
  99. {
  100. //更新拼团开团信息
  101. $update_group['pintuangroup_state'] = 2;
  102. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  103. $this->editPpintuangroup($condition, $update_group);
  104. //更新拼团订单信息
  105. $update_order['pintuanorder_state'] = 2;
  106. model('ppintuanorder')->editPpintuanorder($condition2,$update_order);
  107. }
  108. /**
  109. * 拼团成功,拼团订单信息
  110. * @access public
  111. * @author csdeshang
  112. * @param type $condition 条件
  113. * @return type
  114. */
  115. public function failPpintuangroup($condition)
  116. {
  117. //更新拼团开团信息
  118. $update_group['pintuangroup_state'] = 0;
  119. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  120. $this->editPpintuangroup($condition, $update_group);
  121. //更新拼团订单信息
  122. $update_order['pintuanorder_state'] = 0;
  123. model('ppintuanorder')->editPpintuanorder($condition,$update_order);
  124. }
  125. /**
  126. * 拼团状态数组
  127. * @access public
  128. * @author csdeshang
  129. * @return type
  130. */
  131. public function getPintuangroupStateArray() {
  132. return $this->pintuangroup_state_array;
  133. }
  134. }