zory 3 săptămâni în urmă
părinte
comite
607d26719d

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

@@ -24,6 +24,7 @@ class Goods extends Base
     #[Inject]
     protected SaasGoods $model;
 
+    protected array $noNeedLogin = ["getGoodsData"];
 
     #[GetMapping("data")]
     public function getGoodsData(Request $request): Response

+ 1 - 1
app/controller/api/Home.php

@@ -38,7 +38,7 @@ class Home extends Base
                 ]
             ];
             $store = (new SaasStore)->where("poi_id",$param['store'])->field("poi_name,start_at,end_at,longitude,latitude,service_mobile,poi_id")->findOrEmpty();
-            $goods = (new SaasGoods)->where("poi_id",$param['store'])->field("product_id,product_name,image_list,category,price,line_price,sale_stock,id")->limit(10)->select()->toArray();
+            $goods = (new SaasGoods)->where("poi_id",$param['store'])->where("status",1)->field("product_id,product_name,image_list,category,price,line_price,sale_stock,id")->limit(10)->select()->toArray();
             return success("ok",compact('banner','store','goods'));
         } catch (\Throwable $th) {
             return error($th->getMessage());

+ 29 - 0
app/controller/api/Notify.php

@@ -16,6 +16,35 @@ class Notify extends Base
 
     #[PostMapping("douyin")]
     public function getOrderNotify(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            echo getDateFull()."===支付返回\n";
+            print_r($param);
+            $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
+            print_r($param['msg']);
+            print_r($data);
+            $orderSn = $data['out_order_no'];
+            if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
+            if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
+            $order = (new SaasOrder)->where("out_order_no",$orderSn)->findOrEmpty();
+            if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
+            if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
+            $order->status = 1;
+            $order->pay_at = getDateFull();
+            $order->pay_type = $data['pay_channel'];
+            $order->pay_sn = $data['channel_pay_id'];
+            $order->pay_money = $data['total_amount'];
+            $order->save();
+            return json(['err_no' => 0,'err_tips' => "success"]);
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+
+    #[PostMapping("mini")]
+    public function getOrderNotifyMini(Request $request): Response
     {
         try {
             $param = $request->all();

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

@@ -5,7 +5,10 @@ namespace app\controller\api;
 use app\extra\basic\Base;
 use app\extra\dyLife\Token;
 use app\extra\dyMini\Relation;
+use app\extra\tools\CodeExtend;
 use app\middleware\AuthMiddleware;
+use app\model\saas\SaasGoods;
+use app\model\saas\SaasOrder;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\GetMapping;
 use LinFly\Annotation\Attributes\Route\RequestMapping;
@@ -29,7 +32,60 @@ class Solution extends Base
             $data = $request->all();
             echo getDateFull()."===扩展回调\n";
             print_r($data);
-            print_r($request->rawBody());
+            if (isset($data['operate_type'])) {
+                if ($data['status'] == "PASS") { // 创建商品回调
+                    $goods = (new SaasGoods)->where("goods_id",$data['product_id'])->findOrEmpty();
+                    if ($goods->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
+                    $goods->status = 1;
+                    $goods->save();
+                }
+            }
+            if (isset($data['type']))
+            {
+                $msgData = json_decode($data['msg'],true);
+                switch ($data['type'])
+                {
+                    case "pre_create_order": // 预下单
+                        if (!isset($msgData['item_order_info_list'][0]['goods_id'])) return json(['err_no' => 0,"err_tips" => "success"]);
+                        $goods = (new SaasGoods)->where("goods_id",$msgData['item_order_info_list'][0]['goods_id'])->findOrEmpty();
+                        if ($goods->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
+                        $order = (new SaasOrder)->where("order_sn",$msgData['order_id'])->findOrEmpty();
+                        if (!$order->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
+                        $orderSn = "AL".CodeExtend::uniqidDate(18).rand(100,999);
+                        $goodsImg = is_string($goods['image_list'])?json_decode($goods['image_list'],true):[];
+                        $order->insertGetId([
+                            "out_order_no"  => $orderSn,
+                            "order_sn"  => $msgData['order_id'],
+                            "openid"    => $msgData['open_id'],
+                            "goods_id"  => $goods['id'],
+                            "life_goods_id" => $goods['goods_id'],
+                            "product_id"    => $goods['product_id'],
+                            "sku_id"        => "",
+                            "number"        => $msgData['goods'][0]['quantity']??1,
+                            "price"         => $msgData['item_order_info_list'][0]['price']?:$goods['price'],
+                            "line_price"    => $goods['line_price']*100,
+                            "poi_id"        => $goods['poi_id'],
+                            "img"           => $goodsImg[0]['url'],
+                            "sku_name"      => "",
+                            "mobile"        => $msgData['phone_num']??'',
+                            "pay_money"     => $msgData['total_amount']??0,
+                        ]);
+                        return json(['err_no' => 0,"err_tips" => "success","data" => [
+                            "order_entry_schema"    => [
+                                "path"      => "page/order/detail",
+                                "params"    => json_encode([
+                                    "order" => $orderSn
+                                ])
+                            ],
+                            "out_order_no"  => $orderSn,
+                            "pay_expire_seconds"    => 300,
+                            "pay_notify_url"        => "https://tran.jsshuita.cn/notify/douyin"
+                        ]]);
+                        break;
+                    default:
+                        break;
+                }
+            }
             return json(['err_no' => 0,"err_tips" => "success"]);
         } catch (\Throwable $throwable) {
             return error($throwable->getMessage());

+ 10 - 5
app/controller/merchant/Goods.php

@@ -126,6 +126,8 @@ class Goods extends Base
             $param['image_list'] = empty($param['image_list']) ? [] : json_encode($param['image_list']);
             $param['detail_image_list'] = empty($param['detail_image_list']) ? [] : json_encode($param['detail_image_list']);
             $param['environment_image_list'] = empty($param['environment_image_list']) ? [] : json_encode($param['environment_image_list']);
+            $param['notification'] = empty($param['notification']) ? [] : json_encode($param['notification']);
+            if (empty($param['specs'])) return error("至少添加一组搭配信息");
             if (is_array($param['specs'])) $param['specs'] = json_encode($param['specs']);
             if (is_array($param['category'])) {
                 $param['category_id'] = $param['category'][2]??0;
@@ -136,6 +138,7 @@ class Goods extends Base
             }
             $param['price'] = $param['price']*100;
             $param['poi_id'] = $request->user['store_id'];
+            if (!empty($param['no_use_weeks']) && count($param['no_use_weeks']) == 7) return error("至少需要保留一天可用");
             $skuData = [];
             if (is_array($param['skuSpecs'])) {
                 foreach ($param['skuSpecs'] as $key => $value) {
@@ -156,12 +159,14 @@ class Goods extends Base
                 "account"   => sConf("wechat.shop_id"),
             ])->token()->getStoreCategoryTemplate($param['category_id'],$param['product_type']);
             if (empty($valMap['product_attrs'])) return errorTrans("error.data");
-//            $data = (new BaseData)->config([
-//                "appid"     => sConf("wechat.mini_appid"),
-//                "secret"    => sConf("wechat.mini_secret"),
-//            ])->token()->createGoodsData($param,$skuData,$store->toArray(),$valMap);
-
+            $data = (new BaseData)->config([
+                "appid"     => sConf("wechat.mini_appid"),
+                "secret"    => sConf("wechat.mini_secret"),
+            ])->token()->createGoodsData($param,$skuData,$store->toArray(),$valMap);
+//            return errorTrans("error.data");
 //            print_r($data);
+            if (empty($data['product_id'])) return error($data['description']);
+            $param['goods_id'] = $data['product_id'];
 //            return errorTrans("error.data");
             $stateSku = false;
             if (!empty($skuData)) {

+ 69 - 9
app/extra/dyLife/data/BaseData.php

@@ -72,7 +72,7 @@ class BaseData extends BasicLife
 
         }
         print_r($param);
-        return $this->curlPostApi("goodlife/v1/goods/product/save/",$param);
+//        return $this->curlPostApi("goodlife/v1/goods/product/save/",$param);
     }
 
 
@@ -85,6 +85,58 @@ class BaseData extends BasicLife
     {
         switch ($key)
         {
+            case "commodity": // 商品搭配
+                $specs = json_decode($data['specs'],true);
+                $commodity = [];
+                foreach ($specs as $key=>$val) {
+                    $commodity[$key] = [
+                        "group_name"    => $val['name'],
+                        "total_count"   => count($val['list']),
+                        "option_count"  => $val['num']
+                    ];
+                    foreach ($val['list'] as $sKey=>$sub) {
+                        $commodity[$key]['item_list'][$sKey] = [
+                            "name"  => $sub['name'],
+                            "price" => $sub['price'] * 100,
+                            "count" => 1,
+                            "unit"  => "份"
+                        ];
+                    }
+                }
+                $return = json_encode($commodity);
+                break;
+            case "customer_reserved_info":
+                if ($data['customer_reserved_info'] == 1) { // 不需要留资
+                    $return = json_encode([
+                        "allow" => false
+                    ]);
+                } else {
+                    $return = json_encode([
+                        "allow"             => true,
+                        "allow_tel"         => true,
+                        "require_for_tel"   => true
+                    ]);
+                }
+                break;
+            case "appointment": // 预约规则
+                if ($data['booking_type'] == 1) { // 无需预约
+                    $return = json_encode([
+                        "need_appointment"  => false
+                    ]);
+                } else {
+                    if ($data['booking_unit'] == 1) {
+                        $return = json_encode([
+                            "need_appointment"  => true,
+                            "ahead_day_num"     => $data['booking_date']
+                        ]);
+                    } else {
+                        $return = json_encode([
+                            "need_appointment"  => true,
+                            "ahead_hour_num"    => $data['booking_date']
+                        ]);
+                    }
+                }
+                break;
             case "EntryType": // 入口类型 1:H5 2:小程序 3:抖音 4:lynx
                 $return = "2";
                 break;
@@ -94,8 +146,18 @@ class BaseData extends BasicLife
             case "can_no_use_date": // 不可使用日期
                 if ($data['can_no_use_date'] == 1) {
                     $return = json_encode(["enable" => false]);
-                } else {
-                    $return = json_encode(["enable" => false]);
+                } else { // 指定日期
+                    $noUse = ["enable" => true];
+                    if ($data['can_no_use_week']) { // 每周几不可用
+                        $noUse['days_of_week'] = $data['no_use_weeks'];
+                    }
+                    if ($data['can_no_use_holiday']) { // 节假日不可用
+                        $noUse['holidays'] = $data['no_use_weeks'];
+                    }
+                    if ($data['can_no_use_day']) { // 指定某天不可用
+                        $noUse['date_list'] = $data['no_use_days'];
+                    }
+                    $return = json_encode($noUse);
                 }
                 break;
             case "image_list": // 封面图 图片比例:375:280
@@ -136,12 +198,7 @@ class BaseData extends BasicLife
                 ]);
                 break;
             case "Notification": // 使用规则
-                $return = json_encode([
-                    [
-                        "title"     => "使用规则",
-                        "content"   => "到店出示券码核销"
-                    ]
-                ]);
+                $return = $data['notification'];
                 break;
             case "RefundPolicy": // 退款政策 1-允许退款 2-不可退款 3-有条件退
                 $return = "1";
@@ -162,6 +219,9 @@ class BaseData extends BasicLife
                     $return = json_encode(['is_limit' => false]);
                 }
                 break;
+            case "auto_renew":
+                $return = $data['auto_renew']==1?'true':'false';
+                break;
             default:
                 $return = "";
                 break;