Ppintuangroup.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * 拼团活动模型
  4. *
  5. */
  6. namespace app\common\model;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. *
  11. * ============================================================================
  12. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 数据层模型
  18. */
  19. class Ppintuangroup extends BaseModel {
  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. $field = "ppintuangroup.*,member.member_name";
  40. if ($pagesize) {
  41. $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);
  42. $this->page_info = $result;
  43. $ppintuangroup_list = $result->items();
  44. }else{
  45. $ppintuangroup_list = Db::name('ppintuangroup')->alias('ppintuangroup')->join('member member','ppintuangroup.pintuangroup_headid=member.member_id')->field($field)->where($condition)->order($order)->select()->toArray();
  46. }
  47. if (!empty($ppintuangroup_list)) {
  48. foreach ($ppintuangroup_list as $key => $ppintuangroup) {
  49. //此拼团发起活动剩余还可购买的份额
  50. $pintuangroup_surplus = $ppintuangroup['pintuangroup_limit_number'] - $ppintuangroup['pintuangroup_joined'];
  51. $ppintuangroup_list[$key]['pintuangroup_state_text'] = $this->pintuangroup_state_array[$ppintuangroup['pintuangroup_state']];
  52. $ppintuangroup_list[$key]['pintuangroup_surplus'] = $pintuangroup_surplus;
  53. $ppintuangroup_list[$key]['pintuangroup_avatar'] = get_member_avatar_for_id($ppintuangroup['pintuangroup_headid']);
  54. }
  55. }
  56. return $ppintuangroup_list;
  57. }
  58. /**
  59. * 获取单个单团信息
  60. * @access public
  61. * @author csdeshang
  62. * @param type $condition 条件
  63. * @return type
  64. */
  65. public function getOnePpintuangroup($condition){
  66. return Db::name('ppintuangroup')->where($condition)->find();
  67. }
  68. /**
  69. * 插入拼团开团表
  70. * @access public
  71. * @author csdeshang
  72. * @param type $data 参数数据
  73. * @return type
  74. */
  75. public function addPpintuangroup($data)
  76. {
  77. return Db::name('ppintuangroup')->insertGetId($data);
  78. }
  79. /**
  80. * 编辑拼团开团表
  81. * @access public
  82. * @author csdeshang
  83. * @param type $condition 条件
  84. * @param type $data 数据
  85. * @return type
  86. */
  87. public function editPpintuangroup($condition,$data)
  88. {
  89. return Db::name('ppintuangroup')->where($condition)->update($data);
  90. }
  91. /**
  92. * 拼团成功,拼团订单信息
  93. * @access public
  94. * @author csdeshang
  95. * @param type $condition 条件
  96. */
  97. public function successPpintuangroup($condition,$condition2)
  98. {
  99. //更新拼团开团信息
  100. $update_group['pintuangroup_state'] = 2;
  101. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  102. $this->editPpintuangroup($condition, $update_group);
  103. //更新拼团订单信息
  104. $update_order['pintuanorder_state'] = 2;
  105. model('ppintuanorder')->editPpintuanorder($condition2,$update_order);
  106. }
  107. /**
  108. * 拼团成功,拼团订单信息
  109. * @access public
  110. * @author csdeshang
  111. * @param type $condition 条件
  112. * @return type
  113. */
  114. public function failPpintuangroup($condition)
  115. {
  116. //更新拼团开团信息
  117. $update_group['pintuangroup_state'] = 0;
  118. $update_group['pintuangroup_endtime'] = TIMESTAMP;
  119. $this->editPpintuangroup($condition, $update_group);
  120. //更新拼团订单信息
  121. $update_order['pintuanorder_state'] = 0;
  122. model('ppintuanorder')->editPpintuanorder($condition,$update_order);
  123. }
  124. /**
  125. * 拼团状态数组
  126. * @access public
  127. * @author csdeshang
  128. * @return type
  129. */
  130. public function getPintuangroupStateArray() {
  131. return $this->pintuangroup_state_array;
  132. }
  133. }