|
@@ -7,6 +7,7 @@ use app\api\logic\ServiceOrderLogic;
|
|
|
use app\common\model\Config;
|
|
use app\common\model\Config;
|
|
|
use app\common\model\external\DouyinOrder;
|
|
use app\common\model\external\DouyinOrder;
|
|
|
use app\common\model\external\DouyinRefundOrder;
|
|
use app\common\model\external\DouyinRefundOrder;
|
|
|
|
|
+use app\common\model\external\DouyinUserAuth;
|
|
|
use app\common\model\external\ExternalConsultation;
|
|
use app\common\model\external\ExternalConsultation;
|
|
|
use app\common\model\external\ExternalConsultationOrder;
|
|
use app\common\model\external\ExternalConsultationOrder;
|
|
|
use app\common\model\external\ExternalPlatformGoods;
|
|
use app\common\model\external\ExternalPlatformGoods;
|
|
@@ -82,6 +83,41 @@ class DouYinService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public static function getDouyinUserByOpenId(array $openId)
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $user = DouyinUserAuth::where('openid',$openId)->findOrEmpty();
|
|
|
|
|
+ if ($user->isEmpty()) {
|
|
|
|
|
+ //直接注册用户
|
|
|
|
|
+ $params['channel'] = self::$terminal;
|
|
|
|
|
+ $user = self::register($params);
|
|
|
|
|
+ }
|
|
|
|
|
+ //更新登录信息
|
|
|
|
|
+ $user->login_time = time();
|
|
|
|
|
+ $user->login_ip = request()->ip();
|
|
|
|
|
+ $user->save();
|
|
|
|
|
+
|
|
|
|
|
+ $userInfo = UserTokenService::setToken($user->id, self::$terminal);
|
|
|
|
|
+
|
|
|
|
|
+ //返回登录信息
|
|
|
|
|
+ $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
|
|
|
|
|
+ $avatar = FileService::getFileUrl($avatar);
|
|
|
|
|
+
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'nickname' => $userInfo['nickname'],
|
|
|
|
|
+ 'sn' => $userInfo['sn'],
|
|
|
|
|
+ 'mobile' => $userInfo['mobile'],
|
|
|
|
|
+ 'avatar' => $avatar,
|
|
|
|
|
+ 'token' => $userInfo['token'],
|
|
|
|
|
+ ];
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// **************************** 商品管理 goods_category_id goods_id external_platform_id
|
|
// **************************** 商品管理 goods_category_id goods_id external_platform_id
|
|
|
public static function addProduct($params)
|
|
public static function addProduct($params)
|
|
|
{
|
|
{
|
|
@@ -143,7 +179,7 @@ class DouYinService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 预下单接口 - 前端 首次/尾款
|
|
// 预下单接口 - 前端 首次/尾款
|
|
|
- public static function getPluginCreateOrderData($goods_id, $quantity, $douyinOrderId)
|
|
|
|
|
|
|
+ public static function getPluginCreateOrderData($goods_id, $quantity, $douyinOrderId,$params)
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
$goods = Goods::where('id',$goods_id)->findOrEmpty();
|
|
$goods = Goods::where('id',$goods_id)->findOrEmpty();
|
|
@@ -170,7 +206,7 @@ class DouYinService
|
|
|
[
|
|
[
|
|
|
"quantity" => $quantity,
|
|
"quantity" => $quantity,
|
|
|
"skuId" => (string)$platformGoods['external_goods_sn'],
|
|
"skuId" => (string)$platformGoods['external_goods_sn'],
|
|
|
- "skuType" => 2,
|
|
|
|
|
|
|
+ "skuType" => 1, // 1:商品库商品 2:非商品库商品(融合预约品走加价时,固定传2)
|
|
|
"price" => $platformGoods['service_fee'] * 100,
|
|
"price" => $platformGoods['service_fee'] * 100,
|
|
|
]
|
|
]
|
|
|
],
|
|
],
|
|
@@ -194,6 +230,7 @@ class DouYinService
|
|
|
"outShopId" => self::EXTERNAL_PLATFORM_ID,
|
|
"outShopId" => self::EXTERNAL_PLATFORM_ID,
|
|
|
"skuId" => (string)$platformGoods['external_goods_sn'],
|
|
"skuId" => (string)$platformGoods['external_goods_sn'],
|
|
|
"quantity" => $quantity,
|
|
"quantity" => $quantity,
|
|
|
|
|
+ "user_id" => $params['user_id'],
|
|
|
"douyinOrderId" => $douyinOrderId?:0,
|
|
"douyinOrderId" => $douyinOrderId?:0,
|
|
|
],
|
|
],
|
|
|
/*"tradeOption" => json_encode([
|
|
/*"tradeOption" => json_encode([
|
|
@@ -237,11 +274,8 @@ class DouYinService
|
|
|
try {
|
|
try {
|
|
|
$params['external_platform_id'] = self::EXTERNAL_PLATFORM_ID;
|
|
$params['external_platform_id'] = self::EXTERNAL_PLATFORM_ID;
|
|
|
// order_id goods total_amount discount cp_extra create_order_time phone_num contact_name open_id
|
|
// order_id goods total_amount discount cp_extra create_order_time phone_num contact_name open_id
|
|
|
- if(empty($params['phone_num'])){
|
|
|
|
|
- throw new \Exception('手机号不能为空!');
|
|
|
|
|
- }
|
|
|
|
|
- $user_id = $params['user_id'];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $user_id = $params['cp_extra']['user_id'];
|
|
|
|
|
+ $user = User::where('id',$user_id)->findOrEmpty();
|
|
|
if($params['cp_extra']['douyinOrderId']>0){ // 说明是尾款单
|
|
if($params['cp_extra']['douyinOrderId']>0){ // 说明是尾款单
|
|
|
// 创建尾款单
|
|
// 创建尾款单
|
|
|
$order_number = self::tailOrder([
|
|
$order_number = self::tailOrder([
|
|
@@ -254,9 +288,11 @@ class DouYinService
|
|
|
}else{
|
|
}else{
|
|
|
// 创建首单 goods_id user_info.mobile user_id quantity
|
|
// 创建首单 goods_id user_info.mobile user_id quantity
|
|
|
$order_number = self::submitOrder([
|
|
$order_number = self::submitOrder([
|
|
|
|
|
+ 'open_id'=>$params['open_id'],
|
|
|
|
|
+ 'order_id'=>$params['order_id'], // 抖音订单号
|
|
|
'goods_id'=>$params['cp_extra']['skuId'],
|
|
'goods_id'=>$params['cp_extra']['skuId'],
|
|
|
'user_id'=>$user_id??0,
|
|
'user_id'=>$user_id??0,
|
|
|
- 'mobile'=>$params['phone_num'],
|
|
|
|
|
|
|
+ 'mobile'=>$user['mobile']??'',
|
|
|
'quantity'=>$params['cp_extra']['quantity']
|
|
'quantity'=>$params['cp_extra']['quantity']
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
@@ -287,6 +323,10 @@ class DouYinService
|
|
|
if($goods->isEmpty()){
|
|
if($goods->isEmpty()){
|
|
|
throw new \Exception('产品不存在!');
|
|
throw new \Exception('产品不存在!');
|
|
|
}
|
|
}
|
|
|
|
|
+ $platformGoods = ExternalPlatformGoods::where('goods_id', $params['goods_id'])->where('external_platform_id', self::EXTERNAL_PLATFORM_ID)->findOrEmpty();
|
|
|
|
|
+ if($platformGoods->isEmpty()){
|
|
|
|
|
+ throw new \Exception('产品不存在!');
|
|
|
|
|
+ }
|
|
|
if(empty($params['mobile'])){
|
|
if(empty($params['mobile'])){
|
|
|
throw new \Exception('请先补充您的联系方式后在提交订单');
|
|
throw new \Exception('请先补充您的联系方式后在提交订单');
|
|
|
}
|
|
}
|
|
@@ -300,12 +340,14 @@ class DouYinService
|
|
|
$create_data = [
|
|
$create_data = [
|
|
|
'user_id' => $params['user_id'],
|
|
'user_id' => $params['user_id'],
|
|
|
'mobile' => $params['mobile'],
|
|
'mobile' => $params['mobile'],
|
|
|
|
|
+ 'open_id' => $params['open_id'],
|
|
|
|
|
+ 'goods_id'=>$goods['id'],
|
|
|
'title' => $goods['goods_name'],
|
|
'title' => $goods['goods_name'],
|
|
|
|
|
|
|
|
- 'goods_id'=>$goods['id'],
|
|
|
|
|
- 'unit_price' => $goods['service_fee'],
|
|
|
|
|
|
|
+ 'unit_price' => $platformGoods['service_fee'],
|
|
|
'quantity' => $quantity,
|
|
'quantity' => $quantity,
|
|
|
- 'total_amount' => $goods['service_fee'] * $quantity,
|
|
|
|
|
|
|
+ 'total_amount' => $platformGoods['service_fee'] * $quantity,
|
|
|
|
|
+ 'dy_order_id' => $params['order_id']??'',
|
|
|
'order_number' => generate_sn(DouyinOrder::class, 'order_number'),
|
|
'order_number' => generate_sn(DouyinOrder::class, 'order_number'),
|
|
|
];
|
|
];
|
|
|
$order = DouyinOrder::create($create_data);
|
|
$order = DouyinOrder::create($create_data);
|
|
@@ -448,18 +490,21 @@ class DouYinService
|
|
|
$consultation['lon'] = $params['lon'];
|
|
$consultation['lon'] = $params['lon'];
|
|
|
$consultation['lat'] = $params['lat'];
|
|
$consultation['lat'] = $params['lat'];
|
|
|
$consultation['appointment_time'] = $params['appointment_time'];
|
|
$consultation['appointment_time'] = $params['appointment_time'];
|
|
|
- $result = ExternalConsultationLogic::order($consultation);
|
|
|
|
|
- if (false === $result) {
|
|
|
|
|
|
|
+ $consultationOrderId = ExternalConsultationLogic::order($consultation);
|
|
|
|
|
+ if (false === $consultationOrderId) {
|
|
|
throw new \Exception('预约失败');
|
|
throw new \Exception('预约失败');
|
|
|
}
|
|
}
|
|
|
- if(!empty($result)){
|
|
|
|
|
- $consultationOrder = ExternalConsultationOrder::where('consultation_id', $order->consultation_id)->where('goods_id', $order->goods_id)->where('amount', $order->paid_amount)
|
|
|
|
|
- ->findOrEmpty()->toArray();
|
|
|
|
|
|
|
+ if(!empty($consultationOrderId)){
|
|
|
|
|
+ $consultationOrder = ExternalConsultationOrder::where('id', $consultationOrderId)->findOrEmpty()->toArray();
|
|
|
$work_status = ServiceWork::where('id', $consultationOrder['work_id'])->value('work_status');
|
|
$work_status = ServiceWork::where('id', $consultationOrder['work_id'])->value('work_status');
|
|
|
$order->work_id = $consultationOrder['work_id'];
|
|
$order->work_id = $consultationOrder['work_id'];
|
|
|
$order->fulfillment_status = $work_status;
|
|
$order->fulfillment_status = $work_status;
|
|
|
$order->save();
|
|
$order->save();
|
|
|
}
|
|
}
|
|
|
|
|
+ $params['dy_order_id'] = $order->dy_order_id;
|
|
|
|
|
+ $params['consultationOrderId'] = $consultationOrderId;
|
|
|
|
|
+ $params['open_id'] = $order->open_id;
|
|
|
|
|
+ $params['goods_id'] = $order->goods_id;
|
|
|
}
|
|
}
|
|
|
Db::commit();
|
|
Db::commit();
|
|
|
|
|
|
|
@@ -484,18 +529,25 @@ class DouYinService
|
|
|
public static function getCreateBookParams($params)
|
|
public static function getCreateBookParams($params)
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
|
|
+ $platformGoods = ExternalPlatformGoods::where('goods_id', $params['goods_id'])->where('external_platform_id', self::EXTERNAL_PLATFORM_ID)->findOrEmpty();
|
|
|
|
|
+ if($platformGoods->isEmpty()){
|
|
|
|
|
+ throw new \Exception('产品不存在!');
|
|
|
|
|
+ }
|
|
|
|
|
+ $appointment_time = strtotime($params['appointment_time']);
|
|
|
|
|
+ $book_start_time = $appointment_time * 1000;
|
|
|
|
|
+ $book_end_time = ($appointment_time + (2 * 86400)) * 1000;
|
|
|
$data = [
|
|
$data = [
|
|
|
- "order_id"=> $params['order_number']??'',
|
|
|
|
|
- "out_book_no"=> time()??'',
|
|
|
|
|
- "open_id"=> $params['open_id']??'',
|
|
|
|
|
|
|
+ "order_id"=> (string)$params['dy_order_id']??'',
|
|
|
|
|
+ "out_book_no"=> (string)$params['consultationOrderId']??'',
|
|
|
|
|
+ "open_id"=> (string)$params['open_id']??'',
|
|
|
"item_book_info_list" => [
|
|
"item_book_info_list" => [
|
|
|
[
|
|
[
|
|
|
"poi_id" => '7511543640776017961',
|
|
"poi_id" => '7511543640776017961',
|
|
|
"shop_name" => '亿蜂快修·武汉市',
|
|
"shop_name" => '亿蜂快修·武汉市',
|
|
|
- "ext_shop_id" => self::EXTERNAL_PLATFORM_ID,
|
|
|
|
|
- "goods_id" => (string)$params['external_goods_sn'],
|
|
|
|
|
- "book_start_time" => $params['book_start_time']??'',
|
|
|
|
|
- "book_end_time" => $params['book_end_time']??'',
|
|
|
|
|
|
|
+ "ext_shop_id" => (string)self::EXTERNAL_PLATFORM_ID,
|
|
|
|
|
+ "goods_id" => (string)$platformGoods->external_goods_sn,
|
|
|
|
|
+ "book_start_time" => (int)$book_start_time??0,
|
|
|
|
|
+ "book_end_time" => (int)$book_end_time??0,
|
|
|
]
|
|
]
|
|
|
]
|
|
]
|
|
|
];
|
|
];
|