Переглянути джерело

Merge branch 'master' of ssh://git.9026.com:2212/swdz-WangHaijun/BaoMa into develop

Mike 4 роки тому
батько
коміт
db8f4f42ae

+ 19 - 1
app/Admin/Actions/Community/Docter/Failed.php

xqd
@@ -17,11 +17,29 @@ class Failed extends RowAction
     public $name = '驳回';
     public function handle()
     {
+        $openid = 'oflME5eixHMij2TIVyy52WbfaQvA';
+
+        $data = [
+              $openid,
+              '很抱歉,你的医生身份认证失败!',
+              $this->row->docter->name,
+              $this->row->organization->name,
+              $this->row->qualification->name,
+              $this->row->office->name,
+        ];
         DB::beginTransaction();
         try {
+
             DocterOrganization::where('id',$this->row->id)->update(['state'=>2]);
             $docter_id = $this->row->docter_id;
-            Docter::where(['id'=>$docter_id])->update(['is_then'=>0]);
+            $ret = send_wechatSubscription_message('then_reminder',$data);
+            dd($ret);
+
+//            Docter::where(['id'=>$docter_id])->update(['is_then'=
+//            ewWm59p1oVpHw7vt3LlkQTWpYgOZ_h6rfINUiTc4GbM
+              $data = [
+
+              ];
             DB::commit();
         } catch (Exception $e){
             DB::rollBack();

+ 61 - 33
app/Admin/Actions/Community/Notice/sendNotice.php

xqd xqd
@@ -13,13 +13,32 @@ class sendNotice extends BatchAction
 
     public function handle(Collection $collection)
     {
-        foreach ($collection as $model) {
-            $openid = User::where('id',$model->id)->value('openid');
+        $info = $collection->toArray();
+        $ids = array_unique(array_column($info,'id'));
+        foreach ($ids as $id) {
+            $openid = User::where('id',$id)->value('openid');
             $content = request('content');
             $remark= request('remark');
-//            $openid = 'oVxTzvgYlGktIDZXwfLMLQ01Tr5s'; 自己
+            $stime= request('stime');
+            $type= request('type',1);
+//            $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
+            $service_arr = [1=>'儿保服务',2=>'疫苗接种服务'];
+            $service_name = $service_arr[$type];
+
+            //没有openid 直接不发送
             if(empty($openid)) continue;
-            $this->send($openid,$content,$remark);
+            $template_arr = [
+                1=>'CP3AxrgS-cbW1da8QlIDFcxd-H0RStMEuXdqNRePLoc',
+                2=>'xpcaMFXI0Kc9U12o3D6CGPa7ASTpOZJwXJm2mlip6Zo'
+            ];
+            $tempId =  $template_arr[$type];
+
+            $msg['content'] = $content;
+            $msg['service_date'] = $stime;
+            $msg['remark'] = $remark;
+            $msg['service_name'] = $service_name;
+
+            $this->send($openid,$tempId,$msg);
         }
 
         return $this->response()->success('发送成功')->refresh();
@@ -27,43 +46,52 @@ class sendNotice extends BatchAction
 
     public function form()
     {
-        $this->text('title','标题')->value('社区通知')->disable();
+
+//        xpcaMFXI0Kc9U12o3D6CGPa7ASTpOZJwXJm2mlip6Zo 接种服务提醒
+//        first,keyword1,keword2,remark;
+//        CP3AxrgS-cbW1da8QlIDFcxd-H0RStMEuXdqNRePLoc 儿保服务提醒
+
+//        服务项目:XX疫苗接种
+//        服务日期:后台设置的服务时间
+
         $this->textarea('content','内容')->rows(4);
+        $this->select('type','服务类型')->options([1=>'儿保',2=>'计免']);
+        $this->date('stime','服务时间');
         $this->textarea('remark','备注')->rows(3);
     }
 
-    public function send($open_id,$cotent, $remark)
+    public function send($open_id,$tempId,$msg)
     {
-        if(empty($open_id)) return true;
-        $config = [
-                'app_id' => 'wx1c2357232cd25f65',
-                'secret' => 'c8cab53e4e52234ed1bc2abbdeaba57d',
-//            'app_id' => 'wx13bedfcc62e9bab0',
-//            'secret' => '175e5518b6426dd12d3096f24ca68fb8',
-                'response_type' => 'array'
-            ];
-        $app = Factory::officialAccount($config);
-        if(!isset($user['openid'])) return true;
-        $res = $app->template_message->send([
+        $template = [
             'touser' => $open_id,
-            'template_id' => 'GWIu1FBBA8SOdOwEbXRAmBL9LlYJP_H6EJUC7rv-YiQ',
-            'url' => 'https://t5.9026.com',
-//            'miniprogram' => [
-//                'appid' => 'wx6131f74e623bf6bf',
-//                'pagepath' => '/pages/index/index',
-//            ],
-            'data' => [
-                'first'=>'社区通知',
-                'cardNumber' => '测试服务服务包',
-                'type' => '门诊',
-                'address' => '华西医院',
-                'VIPPhone' => 18719141830,
-                'VIPName' => '测试服务包',
-                'expDate' => '2021年12月31号',
-                'remark' => '请咨询13912345678。',
+            'mp_template_msg' => [
+                'appid' => env('OFFICIAL_WECHAT_APPID'),
+                'template_id' => $tempId,
+                'url' => '',
+                'miniprogram' => [
+                    'appid' => env('WECHAT_APPID', 'wxd41dd232837996c4'),
+                    'pagepath' => '',
+                ],
+                'data' => [
+                    'first' => [
+                        'value' => $msg['content'],
+                    ],
+                    'keyword1' => [
+                        'value' => $msg['service_name'],
+                    ],
+                    'keyword2' => [
+                        'value' => $msg['service_date'],
+                    ],
+                    'remark' => [
+                        'value' => $msg['remark'],
+                    ],
+                ],
             ],
-        ]);
+        ];
+        $app = Factory::miniProgram(config('config.wechat_small_program'));
+        $app->uniform_message->send($template);
         return true;
+
     }
 
 

+ 1 - 1
app/Admin/Actions/backstage/Refund/RefundPartCompleteAction.php

xqd
@@ -19,7 +19,7 @@ class RefundPartCompleteAction extends RowAction
         $num = request('num');
         $num = $num*100;
         $total =  Order::where('id',$this->row->order_id)->value('payment_amount');
-        if ($num>=$total)
+        if ($num>$total)
         {
             return $this->response()->error('部分退款金额不得大于订单金额')->refresh();
         }

+ 41 - 0
app/Admin/Actions/backstage/Refund/RefundServicePackAction.php

xqd
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Admin\Actions\backstage\Refund;
+
+use App\Models\Order;
+use App\Models\OrderPack;
+use Encore\Admin\Actions\RowAction;
+use Illuminate\Database\Eloquent\Model;
+
+class RefundServicePackAction extends RowAction
+{
+    public $name = '服务包退款';
+
+    public function handle(Model $model)
+    {
+        // $model ...
+        //获取到订单类型
+        $product_type = $this->row->product_type;
+        //获取到支付的服务包订单的id
+        $pay_order_pack_id = $this->row->pay_order_pack_id;
+        //根据订单类型进行退款
+        if ($product_type == 3)
+        {
+            //获取到原来剩余的次数
+            $appoint_num = OrderPack::where('id',$pay_order_pack_id)->value('appoint_num');
+            $new_appoint_num = $appoint_num+1;
+            OrderPack::where('id',$pay_order_pack_id)->update(['appoint_num'=>$new_appoint_num]);
+            Order::where('id',$this->row->id)->update(['payment_status'=>4]);
+        }
+        if ($product_type == 5)
+        {
+            //获取到原来剩余的次数
+            $nurses_limit_amount = OrderPack::where('id',$pay_order_pack_id)->value('nurses_limit_amount');
+            $new_nurses_limit_amount = $nurses_limit_amount+1;
+            OrderPack::where('id',$pay_order_pack_id)->update(['nurses_limit_amount'=>$new_nurses_limit_amount]);
+            Order::where('id',$this->row->id)->update(['payment_status'=>4]);
+        }
+        return $this->response()->success('服务包退款成功')->refresh();
+    }
+
+}

+ 8 - 2
app/Admin/Controllers/DataCenter/FinancialOrderChart.php

xqd xqd xqd xqd xqd
@@ -88,7 +88,9 @@ class FinancialOrderChart
     {
 
         //type 1默认选择当前月份 2根据时间+
-        $month >10??$month = '0'.$month;
+        if(intval($month) < 10){
+            $month  = '0'.$month;
+        }
 
         if($type == 1){
             //查找天
@@ -97,6 +99,7 @@ class FinancialOrderChart
                 ->selectRaw('DATE_FORMAT(created_at,"%m-%d") as day')
                 ->selectRaw('SUM(payment_amount) as sum')
                 ->where('payment_status',2)
+                ->where('is_faster',0)
                 ->where('created_at', '>=', $year.'-'.$month)
                 ->where('created_at', '<', $year.'-'.($month+1))
                 ->groupBy('day')
@@ -115,6 +118,7 @@ class FinancialOrderChart
                 ->selectRaw('DATE_FORMAT(created_at,"%Y") as day')
                 ->selectRaw('SUM(payment_amount) as sum')
                 ->where('payment_status',2)
+                ->where('is_faster',0)
                 ->where('created_at', '>', '2000-')
                 ->where('created_at', '<', '2099-')
                 ->groupBy('day')
@@ -130,7 +134,8 @@ class FinancialOrderChart
                 ->selectRaw('DATE_FORMAT(created_at,"%m-%d") as day')
                 ->selectRaw('SUM(payment_amount) as sum')
                 ->where('payment_status',2)
-                ->where('created_at', '>', $year.'-'.$month)
+                ->where('is_faster',0)
+                ->where('created_at', '>=', $year.'-'.$month)
                 ->where('created_at', '<', $year.'-'.($month+1))
                 ->groupBy('day')
                 ->orderBy('day')
@@ -147,6 +152,7 @@ class FinancialOrderChart
                 ->selectRaw('DATE_FORMAT(created_at,"%m") as day')
                 ->selectRaw('SUM(payment_amount) as sum')
                 ->where('payment_status',2)
+                ->where('is_faster',0)
                 ->where('created_at', '>=', $year.'-')
                 ->where('created_at', '<', ($year+1).'-')
                 ->groupBy('day')

+ 4 - 2
app/Admin/Controllers/DataCenter/FinancialRechargeChart.php

xqd xqd
@@ -87,7 +87,9 @@ class FinancialRechargeChart
     {
 
         //type 1默认选择当前月份 2根据时间+
-        $month >10??$month = '0'.$month;
+        if(intval($month) < 10){
+            $month  = '0'.$month;
+        }
 
         if($type == 1){
             //查找天
@@ -132,7 +134,7 @@ class FinancialRechargeChart
                 ->selectRaw('SUM(payment_amount) as sum')
                 ->where('product_type',7)
                 ->where('payment_status',2)
-                ->where('created_at', '>', $year.'-'.$month)
+                ->where('created_at', '>=', $year.'-'.$month)
                 ->where('created_at', '<', $year.'-'.($month+1))
                 ->groupBy('day')
                 ->orderBy('day')

+ 6 - 2
app/Admin/Controllers/DataCenter/FinancialSta.php

xqd xqd xqd xqd xqd xqd
@@ -16,7 +16,7 @@ class FinancialSta
 {
     //获取平台的收入总金额
     public static function getTotalIncome(){
-        $data = Order::where('payment_status',2)->pluck('payment_amount')->sum();
+        $data = Order::where('payment_status',2)->where('is_faster',0)->pluck('payment_amount')->sum();
         $data /=100;
        return $data;
     }
@@ -33,7 +33,7 @@ class FinancialSta
         return $data;
     }
     public static function getTotalRefund(){
-        $data = Order::where('payment_status',4)->pluck('payment_amount')->sum();
+        $data = Order::where('payment_status',4)->where('is_faster',0)->where('is_faster',0)->pluck('payment_amount')->sum();
         $data /= 100;
         return $data;
     }
@@ -70,6 +70,7 @@ class FinancialSta
     //获取今天的支付金额
     public static function getTodayPay(){
         $data = Order::where('payment_status',2)
+            ->where('is_faster',0)
             ->where('created_at','>=',date('Y-m-d 00:00:00',strtotime('today')))
             ->pluck('payment_amount')->sum();
         $data /= 100;
@@ -78,6 +79,7 @@ class FinancialSta
     //获取昨天的支付金额
     public static function getYesterdayPay(){
         $data = Order::where('payment_status',2)
+            ->where('is_faster',0)
             ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-1 days')),date('Y-m-d 23:59:59',strtotime('-1 days'))])
             ->pluck('payment_amount')->sum();
         $data /= 100;
@@ -86,6 +88,7 @@ class FinancialSta
     //获取近七日的支付金额
     public static function getSevenDayPay(){
         $data = Order::where('payment_status',2)
+            ->where('is_faster',0)
             ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-6 days')),date('Y-m-d H:i:s',time())])
             ->pluck('payment_amount')->sum();
         $data /= 100;
@@ -94,6 +97,7 @@ class FinancialSta
     //获取三十日的支付金额
     public static function getOneMonthPay(){
         $data = Order::where('payment_status',2)
+            ->where('is_faster',0)
             ->whereBetween('created_at',[date('Y-m-d 00:00:00',strtotime('-29 days')),date('Y-m-d H:i:s',time())])
             ->pluck('payment_amount')->sum();
         $data /= 100;

+ 1 - 1
app/Admin/Controllers/HomeController.php

xqd
@@ -58,7 +58,7 @@ class HomeController extends Controller
                     $column->append(\App\Admin\Controllers\infoBox('昨日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,-1)));
                 });
                 $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('七日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,7)));
+                    $column->append(\App\Admin\Controllers\infoBox('七日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,7)));
                 });
                 $row->column(3, function (Column $column) {
                     $column->append(\App\Admin\Controllers\infoBox('近三十日订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(7,30)));

+ 27 - 7
app/Admin/Controllers/OrdersManagement/BookingOrderController.php

xqd xqd xqd xqd
@@ -5,6 +5,7 @@ namespace App\Admin\Controllers\OrdersManagement;
 use App\Admin\Actions\backstage\Orders\Evaluate;
 use App\Admin\Actions\backstage\Orders\RefundApplicationAction;
 use App\Admin\Actions\backstage\Refund\RefundCompleteAction;
+use App\Admin\Actions\backstage\Refund\RefundServicePackAction;
 use App\Models\Order;
 use App\Admin\Actions\backstage\Orders\OrderDetails;
 use App\Models\OrderPack;
@@ -62,7 +63,19 @@ class BookingOrderController extends AdminController
                         2=>'待接单',
                         3=>'进行中',
                         4=>'已完成',
-                        5=>'已取消'
+                        5=>'已取消',
+                        6=>'已超时',
+                        7=>'已预约',
+                    ]
+                );
+                $filter->equal('payment_status','支付状态')->radio(
+                    [
+                        ''=>'不限',
+                        1=>'待付款',
+                        2=>'已付款',
+                        3=>'退款中',
+                        4=>'已退款',
+                        5=>'待退款',
                     ]
                 );
                 $filter->timestampBetween('payment_time', "支付时间")->datetime();
@@ -83,7 +96,14 @@ class BookingOrderController extends AdminController
                     ($actions->row->order_status == 5 && $actions->row->payment_status == 5)||
                     //已超时 已支付
                     ($actions->row->order_status == 6 && $actions->row->payment_status == 2)){
-                    $actions->add(new RefundApplicationAction());
+                        //判断是否是服务包支付 是的话走退次数的逻辑,不是的话走退余额的操作
+                        if ($actions->row->payment_type == 3)
+                        {
+                            $actions->add(new RefundServicePackAction());
+                        }else
+                        {
+                            $actions->add(new RefundApplicationAction());
+                        }
                 }
             }
             //有问题 未支付是订单状态,这里冲突了
@@ -136,13 +156,13 @@ class BookingOrderController extends AdminController
                 return '余额支付';
             }
             if ($payment_type == 3){
-                $order_pack_id = OrderPack::where('id',$this->pay_order_pack_id)->pluck('service_pack_id');
-                $name = ServicePack::where('id',$order_pack_id[0])->pluck('name');
-                return '服务包支付('.$name[0].')';
+                $order_pack_id = OrderPack::where('id',$this->pay_order_pack_id)->value('service_pack_id');
+                $name = ServicePack::where('id',$order_pack_id)->value('name');
+                return '服务包支付('.$name.')';
             }
         });
-        $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消']);
-        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款']);
+        $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消',6=>'已超时',7=>'已预约']);
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款']);
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){
             return $money/100;
         });

+ 13 - 3
app/Admin/Controllers/OrdersManagement/ConsultingOrdersController.php

xqd xqd
@@ -69,6 +69,16 @@ class ConsultingOrdersController extends AdminController
                         6=>'已超时'
                     ]
                 );
+                $filter->equal('payment_status','支付状态')->radio(
+                    [
+                        ''=>'不限',
+                        1=>'待付款',
+                        2=>'已付款',
+                        3=>'退款中',
+                        4=>'已退款',
+                        5=>'待退款',
+                    ]
+                );
                 $filter->timestampBetween('payment_time', "支付时间")->datetime();
                 $filter->timestampBetween('receiving_time', "接单时间")->datetime();
                 $filter->timestampBetween('end_time', "订单完成时间")->datetime();
@@ -97,9 +107,9 @@ class ConsultingOrdersController extends AdminController
                 return '余额支付';
             }
             if ($payment_type == 3){
-                $order_pack_id = OrderPack::where('id',$this->pay_order_pack_id)->pluck('service_pack_id');
-                $name = ServicePack::where('id',$order_pack_id[0])->pluck('name');
-                return '服务包支付('.$name[0].')';
+                $order_pack_id = OrderPack::where('id',$this->pay_order_pack_id)->value('service_pack_id');
+                $name = ServicePack::where('id',$order_pack_id)->value('name');
+                return '服务包支付('.$name.')';
             }
         });
         $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消',6=>'已超时',7=>'已预约']);

+ 46 - 7
app/Admin/Controllers/OrdersManagement/RefundApplicationController.php

xqd xqd xqd
@@ -4,6 +4,8 @@ namespace App\Admin\Controllers\OrdersManagement;
 
 use App\Admin\Actions\backstage\Refund\RefundCompleteAction;
 use App\Admin\Actions\backstage\Refund\RefundPartCompleteAction;
+use App\Models\Order;
+use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
 use App\Models\RefundApplication;
@@ -34,21 +36,59 @@ class RefundApplicationController extends AdminController
         $grid = new Grid(new RefundApplication());
         $grid->disableCreateButton();
         $grid->disableBatchActions();
+        $grid->filter(function ($filter){
+            $filter->disableIdFilter();
+            $filter->equal('orders.order_sn','订单号');
+            $filter->equal('orders.product_type','产品类型')->select([3=>'门诊预约',5=>'儿保预约']);
+            $filter->equal('orders.payment_status','支付状态')->select([3=>'退款中',4=>'已退款']);
+            $filter->equal('orders.order_status','订单状态')->select([5=>'已取消',6=>'已超时']);
+        });
         $grid->actions(function ($actions){
            $actions->disableView();
            $actions->disableEdit();
            $actions->disableDelete();
-           if ($actions->row->status == 1)
+            //获取取消时间
+            $cancel_time = Order::where('id',$actions->row->order_id)->value('cancel_time');
+            //获取预约时间
+            $appoint_start_time = OrderPatient::where('order_id',$actions->row->order_id)->value('appoint_start_time');
+            //获取预约前一小时的时间
+            $before_appoint_start_time = $appoint_start_time-60*60;
+            //获取订单备注
+            $notice = Order::where('id',$actions->row->order_id)->value('order_notes');
+            //获取订单类型
+            $order_type = Order::where('id',$actions->row->order_id)->value('product_type');
+            if ($actions->row->status == 1)
            {
                if (\Admin::user()->isRole('financial_staff')){
-                   $actions->add(new RefundCompleteAction());
-                   $actions->add(new RefundPartCompleteAction());
+                    if ($order_type == 3)
+                    {
+                        $actions->add(new RefundCompleteAction());
+                    }
+                    // 3. 儿保 大于一个小时和小于一个小时
+                    //根据时间预约时间进行区分
+                    if ($order_type == 5 && $notice != "医生拒绝接单")
+                    {
+                        if ($before_appoint_start_time>$cancel_time)
+                        {
+                            $actions->add(new RefundCompleteAction());
+                        }
+                        else
+                        {
+                            $actions->add(new RefundPartCompleteAction());
+                        }
+                    }
+                    // 4. 儿保 医生取消订单
+                    if ($order_type ==5 && $notice == "医生拒绝接单")
+                    {
+                        $actions->add(new RefundCompleteAction());
+                    }
                }
            }
         });
         $grid->column('id', __('id'));
         $grid->column('order_id', __('订单id'));
         $grid->column('orders.order_sn', __('订单号'));
+        $grid->column('orders.product_type','产品类型')->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值',8=>'快速预约']);
         $grid->column('orders.user_id', __('用户名'))->display(function ($id){
             $name = User::where('id',$id)->value('nickname');
             return $name;
@@ -57,10 +97,9 @@ class RefundApplicationController extends AdminController
             $name = Patient::where('id',$id)->value('name');
             return $name;
         });
-        $grid->column('orders.product_type','产品类型')->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值',8=>'快速预约']);
-        $grid->column('orders.order_notes','取消备注');
-        $grid->column('orders.order_status','订单状态')->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消']);
-        $grid->column('status', __('退款状态'))->using([1=>'退款中',2=>'已退款']);
+        $grid->column('orders.order_status','订单状态')->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消',6=>'已超时',7=>'已预约']);
+        $grid->column('orders.payment_status','支付状态')->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款']);
+        $grid->column('orders.order_notes','订单备注');
         $grid->column('orders.payment_amount', __('订单金额'))->display(function ($money){
             return $money/100;
         });

+ 99 - 0
app/Console/Commands/ScheduleNotice.php

xqd
@@ -0,0 +1,99 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Docter;
+use App\Models\DocterOrganization;
+use App\Models\OrganizationVaccine;
+use EasyWeChat\Factory;
+use Illuminate\Console\Command;
+
+class ScheduleNotice extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'scheduleNotice';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '排班提醒';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        //门诊医生排班
+        $docters = Docter::where(['type'=>1])->get();
+        $nowDay = intval(date('N',time()));
+        $endDay = (7-$nowDay)*86400 +time();
+        $time = date('Y-m-d',strtotime('this week')).'至'.date('Y-m-d',$endDay);
+        foreach ($docters as $d){
+            if(empty($d->openid)) continue;
+            $teams = get_docter_organization($d->id);
+            $data = [$d->openid,'',$d->name,$time, $teams];
+            $ret = send_wechatSubscription_message('schedule_notice',$data);
+        }
+
+    }
+
+    public function test()
+    {
+        $openid = 'oflME5eixHMij2TIVyy52WbfaQvA';
+        $data =  [
+            'touser' => $openid,
+            'mp_template_msg' => [
+                'appid' => env('OFFICE_APPID'),
+                'template_id' => 'Bd12nbwEtcrsN2IsVA2URiPH1qVGk3uyCemLyxBa-4U',
+                'url' => '',
+                'miniprogram' => [
+                    'appid' => env('WECHAT_APPID', 'wx6131f74e623bf6bf'),
+                    'page' => '',
+                ],
+                'data' => [
+                    'first' => [
+                        'value' => '尊敬的大哥,你下周的排班已经完成,具体如下!',
+                    ]
+                    ,'keyword1' => [
+                        'value' => '2021-01-18 - 2021-01-24',
+                    ],
+                    'keyword2' => [
+                        'value' => '测试团队',
+                    ],
+                    'keyword3' => [
+                        'value' => '总后台',
+                    ],
+                    'remark' => [
+                        'value' => '点击进入小程序查看详情,有疑问请联系客服',
+                    ],
+                ]
+
+            ],
+        ];
+
+        $app = Factory::miniProgram(config('config.docter_small_program'));
+        //先发送模板消息
+
+        $ret = $app->uniform_message->send($data);
+    }
+
+
+}

+ 3 - 3
app/Console/Commands/overTimeOrder.php

xqd xqd
@@ -41,13 +41,12 @@ class overTimeOrder extends Command
     public function handle()
     {
         Log::info('超时命令'.date('Y-m-d H:is',time()).PHP_EOL);
-        return ;
         $config_chat =  SystemConfig::get('docter_config','chat_complete_time');
         $config_phone =  SystemConfig::get('docter_config','phone_complete_time');
 
         // 换算为秒
-        $config_chat = $config_chat*60;
-        $config_phone = $config_phone*60;
+        $config_chat = intval($config_chat)*60;
+        $config_phone = intval($config_phone)*60;
 
         $inOrder = Order::with('orderPatient')->where(['order_status'=>3,'payment_status'=>2])->get();
         $catNewIds = [];
@@ -68,6 +67,7 @@ class overTimeOrder extends Command
             }
 
         }
+
         if ($catNewIds || $menNewIds){
             // 操作图文和电话订单为已完成
             Order::whereIn('id',$catNewIds)->update(['order_status'=>4]);

+ 1 - 0
app/Console/Kernel.php

xqd
@@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
     protected $commands = [
         //
         'overOrder'=>overTimeOrder::class,
+        'scheduleNotice'=>overTimeOrder::class,
     ];
 
     /**

+ 11 - 0
app/Helpers/functions.php

xqd xqd
@@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Log;
 use App\Exceptions\ExitOutException;
 use App\Models\SystemConfig;
 use App\Models\TimePeriod;
+use App\Models\DocterOrganization;
+use App\Models\Organization;
 
 //统一输出格式话的json数据
 if (!function_exists('out')) {
@@ -576,3 +578,12 @@ if (!function_exists('send_wechatSubscription_message')) {
         return $result ?? false;
     }
 }
+
+if (!function_exists('get_docter_organization')) {
+    function get_docter_organization($id){
+        $org_id = DocterOrganization::where('docter_id',$id)->where('state',1)->pluck('organization_id')->toArray();
+        if(empty($org_id)) return '';
+        $name = Organization::whereIn('id',$org_id)->pluck('name')->toArray();
+        return implode(',',$name);
+    }
+}

+ 89 - 220
app/Http/Controllers/Api/V1/OrderController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -48,7 +48,6 @@ class OrderController extends AuthController
             'symptoms' => 'required_if:product_type,2|max:2000',
             'medical_imgs' => 'required_if:product_type,2|json|max:3000',
             'order_pack_id' => 'required_if:payment_type,3|integer',
-            'pay_password|支付密码' => 'integer',
         ]);
         $user = $this->user;
 
@@ -58,15 +57,6 @@ class OrderController extends AuthController
             return out(null, 10011, '当前不在医生服务时间内,不能下单');
         }
 
-        if (!empty($req['pay_password'])) {
-            if (empty($user['pay_password'])) {
-                return out(null, 60010, '未设置支付密码');
-            }
-            if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
-                return out(null, 10001, '密码错误');
-            }
-        }
-
         $discount_amount = 0;
         if (!empty($req['user_coupon_id'])) {
             //计算优惠金额
@@ -75,33 +65,14 @@ class OrderController extends AuthController
         $payment_amount = $req['total_amount'] - $discount_amount;
         $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
 
-        if (in_array($req['payment_type'], [2,3]) && $payment_amount > 0 && empty($req['pay_password'])) {
-            return out(null, 10011, '请输入支付密码');
-        }
-
         //图文咨询订单未结束时不能针对同一医生再次下图文订单
         if ($req['product_type'] == 2 && Order::where('docter_id', $req['docter_id'])->where('product_type', 2)->where('user_id', $user['id'])->whereIn('order_status', [2,3])->exists()) {
             return out(null, 10012, '您已经下过该医生的图文订单了,并且订单还未完成');
         }
 
-        if ($req['payment_type'] == 2) {
-            if ($user['balance'] < $payment_amount) {
-                return out(null, 601, '余额不足');
-            }
-        }
-
-        if ($req['payment_type'] == 3) {
-            OrderPack::checkUserServicePack($req['order_pack_id'], $user['id'], $req['product_type']);
-        }
-
         $order_status = $payment_status = 1;
         $payment_time = 0;
-        if ($payment_amount == 0 || in_array($req['payment_type'], [2,3])) {
-            $order_status = $payment_status = 2;
-            $payment_time = time();
-        }
 
-        $config = null;
         DB::beginTransaction();
         try {
             //保存订单数据
@@ -138,50 +109,6 @@ class OrderController extends AuthController
             }
             OrderPatient::create($addPatient);
 
-            //判断是微信支付
-            if ($req['payment_type'] == 1) {
-                //生成支付交易单
-                if ($payment_amount > 0) {
-                    $trade_sn = build_sn($order['id'], 3, 'T');
-                    $payBody = '超级宝妈-'.config('config.product_type_map')[$req['product_type']];
-                    Payment::create([
-                        'user_id' => $user['id'],
-                        'order_id' => $order['id'],
-                        'trade_sn' => $trade_sn,
-                        'amount' => $payment_amount,
-                        'remark' => $payBody,
-                    ]);
-                    //请求支付
-                    $payment = Factory::payment(config('config.wechat_pay'));
-                    $result = $payment->order->unify([
-                        'body' => $payBody,
-                        'out_trade_no' => $trade_sn,
-                        'total_fee' => $payment_amount,
-                        'trade_type' => 'JSAPI',
-                        'openid' => $user['openid'],
-                    ]);
-
-                    if (empty($result['prepay_id'])) {
-                        $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
-                        return out(null, 702, $errorMsg);
-                    }
-
-                    $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
-                }
-            }
-            //判断是余额支付
-            elseif ($req['payment_type'] == 2) {
-                if ($payment_amount > 0) {
-                    //改变用户余额
-                    $change_amount = 0 - $payment_amount;
-                    User::changeBalance($user['id'], $change_amount, 1, $order['id'], '咨询订单消费');
-                }
-            }
-
-            if ($payment_amount == 0 || in_array($req['payment_type'], [2, 3])) {
-                Order::payCompletedHandle($order['id']);
-            }
-
             //如果有优惠券就标记优惠券为已使用
             if (!empty($req['user_coupon_id'])) {
                 UserCoupon::where('id', $req['user_coupon_id'])->update(['order_id' => $order['id'], 'status' => 2, 'use_time' => time()]);
@@ -193,7 +120,7 @@ class OrderController extends AuthController
             return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
         }
 
-        return out($config);
+        return out(['order_id' => $order['id']]);
     }
 
     public function appointPlaceOrder()
@@ -212,19 +139,9 @@ class OrderController extends AuthController
             'vaccine_id' => 'required_if:product_type,4|integer',
             'nurse_ids' => 'required_if:product_type,5|json',
             'order_pack_id' => 'required_if:payment_type,3|integer',
-            'pay_password|支付密码' => 'integer',
         ]);
         $user = $this->user;
 
-        if (!empty($req['pay_password'])) {
-            if (empty($user['pay_password'])) {
-                return out(null, 60010, '未设置支付密码');
-            }
-            if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
-                return out(null, 10001, '密码错误');
-            }
-        }
-
         $product_type = $req['product_type'];
 
         $discount_amount = 0;
@@ -235,10 +152,6 @@ class OrderController extends AuthController
         $payment_amount = $req['total_amount'] - $discount_amount;
         $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
 
-        if (in_array($req['payment_type'], [2,3]) && $payment_amount > 0 && empty($req['pay_password'])) {
-            return out(null, 10011, '请输入支付密码');
-        }
-
         //检查号源
         if ($product_type == 3) {
             $schedulePeriod = SchedulePeriod::where('docter_id', $req['docter_id'])->where('time_period_id', $req['time_period_id'])->where('schedule_date', $req['schedule_date'])->where('schedule_type', 1)->first();
@@ -262,12 +175,6 @@ class OrderController extends AuthController
             }
         }
 
-        if ($req['payment_type'] == 2) {
-            if ($user['balance'] < $payment_amount) {
-                return out(null, 601, '余额不足');
-            }
-        }
-
         //疫苗预约检查库存是否足够
         if ($req['product_type'] == 4) {
             $stock = OrganizationVaccine::where('org_id', $req['organization_id'])->where('vaccine_id', $req['vaccine_id'])->value('stock');
@@ -276,19 +183,9 @@ class OrderController extends AuthController
             }
         }
 
-        if ($req['payment_type'] == 3) {
-            OrderPack::checkUserServicePack($req['order_pack_id'], $user['id'], $req['product_type']);
-        }
-
         $order_status = $payment_status = 1;
         $payment_time = 0;
-        if ($payment_amount == 0 || in_array($req['payment_type'], [2,3])) {
-            $order_status = 7;
-            $payment_status = 2;
-            $payment_time = time();
-        }
 
-        $config = null;
         DB::beginTransaction();
         try {
             //保存订单数据
@@ -341,50 +238,6 @@ class OrderController extends AuthController
                 }
             }
 
-            //判断是微信支付
-            if ($req['payment_type'] == 1) {
-                //生成支付交易单
-                if ($payment_amount > 0) {
-                    $trade_sn = build_sn($order['id'], 3, 'T');
-                    $payBody = '超级宝妈-'.config('config.product_type_map')[$product_type];
-                    Payment::create([
-                        'user_id' => $user['id'],
-                        'order_id' => $order['id'],
-                        'trade_sn' => $trade_sn,
-                        'amount' => $payment_amount,
-                        'remark' => $payBody,
-                    ]);
-                    //请求支付
-                    $payment = Factory::payment(config('config.wechat_pay'));
-                    $result = $payment->order->unify([
-                        'body' => $payBody,
-                        'out_trade_no' => $trade_sn,
-                        'total_fee' => $payment_amount,
-                        'trade_type' => 'JSAPI',
-                        'openid' => $user['openid'],
-                    ]);
-
-                    if (empty($result['prepay_id'])) {
-                        $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
-                        return out(null, 702, $errorMsg);
-                    }
-
-                    $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
-                }
-            }
-            //判断是余额支付
-            elseif ($req['payment_type'] == 2) {
-                if ($payment_amount > 0) {
-                    //改变用户余额
-                    $change_amount = 0 - $payment_amount;
-                    User::changeBalance($user['id'], $change_amount, 1, $order['id'], '预约订单消费');
-                }
-            }
-
-            if ($payment_amount == 0 || in_array($req['payment_type'], [2, 3])) {
-                Order::payCompletedHandle($order['id']);
-            }
-
             //如果有优惠券就标记优惠券为已使用
             if (!empty($req['user_coupon_id'])) {
                 UserCoupon::where('id', $req['user_coupon_id'])->update(['order_id' => $order['id'], 'status' => 2, 'use_time' => time()]);
@@ -396,7 +249,7 @@ class OrderController extends AuthController
             return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
         }
 
-        return out($config);
+        return out(['order_id' => $order['id']]);
     }
 
     public function packPlaceOrder()
@@ -411,20 +264,10 @@ class OrderController extends AuthController
             'is_security' => 'required|in:0,1',
             'guardian_name' => 'required|max:50',
             'relationship_type' => 'required|integer',
-            'pay_password|支付密码' => 'integer',
             'is_need_insurance' => 'in:0,1',
         ]);
         $user = $this->user;
 
-        if (!empty($req['pay_password'])) {
-            if (empty($user['pay_password'])) {
-                return out(null, 60010, '未设置支付密码');
-            }
-            if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
-                return out(null, 10001, '密码错误');
-            }
-        }
-
         $discount_amount = 0;
         if (!empty($req['user_coupon_id'])) {
             //计算优惠金额
@@ -436,25 +279,9 @@ class OrderController extends AuthController
         $payment_amount = $req['total_amount'] - $discount_amount;
         $payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
 
-        if ($req['payment_type'] == 2 && $payment_amount > 0 && empty($req['pay_password'])) {
-            return out(null, 10011, '请输入支付密码');
-        }
-
-        if ($req['payment_type'] == 2) {
-            if ($user['balance'] < $payment_amount) {
-                return out(null, 601, '余额不足');
-            }
-        }
-
         $order_status = $payment_status = 1;
         $payment_time = 0;
-        if ($payment_amount == 0 || $req['payment_type'] == 2) {
-            $order_status = 3;
-            $payment_status = 2;
-            $payment_time = time();
-        }
 
-        $config = null;
         DB::beginTransaction();
         try {
             //保存订单数据
@@ -494,50 +321,6 @@ class OrderController extends AuthController
             $addPack['is_need_insurance'] = !empty($req['is_need_insurance']) ? $req['is_need_insurance'] : 0;
             OrderPack::create($addPack);
 
-            //判断是微信支付
-            if ($req['payment_type'] == 1) {
-                //生成支付交易单
-                if ($payment_amount > 0) {
-                    $trade_sn = build_sn($order['id'], 3, 'T');
-                    $payBody = '超级宝妈-'.config('config.product_type_map')[6];
-                    Payment::create([
-                        'user_id' => $user['id'],
-                        'order_id' => $order['id'],
-                        'trade_sn' => $trade_sn,
-                        'amount' => $payment_amount,
-                        'remark' => $payBody,
-                    ]);
-                    //请求支付
-                    $payment = Factory::payment(config('config.wechat_pay'));
-                    $result = $payment->order->unify([
-                        'body' => $payBody,
-                        'out_trade_no' => $trade_sn,
-                        'total_fee' => $payment_amount,
-                        'trade_type' => 'JSAPI',
-                        'openid' => $user['openid'],
-                    ]);
-
-                    if (empty($result['prepay_id'])) {
-                        $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
-                        return out(null, 702, $errorMsg);
-                    }
-
-                    $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
-                }
-            }
-            //判断是余额支付
-            elseif ($req['payment_type'] == 2) {
-                if ($payment_amount > 0) {
-                    //改变用户余额
-                    $change_amount = 0 - $payment_amount;
-                    User::changeBalance($user['id'], $change_amount, 1, $order['id'], '购买服务包');
-                }
-            }
-
-            if ($payment_amount == 0 || $req['payment_type'] == 2) {
-                Order::payCompletedHandle($order['id']);
-            }
-
             //如果有优惠券就标记优惠券为已使用
             if (!empty($req['user_coupon_id'])) {
                 UserCoupon::where('id', $req['user_coupon_id'])->update(['order_id' => $order['id'], 'status' => 2, 'use_time' => time()]);
@@ -549,7 +332,7 @@ class OrderController extends AuthController
             return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
         }
 
-        return out($config);
+        return out(['order_id' => $order['id']]);
     }
 
     public function orderList()
@@ -756,4 +539,90 @@ class OrderController extends AuthController
 
         return out($orderPacks);
     }
+
+    public function orderPay()
+    {
+        $req = request()->post();
+        $this->validate(request(), [
+            'order_id' => 'required|integer',
+            'pay_password' => 'max:20',
+        ]);
+        $user = $this->user;
+
+        $order = Order::where('id', $req['order_id'])->first()->toArray();
+        if (in_array($order['payment_type'], [2,3]) && $order['payment_amount'] > 0 && empty($req['pay_password'])) {
+            return out(null, 10011, '请输入支付密码');
+        }
+        if (!empty($req['pay_password'])) {
+            if (empty($user['pay_password'])) {
+                return out(null, 60010, '未设置支付密码');
+            }
+            if (sha1(md5($req['pay_password'])) !== $user['pay_password']) {
+                return out(null, 10001, '密码错误');
+            }
+        }
+        if ($order['payment_type'] == 2) {
+            if ($user['balance'] < $order['payment_amount']) {
+                return out(null, 601, '余额不足');
+            }
+        }
+        if ($order['payment_type'] == 3) {
+            OrderPack::checkUserServicePack($order['pay_order_pack_id'], $user['id'], $order['product_type']);
+        }
+
+        $config = null;
+        DB::beginTransaction();
+        try {
+            //判断是微信支付
+            if ($order['payment_type'] == 1) {
+                //生成支付交易单
+                if ($order['payment_amount'] > 0) {
+                    $trade_sn = build_sn($order['id'], 3, 'T');
+                    $payBody = '超级宝妈-'.config('config.product_type_map')[$order['product_type']];
+                    Payment::create([
+                        'user_id' => $user['id'],
+                        'order_id' => $order['id'],
+                        'trade_sn' => $trade_sn,
+                        'amount' => $order['payment_amount'],
+                        'remark' => $payBody,
+                    ]);
+                    //请求支付
+                    $payment = Factory::payment(config('config.wechat_pay'));
+                    $result = $payment->order->unify([
+                        'body' => $payBody,
+                        'out_trade_no' => $trade_sn,
+                        'total_fee' => $order['payment_amount'],
+                        'trade_type' => 'JSAPI',
+                        'openid' => $user['openid'],
+                    ]);
+
+                    if (empty($result['prepay_id'])) {
+                        $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
+                        return out(null, 702, $errorMsg);
+                    }
+
+                    $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
+                }
+            }
+            //判断是余额支付
+            elseif ($order['payment_type'] == 2) {
+                if ($order['payment_amount'] > 0) {
+                    //改变用户余额
+                    $change_amount = 0 - $order['payment_amount'];
+                    User::changeBalance($user['id'], $change_amount, 1, $order['id'], '预约订单消费');
+                }
+            }
+
+            if ($order['payment_amount'] == 0 || in_array($order['payment_type'], [2, 3])) {
+                Order::payCompletedHandle($order['id']);
+            }
+
+            DB::commit();
+        } catch (Exception $e) {
+            DB::rollBack();
+            return out(null, 500, '下单失败,请稍后重试', $e->getMessage());
+        }
+
+        return out($config);
+    }
 }