StorePink.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\model\ump;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. use app\admin\model\order\StoreOrder;
  6. class StorePink extends BaseModel
  7. {
  8. /**
  9. * 数据表主键
  10. * @var string
  11. */
  12. protected $pk = 'id';
  13. /**
  14. * 模型名称
  15. * @var string
  16. */
  17. protected $name = 'store_pink';
  18. use ModelTrait;
  19. /**分页列表
  20. * @param $where
  21. * @return array
  22. */
  23. public static function systemPage($where)
  24. {
  25. $model = new self;
  26. $model = $model->alias('p');
  27. $model = $model->field('p.*,c.title,u.nickname,u.avatar');
  28. if ($where['data'] !== '') {
  29. list($startTime, $endTime) = explode(' - ', $where['data']);
  30. $model = $model->where('p.add_time', '>', strtotime($startTime));
  31. $model = $model->where('p.add_time', '<', strtotime($endTime));
  32. }
  33. if ($where['status']) $model = $model->where('p.status', $where['status']);
  34. $model = $model->where('p.k_id', 0);
  35. $model = $model->order('p.id desc');
  36. $model = $model->join('store_combination c', 'c.id=p.cid');
  37. $model = $model->join('user u', 'u.uid = p.uid');
  38. return self::page($model, function ($item) use ($where) {
  39. $item['count_people'] = bcadd(self::where('k_id', $item['id'])->count(), 1, 0);
  40. }, $where);
  41. }
  42. /**
  43. * 获取当前产品参与的人数
  44. * @param int $combinationId
  45. * @return int|string
  46. */
  47. public static function getCountPeopleAll($combinationId = 0)
  48. {
  49. if (!$combinationId) return self::count();
  50. return self::where('cid', $combinationId)->count();
  51. }
  52. /**
  53. * 获取当前产品参与的团数
  54. * @param int $combinationId
  55. * @return int|string
  56. */
  57. public static function getCountPeoplePink($combinationId = 0)
  58. {
  59. if (!$combinationId) return self::where('k_id', 0)->count();
  60. return self::where('cid', $combinationId)->where('k_id', 0)->count();
  61. }
  62. /**
  63. * 获取一条拼团数据
  64. * @param $id
  65. * @return mixed
  66. */
  67. public static function getPinkUserOne($id)
  68. {
  69. $model = new self();
  70. $model = $model->alias('p');
  71. $model = $model->field('p.*,u.nickname,u.avatar');
  72. $model = $model->where('id', $id);
  73. $model = $model->join('user u', 'u.uid = p.uid');
  74. $list = $model->find();
  75. if ($list) return $list->toArray();
  76. else return [];
  77. }
  78. /**
  79. * 获取拼团的团员
  80. * @param $id
  81. * @return mixed
  82. */
  83. public static function getPinkMember($id)
  84. {
  85. $model = new self();
  86. $model = $model->alias('p');
  87. $model = $model->field('p.*,u.nickname,u.avatar');
  88. $model = $model->where('k_id', $id);
  89. // $model = $model->where('is_refund', 0);
  90. $model = $model->join('user u', 'u.uid = p.uid');
  91. $model = $model->order('id asc');
  92. $list = $model->select();
  93. if ($list) return $list->toArray();
  94. else return [];
  95. }
  96. /**
  97. * 拼团退款
  98. * @param $id
  99. * @return bool
  100. */
  101. public static function setRefundPink($oid)
  102. {
  103. $res = true;
  104. $order = StoreOrder::where('id', $oid)->find();
  105. if ($order['pink_id']) $id = $order['pink_id'];
  106. else return $res;
  107. $count = self::where('id', $id)->where('uid', $order['uid'])->find();//正在拼团 团长
  108. $countY = self::where('k_id', $id)->where('uid', $order['uid'])->find();//正在拼团 团员
  109. if (!$count && !$countY) return $res;
  110. if ($count) {//团长
  111. //判断团内是否还有其他人 如果有 团长为第二个进团的人
  112. $kCount = self::where('k_id', $id)->order('add_time asc')->find();
  113. if ($kCount) {
  114. $res11 = true;
  115. // $res11 = self::where('k_id',$id)->update(['k_id'=>$kCount['id']]);
  116. // $res12 = self::where('id',$kCount['id'])->update(['stop_time'=>$count['add_time']+86400,'k_id'=>0]);
  117. $res12 = self::where('id', $kCount['id'])->update(['stop_time' => $count['add_time'] + 86400]);
  118. $res1 = $res11 && $res12;
  119. // $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$kCount['id'],'status'=>3]);
  120. $res2 = self::where('id', $id)->update(['stop_time' => time() - 1, 'is_refund' => 1, 'status' => 3]);
  121. } else {
  122. $res1 = true;
  123. // $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
  124. $res2 = self::where('id', $id)->update(['stop_time' => time() - 1, 'is_refund' => 1, 'status' => 3]);
  125. }
  126. //修改结束时间为前一秒 团长ID为0
  127. $res = $res1 && $res2;
  128. } else if ($countY) {//团员
  129. // $res = self::where('id',$countY['id'])->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
  130. $res = self::where('id', $countY['id'])->update(['stop_time' => time() - 1, 'is_refund' => 1, 'status' => 3]);
  131. }
  132. return $res;
  133. }
  134. }