StorePink.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. $model = new self;
  25. $model = $model->alias('p');
  26. $model = $model->field('p.*,c.title,u.nickname,u.avatar');
  27. if($where['data'] !== ''){
  28. list($startTime,$endTime) = explode(' - ',$where['data']);
  29. $model = $model->where('p.add_time','>',strtotime($startTime));
  30. $model = $model->where('p.add_time','<',strtotime($endTime));
  31. }
  32. if($where['status']) $model = $model->where('p.status',$where['status']);
  33. $model = $model->where('p.k_id',0);
  34. $model = $model->order('p.id desc');
  35. $model = $model->join('store_combination c','c.id=p.cid');
  36. $model = $model->join('user u','u.uid = p.uid');
  37. return self::page($model,function($item)use($where){
  38. $item['count_people'] = bcadd(self::where('k_id',$item['id'])->count(),1,0);
  39. },$where);
  40. }
  41. /**
  42. * 获取当前产品参与的人数
  43. * @param int $combinationId
  44. * @return int|string
  45. */
  46. public static function getCountPeopleAll($combinationId = 0){
  47. if(!$combinationId) return self::count();
  48. return self::where('cid',$combinationId)->count();
  49. }
  50. /**
  51. * 获取当前产品参与的团数
  52. * @param int $combinationId
  53. * @return int|string
  54. */
  55. public static function getCountPeoplePink($combinationId = 0){
  56. if(!$combinationId) return self::where('k_id',0)->count();
  57. return self::where('cid',$combinationId)->where('k_id',0)->count();
  58. }
  59. /**
  60. * 获取一条拼团数据
  61. * @param $id
  62. * @return mixed
  63. */
  64. public static function getPinkUserOne($id){
  65. $model = new self();
  66. $model = $model->alias('p');
  67. $model = $model->field('p.*,u.nickname,u.avatar');
  68. $model = $model->where('id',$id);
  69. $model = $model->join('user u','u.uid = p.uid');
  70. $list = $model->find();
  71. if($list) return $list->toArray();
  72. else return [];
  73. }
  74. /**
  75. * 获取拼团的团员
  76. * @param $id
  77. * @return mixed
  78. */
  79. public static function getPinkMember($id){
  80. $model = new self();
  81. $model = $model->alias('p');
  82. $model = $model->field('p.*,u.nickname,u.avatar');
  83. $model = $model->where('k_id',$id);
  84. $model = $model->where('is_refund',0);
  85. $model = $model->join('user u','u.uid = p.uid');
  86. $model = $model->order('id asc');
  87. $list = $model->select();
  88. if($list) return $list->toArray();
  89. else return [];
  90. }
  91. /**
  92. * 拼团退款
  93. * @param $id
  94. * @return bool
  95. */
  96. public static function setRefundPink($oid){
  97. $res = true;
  98. $order = StoreOrder::where('id',$oid)->find();
  99. if($order['pink_id']) $id = $order['pink_id'];
  100. else return $res;
  101. $count = self::where('id',$id)->where('uid',$order['uid'])->find();//正在拼团 团长
  102. $countY = self::where('k_id',$id)->where('uid',$order['uid'])->find();//正在拼团 团员
  103. if(!$count && !$countY) return $res;
  104. if($count){//团长
  105. //判断团内是否还有其他人 如果有 团长为第二个进团的人
  106. $kCount = self::where('k_id',$id)->order('add_time asc')->find();
  107. if($kCount){
  108. $res11 = self::where('k_id',$id)->update(['k_id'=>$kCount['id']]);
  109. $res12 = self::where('id',$kCount['id'])->update(['stop_time'=>$count['add_time']+86400,'k_id'=>0]);
  110. $res1 = $res11 && $res12;
  111. $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$kCount['id'],'status'=>3]);
  112. }else{
  113. $res1 = true;
  114. $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
  115. }
  116. //修改结束时间为前一秒 团长ID为0
  117. $res = $res1 && $res2;
  118. }else if($countY){//团员
  119. $res = self::where('id',$countY['id'])->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
  120. }
  121. return $res;
  122. }
  123. }