Ppintuangroup.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * 拼团活动模型
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. *
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 数据层模型
  17. */
  18. class Ppintuangroup extends BaseModel
  19. {
  20. public $page_info;
  21. const PINTUANGROUP_STATE_CLOSE = 0;
  22. const PINTUANGROUP_STATE_NORMAL = 1;
  23. const PINTUANGROUP_STATE_SUCCESS = 2;
  24. private $pintuangroup_state_array = array(
  25. self::PINTUANGROUP_STATE_CLOSE => '拼团取消',
  26. self::PINTUANGROUP_STATE_NORMAL => '参团中',
  27. self::PINTUANGROUP_STATE_SUCCESS => '拼团成功'
  28. );
  29. /**
  30. * 获取开团表列表
  31. * @access public
  32. * @author csdeshang
  33. * @param type $condition 条件
  34. * @param type $pagesize 分页
  35. * @param type $order 排序
  36. * @return type
  37. */
  38. public function getPpintuangroupList($condition, $pagesize = '', $order = 'pintuangroup_starttime desc')
  39. {
  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. {
  68. return Db::name('ppintuangroup')->where($condition)->find();
  69. }
  70. /**
  71. * 插入拼团开团表
  72. * @access public
  73. * @author csdeshang
  74. * @param type $data 参数数据
  75. * @return type
  76. */
  77. public function addPpintuangroup($data)
  78. {
  79. return Db::name('ppintuangroup')->insertGetId($data);
  80. }
  81. /**
  82. * 编辑拼团开团表
  83. * @access public
  84. * @author csdeshang
  85. * @param type $condition 条件
  86. * @param type $data 数据
  87. * @return type
  88. */
  89. public function editPpintuangroup($condition, $data)
  90. {
  91. return Db::name('ppintuangroup')->where($condition)->update($data);
  92. }
  93. /**
  94. * 拼团成功,拼团订单信息
  95. * @access public
  96. * @author csdeshang
  97. * @param type $condition 条件
  98. */
  99. public function successPpintuangroup($condition, $condition2)
  100. {
  101. //更新拼团开团信息
  102. $update_group['pintuangroup_state'] = 2;
  103. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  104. $this->editPpintuangroup($condition, $update_group);
  105. //更新拼团订单信息
  106. $update_order['pintuanorder_state'] = 2;
  107. model('ppintuanorder')->editPpintuanorder($condition2, $update_order);
  108. }
  109. /**
  110. * 拼团成功,拼团订单信息
  111. * @access public
  112. * @author csdeshang
  113. * @param type $condition 条件
  114. * @return type
  115. */
  116. public function failPpintuangroup($condition)
  117. {
  118. //更新拼团开团信息
  119. $update_group['pintuangroup_state'] = 0;
  120. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  121. $this->editPpintuangroup($condition, $update_group);
  122. //更新拼团订单信息
  123. $update_order['pintuanorder_state'] = 0;
  124. model('ppintuanorder')->editPpintuanorder($condition, $update_order);
  125. }
  126. /**
  127. * 拼团状态数组
  128. * @access public
  129. * @author csdeshang
  130. * @return type
  131. */
  132. public function getPintuangroupStateArray()
  133. {
  134. return $this->pintuangroup_state_array;
  135. }
  136. }