wang jun 2 years ago
parent
commit
021b2c1ea2
2 changed files with 159 additions and 0 deletions
  1. 48 0
      application/api/controller/Courier.php
  2. 111 0
      application/api/logic/CourierLogic.php

+ 48 - 0
application/api/controller/Courier.php

@@ -0,0 +1,48 @@
+<?php
+namespace app\api\controller;
+
+use app\api\logic\CourierLogic;
+
+/**
+ * 配送员
+ *
+ * @author wj
+ * @date 2022-12-09
+ */
+class Courier
+{
+    /**
+     * 获取订单列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-09
+     */
+    public function geiorderlist()
+    {
+        $post = request()->post();
+        $l_d = new CourierLogic();
+        $result = $l_d->geiorderlist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 改送货状态
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-09
+     */
+    public function updatestatusdelivery()
+    {
+        $post = request()->post();
+        $l_d = new CourierLogic();
+        $result = $l_d->updatestatusdelivery($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+}

+ 111 - 0
application/api/logic/CourierLogic.php

@@ -0,0 +1,111 @@
+<?php
+namespace app\api\logic;
+
+use app\common\model\CourierModel;
+use app\common\model\MealModel;
+use app\common\model\MealOrdersModel;
+
+/**
+ * 配送员
+ *
+ * @author wj
+ * @date 2022-12-09
+ */
+class CourierLogic
+{
+    /**
+     * 获取订单信息
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-09
+     */
+    public function geiorderlist($arr)
+    {
+        $fillfields = ['courierid'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $cid = $arr['courierid'];
+        $where = ['status' => 1];
+        if (isset($arr['status_delivery']) && is_numeric($arr['status_delivery'])) {
+            $where['status_delivery'] = $arr['status_delivery'];
+        }
+        $m_mo = new MealOrdersModel();
+        $m_c = new CourierModel();
+        $m_m = new MealModel();
+
+        $cinfo = $m_c->getInfo(['id' => $cid]);
+        if (empty($cinfo)) {
+            return backarr(0, "配送员不存在");
+        }
+        $where['center_id'] = $cinfo['center_id'];
+        $count = $m_mo->getList($where, 'count');
+        if (empty($count)) {
+            return backarr(0, "无数据");
+        }
+        $page = isset($arr['page']) && is_numeric($arr['page']) && !empty($arr['page']) && $arr['page'] > 0 ? $arr['page'] : 1;
+        $size = isset($arr['size']) && is_numeric($arr['size']) && !empty($arr['size']) && $arr['size'] > 0 ? $arr['size'] : 10;
+        //订单编号 套餐名 套餐数量 地址 电话 收件人 备注 送货状态
+        $field = [
+            'id', 'center_id', 'meal_id'
+            , 'orderno', 'quantity', 'createtime', 'remark'
+            , 'user_id', 'status_delivery'
+            , 'receiver_address', 'receiver_username', 'receiver_phone', 'receiver_gcj_lat', 'receiver_gcj_long'];
+        $list = $m_mo->getList($where, $field, $page, $size);
+        foreach ($list as $key => $value) {
+            $minfo = $m_m->getInfo(['id' => $value['meal_id']], ['name_meal']);
+            $value['name_meal'] = '';
+            if (empty($minfo)) {
+                $value['name_meal'] = $minfo['name_meal'];
+            }
+            $list[$key] = $value;
+        }
+        return backarr(1, "查询成功", $list);
+    }
+    /**
+     * 改配送状态
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-09
+     */
+    public function updatestatusdelivery($arr)
+    {
+        $fillfields = ['orderid', 'courierid', 'status_delivery'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $cid = $arr['courierid'];
+        $orderid = $arr['orderid'];
+        $status_delivery = $arr['status_delivery'];
+        $m_c = new CourierModel();
+        $m_mo = new MealOrdersModel();
+        $cinfo = $m_c->getInfo(['id' => $cid]);
+        if (empty($cinfo)) {
+            return backarr(0, "配送员不存在");
+        }
+        $centerid = $cinfo['center_id'];
+        $where = ['id' => $orderid, 'status' => 1, 'center_id' => $centerid];
+        $moinfo = $m_mo->getInfo($where);
+        if (empty($moinfo)) {
+            return backarr(0, "订单不存在");
+        }
+        if (0 == $moinfo['status_delivery']) {
+            $updateData = [
+                'status_delivery' => 2,
+                'deliverytime' => date('Y-m-d H:i:s'),
+            ];
+            $row = $m_mo->updateinfo(['id' => $orderid], $updateData);
+            if (empty($row)) {
+                return backarr(0, "订单配送状态修改失败");
+            }
+        }
+        return backarr(200, "订单配送状态修改成功", ['moid' => $orderid]);
+    }
+
+}