소스 검색

0728-1313-h01

Zory 1 주 전
부모
커밋
e97146e2dc

+ 1 - 2
app/command/ExpressOrder.php

@@ -28,13 +28,12 @@ class ExpressOrder extends Command
                     $nextPage = null;
                     return true;
                 }
-                $orderMode = (new SaasOrder);
+//                $orderMode = (new SaasOrder);
                 foreach ($resp as $item) {
                     [$state,$expressData] = $this->getExpressData($item['express_sn'],$item['mobile']);
                     if ($state && $item['orders']['is_error'] == 0) {
                         if (in_array($expressData['logisticsStatusDesc'],['派件中',"已签收"])) { // 核销订单
                             $output->writeln("订单进入核销=={$item['order_sn']}=={$item['express_sn']}==".getDateFull());
-                            $orderMode->where("order_sn",$item['order_sn'])->update(['express_status' => 2]);
                             (new SaasOrderExpress)->where("id",$item['id'])->update(['status' => 1,'last_at' => getDateFull(),'last_msg' => $expressData['theLastMessage'],'content' => json_encode($expressData['logisticsTraceDetailList'])]);
                             Redis::send("order-done",['order' => $item['order_sn']]);
                         } else {

+ 49 - 0
app/command/SyncPlan.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\command;
+
+use app\extra\dyMini\PlanLive;
+use app\model\saas\SaasLivePlan;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class SyncPlan extends Command
+{
+
+    protected static string $defaultName = 'sync:plan';
+    protected static string $defaultDescription = '查询定向佣金计划带货汇总数据';
+
+    protected function execute(InputInterface $input, OutputInterface $output): int
+    {
+        try {
+
+            $output->writeln("开始更新快递信息====>" . getDateFull());
+            $nextPage = 1;
+            while (is_numeric($nextPage)) {
+                $resp = (new SaasLivePlan)->where(["status" => 1])->page($nextPage, 10)->select();
+                if ($resp->isEmpty()) {
+                    $output->writeln("没有任务啦==".getDateFull());
+                    $nextPage = null;
+                    return true;
+                }
+                foreach ($resp as $item) {
+                    $output->writeln("计划ID=={$item['plan_id']}==".getDateFull());
+                    $planData = (new PlanLive)->config([
+                        "appid"     => sConf("wechat.mini_appid"),
+                        "secret"    => sConf("wechat.mini_secret"),
+                    ])->token()->getPlanData([intval($item['plan_id'])]);
+                    print_r($planData);
+                }
+                $nextPage = $nextPage+1;
+                $output->writeln("进入下一页=={$nextPage}==".getDateFull());
+            }
+        } catch (\Throwable $throwable) {
+            echo getDateFull()."===查询计划数据报错\n";
+            echo $throwable->getFile()."\n";
+            echo $throwable->getLine()."\n";
+        }
+        return self::SUCCESS;
+    }
+
+}

+ 7 - 1
app/controller/admin/Order.php

@@ -4,6 +4,7 @@ namespace app\controller\admin;
 
 use app\extra\basic\Base;
 use app\middleware\AuthMiddleware;
+use app\model\saas\SaasOrderItem;
 use app\service\saas\GoodsService;
 use app\service\saas\OrderService;
 use DI\Attribute\Inject;
@@ -42,8 +43,13 @@ class Order extends Base
                 $query->field("openid,nickname,avatar");
             },'poi' => function($query){
                 $query->field("poi_id,poi_name,poi_address,nick_name");
-            }],true,['end_time'],["end_time" => function ($resp,$next) {
+            }],true,['end_time','refund_num'],["end_time" => function ($resp,$next) {
                 return timeDiff(strtotime("+30 minutes",strtotime($next['create_at'])),time());
+            },'refund_num' => function($resp,$next){
+                if ($next['status'] == 6) {
+                    return (new SaasOrderItem)->where(['order_sn' => $next['order_sn'],'status' => 2])->count()??0;
+                }
+                return 0;
             }]);
             return successTrans("success.data",pageFormat($data),200);
         } catch (\Throwable $throwable) {

+ 6 - 6
app/controller/api/Notify.php

@@ -95,12 +95,6 @@ class Notify extends Base
             if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
             $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
             if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
-            if (!empty($data['refund_item_detail']['item_order_detail']))
-            {
-                foreach ($data['refund_item_detail']['item_order_detail'] as $val) {
-                    (new SaasOrderItem)->where("item_order_id",$val['item_order_id'])->update(['status' => 2]);
-                }
-            }
             $itemNum = (new SaasOrderItem)->where(["order_sn" => $order['order_sn'],'status' => 2])->count();
             $trueNum = count($data['refund_item_detail']['item_order_detail']);
             if (($trueNum+$itemNum) <> $order['number']) { // 部分退款
@@ -108,6 +102,12 @@ class Notify extends Base
             } else { // 全部退款
                 $order->status = 3;
             }
+            if (!empty($data['refund_item_detail']['item_order_detail']))
+            {
+                foreach ($data['refund_item_detail']['item_order_detail'] as $val) {
+                    (new SaasOrderItem)->where("item_order_id",$val['item_order_id'])->update(['status' => 2]);
+                }
+            }
             $order->refund_at = getDateFull();
             $order->save();
             return json(['err_no' => 0,'err_tips' => "success"]);

+ 1 - 0
app/controller/api/Solution.php

@@ -111,6 +111,7 @@ class Solution extends Base
                         $itemData = [];
                         foreach ($msgData['item_order_info_list'] as $key=>$val) {
                             $itemData[$key] = [
+                                "poi_id"        => $goods['poi_id'],
                                 "order_sn"      => $msgData['order_id'],
                                 "item_order_id" => $val['item_order_id'],
                                 "price"         => $val['price']

+ 57 - 0
app/controller/merchant/Dashboard.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace app\controller\merchant;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasOrder;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use support\Request;
+
+/**
+ * 统计
+ */
+#[Controller("/api/merchant/dashboard"),Middleware(AuthMiddleware::class)]
+class Dashboard extends Base
+{
+
+
+    #[GetMapping('list')]
+    public function getData(Request $request)
+    {
+        try {
+            $data = $moneys = $orders = [];
+            $shopId = $request->user['store_id'];
+            $mode = (new SaasOrder);
+            $data = [
+                "userNum"   => $mode->whereDay("create_at")->where("poi_id",$shopId)->where('status','in',[1,3])->sum("money"), // 今日营业额
+                "rechargeNum"   => $mode->whereDay("create_at")->where("poi_id",$shopId)->where('status','in',[1,3])->count(), // 今日订单数
+                "rechargeMoney"   => $mode->whereDay("create_at")->where("poi_id",$shopId)->where('status',1)->count(), // 手机自助打印待处理
+            ];
+            $fields = ['ROUND(sum(money)/100,2)' => 'total','substr(create_at,1,10)' => 'mday'];
+            $orderMoney = $mode->field($fields)->where("poi_id",$shopId)->where('status','in',[1,3])->whereTime('create_at', '-15 days')->group('mday')->select()->column(null, 'mday');
+            for ($i = 15; $i >= 0; $i--) {
+                $date = date('Y-m-d', strtotime("-{$i}days"));
+                $moneys[] = [
+                    '当天日期' => date('Y-m-d', strtotime("-{$i}days")),
+                    '订单金额' => ($orderMoney[$date] ?? [])['total'] ?? 0,
+                ];
+            }
+            $field = ['count(1)' => 'count', 'substr(create_at,1,10)' => 'mday'];
+            $orderNum = $mode->field($field)->where("poi_id",$shopId)->where('status','in',[1,3])->whereTime('create_at', '-15 days')->group('mday')->select()->column(null, 'mday');
+            for ($i = 15; $i >= 0; $i--) {
+                $date = date('Y-m-d', strtotime("-{$i}days"));
+                $orders[] = [
+                    '当天日期' => date('Y-m-d', strtotime("-{$i}days")),
+                    '订单数量' => ($orderNum[$date] ?? [])['count'] ?? 0,
+                ];
+            }
+            return success("ok",compact("data","orders","moneys"));
+        } catch (\Throwable $throwable) {
+
+        }
+    }
+
+}

+ 3 - 2
app/controller/merchant/Goods.php

@@ -275,9 +275,10 @@ class Goods extends Base
             $detail = $this->model->where("id",$param["id"])->findOrEmpty();
             if ($detail->isEmpty()) return errorTrans("empty.data");
             if ($detail['poi_id'] <> $request->user['store_id']) return error("非法操作");
-            $state = $detail->delete();
+            $detail->status = 3;
+            $state = $detail->save();
             if (!$state) return errorTrans("error.data");
-            (new SaasOrder)->where("product_id",$detail["product_id"])->delete();
+//            (new SaasOrder)->where("product_id",$detail["product_id"])->delete();
             return successTrans("success.data");
         } catch (\Throwable $throwable) {
             return error($throwable->getMessage());

+ 1 - 1
app/controller/merchant/Order.php

@@ -56,7 +56,7 @@ class Order extends Base
                 return timeDiff(strtotime("+30 minutes",strtotime($next['create_at'])),time());
             },'refund_num' => function($resp,$next){
                 if ($next['status'] == 6) {
-                    return (new SaasOrderItem)->where(['order_sn' => $next['order_sn'],'status' => 2])->count();
+                    return (new SaasOrderItem)->where(['order_sn' => $next['order_sn'],'status' => 2])->count()??0;
                 }
                 return 0;
             }]);

+ 4 - 1
app/controller/merchant/Plan.php

@@ -219,7 +219,7 @@ class Plan extends Base
                 foreach ($planData as $k => $v) {
                     $starAll[$k] = [
                         "plan_id"   => $resp['plan_id'],
-                        "unique_id" => $v
+                        "unique_id" => $v['unique_id']
                     ];
                 }
                 $state = (new SaasLivePlanStar)->insertAll($starAll);
@@ -227,6 +227,9 @@ class Plan extends Base
             if (!$state) return errorTrans("error.data");
             return successTrans("success.data");
         } catch (\Throwable $throwable) {
+            echo "编辑计划报错:".$throwable->getMessage()."\n";
+            echo "编辑计划报错:".$throwable->getFile()."\n";
+            echo "编辑计划报错:".$throwable->getLine()."\n";
             return error($throwable->getMessage());
         }
     }

+ 17 - 0
app/controller/merchant/Trans.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace app\controller\merchant;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\Middleware;
+
+/**
+ * 交易明显
+ */
+#[Controller("/api/merchant/trans"),Middleware(AuthMiddleware::class)]
+class Trans extends Base
+{
+
+}

+ 25 - 0
app/controller/merchant/User.php

@@ -77,4 +77,29 @@ class User extends Base
             return error($throwable->getMessage());
         }
     }
+
+
+    /**
+     * 删除用户
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("del")]
+    public function delUser(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"    => trans("empty.require")
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $user = $this->model->where("id",$param["id"])->findOrEmpty();
+            if ($user->isEmpty()) return errorTrans("error.data");
+            if ($user['store_id'] <> $request->user['store_id']) return errorTrans("error.data");
+            $state = $user->delete();
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
 }

+ 1 - 0
app/extra/dyLife/BasicLife.php

@@ -85,6 +85,7 @@ class BasicLife
      */
     public function curlPostApi(string $url = "", array $data = [], string $field = "data"): array
     {
+        print_r($this->header);
         $result = Http::asJson()->withHeaders($this->header)->post($this->gateway.$url,$data)->array();
         if (isset($result['err_no']) && $result['err_no'] <> 0) return ['msg' => $result['err_msg']];
         if(!empty($result[$field]))

+ 9 - 0
app/extra/dyLife/data/OrderData.php

@@ -27,6 +27,15 @@ class OrderData extends BasicLife
         return $this->curlPostApi("goodlife/v1/fulfilment/certificate/query/",$param);
     }
 
+    /**
+     * 查询订单详情
+     * @return void
+     */
+    public function getOrderData()
+    {
+
+    }
+
     /**
      * 发起核销
      * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.verify

+ 29 - 0
app/extra/dyMini/PlanLive.php

@@ -79,4 +79,33 @@ class PlanLive extends BasicLife
         return $this->curlPostApi("api/match/v2/poi/save_common_plan/",$param);
     }
 
+
+    /**
+     * 查询定向佣金计划带货汇总数据
+     * https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/locallife/general-ability/cps/query-oriented-plan-detail
+     * @param array $planId
+     * @return array
+     */
+    public function getPlanData(array $planId = []): array
+    {
+        $param = [
+            "plan_id_list"   => $planId
+        ];
+        echo json_encode($param)."\n";
+        print_r([
+            "access-token" => $this->getAccessToken(),
+            "Rpc-Transit-Life-Account" => "7595228109947947043"
+        ]);
+        $result = Http::asJson()->withHeaders([
+            "access-token" => $this->getAccessToken(),
+            "Rpc-Transit-Life-Account" => "7595228109947947043"
+        ])->post($this->gateway."api/match/v2/poi/oriented_plan_detail/",$param)->array();
+        print_r($result);
+        if(!empty($result['data']))
+        {
+            return $result['data'];
+        }
+        return [];
+    }
+
 }

+ 36 - 19
app/queue/redis/fast/OrderDone.php

@@ -4,6 +4,7 @@ namespace app\queue\redis\fast;
 
 use app\extra\dyLife\data\OrderData;
 use app\model\saas\SaasOrder;
+use app\model\saas\SaasOrderItem;
 use app\model\saas\SaasOrderVerify;
 use Webman\RedisQueue\Consumer;
 
@@ -46,15 +47,19 @@ class OrderDone implements Consumer
                 echo getDateFull()."===获取订单数据失败\n";
                 return true;
             }
-            if (!isset($orderCode['certificates'][0]['encrypted_code']))
+            $encrypted_code = [];
+            foreach ($orderCode['certificates'] as $key=>$v)
             {
-                echo getDateFull()."===获取订单数据失败\n";
-                return true;
-            }
-            if ($orderCode['certificates'][0]['status'] <> 1)
-            {
-                echo getDateFull()."===该订单状态不支持核销\n";
-                return true;
+                if (empty($v['encrypted_code']))
+                {
+                    echo getDateFull()."===获取订单数据失败\n";
+                    continue;
+                }
+                if ($v['status'] <> 1) {
+                    echo getDateFull()."===该订单状态不支持核销\n";
+                    continue;
+                }
+                $encrypted_code[$key] = $v['encrypted_code'];
             }
             // 核销订单
             $orderDone = (new OrderData)->config([
@@ -64,7 +69,8 @@ class OrderDone implements Consumer
             ])->token()->verifyCertificate([
                 "account_id"    => $order['poi']['store_id'],
                 "pay_sn"        => $order['pay_sn'],
-                "encrypted_code"    => $orderCode['certificates'][0]['encrypted_code'],
+//                "encrypted_code" => $orderCode['certificates'][0]['encrypted_code'],
+                "encrypted_code" => array_values($encrypted_code),
                 "order_id"      => $order['order_sn'],
                 "poi_id"        => $order['poi_id']
             ]);
@@ -73,6 +79,22 @@ class OrderDone implements Consumer
                 echo getDateFull()."===核销失败\n";
                 return true;
             }
+            $doneData = [];
+            foreach ($orderDone['verify_results'] as $key=>$v)
+            {
+                if(empty($v['verify_id'])) {
+                    continue;
+                }
+                if(empty($v['certificate_id'])) {
+                    continue;
+                }
+                $doneData[$key] = [
+                    "poi_id"            => $order['poi_id'],
+                    "order_sn"          => $order['order_sn'],
+                    "certificate_id"    => $v['certificate_id'],
+                    "verify_id"         => $v['verify_id'],
+                ];
+            }
             if (!isset($orderDone['verify_results'][0]['verify_id']))
             {
                 echo getDateFull()."===核销失败\n";
@@ -83,18 +105,13 @@ class OrderDone implements Consumer
                 echo getDateFull()."===核销失败\n";
                 return true;
             }
-            $order->status = 2;
-            $order->express_status = 1;
-            $order->verify_id = $orderDone['verify_results'][0]['verify_id'];
-            $order->certificate_id = $orderDone['verify_results'][0]['certificate_id'];
+            $order->express_status = 3;
+//            $order->verify_id = $orderDone['verify_results'][0]['verify_id'];
+//            $order->certificate_id = $orderDone['verify_results'][0]['certificate_id'];
             $order->done_at = getDateFull();
             $order->save();
-            (new SaasOrderVerify)->insertGetId([
-                "poi_id"            => $order['poi_id'],
-                "order_sn"          => $order['order_sn'],
-                "certificate_id"    => $orderDone['verify_results'][0]['certificate_id'],
-                "verify_id"         => $orderDone['verify_results'][0]['verify_id'],
-            ]);
+            (new SaasOrderItem)->where(['order_sn'=>$order['order_sn'],'status'=>1])->update(['status'=>3]);
+            (new SaasOrderVerify)->insertAll(array_values($doneData));
         } catch (\Throwable $throwable) {
             echo getDateFull()."==核销队列报错\n";
             echo $throwable->getMessage()."\n";