wang jun 2 éve
szülő
commit
d9eb3c3dc9

+ 7 - 0
application/app/controller/Appointment.php

@@ -61,6 +61,13 @@ class Appointment extends BaseController
     {
         $l_a = new appointmentlogic();
         $list = $l_a->gettesttypelist();
+        foreach ($list as $key => $value) {
+            $item = [
+                'key' => $key,
+                'value' => $value,
+            ];
+            $list[$key] = $item;
+        }
         return backjson2(200, 'success', $list);
     }
 

+ 4 - 3
application/app/logic/appointmentlogic.php

@@ -106,12 +106,13 @@ class appointmentlogic extends baselogic
         try {
             $tinsertData = [
                 'openid' => $ainfo['openid'],
-                'name' => $ainfo['openid'],
-                'telno' => $ainfo['openid'],
-                'sfzid' => $ainfo['openid'],
+                'name' => $ainfo['name'],
+                'telno' => $ainfo['telno'],
+                'sfzid' => $ainfo['sfzid'],
                 'testtubeno' => $testtubeno,
                 'code' => $ainfo['code'],
                 'appointment_id' => $ainfo['id'],
+                'test_type' => $testtype,
             ];
             $tid = $m_t->insertData($tinsertData);
             if (empty($tid)) {

+ 1 - 1
application/app/logic/baselogic.php

@@ -38,7 +38,7 @@ class baselogic
                     $title = $value['title'];
                     //必填
                     if (isset($value['require']) && $value['require']) {
-                        if (!isset($param[$name]) || empty($param[$name])) {
+                        if (!isset($param[$name])) {
                             throw new \Exception($title . '未填');
                         }
                     }

+ 19 - 0
application/common/model/payordermodel.php

@@ -105,4 +105,23 @@ class payordermodel extends Model
         $row = $this->where($where)->update($updateData);
         return $row ? $row : false;
     }
+
+    /**
+     * 修改状态为0的订单状态
+     *
+     * @param  [type] $orderno
+     * @param  [type] $openid
+     * @param  [type] $updarr
+     * @return void
+     * @author wj
+     * @date 2022-07-29
+     */
+    public function updorederstatusbyorderno($orderno, $openid, $updarr)
+    {
+        $where_arr['outorderno'] = $orderno;
+        $where_arr['openid'] = $openid;
+        $where_arr['orderstatus'] = 0;
+        $rcount = $this->where($where_arr)->update($updarr);
+        return $rcount ? $rcount : false;
+    }
 }

+ 16 - 1
application/index/controller/Appointment.php

@@ -76,7 +76,7 @@ class Appointment extends Base
         return backjson(200, $returnData);
     }
     /**
-     * 支付回调
+     * 后端支付回调
      *
      * @return void
      * @author wj
@@ -107,4 +107,19 @@ class Appointment extends Base
         $l_wechat = new wechatlogic();
         $l_wechat->paybackxml($reurnData);
     }
+    /**
+     * 前端支付回调
+     */
+    public function pay_call_back_front()
+    {
+        $param = request()->post();
+        $l_p = new paylogic();
+        $result = $l_p->handlefrontorder($param);
+        if (empty($result['status'])) {
+            return backjson(0, $result['msg']);
+        }
+        $returnData = $result['data'];
+        return backjson(200, $returnData);
+    }
+
 }

+ 1 - 1
application/index/logic/baselogic.php

@@ -38,7 +38,7 @@ class baselogic
                     $title = $value['title'];
                     //必填
                     if (isset($value['require']) && $value['require']) {
-                        if (!isset($param[$name]) || empty($param[$name])) {
+                        if (!isset($param[$name])) {
                             throw new \Exception($title . '未填');
                         }
                     }

+ 87 - 18
application/index/logic/paylogic.php

@@ -23,9 +23,15 @@ class paylogic extends baselogic
     {
         $list = [
             'getappointmentorderforxcx' => [
-                ['name' => 'aid', 'title' => '申请单id', 'require' => true, 'type' => 'numeric'], //以元为单位
+                ['name' => 'aid', 'title' => '申请单id', 'require' => true, 'type' => 'numeric'],
                 ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
-                ['name' => 'total_fee', 'title' => '支付费用', 'require' => true, 'type' => 'numeric'], //以元为单位
+                ['name' => 'total_fee', 'title' => '支付费用', 'require' => true, 'type' => 'numeric'], //以分为单位
+            ],
+            'handlefrontorder' => [
+                ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
+                ['name' => 'orderstatus', 'title' => '订单状态', 'require' => true, 'type' => 'numeric'],
+                ['name' => 'outorderno', 'title' => '商户订单号', 'require' => true, 'type' => 'numeric'],
+                ['name' => 'ispay', 'title' => '已支付', 'require' => true, 'type' => 'numeric'],
             ],
         ];
         return $list;
@@ -74,7 +80,7 @@ class paylogic extends baselogic
         return backarr(1, "success", $orderinfo);
     }
     /**
-     * 处理支付回调
+     * 处理后端支付回调
      *
      * @return void
      * @author wj
@@ -127,22 +133,58 @@ class paylogic extends baselogic
             switch ($ordertype) {
                 case 1:
                     $appointentid = $orderInfo['appointent_id'];
-                    $m_a = new appointmentmodel();
-                    $ainfo = $m_a->getInfo(['id' => $appointentid, 'ispay' => 0]);
-                    if (empty($ainfo)) {
-                        $msg = "申请单id:[" . $appointentid . "]不存在";
-                        throw new \Exception($msg);
+                    if (1 === $ispay) {
+                        $this->updateappointment($appointentid, $outorderno);
                     }
-                    $code = $appointentid . "|" . date("YmdHis");
-                    $aupdateData = [
-                        'ispay' => 1,
-                        'payorderno' => $outorderno,
-                        'code' => $code,
-                    ];
-                    $row = $ainfo->updateinfo(['id' => $appointentid], $aupdateData);
-                    if (empty($row)) {
-                        $msg = "申请单id:[" . $appointentid . "]修改失败";
-                        throw new \Exception($msg);
+                    break;
+            }
+            Db::commit();
+            Log::info("commit");
+            return backarr(1, "处理完成", ['id' => $orderInfo['id']]);
+        } catch (\Exception $e) {
+            Db::rollback();
+            log::info("rollback");
+            return backarr(0, $e->getMessage());
+        }
+    }
+    /**
+     * 处理前端支付回调
+     *
+     * @return void
+     * @author wj
+     * @date 2022-07-29
+     */
+    public function handlefrontorder($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $data = $result['data'];
+        $openid = $data['openid'];
+        $ispay = $data['ispay'];
+        $orderstatus = $data['orderstatus'];
+        $outorderno = $data['outorderno'];
+        Db::startTrans();
+        try {
+            $m_po = new payordermodel;
+            $oupdateData = [
+                'ispay' => $ispay,
+                'orderstatus' => $orderstatus,
+                'paytime' => date('Y-m-d H:i:s'),
+                'is_front_back' => 1,
+            ];
+            $row = $m_po->updorederstatusbyorderno($outorderno, $openid, $oupdateData);
+            if (empty($row)) {
+                throw new \Exception("订单修改失败");
+            }
+            $orderInfo = $m_po->getorderinfobyoutorderno($outorderno);
+            $ordertype = $orderInfo['order_type'];
+            switch ($ordertype) {
+                case 1:
+                    $appointentid = $orderInfo['appointent_id'];
+                    if (1 === $ispay) {
+                        $this->updateappointment($appointentid, $outorderno);
                     }
                     break;
             }
@@ -155,4 +197,31 @@ class paylogic extends baselogic
             return backarr(0, $e->getMessage());
         }
     }
+    /**
+     * 改申请单
+     *
+     * @return void
+     * @author wj
+     * @date 2022-07-29
+     */
+    private function updateappointment($appointentid, $outorderno)
+    {
+        $m_a = new appointmentmodel();
+        $ainfo = $m_a->getInfo(['id' => $appointentid, 'ispay' => 0]);
+        if (empty($ainfo)) {
+            $msg = "申请单id:[" . $appointentid . "]不存在";
+            throw new \Exception($msg);
+        }
+        $code = $appointentid . "|" . date("YmdHis");
+        $aupdateData = [
+            'ispay' => 1,
+            'payorderno' => $outorderno,
+            'code' => $code,
+        ];
+        $row = $ainfo->updateinfo(['id' => $appointentid], $aupdateData);
+        if (empty($row)) {
+            $msg = "申请单id:[" . $appointentid . "]修改失败";
+            throw new \Exception($msg);
+        }
+    }
 }