| xqd
@@ -0,0 +1,103 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Admin\Actions\backstage\Service;
|
|
|
+
|
|
|
+use App\Models\Order;
|
|
|
+use App\Models\OrderPack;
|
|
|
+use App\Models\Patient;
|
|
|
+use App\Models\ServicePack;
|
|
|
+use Encore\Admin\Actions\BatchAction;
|
|
|
+use Illuminate\Database\Eloquent\Collection;
|
|
|
+
|
|
|
+class ServiceBatchGrant extends BatchAction
|
|
|
+{
|
|
|
+ public $name = '批量发放服务包';
|
|
|
+
|
|
|
+ public function handle(Collection $collection)
|
|
|
+ {
|
|
|
+ $service_pack_id = request('id');
|
|
|
+ //拿到服务包id
|
|
|
+ $service_pack = ServicePack::where('id',$service_pack_id)->get()->toArray();
|
|
|
+ //计算有效天数
|
|
|
+ $effective_days = $service_pack[0]['effective_days'];
|
|
|
+ $start_time = time();
|
|
|
+ $str = '+'.$effective_days.'days';
|
|
|
+ $end_time = strtotime($str,$start_time);
|
|
|
+ foreach ($collection as $model) {
|
|
|
+ //获取患者是否有医保
|
|
|
+ $has_security = Patient::where('id',$model->id)->value('social_card_number');
|
|
|
+ if (!empty($has_security))
|
|
|
+ {
|
|
|
+ $is_security = 1;
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ $is_security = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入订单表
|
|
|
+ $order_arr = [
|
|
|
+ 'user_id' => $model->user_id,
|
|
|
+ 'docter_id' => 0,
|
|
|
+ 'patient_id' => $model->id,
|
|
|
+ 'organization_id' => 0,
|
|
|
+ 'order_sn' => 0,
|
|
|
+ 'pay_order_pack_id' =>0,
|
|
|
+ 'is_faster' => 0,
|
|
|
+ 'is_discount' => 0,
|
|
|
+ 'is_evaluate' => 0,
|
|
|
+ 'payment_type' => 2,
|
|
|
+ 'product_type' => 6,
|
|
|
+ 'order_status' => 3,
|
|
|
+ 'payment_status' => 2,
|
|
|
+ 'total_amount' => 0,
|
|
|
+ 'payment_amount' => 0,
|
|
|
+ 'discount_amount' => 0,
|
|
|
+ 'payment_time' => time(),
|
|
|
+ 'end_time' => 0,
|
|
|
+ 'receiving_time' => 0,
|
|
|
+ 'cancel_time' => 0,
|
|
|
+ ];
|
|
|
+ //先创建订单,再根据订单号去修改订单号
|
|
|
+ $order_id = Order::create($order_arr)->id;
|
|
|
+ $order_sn = build_sn($order_id);
|
|
|
+ Order::where('id',$order_id)->update(['order_sn'=>$order_sn]);
|
|
|
+
|
|
|
+ //创建订单服务包数据
|
|
|
+ $order_pack_arr = [
|
|
|
+ 'user_id' => $model->user_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ 'service_pack_id' => $service_pack_id,
|
|
|
+ 'pack_name' => $service_pack[0]['name'],
|
|
|
+ 'pack_intro' => $service_pack[0]['intro'],
|
|
|
+ 'pack_price' => $service_pack[0]['price'],
|
|
|
+ 'team_id' => $service_pack[0]['team_id'],
|
|
|
+ 'total_phone_minutes' => $service_pack[0]['phone_minutes'],
|
|
|
+ 'phone_minutes' => $service_pack[0]['phone_minutes'],
|
|
|
+ 'total_chat_num' => $service_pack[0]['chat_num'],
|
|
|
+ 'chat_num' => $service_pack[0]['chat_num'],
|
|
|
+ 'total_appoint_num' => $service_pack[0]['appoint_num'],
|
|
|
+ 'appoint_num' => $service_pack[0]['appoint_num'],
|
|
|
+ 'total_vaccine_limit_amount' => $service_pack[0]['vaccine_limit_amount'],
|
|
|
+ 'vaccine_limit_amount' => $service_pack[0]['vaccine_limit_amount'],
|
|
|
+ 'total_nurses_limit_amount' => $service_pack[0]['nurses_limit_amount'],
|
|
|
+ 'nurses_limit_amount' => $service_pack[0]['nurses_limit_amount'],
|
|
|
+ 'effective_days' => $effective_days,
|
|
|
+ 'start_time' => $start_time,
|
|
|
+ 'end_time' => $end_time,
|
|
|
+ 'is_security' => $is_security,
|
|
|
+ 'guardian_name' => $model->guardian_name,
|
|
|
+ 'relationship_type' => $model->relationship_type,
|
|
|
+ 'label' => $service_pack[0]['label'],
|
|
|
+ 'is_need_insurance' => $service_pack[0]['is_need_insure'],
|
|
|
+ 'expire_type' => 1,
|
|
|
+ ];
|
|
|
+ OrderPack::create($order_pack_arr);
|
|
|
+ }
|
|
|
+ return $this->response()->success('批量发放服务包成功')->refresh();
|
|
|
+ }
|
|
|
+ public function form()
|
|
|
+ {
|
|
|
+ $name = ServicePack::pluck('name','id');
|
|
|
+ $this->select('id', '服务包名称')->options($name);
|
|
|
+ }
|
|
|
+}
|