|
|
@@ -0,0 +1,155 @@
|
|
|
+<?php
|
|
|
+namespace app\api\logic;
|
|
|
+
|
|
|
+use app\common\logic\BaseLogic;
|
|
|
+use app\common\model\group_activity\GroupActivity;
|
|
|
+use think\facade\Db;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 拼团活动逻辑处理
|
|
|
+ * Class GroupActivityLogic
|
|
|
+ * @package app\api\logic
|
|
|
+ */
|
|
|
+class GroupActivityLogic extends BaseLogic
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 拼团活动详情
|
|
|
+ */
|
|
|
+ public static function detail($id){
|
|
|
+ $detail = GroupActivity::where(['id'=>$id])->visible([
|
|
|
+ 'id','title','image','start_time','end_time','type','equity_id',
|
|
|
+ 'participant_num','origin_price','price','form_time_limit','is_simulate_form','simulate_num'
|
|
|
+ ])->select()->toArray();
|
|
|
+
|
|
|
+ if(!empty($detail)){
|
|
|
+ $detail['price'] = explode(",",$detail['price']);
|
|
|
+ $detail['participant_num'] = explode(",",$detail['participant_num']);
|
|
|
+ $detail['simulate_num'] = $detail['simulate_num'] ? explode(",",$detail['simulate_num']) : [];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function orderDetail($id,$userId){
|
|
|
+ $goods = GroupOrder::where(['id'=>$id, 'user_id' => $userId])->visible([
|
|
|
+ 'id','sn','group_activity_id','status','create_time','sell_num','base_service_fee',
|
|
|
+ 'service_total','service_fee','service_image','fee_schedule','warranty_period','goods_payment_type','goods_category_id'
|
|
|
+ ])->select()
|
|
|
+ ->each(function (&$item, $key) use ($userId){
|
|
|
+ //判定是否存在可使用的用户优惠券,存在的话直接更新展示价格
|
|
|
+ if($userId!=0){
|
|
|
+ $result = UserCouponLogic::categoryWithAmountLists(['user_id'=>$userId,'amount'=>$item['service_fee'],'goods_category_id'=>$item['goods_category_id'],'goods_id'=>$item['id']]);
|
|
|
+ if(!empty($result[0]['amount'])){
|
|
|
+ $item['base_service_fee'] = '券后'.($item['base_service_fee'] - $result[0]['amount']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })->toArray();
|
|
|
+
|
|
|
+ if(!empty($goods)){
|
|
|
+ $data = [];
|
|
|
+ foreach ($goods as $key => $value) {
|
|
|
+ if($value['goods_payment_type'] == '2'){
|
|
|
+ $coupon = ($value['service_total']-$value['service_fee'])>0?'立减'.$value['service_total']-$value['service_fee']:'';
|
|
|
+ }
|
|
|
+ if($value['goods_payment_type'] == '3'){
|
|
|
+ $coupon = '首付'.$value['service_fee'];
|
|
|
+ }
|
|
|
+ $data[] = [
|
|
|
+ 'id'=>$value['id'],
|
|
|
+ 'goods_image'=>$value['goods_image'],
|
|
|
+ 'goods_name'=>$value['goods_name'],
|
|
|
+ 'good_unit'=>$value['good_unit'],
|
|
|
+ 'goods_banners'=>!empty($value['goods_banners']) ? $value['goods_banners'] : [],
|
|
|
+ 'goods_payment_type'=>$value['goods_payment_type'],
|
|
|
+ 'sell_num'=>$value['sell_num'],
|
|
|
+ 'base_service_fee'=>$value['base_service_fee'],
|
|
|
+ 'service_total'=>$value['service_total'],
|
|
|
+ 'service_fee'=>$value['service_fee'],
|
|
|
+ 'coupon'=>!empty($coupon)?$coupon:'',
|
|
|
+ 'service_image'=>$value['service_image'],
|
|
|
+ 'warranty_period'=>$value['warranty_period'],
|
|
|
+ 'fee_schedule'=>$value['fee_schedule'],
|
|
|
+ 'goods_category_id'=>$value['goods_category_id']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $goods = $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $goods;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getHotData()
|
|
|
+ {
|
|
|
+ return Goods::where(['user_id'=>0,'is_hot'=>1,'platform_value'=>0])
|
|
|
+ ->with('goodsCategory')
|
|
|
+ ->visible(['id','goods_name','goods_image'])
|
|
|
+ ->order(['top_weight' => 'desc', 'id' => 'desc'])
|
|
|
+ ->select()->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function sync(array $params,int $userId): bool
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if(isset($params['id'])){
|
|
|
+ $model = Goods::findOrEmpty($params['id']);
|
|
|
+ if($model->isEmpty()){
|
|
|
+ throw new \Exception('数据异常');
|
|
|
+ }
|
|
|
+ } else{
|
|
|
+ $model = new Goods();
|
|
|
+ }
|
|
|
+ $params['goods_category_id'] = end($params['goods_category_ids']);
|
|
|
+ $model->goods_category_id = $params['goods_category_id'];
|
|
|
+ $model->category_type = GoodsCategory::where('id',$params['goods_category_id'])->value('category_type');
|
|
|
+ $model->goods_category_ids = $params['goods_category_ids'];
|
|
|
+ $model->goods_category_id = $params['goods_category_id'];
|
|
|
+ $model->goods_name = $params['goods_name'];
|
|
|
+ $model->goods_image = $params['goods_image'];
|
|
|
+ $model->goods_video = $params['goods_video'];
|
|
|
+ $model->goods_banners = $params['goods_banners'];
|
|
|
+ $model->goods_number = $params['goods_number'];
|
|
|
+ $model->good_unit = $params['good_unit'];
|
|
|
+ $model->goods_size = $params['goods_size'];
|
|
|
+ $model->goods_type = $params['goods_type'];
|
|
|
+ $model->goods_brand = $params['goods_brand'];
|
|
|
+ $model->install_guide = $params['install_guide'];
|
|
|
+ $model->goods_payment_type = $params['goods_payment_type'];
|
|
|
+ $model->base_service_fee = $params['base_service_fee'];
|
|
|
+ $model->service_total = $params['service_total'];
|
|
|
+ $model->service_fee = $params['service_fee'];
|
|
|
+ $model->service_image = $params['service_image'];
|
|
|
+ $model->warranty_period = $params['warranty_period'];
|
|
|
+ $model->fee_schedule = $params['fee_schedule'];
|
|
|
+ $model->goods_status = $params['goods_status'];
|
|
|
+ $model->user_id = $userId;
|
|
|
+ $model->save();
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function firmGoodsDetail($params){
|
|
|
+ try{
|
|
|
+ $data= Goods::where('id',$params['id'])
|
|
|
+ ->where('user_id',$params['user_id'])
|
|
|
+ ->with('goodsCategory')
|
|
|
+ ->withoutField(['is_recommend','recommend_weight','is_top','top_weight','is_hot','hot_weight'])
|
|
|
+ ->findOrEmpty()->toArray();
|
|
|
+ if(!empty($data['goods_category_ids'])) {
|
|
|
+ $data['goods_category_ids'] = array_map("intval", $data['goods_category_ids']);
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }catch(\Exception $e){
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|