zory 1 Minggu lalu
induk
melakukan
bd9788ab90

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

@@ -35,7 +35,7 @@ class Goods extends Base
                 "spm.require"   => trans("empty.require"),
             ],$request->method());
             if (!is_array($param)) return error($param);
-            $data = $this->model->where("id",$param['spm'])->with(['poi' => function ($query) {
+            $data = $this->model->where("product_id",$param['goods'])->with(['poi' => function ($query) {
                 $query->field("poi_id,poi_name,poi_address,longitude,latitude,poi_id");
             },'skuSpecs'])->findOrEmpty();
             if ($data->isEmpty()) return errorTrans("empty.data");

+ 33 - 0
app/controller/api/Order.php

@@ -7,6 +7,7 @@ use app\extra\dyLife\Crypt;
 use app\extra\dyMini\Pay;
 use app\middleware\AuthMiddleware;
 use app\model\saas\SaasOrder;
+use app\model\saas\SaasOrderPrice;
 use app\service\saas\OrderService;
 use DI\Attribute\Inject;
 use LinFly\Annotation\Attributes\Route\Controller;
@@ -121,6 +122,38 @@ class Order extends Base
     }
 
 
+    /**
+     * 差价支付
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("pricePay")]
+    public function orderPricePay(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "order.require"     => trans("empty.require")
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $order = (new SaasOrderPrice)->where("order_sn",$param['order'])->findOrEmpty();
+            $payParam = [
+                "order_sn"      => $order['order_sn'],
+                "total"         => $order['price'],
+                "name"          => $order['name'],
+                "notify_url"    => "https://tran.jsshuita.cn/notify/price"
+            ];
+            $byteAuthorization = (new Pay)->config([
+                "appid"     => sConf("wechat.mini_appid"),
+                "secret"    => sConf("wechat.mini_secret"),
+                "salt"      => sConf("wechat.mch_salt"),
+            ])->createOrder($payParam);
+            return success("ok",['pay' => $byteAuthorization]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
     /**
      * 发起支付
      * @param Request $request

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

@@ -164,7 +164,7 @@ class Goods extends Base
                 "secret"    => sConf("wechat.mini_secret"),
             ])->token()->createGoodsData($param,$skuData,$store->toArray(),$valMap);
 //            return errorTrans("error.data");
-//            print_r($data);
+            print_r($data);
             if (empty($data['product_id'])) return error($data['description']);
             $param['goods_id'] = $data['product_id'];
 //            return errorTrans("error.data");

+ 65 - 0
app/controller/service/Service.php

@@ -3,9 +3,11 @@
 namespace app\controller\service;
 
 use app\extra\basic\Base;
+use app\extra\tools\CodeExtend;
 use app\middleware\AuthMiddleware;
 use app\model\saas\SaasChatMsg;
 use app\model\saas\SaasChatStore;
+use app\model\saas\SaasOrderPrice;
 use app\service\saas\ChatStoreService;
 use DI\Attribute\Inject;
 use LinFly\Annotation\Attributes\Route\Controller;
@@ -112,4 +114,67 @@ class Service extends Base
         }
     }
 
+
+    #[PostMapping('send/price')]
+    public function sendPriceData(Request $request)
+    {
+        try {
+            $param = $this->_valid([
+                "name.require"      => trans("empty.require"),
+                "price.require"     => trans("empty.require"),
+                "groupId.require"   => trans("empty.require"),
+                "openid.require"    => trans("empty.require"),
+                "type.require"      => trans("empty.require"),
+            ],"post");
+            if (!is_array($param)) return error($param);
+            $orderSn = CodeExtend::uniqidDate(18,"P");
+            $msgId = time();
+            $priceState = (new SaasOrderPrice)->insertGetId([
+                "openid"        => $param['openid'],
+                "poi_id"        => $param['groupId'],
+                "service_id"    => $request->user['id'],
+                "name"          => $param['name'],
+                "price"         => $param['price'] * 100,
+                "image"         => "https://jymini.oss-cn-guangzhou.aliyuncs.com/mini/chajia.jpg",
+                "order_sn"      => $orderSn,
+                "msgId"         => $msgId,
+            ]);
+            if (!$priceState) return errorTrans("error.data");
+            $msgData = [
+                "img"   => "https://jymini.oss-cn-guangzhou.aliyuncs.com/mini/chajia.jpg",
+                "name"  => $param['name'],
+                "order" => $orderSn,
+                "price" => $param['price'],
+                "msgId" => $msgId,
+                "status"    => 0
+            ];
+            $state = (new SaasChatMsg)->insertGetId([
+                "source"    => 2,
+                "openid"    => $param['openid'],
+                "content"   => json_encode($msgData),
+                "type"      => $param['type'],
+                "msgId"     => $msgId,
+                "poi_id"    => $param['groupId'],
+                "service_id" => $request->user['id'],
+            ]);
+            if (!$state) return errorTrans("error.data");
+            $api = new Api('http://127.0.0.1:3232', config('plugin.webman.push.app.app_key'),config('plugin.webman.push.app.app_secret'));
+            $api->trigger("user-{$param['openid']}","message",[
+                "type"  =>  $param['type'],
+                "time"  =>  time() * 1000,
+                "msgId" => time(),
+                "content"   => json_encode($msgData),
+                "source" => 2,
+                "avatar"    => "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png",
+                "poi_id"    => $param['groupId'],
+                "openid"  => $param['openid'],
+                "service_id"  => $request->user['id'],
+                "create_at"  => formatTime(time()),
+            ]);
+            return successTrans("success.data",$msgData);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 }

+ 2 - 2
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);
     }
 
 
@@ -92,7 +92,7 @@ class BaseData extends BasicLife
                     $commodity[$key] = [
                         "group_name"    => $val['name'],
                         "total_count"   => count($val['list']),
-                        "option_count"  => $val['num']
+                        "option_count"  => $val['num']==0?count($val['list']):$val['num']
                     ];
                     foreach ($val['list'] as $sKey=>$sub) {
                         $commodity[$key]['item_list'][$sKey] = [

+ 49 - 0
app/model/saas/SaasOrderPrice.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property string $name 
+ * @property integer $price 
+ * @property string $image 
+ * @property mixed $order_sn 
+ * @property integer $status 
+ * @property mixed $msgId 
+ * @property mixed $create_at
+ */
+class SaasOrderPrice extends Model
+{
+    /**
+     * The connection name for the model.
+     *
+     * @var string|null
+     */
+    protected $connection = 'mysql';
+    
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected string $table = "saas_order_price";
+    
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected string $primaryKey = "id";
+    
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public bool $timestamps = false;
+
+
+}