Просмотр исходного кода

wesmiler 报恩寺项目提交

wesmiler 4 лет назад
Родитель
Сommit
65d17349aa

+ 10 - 59
app/Http/Controllers/Api/v1/DonatesController.php

@@ -3,16 +3,13 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\BaseController;
-use App\Http\Validator\ArticleValidator;
-use App\Services\ArticleBooksService;
-use App\Services\ArticleCatesService;
-use App\Services\ArticleService;
-use App\Services\ConfigService;
+use App\Http\Validator\DonateValidator;
 use App\Services\DonateService;
+use App\Services\MecryService;
 use Illuminate\Http\Request;
 
 /**
- * 善控制器类
+ * 捐赠/慈善控制器类
  * @author wesmiler
  * @since 2020/11/10
  * Class DonatesController
@@ -31,7 +28,7 @@ class DonatesController extends BaseController
         parent::__construct();
 
         $this->service = new DonateService();
-        $this->recordService = new Me();
+        $this->mecryService = new MecryService();
     }
 
     /**
@@ -40,68 +37,22 @@ class DonatesController extends BaseController
      */
     public function index(){
         $params = request()->all();
+        $params['user_id']=> $this->userId;
         return $this->service->getDataList($params);
     }
 
     /**
-     * 详情
-     * @return array|mixed
-     */
-    public function info(){
-        $id = request()->get('id',0);
-        if($id<=0){
-            return message(1006, false);
-        }
-
-        $this->service->updateVisit($this->userId);
-        $info = $this->service->getDetail($id, $this->userId);
-        return message(1005, true, $info);
-    }
-
-    /**
-     * 报名
+     * 发布
      * @param Request $request
-     * @param ArticleValidator $validate
+     * @param DonateValidator $validate
      * @return array
      */
-    public function books(Request $request, ArticleValidator $validator){
-        $params = $validator->check($request->all(),'books');
+    public function send(Request $request, DonateValidator $validator){
+        $params = $validator->check($request->all(),'send');
         if(!is_array($params)){
             return message($params, false);
         }
         $params['user_id'] = $this->userId;
-        return $this->bookService->books($params);
-    }
-
-    /**
-     * 获取文章分类
-     * @return mixed
-     */
-    public function cates(){
-        return $this->cateService->getOptions();
-    }
-
-    /**
-     * 单页文章内容
-     * @return array
-     */
-    public function page(){
-        $code = request()->get('code', '');
-        if(empty($code)){
-            return message('参数错误', false);
-        }
-
-        $pageId = ConfigService::make()->getConfigByCode($code);
-        if($pageId<=0){
-            return message(1006, false);
-        }
-
-        $info = ArticleService::make()->getDetail($pageId);
-        if($info){
-            return message(1005, true, $info);
-        }else{
-            return message(1006, false);
-        }
-
+        return $this->service->send($params);
     }
 }

+ 49 - 0
app/Http/Validator/DonateValidator.php

@@ -0,0 +1,49 @@
+<?php
+namespace App\Http\Validator;
+class DonateValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'title' => 'required|string|min:1|max:20',
+        'stock' => 'required|string|min:1|max:10',
+        'thumb' => 'required|string|min:2|max:250',
+        'description' => 'required|string|min:2|max:500',
+    ];
+
+    // 当前模型所有错误提示信息
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'stock' => '数量',
+        'thumb' => '图片',
+        'title' => '物品名称',
+        'description' => '物品描述',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'send'=> ['title','stock','description','thumb'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 3 - 0
app/Services/DevicesService.php

@@ -180,6 +180,7 @@ class DevicesService extends BaseService
             'LEDID'=> $deviceLampNo, // 亮灯灯号1-498对应1号设备,498后为设备2
             'Color'=> $colors[0], // 颜色
             'OrderNo'=> $orderSn, // 订单号
+            'text'=> isset($info['qf_content'])? $info['qf_content'] : '',
         ];
         $dataStr = [];
         foreach($data as $k => $v){
@@ -187,6 +188,7 @@ class DevicesService extends BaseService
         }
 
         // 屏幕控制队列数据
+        /*
         $params = [
             'order_sn'=> $orderSn,
             'device_code'=> $deviceCode,
@@ -195,6 +197,7 @@ class DevicesService extends BaseService
         ];
 
         CatchLedScreen::dispatch($params)->delay(rand(2, 5));
+        */
 
         // 调用亮灯接口处理
         $dataStr = implode('&', $dataStr);

+ 80 - 0
app/Services/DonateService.php

@@ -93,6 +93,62 @@ class DonateService extends BaseService
     }
 
     /**
+     * 获取列表
+     * @return array
+     * @since 2020/11/11
+     * @author wesmiler
+     */
+    public function getDataList($params)
+    {
+        $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
+        $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
+
+        $dataList = $this->model::from('donates as a')
+            ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
+            ->where(function ($query) use ($params) {
+                $query->where(['a.mark'=>1,'a.status'=> 1]);
+
+                $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+                if ($userId > 0) {
+                    $query->where('a.user_id', $userId);
+                }
+
+                $status = isset($params['status']) ? $params['status'] : 0;
+                if ($status > 0) {
+                    $query->where('a.status', $status);
+                }
+
+            })
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
+                if (!empty($keyword)) {
+                    $query->where('a.title','like',"%{$keyword}%")
+                        ->orWhere('m.nickname','like',"%{$keyword}%");
+                }
+            })
+            ->select(['a.id', 'a.user_id', 'm.nickname','a.stock','a.thumb', 'a.title', 'a.status', 'a.create_time', 'a.update_time','a.description'])
+            ->orderBy('a.create_time', 'desc')
+            ->paginate($pageSize);
+
+        $dataList = $dataList ? $dataList->toArray() : [];
+        if ($dataList) {
+            foreach ($dataList['data'] as &$item) {
+                $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
+                $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
+            }
+            unset($item);
+        }
+
+        return [
+            'code' => 0,
+            'success'=> true,
+            'msg' => '操作成功',
+            'count' => isset($dataList['total']) ? $dataList['total'] : 0,
+            'data' => isset($dataList['data']) ? $dataList['data'] : 0,
+        ];
+    }
+
+    /**
      * 添加或编辑
      * @return array
      * @since 2020/11/11
@@ -105,4 +161,28 @@ class DonateService extends BaseService
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 
+    /**
+     * 发布
+     * @param $params
+     * @return array
+     */
+    public function send($params){
+        $data = [
+            'id'=> isset($params['id'])? $params['id'] : 0,
+            'user_id'=> isset($params['user_id'])? $params['user_id'] : 0,
+            'title'=> isset($params['title'])? $params['title'] : '',
+            'stock'=> isset($params['stock'])? intval($params['stock']) : 0,
+            'thumb'=> isset($params['thumb'])? $params['thumb'] : '',
+            'description'=> isset($params['description'])? $params['description'] : '',
+            'create_time'=> time(),
+            'mark'=> 1,
+            'status'=> 1,
+        ];
+
+        if($data['thumb']){
+            $data['thumb'] = is_array($data['thumb'])? '' : str_replace(IMG_URL, "", $data['thumb']);
+        }
+        $data['update_time'] = time();
+        return parent::edit($data); // TODO: Change the autogenerated stub
+    }
 }

+ 4 - 0
routes/api.php

@@ -198,6 +198,10 @@ Route::post('/signs/list', [\App\Http\Controllers\Api\v1\SignController::class,
 Route::post('/signs/options', [\App\Http\Controllers\Api\v1\SignController::class, 'options']);
 Route::post('/signs/submit', [\App\Http\Controllers\Api\v1\SignController::class, 'submit']);
 
+// 捐赠行善
+Route::post('/donates/list', [\App\Http\Controllers\Api\v1\DonatesController::class, 'index']);
+Route::post('/donates/send', [\App\Http\Controllers\Api\v1\DonatesController::class, 'send']);
+