Ppintuangroup.php 4.7 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. class Ppintuangroup extends BaseModel
  16. {
  17. public $page_info;
  18. const PINTUANGROUP_STATE_CLOSE = 0;
  19. const PINTUANGROUP_STATE_NORMAL = 1;
  20. const PINTUANGROUP_STATE_SUCCESS = 2;
  21. private $pintuangroup_state_array = array(
  22. self::PINTUANGROUP_STATE_CLOSE => '拼团取消',
  23. self::PINTUANGROUP_STATE_NORMAL => '参团中',
  24. self::PINTUANGROUP_STATE_SUCCESS => '拼团成功'
  25. );
  26. /**
  27. * 获取开团表列表
  28. * @access public
  29. * @author csdeshang
  30. * @param type $condition 条件
  31. * @param type $pagesize 分页
  32. * @param type $order 排序
  33. * @return type
  34. */
  35. public function getPpintuangroupList($condition, $pagesize = '', $order = 'pintuangroup_starttime desc')
  36. {
  37. $field = "ppintuangroup.*,member.member_name";
  38. if ($pagesize) {
  39. $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);
  40. $this->page_info = $result;
  41. $ppintuangroup_list = $result->items();
  42. } else {
  43. $ppintuangroup_list = Db::name('ppintuangroup')->alias('ppintuangroup')->join('member member', 'ppintuangroup.pintuangroup_headid=member.member_id')->field($field)->where($condition)->order($order)->select()->toArray();
  44. }
  45. if (!empty($ppintuangroup_list)) {
  46. foreach ($ppintuangroup_list as $key => $ppintuangroup) {
  47. //此拼团发起活动剩余还可购买的份额
  48. $pintuangroup_surplus = $ppintuangroup['pintuangroup_limit_number'] - $ppintuangroup['pintuangroup_joined'];
  49. $ppintuangroup_list[$key]['pintuangroup_state_text'] = $this->pintuangroup_state_array[$ppintuangroup['pintuangroup_state']];
  50. $ppintuangroup_list[$key]['pintuangroup_surplus'] = $pintuangroup_surplus;
  51. $ppintuangroup_list[$key]['pintuangroup_avatar'] = get_member_avatar_for_id($ppintuangroup['pintuangroup_headid']);
  52. }
  53. }
  54. return $ppintuangroup_list;
  55. }
  56. /**
  57. * 获取单个单团信息
  58. * @access public
  59. * @author csdeshang
  60. * @param type $condition 条件
  61. * @return type
  62. */
  63. public function getOnePpintuangroup($condition)
  64. {
  65. return Db::name('ppintuangroup')->where($condition)->find();
  66. }
  67. /**
  68. * 插入拼团开团表
  69. * @access public
  70. * @author csdeshang
  71. * @param type $data 参数数据
  72. * @return type
  73. */
  74. public function addPpintuangroup($data)
  75. {
  76. return Db::name('ppintuangroup')->insertGetId($data);
  77. }
  78. /**
  79. * 编辑拼团开团表
  80. * @access public
  81. * @author csdeshang
  82. * @param type $condition 条件
  83. * @param type $data 数据
  84. * @return type
  85. */
  86. public function editPpintuangroup($condition, $data)
  87. {
  88. return Db::name('ppintuangroup')->where($condition)->update($data);
  89. }
  90. /**
  91. * 拼团成功,拼团订单信息
  92. * @access public
  93. * @author csdeshang
  94. * @param type $condition 条件
  95. */
  96. public function successPpintuangroup($condition, $condition2)
  97. {
  98. //更新拼团开团信息
  99. $update_group['pintuangroup_state'] = 2;
  100. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  101. $this->editPpintuangroup($condition, $update_group);
  102. //更新拼团订单信息
  103. $update_order['pintuanorder_state'] = 2;
  104. model('ppintuanorder')->editPpintuanorder($condition2, $update_order);
  105. }
  106. /**
  107. * 拼团成功,拼团订单信息
  108. * @access public
  109. * @author csdeshang
  110. * @param type $condition 条件
  111. * @return type
  112. */
  113. public function failPpintuangroup($condition)
  114. {
  115. //更新拼团开团信息
  116. $update_group['pintuangroup_state'] = 0;
  117. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  118. $this->editPpintuangroup($condition, $update_group);
  119. //更新拼团订单信息
  120. $update_order['pintuanorder_state'] = 0;
  121. model('ppintuanorder')->editPpintuanorder($condition, $update_order);
  122. }
  123. /**
  124. * 拼团状态数组
  125. * @access public
  126. * @author csdeshang
  127. * @return type
  128. */
  129. public function getPintuangroupStateArray()
  130. {
  131. return $this->pintuangroup_state_array;
  132. }
  133. }