Explorar o código

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

zilong %!s(int64=4) %!d(string=hai) anos
pai
achega
e04edbbddc

+ 2 - 0
README.md

xqd
@@ -7,6 +7,8 @@
 - 执行 `php artisan migrate`
 - 执行 `php artisan db:seed`
 - 执行 `php artisan passport:install`
+- 执行 `php artisan vendor:publish --tag=laravel-admin-grid-lightbox`
+- 执行 `php artisan vendor:publish --tag=laravel-admin-wang-editor2`
 - storage下所有目录 和 bootstrap/cache 目录应该是可写的
 - 键入 '域名/admin/auth/login'(后台登录)
 - 用户名:admin;密码:admin

+ 14 - 13
app/Admin/Controllers/HomeController.php

xqd
@@ -14,35 +14,36 @@ class HomeController extends Controller
 {
     public function index(Content $content)
     {
-//        dd(\Admin::user()->isRole('financial_staff'));
         if (\Admin::user()->isRole('financial_staff')){
             return redirect('admin/refund_applications');
         }
+        $start_time = date('Y-m-d 00:00:00',time());
+        $end_time = date('Y-m-d 00:00:00',strtotime('+1 days',time()));
         return $content
             ->title('欢迎进入后台管理系统')
             ->description('后台数据中心')
             ->row('<h1 text-align="center">订单概况</h1>')
-            ->row(function (Row $row) {
+            ->row(function (Row $row) use ($end_time,$start_time){
                 // 产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
-                $row->column(3, function (Column $column) {
-                    $column->append(infoBox('新增电话咨询订单', 'dropbox', '/admin/consulting_orders?product_type=1', 'green', Sta::getOrderCount(1)));
+                $row->column(3, function (Column $column) use ($end_time,$start_time){
+                    $column->append(infoBox('新增电话咨询订单', 'dropbox', '/admin/consulting_orders?product_type=1&created_at[start]='.$start_time.'&created_at[end]='.$end_time.'', 'green', Sta::getOrderCount(1)));
                 });
-                $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('新增图文咨询订单', 'dropbox', '/admin/consulting_orders?product_type=2', 'green', Sta::getOrderCount(2)));
+                $row->column(3, function (Column $column) use ($end_time,$start_time) {
+                    $column->append(\App\Admin\Controllers\infoBox('新增图文咨询订单', 'dropbox', '/admin/consulting_orders?product_type=2&created_at[start]='.$start_time.'&created_at[end]='.$end_time.'', 'green', Sta::getOrderCount(2)));
                 });
 
-                $row->column(3, function (Column $column) {
-                    $column->append(infoBox('新增门诊预约订单', 'user-plus', '/admin/booking_order?product_type=3', 'green',Sta::getOrderCount(3)));
+                $row->column(3, function (Column $column) use ($end_time,$start_time) {
+                    $column->append(infoBox('新增门诊预约订单', 'user-plus', '/admin/booking_order?product_type=3&created_at[start]='.$start_time.'&created_at[end]='.$end_time.'', 'green',Sta::getOrderCount(3)));
                 });
 
-                $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('新增计免预约订单', 'user-plus', '/admin/booking_order?product_type=4', 'green', Sta::getOrderCount(4)));
+                $row->column(3, function (Column $column) use ($end_time,$start_time) {
+                    $column->append(\App\Admin\Controllers\infoBox('新增计免预约订单', 'user-plus', '/admin/booking_order?product_type=4&created_at[start]='.$start_time.'&created_at[end]='.$end_time.'', 'green', Sta::getOrderCount(4)));
                 });
             })
-            ->row(function (Row $row) {
+            ->row(function (Row $row) use ($end_time,$start_time) {
                 //产品类型(1.电话咨询 2.图文咨询 3.门诊预约 4.疫苗接种预约 5.儿保预约 6.服务包 7.充值)
-                $row->column(3, function (Column $column) {
-                    $column->append(\App\Admin\Controllers\infoBox('新增儿保订单', 'dropbox', '/admin/booking_order?product_type=5', 'green', Sta::getOrderCount(5)));
+                $row->column(3, function (Column $column) use ($end_time,$start_time) {
+                    $column->append(\App\Admin\Controllers\infoBox('新增儿保订单', 'dropbox', '/admin/booking_order?product_type=5&created_at[start]='.$start_time.'&created_at[end]='.$end_time.'', 'green', Sta::getOrderCount(5)));
                 });
                 $row->column(3, function (Column $column) {
                     $column->append(\App\Admin\Controllers\infoBox('历史总订单', 'dropbox', 'javascript:void(0)', 'green', Sta::getOrderCount(0)));

+ 3 - 1
app/Admin/Controllers/OrdersManagement/BookingOrderController.php

xqd xqd xqd
@@ -82,6 +82,7 @@ class BookingOrderController extends AdminController
                 );
                 $filter->timestampBetween('payment_time', "支付时间")->datetime();
                 $filter->timestampBetween('end_time', "订单完成时间")->datetime();
+                $filter->between('created_at','创建时间')->datetime();
 
             });
         });
@@ -114,6 +115,7 @@ class BookingOrderController extends AdminController
     });
         $status_arr = Order::getStatus();
         $grid->model()->orderBy('id','desc');
+        $grid->column('created_at','创建时间')->hide();
         $grid->column('id', __('Id'))->sortable();
         $grid->column('user.nickname', __('用户姓名'));
         $grid->column('docter.name', __('医生姓名'));
@@ -155,7 +157,7 @@ class BookingOrderController extends AdminController
                 return '<span class="label label-default">'.$info.'</span>';
             }
         });;
-        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款'])->label([1=>'warring',2=>'success',3=>'info',4=>'danger',5=>'default']);;
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款'])->label([1=>'warning',2=>'success',3=>'info',4=>'danger',5=>'default']);;
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){
             return $money/100;
         });

+ 4 - 2
app/Admin/Controllers/OrdersManagement/ConsultingOrdersController.php

xqd xqd xqd
@@ -83,6 +83,8 @@ class ConsultingOrdersController extends AdminController
                 $filter->timestampBetween('payment_time', "支付时间")->datetime();
                 $filter->timestampBetween('receiving_time', "接单时间")->datetime();
                 $filter->timestampBetween('end_time', "订单完成时间")->datetime();
+                // 设置datetime类型
+                $filter->between('created_at','创建时间')->datetime();
             });
         });
         //操作
@@ -133,7 +135,7 @@ class ConsultingOrdersController extends AdminController
                 return '<span class="label label-default">'.$info.'</span>';
             }
         });
-        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款'])->label([1=>'warring',2=>'success',3=>'info',4=>'danger',5=>'default']);
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款',5=>'待退款'])->label([1=>'warning',2=>'success',3=>'info',4=>'danger',5=>'default']);
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){
             return $money/100;
         });
@@ -194,7 +196,7 @@ class ConsultingOrdersController extends AdminController
                 return date('Y-m-d H:i:s',$time);
             }
         });
-
+        $grid->column('created_at','创建时间')->hide();
         return $grid;
     }
 

+ 2 - 1
app/Admin/Controllers/OrdersManagement/RechargeOrderController.php

xqd xqd
@@ -36,6 +36,7 @@ class RechargeOrderController extends AdminController
             $filter->disableIdFilter();
 
             $filter->like('user.nickname','用户姓名');
+            $filter->equal('user.phone','用户电话');
             $filter->equal('order_status','订单状态')->radio(
                 [
                     ''=>'不限',
@@ -79,7 +80,7 @@ class RechargeOrderController extends AdminController
                 return '<span class="label label-default">'.$info.'</span>';
             }
         });
-        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label([1=>'warring',2=>'success',3=>'info',4=>'danger']);;
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label([1=>'warning',2=>'success',3=>'info',4=>'danger']);;
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){
             return $money/100;
         });

+ 20 - 2
app/Admin/Controllers/OrdersManagement/ServicePackOrderController.php

xqd xqd xqd xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\OrdersManagement;
 
+use App\Admin\Actions\backstage\Docters\Team;
 use App\Admin\Actions\backstage\Orders\Evaluate;
 use App\Admin\Actions\backstage\Orders\ServicePack;
 use App\Admin\Actions\backstage\Orders\ServicePackOrderList;
@@ -38,6 +39,8 @@ class ServicePackOrderController extends AdminController
             $filter->disableIdFilter();
 
                 $filter->like('user.nickname','用户姓名');
+                $filter->equal('user.phone','用户电话');
+                $filter->like('orderPack.pack_name','服务包名称');
                 $filter->like('patient.name','患者姓名');
                 $filter->equal('order_status','订单状态')->radio(
                     [
@@ -49,7 +52,12 @@ class ServicePackOrderController extends AdminController
                         5=>'已取消'
                     ]
                 );
-                $filter->timestampBetween('payment_time', "支付时间")->datetime();
+                $filter->where(function ($query){
+                   $query->whereHas('orderPack',function ($query){
+                       $query->where('team_id','like',"%{$this->input}%");
+                   });
+                },'医生团队')->select(\App\Models\Team::where('status',1)->pluck('name','id'));
+            $filter->timestampBetween('payment_time', "支付时间")->datetime();
 
             });
         //操作
@@ -78,6 +86,16 @@ class ServicePackOrderController extends AdminController
         $grid->column('orderPack.pack_price', __('服务包价格'))->display(function ($money){
             return $money/100;
         });
+        $grid->column('orderPack.team_id', __('医生团队'))->display(function ($team){
+            if (empty($team))
+            {
+                return '无';
+            }else
+            {
+                $res = \App\Models\Team::whereIn('id',$team)->pluck('name')->toArray();
+                return $res;
+            }
+        })->label('info');
         $grid->column('product_type', __('产品类型'))->using([6=>'服务包订单']);
         $grid->column('payment_type', __('支付方式'))->using([1=>'微信支付',2=>'余额支付']);
         $grid->column('order_status', __('订单状态'))->display(function ($w) use ($status_arr) {
@@ -94,7 +112,7 @@ class ServicePackOrderController extends AdminController
                 return '<span class="label label-default">'.$info.'</span>';
             }
         });
-        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label([1=>'warring',2=>'success',3=>'info',4=>'danger']);;
+        $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label([1=>'warning',2=>'success',3=>'info',4=>'danger']);
         $grid->column('total_amount', __('订单总金额'))->display(function ($money){
             return $money/100;
         });

+ 22 - 17
app/Admin/Controllers/ServiceManagement/ServiceController.php

xqd xqd xqd
@@ -25,7 +25,7 @@ class ServiceController extends AdminController
      *
      * @var string
      */
-    protected $title = '服务审核';
+    protected $title = '服务开通';
 
     /**
      * Make a grid builder.
@@ -38,31 +38,34 @@ class ServiceController extends AdminController
 
 //        $status = request('status',2);
 
-        $grid->tools(function ($tools) {
-            $tools->batch(function ($batch) {
-                $batch->disableDelete();
-            });
-        });
+//        $grid->tools(function ($tools) {
+//            $tools->batch(function ($batch) {
+//                $batch->disableDelete();
+//            });
+//        });
+        $grid->disableBatchActions();
         $grid->model()->where('status','!=',3)->orderBy('id','desc');
         $grid->column('id', __('Id'));
-        $grid->column('ondocter.avatar', __('头像'))->lightbox(['width' =>'', 'height' => 30]);
+//        $grid->column('ondocter.avatar', __('头像'))->lightbox(['width' =>'', 'height' => 30]);
         $grid->column('ondocter.id', __('医生ID'));
         $grid->column('ondocter.name','医生名称');
-        $grid->column('service_type','服务类别')->using([1=>'图文咨询',2=>'电话咨询',3=>'门诊预约'])->label('default');
+        $grid->column('ondocter.phone','医生电话');
         $grid->column('ondocter.sex','性别')->using([1=>'男',2=>'女']);
+
+        $grid->column('service_type','服务类别')->using([1=>'图文咨询',2=>'电话咨询',3=>'门诊预约'])->label('default');
         $grid->column('docterorganization', __('所属机构'))->where('state',1)->pluck('organization_id')->display(function ($organization){
             $value = Organization::whereIn('id',$organization->toArray())->pluck('intro')->toArray();
             return $value;
         })->label('info')->width(300);
-        $grid->column('ondocter.label', __('标签'))->display(function ($label){
-            if($label==null || $label == '无')
-            {
-                return '无';
-            }else{
-                $label_value = DocterLabel::whereIn('id',$label)->pluck('label_name')->toArray();
-                return $label_value;
-            }
-        })->label(['info']);
+//        $grid->column('ondocter.label', __('标签'))->display(function ($label){
+//            if($label==null || $label == '无')
+//            {
+//                return '无';
+//            }else{
+//                $label_value = DocterLabel::whereIn('id',$label)->pluck('label_name')->toArray();
+//                return $label_value;
+//            }
+//        })->label(['info']);
 
 
         $grid->column('status', __('状态'))->using([1=>'待审核',2=>'已开通',3=>'未开通'])->label([
@@ -78,6 +81,8 @@ class ServiceController extends AdminController
             $filter->equal('service_type','服务类别')->select([1 => '图文咨询', 2 => '电话咨询', 3 => '门诊预约']);
             $filter->equal('status','状态')->select([1=>'待审核',2 =>'已开通 ']);
             $filter->equal('docterorganization.organization_id','所属机构')->select(Organization::pluck('intro','id'));
+            $filter->like('ondocter.name','医生名称');
+            $filter->equal('ondocter.phone','医生电话');
         });
         $grid->actions(function ($actions) {
             $actions->disableEdit();

+ 8 - 8
app/Admin/Controllers/UserManagement/BmUser/UserListController.php

xqd xqd
@@ -54,7 +54,7 @@ class UserListController extends AdminController
         $grid->filter(function ($filter){
             $filter->column(1/2, function ($filter) {
                 $filter->disableIdFilter();
-                $filter->equal('phone','手机号码')->mobile()->placeholder("请输入手机");
+                $filter->equal('phone','手机号码');
                 $filter->like('nickname','用户名');
                 $filter->equal('status','用户状态')->radio([
                     ''   => '不限',
@@ -84,13 +84,13 @@ class UserListController extends AdminController
                     return $time;
                 }
             });
-            $grid->column('last_login_time', __('最后登录时间'))->display(function ($time){
-                if ($time == 0 ){
-                    return '';
-                }else{
-                    return date('Y-m-d H:i:s',$time);
-                }
-            });
+//            $grid->column('last_login_time', __('最后登录时间'))->display(function ($time){
+//                if ($time == 0 ){
+//                    return '';
+//                }else{
+//                    return date('Y-m-d H:i:s',$time);
+//                }
+//            });
         return $grid;
     }
 

+ 6 - 3
app/Admin/Controllers/UserManagement/BmUser/UserOrdersController.php

xqd xqd xqd
@@ -5,6 +5,7 @@ namespace App\Admin\Controllers\UserManagement\BmUser;
 use App\Admin\Actions\backstage\Orders\OrderOpinion;
 use App\Admin\Actions\backstage\Orders\ServicePack;
 use App\Models\Order;
+use App\Models\OrderPack;
 use Encore\Admin\Controllers\AdminController;
 use Encore\Admin\Form;
 use Encore\Admin\Grid;
@@ -30,7 +31,8 @@ class UserOrdersController extends AdminController
         $uesr_id = \request('user_id');
         $grid->filter(function ($filter){
             $filter->disableIdFilter();
-            $filter->equal('user_id','用户id');
+//            $filter->equal('user_id','用户id');
+            $filter->like('orderPatient.name','患者姓名');
         });
         $grid->actions(function ($actions){
             $actions->disableView();
@@ -75,8 +77,9 @@ class UserOrdersController extends AdminController
                 return '余额支付';
             }
             if ($payment_type == 3){
-                $name = ServicePack::where('id',$this->pay_order_pack_id)->pluck('name');
-                return '服务包支付('.$name[0].')';
+                $order_pack_id = OrderPack::where('id',$this->pay_order_pack_id)->value('service_pack_id');
+                $name = \App\Models\ServicePack::where('id',$order_pack_id)->value('name');
+                return '服务包支付('.$name.')';
             }
             return '';
         });

+ 2 - 1
app/Admin/Controllers/UserManagement/BmUser/UserServiceController.php

xqd
@@ -52,7 +52,8 @@ class UserServiceController extends AdminController
         });
         $grid->column('orderPack.team_id', __('医生团队'))->display(function ($team)
         {
-            $team = json_decode($team);
+//            $team = json_encode($team);
+//            $team = json_decode($team);
             if (empty($team))
             {
                 return '无';

+ 1 - 0
app/Admin/Controllers/UserManagement/DocterManagement/DoctorManagementController.php

xqd
@@ -55,6 +55,7 @@ class DoctorManagementController extends AdminController
                 1    => '已认证',
             ]);
         });
+        $grid->disableBatchActions();
         $grid->actions(function ($actions) {
             // 去掉编辑
             $actions->disableEdit();

+ 40 - 32
app/Community/Controllers/ApiController.php

xqd xqd xqd xqd xqd
@@ -5,6 +5,7 @@ namespace App\Community\Controllers;
 
 
 use App\Http\Controllers\Controller;
+use App\Imports\Docter\DocterOrganizationInfo;
 use App\Models\Area;
 use App\Models\Docter;
 use App\Models\DocterOrganization;
@@ -47,11 +48,19 @@ class ApiController extends Controller
     public function getDocter()
     {
         $user = Admin::user();
+        $org_id = $user->org_id;
         $where = [];
         if ($user->docter_id) {
             $where ['id'] = $user->docter_id;
+            return Docter::where($where)->get(['name as text', 'id'])->toArray();
+        }
+        if ($org_id)
+        {
+            $docter_arr =  DocterOrganization::where('organization_id',$org_id)->where('state',1)->pluck('docter_id')->toArray();
+            return Docter::whereIn('id',$docter_arr)->get(['name as text', 'id'])->toArray();
+        }else{
+            return Docter::where($where)->get(['name as text', 'id'])->toArray();
         }
-        return Docter::where($where)->get(['name as text', 'id'])->toArray();
     }
 
     /**
@@ -731,43 +740,43 @@ class ApiController extends Controller
         }
 
         TimePeriod::where(['org_id' => $org_id, 'type' => $sType, 'docter_id' => $docter_id])->delete();
+        if($configData['status']){
+            for ($i = 1; $i <= 3; $i++) {
+                $tType = $i;
+                DB::beginTransaction();
+                try {
+                    //1.删除旧时间段,并删除排班数据
 
-        for ($i = 1; $i <= 3; $i++) {
-            $tType = $i;
-            DB::beginTransaction();
-            try {
-                //1.删除旧时间段,并删除排班数据
-
-                //todo 暂时未删除周排班
-                self::deleteScheduleInfo($docter_id, $sType, $tType, $org_id);
-                $count = $countArr[$i];
-                //2.创建新时间段
-                self::makeTimePeriod($docter_id, $org_id, $sType, $c_r[$tType], $count, $serviceTime);
+                    //todo 暂时未删除周排班
+                    self::deleteScheduleInfo($docter_id, $sType, $tType, $org_id);
+                    $count = $countArr[$i];
+                    //2.创建新时间段
+                    self::makeTimePeriod($docter_id, $org_id, $sType, $c_r[$tType], $count, $serviceTime);
 
-                $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period', $times[$tType])->pluck('id')->toArray();
+                    $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period', $times[$tType])->pluck('id')->toArray();
 
 
-                if ($sType == 1) {
-                    $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType, 'schedule_type' => $sType]);
-                } else {
-                    $week_schedule = WeekSchedule::where(['organization_id' => $org_id, 'type' => $tType, 'schedule_type' => $sType]);
-                }
-                $week = $week_schedule->count();
+                    if ($sType == 1) {
+                        $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType, 'schedule_type' => $sType]);
+                    } else {
+                        $week_schedule = WeekSchedule::where(['organization_id' => $org_id, 'type' => $tType, 'schedule_type' => $sType]);
+                    }
+                    $week = $week_schedule->count();
 
-                if ($week != 0) {
-                    //3.以周模板添加2个月的数据
-                    self::makeSchedule($sType, $docter_id, $org_id, $tType, $time_periods);
-                    //TODO 删除周排班,插入新周排班
-                    self::changeWeekSchedule($docter_id, $org_id, $sType, $tType, $time_periods);
+                    if ($week != 0) {
+                        //3.以周模板添加2个月的数据
+                        self::makeSchedule($sType, $docter_id, $org_id, $tType, $time_periods);
+                        //TODO 删除周排班,插入新周排班
+                        self::changeWeekSchedule($docter_id, $org_id, $sType, $tType, $time_periods);
+                    }
+                    DB::commit();
+                } catch (\Exception $e) {
+                    dd($e->getMessage());
+                    DB::rollBack();
                 }
-                DB::commit();
-            } catch (\Exception $e) {
-                dd($e->getMessage());
-                DB::rollBack();
             }
         }
 
-
         //{"1":{"amStartTime":"08:00","amEndTime":"12:00","amPerson":3},"2":{"pmStartTime":"14:00","pmEndTime":"18:00","pmPerson":5},"3":{"nightStartTime":"18:00","nightEndTime":"23:00","nightPerson":4}}
         $config = [
             1 => ['amStartTime' => $configData['amStartTime'], "amEndTime" => $configData['amEndTime'], 'amPerson' => $configData['amNum']],
@@ -870,9 +879,9 @@ class ApiController extends Controller
     public static function deleteScheduleInfo($docter_id, $sType, $timeType, $orgId = 0)
     {
         if ($docter_id != 0) {
-            SchedulePeriod::where(['docter_id' => $docter_id, 'type' => $timeType, 'me_sure' => 0])->where('organization_id', '=', $orgId)->delete();
+            SchedulePeriod::where(['docter_id' => $docter_id, 'schedule_type'=>$sType,'type' => $timeType, 'me_sure' => 0])->where('organization_id', '=', $orgId)->delete();
         } else {
-            SchedulePeriod::where(['organization_id' => $orgId, 'type' => $timeType, 'me_sure' => 0])->where('docter_id', 0)->delete();
+            SchedulePeriod::where(['organization_id' => $orgId, 'schedule_type'=>$sType,'type' => $timeType, 'me_sure' => 0])->where('docter_id', 0)->delete();
         }
         return true;
     }
@@ -889,7 +898,6 @@ class ApiController extends Controller
                 'end_time_period' => date('H:i', strtotime($timeConfig['start_time']) + $i * $serviceTime * 60),
             ];
             $isHave = TimePeriod::where($timePreiod)->count();
-//            dump($timePreiod);
 //            dump($isHave);
 
             if ($isHave == 0) $allData[] = $timePreiod;

+ 11 - 6
app/Community/Controllers/DocterChatController.php

xqd xqd
@@ -42,21 +42,20 @@ class DocterChatController extends AdminController
         $grid->batchActions(function ($batch) {
             $batch->add(new sendNotice());
         });
+        $where['product_type'] = 2;
         if(!$is_admin){
             $where['organization_id']=$org_id;
             if($docter_id){
                 $where['docter_id'] = $docter_id;
             }
-            $grid->model()->where($where);
-//            $grid->model()->whereHas('orders',function ($query) use ($org_id,$docter_id) {
-//                $query->where($where);
-//            });
         }
+        $grid->model()->where($where);
 
         $grid->column('order_sn', __('订单号'));
         $grid->column('docter.name', __('医生'));
         $grid->column('orderUser.nickname', __('咨询用户'));
         $grid->column('orderPatient.name', __('咨询患者'));
+        $grid->column('patient.phone', __('电话'));
         $grid->column('orderPatient.birthday', __('患者年龄'))->display(function ($w){
             return birthday_to_age($w);
         });
@@ -69,9 +68,15 @@ class DocterChatController extends AdminController
            $actions->disableView();
            $actions->disableEdit();
         });
-        $grid->filter(function ($filter){
+        $grid->filter(function (Grid\Filter $filter){
             $filter->disableIdFilter();
-            $filter->equal('order_status','订单状态')->select(Order::$_order_status);
+            $filter->column(1/2, function ($filter) {
+                $filter->like('order_sn','订单号');
+                $filter->like('patient.phone','电话');
+                $filter->like('patient.name','患者名称');
+                $filter->equal('order_status','订单状态')->select(Order::$_order_status);
+                $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
+            });
         });
         $grid->column('order_status', __('订单状态'))->using(Order::$_order_status);
         $grid->column('created_at', __('下单时间'));

+ 2 - 2
app/Community/Controllers/OrderController.php

xqd xqd xqd
@@ -6,6 +6,7 @@ use App\Community\Actions\Clinc\Finished;
 use App\Community\Actions\Clinc\OrderCancel;
 use App\Community\Actions\Clinc\Reserved;
 use App\Models\Docter;
+use App\Models\DocterOrganization;
 use App\Models\Order;
 use Encore\Admin\Controllers\AdminController;
 use Encore\Admin\Facades\Admin;
@@ -41,7 +42,6 @@ class OrderController extends AdminController
             } );
         });
         $is_admin = Admin::user()->inRoles(['administrator','devloper']);
-
         //检查是否是门诊医生
         $is_docter = $user->isRole('opc');
         $org_id = $user->org_id;
@@ -53,7 +53,7 @@ class OrderController extends AdminController
             $where ['organization_id']=$org_id;
         }
         $res = request()->all();
-        $grid->model()->where($where);
+        $grid->model()->where($where)->where('payment_status','!=',1);
         if(!empty($res['orderPatient']['appoint_start_time']['start']) || !empty($res['orderPatient']['appoint_start_time']['start']) ){
             $grid->model()->orderBy('appoint_start_time','desc');
         } else {

+ 1 - 1
app/Community/Controllers/OrderNurseController.php

xqd
@@ -96,7 +96,7 @@ class OrderNurseController extends AdminController
                 return '<span class="label label-default">'.$info.'</span>';
             }
         });
-        $grid->column('payment_status', __('支付状态'))->using(Order::getPayStatus())->label([1=>'warring',2=>'success',3=>'info',4=>'danger',5=>'default']);
+        $grid->column('payment_status', __('支付状态'))->using(Order::getPayStatus())->label([1=>'warning',2=>'success',3=>'info',4=>'danger',5=>'default']);
         //查询
 //        $grid->quickSearch(function ($model, $query) {
 //            $model->whereHas('patient',function ($model) use ($query) {

+ 11 - 24
app/Helpers/functions.php

xqd
@@ -145,36 +145,23 @@ if (!function_exists('build_sn')) {
 }
 
 //生日转年龄
-if (!function_exists('birthday_to_age')) {
+if (!function_exists('birthday_to_age')){
     function birthday_to_age($birthday)
     {
-        $date2 = date('Y-m-d');
-        list($y1, $m1, $d1) = explode('-', $birthday);
-        list($y2, $m2, $d2) = explode('-', $date2);
-        $y = $y2 - $y1;
-        $m = $m2 - $m1;
-        $d = $d2 - $d1;
-        if ($d < 0) {
-            $d += (int)date('t', strtotime("-1 month $date2"));
-            $m = $m - 1;
+        if($birthday==null)
+        {
+            return "0岁";
         }
-        if ($m < 0) {
-            $m += 12;
-            $y = $y - 1;
+        list($year, $month, $day) = explode("-", $birthday);
+        $year_diff = (date("Y") - $year) > 0 ? date("Y") - $year.'岁':'';
+        $month_diff = (date("m") - $month) > 0 ? date("m") - $month.'个月':'';
+        $day_diff = (date("d") - $day) > 0 ? date("d") - $day.'天':'';
+        if ($day_diff < 0 || $month_diff < 0) {
+            $year_diff--;
         }
-
-        if ($y == 0 && $m == 0 && $d != 0) {
-            return $d . '岁';
-        } elseif ($y == 0 && $m != 0 && $d != 0) {
-            return $m . '个月' . $d . '天';
-        } elseif ($y != 0 && $m == 0 && $d != 0) {
-            return $y . '岁' . $d . '天';
-        }
-
-        return $y . '岁' . $m . '个月' . $d . '天';
+        return $year_diff.$month_diff.$day_diff ;
     }
 }
-
 //计算经纬度两点之间距离(返回为米)
 if (!function_exists('get_distance')) {
     function get_distance($lat1, $lng1, $lat2, $lng2)

+ 66 - 10
app/Http/Controllers/AppiontController.php

xqd
@@ -159,17 +159,73 @@ class AppiontController extends Controller
     public function orverTime()
     {
         $st = strtotime('2021-02-25 18:00:00');
-        $orders = Order::select('id')
-            ->where(['product_type'=>4,'order_status'=>7])
-            ->where('appoint_end_time','<',$st)->get();
-//        DB::enableQueryLog();
-//        $orders = Order::leftjoin('order_patients','order_patients.order_id','=','orders.id')->where(['orders.product_type'=>4,'orders.order_status'=>7])->where('order_patients.appoint_end_time','<',$st)->get(['orders.id']);
-//        dd(DB::getQueryLog());
-        if(request('c') && !empty($orders)) return count($orders->toArray());
-        if(request('b') && !empty($orders)) dd($orders->toArray());
-        foreach ($orders as $order){
-            Order::where('id',$order->id)->update(['order_status'=>6]);
+        $type = intval(request('type'));
+        if($type == 2){
+            $orders = Order::where(['product_type'=>2,'order_status'=>6])->where('appoint_end_time','<',$st)->get();
+            foreach ($orders as $order){
+                if(strpos($order->order_notes,'取') || in_array(intval($order->payment_status),[3,4,5])){
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                    echo 'id:---'.$order->id.PHP_EOL;
+                }
+                if(intval($order->payment_status) == 0 || intval($order->payment_status) == 1){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>1]);
+                }
+                if(intval($order->payment_status) == 4){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                }
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) > 0 && $order->end_time == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>3]);
+                }
+
+                if(intval($order->payment_status) == 2  && $order->end_time > 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>4]);
+                }
+
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>2]);
+                }
+            }
+        } else if($type == 1) {
+            $orders = Order::where(['product_type'=>1,'order_status'=>6])->where('appoint_end_time','<',$st)->get();
+
+            foreach ($orders as $order){
+                if(strpos($order->order_notes,'取') || in_array(intval($order->payment_status),[3,4,5])){
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                    echo 'id:---'.$order->id.PHP_EOL;
+                }
+                if(intval($order->payment_status) == 0 || intval($order->payment_status) == 1){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>1]);
+                }
+                if(intval($order->payment_status) == 4){
+//                echo 'id:---'.$order->id.PHP_EOL;
+                    Order::where('id',intval($order->id))->update(['order_status'=>5]);
+                }
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) > 0 && $order->end_time == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>3]);
+                }
+
+                if(intval($order->payment_status) == 2  && $order->end_time > 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>4]);
+                }
+
+                if(intval($order->payment_status) == 2 && intval($order->receiving_time) == 0 ){
+                    Order::where('id',intval($order->id))->update(['order_status'=>2]);
+                }
+            }
         }
+
+
+////        DB::enableQueryLog();
+//        $orders = Order::leftjoin('order_patients','order_patients.order_id','=','orders.id')->where(['orders.product_type'=>4,'orders.order_status'=>7])->where('order_patients.appoint_end_time','<',$st)->get(['orders.id']);
+////        dd(DB::getQueryLog());
+//        if(request('c') && !empty($orders)) return count($orders->toArray());
+//        if(request('b') && !empty($orders)) dd($orders->toArray());
+//        foreach ($orders as $order){
+//            Order::where('id',$order->id)->update(['order_status'=>6]);
+//        }
     }
 
 

+ 25 - 59
app/Imports/Order/chatOrder.php

xqd xqd xqd
@@ -8,6 +8,7 @@ use App\Models\Order;
 use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
+use App\Models\UserBalanceLog;
 use App\User;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Log;
@@ -29,34 +30,7 @@ class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
 
         foreach ($collection as $row) {
             if ($row[0] == '订单编号') continue;
-            //检查是否有该订单
-            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
-            if ($isHave) continue;
 
-            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
-            if (empty($user_id)) {
-                echo $row[3] . '用户缺失' . PHP_EOL;
-                continue;
-            }
-            //患者信息
-            $patientInfo = Patient::where(['name' => $row[2]])->first();
-            if (empty($patientInfo)) {
-//                $pp = Patient::where('user_id',$user_id)->get()->toArray();
-                echo $row[2] . '患者缺失' . PHP_EOL;
-                continue;
-            }
-            $org_name = substr($row[6],18);
-            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
-            if (empty($org_id)) {
-                echo $row[6] . '机构缺失' . PHP_EOL;
-                continue;
-            }
-
-            //如果没有用户不导入该订单
-            if (empty($user_id)) {
-                Log::info('订单没有用户信息,订单编号: ' . $row[0] . PHP_EOL);
-                continue;
-            }
 
             //订单状态
             $status = Order::getStatus();
@@ -68,43 +42,35 @@ class chatOrder implements ToCollection,WithBatchInserts,WithChunkReading
             if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
 
 
-            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
-            $evaluate = $row[10] == '已评价' ? 1 : 0;
             $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
             //支付方式
             $payType = array_search($row[16], $pay_types) + 1;
             if ($payType == 1) $payType = 2;
+            $order = Order::where('order_sn',$row[0])->first();
+            if(!empty($order)){
+                $orderInfo = [
+                    'order_sn' => $row[0],
+                    'order_status' => $order_status,
+                    'order_notes' => '',
+                    'payment_status'=>$pay_status,
+                ];
+                $old_order_status = intval($order->order_status);
+                $old_notice = intval($order->order_notes);
+                if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消'  || $old_notice == '医生超时未接单自动取消') ){
+                    $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
+                    if(!empty($log)){
+                        $user = \App\Models\User::where('id',$order->user_id)->first();
+                        if($user->balance >0){
+                            User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
+                            UserBalanceLog::where('id',$log->id)->delete();
+                        }
+                    }
+                    Order::where('id',$order->id)->update($orderInfo);
+                }
+            }  else {
+                continue;
+            }
 
-            $orderInfo = [
-                'order_sn' => $row[0],
-                'patient_id' => $patientInfo->id,
-                'user_id' => $user_id,
-                'docter_id' => $docter_id,
-                'order_status' => $order_status,
-                'organization_id' => $org_id,
-                'is_evaluate' => $evaluate,
-                'is_discount' => $row[11],
-                'total_amount' => $row[12] * 100,
-                'discount_amount' => $row[13] * 100,
-                'payment_amount' => $row[15] * 100,
-                'payment_type' => $payType,
-                'payment_status' => $pay_status,
-                'product_type' => 2,
-                'created_at' => $row[19],
-            ];
-            $order = Order::create($orderInfo);
-            $orderId = $order['id'];
-
-            $orderPatient = [
-                'patient_id' => $patientInfo->id,
-                'name' => $row[0],
-                'order_id' => $orderId,
-                'patient_id' => $patientInfo->id,
-                'address' => $patientInfo->address,
-                'sex' => $patientInfo->sex,
-                'organization_id' => $org_id,
-            ];
-            OrderPatient::insert($orderPatient);
         }
         return null;
     }

+ 27 - 57
app/Imports/Order/phoneOrder.php

xqd xqd xqd
@@ -7,6 +7,7 @@ use App\Models\Order;
 use App\Models\OrderPatient;
 use App\Models\Organization;
 use App\Models\Patient;
+use App\Models\UserBalanceLog;
 use App\User;
 use Illuminate\Support\Collection;
 use Maatwebsite\Excel\Concerns\ToCollection;
@@ -21,28 +22,6 @@ class phoneOrder implements ToCollection
         foreach ($collection as $row){
             if ($row[0] == '订单编号') continue;
 
-            //检查是否有该订单
-            $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id');
-            if ($isHave) continue;
-            //支付状态(1.待付款 2.已付款 3.退款中 4.已退款 5.待退款)
-            //如果没有用户不导入该订单
-            $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id');
-            if (empty($user_id)) {
-                echo $row[3] . '用户缺失' . PHP_EOL;
-                continue;
-            }
-            //患者信息
-            $patientInfo = Patient::where(['name' => $row[2]])->first();
-            if (empty($patientInfo)) {
-                echo $row[2] . '患者缺失' . PHP_EOL;
-                continue;
-            }
-            $org_name = substr($row[6],18);
-            $org_id = $this->getValue(new Organization(), ['name' => $org_name], 'id');
-            if (empty($org_id)) {
-                echo $row[6] . '机构缺失' . PHP_EOL;
-                continue;
-            }
 
             //订单状态
             $status = Order::getStatus();
@@ -50,47 +29,38 @@ class phoneOrder implements ToCollection
             $paystatus = Order::getPayStatus();
             $pay_status = array_search($row[18], $paystatus);
             $order_status = array_search($row[9], $status);
-
-            if( $row[18] == '已退款') $pay_status = 4;
             if($row[9] == '已过期') $order_status = 6;
+            if($row[18] == '未付款' || empty($row[18])) $pay_status = 1;
+
 
-            $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id');
-            $evaluate = $row[10] == '已评价' ? 1 : 0;
             $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付'];
             //支付方式
             $payType = array_search($row[16], $pay_types) + 1;
             if ($payType == 1) $payType = 2;
-
-            $orderInfo = [
-                'order_sn' => $row[0],
-                'patient_id' => $patientInfo->id,
-                'user_id' => $user_id,
-                'docter_id' => $docter_id,
-                'order_status' => $order_status,
-                'organization_id' => $org_id,
-                'is_evaluate' => $evaluate,
-                'is_discount' => $row[11],
-                'total_amount' => intval($row[12]) * 100,
-                'discount_amount' => intval($row[13]) * 100,
-                'payment_amount' => intval($row[15]) * 100,
-                'payment_type' => $payType,
-                'payment_status' => $pay_status,
-                'product_type' => 1,
-                'created_at' => $row[19],
-            ];
-            $order = Order::create($orderInfo);
-            $orderId = $order['id'];
-
-            $orderPatient = [
-                'patient_id' => $patientInfo->id,
-                'name' => $row[2],
-                'order_id' => $orderId,
-                'patient_id' => $patientInfo->id,
-                'address' => $patientInfo->address,
-                'sex' => $patientInfo->sex,
-                'organization_id' => $org_id,
-            ];
-            OrderPatient::insert($orderPatient);
+            $order = Order::where('order_sn',$row[0])->first();
+            if(!empty($order)){
+                $orderInfo = [
+                    'order_sn' => $row[0],
+                    'order_status' => $order_status,
+                    'order_notes' => '',
+                    'payment_status'=>$pay_status,
+                ];
+                $old_order_status = intval($order->order_status);
+                $old_notice = intval($order->order_notes);
+                if($old_order_status == 5 && ($old_notice == '医生超时未接单自动取消'  || $old_notice == '医生超时未接单自动取消') ){
+                    $log = UserBalanceLog::where(['relation_id'=>$order->id])->first();
+                    if(!empty($log)){
+                        $user = \App\Models\User::where('id',$order->user_id)->first();
+                        if($user->balance >0){
+                            User::where('id',$order->user_id)->decrement('balance',$log->change_balance);
+                            UserBalanceLog::where('id',$log->id)->delete();
+                        }
+                    }
+                    Order::where('id',$order->id)->update($orderInfo);
+                }
+            }  else {
+                continue;
+            }
         }
         return null;
     }

+ 3 - 0
app/Models/OrderPack.php

xqd
@@ -20,6 +20,9 @@ class OrderPack extends BaseModel
     {
         return $this->belongsTo(Order::class);
     }
+    public function teams(){
+        return $this->hasOne(Team::class,'id','team_id');
+    }
 
     public function user()
     {