PinkApi.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace app\ebapi\controller;
  3. use app\admin\model\system\SystemAttachment;
  4. use app\core\model\routine\RoutineCode;
  5. use app\core\util\SystemConfigService;
  6. use app\ebapi\model\store\StoreCombination;
  7. use app\ebapi\model\store\StoreOrder;
  8. use app\ebapi\model\store\StorePink;
  9. use app\ebapi\model\store\StoreProductRelation;
  10. use app\ebapi\model\store\StoreProductReply;
  11. use app\ebapi\model\user\WechatUser;
  12. use app\core\util\GroupDataService;
  13. use service\JsonService;
  14. use service\UploadService;
  15. use service\UtilService;
  16. /**
  17. * TODO 小程序拼团产品和拼团其他api接口
  18. * Class PinkApi
  19. * @package app\ebapi\controller
  20. */
  21. class PinkApi extends AuthController
  22. {
  23. /**
  24. * TODO 获取拼团列表
  25. */
  26. public function get_combination_list(){
  27. $data = UtilService::postMore([['offset',0],['limit',20]]);
  28. $store_combination = StoreCombination::getAll($data['offset'],$data['limit']);
  29. return JsonService::successful($store_combination);
  30. }
  31. /**
  32. * TODO 获取拼团列表顶部图
  33. */
  34. public function get_combination_list_banner(){
  35. return JsonService::successful();
  36. }
  37. /**
  38. * TODO 获取拼团产品详情
  39. * @throws \think\Exception
  40. * @throws \think\exception\DbException
  41. */
  42. public function combination_detail(){
  43. list($id) = UtilService::postMore([['id',0]],null,true);
  44. if(!$id) return JsonService::fail('拼团不存在或已下架');
  45. $combinationOne = StoreCombination::getCombinationOne($id);
  46. if(!$combinationOne) return JsonService::fail('拼团不存在或已下架');
  47. $combinationOne['images'] = json_decode($combinationOne['images'],true);
  48. $combinationOne['userCollect'] = StoreProductRelation::isProductRelation($id,$this->userInfo['uid'],'collect','pink_product');
  49. list($pink ,$pindAll)= StorePink::getPinkAll($id,true);//拼团列表
  50. $data['pink'] = $pink;
  51. $data['user'] = $this->userInfo;//用户信息
  52. $data['pindAll'] = $pindAll;
  53. $data['storeInfo'] = $combinationOne;
  54. $data['pink_ok_list']=StorePink::getPinkOkList($this->uid);
  55. $data['pink_ok_sum']=StorePink::getPinkOkSumTotalNum($id);
  56. $data['reply'] = StoreProductReply::getRecProductReply($combinationOne['product_id']);
  57. $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$combinationOne['product_id'])->count();
  58. if($data['replyCount']){
  59. $goodReply=StoreProductReply::productValidWhere()->where('product_id',$combinationOne['product_id'])->where('product_score',5)->count();
  60. $data['replyChance']=bcdiv($goodReply,$data['replyCount'],2);
  61. $data['replyChance']=bcmul($data['replyChance'],100,3);
  62. }else $data['replyChance']=0;
  63. return JsonService::successful($data);
  64. }
  65. /**
  66. * 开团页面
  67. * @param int $id
  68. * @return mixed
  69. */
  70. public function get_pink($id = 0){
  71. $is_ok = 0;//判断拼团是否完成
  72. $userBool = 0;//判断当前用户是否在团内 0未在 1在
  73. $pinkBool = 0;//判断当前用户是否在团内 0未在 1在
  74. if(!$id) return JsonService::fail('参数错误');
  75. $pink = StorePink::getPinkUserOne($id);
  76. if(isset($pink['is_refund']) && $pink['is_refund']) {
  77. if($pink['is_refund'] != $pink['id']){
  78. $id = $pink['is_refund'];
  79. return $this->get_pink($id);
  80. }else{
  81. return JsonService::fail('订单已退款');
  82. }
  83. }
  84. if(!$pink) return JsonService::fail('参数错误');
  85. list($pinkAll,$pinkT,$count,$idAll,$uidAll)=StorePink::getPinkMemberAndPinkK($pink);
  86. if($pinkT['status'] == 2){
  87. $pinkBool = 1;
  88. $is_ok = 1;
  89. }else{
  90. if(!$count){//组团完成
  91. $is_ok = 1;
  92. $pinkBool=StorePink::PinkComplete($uidAll,$idAll,$this->userInfo['uid'],$pinkT);
  93. }else{
  94. $pinkBool=StorePink::PinkFail($pinkAll,$pinkT,$pinkBool);
  95. }
  96. }
  97. if(!empty($pinkAll)){
  98. foreach ($pinkAll as $v){
  99. if($v['uid'] == $this->userInfo['uid']) $userBool = 1;
  100. }
  101. }
  102. if($pinkT['uid'] == $this->userInfo['uid']) $userBool = 1;
  103. $combinationOne = StoreCombination::getCombinationOne($pink['cid']);
  104. if(!$combinationOne) return JsonService::fail('拼团不存在或已下架');
  105. $data['userInfo'] = $this->userInfo;
  106. $data['pinkBool'] = $pinkBool;
  107. $data['is_ok'] = $is_ok;
  108. $data['userBool'] = $userBool;
  109. $data['store_combination'] =$combinationOne;
  110. $data['pinkT'] = $pinkT;
  111. $data['pinkAll'] = $pinkAll;
  112. $data['count'] = $count;
  113. $data['store_combination_host'] = StoreCombination::getCombinationHost();
  114. $data['current_pink_order'] = StorePink::getCurrentPink($id,$this->uid);
  115. return JsonService::successful($data);
  116. }
  117. /**
  118. * 获取今天正在拼团的人的头像和名称
  119. * @return \think\response\Json
  120. */
  121. public function get_pink_second_one()
  122. {
  123. return JsonService::successful(StorePink::getPinkSecondOne());
  124. }
  125. /*
  126. * 取消开团
  127. * @param int $pink_id 团长id
  128. * */
  129. public function remove_pink($pink_id=0,$cid=0,$formId='')
  130. {
  131. if(!$pink_id || !$cid) return JsonService::fail('缺少参数');
  132. $res=StorePink::removePink($this->uid,$cid,$pink_id,$formId);
  133. if($res)
  134. return JsonService::successful('取消成功');
  135. else{
  136. $error=StorePink::getErrorInfo();
  137. if(is_array($error))
  138. return JsonService::status($error['status'],$error['msg']);
  139. else
  140. return JsonService::fail($error);
  141. }
  142. }
  143. /**
  144. * TODO 生成海报
  145. */
  146. public function pink_share_poster()
  147. {
  148. list($pinkId) = UtilService::postMore([['id',0]],null,true);
  149. $pinkInfo = StorePink::getPinkUserOne($pinkId);
  150. $storeCombinationInfo = StoreCombination::getCombinationOne($pinkInfo['cid']);
  151. $data['title'] = $storeCombinationInfo['title'];
  152. if(stripos($storeCombinationInfo['image'], '/public/uploads/'))
  153. $data['image'] = ROOT_PATH.substr($storeCombinationInfo['image'],stripos($storeCombinationInfo['image'], '/public/uploads/'),strlen($storeCombinationInfo['image']));
  154. else
  155. $data['image'] = $storeCombinationInfo['image'];
  156. $data['price'] = $pinkInfo['total_price'];
  157. $data['label'] = $pinkInfo['people'].'人团';
  158. if($pinkInfo['k_id']) $pinkAll = StorePink::getPinkMember($pinkInfo['k_id']);
  159. else $pinkAll = StorePink::getPinkMember($pinkInfo['id']);
  160. $count = count($pinkAll)+1;
  161. $data['msg'] = '原价¥'.$storeCombinationInfo['product_price'].' 还差'.(int)bcsub((int)$pinkInfo['people'],$count,0).'人拼团成功';
  162. try{
  163. $name = $pinkId.'_'.$this->userInfo['uid'].'_'.$this->userInfo['is_promoter'].'_pink_share.jpg';
  164. $imageInfo = SystemAttachment::getInfo($name,'name');
  165. $siteUrl = SystemConfigService::get('site_url').DS;
  166. if(!$imageInfo){
  167. $valueData = 'id='.$pinkId.'&pid='.$this->uid;
  168. // if($this->userInfo['is_promoter'] || SystemConfigService::get('store_brokerage_statu')==2) $valueData.='&pid='.$this->uid;
  169. $res = RoutineCode::getPageCode('pages/activity/goods_combination_status/index',$valueData,280);
  170. if(!$res) return JsonService::fail('二维码生成失败');
  171. $imageInfo = UploadService::imageStream($name,$res,'routine/activity/pink/code');
  172. if(!is_array($imageInfo)) return JsonService::fail($imageInfo);
  173. if($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl.$imageInfo['dir']);
  174. else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
  175. if(!$remoteImage['status']) return JsonService::fail($remoteImage['msg']);
  176. SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time'],2);
  177. $url = $imageInfo['dir'];
  178. }else $url = $imageInfo['att_dir'];
  179. if($imageInfo['image_type'] == 1)
  180. $data['url'] = str_replace('//','/',ROOT_PATH.$url);
  181. else
  182. $data['url'] = $url;
  183. $posterImage = UtilService::setShareMarketingPoster($data,'routine/activity/pink/poster');
  184. if(!is_array($posterImage)) return JsonService::fail('海报生成失败');
  185. SystemAttachment::attachmentAdd($posterImage['name'],$posterImage['size'],$posterImage['type'],$posterImage['dir'],$posterImage['thumb_path'],1,$posterImage['image_type'],$posterImage['time'],2);
  186. if($posterImage['image_type'] == 1) $posterImage['dir'] = $siteUrl.$posterImage['dir'];
  187. return JsonService::successful('ok',$posterImage['dir']);
  188. }catch (\Exception $e){
  189. return JsonService::fail('系统错误:生成图片失败',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
  190. }
  191. }
  192. }