소스 검색

wesmiler 抢表商城

APPLE 3 년 전
부모
커밋
8ae1f01bfe

+ 50 - 0
app/Http/Controllers/Admin/OrderController.php

@@ -0,0 +1,50 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Admin;
+
+use App\Services\Common\OrderService;
+
+/**
+ * 积分订单管理-控制器
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class OrderController
+ * @package App\Http\Controllers
+ */
+class OrderController extends Backend
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * OrderController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new OrderService();
+    }
+
+    public function index()
+    {
+        $params = request()->all();
+        $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
+        $list = OrderService::make()->getDataList($params, $pageSize);
+        $message = array(
+            "msg" => '操作成功',
+            "code" => 0,
+            "data" => isset($list['list'])? $list['list']:[],
+            "count" => isset($list['total'])? $list['total']:0,
+        );
+        return $message;
+    }
+}

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

@@ -0,0 +1,33 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Common\ArticleService;
+
+/**
+ * 文章
+ * Class ArticleController
+ * @package App\Http\Controllers\Api
+ */
+class ArticleController extends webApp
+{
+
+    /**
+     * 关于我们
+     */
+    public function about()
+    {
+        $info = ArticleService::make()->getInfoByCate(1);
+        return message(1010, true, $info);
+    }
+
+    /**
+     * 协议
+     */
+    public function agree()
+    {
+        $info = ArticleService::make()->getInfoByCate(2);
+        return message(1010, true, $info);
+    }
+}

+ 4 - 4
app/Http/Controllers/Api/v1/GoodsController.php

@@ -89,7 +89,7 @@ class GoodsController extends webApp
     {
         $params = request()->all();
         $goodsId = isset($params['id'])? $params['id'] : 0;
-        if(GoodsService::make()->split($goodsId)){
+        if(GoodsService::make()->splitGoods($goodsId)){
             return message(GoodsService::make()->getError(), true);
         }else{
             return message(GoodsService::make()->getError(), false);
@@ -141,14 +141,14 @@ class GoodsController extends webApp
     }
 
     /**
-     * 
+     * 
      * @return array
      */
-    public function updateData()
+    public function modify()
     {
         $params = request()->all();
         $goodsId = isset($params['id'])? $params['id'] : 0;
-        if(GoodsService::make()->updateData($goodsId)){
+        if(GoodsService::make()->modify($goodsId)){
             return message(GoodsService::make()->getError(), true);
         }else{
             return message(GoodsService::make()->getError(), false);

+ 61 - 0
app/Http/Controllers/Api/v1/ShopController.php

@@ -0,0 +1,61 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Api\v1;
+
+
+use App\Http\Controllers\Api\webApp;
+use App\Services\Common\ShopService;
+
+/**
+ * 店铺管理-控制器
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ShopController
+ * @package App\Http\Controllers
+ */
+class ShopController extends webApp
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * ShopController constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new ShopService();
+    }
+
+    public function index()
+    {
+        $pageSize = request()->get('limit', 15);
+        $list = $this->service->getDataList(request()->all(), $pageSize);
+        $message = array(
+            "msg" => '操作成功',
+            "code" => 0,
+            "data" => isset($list['list'])? $list['list']:[],
+            "count" => isset($list['total'])? $list['total']:0,
+        );
+        return $message;
+    }
+
+
+    /**
+     * 选项列表
+     * @return mixed
+     */
+    public function options(){
+        $result = $this->service->options();
+        return message(1002,true, $result);
+    }
+}

+ 39 - 0
app/Models/ArticleModel.php

@@ -0,0 +1,39 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 文章管理-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ArticleModel
+ * @package App\Models
+ */
+class ArticleModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'article';
+
+    /**
+     * 获取信息
+     * @param int $id
+     * @return array|string
+     * @author laravel开发员
+     * @since 2020/11/11
+     */
+    public function getInfo($id)
+    {
+        $info = parent::getInfo($id); // TODO: Change the autogenerated stu
+        return $info;
+    }
+
+}

+ 125 - 0
app/Services/Common/ArticleService.php

@@ -0,0 +1,125 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Common;
+
+use App\Models\AccountModel;
+use App\Models\ArticleModel;
+use App\Services\BaseService;
+
+/**
+ * 文章管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * Class ArticleService
+ * @package App\Services\Common
+ */
+class ArticleService extends BaseService
+{
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * ArticleService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new ArticleModel();
+    }
+
+    /**
+     * 静态入口
+     * @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];
+        $status = isset($params['status'])? $params['status'] : 0;
+        $type = isset($params['type'])? $params['type'] : 0;
+        $cateId = isset($params['cate_id'])? $params['cate_id'] : 0;
+        if($status>0){
+            $where['a.status'] = $status;
+        }
+        if($type>0){
+            $where['a.type'] = $type;
+        }
+        if($cateId>0){
+            $where['a.cate_id'] = $cateId;
+        }
+        $list = $this->model->from('article as a')
+            ->leftJoin('article_cate as b', 'b.id', '=', 'a.cate_id')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $keyword = isset($params['keyword'])? $params['keyword'] : '';
+                if($keyword){
+                    $query->where('a.title','like',"%{$keyword}%")->orWhere('b.name','like',"%{$keyword}%");
+                }
+
+            })
+            ->select(['a.*','b.name as cate_name'])
+            ->orderBy('a.create_time','desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach($list['data'] as &$item){
+                $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
+                $item['cover'] = $item['cover']? get_image_url($item['cover']) : '';
+            }
+        }
+
+        return [
+            'pageSize'=> $pageSize,
+            'total'=>isset($list['total'])? $list['total'] : 0,
+            'list'=> isset($list['data'])? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 添加或编辑
+     * @return array
+     * @since 2020/11/11
+     * @author laravel开发员
+     */
+    public function edit()
+    {
+        $data = request()->all();
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 获取店铺交易统计
+     * @param $shopId
+     * @param int $type
+     * @param int $coinType
+     * @return mixed
+     */
+    public function getInfoByCate($cateId)
+    {
+
+        return $this->model->where(['cate_id'=> $cateId,'status'=>1,'mark'=>1])
+            ->orderBy('create_time','desc')
+            ->first();
+    }
+
+}

+ 245 - 120
app/Services/Common/GoodsService.php

@@ -64,58 +64,62 @@ class GoodsService extends BaseService
     public function getDataList($params, $pageSize = 15)
     {
         $where = ['a.mark' => 1];
-        $status = isset($params['status'])? $params['status'] : 0;
-        if($status>0){
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
             $where['a.status'] = $status;
         }
-        $isTrade = isset($params['is_trade'])? $params['is_trade'] : 0;
-        if($isTrade>0){
+        $isTrade = isset($params['is_trade']) ? $params['is_trade'] : 0;
+        if ($isTrade > 0) {
             $where['a.is_trade'] = $isTrade;
         }
+        $shopId = isset($params['shop_id']) ? $params['shop_id'] : 0;
+        if ($shopId > 0) {
+            $where['a.shop_id'] = $shopId;
+        }
         $list = $this->model->from('goods as a')
             ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
             ->leftJoin('shop as c', 'c.id', '=', 'a.shop_id')
             ->where($where)
-            ->where(function ($query) use($params){
-                $keyword = isset($params['keyword'])? $params['keyword'] : '';
-                if($keyword){
-                    $query->where('a.goods_name','like',"%{$keyword}%")->orWhere('c.name','like',"%{$keyword}%")->orWhere('b.nickname','like',"%{$keyword}%")->orWhere('b.mobile','like',"%{$keyword}%");
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['keyword']) ? $params['keyword'] : '';
+                if ($keyword) {
+                    $query->where('a.goods_name', 'like', "%{$keyword}%")->orWhere('c.name', 'like', "%{$keyword}%")->orWhere('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%");
                 }
 
-                $username = isset($params['username'])? $params['username'] : '';
-                if($username){
-                    $query->orWhere('b.nickname','like',"%{$keyword}%")->orWhere('b.mobile','like',"%{$keyword}%");
+                $username = isset($params['username']) ? $params['username'] : '';
+                if ($username) {
+                    $query->orWhere('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%");
                 }
             })
-            ->where(function($query) use ($params){
-                $time = isset($params['time'])? $params['time'] : '';
-                if($time){
-                    $query->where('a.last_sell_time','<=', $time);
+            ->where(function ($query) use ($params) {
+                $time = isset($params['time']) ? $params['time'] : '';
+                if ($time) {
+                    $query->where('a.last_sell_time', '<=', $time);
                 }
             })
-            ->where(function($query) use ($params){
-                $notUserId = isset($params['not_user_id'])? $params['not_user_id'] : 0;
-                if($notUserId){
+            ->where(function ($query) use ($params) {
+                $notUserId = isset($params['not_user_id']) ? $params['not_user_id'] : 0;
+                if ($notUserId) {
                     $query->whereNotIn('a.user_id', [$notUserId]);
                 }
             })
-            ->select(['a.*','b.nickname','b.code as user_code','b.mobile as mobile','c.name as shop_name','c.code as shop_code'])
-            ->orderBy('a.create_time','desc')
-            ->orderBy('a.id','desc')
+            ->select(['a.*', 'b.nickname', 'b.code as user_code', 'b.mobile as mobile', 'c.name as shop_name', 'c.code as shop_code'])
+            ->orderBy('a.create_time', 'desc')
+            ->orderBy('a.id', 'desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
-        $list = $list? $list->toArray() :[];
-        if($list){
-            foreach($list['data'] as &$item){
-                $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
-                $item['thumb'] = isset($item['thumb']) && $item['thumb']? get_image_url($item['thumb']) : '';
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
+                $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
                 $item['real_price'] = round($item['price'] - $item['sell_price'] + $item['source_price']);
             }
         }
 
         return [
-            'pageSize'=> $pageSize,
-            'total'=>isset($list['total'])? $list['total'] : 0,
-            'list'=> isset($list['data'])? $list['data'] : []
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
         ];
     }
 
@@ -128,17 +132,17 @@ class GoodsService extends BaseService
     public function getTradeGoods($params, $pageSize = 15)
     {
         $where = ['a.mark' => 1];
-        $status = isset($params['status'])? $params['status'] : 0;
-        $userId = isset($params['user_id'])? $params['user_id'] : 0;
-        $shopId = isset($params['shop_id'])? $params['shop_id'] : 0;
-        $isSell = isset($params['is_sell'])? $params['is_sell'] : 0;
-        if($status>0){
+        $status = isset($params['status']) ? $params['status'] : 0;
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        $shopId = isset($params['shop_id']) ? $params['shop_id'] : 0;
+        $isSell = isset($params['is_sell']) ? $params['is_sell'] : 0;
+        if ($status > 0) {
             $where['a.status'] = $status;
         }
-        if($shopId>0){
+        if ($shopId > 0) {
             $where['a.shop_id'] = $shopId;
         }
-        if($isSell>0){
+        if ($isSell > 0) {
             $where['a.is_sell'] = $isSell;
         }
         $list = $this->model->from('trade as a')
@@ -147,30 +151,30 @@ class GoodsService extends BaseService
             ->leftJoin('shop as d', 'd.id', '=', 'a.shop_id')
             ->leftJoin('goods as g', 'g.id', '=', 'a.goods_id')
             ->where($where)
-            ->where(function ($query) use($params){
-                $keyword = isset($params['keyword'])? $params['keyword'] : '';
-                if($keyword){
-                    $query->orWhere('b.nickname','like',"%{$keyword}%")->orWhere('b.mobile','like',"%{$keyword}%");
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['keyword']) ? $params['keyword'] : '';
+                if ($keyword) {
+                    $query->orWhere('b.nickname', 'like', "%{$keyword}%")->orWhere('b.mobile', 'like', "%{$keyword}%");
                 }
             })
-            ->select(['a.*','b.nickname','b.mobile as mobile','c.nickname as sell_nickname', 'c.mobile as sell_mobile','d.name as shop_name','g.goods_name','g.thumb','g.code','g.split_stop','g.status as goods_status'])
-            ->orderBy('a.confirm_time','desc')
-            ->orderBy('a.id','desc')
+            ->select(['a.*', 'b.nickname', 'b.mobile as mobile', 'c.nickname as sell_nickname', 'c.mobile as sell_mobile', 'd.name as shop_name', 'g.goods_name', 'g.thumb', 'g.code', 'g.split_stop', 'g.status as goods_status'])
+            ->orderBy('a.confirm_time', 'desc')
+            ->orderBy('a.id', 'desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
-        $list = $list? $list->toArray() :[];
-        if($list){
-            foreach($list['data'] as &$item){
-                $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H:i:s') : '';
-                $item['confirm_time'] = $item['confirm_time']? datetime($item['confirm_time'],'Y-m-d H:i:s') : '';
-                $item['thumb'] = isset($item['thumb']) && $item['thumb']? get_image_url($item['thumb']) : '';
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H:i:s') : '';
+                $item['confirm_time'] = $item['confirm_time'] ? datetime($item['confirm_time'], 'Y-m-d H:i:s') : '';
+                $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
 
             }
         }
 
         return [
-            'pageSize'=> $pageSize,
-            'total'=>isset($list['total'])? $list['total'] : 0,
-            'list'=> isset($list['data'])? $list['data'] : []
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
         ];
     }
 
@@ -185,18 +189,18 @@ class GoodsService extends BaseService
         // 请求参数
         $data = request()->all();
         // thumb处理
-        $thumb = isset($data['thumb'])? trim($data['thumb']) : '';
+        $thumb = isset($data['thumb']) ? trim($data['thumb']) : '';
         if ($thumb && strpos($thumb, "temp")) {
             $data['thumb'] = save_image($thumb, 'member');
-        } else if($thumb){
+        } else if ($thumb) {
             $data['thumb'] = str_replace(IMG_URL, "", $data['thumb']);
         }
 
-        if(!isset($data['code']) || empty($data['code'])){
-            $data['code'] = isset($data['id'])&&$data['id']? 'G'.$data['id'] :'G'.(GoodsModel::max('id')+1);
+        if (!isset($data['code']) || empty($data['code'])) {
+            $data['code'] = isset($data['id']) && $data['id'] ? 'G' . $data['id'] : 'G' . (GoodsModel::max('id') + 1);
         }
 
-        if(!isset($data['price']) || empty($data['price'])){
+        if (!isset($data['price']) || empty($data['price'])) {
             $data['price'] = $data['sell_price'];
         }
 //
@@ -213,9 +217,9 @@ class GoodsService extends BaseService
      */
     public function getInfo($where, array $field = [])
     {
-        $cacheKey = "caches:goods:".(!is_array($where)? $where : md5(json_encode($where)));
+        $cacheKey = "caches:goods:" . (!is_array($where) ? $where : md5(json_encode($where)));
         $info = RedisService::get($cacheKey);
-        if($info){
+        if ($info) {
             return $info;
         }
 
@@ -227,9 +231,9 @@ class GoodsService extends BaseService
         }
 
         $info = $info ? $info->toArray() : [];
-        if($info){
+        if ($info) {
             $info['thumb'] = $info['thumb'] ? get_image_url($info['thumb']) : '';
-            RedisService::set($cacheKey, $info, rand(5,10));
+            RedisService::set($cacheKey, $info, rand(5, 10));
         }
         return $info;
     }
@@ -241,75 +245,190 @@ class GoodsService extends BaseService
      */
     public function checkNewGoods($userId)
     {
-        return $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])
-            ->where('create_time','>=', strtotime(date('Y-m-d')))
+        return $this->model->where(['user_id' => $userId, 'status' => 1, 'mark' => 1])
+            ->where('create_time', '>=', strtotime(date('Y-m-d')))
             ->count('id');
     }
 
     /**
      * 拆分
-     * @param $info
-     * @param $goods
+     * @param $goodsId
+     * @param array $info
+     * @return bool
+     */
+    public function split($goodsId, $info = [])
+    {
+        $goods = $this->model->where(['id' => $goodsId, 'mark' => 1])->first();
+        $splitNum = isset($goods['split_num']) ? $goods['split_num'] : 0;
+        if ($splitNum <= 0) {
+            return false;
+        }
+
+        $datas = [];
+        $sumPrice = 0;
+        for ($i = 1; $i <= $splitNum; $i++) {
+            if ($i < $splitNum) {
+                $price = round($goods['price'] / $splitNum, 0);
+                $sumPrice += $price;
+            } else {
+                $price = round($goods['price'] - $sumPrice, 0);
+            }
+
+            $datas[] = [
+                'user_id' => $goods['user_id'],
+                'shop_id' => $goods['shop_id'],
+                'goods_name' => $goods['goods_name'],
+                'code' => $goods['code'] . '-' . $i,
+                'source_price' => round($goods['source_price'] / $splitNum, 0),
+                'sell_price' => round($goods['sell_price'] / $splitNum, 0),
+                'price' => $price,
+                'fee' => 0,
+                'thumb' => $goods['thumb'],
+                'albums' => $goods['albums'],
+                'content' => $goods['content'],
+                'split_num' => $goods['split_num'],
+                'split_price' => $goods['split_price'],
+                'last_sell_time' => time(),
+                'create_time' => time(),
+                'update_time' => time(),
+                'mark' => 1,
+                'status' => 1,
+            ];
+        }
+
+        DB::beginTransaction();
+        if ($datas) {
+            if (!$this->model->insert($datas)) {
+                DB::rollBack();
+                return false;
+            }
+
+            if (!$this->model->where(['id' => $goods['id'], 'mark' => 1])->update(['status' => 2, 'mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
+                DB::rollBack();
+                return false;
+            }
+
+            if ($info && !TradeModel::where(['id' => $info['id'], 'mark' => 1])->update(['is_split' => 1, 'mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
+                DB::rollBack();
+                return false;
+            }
+        }
+
+        DB::commit();
+        return true;
+    }
+
+    /**
+     * 手动拆分
+     * @param $goodsId
      * @return bool
      */
-    public function split($goodsId, $info=[])
+    public function splitGoods($goodsId)
     {
-        $goods = $this->model->where(['id'=> $goodsId,'mark'=>1])->first();
-        $splitNum = isset($goods['split_num'])? $goods['split_num'] : 0;
-        if($splitNum<=0){
+        $goods = $this->model->where(['id' => $goodsId, 'mark' => 1])->first();
+        $splitNum = isset($goods['split_num']) ? $goods['split_num'] : 0;
+        $splitPrice = isset($goods['split_price']) ? $goods['split_price'] : 0;
+        $sellPrice = isset($goods['sell_price']) ? $goods['sell_price'] : 0;
+        $sourcePrice = isset($goods['source_price']) ? $goods['source_price'] : 0;
+        $price = isset($goods['price']) ? $goods['price'] : 0;
+        if ($splitNum <= 0) {
+            $this->error = 2066;
+            return false;
+        }
+
+        $tradeInfo = TradeModel::where(['goods_id' => $goodsId, 'mark' => 1])
+            ->whereIn('status', [1, 2, 3, 4])
+            ->orderBy('create_time', 'desc')
+            ->first();
+        $tradeStatus = isset($tradeInfo['status']) ? $tradeInfo['status'] : 0;
+        $isSell = isset($tradeInfo['is_sell']) ? $tradeInfo['is_sell'] : 0;
+        if ($tradeInfo && in_array($tradeStatus, [1, 2, 3])) {
+            $this->error = 2067;
+            return false;
+        }
+
+        if ($tradeInfo && $tradeStatus==4 && $isSell != 2) {
+            $this->error = 2068;
+            return false;
+        }
+
+        $priceRate = ConfigService::make()->getConfigByCode('price_rate');
+        $priceRate = $priceRate ? $priceRate : 4;
+
+        $stopSplitPrice = ConfigService::make()->getConfigByCode('stop_split_price');
+        $stopSplitPrice = $stopSplitPrice ? $stopSplitPrice : 500;
+
+        $splitMinPrice = ConfigService::make()->getConfigByCode('split_min_price');
+        $splitMinPrice = $splitMinPrice ? $splitMinPrice : 200;
+
+        $realPrice = ($price - $sellPrice + $sourcePrice);
+        $price = $goods['price']; // 当前价格
+        $addPrice = intval($realPrice * $priceRate / 100, 0);
+        if($price <= $splitMinPrice){
+            $this->error = 2065;
+            return false;
+        }
+
+        // 若特价拆分到停止拆分价格,且交易金额已上涨到最后一次涨价,则停止拆分
+        if ($sellPrice == $stopSplitPrice && ($price + $addPrice >= $splitPrice)) {
+            $this->error = 2065;
             return false;
         }
 
         $datas = [];
         $sumPrice = 0;
-        for($i=1; $i<= $splitNum; $i++){
-            if($i < $splitNum){
-                $price = round($goods['price']/$splitNum, 0);
+        for ($i = 1; $i <= $splitNum; $i++) {
+            if ($i < $splitNum) {
+                $price = round($goods['price'] / $splitNum, 0);
                 $sumPrice += $price;
-            }else{
+            } else {
                 $price = round($goods['price'] - $sumPrice, 0);
             }
 
             $datas[] = [
-                'user_id'=> $goods['user_id'],
-                'shop_id'=> $goods['shop_id'],
-                'goods_name'=> $goods['goods_name'],
-                'code'=> $goods['code'].'-'.$i,
-                'source_price'=> round($goods['source_price']/$splitNum, 0),
-                'sell_price'=> round($goods['sell_price']/$splitNum, 0),
-                'price'=> $price,
-                'fee'=> 0,
-                'thumb'=> $goods['thumb'],
-                'albums'=> $goods['albums'],
-                'content'=> $goods['content'],
-                'split_num'=> $goods['split_num'],
-                'split_price'=> $goods['split_price'],
-                'last_sell_time'=> time(),
-                'create_time'=> time(),
-                'update_time'=> time(),
-                'mark'=>1,
-                'status'=>1,
+                'user_id' => $goods['user_id'],
+                'shop_id' => $goods['shop_id'],
+                'goods_name' => $goods['goods_name'],
+                'code' => $goods['code'] . '-' . $i,
+                'source_price' => round($goods['source_price'] / $splitNum, 0),
+                'sell_price' => round($goods['sell_price'] / $splitNum, 0),
+                'price' => $price,
+                'fee' => 0,
+                'thumb' => $goods['thumb'],
+                'albums' => $goods['albums'],
+                'content' => $goods['content'],
+                'split_num' => $goods['split_num'],
+                'split_price' => $goods['split_price'],
+                'last_sell_time' => time(),
+                'create_time' => time(),
+                'update_time' => time(),
+                'mark' => 1,
+                'status' => 1,
             ];
         }
 
         DB::beginTransaction();
-        if($datas){
-            if(!$this->model->insert($datas)){
+        if ($datas) {
+            if (!$this->model->insert($datas)) {
+                $this->error = 2070;
                 DB::rollBack();
                 return false;
             }
 
-            if(!$this->model->where(['id'=> $goods['id'],'mark'=>1])->update(['status'=>2,'mark'=>0,'remark'=>'已被拆分','update_time'=>time()])){
+            if (!$this->model->where(['id' => $goods['id'], 'mark' => 1])->update(['status' => 2, 'mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
                 DB::rollBack();
+                $this->error = 2070;
                 return false;
             }
 
-            if($info && !TradeModel::where(['id'=> $info['id'],'mark'=>1])->update(['status'=>-1,'is_split'=>1,'mark'=>0,'remark'=>'已被拆分','update_time'=>time()])){
+            if ($tradeInfo && !TradeModel::where(['id' => $tradeInfo['id'], 'mark' => 1])->update(['is_split' => 1, 'mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
                 DB::rollBack();
+                $this->error = 2070;
                 return false;
             }
         }
 
+        $this->error = 2069;
         DB::commit();
         return true;
     }
@@ -321,20 +440,20 @@ class GoodsService extends BaseService
     public function change($goodsId)
     {
         $params = request()->all();
-        $shopId = isset($params['shop_id'])? $params['shop_id']:0;
-        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
-        if(empty($goods)){
+        $changeShopId = isset($params['change_shop_id']) ? $params['change_shop_id'] : 0;
+        $goods = $this->model->where(['id' => $goodsId, 'mark' => 1])->first();
+        if (empty($goods)) {
             $this->error = 2061;
             return false;
         }
 
-        $shopInfo = ShopModel::where(['id'=> $shopId,'mark'=>1])->first();
-        if(empty($shopInfo)){
+        $shopInfo = ShopModel::where(['id' => $changeShopId, 'mark' => 1])->first();
+        if (empty($shopInfo)) {
             $this->error = 2062;
             return false;
         }
 
-        if($this->model->where(['id'=> $goodsId])->update(['shop_id'=> $shopId,'update_time'=> time(),'remark'=> '店长转场'])){
+        if ($this->model->where(['id' => $goodsId])->update(['shop_id' => $changeShopId, 'update_time' => time(), 'remark' => '店长转场'])) {
             $this->error = 1002;
             return true;
         }
@@ -348,25 +467,25 @@ class GoodsService extends BaseService
      */
     public function switchUser($params)
     {
-        $userId = isset($params['user_id'])? $params['user_id']:0;
-        $ids = isset($params['ids'])? $params['ids']:[];
-        if(empty($ids)){
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        $ids = isset($params['ids']) ? $params['ids'] : [];
+        if (empty($ids)) {
             $this->error = 2063;
             return false;
         }
-        $goodsList = $this->whereIn('id',$ids)->where(['mark'=>1])->first();
-        if(empty($goodsList)){
+        $goodsList = $this->model->whereIn('id', $ids)->where(['mark' => 1])->first();
+        if (empty($goodsList)) {
             $this->error = 2061;
             return false;
         }
 
-        $memberInfo = MemberModel::where(['id'=> $userId,'mark'=>1])->first();
-        if(empty($memberInfo)){
+        $memberInfo = MemberModel::where(['id' => $userId, 'mark' => 1])->first();
+        if (empty($memberInfo)) {
             $this->error = 2062;
             return false;
         }
 
-        if($this->model->whereIn('id', $ids)->update(['user_id'=> $userId,'update_time'=> time(),'remark'=> '商品转会员'])){
+        if ($this->model->whereIn('id', $ids)->update(['user_id' => $userId, 'update_time' => time(), 'remark' => '商品转会员'])) {
             $this->error = 1002;
             return true;
         }
@@ -381,14 +500,16 @@ class GoodsService extends BaseService
     public function lock($goodsId)
     {
         $params = request()->all();
-        $status = isset($params['status'])? $params['status'] : 2;
-        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
-        if(empty($goods)){
+        $status = isset($params['status']) ? $params['status'] : 2;
+        $goods = $this->model->where(['id' => $goodsId, 'mark' => 1])->first();
+        if (empty($goods)) {
             $this->error = 2061;
             return false;
         }
 
-        if($this->model->where(['id'=> $goodsId])->update(['status'=> $status,'update_time'=> time(),'remark'=> '店长封存'])){
+
+
+        if ($this->model->where(['id' => $goodsId])->update(['status' => $status, 'update_time' => time(), 'remark' => '店长封存'])) {
             $this->error = 1002;
             return true;
         }
@@ -401,22 +522,26 @@ class GoodsService extends BaseService
      * @param $goodsId
      * @return bool
      */
-    public function updateData($goodsId)
+    public function modify($goodsId)
     {
         $params = request()->all();
-        $goods = $this->where(['id'=> $goodsId,'mark'=>1])->first();
-        if(empty($goods)){
+        $goods = $this->model->where(['id' => $goodsId, 'mark' => 1])->first();
+        if (empty($goods)) {
             $this->error = 2061;
             return false;
         }
 
         $data = [
-            'thumb'=> isset($params['thumb'])? $params['thumb']: '',
-            'goods_name'=> isset($params['goods_name'])? $params['goods_name']: '',
-            'update_time'=>time(),
+            'goods_name' => isset($params['goods_name']) ? $params['goods_name'] : '',
+            'update_time' => time(),
         ];
 
-        if($this->model->where(['id'=> $goodsId])->update($data)){
+        $thumb = isset($params['thumb_path']) ? $params['thumb_path'] : '';
+        if ($thumb) {
+            $data['thumb'] = $thumb;
+        }
+
+        if ($this->model->where(['id' => $goodsId])->update($data)) {
             $this->error = 1008;
             return true;
         }

+ 26 - 7
app/Services/Common/TradeService.php

@@ -85,7 +85,7 @@ class TradeService extends BaseService
             $where['a.status'] = $status;
         }
 
-        $list = $this->model->from('trade as a')
+        $model = $this->model->from('trade as a')
             ->leftJoin('member as b', 'a.user_id', '=', 'b.id')
             ->leftJoin('member as c', 'c.id', '=', 'a.sell_uid')
             ->leftJoin('goods as g', 'g.id', '=', 'a.goods_id')
@@ -118,8 +118,10 @@ class TradeService extends BaseService
             })
             ->select(['a.*', 'b.nickname', 'b.mobile as buy_mobile','s.name as shop_name','s.code as shop_code', 'c.nickname as sell_nickname', 'c.mobile as sell_mobile', 'g.goods_name', 'g.code', 'g.thumb'])
             ->orderBy('a.create_time', 'desc')
-            ->orderBy('a.id', 'desc')
-            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+            ->orderBy('a.id', 'desc');
+
+
+        $list = $model->paginate($pageSize > 0 ? $pageSize : 9999999);
         $list = $list ? $list->toArray() : [];
         if ($list) {
             foreach ($list['data'] as &$item) {
@@ -134,13 +136,20 @@ class TradeService extends BaseService
             }
         }
 
+        $counts = ['total' => 0, 'service_fee' => 0, 'bonus' => 0, 'fee' => 0];
+        $total = $model->sum('a.real_price');
+        $counts['total'] = intval($total);
+        $bonus = $model->sum('a.bonus');
+        $counts['bonus'] = intval($bonus);
+        $serviceFee = $model->sum('a.service_fee');
+        $counts['service_fee'] = intval($serviceFee);
+        $fee = $model->sum('a.fee');
+        $counts['fee'] = intval($fee);
 
         return [
             'pageSize' => $pageSize,
             'total' => isset($list['total']) ? $list['total'] : 0,
-            'counts' => [
-                ''
-            ],
+            'counts' => $counts,
             'list' => isset($list['data']) ? $list['data'] : []
         ];
     }
@@ -611,6 +620,12 @@ class TradeService extends BaseService
             $bonus = $info['real_price'] * $bonusRate / 100;
 
             if ($bonus > 0) {
+                if ($this->model->where(['id' => $id, 'mark' => 1])->update(['bonus' => $bonus, 'update_time' => time()])) {
+                    $this->error = 2051;
+                    DB::rollBack();
+                    return true;
+                }
+
                 if (!MemberModel::where(['id' => $parentId, 'mark' => 1])->update(['bonus' => $parentInfo['bonus'] + $bonus, 'update_time' => time()])) {
                     $this->error = 2051;
                     DB::rollBack();
@@ -725,7 +740,11 @@ class TradeService extends BaseService
 
         // 满足涨价上架
         if($price1+$addPrice < $info['split_price']){
-            if (!$this->model->where(['id' => $id])->update(['status' => 4,'new_price'=> $price1+$addPrice,'real_price'=> $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
+            // 平台服务费
+            $serviceRate = ConfigService::make()->getConfigByCode('service_fee_rate');
+            $serviceRate = $serviceRate ? $serviceRate : 8;
+            $serviceFee = round(($realPrice + $addPrice)*$serviceRate, 0);
+            if (!$this->model->where(['id' => $id])->update(['status' => 4,'service_fee'=> $serviceFee,'new_price'=> $price1+$addPrice,'real_price'=> $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
                 $this->error = 2056;
                 DB::rollBack();
                 return false;