wesmiler 1 day ago
parent
commit
d35c860352

+ 0 - 26
app/Http/Controllers/Api/v1/ArticleController.php

@@ -3,10 +3,7 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
-use App\Http\Validator\ConsultValidator;
 use App\Services\Api\ArticleService;
-use App\Services\Api\SupervisorsService;
-use App\Services\Common\AdService;
 
 /**
  * 文章管理
@@ -76,27 +73,4 @@ class ArticleController extends webApp
         }
     }
 
-    /**
-     * 咨询提交
-     */
-    public function consult(ConsultValidator $validator)
-    {
-        $params = request()->post();
-        $params = $validator->check($params, 'submit');
-        if (!is_array($params)) {
-            return showJson($params, false);
-        }
-        try {
-            if (ArticleService::make()->consultSubmit($this->userId, $params)) {
-                return showJson(ArticleService::make()->getError(), true);
-            } else {
-                return showJson(ArticleService::make()->getError(), false);
-            }
-        }  catch (\Exception $exception) {
-            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
-            return showJson(1046, false, $error);
-        }
-    }
-
-
 }

+ 47 - 0
app/Http/Controllers/Api/v1/MemberCouponController.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Api\MemberCouponService;
+
+/**
+ * 优惠券
+ * @package App\Http\Controllers\Api
+ */
+class MemberCouponController extends webApp
+{
+
+    /**
+     * 列表
+     * @return array
+     */
+    public function index()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $params['user_id'] = $this->userId;
+        $datas = MemberCouponService::make()->getDataList($params, $pageSize);
+        return showJson(1010, true, $datas);
+    }
+
+    /**
+     * 详情
+     * @return array
+     */
+    public function info()
+    {
+        $params = request()->all();
+        $id = isset($params['id'])? $params['id'] : 0;
+        try {
+            if(!$result = MemberCouponService::make()->getInfo($id, $this->userId)){
+                return showJson(1009, false);
+            }else{
+                return showJson(1010, true, $result);
+            }
+        } catch (\Exception $exception) {
+            $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
+            return showJson(1046, false, $error);
+        }
+    }
+}

+ 285 - 0
app/Services/Api/MemberCouponService.php

@@ -0,0 +1,285 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\MemberAddressModel;
+use App\Models\MemberCouponModel;
+use App\Services\BaseService;
+use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 用户优惠券管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Services\Api
+ */
+class MemberCouponService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function __construct()
+    {
+        $this->model = new MemberCouponModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1,'a.status'=>1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        if ($userId > 0) {
+            $where['a.user_id'] = $userId;
+        }
+        $list = $this->model->from('member_coupons as a')
+            ->where($where)
+            ->where(function($query) use($params){
+                $ids = isset($params['ids'])?$params['ids']:[];
+                if($ids){
+                    $query->where(function($query) use($ids){
+                        $query->where(DB::raw("FIND_IN_SET(?, goods_ids)",[implode(',', $ids)]))
+                            ->orWhere('goods_ids','');
+                    });
+                }else{
+                    $query->where('goods_ids','');
+                }
+
+                $total = isset($params['total'])?$params['total']:0;
+                if($total){
+                    $query->where(function($query) use($total){
+                        $query->where(function($query) use($total){
+                                $query->where('a.coupon_type',10)
+                                    ->where('a.min_price','<=', $total);
+                            })
+                            ->orWhereIn('a.coupon_type',[20,30]);
+                    });
+                }
+            })
+            ->select(['a.*'])
+            ->orderBy('a.reduce_price', 'desc')
+            ->orderBy('a.id', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 保存数据
+     * @param $userId
+     * @param $params
+     * @return mixed
+     */
+    public function saveData($userId, $params)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $isDefault = isset($params['is_default']) ? $params['is_default'] : 2;
+        $data = [
+            'user_id'=> $userId,
+            'mobile'=> isset($params['mobile'])? $params['mobile'] : '',
+            'realname'=> isset($params['realname'])? $params['realname'] : '',
+            'province'=> isset($params['province'])? $params['province'] : '',
+            'city'=> isset($params['city'])? $params['city'] : '',
+            'district'=> isset($params['district'])? $params['district'] : '',
+            'codes'=> isset($params['codes'])? $params['codes'] : '',
+            'address'=> isset($params['address'])? $params['address'] : '',
+            'is_default'=> $isDefault==1? 1: 2,
+            'status'=> isset($params['status'])? $params['status'] : 1,
+            'update_time'=> time(),
+            'mark'=> 1,
+        ];
+
+        DB::beginTransaction();
+        if($isDefault==1){
+            $this->model->where(['user_id'=> $userId])->update(['is_default'=> 2,'update_time'=> time()]);
+        }
+
+        RedisService::keyDel("caches:members:address:{$userId}*");
+        if($id && $id = $this->model->where(['id'=> $id])->value('id')){
+            $this->model->where(['id'=> $id])->update($data);
+            $this->error = '保存成功';
+            DB::commit();
+            return ['id'=>$id];
+        }else{
+            $data['create_time'] = time();
+            if(!$id = $this->model->insertGetId($data)){
+                DB::rollBack();
+                $this->error = '添加失败';
+                return false;
+            }
+
+            DB::commit();
+            $this->error = '添加成功';
+            return ['id'=>$id];
+        }
+    }
+
+    /**
+     * 默认
+     * @param $userId
+     * @param $params
+     * @return mixed
+     */
+    public function setDefault($userId, $params)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $isDefault = isset($params['is_default']) ? $params['is_default'] : 2;
+        $data = [
+            'user_id'=> $userId,
+            'is_default'=> $isDefault==1? 1: 2,
+            'update_time'=> time(),
+        ];
+
+
+        if($isDefault==1){
+            $this->model->where(['user_id'=> $userId])->update(['is_default'=> 2,'update_time'=> time()]);
+        }
+
+        $this->model->where(['id'=> $id])->update($data);
+        $this->error = '保存成功';
+        RedisService::keyDel("caches:members:address:{$userId}*");
+        return ['id'=>$id];
+    }
+
+    /**
+     * @param $id
+     * @param $userId
+     * @return array|mixed
+     */
+    public function getInfo($id, $userId)
+    {
+        $cacheKey = "caches:members:address:{$userId}_info_".($id?'_'.$id:'');
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+        $where = ['id'=> $id,'user_id'=> $userId,'mark'=>1,'status'=>1];
+        if($id<=0){
+            unset($where['id']);
+        }
+        $info = $this->model->where($where)->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            $address = [];
+            $info['mobile_text'] = format_mobile($info['mobile']);
+            if(isset($info['province']) && $info['province']){
+                $address[] = $info['province'];
+            }
+            if(isset($info['city']) && $info['city']){
+                $address[] = $info['city'];
+            }
+            if(isset($info['district']) && $info['district']){
+                $address[] = $info['district'];
+            }
+
+            $info['area'] = $address? implode('/', $address) : '';
+            if($info['address']){
+                $address[] = $info['address'];
+            }
+            $info['address_text'] = $address? implode(' ', $address) : '';
+            RedisService::set($cacheKey, $info, rand(5, 10));
+        }
+
+        return $info;
+    }
+
+    /**
+     * @param $userId
+     * @return array|mixed
+     */
+    public function getBindInfo($userId, $addressId=0)
+    {
+        $cacheKey = "caches:members:address:{$userId}".($addressId?'_'.$addressId:'');
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $where = ['id'=> $addressId,'user_id'=> $userId,'mark'=>1,'status'=>1];
+        if($addressId<=0){
+            unset($where['id']);
+        }
+        $info = $this->model->where($where)
+            ->orderBy('is_default','asc')
+            ->orderBy('id','desc')
+            ->first();
+        $info = $info? $info->toArray() : [];
+        if($info){
+            $address = [];
+            $info['mobile_text'] = format_mobile($info['mobile']);
+            if(isset($info['province']) && $info['province']){
+                $address[] = $info['province'];
+            }
+            if(isset($info['city']) && $info['city']){
+                $address[] = $info['city'];
+            }
+            if(isset($info['district']) && $info['district']){
+                $address[] = $info['district'];
+            }
+            $info['area'] = $address? implode('/', $address) : '';
+            if($info['address']){
+                $address[] = $info['address'];
+            }
+            $info['address_text'] = $address? implode(' ', $address) : '';
+            RedisService::set($cacheKey, $info, rand(5, 10));
+        }
+
+        return $info;
+    }
+
+    /**
+     * @return array|false
+     */
+    public function delete()
+    {
+        // 参数
+        $id = request()->post('id');
+        if (empty($id)) {
+            $this->error = 2014;
+            return false;
+        }
+
+        $this->error = 1002;
+        $this->model->where(['id'=> $id,'mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
+        return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
+    }
+}

+ 7 - 25
app/Services/Api/OrderService.php

@@ -231,6 +231,7 @@ class OrderService extends BaseService
     public function createOrder($userId, $params)
     {
         $addressId = isset($params['address_id']) && $params['address_id'] ? $params['address_id'] : 0;
+        $couponId = isset($params['coupon_id']) && $params['coupon_id'] ? $params['coupon_id'] : 0;
         $submitType = isset($params['submit_type']) && $params['submit_type'] ? $params['submit_type'] : 0;
         $goods = isset($params['goods']) && $params['goods'] ? $params['goods'] : [];
         $ids = $goods ? array_column($goods, 'id') : [];
@@ -282,6 +283,8 @@ class OrderService extends BaseService
         $orderGoods = isset($result['goods']) ? $result['goods'] : [];
         $goodsTotal = isset($result['goods_total']) ? $result['goods_total'] : 0; // 商品总价
         $orderTotal = isset($result['order_total']) ? $result['order_total'] : 0; // 订单结算金额(折后)
+        $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 会员折扣金额
+        $couponTotal = isset($result['coupon_total']) ? $result['coupon_total'] : 0; // 优惠金额
         $discountTotal = isset($result['discount_total']) ? $result['discount_total'] : 0; // 折扣金额
         $orderCount = isset($result['count']) ? $result['count'] : 0;
         $deliveryFee = isset($result['delivery_fee']) ? $result['delivery_fee'] : 0; // 运费
@@ -316,29 +319,6 @@ class OrderService extends BaseService
             return false;
         }
 
-        // 商家佣金
-        $storeInfo = StoreModel::where(['id' => $storeId])->first();
-        $bonusRate = isset($storeInfo['bonus_rate']) ? floatval($storeInfo['bonus_rate']) : 0;
-        $storeBonusRate = ConfigService::make()->getConfigByCode('store_bonus_rate', 0);
-        $storeBonusRate = $storeBonusRate > 0 && $storeBonusRate <= 100 ? $storeBonusRate : 0;
-        $bonusRate = $bonusRate > 0 && $bonusRate <= 100 ? $bonusRate : $storeBonusRate;
-        $bonus = moneyFormat($orderTotal * $bonusRate / 100, 2);
-
-        // 检查是否关联为会议订单,先签到的会议先关联
-        $record = MeetingRecordsModel::with(['meeting'])->where(['user_id'=>$userId,'mark'=>1])
-            ->where('expired_at','>=', date('Y-m-d H:i:s'))
-            ->orderBy('create_time', 'desc')
-            ->first();
-        $recordMeetingId = isset($record['meeting_id'])? $record['meeting_id'] : 0;
-        $meeting = isset($record['meeting'])?$record['meeting'] : [];
-        $meetingBonusRate = isset($meeting['bonus_rate'])?$meeting['bonus_rate'] : 0;
-        $meetingUserBonusRate = isset($meeting['user_bonus_rate'])?$meeting['user_bonus_rate'] : 0;
-        $meetingBonusRate = $meetingBonusRate>0 && $meetingBonusRate<100? $meetingBonusRate : 0;
-        $meetingUserBonusRate = $meetingUserBonusRate>0 && $meetingUserBonusRate<100? $meetingUserBonusRate : 0;
-        $meetingBonus = moneyFormat($orderTotal * $meetingBonusRate / 100, 2);
-        $meetingUserBonus = moneyFormat($orderTotal * $meetingUserBonusRate / 100, 2);
-
-
         // 是否开启分账功能
         $payTotal = moneyFormat($orderTotal + $deliveryFee, 2); // 含运费支付金额
         $revenueOpen = ConfigService::make()->getConfigByCode('order_revenue_open', 0);
@@ -358,8 +338,10 @@ class OrderService extends BaseService
             'total' => $goodsTotal, // 商品总价
             'num' => $orderCount,
             'pay_total' => $orderTotal, // 折扣后商品总价(不含运费)
-            'discount_point' => $discountPoint,
-            'discount_total' => $discountTotal, // 折扣金额
+            'discount_point' => $discountPoint, //会员折扣
+            'discount_total' => $discountTotal, // 会员折扣金额
+            'coupon_id' => $couponId, // 优惠券
+            'coupon_total' => $couponTotal, // 优惠金额
             'delivery_fee' => $deliveryFee, // 运费
             'receiver_name' => $realname,
             'receiver_mobile' => $mobile,

+ 4 - 0
routes/api.php

@@ -75,6 +75,10 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::post('/user/banks/save', [\App\Http\Controllers\Api\v1\MemberBankController::class, 'save']);
     Route::post('/user/banks/delete', [\App\Http\Controllers\Api\v1\MemberBankController::class, 'delete']);
 
+    // 优惠券
+    Route::post('/coupon/index', [\App\Http\Controllers\Api\v1\MemberCouponController::class, 'delete']);
+    Route::post('/coupon/list', [\App\Http\Controllers\Api\v1\MemberCouponController::class, 'delete']);
+
 
     // 账户明细
     Route::post('/account/index', [\App\Http\Controllers\Api\v1\AccountController::class, 'index']);