zgg 1 day ago
parent
commit
fad07c7eea

+ 49 - 3
application/admin/controller/PhOrders.php

@@ -2,9 +2,10 @@
 namespace app\admin\controller;
 
 use app\hander\HelpHander;
-use think\App;
+use PhpOffice\PhpWord\Shared\Html;
 use think\Db;
-use think\Exception;
+use PhpOffice\PhpWord\PhpWord;
+use PhpOffice\PhpWord\IOFactory;
 
 class PhOrders extends Auth
 {
@@ -262,7 +263,7 @@ class PhOrders extends Auth
                 HelpHander::error('输入金额错误');
             }
 
-            $res = model('PhOrderPay')->addSaveDispatch($this->orgId,$id,$money,$remark,$busType);
+            $res = model('PhOrderPay')->addSaveDispatch($this->orgId,$this->userId,$id,$money,$remark,$busType);
             if($res){
                 $this->success('操作成功',url('index'));
             }else{
@@ -877,4 +878,49 @@ class PhOrders extends Auth
 
     }
 
+
+    public function exportWord()
+    {
+        $id = input('id',0);
+        $orders = Db::name('ph_orders')
+            ->where('id',$id)
+            ->field('sign,sn')
+            ->find();
+        $todos = Db::name('ph_todo')
+            ->where('order_id',$id)
+            ->whereIn('status',[1,2])
+            ->column('sign');
+        $protocol = Db::name("ph_protocol")->where('org_id',$this->orgId)->value('content');
+        $phpWord = new PhpWord();
+        $section = $phpWord->addSection();
+        Html::addHtml($section, $protocol);
+        $section->addText('客户签名:', ['name' => 'Arial', 'size' => 26, 'bold' => true]);
+        if ($orders['sign']){
+            $section->addImage($orders['sign'], ['width' => 120, 'height' => 110]);
+        }
+        $section->addText('护工签名:', ['name' => 'Arial', 'size' => 26, 'bold' => true]);
+        $table = $section->addTable();
+        $length = count($todos) > 4 ? ceil(count($todos) / 4) : 1;
+        for ($i = 0; $i < $length; $i++) {
+            $table->addRow(1, 4); // 添加1行4列
+            $imgs = array_slice($todos, $i * 4, 4);
+            foreach ($imgs as $index => $v2) {
+                if ($v2 != '') {
+                    $cell = $table->addCell(1000); // 单元格宽度,单位为EMU
+                    $cell->addImage($v2, [
+                        'width' => 120,
+                        'height' => 110
+                    ]);
+                }
+            }
+        }
+        $objWriter = IOFactory::createWriter($phpWord, 'Word2007');
+        $fileName = '陪护协议-'.$orders['sn'].'.docx';
+        header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
+        header('Content-Disposition: attachment;filename="'.$fileName);
+        header('Cache-Control: max-age=0');
+        $objWriter->save('php://output');
+        exit;
+    }
+
 }

+ 7 - 4
application/admin/controller/PhStatistics.php

@@ -82,10 +82,13 @@ class PhStatistics extends Auth
                 $lists[$k]['contact'] = $order?$order['name']:'';
                 $lists[$k]['phone'] = $order?$order['phone']:'';
                 $lists[$k]['pay_text'] = $v['type'] == 1 ?  "线下" : '线上';
-                $lists[$k]['name'] = Db::name('user')
-                    ->where('id',$v['user_id'])
-                    ->value('real_name');
-
+                if ($v['user_id'] == 0){
+                    $lists[$k]['name'] = '客户';
+                }else{
+                    $lists[$k]['name'] = Db::name('user')
+                        ->where('id',$v['user_id'])
+                        ->value('real_name');
+                }
                 if ($v['mode'] == 0) {
                     $lists[$k]['modeName'] ='预收金';
                 }elseif ($v['mode'] == 1){

+ 41 - 4
application/admin/view/ph_orders/detail.html

@@ -90,7 +90,7 @@
                     <tr>
                         <td class="table-left">服务费</td>
                         <td>{$info.service_money}</td>
-                        <td class="table-left">签名图片</td>
+                        <td class="table-left">客户签名</td>
                         <td>
                             {if condition="$info['sign']"}
                             <img src="{$info['sign']}" onclick="open_img(this)" style="width: 80px;height: auto" alt="">
@@ -114,6 +114,7 @@
                             {eq name="info['status']" value="1"}
                             <a href="javascript:;" url="{:url('PhOrders/finish',['id'=>$info['id']])}" data-title="完成" onclick="layer_open(this,2)" class="btn btn-sm btn-success">完成</a>
                             {/eq}
+                            <a href="javascript:;" data-url="{:url('exportWord')}" onclick="exportWord(this,'{$info.id}')" class="btn btn-sm btn-info">导出协议</a>
                         </td>
                     </tr>
                 </table>
@@ -160,7 +161,7 @@
                     {/volist}
                     {empty name="info['todo']"}
                     <tr>
-                        <td colspan="9" class="text-center">暂无数据</td>
+                        <td colspan="10" class="text-center">暂无数据</td>
                     </tr>
                     {/empty}
                 </table>
@@ -175,6 +176,7 @@
                         <th>支付类型</th>
                         <th>支付时间</th>
                         <th>备注</th>
+                        <th>操作人</th>
                         {if condition="$info['status'] eq 0 or $info['status'] eq 1"}
                         <th>操作</th>
                         {/if}
@@ -190,6 +192,7 @@
                         </td>
                         <td>{$v.pay_time}</td>
                         <td>{$v.remark}</td>
+                        <td>{$v.name}</td>
                         {if in_array($info.status,[0,1,2])}
                         <td>
                             <a href="javascript:;" url="{:url('PhOrders/refund',['id'=>$v['id']])}" data-title="退款" onclick="layer_open(this,2)" class="btn btn-xs btn-danger">退款</a>
@@ -214,6 +217,7 @@
                         <th>支付类型</th>
                         <th>支付时间</th>
                         <th>备注</th>
+                        <th>操作人</th>
                         {if condition="$info['status'] eq 0 or $info['status'] eq 1"}
                         <th>操作</th>
                         {/if}
@@ -229,6 +233,7 @@
                         </td>
                         <td>{$v.pay_time}</td>
                         <td>{$v.remark}</td>
+                        <td>{$v.name}</td>
                         {if in_array($info.status,[0,1,2])}
                         <td>
                             <a href="javascript:;" url="{:url('PhOrders/refund',['id'=>$v['id']])}" data-title="退款" onclick="layer_open(this,2)" class="btn btn-xs btn-danger">退款</a>
@@ -242,10 +247,36 @@
                     </tr>
                     {/empty}
                 </table>
-
+                {notempty name="info['refunds2']"}
+                <p><br></p>
+                <h3>服务费退款记录</h3>
+                <table class="table table-bordered table-striped">
+                    <tr>
+                        <th>退款单号</th>
+                        <th>金额</th>
+                        <th>类型</th>
+                        <th>时间</th>
+                        <th>备注</th>
+                        <th>操作人</th>
+                    </tr>
+                    {volist name="info['refunds2']" id="v"}
+                    <tr>
+                        <td>{$v.sn}</td>
+                        <td>{$v.money}</td>
+                        <td>
+                            {eq name="v['type']" value="1"}<span>线下</span>{/eq}
+                            {eq name="v['type']" value="2"}<span>线上</span>{/eq}
+                        </td>
+                        <td>{$v.create_time}</td>
+                        <td>{$v.remark}</td>
+                        <td>{$v.name}</td>
+                    </tr>
+                    {/volist}
+                </table>
+                {/notempty}
                 {notempty name="info['refunds']"}
                 <p><br></p>
-                <h3>退款记录</h3>
+                <h3>预收金退款记录</h3>
                 <table class="table table-bordered table-striped">
                     <tr>
                         <th>退款单号</th>
@@ -253,6 +284,7 @@
                         <th>类型</th>
                         <th>时间</th>
                         <th>备注</th>
+                        <th>操作人</th>
                     </tr>
                     {volist name="info['refunds']" id="v"}
                     <tr>
@@ -264,6 +296,7 @@
                         </td>
                         <td>{$v.create_time}</td>
                         <td>{$v.remark}</td>
+                        <td>{$v.name}</td>
                     </tr>
                     {/volist}
                 </table>
@@ -284,5 +317,9 @@
         trigger: 'click',
         theme: '#2e6da4'
     });
+    function exportWord(_self,id){
+        var url = $(_self).attr('data-url');
+        window.location.href = url+'?id='+id;
+    }
 </script>
 {/block}

+ 30 - 1
application/api/controller/h5/Common.php

@@ -39,10 +39,39 @@ class Common extends Base {
     }
 
     public function phprotocol() {
+        $id = input('orderId',0);
+        $str = '';
+        if ($id > 0){
+            $sign = Db::name('ph_orders')->where('id', $id)->value('sign');
+            $str = '
+            <p style="font-family:Calibri;margin-top: 50px">
+                <span style="font-family:宋体;font-size:28px;">客户签名:</span>
+            </p>
+            <p style="font-family:Calibri;">
+                <img height="150" width="130" src="' . $sign . '" alt="" />
+            </p>
+            <p style="font-family:Calibri;margin-top: 10px">
+                <span style="font-family:宋体;font-size:28px;">护工签名:</span>
+            </p>
+            <p style="font-family:Calibri;margin-bottom: 80px">
+            ';
+            $todos = Db::name('ph_todo')
+                ->where('order_id',$id)
+                ->whereIn('status',[1,2])
+                ->column('sign');
+            foreach ($todos as $k => $v){
+                if ($v){
+                    $str .= ' 
+                    <img height="130" width="120" src="' . $v . '" alt="" />
+                    ';
+                }
+            }
+            $str .= '</p>';
+        }
         $info = Db::name("ph_protocol")->where('org_id',$this->orgId)->find();
         if (!$info) {
             HelpHander::success(['content'=>""]);
         }
-        HelpHander::success(['content' => $info['content']]);
+        HelpHander::success(['content' => $info['content'].$str]);
     }
 }

+ 2 - 2
application/api/controller/h5/Worker.php

@@ -39,9 +39,9 @@ class Worker extends Base
             ->where('','exp',Db::raw("FIND_IN_SET($depId,dep)"))
             ->column('user');
         if (!empty($ids)) {
-            send_jpush($ids,AppMsg::PUSH_WORKER_ORDER_SEND,'有一个新的陪护订单,请注意查看',['id'=>$res]);
+            send_jpush($ids,AppMsg::PUSH_WORKER_ORDER_SEND,'有一个新的陪护订单,请注意查看',['id'=>$res['orderId']]);
         }
-        HelpHander::success(['payId'=>$res],'操作成功');
+        HelpHander::success(['payId'=>$res['payId'],'orderId'=>$res['orderId']],'操作成功');
     }
 
     public function userInfo(){

+ 1 - 1
application/api/controller/v1/PhOrders.php

@@ -120,7 +120,7 @@ class PhOrders extends Base
             HelpHander::error('输入金额错误');
         }
 
-        $res = model('PhOrderPay')->addSaveDispatch($this->orgId,$id,$money,$remark,$busType);
+        $res = model('PhOrderPay')->addSaveDispatch($this->orgId,$this->userId,$money,$remark,$busType);
         if($res){
             HelpHander::success([],'操作成功');
         }else{

+ 3 - 2
application/common/model/PhOrderPay.php

@@ -103,7 +103,7 @@ class PhOrderPay extends Base
     }
 
     // 调度生成支付单
-    public function addSaveDispatch($orgId,$orderId,$money,$remark='',$busType=0){
+    public function addSaveDispatch($orgId,$userId,$orderId,$money,$remark='',$busType=0){
         $data = [
             'sn' => get_unique_id('PH'),
             'order_id' => $orderId,
@@ -114,7 +114,8 @@ class PhOrderPay extends Base
             'create_time' => date('Y-m-d H:i:s'),
             'pay_time' => date('Y-m-d H:i:s'),
             'remark' => $remark,
-            'bus_type' => $busType
+            'bus_type' => $busType,
+            'user_id'=>$userId
         ];
 
         Db::startTrans();

+ 42 - 7
application/common/model/PhOrders.php

@@ -101,7 +101,7 @@ class PhOrders extends Base
             $this->sendSmsDispatch($data['name'],$data['phone'],$data['org_id'],$orderId);
         }
 
-        return $payId;
+        return ['payId'=>$payId,'orderId'=>$orderId];
     }
 
     // Base64字符串转文件
@@ -396,10 +396,10 @@ class PhOrders extends Base
             'amount' => input('amount/f',0)
         ];
 
-        if($data['amount'] <= 0){
-            $this->error = '收费金额不能小于0';
-            return false;
-        }
+//        if($data['amount'] <= 0){
+//            $this->error = '收费金额不能小于0';
+//            return false;
+//        }
         if(!$data['end']){
             $this->error = '未选择服务结束日期';
             return false;
@@ -666,9 +666,12 @@ class PhOrders extends Base
                 $user_id = Db::name('worker')
                     ->where('id',$v['worker_id'])
                     ->value('user_id');
-                $todos[$k]['worker_name'] =  Db::name('user')
+                $user = Db::name('user')
                     ->where('id',$user_id)
-                    ->value('real_name');
+                    ->field('real_name,mobile')
+                    ->find();
+                $todos[$k]['worker_name'] = $user['real_name'] ?? '';
+                $todos[$k]['phone'] = $user['mobile'] ?? '';
                 $todos[$k]['end'] = $v['end']? $v['end']:"";
 
             }
@@ -677,11 +680,27 @@ class PhOrders extends Base
             // 获取缴费记录-预收款
             $pays = Db::name('ph_order_pay')->where('status',1)->where('bus_type',0)->where('order_id',$id)->select();
             $pays = $pays?$pays:[];
+            if (!empty($pays)){
+                $userIds = array_column($pays,'user_id');
+                $users = Db::name('user')->whereIn('id',$userIds)->column('real_name','id');
+                foreach ($pays as &$pay){
+                    $pay['name'] = $users[$pay['user_id']] ?? '客户';
+                }
+                unset($pay);
+            }
             $info['pays'] = $pays;
 
             // 获取缴费记录-服务费
             $pays = Db::name('ph_order_pay')->where('status',1)->where('bus_type',1)->where('order_id',$id)->select();
             $pays = $pays?$pays:[];
+            if (!empty($pays)){
+                $userIds = array_column($pays,'user_id');
+                $users = Db::name('user')->whereIn('id',$userIds)->column('real_name','id');
+                foreach ($pays as &$pay){
+                    $pay['name'] = $users[$pay['user_id']] ?? '客户';
+                }
+                unset($pay);
+            }
             $info['pays2'] = $pays;
             $info['serviceFee'] = empty($pays)?0:1;
 
@@ -695,6 +714,14 @@ class PhOrders extends Base
                 ->field('a.*')
                 ->select();
             $refunds = $refunds?$refunds:[];
+            if (!empty($refunds)){
+                $userIds = array_column($refunds,'user_id');
+                $users = Db::name('user')->whereIn('id',$userIds)->column('real_name','id');
+                foreach ($refunds as &$refund){
+                    $refund['name'] = $users[$refund['user_id']] ?? '客户';
+                }
+                unset($refund);
+            }
             $info['refunds'] = $refunds;
 
             // 获取服务费退款记录
@@ -707,6 +734,14 @@ class PhOrders extends Base
                 ->field('a.*')
                 ->select();
             $refunds2 = $refunds2?$refunds2:[];
+            if (!empty($refunds2)){
+                $userIds = array_column($refunds2,'user_id');
+                $users = Db::name('user')->whereIn('id',$userIds)->column('real_name','id');
+                foreach ($refunds2 as &$refund2){
+                    $refund2['name'] = $users[$refund2['user_id']] ?? '客户';
+                }
+                unset($refund2);
+            }
             $info['refunds2'] = $refunds2;
 
             //固定服务费金额