Browse Source

api代码格式化

Cherry 2 years ago
parent
commit
33ac1080e5
2 changed files with 128 additions and 98 deletions
  1. 99 87
      application/api/controller/Pond.php
  2. 29 11
      public/api.html

+ 99 - 87
application/api/controller/Pond.php

@@ -17,10 +17,11 @@ class Pond extends Api
     protected $noNeedLogin = [];
     protected $noNeedRight = ['*'];
 
-    public function order_list(){
+    public function order_list()
+    {
         $order_model = new Order();
-        $order_item_model= new Orderitem();
-        $status=input('status',0);
+        $order_item_model = new Orderitem();
+        $status = input('status', 0);
         $stand_time = input('stand_time');
         $end_time = input('end_time');
         $phone = input('phone');
@@ -28,9 +29,9 @@ class Pond extends Api
         $type = input('type');
         $moshi = input('moshi');
         //订单状态:1=待支付,2=待核销,3=进行中,4=待评价,5=已完成,6=退款中,7=已退款,8=已取消
-        switch ($status){
+        switch ($status) {
             case 0:
-                $array = [0,1,2,3,4,5,6,7,8];
+                $array = [0, 1, 2, 3, 4, 5, 6, 7, 8];
                 break;
             case 1:
                 $array = [1];
@@ -45,40 +46,41 @@ class Pond extends Api
                 $array = [4];
                 break;
             case 5:
-                $array = [6,7];
+                $array = [6, 7];
                 break;
             case 6:
                 $array = [8];
                 break;
         }
         $where = [];
-        if($stand_time&&$end_time) {
+        if ($stand_time && $end_time) {
             $where['create_time'] = ['between', [strtotime($stand_time), strtotime($end_time)]];
         }
-        if($yutang_id){
+        if ($yutang_id) {
             $where['yutang_id'] = ['=', $yutang_id];
         }
-        if($type){
+        if ($type) {
             $where['type'] = ['=', $type];
         }
-        if($moshi){
+        if ($moshi) {
             $where['moshi'] = ['=', $moshi];
         }
-        if($phone){
+        if ($phone) {
             $where['phone'] = ['=', $phone];
         }
-        $list= $order_model->where('t_user_id',$this->auth->id)->whereIn('status',$array)->where($where)->order('id','desc')->paginate();
-        foreach ($list as &$v){
-            $v['item']=$order_item_model->where('order_id',$v['id'])->select();
-            if($v['status']==3){
-                $time=strtotime($v['end'])-strtotime(date( "H:i"));
-                if($time<=1800) {
+        $list = $order_model->where('t_user_id', $this->auth->id)->whereIn('status', $array)->where($where)->order('id', 'desc')->paginate();
+        foreach ($list as &$v) {
+            $v['item'] = $order_item_model->where('order_id', $v['id'])->select();
+            if ($v['status'] == 3) {
+                $time = strtotime($v['end']) - strtotime(date("H:i"));
+                if ($time <= 1800) {
                     $v['time'] = $time;
                 }
             }
         }
-        $this->success('我的订单列表',$list);
+        $this->success('我的订单列表', $list);
     }
+
     public function order_detail()
     {
         $order_id = input('order_id');
@@ -95,11 +97,13 @@ class Pond extends Api
         }
         $order_info['item'] = $order_item->where('order_id', $order_id)->select();
         $order_info['code'] = $order_code->where('order_id', $order_id)->select();
-        $order_info['pingjia'] = $pingjia_model->where('user_id',$order_info['user_id'])->where('yutang_id',$order_info['yutang_id'])->find();
+        $order_info['pingjia'] = $pingjia_model->where('user_id', $order_info['user_id'])->where('yutang_id', $order_info['yutang_id'])->find();
         $this->success('订单详情', $order_info);
 
     }
-    public function method_log(){
+
+    public function method_log()
+    {
         $user_id = $this->auth->id;
         $user = (new \app\admin\model\User())->where('id', $user_id)->find();
         if ($user->pid != 0) {
@@ -109,112 +113,118 @@ class Pond extends Api
             $user_ids = array_merge([$user_id], array_column($users, 'id'));
         }
 
-        $query = (new OrderCodeWriteOffLog())->with(['order' => function($query){ $query->with('method'); }])->whereIn('user_id', $user_ids)->order('id', 'desc');
+        $query = (new OrderCodeWriteOffLog())->with(['order' => function ($query) {
+            $query->with('method');
+        }])->whereIn('user_id', $user_ids)->order('id', 'desc');
         // 1是今日2是全部
-        if(input('type', 1)) {
+        if (input('type', 1)) {
             $query->whereBetween('write_off_time', [date('Y-m-d OO:00:00'), date('Y-m-d 23:59:59')]);
         }
 
-        $list = array_map(function($item){
-                return $item->order->method;
+        $list = array_map(function ($item) {
+            return $item->order->method;
         }, $query->limit(30)->group('order_id')->select());
 
-        $this->success('我的发布',$list);
+        $this->success('我的发布', $list);
     }
-    public function write_log(){
-        $method_id  = input('method_id');
-        $type = input('type','1');
-        if($type==1){
-            $where['ruchang_status']=['=',2];
+
+    public function write_log()
+    {
+        $method_id = input('method_id');
+        $type = input('type', '1');
+        if ($type == 1) {
+            $where['ruchang_status'] = ['=', 2];
         }
-        if($type==2){
-            $where['wucan_status']=['=',2];
+        if ($type == 2) {
+            $where['wucan_status'] = ['=', 2];
         }
-        if($type==3){
-            $where['yajin_status']=['=',2];
+        if ($type == 3) {
+            $where['yajin_status'] = ['=', 2];
         }
         $method_model = new Method();
         $item_model = new Time();
         $order_code_model = new Ordercode();
-        $method_info = $method_model->where('id',$method_id)->find();
-        $time_list = $item_model->where('m_id',$method_id)->select();
-        foreach ($time_list as &$v){
+        $method_info = $method_model->where('id', $method_id)->find();
+        $time_list = $item_model->where('m_id', $method_id)->select();
+        foreach ($time_list as &$v) {
             $v['show_image'] = $method_info['show_images'];
             $v['yutang_name'] = $method_info['yutang_name'];
-            $v['moshi']    = $method_info['moshi'];
+            $v['moshi'] = $method_info['moshi'];
             $v['m_type'] = $method_info['type'];
             $v['date'] = date('Y-m-d');
-            $v['count'] = $order_code_model->where('time_id',$v['id'])->where($where)->count();
+            $v['count'] = $order_code_model->where('time_id', $v['id'])->where($where)->count();
         }
-        $this->success('核销时间段',$time_list);
+        $this->success('核销时间段', $time_list);
 
     }
-    public function write_list(){
+
+    public function write_list()
+    {
         $method_model = new Method();
         $item_model = new Time();
         $order_code_model = new Ordercode();
         $time_id = input('time_id');
-        $type = input('type','1');
-        if($type==1){
-            $where['ruchang_status']=['=',2];
+        $type = input('type', '1');
+        if ($type == 1) {
+            $where['ruchang_status'] = ['=', 2];
         }
-        if($type==2){
-            $where['wucan_status']=['=',2];
+        if ($type == 2) {
+            $where['wucan_status'] = ['=', 2];
         }
-        if($type==3){
-            $where['yajin_status']=['=',2];
+        if ($type == 3) {
+            $where['yajin_status'] = ['=', 2];
         }
-        $time_info =  $item_model->where('id',$time_id)->find();
-        $time_info['desc'] = $method_model->alias('m')->join('yutang y','y.id=m.yutang_id')->where('m.id',$time_info['m_id'])->field('m.yutang_name,m.type,m.moshi,y.image')->find();
-        $time_info['code'] = $order_code_model->where('time_id',$time_id)->where($where)->order('ruchang_time desc')->paginate();
-        $this->success('已核销信息',$time_info);
+        $time_info = $item_model->where('id', $time_id)->find();
+        $time_info['desc'] = $method_model->alias('m')->join('yutang y', 'y.id=m.yutang_id')->where('m.id', $time_info['m_id'])->field('m.yutang_name,m.type,m.moshi,y.image')->find();
+        $time_info['code'] = $order_code_model->where('time_id', $time_id)->where($where)->order('ruchang_time desc')->paginate();
+        $this->success('已核销信息', $time_info);
     }
 
     /**
      * 塘主-午餐通知
      * @ApiMethod (GET)
      * @ApiParams (name=method_id,type="int", required=true,description="玩法id")
-     * @ApiReturnParams (name="lunch_num", type="int", required=true, description="午餐订购数量")
-     * @ApiReturn ({"code":1,"msg":"ok","time":"1680761053","data":{"total":1,"per_page":15,"current_page":1,"last_page":1,"data":[{"id":710,"order_no":"40012420230406102824","create_time":1680748104,"user_id":"124","phone":"18206485031","number":1,"username":"u124","create_time_text":"2023-04-06 10:28:24","status_text":"","pay_time_text":"","reson_time_text":""}]}})
+     * @ApiReturn ({"code":1,"msg":"ok","time":"1680761053"})
      */
-    public function lunch_tongzhi(){
-        $method_id = input('method_id',0);
-        if($method_id==0){
+    public function lunch_tongzhi()
+    {
+        $method_id = input('method_id', 0);
+        if ($method_id == 0) {
             $this->error('参数错误');
         }
 
         $order_model = new Order();
-        $mobiles  = $order_model->where('t_user_id',$this->auth->id)
+        $mobiles = $order_model->where('t_user_id', $this->auth->id)
 //            ->where('wucan_money','>',0)
             ->where('method_id', $method_id)
             ->where('eat', 2)
-            ->whereIn('status','2,3')
+            ->whereIn('status', '2,3')
             ->field('id,phone,user_id,yutang,image,auto_expire,huodong_time')->select();
-        if(empty($mobiles)){
+        if (empty($mobiles)) {
             $this->error('没有就餐人员');
         }
 
-        $user = (new \app\admin\model\User())->where('id', $this->auth->id)->find() ;
-        if($user->zhannei == 1){
+        $user = (new \app\admin\model\User())->where('id', $this->auth->id)->find();
+        if ($user->zhannei == 1) {
             $message_model = new \app\admin\model\Message();
-            foreach($mobiles as $val){
+            foreach ($mobiles as $val) {
                 $to_time = time();
                 if ($to_time < $val['auto_expire'] && date('Ymd', $val['huodong_time']) == date('Ymd')) {
                     $message_data = [
-                        'category_id'=>3,
-                        'user_id'=>$val->user_id,
-                        'title'=>'午餐通知',
-                        'name'=>$val->yutang,
+                        'category_id' => 3,
+                        'user_id' => $val->user_id,
+                        'title' => '午餐通知',
+                        'name' => $val->yutang,
                         'image' => $val->image,
-                        'description'=>$val->yutang.'通知您午餐开始了',
-                        'is_read'=>0,
-                        'createtime'=>time(),
+                        'description' => $val->yutang . '通知您午餐开始了',
+                        'is_read' => 0,
+                        'createtime' => time(),
                     ];
                     $message_model->insert($message_data);
                 }
             }
         }
-        if($user->duanxin == 1){
+        if ($user->duanxin == 1) {
 
             $order_ids = [];
             foreach ($mobiles as $val) {
@@ -225,14 +235,14 @@ class Pond extends Api
             }
 
             $orderCodes = (new Ordercode())->whereIn('order_id', $order_ids)->field('phone')->select();
-            if(count($orderCodes) > $user->sms_number){
+            if (count($orderCodes) > $user->sms_number) {
                 $this->error('短信数量不足');
             }
             if (count($orderCodes) > 0) {
-                $user->sms_number -=count($orderCodes);
+                $user->sms_number -= count($orderCodes);
                 $user->save();
-                $sms= new Sms();
-                $sms->wucna_tongzhi($orderCodes,$this->auth->id);
+                $sms = new Sms();
+                $sms->wucna_tongzhi($orderCodes, $this->auth->id);
             }
         }
 
@@ -249,22 +259,23 @@ class Pond extends Api
      * @ApiReturnParams (name="lunch_num", type="int", required=true, description="午餐订购数量")
      * @ApiReturn ({"code":1,"msg":"ok","time":"1680759306","data":{"total":2,"per_page":15,"current_page":1,"last_page":1,"data":[{"id":444,"type":1,"show_images":"http://yutang.zhousi.hdlkeji.com/uploads/20230327/83e103697d24ea91145083aa813f1f6c.png","yutang_name":"啦啦啦1","moshi":1,"lunch_num":0,"type_text":"Type 1","put_time_text":"","tuisong_text":""}]}})
      */
-    public function lunch_list(){
+    public function lunch_list()
+    {
         $page = input('page', 1);
         $limit = input('limit');
-        $status = input('status',0);
+        $status = input('status', 0);
 
         $method_model = new Method();
         $query = $method_model->field('id,type,show_images,yutang_name,moshi');
-        switch ($status){
+        switch ($status) {
             case 0:
-                $query = $query->where('huodong_time',date('Y-m-d',time()));
+                $query = $query->where('huodong_time', date('Y-m-d', time()));
                 break;
             case 1:
-                $query = $query->where('huodong_time','>',date('Y-m-d',time()));
+                $query = $query->where('huodong_time', '>', date('Y-m-d', time()));
                 break;
             case 2:
-                $query = $query->where('huodong_time','<',date('Y-m-d',time()));
+                $query = $query->where('huodong_time', '<', date('Y-m-d', time()));
                 break;
         }
 
@@ -274,11 +285,11 @@ class Pond extends Api
             ->paginate($limit, false, ['page' => $page]);
 
         $order_model = new Order();
-        foreach ($list as &$v){
-            $v['lunch_num'] = $order_model->where('method_id',$v['id'])->where('eat',2)->sum('number');
+        foreach ($list as &$v) {
+            $v['lunch_num'] = $order_model->where('method_id', $v['id'])->where('eat', 2)->sum('number');
         }
 
-        $this->success('ok',$list);
+        $this->success('ok', $list);
     }
 
     /**
@@ -290,10 +301,11 @@ class Pond extends Api
      * @ApiReturnParams (name="lunch_num", type="int", required=true, description="午餐订购数量")
      * @ApiReturn ({"code":1,"msg":"ok","time":"1680761053","data":{"total":1,"per_page":15,"current_page":1,"last_page":1,"data":[{"id":710,"order_no":"40012420230406102824","create_time":1680748104,"user_id":"124","phone":"18206485031","number":1,"username":"u124","create_time_text":"2023-04-06 10:28:24","status_text":"","pay_time_text":"","reson_time_text":""}]}})
      */
-    public function lunch_order(){
+    public function lunch_order()
+    {
         $page = input('page', 1);
         $limit = input('limit');
-        $method_id = input('method_id',0);
+        $method_id = input('method_id', 0);
 
         $order_model = new Order();
         $list = $order_model->with(['userN'])->field('id,order_no,create_time,user_id,phone,number')
@@ -303,7 +315,7 @@ class Pond extends Api
             ->order('id', 'DESC')
             ->paginate($limit, false, ['page' => $page]);
 
-        $this->success('ok',$list);
+        $this->success('ok', $list);
     }
 
 

+ 29 - 11
public/api.html

@@ -811,11 +811,11 @@
                                                                     <span class="label label-success pull-right noneedlogin">登</span>
                                                             </span>
                         </a>
-                                                <a href="javascript:;" data-id="49" class="list-group-item">wucna_tongzhi                            <span class="tag">
+                                                <a href="javascript:;" data-id="49" class="list-group-item">塘主-午餐通知                            <span class="tag">
                                                                     <span class="label label-success pull-right noneedlogin">登</span>
                                                             </span>
                         </a>
-                                                <a href="javascript:;" data-id="50" class="list-group-item">塘主-午餐订单                            <span class="tag">
+                                                <a href="javascript:;" data-id="50" class="list-group-item">塘主-午餐列表                            <span class="tag">
                                                                     <span class="label label-success pull-right noneedlogin">登</span>
                                                             </span>
                         </a>
@@ -23296,7 +23296,7 @@
                     <div class="panel-heading" id="heading-49">
                         <h4 class="panel-title">
                             <span class="label label-success">GET</span>
-                            <a data-toggle="collapse" data-parent="#accordion49" href="#collapseOne49"> wucna_tongzhi <span class="text-muted">/api/pond/wucna_tongzhi</span></a>
+                            <a data-toggle="collapse" data-parent="#accordion49" href="#collapseOne49"> 塘主-午餐通知 <span class="text-muted">/api/pond/lunch_tongzhi</span></a>
                         </h4>
                     </div>
                     <div id="collapseOne49" class="panel-collapse collapse">
@@ -23314,7 +23314,7 @@
 
                                 <div class="tab-pane active" id="info49">
                                     <div class="well">
-                                        wucna_tongzhi                                    </div>
+                                        塘主-午餐通知                                    </div>
                                     <div class="panel panel-default">
                                         <div class="panel-heading"><strong>权限</strong></div>
                                         <div class="panel-body">
@@ -23341,7 +23341,24 @@
                                     <div class="panel panel-default">
                                         <div class="panel-heading"><strong>参数</strong></div>
                                         <div class="panel-body">
-                                                                                        无
+                                                                                        <table class="table table-hover">
+                                                <thead>
+                                                    <tr>
+                                                        <th>名称</th>
+                                                        <th>类型</th>
+                                                        <th>必选</th>
+                                                        <th>描述</th>
+                                                    </tr>
+                                                </thead>
+                                                <tbody>
+                                                                                                        <tr>
+                                                        <td>method_id</td>
+                                                        <td>int</td>
+                                                        <td>是</td>
+                                                        <td>玩法id</td>
+                                                    </tr>
+                                                                                                    </tbody>
+                                            </table>
                                                                                     </div>
                                     </div>
                                     <div class="panel panel-default">
@@ -23361,9 +23378,10 @@
                                                 </div>
                                                 </div>
                                                 <div class="panel-body">
-                                                    <form enctype="application/x-www-form-urlencoded" role="form" action="/api/pond/wucna_tongzhi" method="get" name="form49" id="form49">
+                                                    <form enctype="application/x-www-form-urlencoded" role="form" action="/api/pond/lunch_tongzhi" method="GET" name="form49" id="form49">
                                                                                                                 <div class="form-group">
-                                                            无
+                                                            <label class="control-label" for="method_id">method_id</label>
+                                                            <input type="int" class="form-control input-sm" id="method_id" required placeholder="玩法id" name="method_id">
                                                         </div>
                                                                                                                 <div class="form-group form-group-submit">
                                                             <button type="submit" class="btn btn-success send" rel="49">提交</button>
@@ -23396,7 +23414,7 @@
                                 <div class="tab-pane" id="sample49">
                                     <div class="row">
                                         <div class="col-md-12">
-                                            <pre id="sample_response49"></pre>
+                                            <pre id="sample_response49">{"code":1,"msg":"ok","time":"1680761053"}</pre>
                                         </div>
                                     </div>
                                 </div><!-- #sample -->
@@ -23409,7 +23427,7 @@
                     <div class="panel-heading" id="heading-50">
                         <h4 class="panel-title">
                             <span class="label label-success">GET</span>
-                            <a data-toggle="collapse" data-parent="#accordion50" href="#collapseOne50"> 塘主-午餐订单 <span class="text-muted">/api/pond/lunch_list</span></a>
+                            <a data-toggle="collapse" data-parent="#accordion50" href="#collapseOne50"> 塘主-午餐列表 <span class="text-muted">/api/pond/lunch_list</span></a>
                         </h4>
                     </div>
                     <div id="collapseOne50" class="panel-collapse collapse">
@@ -23427,7 +23445,7 @@
 
                                 <div class="tab-pane active" id="info50">
                                     <div class="well">
-                                        塘主-午餐订单                                    </div>
+                                        塘主-午餐列表                                    </div>
                                     <div class="panel panel-default">
                                         <div class="panel-heading"><strong>权限</strong></div>
                                         <div class="panel-body">
@@ -28812,7 +28830,7 @@
 
                 </div>
                 <div class="col-md-6" align="right">
-                    Generated on 2023-04-06 14:06:17 <a href="./" target="_blank">渔播报</a>
+                    Generated on 2023-04-06 14:24:37 <a href="./" target="_blank">渔播报</a>
                 </div>
             </div>